Neko 1.99.7
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
derivative_simcomp.f90
Go to the documentation of this file.
1! Copyright (c) 2024-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
40 use time_state, only : time_state_t
41 use registry, only : neko_registry
42 use field, only : field_t
43 use operators, only : dudxyz
44 use case, only : case_t
49 implicit none
50 private
51
54 type, public, extends(simulation_component_t) :: derivative_t
56 type(field_t), pointer :: u
58 type(field_t), pointer :: du
60 real(kind=rp), pointer, contiguous :: dr(:,:,:,:)
62 real(kind=rp), pointer, contiguous :: ds(:,:,:,:)
64 real(kind=rp), pointer, contiguous :: dt(:,:,:,:)
66 type(field_writer_t) :: writer
67
68 contains
70 procedure, pass(this) :: init => derivative_init_from_json
72 generic :: init_from_components => &
73 init_from_controllers, init_from_controllers_properties
75 procedure, pass(this) :: init_from_controllers => &
79 procedure, pass(this) :: init_from_controllers_properties => &
82 procedure, private, pass(this) :: init_common => derivative_init_common
84 procedure, pass(this) :: free => derivative_free
86 procedure, pass(this) :: compute_ => derivative_compute
87 end type derivative_t
88
89contains
90
92 subroutine derivative_init_from_json(this, json, case)
93 class(derivative_t), intent(inout), target :: this
94 type(json_file), intent(inout) :: json
95 class(case_t), intent(inout), target :: case
96 character(len=:), allocatable :: field_name
97 character(len=:), allocatable :: direction
98 character(len=:), allocatable :: computed_field
99 character(len=:), allocatable :: name
100 character(len=NEKO_VARNAME_LEN) :: fields(1)
101
102 ! Add fields keyword to the json so that the field_writer_t picks it up.
103 ! Will also add fields to the registry.
104 call json_get_or_default(json, "name", name, "derivative")
105 call json_get(json, "field", field_name)
106 call json_get(json, "direction", direction)
107
108 call json_get_or_default(json, "computed_field", computed_field, &
109 "d" // trim(field_name) // "_d" // direction)
110
111 fields(1) = trim(computed_field)
112 call json%add("fields", fields)
113
114 call this%init_base(json, case)
115 call this%writer%init(json, case)
116
117 call this%init_common(name, field_name, computed_field, direction)
118 end subroutine derivative_init_from_json
119
125 subroutine derivative_init_common(this, name, field_name, computed_field, &
126 direction)
127 class(derivative_t), intent(inout) :: this
128 character(len=*) :: name
129 character(len=*) :: field_name
130 character(len=*) :: computed_field
131 character(len=*) :: direction
132
133 this%name = name
134 this%u => neko_registry%get_field_by_name(trim(field_name))
135
136 this%du => neko_registry%get_field_by_name(trim(computed_field))
137
138 if (direction .eq. "x") then
139 this%dr => this%case%fluid%c_Xh%drdx
140 this%ds => this%case%fluid%c_Xh%dsdx
141 this%dt => this%case%fluid%c_Xh%dtdx
142 else if (direction .eq. "y") then
143 this%dr => this%case%fluid%c_Xh%drdy
144 this%ds => this%case%fluid%c_Xh%dsdy
145 this%dt => this%case%fluid%c_Xh%dtdy
146 else if (direction .eq. "z") then
147 this%dr => this%case%fluid%c_Xh%drdz
148 this%ds => this%case%fluid%c_Xh%dsdz
149 this%dt => this%case%fluid%c_Xh%dtdz
150 else
151 call neko_error("The direction of the derivative must be x, y or z")
152 end if
153 end subroutine derivative_init_common
154
168 subroutine derivative_init_from_controllers(this, name, case, order, &
169 preprocess_controller, compute_controller, output_controller, &
170 field_name, computed_field, direction, filename, precision)
171 class(derivative_t), intent(inout) :: this
172 character(len=*), intent(in) :: name
173 class(case_t), intent(inout), target :: case
174 integer :: order
175 type(time_based_controller_t), intent(in) :: preprocess_controller
176 type(time_based_controller_t), intent(in) :: compute_controller
177 type(time_based_controller_t), intent(in) :: output_controller
178 character(len=*) :: field_name
179 character(len=*) :: computed_field
180 character(len=*) :: direction
181 character(len=*), intent(in), optional :: filename
182 integer, intent(in), optional :: precision
183
184 character(len=NEKO_VARNAME_LEN) :: fields(1)
185
186 fields(1) = trim(computed_field)
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(name, field_name, computed_field, direction)
194
196
216 case, order, preprocess_control, preprocess_value, compute_control, &
217 compute_value, output_control, output_value, field_name, &
218 computed_field, direction, filename, precision)
219 class(derivative_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=rp), intent(in) :: preprocess_value
225 character(len=*), intent(in) :: compute_control
226 real(kind=rp), intent(in) :: compute_value
227 character(len=*), intent(in) :: output_control
228 real(kind=rp), intent(in) :: output_value
229 character(len=*) :: field_name
230 character(len=*) :: computed_field
231 character(len=*) :: direction
232 character(len=*), intent(in), optional :: filename
233 integer, intent(in), optional :: precision
234
235 character(len=NEKO_VARNAME_LEN) :: fields(1)
236
237 fields(1) = trim(computed_field)
238
239 call this%init_base_from_components(case, order, preprocess_control, &
240 preprocess_value, compute_control, compute_value, output_control, &
241 output_value)
242 call this%writer%init_from_components("field_writer", case, order, &
243 preprocess_control, preprocess_value, compute_control, compute_value, &
244 output_control, output_value, fields, filename, precision)
245 call this%init_common(name, field_name, computed_field, direction)
246
248
249
251 subroutine derivative_free(this)
252 class(derivative_t), intent(inout) :: this
253 call this%free_base()
254 call this%writer%free()
255 nullify(this%du)
256 nullify(this%u)
257 nullify(this%dr)
258 nullify(this%ds)
259 nullify(this%dt)
260 end subroutine derivative_free
261
264 subroutine derivative_compute(this, time)
265 class(derivative_t), intent(inout) :: this
266 type(time_state_t), intent(in) :: time
267
268 call dudxyz(this%du%x, this%u%x, this%dr, this%ds, this%dt,&
269 this%case%fluid%c_Xh)
270 end subroutine derivative_compute
271
272end module derivative_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.
Compute derivative of a scalar field along a single direction.
Definition operators.f90:78
Defines a simulation case.
Definition case.f90:34
Implements the derivative_t type.
subroutine derivative_free(this)
Destructor.
subroutine derivative_init_common(this, name, field_name, computed_field, direction)
Common part of constructors from components.
subroutine derivative_compute(this, time)
Compute the derivative field.
subroutine derivative_init_from_json(this, json, case)
Constructor from json.
subroutine derivative_init_from_controllers(this, name, case, order, preprocess_controller, compute_controller, output_controller, field_name, computed_field, direction, filename, precision)
Constructor from components, passing controllers.
subroutine derivative_init_from_controllers_properties(this, name, case, order, preprocess_control, preprocess_value, compute_control, compute_value, output_control, output_value, field_name, computed_field, direction, filename, precision)
Constructor from components, passing properties to the time_based_controller` components in the base ...
Implements the field_writer_t type.
Defines a field.
Definition field.f90:34
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
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:144
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 a derivative of a field. Wraps the duxyz operator.
A simulation component that writes a 3d field to a 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.