Neko 1.99.11
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
dynamic_smagorinsky_device.f90
Go to the documentation of this file.
1! Copyright (c) 2024, 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!
33!> Implements the device kernel for the `dynamic_smagorinsky_t` type.
35 use num_types, only : rp
36 use field_list, only : field_list_t
38 use registry, only : neko_registry
39 use field, only : field_t
40 use operators, only : strain_rate
41 use coefs, only : coef_t
43 use gs_ops, only : gs_op_add
44 use device, only : glb_cmd_event
45 use device_math, only : device_col2
49 implicit none
50 private
51
53
54contains
55
56 !> Compute eddy viscosity on the device.
57 !! @param if_ext If extrapolate the velocity field to evaluate
58 !! @param t The time value.
59 !! @param tstep The current time-step.
60 !! @param coef SEM coefficients.
61 !! @param nut The SGS viscosity array.
62 !! @param delta The LES lengthscale.
63 !! @param c_dyn The DS model coefficient
64 !! @param test_filter
65 !! @param mij
66 !! @param lij The Germano identity.
67 !! @param num The numerator in the expression of c_dyn, i.e. <mij*lij>
68 !! @param den The denominator in the expression of c_dyn, i.e. <mij*mij>
69 subroutine dynamic_smagorinsky_compute_device(if_ext, t, tstep, coef, nut, &
70 delta, c_dyn, test_filter, mij, lij, num, den)
71 logical, intent(in) :: if_ext
72 real(kind=rp), intent(in) :: t
73 integer, intent(in) :: tstep
74 type(coef_t), intent(in) :: coef
75 type(field_t), intent(inout) :: nut
76 type(field_t), intent(in) :: delta
77 type(field_t), intent(inout) :: c_dyn
78 type(elementwise_filter_t), intent(inout) :: test_filter
79 type(field_t), intent(inout) :: mij(6), lij(6)
80 type(field_t), intent(inout) :: num, den
81
82 type(field_t), pointer :: u, v, w
83 type(field_t) :: c_dyn_curr
84 ! the strain rate tensor
85 type(field_t), pointer :: s11, s22, s33, s12, s13, s23, s_abs
86 real(kind=rp) :: alpha ! running averaging coefficient
87 integer :: tmp_indices(7)
88 integer :: i
89
90 if (tstep .eq. 1) then
91 alpha = 0.0_rp
92 else
93 alpha = 0.9_rp
94 end if
95
96 if (if_ext .eqv. .true.) then
97 u => neko_registry%get_field_by_name("u_e")
98 v => neko_registry%get_field_by_name("v_e")
99 w => neko_registry%get_field_by_name("w_e")
100 else
101 u => neko_registry%get_field_by_name("u")
102 v => neko_registry%get_field_by_name("v")
103 w => neko_registry%get_field_by_name("w")
104 end if
105
106 call neko_scratch_registry%request_field(s11, tmp_indices(1), .false.)
107 call neko_scratch_registry%request_field(s22, tmp_indices(2), .false.)
108 call neko_scratch_registry%request_field(s33, tmp_indices(3), .false.)
109 call neko_scratch_registry%request_field(s12, tmp_indices(4), .false.)
110 call neko_scratch_registry%request_field(s13, tmp_indices(5), .false.)
111 call neko_scratch_registry%request_field(s23, tmp_indices(6), .false.)
112 call neko_scratch_registry%request_field(s_abs, tmp_indices(7), .false.)
113
114 ! Compute the strain rate tensor
115 call strain_rate(s11%x_d, s22%x_d, s33%x_d, s12%x_d, s13%x_d, s23%x_d, &
116 u%x_d, v%x_d, w%x_d, coef)
117
118 call coef%gs_h%op(s11%x, s22%x, s33%x, s11%dof%size(), gs_op_add, &
120 call coef%gs_h%op(s12%x, s13%x, s23%x, s12%dof%size(), gs_op_add, &
122
123 call device_col2(s11%x_d, coef%mult_d, s11%dof%size())
124 call device_col2(s22%x_d, coef%mult_d, s22%dof%size())
125 call device_col2(s33%x_d, coef%mult_d, s33%dof%size())
126 call device_col2(s12%x_d, coef%mult_d, s12%dof%size())
127 call device_col2(s13%x_d, coef%mult_d, s13%dof%size())
128 call device_col2(s23%x_d, coef%mult_d, s23%dof%size())
129
130 call device_s_abs_compute(s_abs%x_d, s11%x_d, s22%x_d, s33%x_d, &
131 s12%x_d, s13%x_d, s23%x_d, &
132 s11%dof%size())
133
134 call compute_lij_device(lij, u, v, w, test_filter, u%dof%size())
135 call compute_nut_device(nut, c_dyn, num, den, lij, mij, &
136 s11, s22, s33, s12, s13, s23, &
137 s_abs, test_filter, delta, alpha, &
138 coef, u%dof%size())
139
140 call coef%gs_h%op(nut, gs_op_add, glb_cmd_event)
141 call device_col2(nut%x_d, coef%mult_d, nut%dof%size())
142
143 call neko_scratch_registry%relinquish_field(tmp_indices)
145
146 !> Compute Germano Identity on the device.
147 !! ___ ___ _______
148 !! L_ij = u_i*u_j - u_i*u_j
149 !! @param lij The Germano identity.
150 !! @param u x-velocity resolved (only filtered once)
151 !! @param v y-velocity resolved (only filtered once)
152 !! @param w z-velocity resolved (only filtered once)
153 !! @param test_filter
154 !! @param n
155 subroutine compute_lij_device(lij, u, v, w, test_filter, n)
156 type(field_t), intent(inout) :: lij(6)
157 type(field_t), pointer, intent(in) :: u, v, w
158 type(elementwise_filter_t), intent(inout) :: test_filter
159 integer, intent(in) :: n
160 integer :: i
161 !> filtered u,v,w by the test filter
162 type(field_t), pointer :: fu, fv, fw, fuu, fvv, fww, fuv, fuw, fvw
163 integer :: tmp_indices(9)
164
165 call neko_scratch_registry%request_field(fu, tmp_indices(1), .false.)
166 call neko_scratch_registry%request_field(fv, tmp_indices(2), .false.)
167 call neko_scratch_registry%request_field(fw, tmp_indices(3), .false.)
168 call neko_scratch_registry%request_field(fuu, tmp_indices(4), .false.)
169 call neko_scratch_registry%request_field(fvv, tmp_indices(5), .false.)
170 call neko_scratch_registry%request_field(fww, tmp_indices(6), .false.)
171 call neko_scratch_registry%request_field(fuv, tmp_indices(7), .false.)
172 call neko_scratch_registry%request_field(fuw, tmp_indices(8), .false.)
173 call neko_scratch_registry%request_field(fvw, tmp_indices(9), .false.)
174
175 ! Use test filter for the velocity fields
176 call test_filter%apply(fu, u)
177 call test_filter%apply(fv, v)
178 call test_filter%apply(fw, w)
179
180 !! ___ ___
181 !! Compute u_i*u_j and u_i*u_j
182 call device_lij_compute_part1(lij(1)%x_d, lij(2)%x_d, lij(3)%x_d, &
183 lij(4)%x_d, lij(5)%x_d, lij(6)%x_d, &
184 u%x_d, v%x_d, w%x_d, &
185 fu%x_d, fv%x_d, fw%x_d, &
186 fuu%x_d, fvv%x_d, fww%x_d, &
187 fuv%x_d, fuw%x_d, fvw%x_d, n)
188
189 !! Filter u_i*u_j by the test filter
190 call test_filter%apply(fuu, fuu)
191 call test_filter%apply(fvv, fvv)
192 call test_filter%apply(fww, fww)
193 call test_filter%apply(fuv, fuv)
194 call test_filter%apply(fuw, fuw)
195 call test_filter%apply(fvw, fvw)
196
197 !! Assember the final form
198 !! ___ ___ _______
199 !! L_ij = u_i*u_j - u_i*u_j
200 call device_lij_compute_part2(lij(1)%x_d, lij(2)%x_d, lij(3)%x_d, &
201 lij(4)%x_d, lij(5)%x_d, lij(6)%x_d, &
202 fuu%x_d, fvv%x_d, fww%x_d, &
203 fuv%x_d, fuw%x_d, fvw%x_d, n)
204 call neko_scratch_registry%relinquish_field(tmp_indices)
205 end subroutine compute_lij_device
206
207 !> Compute M_ij and nut on the device.
208 !! _____ ____ __________
209 !! M_ij = ((delta_test/delta)^2 s_abs*s_ij - s_abs*s_ij)*(delta^2)
210 !! @param nut The SGS viscosity array
211 !! @param c_dyn The DS model coefficient
212 !! @param num The numerator in the expression of c_dyn, i.e. <mij*lij>
213 !! @param den The denominator in the expression of c_dyn, i.e. <mij*mij>
214 !! @param lij The Germano identity
215 !! @param Mij
216 !! @param s11
217 !! @param s22
218 !! @param s33
219 !! @param s12
220 !! @param s13
221 !! @param s23
222 !! @param s_abs
223 !! @param test_filter
224 !! @param delta The filter size
225 !! @param alpha The moving average coefficient
226 !! @param n
227 subroutine compute_nut_device(nut, c_dyn, num, den, lij, mij, &
228 s11, s22, s33, s12, s13, s23, &
229 s_abs, test_filter, delta, alpha, &
230 coef, n)
231 type(field_t), intent(inout) :: nut, c_dyn
232 type(field_t), intent(inout) :: num, den
233 type(field_t), intent(in) :: lij(6)
234 type(field_t), intent(inout) :: mij(6)
235 type(field_t), intent(inout) :: s11, s22, s33, s12, s13, s23, s_abs
236 type(elementwise_filter_t), intent(inout) :: test_filter
237 type(field_t), intent(in) :: delta
238 real(kind=rp), intent(in) :: alpha
239 type(coef_t), intent(in) :: coef
240 integer, intent(in) :: n
241
242 real(kind=rp) :: delta_ratio2
243 integer :: tmp_indices(12)
244 type(field_t), pointer :: fs11, fs22, fs33, fs12, fs13, fs23, &
245 fsabss11, fsabss22, fsabss33, &
246 fsabss12, fsabss13, fsabss23
247
248 delta_ratio2 = ((test_filter%nx-1.0_rp)/(test_filter%nt-1.0_rp))**2
249
250 call neko_scratch_registry%request_field(fs11, tmp_indices(1), .false.)
251 call neko_scratch_registry%request_field(fs22, tmp_indices(2), .false.)
252 call neko_scratch_registry%request_field(fs33, tmp_indices(3), .false.)
253 call neko_scratch_registry%request_field(fs12, tmp_indices(4), .false.)
254 call neko_scratch_registry%request_field(fs13, tmp_indices(5), .false.)
255 call neko_scratch_registry%request_field(fs23, tmp_indices(6), .false.)
256 call neko_scratch_registry%request_field(fsabss11, tmp_indices(7), .false.)
257 call neko_scratch_registry%request_field(fsabss22, tmp_indices(8), .false.)
258 call neko_scratch_registry%request_field(fsabss33, tmp_indices(9), .false.)
259 call neko_scratch_registry%request_field(fsabss12, tmp_indices(10), .false.)
260 call neko_scratch_registry%request_field(fsabss13, tmp_indices(11), .false.)
261 call neko_scratch_registry%request_field(fsabss23, tmp_indices(12), .false.)
262
263 !! Compute M_ij
264 !! Compute the test-filtered strain tensor
265 call test_filter%apply(fs11, s11)
266 call test_filter%apply(fs22, s22)
267 call test_filter%apply(fs33, s33)
268 call test_filter%apply(fs12, s12)
269 call test_filter%apply(fs13, s13)
270 call test_filter%apply(fs23, s23)
271
272 !! Compute delta_test**2 |S_test| S_ij_test and delta**2 |S| S_ij
273 call device_mij_compute_part1(mij(1)%x_d, mij(2)%x_d, mij(3)%x_d, &
274 mij(4)%x_d, mij(5)%x_d, mij(6)%x_d, &
275 s_abs%x_d, s11%x_d, s22%x_d, s33%x_d, &
276 s12%x_d, s13%x_d, s23%x_d, &
277 delta%x_d, fs11%x_d, fs22%x_d, fs33%x_d, &
278 fs12%x_d, fs13%x_d, fs23%x_d, &
279 fsabss11%x_d, fsabss22%x_d, fsabss33%x_d, &
280 fsabss12%x_d, fsabss13%x_d, fsabss23%x_d, &
281 delta_ratio2, n)
282
283 !! Filter delta**2 |S| S_ij by the test filter
284 call test_filter%apply(fsabss11, fsabss11)
285 call test_filter%apply(fsabss22, fsabss22)
286 call test_filter%apply(fsabss33, fsabss33)
287 call test_filter%apply(fsabss12, fsabss12)
288 call test_filter%apply(fsabss13, fsabss13)
289 call test_filter%apply(fsabss23, fsabss23)
290
291 !! Finalise the compute of Mij and nut
292 call device_mij_nut_compute_part2(mij(1)%x_d, mij(2)%x_d, mij(3)%x_d, &
293 mij(4)%x_d, mij(5)%x_d, mij(6)%x_d, &
294 lij(1)%x_d, lij(2)%x_d, lij(3)%x_d, &
295 lij(4)%x_d, lij(5)%x_d, lij(6)%x_d, &
296 fsabss11%x_d, fsabss22%x_d, fsabss33%x_d, &
297 fsabss12%x_d, fsabss13%x_d, fsabss23%x_d, &
298 num%x_d, den%x_d, c_dyn%x_d, delta%x_d, &
299 s_abs%x_d, nut%x_d, alpha, n)
300 call neko_scratch_registry%relinquish_field(tmp_indices)
301 end subroutine compute_nut_device
302
304
Compute the strain rate tensor of a vector field.
Coefficients.
Definition coef.f90:34
subroutine, public device_lij_compute_part1(l11_d, l22_d, l33_d, l12_d, l13_d, l23_d, u_d, v_d, w_d, fu_d, fv_d, fw_d, fuu_d, fvv_d, fww_d, fuv_d, fuw_d, fvw_d, n)
part 1 of the computing of the lij field
subroutine, public device_mij_nut_compute_part2(m11_d, m22_d, m33_d, m12_d, m13_d, m23_d, l11_d, l22_d, l33_d, l12_d, l13_d, l23_d, fsabss11_d, fsabss22_d, fsabss33_d, fsabss12_d, fsabss13_d, fsabss23_d, num_d, den_d, c_dyn_d, delta_d, s_abs_d, nut_d, alpha, n)
part 1 of the computing of the mij field
subroutine, public device_mij_compute_part1(m11_d, m22_d, m33_d, m12_d, m13_d, m23_d, s_abs_d, s11_d, s22_d, s33_d, s12_d, s13_d, s23_d, delta_d, fs11_d, fs22_d, fs33_d, fs12_d, fs13_d, fs23_d, fsabss11_d, fsabss22_d, fsabss33_d, fsabss12_d, fsabss13_d, fsabss23_d, delta_ratio2, n)
part 1 of the computing of the mij field
subroutine, public device_s_abs_compute(s_abs_d, s11_d, s22_d, s33_d, s12_d, s13_d, s23_d, n)
Compute the s_abs field for the Sigma model indevice.
subroutine, public device_lij_compute_part2(l11_d, l22_d, l33_d, l12_d, l13_d, l23_d, fuu_d, fvv_d, fww_d, fuv_d, fuw_d, fvw_d, n)
part 2 of the computing of the lij field
subroutine, public device_col2(a_d, b_d, n, strm)
Vector multiplication .
Device abstraction, common interface for various accelerators.
Definition device.F90:34
type(c_ptr), bind(C), public glb_cmd_event
Event for the global command queue.
Definition device.F90:63
Implements the device kernel for the dynamic_smagorinsky_t type.
subroutine, public dynamic_smagorinsky_compute_device(if_ext, t, tstep, coef, nut, delta, c_dyn, test_filter, mij, lij, num, den)
Compute eddy viscosity on the device.
subroutine compute_nut_device(nut, c_dyn, num, den, lij, mij, s11, s22, s33, s12, s13, s23, s_abs, test_filter, delta, alpha, coef, n)
Compute M_ij and nut on the device.
subroutine compute_lij_device(lij, u, v, w, test_filter, n)
Compute Germano Identity on the device.
Implements elementwise_filter_t.
Defines a field.
Definition field.f90:34
Defines Gather-scatter operations.
Definition gs_ops.f90:34
integer, parameter, public gs_op_add
Definition gs_ops.f90:36
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:14
Operators.
Definition operators.f90:34
Defines a registry for storing solution fields.
Definition registry.f90:34
type(registry_t), target, public neko_registry
Global field registry.
Definition registry.f90:158
Defines a registry for storing and requesting temporary objects This can be used when you have a func...
type(scratch_registry_t), target, public neko_scratch_registry
Global scratch registry.
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:136
Implements the elementwise filter for SEM.
field_list_t, To be able to group fields together