Neko  0.8.1
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
40  use device
41  use output, only : output_t
42  implicit none
43 
45  type, public, extends(output_t) :: fluid_output_t
46  type(field_list_t) :: fluid
47  contains
48  procedure, pass(this) :: sample => fluid_output_sample
49  end type fluid_output_t
50 
51  interface fluid_output_t
52  module procedure fluid_output_init
53  end interface fluid_output_t
54 
55 contains
56 
57  function fluid_output_init(precision, fluid, scalar, name, path) result(this)
58  integer, intent(inout) :: precision
59  class(fluid_scheme_t), intent(in), target :: fluid
60  class(scalar_scheme_t), intent(in), optional, target :: scalar
61  character(len=*), intent(in), optional :: name
62  character(len=*), intent(in), optional :: path
63  type(fluid_output_t) :: this
64  character(len=1024) :: fname
65 
66  if (present(name) .and. present(path)) then
67  fname = trim(path) // trim(name) // '.fld'
68  else if (present(name)) then
69  fname = trim(name) // '.fld'
70  else if (present(path)) then
71  fname = trim(path) // 'field.fld'
72  else
73  fname = 'field.fld'
74  end if
75 
76  call this%init_base(fname, precision)
77 
78  if (allocated(this%fluid%fields)) then
79  deallocate(this%fluid%fields)
80  end if
81 
82  if (present(scalar)) then
83  allocate(this%fluid%fields(5))
84  else
85  allocate(this%fluid%fields(4))
86  end if
87 
88  this%fluid%fields(1)%f => fluid%p
89  this%fluid%fields(2)%f => fluid%u
90  this%fluid%fields(3)%f => fluid%v
91  this%fluid%fields(4)%f => fluid%w
92 
93  if (present(scalar)) then
94  this%fluid%fields(5)%f => scalar%s
95  end if
96 
97  end function fluid_output_init
98 
100  subroutine fluid_output_sample(this, t)
101  class(fluid_output_t), intent(inout) :: this
102  real(kind=rp), intent(in) :: t
103  integer :: i
104 
105  if (neko_bcknd_device .eq. 1) then
106 
107  associate(fields => this%fluid%fields)
108  do i = 1, size(fields)
109  call device_memcpy(fields(i)%f%x, fields(i)%f%x_d, &
110  fields(i)%f%dof%size(), device_to_host, &
111  sync=(i .eq. size(fields))) ! Sync on the last field
112  end do
113  end associate
114 
115  end if
116 
117  call this%file_%write(this%fluid, t)
118 
119  end subroutine fluid_output_sample
120 
121 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:7
Base type of all fluid formulations.
Abstract type defining an output type.
Definition: output.f90:41
Base type for a scalar advection-diffusion solver.