Neko 1.99.2
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
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
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
49 procedure, pass(this) :: init => fld_file_output_init
51 procedure, pass(this) :: free => fld_file_output_free
53 procedure, pass(this) :: sample => fld_file_output_sample
54 end type fld_file_output_t
55
56contains
57
63 subroutine fld_file_output_init(this, precision, name, nfields, path)
64 class(fld_file_output_t), intent (inout) :: this
65 integer, intent(in) :: precision
66 character(len=*), intent(in) :: name
67 character(len=*), intent(in), optional :: path
68 integer, intent(in) :: nfields
69 character(len=1024) :: fname
70
71 if (present(path)) then
72 fname = trim(path) // trim(name) // '.fld'
73 else
74 fname = trim(name) // '.fld'
75 end if
76
77 call this%init_base(fname, precision)
78
79 call this%fields%init(nfields)
80
81 end subroutine fld_file_output_init
82
84 subroutine fld_file_output_free(this)
85 class(fld_file_output_t), intent(inout) :: this
86
87 call this%free_base()
88 call this%fields%free()
89
90 end subroutine fld_file_output_free
91
94 subroutine fld_file_output_sample(this, t)
95 class(fld_file_output_t), intent(inout) :: this
96 real(kind=rp), intent(in) :: t
97 integer :: i
98
99 if (neko_bcknd_device .eq. 1) then
100 associate(fields => this%fields%items)
101 do i = 1, size(fields)
102 call device_memcpy(fields(i)%ptr%x, fields(i)%ptr%x_d, &
103 fields(i)%ptr%dof%size(), device_to_host, &
104 sync = (i .eq. size(fields))) ! Sync on the last field
105 end do
106 end associate
107
108 end if
109
110 call this%file_%write(this%fields, t)
111
112 end subroutine fld_file_output_sample
113
114end module fld_file_output
Copy data between host and device (or device and device)
Definition device.F90:71
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_free(this)
Destructor.
subroutine fld_file_output_init(this, precision, name, nfields, path)
Constructor.
subroutine fld_file_output_sample(this, t)
Writes the data.
Build configurations.
integer, parameter neko_bcknd_device
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
A simple output saving a list of fields to a .fld file.
Abstract type defining an output type.
Definition output.f90:41