Neko 1.99.9
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
mean_field_output.f90
Go to the documentation of this file.
1! Copyright (c) 2020-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!
35 use num_types, only : dp, rp
36 use field_list, only : field_list_t
39 use map_2d, only : map_2d_t
40 use map_1d, only : map_1d_t
41 use coefs, only : coef_t
43 use mean_field, only : mean_field_t
44 use output, only : output_t
45 use matrix, only : matrix_t
46 use fld_file, only : fld_file_t
47 implicit none
48 private
49
51 type, public, extends(output_t) :: mean_field_output_t
53 type(mean_field_t), pointer :: mean_fields(:)
55 type(field_list_t) :: fields
57 real(kind=dp) :: start_time = 0.0_dp
59 integer :: n_fields = 0
65 integer :: output_dim = 0
66 contains
68 procedure, pass(this) :: init => mean_field_output_init
70 procedure, pass(this) :: free => mean_field_output_free
72 procedure, pass(this) :: sample => mean_field_output_sample
74 procedure, pass(this) :: configure_file => &
76 end type mean_field_output_t
77
78contains
79
89 subroutine mean_field_output_init(this, mean_fields, n_fields, start_time, &
90 coef, avg_dir, name, path)
91 class(mean_field_output_t), intent(inout):: this
92 integer, intent(in) :: n_fields
93 type(mean_field_t), intent(inout), target :: mean_fields(n_fields)
94 type(coef_t), intent(inout) :: coef
95 character(len=*), intent(in) :: avg_dir
96 character(len=*), intent(in), optional :: name
97 character(len=*), intent(in), optional :: path
98 real(kind=dp), intent(in) :: start_time
99 character(len=1024) :: fname
100 integer :: i
101
102 this%start_time = start_time
103
104 if (trim(avg_dir) .eq. 'none' .or. &
105 trim(avg_dir) .eq. 'x' .or.&
106 trim(avg_dir) .eq. 'y' .or.&
107 trim(avg_dir) .eq. 'z'&
108 ) then
109 if (present(name) .and. present(path)) then
110 fname = trim(path) // trim(name) // '.fld'
111 else if (present(name)) then
112 fname = trim(name) // '.fld'
113 else if (present(path)) then
114 fname = trim(path) // 'user_stats.fld'
115 else
116 fname = 'user_stats.fld'
117 end if
118
119 this%output_dim = 3
120
121 if (trim(avg_dir) .eq. 'x' .or.&
122 trim(avg_dir) .eq. 'y' .or.&
123 trim(avg_dir) .eq. 'z' ) then
124 call this%map_2d%init_char(coef, avg_dir, 1e-7_rp)
125 this%output_dim = 2
126 end if
127 else
128 if (present(name) .and. present(path)) then
129 fname = trim(path) // trim(name) // '.csv'
130 else if (present(name)) then
131 fname = trim(name) // '.csv'
132 else if (present(path)) then
133 fname = trim(path) // 'user_stats.csv'
134 else
135 fname = 'user_stats.csv'
136 end if
137 call this%map_1d%init_char(coef, avg_dir, 1e-7_rp)
138 this%output_dim = 1
139 end if
140
141 call this%init_base(fname)
142 call this%fields%init(n_fields)
143 this%n_fields = n_fields
144 this%mean_fields => mean_fields
145 do i = 1, n_fields
146 this%fields%items(i)%ptr => this%mean_fields(i)%mf
147 end do
148
149 end subroutine mean_field_output_init
150
152 subroutine mean_field_output_free(this)
153 class(mean_field_output_t), intent(inout) :: this
154
155 call this%free_base()
156
157 nullify(this%mean_fields)
158 call this%map_1d%free()
159 call this%map_2d%free()
160 call this%fields%free()
161
162 end subroutine mean_field_output_free
163
165 subroutine mean_field_output_sample(this, t)
166 class(mean_field_output_t), intent(inout) :: this
167 real(kind=dp), intent(in) :: t
168 integer :: i
169 type(fld_file_data_t) :: output_2d
170 type(matrix_t) :: avg_output_1d
171
172 associate(out_fields => this%fields%items)
173 if (t .ge. this%start_time) then
174 if ( neko_bcknd_device .eq. 1) then
175 do i = 1, size(out_fields)
176 call device_memcpy(out_fields(i)%ptr%x, out_fields(i)%ptr%x_d,&
177 out_fields(i)%ptr%dof%size(), device_to_host, &
178 sync = (i .eq. size(out_fields))) ! Sync on last field
179 end do
180 end if
181 if (this%output_dim .eq. 1) then
182 call this%map_1d%average_planes(avg_output_1d, &
183 this%fields)
184 call this%file_%write(avg_output_1d, t)
185 call avg_output_1d%free()
186 else if (this%output_dim .eq. 2) then
187 call this%map_2d%average(output_2d, this%fields)
188 call this%file_%write(output_2d, t)
189 call output_2d%free()
190 else
191 call this%file_%write(this%fields, t)
192 end if
193 do i = 1, this%n_fields
194 call this%mean_fields(i)%reset()
195 end do
196 end if
197 end associate
198
199 end subroutine mean_field_output_sample
200
204 class(mean_field_output_t), intent(inout) :: this
205
206 select type (ft => this%file_%file_type)
207 type is (fld_file_t)
208 ft%skip_pressure = .false.
209 ft%skip_velocity = .false.
210 ft%skip_temperature = .false.
211 end select
212
214
215end module mean_field_output
Copy data between host and device (or device and device)
Definition device.F90:72
Coefficients.
Definition coef.f90:34
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
Defines an output for a list of mean fields.
subroutine mean_field_output_configure_file(this)
Puts the leading fields in the UVW, P and T slots rather than the scalar block.
subroutine mean_field_output_free(this)
Destructor.
subroutine mean_field_output_init(this, mean_fields, n_fields, start_time, coef, avg_dir, name, path)
Constructor.
subroutine mean_field_output_sample(this, t)
Sample the mean solution at time t and reset.
Implements mean_field_t.
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
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:136
field_list_t, To be able to group fields together
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
Computes the temporal mean of a field.
Output for a list of mean fields.
Abstract type defining an output type.
Definition output.f90:41