Neko  0.8.1
A portable framework for high-order spectral element flow simulations
mean_flow_output.f90
Go to the documentation of this file.
1 ! Copyright (c) 2021-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 mean_flow, only : mean_flow_t
36  use num_types
37  use device
38  use output
39  implicit none
40  private
41 
42  type, public, extends(output_t) :: mean_flow_output_t
43  type(mean_flow_t), pointer :: mf
44  real(kind=rp) :: t_begin
45  contains
46  procedure, pass(this) :: sample => mean_flow_output_sample
47  end type mean_flow_output_t
48 
49  interface mean_flow_output_t
50  module procedure mean_flow_output_init
51  end interface mean_flow_output_t
52 
53 contains
54 
55  function mean_flow_output_init(mf, T_begin, name, path) result(this)
56  type(mean_flow_t), intent(in), target ::mf
57  real(kind=rp), intent(in) :: t_begin
58  character(len=*), intent(in), optional :: name
59  character(len=*), intent(in), optional :: path
60  type(mean_flow_output_t) :: this
61  character(len=1024) :: fname
62 
63  if (present(name) .and. present(path)) then
64  fname = trim(path) // trim(name) // '.fld'
65  else if (present(name)) then
66  fname = trim(name) // '.fld'
67  else if (present(path)) then
68  fname = trim(path) // 'mean_field.fld'
69  else
70  fname = 'mean_field.fld'
71  end if
72 
73  call this%init_base(fname)
74  this%mf => mf
75  this%T_begin = t_begin
76  end function mean_flow_output_init
77 
79  subroutine mean_flow_output_sample(this, t)
80  class(mean_flow_output_t), intent(inout) :: this
81  real(kind=rp), intent(in) :: t
82 
83  if (t .ge. this%T_begin) then
84  call device_memcpy(this%mf%p%mf%x, this%mf%p%mf%x_d, this%mf%p%mf%dof%size(), &
85  device_to_host, sync=.false.)
86  call device_memcpy(this%mf%u%mf%x, this%mf%u%mf%x_d, this%mf%p%mf%dof%size(), &
87  device_to_host, sync=.false.)
88  call device_memcpy(this%mf%v%mf%x, this%mf%v%mf%x_d, this%mf%p%mf%dof%size(), &
89  device_to_host, sync=.false.)
90  call device_memcpy(this%mf%w%mf%x, this%mf%w%mf%x_d, this%mf%p%mf%dof%size(), &
91  device_to_host, sync=.true.)
92  call this%file_%write(this%mf, t)
93  call this%mf%reset()
94  end if
95 
96  end subroutine mean_flow_output_sample
97 
98 end module mean_flow_output
99 
100 
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(mean_flow_output_t) function mean_flow_output_init(mf, T_begin, name, path)
subroutine mean_flow_output_sample(this, t)
Sample a mean flow field at time t.
Defines a mean flow field.
Definition: mean_flow.f90:34
integer, parameter, public rp
Global precision used in computations.
Definition: num_types.f90:12
Defines an output.
Definition: output.f90:34
Abstract type defining an output type.
Definition: output.f90:41