Neko 1.99.9
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
fluid_stats.f90
Go to the documentation of this file.
1! Copyright (c) 2022-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!
37 use mean_field, only : mean_field_t
39 use num_types, only : rp
40 use math, only : copy, subcol3
41 use operators, only : opgrad
42 use coefs, only : coef_t
43 use field, only : field_t
44 use field_list, only : field_list_t
45 use field_math, only : field_col3
46 use stats_quant, only : stats_quant_t
50 use utils, only : neko_warning
51 implicit none
52 private
53
54 type, public, extends(stats_quant_t) :: fluid_stats_t
56 type(field_t), pointer :: u
57 type(field_t), pointer :: v
58 type(field_t), pointer :: w
59 type(field_t), pointer :: p
60
61 type(mean_field_t) :: u_mean
62 type(mean_field_t) :: v_mean
63 type(mean_field_t) :: w_mean
64 type(mean_field_t) :: p_mean
66 type(mean_field_t) :: uu
67 type(mean_field_t) :: vv
68 type(mean_field_t) :: ww
69 type(mean_field_t) :: uv
70 type(mean_field_t) :: uw
71 type(mean_field_t) :: vw
73 type(mean_field_t) :: uuu
74 type(mean_field_t) :: vvv
75 type(mean_field_t) :: www
76 type(mean_field_t) :: uuv
77 type(mean_field_t) :: uuw
78 type(mean_field_t) :: uvv
79 type(mean_field_t) :: uvw
80 type(mean_field_t) :: vvw
81 type(mean_field_t) :: uww
82 type(mean_field_t) :: vww
84 type(mean_field_t) :: uuuu
85 type(mean_field_t) :: vvvv
86 type(mean_field_t) :: wwww
88 type(mean_field_t) :: pp
89 type(mean_field_t) :: ppp
90 type(mean_field_t) :: pppp
92 type(mean_field_t) :: pu
93 type(mean_field_t) :: pv
94 type(mean_field_t) :: pw
95
97 type(mean_field_t) :: pdudx
98 type(mean_field_t) :: pdudy
99 type(mean_field_t) :: pdudz
100 type(mean_field_t) :: pdvdx
101 type(mean_field_t) :: pdvdy
102 type(mean_field_t) :: pdvdz
103 type(mean_field_t) :: pdwdx
104 type(mean_field_t) :: pdwdy
105 type(mean_field_t) :: pdwdz
106
108 type(mean_field_t) :: e11
109 type(mean_field_t) :: e22
110 type(mean_field_t) :: e33
111 type(mean_field_t) :: e12
112 type(mean_field_t) :: e13
113 type(mean_field_t) :: e23
115 type(coef_t), pointer :: coef
117 integer :: n_stats = 44
120 character(5) :: stat_set
123 type(field_list_t) :: stat_fields
124 contains
126 procedure, pass(this) :: init => fluid_stats_init
128 procedure, pass(this) :: free => fluid_stats_free
130 procedure, pass(this) :: update => fluid_stats_update
132 procedure, pass(this) :: reset => fluid_stats_reset
133 ! Convert computed weak gradients to strong.
134 procedure, pass(this) :: make_strong_grad => fluid_stats_make_strong_grad
137 procedure, pass(this) :: post_process => fluid_stats_post_process
138 end type fluid_stats_t
139
140contains
141
150 subroutine fluid_stats_init(this, coef, u, v, w, p, set, name)
151 class(fluid_stats_t), intent(inout), target:: this
152 type(coef_t), target, optional :: coef
153 type(field_t), target, intent(in) :: u, v, w, p
154 character(*), intent(in), optional :: set
155 character(*), intent(in), optional :: name
156
157 character(len=1024) :: unique_name
158 unique_name = ""
159
160 call this%free()
161 this%coef => coef
162
163 this%u => u
164 this%v => v
165 this%w => w
166 this%p => p
167
168 if (present(set)) then
169 this%stat_set = trim(set)
170 if (this%stat_set .eq. 'basic') then
171 this%n_stats = 11
172 end if
173 else
174 this%stat_set = 'full'
175 this%n_stats = 44
176 end if
177
178 if (present(name)) then
179 unique_name = name // "/"
180 else
181 unique_name = "fluid_stats/"
182 end if
183
184 call this%u_mean%init(this%u, trim(unique_name) // 'mean_u')
185 call this%v_mean%init(this%v, trim(unique_name) // 'mean_v')
186 call this%w_mean%init(this%w, trim(unique_name) // 'mean_w')
187 call this%p_mean%init(this%p, trim(unique_name) // 'mean_p')
188 ! The remaining means are of products of the instantaneous fields, and are
189 ! updated with update_col3/update_dot3. The field passed to init only
190 ! provides the dofmap.
191 call this%uu%init(this%u, trim(unique_name) // 'mean_uu')
192 call this%vv%init(this%u, trim(unique_name) // 'mean_vv')
193 call this%ww%init(this%u, trim(unique_name) // 'mean_ww')
194 call this%uv%init(this%u, trim(unique_name) // 'mean_uv')
195 call this%uw%init(this%u, trim(unique_name) // 'mean_uw')
196 call this%vw%init(this%u, trim(unique_name) // 'mean_vw')
197 call this%pp%init(this%u, trim(unique_name) // 'mean_pp')
198
199 if (this%n_stats .eq. 44) then
200 call this%uuu%init(this%u, trim(unique_name) // 'mean_uuu')
201 call this%vvv%init(this%u, trim(unique_name) // 'mean_vvv')
202 call this%www%init(this%u, trim(unique_name) // 'mean_www')
203 call this%uuv%init(this%u, trim(unique_name) // 'mean_uuv')
204 call this%uuw%init(this%u, trim(unique_name) // 'mean_uuw')
205 call this%uvv%init(this%u, trim(unique_name) // 'mean_uvv')
206 call this%uvw%init(this%u, trim(unique_name) // 'mean_uvw')
207 call this%vvw%init(this%u, trim(unique_name) // 'mean_vvw')
208 call this%uww%init(this%u, trim(unique_name) // 'mean_uww')
209 call this%vww%init(this%u, trim(unique_name) // 'mean_vww')
210 call this%uuuu%init(this%u, trim(unique_name) // 'mean_uuuu')
211 call this%vvvv%init(this%u, trim(unique_name) // 'mean_vvvv')
212 call this%wwww%init(this%u, trim(unique_name) // 'mean_wwww')
214 call this%ppp%init(this%u, trim(unique_name) // 'mean_ppp')
215 call this%pppp%init(this%u, trim(unique_name) // 'mean_pppp')
217 call this%pu%init(this%u, trim(unique_name) // 'mean_pu')
218 call this%pv%init(this%u, trim(unique_name) // 'mean_pv')
219 call this%pw%init(this%u, trim(unique_name) // 'mean_pw')
220
221 call this%pdudx%init(this%u, trim(unique_name) // 'mean_pdudx')
222 call this%pdudy%init(this%u, trim(unique_name) // 'mean_pdudy')
223 call this%pdudz%init(this%u, trim(unique_name) // 'mean_pdudz')
224 call this%pdvdx%init(this%u, trim(unique_name) // 'mean_pdvdx')
225 call this%pdvdy%init(this%u, trim(unique_name) // 'mean_pdvdy')
226 call this%pdvdz%init(this%u, trim(unique_name) // 'mean_pdvdz')
227 call this%pdwdx%init(this%u, trim(unique_name) // 'mean_pdwdx')
228 call this%pdwdy%init(this%u, trim(unique_name) // 'mean_pdwdy')
229 call this%pdwdz%init(this%u, trim(unique_name) // 'mean_pdwdz')
230
231 call this%e11%init(this%u, trim(unique_name) // 'mean_e11')
232 call this%e22%init(this%u, trim(unique_name) // 'mean_e22')
233 call this%e33%init(this%u, trim(unique_name) // 'mean_e33')
234 call this%e12%init(this%u, trim(unique_name) // 'mean_e12')
235 call this%e13%init(this%u, trim(unique_name) // 'mean_e13')
236 call this%e23%init(this%u, trim(unique_name) // 'mean_e23')
237 end if
238
239 call this%stat_fields%init(this%n_stats)
240
241 call this%stat_fields%assign_to_field(1, this%p_mean%mf)
242 call this%stat_fields%assign_to_field(2, this%u_mean%mf)
243 call this%stat_fields%assign_to_field(3, this%v_mean%mf)
244 call this%stat_fields%assign_to_field(4, this%w_mean%mf)
245 call this%stat_fields%assign_to_field(5, this%pp%mf)
246 call this%stat_fields%assign_to_field(6, this%uu%mf)
247 call this%stat_fields%assign_to_field(7, this%vv%mf)
248 call this%stat_fields%assign_to_field(8, this%ww%mf)
249 call this%stat_fields%assign_to_field(9, this%uv%mf)
250 call this%stat_fields%assign_to_field(10, this%uw%mf)
251 call this%stat_fields%assign_to_field(11, this%vw%mf)
252
253 if (this%n_stats .eq. 44) then
254 call this%stat_fields%assign_to_field(12, this%uuu%mf)
255 call this%stat_fields%assign_to_field(13, this%vvv%mf)
256 call this%stat_fields%assign_to_field(14, this%www%mf)
257 call this%stat_fields%assign_to_field(15, this%uuv%mf)
258 call this%stat_fields%assign_to_field(16, this%uuw%mf)
259 call this%stat_fields%assign_to_field(17, this%uvv%mf)
260 call this%stat_fields%assign_to_field(18, this%uvw%mf)
261 call this%stat_fields%assign_to_field(19, this%vvw%mf)
262 call this%stat_fields%assign_to_field(20, this%uww%mf)
263 call this%stat_fields%assign_to_field(21, this%vww%mf)
264 call this%stat_fields%assign_to_field(22, this%uuuu%mf)
265 call this%stat_fields%assign_to_field(23, this%vvvv%mf)
266 call this%stat_fields%assign_to_field(24, this%wwww%mf)
267 call this%stat_fields%assign_to_field(25, this%ppp%mf)
268 call this%stat_fields%assign_to_field(26, this%pppp%mf)
269 call this%stat_fields%assign_to_field(27, this%pu%mf)
270 call this%stat_fields%assign_to_field(28, this%pv%mf)
271 call this%stat_fields%assign_to_field(29, this%pw%mf)
272
273 call this%stat_fields%assign_to_field(30, this%pdudx%mf)
274 call this%stat_fields%assign_to_field(31, this%pdudy%mf)
275 call this%stat_fields%assign_to_field(32, this%pdudz%mf)
276 call this%stat_fields%assign_to_field(33, this%pdvdx%mf)
277 call this%stat_fields%assign_to_field(34, this%pdvdy%mf)
278 call this%stat_fields%assign_to_field(35, this%pdvdz%mf)
279 call this%stat_fields%assign_to_field(36, this%pdwdx%mf)
280 call this%stat_fields%assign_to_field(37, this%pdwdy%mf)
281 call this%stat_fields%assign_to_field(38, this%pdwdz%mf)
282 call this%stat_fields%assign_to_field(39, this%e11%mf)
283 call this%stat_fields%assign_to_field(40, this%e22%mf)
284 call this%stat_fields%assign_to_field(41, this%e33%mf)
285 call this%stat_fields%assign_to_field(42, this%e12%mf)
286 call this%stat_fields%assign_to_field(43, this%e13%mf)
287 call this%stat_fields%assign_to_field(44, this%e23%mf)
288 end if
289
290 end subroutine fluid_stats_init
291
294 subroutine fluid_stats_update(this, k)
295 class(fluid_stats_t), intent(inout) :: this
296 real(kind=rp), intent(in) :: k
297 type(field_t), pointer :: work
298 type(field_t), pointer :: dudx, dudy, dudz
299 type(field_t), pointer :: dvdx, dvdy, dvdz
300 type(field_t), pointer :: dwdx, dwdy, dwdz
301 integer :: idx(10)
302
303 associate(u => this%u, v => this%v, w => this%w, p => this%p)
304
305 call this%u_mean%update(k)
306 call this%v_mean%update(k)
307 call this%w_mean%update(k)
308 call this%p_mean%update(k)
309
310 call this%uu%update_col3(k, u, u)
311 call this%vv%update_col3(k, v, v)
312 call this%ww%update_col3(k, w, w)
313 call this%pp%update_col3(k, p, p)
314
315 call this%uv%update_col3(k, u, v)
316 call this%uw%update_col3(k, u, w)
317 call this%vw%update_col3(k, v, w)
318
319 if (this%n_stats .eq. 11) return
320
321 call neko_scratch_registry%request_field(work, idx(1), &
322 this%u%dof, .false.)
323
324 call field_col3(work, u, u)
325 call this%uuu%update_col3(k, work, u)
326 call this%uuv%update_col3(k, work, v)
327 call this%uuw%update_col3(k, work, w)
328 call this%uuuu%update_col3(k, work, work)
329
330 call field_col3(work, v, v)
331 call this%vvv%update_col3(k, work, v)
332 call this%uvv%update_col3(k, work, u)
333 call this%vvw%update_col3(k, work, w)
334 call this%vvvv%update_col3(k, work, work)
335
336 call field_col3(work, w, w)
337 call this%www%update_col3(k, work, w)
338 call this%uww%update_col3(k, work, u)
339 call this%vww%update_col3(k, work, v)
340 call this%wwww%update_col3(k, work, work)
341
342 call field_col3(work, v, w)
343 call this%uvw%update_col3(k, work, u)
344
345 call field_col3(work, p, p)
346 call this%ppp%update_col3(k, work, p)
347 call this%pppp%update_col3(k, work, work)
348
349 call neko_scratch_registry%relinquish_field(idx(1))
350
351 call this%pu%update_col3(k, p, u)
352 call this%pv%update_col3(k, p, v)
353 call this%pw%update_col3(k, p, w)
354
355 call neko_scratch_registry%request_field(dudx, idx(2), &
356 this%u%dof, .false.)
357 call neko_scratch_registry%request_field(dudy, idx(3), &
358 this%u%dof, .false.)
359 call neko_scratch_registry%request_field(dudz, idx(4), &
360 this%u%dof, .false.)
361 call neko_scratch_registry%request_field(dvdx, idx(5), &
362 this%u%dof, .false.)
363 call neko_scratch_registry%request_field(dvdy, idx(6), &
364 this%u%dof, .false.)
365 call neko_scratch_registry%request_field(dvdz, idx(7), &
366 this%u%dof, .false.)
367 call neko_scratch_registry%request_field(dwdx, idx(8), &
368 this%u%dof, .false.)
369 call neko_scratch_registry%request_field(dwdy, idx(9), &
370 this%u%dof, .false.)
371 call neko_scratch_registry%request_field(dwdz, idx(10), &
372 this%u%dof, .false.)
373
374 call opgrad(dudx%x, dudy%x, dudz%x, u%x, this%coef)
375 call opgrad(dvdx%x, dvdy%x, dvdz%x, v%x, this%coef)
376 call opgrad(dwdx%x, dwdy%x, dwdz%x, w%x, this%coef)
377
378 call this%pdudx%update_col3(k, dudx, p)
379 call this%pdudy%update_col3(k, dudy, p)
380 call this%pdudz%update_col3(k, dudz, p)
381 call this%pdvdx%update_col3(k, dvdx, p)
382 call this%pdvdy%update_col3(k, dvdy, p)
383 call this%pdvdz%update_col3(k, dvdz, p)
384 call this%pdwdx%update_col3(k, dwdx, p)
385 call this%pdwdy%update_col3(k, dwdy, p)
386 call this%pdwdz%update_col3(k, dwdz, p)
387
388 call this%e11%update_dot3(k, dudx, dudy, dudz, dudx, dudy, dudz)
389 call this%e22%update_dot3(k, dvdx, dvdy, dvdz, dvdx, dvdy, dvdz)
390 call this%e33%update_dot3(k, dwdx, dwdy, dwdz, dwdx, dwdy, dwdz)
391 call this%e12%update_dot3(k, dudx, dudy, dudz, dvdx, dvdy, dvdz)
392 call this%e13%update_dot3(k, dudx, dudy, dudz, dwdx, dwdy, dwdz)
393 call this%e23%update_dot3(k, dvdx, dvdy, dvdz, dwdx, dwdy, dwdz)
394
395 call neko_scratch_registry%relinquish_field(idx(2:10))
396 end associate
397
398 end subroutine fluid_stats_update
399
400
402 subroutine fluid_stats_free(this)
403 class(fluid_stats_t), intent(inout) :: this
404
405 call this%u_mean%free()
406 call this%v_mean%free()
407 call this%w_mean%free()
408 call this%p_mean%free()
409
410 call this%uu%free()
411 call this%vv%free()
412 call this%ww%free()
413 call this%uv%free()
414 call this%uw%free()
415 call this%vw%free()
416
417 call this%uuu%free()
418 call this%vvv%free()
419 call this%www%free()
420 call this%uuv%free()
421 call this%uuw%free()
422 call this%uvv%free()
423 call this%uvw%free()
424 call this%vvw%free()
425 call this%uww%free()
426 call this%vww%free()
427
428 call this%uuuu%free()
429 call this%vvvv%free()
430 call this%wwww%free()
431
432 call this%pp%free()
433 call this%ppp%free()
434 call this%pppp%free()
435
436 call this%pu%free()
437 call this%pv%free()
438 call this%pw%free()
439
440 call this%pdudx%free()
441 call this%pdudy%free()
442 call this%pdudz%free()
443 call this%pdvdx%free()
444 call this%pdvdy%free()
445 call this%pdvdz%free()
446 call this%pdwdx%free()
447 call this%pdwdy%free()
448 call this%pdwdz%free()
449
450 call this%e11%free()
451 call this%e22%free()
452 call this%e33%free()
453 call this%e12%free()
454 call this%e13%free()
455 call this%e23%free()
456
457 nullify(this%u)
458 nullify(this%v)
459 nullify(this%w)
460 nullify(this%p)
461 nullify(this%coef)
462
463 call this%stat_fields%free()
464
465 end subroutine fluid_stats_free
466
468 subroutine fluid_stats_reset(this)
469 class(fluid_stats_t), intent(inout), target:: this
470
471 call this%p_mean%reset()
472 call this%u_mean%reset()
473 call this%v_mean%reset()
474 call this%w_mean%reset()
475
476 call this%uu%reset()
477 call this%vv%reset()
478 call this%ww%reset()
479 call this%uv%reset()
480 call this%uw%reset()
481 call this%vw%reset()
482 call this%pp%reset()
483 if (this%n_stats .eq. 44) then
484 call this%uuu%reset()
485 call this%vvv%reset()
486 call this%www%reset()
487 call this%uuv%reset()
488 call this%uuw%reset()
489 call this%uvv%reset()
490 call this%uvw%reset()
491 call this%vvw%reset()
492 call this%uww%reset()
493 call this%vww%reset()
494 call this%uuuu%reset()
495 call this%vvvv%reset()
496 call this%wwww%reset()
497 call this%ppp%reset()
498 call this%pppp%reset()
499 call this%pu%reset()
500 call this%pv%reset()
501 call this%pw%reset()
502
503 call this%pdudx%reset()
504 call this%pdudy%reset()
505 call this%pdudz%reset()
506 call this%pdvdx%reset()
507 call this%pdvdy%reset()
508 call this%pdvdz%reset()
509 call this%pdwdx%reset()
510 call this%pdwdy%reset()
511 call this%pdwdz%reset()
512
513 call this%e11%reset()
514 call this%e22%reset()
515 call this%e33%reset()
516 call this%e12%reset()
517 call this%e13%reset()
518 call this%e23%reset()
519 end if
520
521 end subroutine fluid_stats_reset
522
523 ! Convert computed weak gradients to strong.
525 class(fluid_stats_t) :: this
526 integer :: n, i
527 real(kind=rp) :: wrk, wrk_sqr
528 type(field_t), pointer :: work
529 integer :: idx
530
531 if (this%n_stats .eq. 11) return
532
533 n = size(this%coef%B)
534
535 if (neko_bcknd_device .eq. 1) then
536 call neko_scratch_registry%request_field(work, idx, &
537 this%u%dof, .false.)
538 call device_cfill(work%x_d, 1.0_rp, n)
539 call device_invcol2(work%x_d, this%coef%B_d, n)
540 call device_col2(this%pdudx%mf%x_d, work%x_d, n)
541 call device_col2(this%pdudy%mf%x_d, work%x_d, n)
542 call device_col2(this%pdudz%mf%x_d, work%x_d, n)
543 call device_col2(this%pdvdx%mf%x_d, work%x_d, n)
544 call device_col2(this%pdvdy%mf%x_d, work%x_d, n)
545 call device_col2(this%pdvdz%mf%x_d, work%x_d, n)
546 call device_col2(this%pdwdx%mf%x_d, work%x_d, n)
547 call device_col2(this%pdwdy%mf%x_d, work%x_d, n)
548 call device_col2(this%pdwdz%mf%x_d, work%x_d, n)
549
550 call device_col2(work%x_d, work%x_d, n)
551 call device_col2(this%e11%mf%x_d, work%x_d, n)
552 call device_col2(this%e22%mf%x_d, work%x_d, n)
553 call device_col2(this%e33%mf%x_d, work%x_d, n)
554 call device_col2(this%e12%mf%x_d, work%x_d, n)
555 call device_col2(this%e13%mf%x_d, work%x_d, n)
556 call device_col2(this%e23%mf%x_d, work%x_d, n)
557 call neko_scratch_registry%relinquish_field(idx)
558
559 else
560 !$omp parallel do private(i, wrk, wrk_sqr)
561 do i = 1, n
562 wrk = 1.0_rp / this%coef%B(i,1,1,1)
563 this%pdudx%mf%x(i,1,1,1) = this%pdudx%mf%x(i,1,1,1) * wrk
564 this%pdudy%mf%x(i,1,1,1) = this%pdudy%mf%x(i,1,1,1) * wrk
565 this%pdudz%mf%x(i,1,1,1) = this%pdudz%mf%x(i,1,1,1) * wrk
566
567 this%pdvdx%mf%x(i,1,1,1) = this%pdvdx%mf%x(i,1,1,1) * wrk
568 this%pdvdy%mf%x(i,1,1,1) = this%pdvdy%mf%x(i,1,1,1) * wrk
569 this%pdvdz%mf%x(i,1,1,1) = this%pdvdz%mf%x(i,1,1,1) * wrk
570
571 this%pdwdx%mf%x(i,1,1,1) = this%pdwdx%mf%x(i,1,1,1) * wrk
572 this%pdwdy%mf%x(i,1,1,1) = this%pdwdy%mf%x(i,1,1,1) * wrk
573 this%pdwdz%mf%x(i,1,1,1) = this%pdwdz%mf%x(i,1,1,1) * wrk
574
575 wrk_sqr = wrk * wrk
576 this%e11%mf%x(i,1,1,1) = this%e11%mf%x(i,1,1,1) * wrk_sqr
577 this%e22%mf%x(i,1,1,1) = this%e22%mf%x(i,1,1,1) * wrk_sqr
578 this%e33%mf%x(i,1,1,1) = this%e33%mf%x(i,1,1,1) * wrk_sqr
579
580 this%e12%mf%x(i,1,1,1) = this%e12%mf%x(i,1,1,1) * wrk_sqr
581 this%e13%mf%x(i,1,1,1) = this%e13%mf%x(i,1,1,1) * wrk_sqr
582 this%e23%mf%x(i,1,1,1) = this%e23%mf%x(i,1,1,1) * wrk_sqr
583 end do
584 !$omp end parallel do
585 end if
586
587 end subroutine fluid_stats_make_strong_grad
588
591 subroutine fluid_stats_post_process(this, mean, reynolds, pressure_flatness,&
592 pressure_skewness, skewness_tensor, mean_vel_grad, dissipation_tensor)
593 class(fluid_stats_t) :: this
594 type(field_list_t), intent(inout), optional :: mean
595 type(field_list_t), intent(inout), optional :: reynolds
596 type(field_list_t), intent(in), optional :: pressure_skewness
597 type(field_list_t), intent(in), optional :: pressure_flatness
598 type(field_list_t), intent(in), optional :: skewness_tensor
599 type(field_list_t), intent(inout), optional :: mean_vel_grad
600 type(field_list_t), intent(in), optional :: dissipation_tensor
601 integer :: n, i
602 real(kind=rp) :: wrk
603 type(field_t), pointer :: dudx, dudy, dudz
604 type(field_t), pointer :: dvdx, dvdy, dvdz
605 type(field_t), pointer :: dwdx, dwdy, dwdz
606 integer :: idx(9)
607
608 if (present(mean)) then
609 n = mean%item_size(1)
610 call copy(mean%items(1)%ptr%x, this%u_mean%mf%x, n)
611 call copy(mean%items(2)%ptr%x, this%v_mean%mf%x, n)
612 call copy(mean%items(3)%ptr%x, this%w_mean%mf%x, n)
613 call copy(mean%items(4)%ptr%x, this%p_mean%mf%x, n)
614 end if
615
616 if (present(reynolds)) then
617 n = reynolds%item_size(1)
618 call copy(reynolds%items(1)%ptr%x, this%pp%mf%x, n)
619 call subcol3(reynolds%items(1)%ptr%x, this%p_mean%mf%x, &
620 this%p_mean%mf%x, n)
621
622 call copy(reynolds%items(2)%ptr%x, this%uu%mf%x, n)
623 call subcol3(reynolds%items(2)%ptr%x, this%u_mean%mf%x, &
624 this%u_mean%mf%x, n)
625
626 call copy(reynolds%items(3)%ptr%x, this%vv%mf%x, n)
627 call subcol3(reynolds%items(3)%ptr%x, this%v_mean%mf%x, &
628 this%v_mean%mf%x,n)
629
630 call copy(reynolds%items(4)%ptr%x, this%ww%mf%x, n)
631 call subcol3(reynolds%items(4)%ptr%x, this%w_mean%mf%x, &
632 this%w_mean%mf%x,n)
633
634 call copy(reynolds%items(5)%ptr%x, this%uv%mf%x, n)
635 call subcol3(reynolds%items(5)%ptr%x, this%u_mean%mf%x, &
636 this%v_mean%mf%x, n)
637
638 call copy(reynolds%items(6)%ptr%x, this%uw%mf%x, n)
639 call subcol3(reynolds%items(6)%ptr%x, this%u_mean%mf%x, &
640 this%w_mean%mf%x, n)
641
642 call copy(reynolds%items(7)%ptr%x, this%vw%mf%x, n)
643 call subcol3(reynolds%items(7)%ptr%x, this%v_mean%mf%x, &
644 this%w_mean%mf%x, n)
645 end if
646 if (present(pressure_skewness)) then
647
648 call neko_warning('Presssure skewness stat not implemented'// &
649 ' in fluid_stats, process stats in python instead')
650
651 end if
652
653 if (present(pressure_flatness)) then
654 call neko_warning('Presssure flatness stat not implemented'// &
655 ' in fluid_stats, process stats in python instead')
656
657 end if
658
659 if (present(skewness_tensor)) then
660 call neko_warning('Skewness tensor stat not implemented'// &
661 ' in fluid_stats, process stats in python instead')
662 end if
663
664 if (present(mean_vel_grad)) then
665 !Compute gradient of mean flow
666 n = mean_vel_grad%item_size(1)
667 call neko_scratch_registry%request_field(dudx, idx(1), &
668 this%u%dof, .false.)
669 call neko_scratch_registry%request_field(dudy, idx(2), &
670 this%u%dof, .false.)
671 call neko_scratch_registry%request_field(dudz, idx(3), &
672 this%u%dof, .false.)
673 call neko_scratch_registry%request_field(dvdx, idx(4), &
674 this%u%dof, .false.)
675 call neko_scratch_registry%request_field(dvdy, idx(5), &
676 this%u%dof, .false.)
677 call neko_scratch_registry%request_field(dvdz, idx(6), &
678 this%u%dof, .false.)
679 call neko_scratch_registry%request_field(dwdx, idx(7), &
680 this%u%dof, .false.)
681 call neko_scratch_registry%request_field(dwdy, idx(8), &
682 this%u%dof, .false.)
683 call neko_scratch_registry%request_field(dwdz, idx(9), &
684 this%u%dof, .false.)
685 if (neko_bcknd_device .eq. 1) then
686 call device_memcpy(this%u_mean%mf%x, this%u_mean%mf%x_d, n, &
687 host_to_device, sync = .false.)
688 call device_memcpy(this%v_mean%mf%x, this%v_mean%mf%x_d, n, &
689 host_to_device, sync = .false.)
690 call device_memcpy(this%w_mean%mf%x, this%w_mean%mf%x_d, n, &
691 host_to_device, sync = .false.)
692 call opgrad(dudx%x, dudy%x, dudz%x, &
693 this%u_mean%mf%x, this%coef)
694 call opgrad(dvdx%x, dvdy%x, dvdz%x, &
695 this%v_mean%mf%x, this%coef)
696 call opgrad(dwdx%x, dwdy%x, dwdz%x, &
697 this%w_mean%mf%x, this%coef)
698 call device_memcpy(dudx%x, dudx%x_d, n, &
699 device_to_host, sync = .false.)
700 call device_memcpy(dvdx%x, dvdx%x_d, n, &
701 device_to_host, sync = .false.)
702 call device_memcpy(dwdx%x, dwdx%x_d, n, &
703 device_to_host, sync = .false.)
704 call device_memcpy(dudy%x, dudy%x_d, n, &
705 device_to_host, sync = .false.)
706 call device_memcpy(dvdy%x, dvdy%x_d, n, &
707 device_to_host, sync = .false.)
708 call device_memcpy(dwdy%x, dwdy%x_d, n, &
709 device_to_host, sync = .false.)
710 call device_memcpy(dudz%x, dudz%x_d, n, &
711 device_to_host, sync = .false.)
712 call device_memcpy(dvdz%x, dvdz%x_d, n, &
713 device_to_host, sync = .false.)
714 call device_memcpy(dwdz%x, dwdz%x_d, n, &
715 device_to_host, sync = .true.)
716 else
717 call opgrad(dudx%x, dudy%x, dudz%x, &
718 this%u_mean%mf%x, this%coef)
719 call opgrad(dvdx%x, dvdy%x, dvdz%x, &
720 this%v_mean%mf%x, this%coef)
721 call opgrad(dwdx%x, dwdy%x, dwdz%x, &
722 this%w_mean%mf%x, this%coef)
723 end if
724
725 !$omp parallel do private(i, wrk)
726 do i = 1, n
727 wrk = 1.0_rp / this%coef%B(i,1,1,1)
728 mean_vel_grad%items(1)%ptr%x(i,1,1,1) = dudx%x(i,1,1,1) * wrk
729 mean_vel_grad%items(2)%ptr%x(i,1,1,1) = dudy%x(i,1,1,1) * wrk
730 mean_vel_grad%items(3)%ptr%x(i,1,1,1) = dudz%x(i,1,1,1) * wrk
731
732 mean_vel_grad%items(4)%ptr%x(i,1,1,1) = dvdx%x(i,1,1,1) * wrk
733 mean_vel_grad%items(5)%ptr%x(i,1,1,1) = dvdy%x(i,1,1,1) * wrk
734 mean_vel_grad%items(6)%ptr%x(i,1,1,1) = dvdz%x(i,1,1,1) * wrk
735
736 mean_vel_grad%items(7)%ptr%x(i,1,1,1) = dwdx%x(i,1,1,1) * wrk
737 mean_vel_grad%items(8)%ptr%x(i,1,1,1) = dwdy%x(i,1,1,1) * wrk
738 mean_vel_grad%items(9)%ptr%x(i,1,1,1) = dwdz%x(i,1,1,1) * wrk
739 end do
740 !$omp end parallel do
741
742 call neko_scratch_registry%relinquish_field(idx)
743 end if
744
745 if (present(dissipation_tensor)) then
746 call neko_warning('Dissipation tensor stat not implemented'// &
747 ' in fluid_stats, process stats in python instead')
748 end if
749
750 end subroutine fluid_stats_post_process
751
752end module fluid_stats
Copy data between host and device (or device and device)
Definition device.F90:72
Coefficients.
Definition coef.f90:34
subroutine, public device_col2(a_d, b_d, n, strm)
Vector multiplication .
subroutine, public device_invcol2(a_d, b_d, n, strm)
Vector division .
subroutine, public device_cfill(a_d, c, n, strm)
Set all elements to a constant c .
Device abstraction, common interface for various accelerators.
Definition device.F90:34
integer, parameter, public host_to_device
Definition device.F90:48
integer, parameter, public device_to_host
Definition device.F90:48
subroutine, public field_col3(a, b, c, n)
Vector multiplication with 3 vectors .
Defines a field.
Definition field.f90:34
Computes various statistics for the fluid fields. We use the Reynolds decomposition for a field u = ...
subroutine fluid_stats_reset(this)
Resets all the computed means values and sampling times to zero.
subroutine fluid_stats_make_strong_grad(this)
subroutine fluid_stats_update(this, k)
Updates all fields with a new sample.
subroutine fluid_stats_free(this)
Destructor.
subroutine fluid_stats_post_process(this, mean, reynolds, pressure_flatness, pressure_skewness, skewness_tensor, mean_vel_grad, dissipation_tensor)
Compute certain physical statistical quantities based on existing mean fields.
subroutine fluid_stats_init(this, coef, u, v, w, p, set, name)
Constructor. Initialize the fields associated with fluid_stats.
Definition math.F90:60
subroutine, public subcol3(a, b, c, n)
Returns .
Definition math.F90:1126
subroutine, public copy(a, b, n)
Copy a vector .
Definition math.F90:305
Implements mean_field_t.
Build configurations.
integer, parameter neko_bcknd_device
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:14
Operators.
Definition operators.f90:34
subroutine, public opgrad(ux, uy, uz, u, coef, es, ee)
Compute the weak gradient of a scalar field, i.e. the gradient multiplied by the mass matrix.
Defines a registry for storing and requesting temporary objects This can be used when you have a func...
type(scratch_registry_t), target, public neko_scratch_registry
Global scratch registry.
Defines a statistical quantity.
Utilities.
Definition utils.f90:35
subroutine, public neko_warning(warning_msg)
Reports a warning to standard output.
Definition utils.f90:454
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:136
field_list_t, To be able to group fields together
Computes the temporal mean of a field.
Abstract type defining a statistical quantity.