Neko 1.99.3
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
field_writer.f90
Go to the documentation of this file.
1! Copyright (c) 2024-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!
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 case, only : case_t
46 use utils, only : neko_error
47 use logger, only : neko_log
48 implicit none
49 private
50
52 type, public, extends(simulation_component_t) :: field_writer_t
54 type(field_output_t), private :: output
55
56 ! Default values for optional parameters in the constructor.
57 character(len=20), private :: default_name = "field_writer"
58 character(len=20), private :: default_precision = "single"
59 character(len=20), private :: default_filename = ""
60 character(len=20), private :: default_format = "nek5000"
61 logical, private :: default_subdivide = .false.
62
63 contains
65 procedure, pass(this) :: init => field_writer_init_from_json
67 generic :: init_from_components => &
68 init_from_controllers, init_from_controllers_properties
70 procedure, pass(this) :: init_from_controllers => &
74 procedure, pass(this) :: init_from_controllers_properties => &
77 procedure, private, pass(this) :: init_common => field_writer_init_common
79 procedure, pass(this) :: free => field_writer_free
81 procedure, pass(this) :: compute_ => field_writer_compute
82 end type field_writer_t
83
84contains
85
89 subroutine field_writer_init_from_json(this, json, case)
90 class(field_writer_t), intent(inout), target :: this
91 type(json_file), intent(inout) :: json
92 class(case_t), intent(inout), target :: case
93 character(len=:), allocatable :: filename
94 character(len=:), allocatable :: name
95 character(len=:), allocatable :: precision
96 character(len=:), allocatable :: format
97 character(len=20), allocatable :: fields(:)
98 integer :: precision_value
99 logical :: subdivide
100
101 call this%init_base(json, case)
102 call json_get(json, "fields", fields)
103 call json_get_or_default(json, "name", name, this%default_name)
104 call json_get_or_default(json, "output_filename", filename, &
105 this%default_filename)
106 call json_get_or_default(json, "output_precision", precision, &
107 this%default_precision)
108 call json_get_or_default(json, "output_format", format, this%default_format)
109
110 if (precision .eq. "single") then
111 precision_value = sp
112 else if (precision .eq. "double") then
113 precision_value = dp
114 else
115 call neko_error("Invalid precision specified for field_writer: " &
116 // trim(precision))
117 end if
118
119 call json_get_or_default(json, "output_subdivide", subdivide, &
120 this%default_subdivide)
121
122 call this%init_common(name, fields, filename, precision_value, format, &
123 subdivide)
124 end subroutine field_writer_init_from_json
125
142 subroutine field_writer_init_from_controllers(this, name, case, order, &
143 preprocess_controller, compute_controller, output_controller, &
144 fields, filename, precision, format, subdivide)
145 class(field_writer_t), intent(inout) :: this
146 character(len=*), intent(in) :: name
147 class(case_t), intent(inout), target :: case
148 integer :: order
149 type(time_based_controller_t), intent(in) :: preprocess_controller
150 type(time_based_controller_t), intent(in) :: compute_controller
151 type(time_based_controller_t), intent(in) :: output_controller
152 character(len=20), intent(in) :: fields(:)
153 character(len=*), intent(in), optional :: filename
154 integer, intent(in), optional :: precision
155 character(len=20), intent(in), optional :: format
156 logical, intent(in), optional :: subdivide
157
158 call this%init_base_from_components(case, order, preprocess_controller, &
159 compute_controller, output_controller)
160 call this%init_common(name, fields, filename, precision, format, subdivide)
161
163
185 case, order, preprocess_control, preprocess_value, compute_control, &
186 compute_value, output_control, output_value, fields, filename, &
187 precision, format, subdivide)
188 class(field_writer_t), intent(inout) :: this
189 character(len=*), intent(in) :: name
190 class(case_t), intent(inout), target :: case
191 integer :: order
192 character(len=*), intent(in) :: preprocess_control
193 real(kind=rp), intent(in) :: preprocess_value
194 character(len=*), intent(in) :: compute_control
195 real(kind=rp), intent(in) :: compute_value
196 character(len=*), intent(in) :: output_control
197 real(kind=rp), intent(in) :: output_value
198 character(len=20), intent(in) :: fields(:)
199 character(len=*), intent(in), optional :: filename
200 integer, intent(in), optional :: precision
201 character(len=*), intent(in), optional :: format
202 logical, intent(in), optional :: subdivide
203
204 call this%init_base_from_components(case, order, preprocess_control, &
205 preprocess_value, compute_control, compute_value, output_control, &
206 output_value)
207 call this%init_common(name, fields, filename, precision, format, subdivide)
208
210
222 subroutine field_writer_init_common(this, name, fields, filename, precision, &
223 format, subdivide)
224 class(field_writer_t), intent(inout) :: this
225 character(len=*), intent(in) :: name
226 character(len=20), intent(in) :: fields(:)
227 character(len=*), intent(in), optional :: filename
228 integer, intent(in), optional :: precision
229 character(len=*), intent(in), optional :: format
230 logical, intent(in), optional :: subdivide
231 character(len=20) :: fieldi
232 logical :: filename_provided
233 character(len=120) :: message
234 integer :: i
235
236 this%name = name
237 ! Register fields if they don't exist.
238 do i = 1, size(fields)
239 fieldi = trim(fields(i))
240 call neko_registry%add_field(this%case%fluid%dm_Xh, fieldi, &
241 ignore_existing = .true.)
242 end do
243
244 filename_provided = .false.
245 if (present(filename)) then
246 if (len_trim(filename) .ne. 0) then
247 filename_provided = .true.
248 call this%output%init(trim(filename), size(fields), &
249 precision = precision, format = format)
250
251 if (present(subdivide)) then
252 call this%output%file_%set_subdivide(subdivide)
253 end if
254
255 do i = 1, size(fields)
256 fieldi = trim(fields(i))
257 call this%output%fields%assign(i, &
258 neko_registry%get_field(fieldi))
259 end do
260
261 call this%case%output_controller%add(this%output, &
262 this%output_controller%control_value, &
263 this%output_controller%control_mode)
264
265 end if
266 end if
267
268 if (.not. filename_provided) then
269 do i = 1, size(fields)
270 fieldi = trim(fields(i))
271 call this%case%f_out%fluid%append( &
272 neko_registry%get_field(fieldi))
273 end do
274 end if
275
276 end subroutine field_writer_init_common
277
279 subroutine field_writer_free(this)
280 class(field_writer_t), intent(inout) :: this
281 call this%free_base()
282 call this%output%free()
283 end subroutine field_writer_free
284
286 subroutine field_writer_compute(this, time)
287 class(field_writer_t), intent(inout) :: this
288 type(time_state_t), intent(in) :: time
289
290 end subroutine field_writer_compute
291
292end module field_writer
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 field_output_t.
Implements the field_writer_t type.
subroutine field_writer_compute(this, time)
Here to comply with the interface, does nothing.
subroutine field_writer_free(this)
Destructor.
subroutine field_writer_init_from_controllers(this, name, case, order, preprocess_controller, compute_controller, output_controller, fields, filename, precision, format, subdivide)
Constructor from components, passing controllers.
subroutine field_writer_init_from_json(this, json, case)
Constructor from json.
subroutine field_writer_init_common(this, name, fields, filename, precision, format, subdivide)
Common part of both constructors.
subroutine field_writer_init_from_controllers_properties(this, name, case, order, preprocess_control, preprocess_value, compute_control, compute_value, output_control, output_value, fields, filename, precision, format, subdivide)
Constructor from components, passing properties to the time_based_controllercomponents in the base ty...
Utilities for retrieving parameters from the case files.
Logging routines.
Definition log.f90:34
type(log_t), public neko_log
Global log stream.
Definition log.f90:79
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
Implements output_controller_t
Defines an output.
Definition output.f90:34
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
A simple output saving a list of fields to a file.
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.