Neko  0.8.1
A portable framework for high-order spectral element flow simulations
fld_file_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 field_list, only : field_list_t
37  use neko_config, only : neko_bcknd_device
39  use output, only : output_t
40  implicit none
41  private
42 
44  type, public, extends(output_t) :: fld_file_output_t
45  ! The list of fields to save.
46  type(field_list_t) :: fields
47  contains
48  ! Constructor.
49  procedure, pass(this) :: init => fld_file_output_init
50  ! Writes the data.
51  procedure, pass(this) :: sample => fld_file_output_sample
52  end type fld_file_output_t
53 
54 contains
55 
61  subroutine fld_file_output_init(this, precision, name, nfields, path)
62  class(fld_file_output_t), intent (inout) :: this
63  integer, intent(in) :: precision
64  character(len=*), intent(in) :: name
65  character(len=*), intent(in), optional :: path
66  integer, intent(in) :: nfields
67  character(len=1024) :: fname
68 
69  if (present(path)) then
70  fname = trim(path) // trim(name) // '.fld'
71  else
72  fname = trim(name) // '.fld'
73  end if
74 
75  call this%init_base(fname, precision)
76 
77  if (allocated(this%fields%fields)) then
78  deallocate(this%fields%fields)
79  end if
80 
81  allocate(this%fields%fields(nfields))
82 
83  end subroutine fld_file_output_init
84 
87  subroutine fld_file_output_sample(this, t)
88  class(fld_file_output_t), intent(inout) :: this
89  real(kind=rp), intent(in) :: t
90  integer :: i
91 
92  if (neko_bcknd_device .eq. 1) then
93  associate(fields => this%fields%fields)
94  do i = 1, size(fields)
95  call device_memcpy(fields(i)%f%x, fields(i)%f%x_d, &
96  fields(i)%f%dof%size(), device_to_host, &
97  sync=(i .eq. size(fields))) ! Sync on the last field
98  end do
99  end associate
100 
101  end if
102 
103  call this%file_%write(this%fields, t)
104 
105  end subroutine fld_file_output_sample
106 
107 end module fld_file_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
Implements fld_file_output_t.
subroutine fld_file_output_init(this, precision, name, nfields, path)
Constructor.
subroutine fld_file_output_sample(this, t)
Writes the data.
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
field_list_t, To be able to group fields together
Definition: field_list.f90:7
A simple output saving a list of fields to a .fld file.
Abstract type defining an output type.
Definition: output.f90:41