Neko 1.99.3
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
fluid_sgs_stats_simcomp.f90
Go to the documentation of this file.
1! Copyright (c) 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
44 use case, only : case_t
45 use coefs, only : coef_t
47 use logger, only : log_size, neko_log
50 use comm, only : neko_comm
51 use mpi_f08, only : mpi_wtime, mpi_barrier
52 implicit none
53 private
54
63 type(fluid_sgs_stats_output_t) :: stats_output
65 real(kind=rp) :: start_time
66 real(kind=rp) :: time
67 logical :: default_fname = .true.
68
69 contains
71 procedure, pass(this) :: init => fluid_sgs_stats_simcomp_init_from_json
73 procedure, pass(this) :: init_from_components => &
76 procedure, pass(this) :: free => fluid_sgs_stats_simcomp_free
78 procedure, pass(this) :: compute_ => fluid_sgs_stats_simcomp_compute
80 procedure, pass(this) :: output_ => fluid_sgs_stats_simcomp_compute
82 procedure, pass(this) :: restart_ => fluid_sgs_stats_simcomp_restart
84
85contains
86
90 subroutine fluid_sgs_stats_simcomp_init_from_json(this, json, case)
91 class(fluid_sgs_stats_simcomp_t), target, intent(inout) :: this
92 type(json_file), intent(inout) :: json
93 class(case_t), intent(inout), target :: case
94 character(len=:), allocatable :: filename
95 character(len=20), allocatable :: fields(:)
96 character(len=:), allocatable :: hom_dir
97 character(len=:), allocatable :: nut_field
98 character(len=:), allocatable :: name
99 real(kind=rp) :: start_time
100 type(field_t), pointer :: u, v, w
101 type(coef_t), pointer :: coef
102
103 call json_get_or_default(json, "name", name, "fluid_sgs_stats")
104 call this%init_base(json, case)
105 call json_get_or_default(json, 'avg_direction', &
106 hom_dir, 'none')
107 call json_get_or_lookup_or_default(json, 'start_time', &
108 start_time, 0.0_rp)
109 call json_get_or_default(json, 'nut_field', &
110 nut_field, 'nut')
111
112
113 u => neko_registry%get_field("u")
114 v => neko_registry%get_field("v")
115 w => neko_registry%get_field("w")
116 coef => case%fluid%c_Xh
117 this%name = name
118
119 if (json%valid_path("output_filename")) then
120 call json_get(json, "output_filename", filename)
121 call fluid_sgs_stats_simcomp_init_from_components(this, u, v, w, coef, &
122 start_time, hom_dir, nut_field, filename)
123 else
124 call fluid_sgs_stats_simcomp_init_from_components(this, u, v, w, coef, &
125 start_time, hom_dir, nut_field)
126 end if
127
129
139 subroutine fluid_sgs_stats_simcomp_init_from_components(this, u, v, w, coef, &
140 start_time, hom_dir, nut_field, fname)
141 class(fluid_sgs_stats_simcomp_t), target, intent(inout) :: this
142 character(len=*), intent(in) :: hom_dir
143 character(len=*), intent(in) :: nut_field
144 real(kind=rp), intent(in) :: start_time
145 type(field_t), intent(in), target :: u, v, w
146 type(coef_t), intent(in), target :: coef
147 character(len=*), intent(in), optional :: fname
148 character(len=NEKO_FNAME_LEN) :: stats_fname
149 character(len=LOG_SIZE) :: log_buf
150 character(len=5) :: prefix
151
152 call neko_log%section('Fluid stats')
153 write(log_buf, '(A,E15.7)') 'Start time: ', start_time
154 call neko_log%message(log_buf)
155 write(log_buf, '(A,A)') 'Nut field name: ', trim(nut_field)
156 call neko_log%message(log_buf)
157 write(log_buf, '(A,A)') 'Averaging in direction: ', trim(hom_dir)
158 call neko_log%message(log_buf)
159
160
161 call this%stats%init(coef, u, v, w, nut_field)
162
163 this%start_time = start_time
164 this%time = start_time
165 if (present(fname)) then
166 this%default_fname = .false.
167 stats_fname = fname
168 else
169 stats_fname = "fluid_sgs_stats0"
170 this%default_fname = .true.
171 end if
172
173 call this%stats_output%init(this%stats, this%start_time, &
174 hom_dir = hom_dir, name = stats_fname, &
175 path = this%case%output_directory)
176
177 call this%case%output_controller%add(this%stats_output, &
178 this%output_controller%control_value, &
179 this%output_controller%control_mode)
180
181 call neko_log%end_section()
182
184
187 class(fluid_sgs_stats_simcomp_t), intent(inout) :: this
188 call this%free_base()
189 call this%stats%free()
190 call this%stats_output%free()
191 end subroutine fluid_sgs_stats_simcomp_free
192
193 subroutine fluid_sgs_stats_simcomp_restart(this, time)
194 class(fluid_sgs_stats_simcomp_t), intent(inout) :: this
195 type(time_state_t), intent(in) :: time
196 character(len=NEKO_FNAME_LEN) :: fname
197 character(len=5) :: prefix, suffix
198 integer :: last_slash_pos
199 real(kind=rp) :: t
200 t = time%t
201 if (t .gt. this%time) this%time = t
202 if (this%default_fname) then
203 fname = this%stats_output%file_%get_base_fname()
204 write (prefix, '(I5)') this%stats_output%file_%get_counter()
205 call filename_suffix(fname, suffix)
206 last_slash_pos = &
208 if (last_slash_pos .ne. 0) then
209 fname = &
210 trim(fname(1:last_slash_pos))// &
211 "fluid_sgs_stats"//trim(adjustl(prefix))//"."//suffix
212 else
213 fname = "fluid_sgs_stats"// &
214 trim(adjustl(prefix))//"."//suffix
215 end if
216 call this%stats_output%init_base(fname)
217 end if
219
222 subroutine fluid_sgs_stats_simcomp_compute(this, time)
223 class(fluid_sgs_stats_simcomp_t), intent(inout) :: this
224 type(time_state_t), intent(in) :: time
225 real(kind=rp) :: delta_t, t
226 real(kind=rp) :: sample_start_time, sample_time
227 character(len=LOG_SIZE) :: log_buf
228 integer :: ierr
229
230 if (time%start_time .gt. this%start_time) then
231 write(log_buf, '(A)') 'Simulation start time is later than the ' &
232 // 'fluid stats start time.'
233 call neko_log%warning(log_buf)
234 write(log_buf, '(A,E15.7)') 'Simulation start time:', time%start_time
235 call neko_log%warning(log_buf)
236 write(log_buf, '(A,E15.7)') 'Fluid stats start time:', this%start_time
237 call neko_log%warning(log_buf)
238 write(log_buf, '(A)') 'Assigning the statistics start time to ' &
239 // 'the simulation start time.'
240 call neko_log%warning(log_buf)
241 this%start_time = time%start_time
242 this%time = time%start_time
243 end if
244
245 t = time%t
246
247 if (t .ge. this%start_time) then
248 delta_t = t - this%time !This is only a real number
249
250 call mpi_barrier(neko_comm, ierr)
251
252 sample_start_time = mpi_wtime()
253
254 call this%stats%update(delta_t)
255 call mpi_barrier(neko_comm, ierr)
256 this%time = t
257
258 sample_time = mpi_wtime() - sample_start_time
259
260 call neko_log%section('Fluid SGS stats')
261 write(log_buf, '(A,E15.7)') 'Sampling at time:', t
262 call neko_log%message(log_buf)
263 write(log_buf, '(A33,E15.7)') 'Simulation time since last sample:', &
264 delta_t
265 call neko_log%message(log_buf)
266 write(log_buf, '(A,E15.7)') 'Sampling time (s):', sample_time
267 call neko_log%message(log_buf)
268 call neko_log%end_section()
269 end if
270
272
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_sgs_stats_ouput_t.
Implements the fluid_sgs_stats_simcomp_t type.
subroutine fluid_sgs_stats_simcomp_init_from_components(this, u, v, w, coef, start_time, hom_dir, nut_field, fname)
Actual constructor.
subroutine fluid_sgs_stats_simcomp_compute(this, time)
fluid_sgs_stats, called depending on compute_control and compute_value
subroutine fluid_sgs_stats_simcomp_restart(this, time)
subroutine fluid_sgs_stats_simcomp_free(this)
Destructor.
subroutine fluid_sgs_stats_simcomp_init_from_json(this, json, case)
Constructor from json.
Computes the subgrid-scale contributions for Reynolds stresses. We use the Reynolds decomposition for...
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:62
Defines an output for the sgs statistics for fluid computed using the fluid_sgs_stats_t object.
A simulation component that computes the subgrid-scale contributions to the Reynolds stresses in LES.
Base abstract class for simulation components.
A struct that contains all info about the time, expand as needed.