Neko 1.99.1
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
42 use case, only : case_t
44 use json_utils, only : json_get
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 :: precision
86 character(len=20), allocatable :: fields(:)
87
88 call this%init_base(json, case)
89 call json_get(json, "fields", fields)
90
91 if (json%valid_path("output_filename")) then
92 call json_get(json, "output_filename", filename)
93 if (json%valid_path("output_precision")) then
94 call json_get(json, "output_precision", precision)
95 if (precision == "double") then
96 call this%init_common(fields, filename, dp)
97 else
98 call this%init_common(fields, filename, sp)
99 end if
100 else
101 call this%init_common(fields, filename)
102 end if
103 else
104 call this%init_common(fields)
105 end if
106 end subroutine field_writer_init_from_json
107
119 subroutine field_writer_init_from_controllers(this, case, order, &
120 preprocess_controller, compute_controller, output_controller, &
121 fields, filename, precision)
122 class(field_writer_t), intent(inout) :: this
123 class(case_t), intent(inout), target :: case
124 integer :: order
125 type(time_based_controller_t), intent(in) :: preprocess_controller
126 type(time_based_controller_t), intent(in) :: compute_controller
127 type(time_based_controller_t), intent(in) :: output_controller
128 character(len=20), intent(in) :: fields(:)
129 character(len=*), intent(in), optional :: filename
130 integer, intent(in), optional :: precision
131
132 call this%init_base_from_components(case, order, preprocess_controller, &
133 compute_controller, output_controller)
134 call this%init_common(fields, filename, precision)
135
137
154 case, order, preprocess_control, preprocess_value, compute_control, &
155 compute_value, output_control, output_value, fields, filename, precision)
156 class(field_writer_t), intent(inout) :: this
157 class(case_t), intent(inout), target :: case
158 integer :: order
159 character(len=*), intent(in) :: preprocess_control
160 real(kind=rp), intent(in) :: preprocess_value
161 character(len=*), intent(in) :: compute_control
162 real(kind=rp), intent(in) :: compute_value
163 character(len=*), intent(in) :: output_control
164 real(kind=rp), intent(in) :: output_value
165 character(len=20), intent(in) :: fields(:)
166 character(len=*), intent(in), optional :: filename
167 integer, intent(in), optional :: precision
168
169 call this%init_base_from_components(case, order, preprocess_control, &
170 preprocess_value, compute_control, compute_value, output_control, &
171 output_value)
172 call this%init_common(fields, filename, precision)
173
175
182 subroutine field_writer_init_common(this, fields, filename, precision)
183 class(field_writer_t), intent(inout) :: this
184 character(len=20), intent(in) :: fields(:)
185 character(len=*), intent(in), optional :: filename
186 integer, intent(in), optional :: precision
187 character(len=20) :: fieldi
188 integer :: i
189
190 ! Regsiter fields if they don't exist.
191 do i = 1, size(fields)
192 fieldi = trim(fields(i))
193 call neko_field_registry%add_field(this%case%fluid%dm_Xh, fieldi,&
194 ignore_existing = .true.)
195 end do
196
197 if (present(filename)) then
198 if (present(precision)) then
199 call this%output%init(precision, filename, size(fields))
200 else
201 call this%output%init(sp, filename, size(fields))
202 end if
203 do i = 1, size(fields)
204 fieldi = trim(fields(i))
205 call this%output%fields%assign(i, &
206 neko_field_registry%get_field(fieldi))
207 end do
208
209 call this%case%output_controller%add(this%output, &
210 this%output_controller%control_value, &
211 this%output_controller%control_mode)
212 else
213 do i = 1, size(fields)
214 fieldi = trim(fields(i))
215 call this%case%f_out%fluid%append( &
216 neko_field_registry%get_field(fieldi))
217 end do
218 end if
219
220 end subroutine field_writer_init_common
221
223 subroutine field_writer_free(this)
224 class(field_writer_t), intent(inout) :: this
225 call this%free_base()
226 end subroutine field_writer_free
227
229 subroutine field_writer_compute(this, time)
230 class(field_writer_t), intent(inout) :: this
231 type(time_state_t), intent(in) :: time
232
233 end subroutine field_writer_compute
234
235end module field_writer
Retrieves a parameter by name or throws an error.
Defines a simulation case.
Definition case.f90:34
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.
subroutine field_writer_compute(this, time)
Here to comply with the interface, does nothing.
subroutine field_writer_init_from_controllers(this, case, order, preprocess_controller, compute_controller, output_controller, fields, filename, precision)
Constructor from components, passing controllers.
subroutine field_writer_free(this)
Destructor.
subroutine field_writer_init_common(this, fields, filename, precision)
Common part of both constructors.
subroutine field_writer_init_from_json(this, json, case)
Constructor from json.
subroutine field_writer_init_from_controllers_properties(this, 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 ...
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
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.