Neko  0.8.99
A portable framework for high-order spectral element flow simulations
fluid_stats_output.f90
Go to the documentation of this file.
1 ! Copyright (c) 2022, 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 !
35  use fluid_stats, only : fluid_stats_t
36  use neko_config, only : neko_bcknd_device
37  use num_types, only : rp
38  use device
39  use output, only : output_t
40  implicit none
41  private
42 
43  type, public, extends(output_t) :: fluid_stats_output_t
44  type(fluid_stats_t), pointer :: stats
45  real(kind=rp) :: t_begin
46  contains
47  procedure, pass(this) :: sample => fluid_stats_output_sample
48  end type fluid_stats_output_t
49 
50  interface fluid_stats_output_t
51  module procedure fluid_stats_output_init
52  end interface fluid_stats_output_t
53 
54 contains
55 
56  function fluid_stats_output_init(stats, T_begin, name, path) result(this)
57  type(fluid_stats_t), intent(in), target :: stats
58  real(kind=rp), intent(in) :: t_begin
59  character(len=*), intent(in), optional :: name
60  character(len=*), intent(in), optional :: path
61  type(fluid_stats_output_t) :: this
62  character(len=1024) :: fname
63 
64  if (present(name) .and. present(path)) then
65  fname = trim(path) // trim(name) // '.fld'
66  else if (present(name)) then
67  fname = trim(name) // '.fld'
68  else if (present(path)) then
69  fname = trim(path) // 'stats.fld'
70  else
71  fname = 'stats.fld'
72  end if
73 
74  call this%init_base(fname)
75  this%stats => stats
76  this%T_begin = t_begin
77  end function fluid_stats_output_init
78 
80  subroutine fluid_stats_output_sample(this, t)
81  class(fluid_stats_output_t), intent(inout) :: this
82  real(kind=rp), intent(in) :: t
83  integer :: i
84  associate(out_fields => this%stats%stat_fields%items)
85  if (t .ge. this%T_begin) then
86  call this%stats%make_strong_grad()
87  if ( neko_bcknd_device .eq. 1) then
88  do i = 1, size(out_fields)
89  call device_memcpy(out_fields(i)%ptr%x, out_fields(i)%ptr%x_d,&
90  out_fields(i)%ptr%dof%size(), device_to_host, &
91  sync=(i .eq. size(out_fields))) ! Sync on last field
92  end do
93  end if
94  call this%file_%write(this%stats%stat_fields, t)
95  call this%stats%reset()
96  end if
97  end associate
98  end subroutine fluid_stats_output_sample
99 
100 end module fluid_stats_output
101 
102 
Copy data between host and device (or device and device)
Definition: device.F90:51
Device abstraction, common interface for various accelerators.
Definition: device.F90:34
integer, parameter, public device_to_host
Definition: device.F90:47
Defines an output for a mean flow field.
type(fluid_stats_output_t) function fluid_stats_output_init(stats, T_begin, name, path)
subroutine fluid_stats_output_sample(this, t)
Sample a mean flow field at time t.
Computes various statistics for the fluid fields. We use the Reynolds decomposition for a field u = ...
Definition: fluid_stats.f90:36
Build configurations.
Definition: neko_config.f90:34
integer, parameter neko_bcknd_device
Definition: neko_config.f90:44
integer, parameter, public rp
Global precision used in computations.
Definition: num_types.f90:12
Defines an output.
Definition: output.f90:34
Defines a container for all statistics.
Definition: statistics.f90:34
Abstract type defining an output type.
Definition: output.f90:41