Neko 1.99.11
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
curl_simcomp.f90
Go to the documentation of this file.
1! Copyright (c) 2023-2026, The Neko Authors
2! All rights reserved.
3!
4! Redistribution and use in source and binary forms, with or without
5! modification, are permitted provided that the following conditions
6! are met:
7!
8! * Redistributions of source code must retain the above copyright
9! notice, this list of conditions and the following disclaimer.
10!
11! * Redistributions in binary form must reproduce the above
12! copyright notice, this list of conditions and the following
13! disclaimer in the documentation and/or other materials provided
14! with the distribution.
15!
16! * Neither the name of the authors nor the names of its
17! contributors may be used to endorse or promote products derived
18! from this software without specific prior written permission.
19!
20! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24! COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30! ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31! POSSIBILITY OF SUCH DAMAGE.
32!
33!
34!> Implements the `curl_t` type.
35
37 use num_types, only : rp, dp, sp
38 use json_module, only : json_file
40 use registry, only : neko_registry
41 use field, only : field_t
42 use time_state, only : time_state_t
43 use operators, only : curl
44 use case, only : case_t
48 use device, only : glb_cmd_event
52 implicit none
53 private
54
55 !> A simulation component that computes the curl of a vector field.
56 !! Added to the field registry as `curl_x`, `curl_y``, and `curl_z` by
57 !! default, but can be controlled by the computed_field keyword.
58 type, public, extends(simulation_component_t) :: curl_t
59 !> X input vector field component.
60 type(field_t), pointer :: u
61 !> Y input vector field component.
62 type(field_t), pointer :: v
63 !> Z input vector field component.
64 type(field_t), pointer :: w
65
66 !> X curl component.
67 type(field_t), pointer :: curl_x
68 !> Y curl component.
69 type(field_t), pointer :: curl_y
70 !> Z curl component.
71 type(field_t), pointer :: curl_z
72
73 !> Output writer.
74 type(field_writer_t) :: writer
75
76 contains
77 !> Constructor from json, wrapping the actual constructor.
78 procedure, pass(this) :: init => curl_init_from_json
79 !> Generic for constructing from components.
80 generic :: init_from_components => &
81 init_from_controllers, init_from_controllers_properties
82 !> Constructor from components, passing time_based_controllers.
83 procedure, pass(this) :: init_from_controllers => &
85 !> Constructor from components, passing the properties of
86 !! time_based_controllers.
87 procedure, pass(this) :: init_from_controllers_properties => &
89 !> Common part of both constructors.
90 procedure, private, pass(this) :: init_common => curl_init_common
91 !> Destructor.
92 procedure, pass(this) :: free => curl_free
93 !> Compute the curl field.
94 procedure, pass(this) :: compute_ => curl_compute
95 end type curl_t
96
97contains
98
99 !> Constructor from json.
100 subroutine curl_init_from_json(this, json, case)
101 class(curl_t), intent(inout), target :: this
102 type(json_file), intent(inout) :: json
103 class(case_t), intent(inout), target :: case
104 character(len=NEKO_VARNAME_LEN) :: fields(3)
105 character(len=NEKO_VARNAME_LEN), allocatable :: field_names(:)
106 character(len=:), allocatable :: computed_field
107
108
109 call json_get_or_default(json, "name", this%name, "curl")
110 call json_get_or_default(json, "computed_field", computed_field, &
111 "curl")
112 call json_get(json, "fields", field_names)
113
114 if (size(field_names) .ne. 3) then
115 call neko_error("The curl simcomp requires exactly 3 entries in " // &
116 "fields.")
117 end if
118
119 fields(1) = trim(computed_field) // "_x"
120 fields(2) = trim(computed_field) // "_y"
121 fields(3) = trim(computed_field) // "_z"
122
123 ! This is needed for the field writer to pick up the fields.
124 call json%add("fields", fields)
125
126 call this%init_base(json, case)
127 call this%writer%init(json, case)
128
129 call curl_init_common(this, this%name, field_names, computed_field)
130 end subroutine curl_init_from_json
131
132 !> Common part of the constructors.
133 !! @param name The unique name of the simcomp.
134 !! @param field_names The component names of the field to compute the curl of.
135 !! @param computed_field The name prefix of the computed curl field.
136 subroutine curl_init_common(this, name, field_names, computed_field)
137 class(curl_t), intent(inout) :: this
138 character(len=*), intent(in) :: name
139 character(len=*), intent(in) :: field_names(3)
140 character(len=*), intent(in) :: computed_field
141 this%name = name
142 this%u => neko_registry%get_field_by_name(field_names(1))
143 this%v => neko_registry%get_field_by_name(field_names(2))
144 this%w => neko_registry%get_field_by_name(field_names(3))
145
146 this%curl_x => neko_registry%get_field_by_name(computed_field // "_x")
147 this%curl_y => neko_registry%get_field_by_name(computed_field // "_y")
148 this%curl_z => neko_registry%get_field_by_name(computed_field // "_z")
149
150 end subroutine curl_init_common
151
152 !> Constructor from components, passing controllers.
153 !! @param case The simulation case object.
154 !! @param name The unique name of the simcomp, prefixes computed curl field
155 !! names.
156 !! @param order The execution oder priority of the simcomp.
157 !! @param preprocess_controller The controller for running preprocessing.
158 !! @param compute_controller The controller for running compute.
159 !! @param output_controller The controller for producing output.
160 !! @param field_names The component names of the field to compute the curl of.
161 !! @param computed_field The base name of the curl field components.
162 !! @param filename The name of the file save the fields to. Optional, if not
163 !! @param precision The real precision of the output data. Optional, defaults
164 !! to single precision.
165 subroutine curl_init_from_controllers(this, name, case, order, &
166 preprocess_controller, compute_controller, output_controller, &
167 field_names, computed_field, filename, precision)
168 class(curl_t), intent(inout) :: this
169 character(len=*), intent(in) :: name
170 class(case_t), intent(inout), target :: case
171 integer :: order
172 type(time_based_controller_t), intent(in) :: preprocess_controller
173 type(time_based_controller_t), intent(in) :: compute_controller
174 type(time_based_controller_t), intent(in) :: output_controller
175 character(len=*), intent(in) :: field_names(3)
176 character(len=*), intent(in) :: computed_field
177 character(len=*), intent(in), optional :: filename
178 integer, intent(in), optional :: precision
179
180 character(len=NEKO_VARNAME_LEN) :: fields(3)
181
182 this%name = name
183
184 fields(1) = trim(this%name) // "_x"
185 fields(2) = trim(this%name) // "_y"
186 fields(3) = trim(this%name) // "_z"
187
188 call this%init_base_from_components(case, order, preprocess_controller, &
189 compute_controller, output_controller)
190 call this%writer%init_from_components("field_writer", case, order, &
191 preprocess_controller, compute_controller, output_controller, fields, &
192 filename, precision)
193 call this%init_common(this%name, field_names, computed_field)
194
195 end subroutine curl_init_from_controllers
196
197 !> Constructor from components, passing properties to the
198 !! time_based_controller` components in the base type.
199 !! @param name The unique name of the simcomp, prefixes computed curl field.
200 !! names.
201 !! @param case The simulation case object.
202 !! @param order The execution oder priority of the simcomp.
203 !! @param preprocess_controller Control mode for preprocessing.
204 !! @param preprocess_value Value parameter for preprocessing.
205 !! @param compute_controller Control mode for computing.
206 !! @param compute_value Value parameter for computing.
207 !! @param output_controller Control mode for output.
208 !! @param output_value Value parameter for output.
209 !! @param field_names The component names of the field to compute the curl of.
210 !! @param computed_field The base name of the curl field components.
211 !! @param filename The name of the file save the fields to. Optional, if not
212 !! provided, fields are added to the main output file.
213 !! @param precision The real precision of the output data. Optional, defaults
214 !! to single precision.
215 subroutine curl_init_from_controllers_properties(this, name, case, order, &
216 preprocess_control, preprocess_value, compute_control, compute_value, &
217 output_control, output_value, field_names, computed_field, filename, &
218 precision)
219 class(curl_t), intent(inout) :: this
220 character(len=*), intent(in) :: name
221 class(case_t), intent(inout), target :: case
222 integer :: order
223 character(len=*), intent(in) :: preprocess_control
224 real(kind=dp), intent(in) :: preprocess_value
225 character(len=*), intent(in) :: compute_control
226 real(kind=dp), intent(in) :: compute_value
227 character(len=*), intent(in) :: output_control
228 real(kind=dp), intent(in) :: output_value
229 character(len=*), intent(in) :: field_names(3)
230 character(len=*), intent(in) :: computed_field
231 character(len=*), intent(in), optional :: filename
232 integer, intent(in), optional :: precision
233
234 character(len=NEKO_VARNAME_LEN) :: fields(3)
235
236 this%name = name
237
238 fields(1) = trim(computed_field) // "_x"
239 fields(2) = trim(computed_field) // "_y"
240 fields(3) = trim(computed_field) // "_z"
241
242 call this%init_base_from_components(case, order, preprocess_control, &
243 preprocess_value, compute_control, compute_value, output_control, &
244 output_value)
245 call this%writer%init_from_components("field_writer", case, order, &
246 preprocess_control, preprocess_value, compute_control, compute_value, &
247 output_control, output_value, fields, filename, precision)
248 call this%init_common(this%name, field_names, computed_field)
249
251
252 !> Destructor.
253 subroutine curl_free(this)
254 class(curl_t), intent(inout) :: this
255 call this%free_base()
256 call this%writer%free()
257
258 nullify(this%u)
259 nullify(this%v)
260 nullify(this%w)
261 nullify(this%curl_x)
262 nullify(this%curl_y)
263 nullify(this%curl_z)
264 end subroutine curl_free
265
266 !> Compute the curl field.
267 subroutine curl_compute(this, time)
268 class(curl_t), intent(inout) :: this
269 type(time_state_t), intent(in) :: time
270 type(field_t), pointer :: temp1, temp2
271 integer :: tmp_idx(2)
272
273 call neko_scratch_registry%request_field(temp1, tmp_idx(1), .false.)
274 call neko_scratch_registry%request_field(temp2, tmp_idx(2), .false.)
275
276 call curl(this%curl_x, this%curl_y, this%curl_z, this%u, this%v, &
277 this%w, temp1, temp2, this%case%fluid%c_Xh, &
279
280 call neko_scratch_registry%relinquish_field(tmp_idx)
281 end subroutine curl_compute
282
283end module curl_simcomp
Retrieves a parameter by name or assigns a provided default value. In the latter case also adds the m...
Retrieves a parameter by name or throws an error.
Defines a simulation case.
Definition case.f90:34
Implements the curl_t type.
subroutine curl_init_common(this, name, field_names, computed_field)
Common part of the constructors.
subroutine curl_init_from_controllers_properties(this, name, case, order, preprocess_control, preprocess_value, compute_control, compute_value, output_control, output_value, field_names, computed_field, filename, precision)
Constructor from components, passing properties to the time_based_controller` components in the base ...
subroutine curl_free(this)
Destructor.
subroutine curl_init_from_controllers(this, name, case, order, preprocess_controller, compute_controller, output_controller, field_names, computed_field, filename, precision)
Constructor from components, passing controllers.
subroutine curl_init_from_json(this, json, case)
Constructor from json.
subroutine curl_compute(this, time)
Compute the curl field.
Device abstraction, common interface for various accelerators.
Definition device.F90:34
type(c_ptr), bind(C), public glb_cmd_event
Event for the global command queue.
Definition device.F90:63
Implements the field_writer_t type.
Defines a field.
Definition field.f90:34
Implements fld_file_output_t.
Utilities for retrieving parameters from the case files.
integer, parameter, public dp
Definition num_types.f90:10
integer, parameter, public sp
Definition num_types.f90:8
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:14
Operators.
Definition operators.f90:34
subroutine, public curl(w1, w2, w3, u1, u2, u3, work1, work2, coef, event)
Implements output_controller_t.
Defines a registry for storing solution fields.
Definition registry.f90:34
type(registry_t), target, public neko_registry
Global field registry.
Definition registry.f90:158
Defines a registry for storing and requesting temporary objects This can be used when you have a func...
type(scratch_registry_t), target, public neko_scratch_registry
Global scratch registry.
Simulation components are objects that encapsulate functionality that can be fit to a particular comp...
subroutine compute_(this, time)
Dummy compute function.
Contains the time_based_controller_t type.
Module with things related to the simulation time.
Utilities.
Definition utils.f90:35
integer, parameter, public neko_varname_len
Definition utils.f90:43
A simulation component that computes the curl of a vector field. Added to the field registry as curl_...
A simulation component that writes a 3d field to a file.
A simple output saving a list of fields to a .fld file.
Base abstract class for simulation components.
A utility type for determining whether an action should be executed based on the current time value....
A struct that contains all info about the time, expand as needed.