Neko 1.99.3
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
fluid_sgs_stats_output.f90
Go to the documentation of this file.
1! Copyright (c) 2026, 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!
37 use num_types, only : rp
38 use map_1d, only : map_1d_t
39 use map_2d, only : map_2d_t
42 use output, only : output_t
43 use matrix, only : matrix_t
44 use fld_file, only : fld_file_t
45 implicit none
46 private
47
50 type, public, extends(output_t) :: fluid_sgs_stats_output_t
52 type(fluid_sgs_stats_t), pointer :: stats => null()
57 real(kind=rp) :: t_begin
59 integer :: output_dim
60 contains
62 procedure, pass(this) :: init => fluid_sgs_stats_output_init
64 procedure, pass(this) :: free => fluid_sgs_stats_output_free
66 procedure, pass(this) :: sample => fluid_sgs_stats_output_sample
68
69
70contains
71
73 subroutine fluid_sgs_stats_output_init(this, stats, T_begin, &
74 hom_dir, name, path)
75 class(fluid_sgs_stats_output_t), intent(inout) :: this
76 type(fluid_sgs_stats_t), intent(inout), target :: stats
77 real(kind=rp), intent(in) :: t_begin
78 character(len=*), intent(in) :: hom_dir
79 character(len=*), intent(in), optional :: name
80 character(len=*), intent(in), optional :: path
81 character(len=1024) :: fname
82
83 if (trim(hom_dir) .eq. 'none' .or. &
84 trim(hom_dir) .eq. 'x' .or.&
85 trim(hom_dir) .eq. 'y' .or.&
86 trim(hom_dir) .eq. 'z'&
87 ) then
88 if (present(name) .and. present(path)) then
89 fname = trim(path) // trim(name) // '.fld'
90 else if (present(name)) then
91 fname = trim(name) // '.fld'
92 else if (present(path)) then
93 fname = trim(path) // 'fluid_sgs_stats.fld'
94 else
95 fname = 'fluid_sgs_stats.fld'
96 end if
97
98 this%output_dim = 3
99
100 if (trim(hom_dir) .eq. 'x' .or.&
101 trim(hom_dir) .eq. 'y' .or.&
102 trim(hom_dir) .eq. 'z' ) then
103 call this%map_2d%init_char(stats%coef, hom_dir, 1e-7_rp)
104 this%output_dim = 2
105 end if
106 else
107 if (present(name) .and. present(path)) then
108 fname = trim(path) // trim(name) // '.csv'
109 else if (present(name)) then
110 fname = trim(name) // '.csv'
111 else if (present(path)) then
112 fname = trim(path) // 'fluid_sgs_stats.csv'
113 else
114 fname = 'fluid_sgs_stats.csv'
115 end if
116 call this%map_1d%init_char(stats%coef, hom_dir, 1e-7_rp)
117 this%output_dim = 1
118 end if
119
120 call this%init_base(fname)
121 select type (ft => this%file_%file_type)
122 type is (fld_file_t)
123 ft%skip_pressure = .false.
124 ft%skip_velocity = .false.
125 ft%skip_temperature = .false.
126 end select
127 this%stats => stats
128 this%T_begin = t_begin
129 end subroutine fluid_sgs_stats_output_init
130
133 class(fluid_sgs_stats_output_t), intent(inout) :: this
134
135 call this%free_base()
136
137 nullify(this%stats)
138 call this%map_1d%free()
139 call this%map_2d%free()
140
141 end subroutine fluid_sgs_stats_output_free
142
145 class(fluid_sgs_stats_output_t), intent(inout) :: this
146 real(kind=rp), intent(in) :: t
147 integer :: i
148 type(matrix_t) :: avg_output_1d
149 type(fld_file_data_t) :: output_2d
150 real(kind=rp) :: u, v, w, p
151 associate(out_fields => this%stats%stat_fields%items)
152 if (t .ge. this%T_begin) then
153 if ( neko_bcknd_device .eq. 1) then
154 do i = 1, size(out_fields)
155 call device_memcpy(out_fields(i)%ptr%x, out_fields(i)%ptr%x_d,&
156 out_fields(i)%ptr%dof%size(), device_to_host, &
157 sync = (i .eq. size(out_fields))) ! Sync on last field
158 end do
159 end if
160 if (this%output_dim .eq. 1) then
161 call this%map_1d%average_planes(avg_output_1d, &
162 this%stats%stat_fields)
163 call this%file_%write(avg_output_1d, t)
164 else if (this%output_dim .eq. 2) then
165 call this%map_2d%average(output_2d, this%stats%stat_fields)
166 !Switch around fields to get correct orders
167 do i = 1, this%map_2d%n_2d
168 u = output_2d%v%x(i)
169 v = output_2d%w%x(i)
170 w = output_2d%p%x(i)
171 p = output_2d%u%x(i)
172 output_2d%p%x(i) = p
173 output_2d%u%x(i) = u
174 output_2d%v%x(i) = v
175 output_2d%w%x(i) = w
176 end do
177
178 call this%file_%write(output_2d, t)
179 else
180 call this%file_%write(this%stats%stat_fields, t)
181 end if
182 call this%stats%reset()
183 end if
184 end associate
185 end subroutine fluid_sgs_stats_output_sample
186
187end module fluid_sgs_stats_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
Simple module to handle fld file series. Provides an interface to the different fields sotred in a fl...
NEKTON fld file format.
Definition fld_file.f90:35
Implements fluid_sgs_stats_ouput_t.
subroutine fluid_sgs_stats_output_free(this)
Destructor.
subroutine fluid_sgs_stats_output_init(this, stats, t_begin, hom_dir, name, path)
Constructor.
subroutine fluid_sgs_stats_output_sample(this, t)
Sample fluid_sgs_stats at time t.
Computes the subgrid-scale contributions for Reynolds stresses. We use the Reynolds decomposition for...
Creates a 1d GLL point map along a specified direction based on the connectivity in the mesh.
Definition map_1d.f90:3
Maps a 3D dofmap to a 2D spectral element grid.
Definition map_2d.f90:3
Defines a matrix.
Definition matrix.f90:34
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
Defines a container for all statistics.
Interface for NEKTON fld files.
Definition fld_file.f90:66
Defines an output for the sgs statistics for fluid computed using the fluid_sgs_stats_t object.
Type that encapsulates a mapping from each gll point in the mesh to its corresponding (global) GLL po...
Definition map_1d.f90:27
Abstract type defining an output type.
Definition output.f90:41