Neko 1.99.3
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
fluid_stats_simcomp.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!
36 use num_types, only : rp, dp, sp
37 use json_module, only : json_file
39 use registry, only : neko_registry
40 use time_state, only : time_state_t
41 use field, only : field_t
42 use fluid_stats, only : fluid_stats_t
44 use case, only : case_t
45 use coefs, only : coef_t
47 use logger, only : log_size, neko_log
49 use comm, only : neko_comm
50 use mpi_f08, only : mpi_wtime, mpi_barrier
51 implicit none
52 private
53
68 type(fluid_stats_output_t) :: stats_output
70 real(kind=rp) :: start_time
71 real(kind=rp) :: time
72 logical :: default_fname = .true.
73
74 contains
76 procedure, pass(this) :: init => fluid_stats_simcomp_init_from_json
78 procedure, pass(this) :: init_from_components => &
81 procedure, pass(this) :: free => fluid_stats_simcomp_free
83 procedure, pass(this) :: compute_ => fluid_stats_simcomp_compute
85 procedure, pass(this) :: output_ => fluid_stats_simcomp_compute
87 procedure, pass(this) :: restart_ => fluid_stats_simcomp_restart
89
90contains
91
95 subroutine fluid_stats_simcomp_init_from_json(this, json, case)
96 class(fluid_stats_simcomp_t), target, intent(inout) :: this
97 type(json_file), intent(inout) :: json
98 class(case_t), intent(inout), target :: case
99 character(len=:), allocatable :: filename
100 character(len=20), allocatable :: fields(:)
101 character(len=:), allocatable :: hom_dir
102 character(len=:), allocatable :: stat_set
103 character(len=:), allocatable :: name
104 real(kind=rp) :: start_time
105 type(field_t), pointer :: u, v, w, p
106 type(coef_t), pointer :: coef
107
108 call json_get_or_default(json, "name", name, "fluid_stats")
109 call this%init_base(json, case)
110 call json_get_or_default(json, 'avg_direction', &
111 hom_dir, 'none')
112 call json_get_or_default(json, 'start_time', &
113 start_time, 0.0_rp)
114 call json_get_or_default(json, 'set_of_stats', &
115 stat_set, 'full')
116
117
118 u => neko_registry%get_field("u")
119 v => neko_registry%get_field("v")
120 w => neko_registry%get_field("w")
121 p => neko_registry%get_field("p")
122 coef => case%fluid%c_Xh
123 this%name = name
124
125 if (json%valid_path("output_filename")) then
126 call json_get(json, "output_filename", filename)
127 call fluid_stats_simcomp_init_from_components(this, name, u, v, w, p, &
128 coef, start_time, hom_dir, stat_set, filename)
129 else
130 call fluid_stats_simcomp_init_from_components(this, name, u, v, w, p, &
131 coef, start_time, hom_dir, stat_set)
132 end if
133
135
146 subroutine fluid_stats_simcomp_init_from_components(this, name, u, v, w, p, &
147 coef, start_time, hom_dir, stat_set, fname)
148 class(fluid_stats_simcomp_t), target, intent(inout) :: this
149 character(len=*), intent(in) :: name
150 character(len=*), intent(in) :: hom_dir
151 character(len=*), intent(in) :: stat_set
152 real(kind=rp), intent(in) :: start_time
153 type(field_t), intent(in), target :: u, v, w, p
154 type(coef_t), intent(in), target :: coef
155 character(len=*), intent(in), optional :: fname
156 character(len=NEKO_FNAME_LEN) :: stats_fname
157 character(len=LOG_SIZE) :: log_buf
158 character(len=5) :: prefix
159
160 call neko_log%section('Fluid stats')
161 write(log_buf, '(A,E15.7)') 'Start time: ', start_time
162 call neko_log%message(log_buf)
163 write(log_buf, '(A,A)') 'Set of statistics: ', trim(stat_set)
164 call neko_log%message(log_buf)
165 write(log_buf, '(A,A)') 'Averaging in direction: ', trim(hom_dir)
166 call neko_log%message(log_buf)
167
168 call this%stats%init(coef, u, v, w, p, stat_set, name)
169
170 this%name = name
171 this%start_time = start_time
172 this%time = start_time
173 if (present(fname)) then
174 this%default_fname = .false.
175 stats_fname = fname
176 else
177 stats_fname = "fluid_stats0"
178 this%default_fname = .true.
179 end if
180
181 call this%stats_output%init(this%stats, this%start_time, &
182 hom_dir = hom_dir, name = stats_fname, &
183 path = this%case%output_directory)
184
185 call this%case%output_controller%add(this%stats_output, &
186 this%output_controller%control_value, &
187 this%output_controller%control_mode)
188
189 call neko_log%end_section()
190
192
195 class(fluid_stats_simcomp_t), intent(inout) :: this
196 call this%free_base()
197 call this%stats%free()
198 call this%stats_output%free()
199 end subroutine fluid_stats_simcomp_free
200
201 subroutine fluid_stats_simcomp_restart(this, time)
202 class(fluid_stats_simcomp_t), intent(inout) :: this
203 type(time_state_t), intent(in) :: time
204 character(len=NEKO_FNAME_LEN) :: fname
205 character(len=5) :: prefix, suffix
206 integer :: last_slash_pos
207 real(kind=rp) :: t
208 t = time%t
209 if (t .gt. this%time) this%time = t
210 if (this%default_fname) then
211 fname = this%stats_output%file_%get_base_fname()
212 write (prefix, '(I5)') this%stats_output%file_%get_counter()
213 call filename_suffix(fname, suffix)
214 last_slash_pos = &
216 if (last_slash_pos .ne. 0) then
217 fname = &
218 trim(fname(1:last_slash_pos))// &
219 "fluid_stats"//trim(adjustl(prefix))//"."//suffix
220 else
221 fname = "fluid_stats"// &
222 trim(adjustl(prefix))//"."//suffix
223 end if
224 call this%stats_output%init_base(fname)
225 end if
226 end subroutine fluid_stats_simcomp_restart
227
230 subroutine fluid_stats_simcomp_compute(this, time)
231 class(fluid_stats_simcomp_t), intent(inout) :: this
232 type(time_state_t), intent(in) :: time
233 real(kind=rp) :: delta_t, t
234 real(kind=rp) :: sample_start_time, sample_time
235 character(len=LOG_SIZE) :: log_buf
236 integer :: ierr
237
238 if (time%start_time .gt. this%start_time) then
239 write(log_buf, '(A)') 'Simulation start time is later than the ' &
240 // 'fluid stats start time.'
241 call neko_log%warning(log_buf)
242 write(log_buf, '(A,E15.7)') 'Simulation start time:', time%start_time
243 call neko_log%warning(log_buf)
244 write(log_buf, '(A,E15.7)') 'Fluid stats start time:', this%start_time
245 call neko_log%warning(log_buf)
246 write(log_buf, '(A)') 'Assigning the statistics start time to ' &
247 // 'the simulation start time.'
248 call neko_log%warning(log_buf)
249 this%start_time = time%start_time
250 this%time = time%start_time
251 end if
252
253 t = time%t
254
255 if (t .ge. this%start_time) then
256 delta_t = t - this%time !This is only a real number
257
258 call mpi_barrier(neko_comm, ierr)
259
260 sample_start_time = mpi_wtime()
261
262 call this%stats%update(delta_t)
263 call mpi_barrier(neko_comm, ierr)
264 this%time = t
265
266 sample_time = mpi_wtime() - sample_start_time
267
268 call neko_log%section('Fluid stats')
269 write(log_buf, '(A,E15.7)') 'Sampling at time:', t
270 call neko_log%message(log_buf)
271 write(log_buf, '(A33,E15.7)') 'Simulationtime since last sample:', &
272 delta_t
273 call neko_log%message(log_buf)
274 write(log_buf, '(A,E15.7)') 'Sampling time (s):', sample_time
275 call neko_log%message(log_buf)
276 call neko_log%end_section()
277 end if
278
279 end subroutine fluid_stats_simcomp_compute
280
281end module fluid_stats_simcomp
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
Definition comm.F90:1
type(mpi_comm), public neko_comm
MPI communicator.
Definition comm.F90:43
Defines a field.
Definition field.f90:34
Implements fluid_stats_ouput_t.
Implements the fluid_stats_simcomp_t type.
subroutine fluid_stats_simcomp_free(this)
Destructor.
subroutine fluid_stats_simcomp_restart(this, time)
subroutine fluid_stats_simcomp_init_from_json(this, json, case)
Constructor from json.
subroutine fluid_stats_simcomp_compute(this, time)
fluid_stats, called depending on compute_control and compute_value
subroutine fluid_stats_simcomp_init_from_components(this, name, u, v, w, p, coef, start_time, hom_dir, stat_set, fname)
Actual constructor.
Computes various statistics for the fluid fields. We use the Reynolds decomposition for a field u = ...
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 log_size
Definition log.f90:45
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
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 restart_(this, time)
Dummy restart function.
subroutine compute_(this, time)
Dummy compute function.
Defines a container for all statistics.
Module with things related to the simulation time.
Utilities.
Definition utils.f90:35
integer, parameter, public neko_fname_len
Definition utils.f90:40
subroutine, public filename_suffix(fname, suffix)
Extract a filename's suffix.
Definition utils.f90:108
pure integer function, public filename_tslash_pos(fname)
Find position (in the string) of a filename's trailing slash.
Definition utils.f90:65
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:58
Defines an output for the fluid statistics computed using the fluid_stats_t object.
A simulation component that computes the velocity and pressure statistics up to 4th order....
Base abstract class for simulation components.
A struct that contains all info about the time, expand as needed.