Neko 1.99.1
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
user_stats.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
41 use field, only : field_t
42 use case, only : case_t
45 use mean_field, only : mean_field_t
46 use coefs, only : coef_t
47 use time_state, only : time_state_t
49 implicit none
50 private
51
53 type, public, extends(simulation_component_t) :: user_stats_t
54
56 real(kind=rp) :: start_time
58 real(kind=rp) :: time
60 type(mean_field_t), allocatable :: mean_fields(:)
62 integer :: n_avg_fields = 0
64 character(len=20), allocatable :: field_names(:)
66 type(mean_field_output_t), private :: output
67
68 contains
70 procedure, pass(this) :: init => user_stats_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 => user_stats_init_common
84 procedure, pass(this) :: free => user_stats_free
86 procedure, pass(this) :: compute_ => user_stats_compute
87 procedure, pass(this) :: restart_ => user_stats_restart
88 end type user_stats_t
89
90contains
91
95 subroutine user_stats_init_from_json(this, json, case)
96 class(user_stats_t), intent(inout), target :: this
97 type(json_file), intent(inout) :: json
98 class(case_t), intent(inout), target :: case
99 character(len=:), allocatable :: filename
100 character(len=:), allocatable :: avg_dir
101
102 call this%init_base(json, case)
103
105 call json%info('fields', n_children = this%n_avg_fields)
106 call json_get(json, 'fields', this%field_names)
107 call json_get_or_default(json, 'start_time', this%start_time, 0.0_rp)
108 call json_get_or_default(json, 'avg_direction', avg_dir, 'none')
109 call json_get_or_default(json, 'output_file', filename, 'user_stats')
110
111 call user_stats_init_common(this, this%start_time, &
112 case%fluid%c_Xh, avg_dir, filename = filename)
113 end subroutine user_stats_init_from_json
114
115 subroutine user_stats_restart(this, time)
116 class(user_stats_t), intent(inout) :: this
117 type(time_state_t), intent(in) :: time
118
119 if (time%t .gt. this%time) this%time = time%t
120 end subroutine user_stats_restart
121
134 subroutine user_stats_init_from_controllers(this, case, order, &
135 preprocess_controller, compute_controller, output_controller, &
136 start_time, coef, avg_dir, filename, precision)
137 class(user_stats_t), intent(inout) :: this
138 class(case_t), intent(inout), target :: case
139 integer :: order
140 type(time_based_controller_t), intent(in) :: preprocess_controller
141 type(time_based_controller_t), intent(in) :: compute_controller
142 type(time_based_controller_t), intent(in) :: output_controller
143 real(kind=rp), intent(in) :: start_time
144 character(len=*), intent(in) :: avg_dir
145 type(coef_t), intent(inout) :: coef
146 character(len=*), intent(in), optional :: filename
147 integer, intent(in), optional :: precision
148
149 call this%init_base_from_components(case, order, preprocess_controller, &
150 compute_controller, output_controller)
151 call this%init_common(start_time, coef, avg_dir, filename, precision)
152
154
173 case, order, preprocess_control, preprocess_value, compute_control, &
174 compute_value, output_control, output_value, start_time, coef, avg_dir, &
175 filename, precision)
176 class(user_stats_t), intent(inout) :: this
177 class(case_t), intent(inout), target :: case
178 integer :: order
179 character(len=*), intent(in) :: preprocess_control
180 real(kind=rp), intent(in) :: preprocess_value
181 character(len=*), intent(in) :: compute_control
182 real(kind=rp), intent(in) :: compute_value
183 character(len=*), intent(in) :: output_control
184 real(kind=rp), intent(in) :: output_value
185 real(kind=rp), intent(in) :: start_time
186 character(len=*), intent(in) :: avg_dir
187 type(coef_t), intent(inout) :: coef
188 character(len=*), intent(in), optional :: filename
189 integer, intent(in), optional :: precision
190
191 call this%init_base_from_components(case, order, preprocess_control, &
192 preprocess_value, compute_control, compute_value, output_control, &
193 output_value)
194 call this%init_common(start_time, coef, avg_dir, filename, precision)
195
197
198
203 subroutine user_stats_init_common(this, start_time, coef, avg_dir, &
204 filename, precision)
205 class(user_stats_t), intent(inout) :: this
206 character(len=*), intent(in) :: filename
207 integer, intent(in), optional :: precision
208 real(kind=rp), intent(in) :: start_time
209 character(len=*), intent(in) :: avg_dir
210 type(coef_t), intent(inout) :: coef
211 integer :: i
212 type(field_t), pointer :: field_to_avg
213
214 this%start_time = start_time
215 this%time = start_time
216
218 allocate(this%mean_fields(this%n_avg_fields))
219 do i = 1, this%n_avg_fields
220 field_to_avg => neko_field_registry%get_field(trim(this%field_names(i)))
221 call this%mean_fields(i)%init(field_to_avg)
222 end do
223
224 call this%output%init(this%mean_fields, this%n_avg_fields, &
225 this%start_time, coef, avg_dir, name=filename)
226 call this%case%output_controller%add(this%output, &
227 this%output_controller%control_value, &
228 this%output_controller%control_mode)
229 end subroutine user_stats_init_common
230
232 subroutine user_stats_free(this)
233 class(user_stats_t), intent(inout) :: this
234 integer :: i
235
236 call this%free_base()
237
238 if (allocated(this%mean_fields)) then
239 do i = 1, this%n_avg_fields
240 call this%mean_fields(i)%free()
241 end do
242 deallocate(this%mean_fields)
243 end if
244
245 if (allocated(this%field_names)) then
246 deallocate(this%field_names)
247 end if
248
249 end subroutine user_stats_free
250
253 subroutine user_stats_compute(this, time)
254 class(user_stats_t), intent(inout) :: this
255 type(time_state_t), intent(in) :: time
256 integer :: i
257
259 if (time%t .ge. this%start_time) then
260 do i = 1, this%n_avg_fields
261 call this%mean_fields(i)%update(time%t - this%time)
262 end do
263 this%time = time%t
264 end if
265
266 end subroutine user_stats_compute
267
268end module user_stats
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
Coefficients.
Definition coef.f90:34
Defines a registry for storing solution fields.
type(field_registry_t), target, public neko_field_registry
Global field registry.
Defines a field.
Definition field.f90:34
Utilities for retrieving parameters from the case files.
Defines an output for a list of mean fields.
Implements mean_field_t.
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 restart_(this, time)
Dummy restart function.
subroutine compute_(this, time)
Dummy compute function.
Contains the time_based_controller_t type.
Module with things related to the simulation time.
Implements the user_stats_t type.
subroutine user_stats_free(this)
Destructor.
subroutine user_stats_compute(this, time)
Update the running averages.
subroutine user_stats_restart(this, time)
subroutine user_stats_init_from_controllers_properties(this, case, order, preprocess_control, preprocess_value, compute_control, compute_value, output_control, output_value, start_time, coef, avg_dir, filename, precision)
Constructor from components, passing properties to the time_based_controller` components in the base ...
subroutine user_stats_init_from_json(this, json, case)
Constructor from json.
subroutine user_stats_init_from_controllers(this, case, order, preprocess_controller, compute_controller, output_controller, start_time, coef, avg_dir, filename, precision)
Constructor from components, passing controllers.
subroutine user_stats_init_common(this, start_time, coef, avg_dir, filename, precision)
Common part of constructors.
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:55
Computes the temporal mean of a field.
Output for a list of mean fields.
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.
A simulation component that computes the averages of fields in the registry.