Neko 1.99.2
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, 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 implicit none
47 private
48
50 type, public, extends(simulation_component_t) :: field_writer_t
52 type(fld_file_output_t), private :: output
53
54 contains
56 procedure, pass(this) :: init => field_writer_init_from_json
58 generic :: init_from_components => &
59 init_from_controllers, init_from_controllers_properties
61 procedure, pass(this) :: init_from_controllers => &
65 procedure, pass(this) :: init_from_controllers_properties => &
68 procedure, private, pass(this) :: init_common => field_writer_init_common
70 procedure, pass(this) :: free => field_writer_free
72 procedure, pass(this) :: compute_ => field_writer_compute
73 end type field_writer_t
74
75contains
76
80 subroutine field_writer_init_from_json(this, json, case)
81 class(field_writer_t), intent(inout), target :: this
82 type(json_file), intent(inout) :: json
83 class(case_t), intent(inout), target :: case
84 character(len=:), allocatable :: filename
85 character(len=:), allocatable :: name
86 character(len=:), allocatable :: precision
87 character(len=20), allocatable :: fields(:)
88
89 call this%init_base(json, case)
90 call json_get(json, "fields", fields)
91 call json_get_or_default(json, "name", name, "field_writer")
92
93 if (json%valid_path("output_filename")) then
94 call json_get(json, "output_filename", filename)
95 if (json%valid_path("output_precision")) then
96 call json_get(json, "output_precision", precision)
97 if (precision == "double") then
98 call this%init_common(name, fields, filename, dp)
99 else
100 call this%init_common(name, fields, filename, sp)
101 end if
102 else
103 call this%init_common(name, fields, filename)
104 end if
105 else
106 call this%init_common(name, fields)
107 end if
108 end subroutine field_writer_init_from_json
109
122 subroutine field_writer_init_from_controllers(this, name, case, order, &
123 preprocess_controller, compute_controller, output_controller, &
124 fields, filename, precision)
125 class(field_writer_t), intent(inout) :: this
126 character(len=*), intent(in) :: name
127 class(case_t), intent(inout), target :: case
128 integer :: order
129 type(time_based_controller_t), intent(in) :: preprocess_controller
130 type(time_based_controller_t), intent(in) :: compute_controller
131 type(time_based_controller_t), intent(in) :: output_controller
132 character(len=20), intent(in) :: fields(:)
133 character(len=*), intent(in), optional :: filename
134 integer, intent(in), optional :: precision
135
136 call this%init_base_from_components(case, order, preprocess_controller, &
137 compute_controller, output_controller)
138 call this%init_common(name, fields, filename, precision)
139
141
159 case, order, preprocess_control, preprocess_value, compute_control, &
160 compute_value, output_control, output_value, fields, filename, precision)
161 class(field_writer_t), intent(inout) :: this
162 character(len=*), intent(in) :: name
163 class(case_t), intent(inout), target :: case
164 integer :: order
165 character(len=*), intent(in) :: preprocess_control
166 real(kind=rp), intent(in) :: preprocess_value
167 character(len=*), intent(in) :: compute_control
168 real(kind=rp), intent(in) :: compute_value
169 character(len=*), intent(in) :: output_control
170 real(kind=rp), intent(in) :: output_value
171 character(len=20), intent(in) :: fields(:)
172 character(len=*), intent(in), optional :: filename
173 integer, intent(in), optional :: precision
174
175 call this%init_base_from_components(case, order, preprocess_control, &
176 preprocess_value, compute_control, compute_value, output_control, &
177 output_value)
178 call this%init_common(name, fields, filename, precision)
179
181
189 subroutine field_writer_init_common(this, name, fields, filename, precision)
190 class(field_writer_t), intent(inout) :: this
191 character(len=*), intent(in) :: name
192 character(len=20), intent(in) :: fields(:)
193 character(len=*), intent(in), optional :: filename
194 integer, intent(in), optional :: precision
195 character(len=20) :: fieldi
196 integer :: i
197
198 this%name = name
199 ! Regsiter fields if they don't exist.
200 do i = 1, size(fields)
201 fieldi = trim(fields(i))
202 call neko_registry%add_field(this%case%fluid%dm_Xh, fieldi,&
203 ignore_existing = .true.)
204 end do
205
206 if (present(filename)) then
207 if (present(precision)) then
208 call this%output%init(precision, filename, size(fields))
209 else
210 call this%output%init(sp, filename, size(fields))
211 end if
212 do i = 1, size(fields)
213 fieldi = trim(fields(i))
214 call this%output%fields%assign(i, &
215 neko_registry%get_field(fieldi))
216 end do
217
218 call this%case%output_controller%add(this%output, &
219 this%output_controller%control_value, &
220 this%output_controller%control_mode)
221 else
222 do i = 1, size(fields)
223 fieldi = trim(fields(i))
224 call this%case%f_out%fluid%append( &
225 neko_registry%get_field(fieldi))
226 end do
227 end if
228
229 end subroutine field_writer_init_common
230
232 subroutine field_writer_free(this)
233 class(field_writer_t), intent(inout) :: this
234 call this%free_base()
235 end subroutine field_writer_free
236
238 subroutine field_writer_compute(this, time)
239 class(field_writer_t), intent(inout) :: this
240 type(time_state_t), intent(in) :: time
241
242 end subroutine field_writer_compute
243
244end 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 the field_writer_t type.
subroutine field_writer_init_from_controllers(this, name, case, order, preprocess_controller, compute_controller, output_controller, fields, filename, precision)
Constructor from components, passing controllers.
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)
Constructor from components, passing properties to the time_based_controller` components in the base ...
subroutine field_writer_compute(this, time)
Here to comply with the interface, does nothing.
subroutine field_writer_free(this)
Destructor.
subroutine field_writer_init_common(this, name, fields, filename, precision)
Common part of both constructors.
subroutine field_writer_init_from_json(this, json, case)
Constructor from json.
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
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:149
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.
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.