Loading [MathJax]/extensions/tex2jax.js
Neko 0.9.99
A portable framework for high-order spectral element flow simulations
All Classes Namespaces Files Functions Variables Typedefs Enumerator Macros Pages
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
60 procedure, pass(this) :: init_from_controllers => &
64 procedure, pass(this) :: init_from_controllers_properties => &
67 procedure, private, pass(this) :: init_common => field_writer_init_common
69 procedure, pass(this) :: free => field_writer_free
71 procedure, pass(this) :: compute_ => field_writer_compute
72 end type field_writer_t
73
74contains
75
79 subroutine field_writer_init_from_json(this, json, case)
80 class(field_writer_t), intent(inout) :: this
81 type(json_file), intent(inout) :: json
82 class(case_t), intent(inout), target :: case
83 character(len=:), allocatable :: filename
84 character(len=:), allocatable :: precision
85 character(len=20), allocatable :: fields(:)
86
87 call this%init_base(json, case)
88 call json_get(json, "fields", fields)
89
90 if (json%valid_path("output_filename")) then
91 call json_get(json, "output_filename", filename)
92 if (json%valid_path("output_precision")) then
93 call json_get(json, "output_precision", precision)
94 if (precision == "double") then
95 call this%init_common(fields, filename, dp)
96 else
97 call this%init_common(fields, filename, sp)
98 end if
99 else
100 call this%init_common(fields, filename)
101 end if
102 else
103 call this%init_common(fields)
104 end if
105 end subroutine field_writer_init_from_json
106
118 subroutine field_writer_init_from_controllers(this, case, order, &
119 preprocess_controller, compute_controller, output_controller, &
120 fields, filename, precision)
121 class(field_writer_t), intent(inout) :: this
122 class(case_t), intent(inout), target :: case
123 integer :: order
124 type(time_based_controller_t), intent(in) :: preprocess_controller
125 type(time_based_controller_t), intent(in) :: compute_controller
126 type(time_based_controller_t), intent(in) :: output_controller
127 character(len=20), intent(in) :: fields(:)
128 character(len=*), intent(in), optional :: filename
129 integer, intent(in), optional :: precision
130
131 call this%init_base_from_components(case, order, preprocess_controller, &
132 compute_controller, output_controller)
133 call this%init_common(fields, filename, precision)
134
136
153 case, order, preprocess_control, preprocess_value, compute_control, &
154 compute_value, output_control, output_value, fields, filename, precision)
155 class(field_writer_t), intent(inout) :: this
156 class(case_t), intent(inout), target :: case
157 integer :: order
158 character(len=*), intent(in) :: preprocess_control
159 real(kind=rp), intent(in) :: preprocess_value
160 character(len=*), intent(in) :: compute_control
161 real(kind=rp), intent(in) :: compute_value
162 character(len=*), intent(in) :: output_control
163 real(kind=rp), intent(in) :: output_value
164 character(len=20), intent(in) :: fields(:)
165 character(len=*), intent(in), optional :: filename
166 integer, intent(in), optional :: precision
167
168 call this%init_base_from_components(case, order, preprocess_control, &
169 preprocess_value, compute_control, compute_value, output_control, &
170 output_value)
171 call this%init_common(fields, filename, precision)
172
174
181 subroutine field_writer_init_common(this, fields, filename, precision)
182 class(field_writer_t), intent(inout) :: this
183 character(len=20), intent(in) :: fields(:)
184 character(len=*), intent(in), optional :: filename
185 integer, intent(in), optional :: precision
186 character(len=20) :: fieldi
187 integer :: i
188
189 ! Regsiter fields if they don't exist.
190 do i = 1, size(fields)
191 fieldi = trim(fields(i))
192 call neko_field_registry%add_field(this%case%fluid%dm_Xh, fieldi,&
193 ignore_existing = .true.)
194 end do
195
196 if (present(filename)) then
197 if (present(precision)) then
198 call this%output%init(precision, filename, size(fields))
199 else
200 call this%output%init(sp, filename, size(fields))
201 end if
202 do i = 1, size(fields)
203 fieldi = trim(fields(i))
204 call this%output%fields%assign(i, &
205 neko_field_registry%get_field(fieldi))
206 end do
207
208 call this%case%output_controller%add(this%output, &
209 this%output_controller%control_value, &
210 this%output_controller%control_mode)
211 else
212 do i = 1, size(fields)
213 fieldi = trim(fields(i))
214 call this%case%f_out%fluid%append( &
215 neko_field_registry%get_field(fieldi))
216 end do
217 end if
218
219 end subroutine field_writer_init_common
220
222 subroutine field_writer_free(this)
223 class(field_writer_t), intent(inout) :: this
224 call this%free_base()
225 end subroutine field_writer_free
226
228 subroutine field_writer_compute(this, time)
229 class(field_writer_t), intent(inout) :: this
230 type(time_state_t), intent(in) :: time
231
232 end subroutine field_writer_compute
233
234end 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.