Neko 1.99.9
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
scalar_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, dp
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) :: scalar_sgs_stats_output_t
52 type(scalar_sgs_stats_t), pointer :: stats => null()
57 real(kind=dp) :: t_begin
59 integer :: output_dim
60 contains
62 procedure, pass(this) :: init => scalar_sgs_stats_output_init
64 procedure, pass(this) :: free => scalar_sgs_stats_output_free
66 procedure, pass(this) :: sample => scalar_sgs_stats_output_sample
68 procedure, pass(this) :: configure_file => &
71
72
73contains
74
76 subroutine scalar_sgs_stats_output_init(this, stats, T_begin, &
77 hom_dir, name, path)
78 class(scalar_sgs_stats_output_t), intent(inout) :: this
79 type(scalar_sgs_stats_t), intent(inout), target :: stats
80 real(kind=dp), intent(in) :: t_begin
81 character(len=*), intent(in) :: hom_dir
82 character(len=*), intent(in), optional :: name
83 character(len=*), intent(in), optional :: path
84 character(len=1024) :: fname
85
86 if (trim(hom_dir) .eq. 'none' .or. &
87 trim(hom_dir) .eq. 'x' .or.&
88 trim(hom_dir) .eq. 'y' .or.&
89 trim(hom_dir) .eq. 'z'&
90 ) then
91 if (present(name) .and. present(path)) then
92 fname = trim(path) // trim(name) // '.fld'
93 else if (present(name)) then
94 fname = trim(name) // '.fld'
95 else if (present(path)) then
96 fname = trim(path) // 'scalar_sgs_stats.fld'
97 else
98 fname = 'scalar_sgs_stats.fld'
99 end if
100
101 this%output_dim = 3
102
103 if (trim(hom_dir) .eq. 'x' .or.&
104 trim(hom_dir) .eq. 'y' .or.&
105 trim(hom_dir) .eq. 'z' ) then
106 call this%map_2d%init_char(stats%coef, hom_dir, 1e-7_rp)
107 this%output_dim = 2
108 end if
109 else
110 if (present(name) .and. present(path)) then
111 fname = trim(path) // trim(name) // '.csv'
112 else if (present(name)) then
113 fname = trim(name) // '.csv'
114 else if (present(path)) then
115 fname = trim(path) // 'scalar_sgs_stats.csv'
116 else
117 fname = 'scalar_sgs_stats.csv'
118 end if
119 call this%map_1d%init_char(stats%coef, hom_dir, 1e-7_rp)
120 this%output_dim = 1
121 end if
122
123 call this%init_base(fname)
124 this%stats => stats
125 this%T_begin = t_begin
126 end subroutine scalar_sgs_stats_output_init
127
130 class(scalar_sgs_stats_output_t), intent(inout) :: this
131
132 call this%free_base()
133
134 nullify(this%stats)
135 call this%map_1d%free()
136 call this%map_2d%free()
137
138 end subroutine scalar_sgs_stats_output_free
139
142 class(scalar_sgs_stats_output_t), intent(inout) :: this
143 real(kind=dp), intent(in) :: t
144 integer :: i
145 type(matrix_t) :: avg_output_1d
146 type(fld_file_data_t) :: output_2d
147 real(kind=rp) :: u, v, w, p
148 associate(out_fields => this%stats%stat_fields%items)
149 if (t .ge. this%T_begin) then
150 if ( neko_bcknd_device .eq. 1) then
151 do i = 1, size(out_fields)
152 call device_memcpy(out_fields(i)%ptr%x, out_fields(i)%ptr%x_d,&
153 out_fields(i)%ptr%dof%size(), device_to_host, &
154 sync = (i .eq. size(out_fields))) ! Sync on last field
155 end do
156 end if
157 if (this%output_dim .eq. 1) then
158 call this%map_1d%average_planes(avg_output_1d, &
159 this%stats%stat_fields)
160 call this%file_%write(avg_output_1d, t)
161 call avg_output_1d%free()
162 else if (this%output_dim .eq. 2) then
163 call this%map_2d%average(output_2d, this%stats%stat_fields)
164 !Switch around fields to get correct orders
165 do i = 1, this%map_2d%n_2d
166 u = output_2d%v%x(i)
167 v = output_2d%w%x(i)
168 w = output_2d%p%x(i)
169 p = output_2d%u%x(i)
170 output_2d%p%x(i) = p
171 output_2d%u%x(i) = u
172 output_2d%v%x(i) = v
173 output_2d%w%x(i) = w
174 end do
175
176 call this%file_%write(output_2d, t)
177 call output_2d%free()
178 else
179 call this%file_%write(this%stats%stat_fields, t)
180 end if
181 call this%stats%reset()
182 end if
183 end associate
184 end subroutine scalar_sgs_stats_output_sample
185
186
190 class(scalar_sgs_stats_output_t), intent(inout) :: this
191
192 select type (ft => this%file_%file_type)
193 type is (fld_file_t)
194 ft%skip_pressure = .false.
195 ft%skip_velocity = .false.
196 ft%skip_temperature = .false.
197 end select
198
200
Copy data between host and device (or device and device)
Definition device.F90:72
Device abstraction, common interface for various accelerators.
Definition device.F90:34
integer, parameter, public device_to_host
Definition device.F90:48
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
Creates a 1d GLL point map along a specified direction based on the connectivity in the mesh.
Definition map_1d.f90:36
Maps a 3D dofmap to a 2D spectral element grid.
Definition map_2d.f90:36
Defines a matrix.
Definition matrix.f90:34
Build configurations.
integer, parameter neko_bcknd_device
integer, parameter, public dp
Definition num_types.f90:10
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:14
Defines an output.
Definition output.f90:34
Implements scalar_sgs_stats_ouput_t.
subroutine scalar_sgs_stats_output_configure_file(this)
Puts the leading fields in the UVW, P and T slots rather than the scalar block.
subroutine scalar_sgs_stats_output_free(this)
Destructor.
subroutine scalar_sgs_stats_output_sample(this, t)
Sample scalar_sgs_stats at time t.
subroutine scalar_sgs_stats_output_init(this, stats, t_begin, hom_dir, name, path)
Constructor.
Computes the subgrid-scale contributions for the scalar fluxes. We use the Reynolds decomposition for...
Defines a container for all statistics.
Interface for NEKTON fld files.
Definition fld_file.f90:66
Map every GLL point in the mesh to a level in one physical direction. Can be used to average across t...
Definition map_1d.f90:96
Abstract type defining an output type.
Definition output.f90:41
Defines an output for the sgs statistics for scalar computed using the scalar_sgs_stats_t object.