Neko  0.8.99
A portable framework for high-order spectral element flow simulations
fluid_output.f90
Go to the documentation of this file.
1 ! Copyright (c) 2020-2023, 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 num_types, only : rp
36  use fluid_scheme, only : fluid_scheme_t
37  use scalar_scheme, only : scalar_scheme_t
38  use field_list, only : field_list_t
39  use neko_config, only : neko_bcknd_device
40  use device
41  use output, only : output_t
42  implicit none
43  private
44 
46  type, public, extends(output_t) :: fluid_output_t
47  type(field_list_t) :: fluid
48  contains
49  procedure, pass(this) :: sample => fluid_output_sample
50  end type fluid_output_t
51 
52  interface fluid_output_t
53  module procedure fluid_output_init
54  end interface fluid_output_t
55 
56 contains
57 
58  function fluid_output_init(precision, fluid, scalar, name, path) result(this)
59  integer, intent(inout) :: precision
60  class(fluid_scheme_t), intent(in), target :: fluid
61  class(scalar_scheme_t), intent(in), optional, target :: scalar
62  character(len=*), intent(in), optional :: name
63  character(len=*), intent(in), optional :: path
64  type(fluid_output_t) :: this
65  character(len=1024) :: fname
66 
67  if (present(name) .and. present(path)) then
68  fname = trim(path) // trim(name) // '.fld'
69  else if (present(name)) then
70  fname = trim(name) // '.fld'
71  else if (present(path)) then
72  fname = trim(path) // 'field.fld'
73  else
74  fname = 'field.fld'
75  end if
76 
77  call this%init_base(fname, precision)
78 
79  if (present(scalar)) then
80  call this%fluid%init(5)
81  else
82  call this%fluid%init(4)
83  end if
84 
85  call this%fluid%assign(1, fluid%p)
86  call this%fluid%assign(2, fluid%u)
87  call this%fluid%assign(3, fluid%v)
88  call this%fluid%assign(4, fluid%w)
89 
90  if (present(scalar)) then
91  call this%fluid%assign(5, scalar%s)
92  end if
93 
94  end function fluid_output_init
95 
97  subroutine fluid_output_sample(this, t)
98  class(fluid_output_t), intent(inout) :: this
99  real(kind=rp), intent(in) :: t
100  integer :: i
101 
102  if (neko_bcknd_device .eq. 1) then
103 
104  associate(fields => this%fluid%items)
105  do i = 1, size(fields)
106  call device_memcpy(fields(i)%ptr%x, fields(i)%ptr%x_d, &
107  fields(i)%ptr%dof%size(), device_to_host, &
108  sync=(i .eq. size(fields))) ! Sync on the last field
109  end do
110  end associate
111 
112  end if
113 
114  call this%file_%write(this%fluid, t)
115 
116  end subroutine fluid_output_sample
117 
118 end module fluid_output
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 fluid.
subroutine fluid_output_sample(this, t)
Sample a fluid solution at time t.
type(fluid_output_t) function fluid_output_init(precision, fluid, scalar, name, path)
Fluid formulations.
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
Contains the scalar_scheme_t type.
field_list_t, To be able to group fields together
Definition: field_list.f90:13
Base type of all fluid formulations.
Abstract type defining an output type.
Definition: output.f90:41
Base type for a scalar advection-diffusion solver.