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
fluid_stats_simcomp.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!
36 use num_types, only : rp, dp, sp
37 use json_module, only : json_file
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
46 use comm
48 use logger, only : log_size, neko_log
50 implicit none
51 private
52
67 type(fluid_stats_output_t) :: stats_output
69 real(kind=rp) :: start_time
70 real(kind=rp) :: time
71 logical :: default_fname = .true.
72
73 contains
75 procedure, pass(this) :: init => fluid_stats_simcomp_init_from_json
77 procedure, pass(this) :: init_from_components => &
80 procedure, pass(this) :: free => fluid_stats_simcomp_free
82 procedure, pass(this) :: compute_ => fluid_stats_simcomp_compute
84 procedure, pass(this) :: output_ => fluid_stats_simcomp_compute
86 procedure, pass(this) :: restart_ => fluid_stats_simcomp_restart
88
89contains
90
94 subroutine fluid_stats_simcomp_init_from_json(this, json, case)
95 class(fluid_stats_simcomp_t), intent(inout) :: this
96 type(json_file), intent(inout) :: json
97 class(case_t), intent(inout), target :: case
98 character(len=:), allocatable :: filename
99 character(len=20), allocatable :: fields(:)
100 character(len=:), allocatable :: hom_dir
101 character(len=:), allocatable :: stat_set
102 real(kind=rp) :: start_time
103 type(field_t), pointer :: u, v, w, p
104 type(coef_t), pointer :: coef
105
106 call this%init_base(json, case)
107 call json_get_or_default(json, 'avg_direction', &
108 hom_dir, 'none')
109 call json_get_or_default(json, 'start_time', &
110 start_time, 0.0_rp)
111 call json_get_or_default(json, 'set_of_stats', &
112 stat_set, 'full')
113
114
115 u => neko_field_registry%get_field("u")
116 v => neko_field_registry%get_field("v")
117 w => neko_field_registry%get_field("w")
118 p => neko_field_registry%get_field("p")
119 coef => case%fluid%c_Xh
120
121 if (json%valid_path("output_filename")) then
122 call json_get(json, "output_filename", filename)
123 call fluid_stats_simcomp_init_from_components(this, u, v, w, p, coef, &
124 start_time, hom_dir, stat_set,filename)
125 else
126 call fluid_stats_simcomp_init_from_components(this, u, v, w, p, coef, &
127 start_time, hom_dir, stat_set)
128 end if
129
131
140 subroutine fluid_stats_simcomp_init_from_components(this, u, v, w, p, coef, &
141 start_time, hom_dir, stat_set, fname)
142 class(fluid_stats_simcomp_t), intent(inout) :: this
143 character(len=*), intent(in) :: hom_dir
144 character(len=*), intent(in) :: stat_set
145 real(kind=rp), intent(in) :: start_time
146 type(field_t), intent(in) :: u, v, w, p
147 type(coef_t), intent(in) :: coef
148 character(len=*), intent(in), optional :: fname
149 character(len=NEKO_FNAME_LEN) :: stats_fname
150 character(len=LOG_SIZE) :: log_buf
151 character(len=5) :: prefix
152
153 call neko_log%section('Fluid stats')
154 write(log_buf, '(A,E15.7)') 'Start time: ', start_time
155 call neko_log%message(log_buf)
156 write(log_buf, '(A,A)') 'Set of statistics: ', trim(stat_set)
157 call neko_log%message(log_buf)
158 write(log_buf, '(A,A)') 'Averaging in direction: ', trim(hom_dir)
159 call neko_log%message(log_buf)
160
161
162 call this%stats%init(coef, u, v, w, p, stat_set)
163
164 this%start_time = start_time
165 this%time = start_time
166 if (present(fname)) then
167 this%default_fname = .false.
168 stats_fname = fname
169 else
170 stats_fname = "fluid_stats0"
171 this%default_fname = .true.
172 end if
173
174 call this%stats_output%init(this%stats, this%start_time, &
175 hom_dir = hom_dir,name = stats_fname, &
176 path = this%case%output_directory)
177
178 call this%case%output_controller%add(this%stats_output, &
179 this%output_controller%control_value, &
180 this%output_controller%control_mode)
181
182 call neko_log%end_section()
183
185
188 class(fluid_stats_simcomp_t), intent(inout) :: this
189 call this%free_base()
190 call this%stats%free()
191 end subroutine fluid_stats_simcomp_free
192
193 subroutine fluid_stats_simcomp_restart(this, time)
194 class(fluid_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 write (prefix, '(I5)') this%stats_output%file_%get_counter()
204 call filename_suffix(this%stats_output%file_%file_type%fname,suffix)
205 last_slash_pos = &
206 filename_tslash_pos(this%stats_output%file_%file_type%fname)
207 if (last_slash_pos .ne. 0) then
208 fname = &
209 trim(this%stats_output%file_%file_type%fname(1:last_slash_pos))// &
210 "fluid_stats"//trim(adjustl(prefix))//"."//suffix
211 else
212 fname = "fluid_stats"// &
213 trim(adjustl(prefix))//"."//suffix
214 end if
215 call this%stats_output%init_base(fname)
216 end if
217 end subroutine fluid_stats_simcomp_restart
218
222 subroutine fluid_stats_simcomp_compute(this, time)
223 class(fluid_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 t = time%t
231
232 if (t .ge. this%start_time) then
233 delta_t = t - this%time !This is only a real number
234
235 call mpi_barrier(neko_comm, ierr)
236
237 sample_start_time = mpi_wtime()
238
239 call this%stats%update(delta_t)
240 call mpi_barrier(neko_comm, ierr)
241 this%time = t
242
243 sample_time = mpi_wtime() - sample_start_time
244
245 call neko_log%section('Fluid stats')
246 write(log_buf, '(A,E15.7)') 'Sampling at time:', t
247 call neko_log%message(log_buf)
248 write(log_buf, '(A33,E15.7)') 'Simulationtime since last sample:', &
249 delta_t
250 call neko_log%message(log_buf)
251 write(log_buf, '(A,E15.7)') 'Sampling time (s):', sample_time
252 call neko_log%message(log_buf)
253 call neko_log%end_section()
254 end if
255
256 end subroutine fluid_stats_simcomp_compute
257
258end 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) neko_comm
MPI communicator.
Definition comm.F90:38
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
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, 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:65
integer, parameter, public log_size
Definition log.f90:42
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
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:70
pure integer function, public filename_tslash_pos(fname)
Find position (in the string) of a filename's trailing slash.
Definition utils.f90:63
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:55
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.