Neko 1.99.1
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-2025, 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!
35
37 use num_types, only : rp, dp, sp
38 use json_module, only : json_file
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
51 use utils, only : neko_error
52 implicit none
53 private
54
58 type, public, extends(simulation_component_t) :: curl_t
60 type(field_t), pointer :: u
62 type(field_t), pointer :: v
64 type(field_t), pointer :: w
65
67 type(field_t), pointer :: curl_x
69 type(field_t), pointer :: curl_y
71 type(field_t), pointer :: curl_z
72
74 type(field_writer_t) :: writer
75
76 contains
78 procedure, pass(this) :: init => curl_init_from_json
80 generic :: init_from_components => &
81 init_from_controllers, init_from_controllers_properties
83 procedure, pass(this) :: init_from_controllers => &
87 procedure, pass(this) :: init_from_controllers_properties => &
90 procedure, private, pass(this) :: init_common => curl_init_common
92 procedure, pass(this) :: free => curl_free
94 procedure, pass(this) :: compute_ => curl_compute
95 end type curl_t
96
97contains
98
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=20) :: fields(3)
105 character(len=20), allocatable :: field_names(:)
106 character(len=:), allocatable :: computed_field
107
108
109 call json_get_or_default(json, "computed_field", computed_field, "curl")
110 call json_get(json, "fields", field_names)
111
112 if (size(field_names) .ne. 3) then
113 call neko_error("The curl simcomp requires exactly 3 entries in " // &
114 "fields.")
115 end if
116
117 fields(1) = trim(computed_field) // "_x"
118 fields(2) = trim(computed_field) // "_y"
119 fields(3) = trim(computed_field) // "_z"
120
121 ! This is needed for the field writer to pick up the fields.
122 call json%add("fields", fields)
123
124 call this%init_base(json, case)
125 call this%writer%init(json, case)
126
127 call curl_init_common(this, field_names, computed_field)
128 end subroutine curl_init_from_json
129
133 subroutine curl_init_common(this, field_names, computed_field)
134 class(curl_t), intent(inout) :: this
135 character(len=*) :: field_names(3)
136 character(len=*) :: computed_field
137
138 this%u => neko_field_registry%get_field_by_name(field_names(1))
139 this%v => neko_field_registry%get_field_by_name(field_names(2))
140 this%w => neko_field_registry%get_field_by_name(field_names(3))
141
142 this%curl_x => neko_field_registry%get_field_by_name(computed_field // &
143 "_x")
144 this%curl_y => neko_field_registry%get_field_by_name(computed_field // &
145
146 "_y")
147 this%curl_z => neko_field_registry%get_field_by_name(computed_field // &
148 "_z")
149
150 end subroutine curl_init_common
151
163 subroutine curl_init_from_controllers(this, case, order, &
164 preprocess_controller, compute_controller, output_controller, &
165 field_names, computed_field, filename, precision)
166 class(curl_t), intent(inout) :: this
167 class(case_t), intent(inout), target :: case
168 integer :: order
169 type(time_based_controller_t), intent(in) :: preprocess_controller
170 type(time_based_controller_t), intent(in) :: compute_controller
171 type(time_based_controller_t), intent(in) :: output_controller
172 character(len=*) :: field_names(3)
173 character(len=*) :: computed_field
174 character(len=*), intent(in), optional :: filename
175 integer, intent(in), optional :: precision
176
177 character(len=20) :: fields(3)
178
179 fields(1) = trim(computed_field) // "_x"
180 fields(2) = trim(computed_field) // "_y"
181 fields(3) = trim(computed_field) // "_z"
182
183 call this%init_base_from_components(case, order, preprocess_controller, &
184 compute_controller, output_controller)
185 call this%writer%init_from_components(case, order, preprocess_controller, &
186 compute_controller, output_controller, fields, filename, precision)
187 call this%init_common(field_names, computed_field)
188
189 end subroutine curl_init_from_controllers
190
208 case, order, preprocess_control, preprocess_value, compute_control, &
209 compute_value, output_control, output_value, field_names, computed_field, &
210 filename, precision)
211 class(curl_t), intent(inout) :: this
212 class(case_t), intent(inout), target :: case
213 integer :: order
214 character(len=*), intent(in) :: preprocess_control
215 real(kind=rp), intent(in) :: preprocess_value
216 character(len=*), intent(in) :: compute_control
217 real(kind=rp), intent(in) :: compute_value
218 character(len=*), intent(in) :: output_control
219 real(kind=rp), intent(in) :: output_value
220 character(len=*) :: field_names(3)
221 character(len=*) :: computed_field
222 character(len=*), intent(in), optional :: filename
223 integer, intent(in), optional :: precision
224
225 character(len=20) :: fields(3)
226
227 fields(1) = trim(computed_field) // "_x"
228 fields(2) = trim(computed_field) // "_y"
229 fields(3) = trim(computed_field) // "_z"
230
231 call this%init_base_from_components(case, order, preprocess_control, &
232 preprocess_value, compute_control, compute_value, output_control, &
233 output_value)
234 call this%writer%init_from_components(case, order, preprocess_control, &
235 preprocess_value, compute_control, compute_value, output_control, &
236 output_value, fields, filename, precision)
237 call this%init_common(field_names, computed_field)
238
240
242 subroutine curl_free(this)
243 class(curl_t), intent(inout) :: this
244 call this%free_base()
245 call this%writer%free()
246
247 nullify(this%u)
248 nullify(this%v)
249 nullify(this%w)
250 nullify(this%curl_x)
251 nullify(this%curl_y)
252 nullify(this%curl_z)
253 end subroutine curl_free
254
256 subroutine curl_compute(this, time)
257 class(curl_t), intent(inout) :: this
258 type(time_state_t), intent(in) :: time
259 type(field_t), pointer :: temp1, temp2
260 integer :: tmp_idx(2)
261
262 call neko_scratch_registry%request_field(temp1, tmp_idx(1))
263 call neko_scratch_registry%request_field(temp2, tmp_idx(2))
264
265 call curl(this%curl_x, this%curl_y, this%curl_z, this%u, this%v, &
266 this%w, temp1, temp2, this%case%fluid%c_Xh, &
268
269 call neko_scratch_registry%relinquish_field(tmp_idx)
270 end subroutine curl_compute
271
272end 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_from_controllers(this, case, order, preprocess_controller, compute_controller, output_controller, field_names, computed_field, filename, precision)
Constructor from components, passing controllers.
subroutine curl_init_from_controllers_properties(this, 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_common(this, field_names, computed_field)
Common part of the constructors.
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:57
Defines a registry for storing solution fields.
type(field_registry_t), target, public neko_field_registry
Global field registry.
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:9
integer, parameter, public sp
Definition num_types.f90:8
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
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 and requesting temporary fields This can be used when you have a funct...
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
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.