Neko 1.99.6
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
sigma_cpu.f90
Go to the documentation of this file.
1! Copyright (c) 2023-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!
37
39 use num_types, only : rp
40 use field_list, only : field_list_t
42 use registry, only : neko_registry
43 use field, only : field_t
44 use operators, only : dudxyz
45 use coefs, only : coef_t
46 use gs_ops, only : gs_op_add
47 use math, only : neko_eps, col2
48 implicit none
49 private
50
51 public :: sigma_compute_cpu
52
53contains
54
63 subroutine sigma_compute_cpu(if_ext, t, tstep, coef, nut, delta, c)
64 logical, intent(in) :: if_ext
65 real(kind=rp), intent(in) :: t
66 integer, intent(in) :: tstep
67 type(coef_t), intent(in) :: coef
68 type(field_t), intent(inout) :: nut
69 type(field_t), intent(in) :: delta
70 real(kind=rp), intent(in) :: c
71 ! This is the velocity gradient tensor
72 type(field_t), pointer :: g11, g12, g13, g21, g22, g23, g31, g32, g33
73 type(field_t), pointer :: u, v, w
74
75 real(kind=rp) :: sigg11, sigg12, sigg13, sigg22, sigg23, sigg33
76 real(kind=rp) :: sigma1, sigma2, sigma3
77 real(kind=rp) :: invariant1, invariant2, invariant3
78 real(kind=rp) :: alpha1, alpha2, alpha3
79 real(kind=rp) :: dsigma
80 real(kind=rp) :: pi_3 = 4.0_rp/3.0_rp*atan(1.0_rp)
81 real(kind=rp) :: tmp1
82 real(kind=rp) :: eps
83
84 integer :: temp_indices(9)
85 integer :: e, i
86
87 ! some constant
88 eps = neko_eps
89
90
91 ! get fields from registry
92 if (if_ext .eqv. .true.) then
93 u => neko_registry%get_field_by_name("u_e")
94 v => neko_registry%get_field_by_name("v_e")
95 w => neko_registry%get_field_by_name("w_e")
96 else
97 u => neko_registry%get_field_by_name("u")
98 v => neko_registry%get_field_by_name("v")
99 w => neko_registry%get_field_by_name("w")
100 end if
101
102 call neko_scratch_registry%request_field(g11, temp_indices(1), .false.)
103 call neko_scratch_registry%request_field(g12, temp_indices(2), .false.)
104 call neko_scratch_registry%request_field(g13, temp_indices(3), .false.)
105 call neko_scratch_registry%request_field(g21, temp_indices(4), .false.)
106 call neko_scratch_registry%request_field(g22, temp_indices(5), .false.)
107 call neko_scratch_registry%request_field(g23, temp_indices(6), .false.)
108 call neko_scratch_registry%request_field(g31, temp_indices(7), .false.)
109 call neko_scratch_registry%request_field(g32, temp_indices(8), .false.)
110 call neko_scratch_registry%request_field(g33, temp_indices(9), .false.)
111
112
113 ! Compute the derivatives of the velocity (the components of the g tensor)
114 call dudxyz (g11%x, u%x, coef%drdx, coef%dsdx, coef%dtdx, coef)
115 call dudxyz (g12%x, u%x, coef%drdy, coef%dsdy, coef%dtdy, coef)
116 call dudxyz (g13%x, u%x, coef%drdz, coef%dsdz, coef%dtdz, coef)
117
118 call dudxyz (g21%x, v%x, coef%drdx, coef%dsdx, coef%dtdx, coef)
119 call dudxyz (g22%x, v%x, coef%drdy, coef%dsdy, coef%dtdy, coef)
120 call dudxyz (g23%x, v%x, coef%drdz, coef%dsdz, coef%dtdz, coef)
121
122 call dudxyz (g31%x, w%x, coef%drdx, coef%dsdx, coef%dtdx, coef)
123 call dudxyz (g32%x, w%x, coef%drdy, coef%dsdy, coef%dtdy, coef)
124 call dudxyz (g33%x, w%x, coef%drdz, coef%dsdz, coef%dtdz, coef)
125
126 call coef%gs_h%op(g11, gs_op_add)
127 call coef%gs_h%op(g12, gs_op_add)
128 call coef%gs_h%op(g13, gs_op_add)
129 call coef%gs_h%op(g21, gs_op_add)
130 call coef%gs_h%op(g22, gs_op_add)
131 call coef%gs_h%op(g23, gs_op_add)
132 call coef%gs_h%op(g31, gs_op_add)
133 call coef%gs_h%op(g32, gs_op_add)
134 call coef%gs_h%op(g33, gs_op_add)
135
136 !$omp parallel do private(e, i, sigG11, sigG12, sigG13, sigG22, sigG23, &
137 !$omp& sigG33, sigma1, sigma2, sigma3, Invariant1, Invariant2, Invariant3, &
138 !$omp& alpha1, alpha2, alpha3, Dsigma, tmp1)
139 do e = 1, coef%msh%nelv
140 !OCL NORECURRENCE, NOVREC, NOALIAS
141 !DIR$ CONCURRENT
142 !DIR$ IVDEP
143 !GCC$ ivdep
144 do i = 1, coef%Xh%lxyz
145 ! G_ij = g^t g = g_mi g_mj
146 sigg11 = g11%x(i,1,1,e)**2 + g21%x(i,1,1,e)**2 + g31%x(i,1,1,e)**2
147 sigg22 = g12%x(i,1,1,e)**2 + g22%x(i,1,1,e)**2 + g32%x(i,1,1,e)**2
148 sigg33 = g13%x(i,1,1,e)**2 + g23%x(i,1,1,e)**2 + g33%x(i,1,1,e)**2
149 sigg12 = g11%x(i,1,1,e)*g12%x(i,1,1,e) + &
150 g21%x(i,1,1,e)*g22%x(i,1,1,e) + &
151 g31%x(i,1,1,e)*g32%x(i,1,1,e)
152 sigg13 = g11%x(i,1,1,e)*g13%x(i,1,1,e) + &
153 g21%x(i,1,1,e)*g23%x(i,1,1,e) + &
154 g31%x(i,1,1,e)*g33%x(i,1,1,e)
155 sigg23 = g12%x(i,1,1,e)*g13%x(i,1,1,e) + &
156 g22%x(i,1,1,e)*g23%x(i,1,1,e) + &
157 g32%x(i,1,1,e)*g33%x(i,1,1,e)
158
159 ! If LAPACK compute eigenvalues of the semi-definite positive matrix G
160 ! ..........to be done later on......
161 ! ELSE use the analytical method as done in the following
162
163 ! eigenvalues with the analytical method of Hasan et al. (2001)
164 ! doi:10.1006/jmre.2001.2400
165 if (abs(sigg11) .lt. eps) then
166 sigg11 = 0.0_rp
167 end if
168 if (abs(sigg12) .lt. eps) then
169 sigg12 = 0.0_rp
170 end if
171 if (abs(sigg13) .lt. eps) then
172 sigg13 = 0.0_rp
173 end if
174 if (abs(sigg22) .lt. eps) then
175 sigg22 = 0.0_rp
176 end if
177 if (abs(sigg23) .lt. eps) then
178 sigg23 = 0.0_rp
179 end if
180 if (abs(sigg33) .lt. eps) then
181 sigg33 = 0.0_rp
182 end if
183
184 if (abs(sigg12*sigg12 + &
185 sigg13*sigg13 + sigg23*sigg23) .lt. eps) then
186 ! G is diagonal
187 ! estimate the singular values according to:
188 sigma1 = sqrt(max(max(max(sigg11, sigg22), sigg33), 0.0_rp))
189 sigma3 = sqrt(max(min(min(sigg11, sigg22), sigg33), 0.0_rp))
190 invariant1 = sigg11 + sigg22 + sigg33
191 sigma2 = sqrt(abs(invariant1 - sigma1*sigma1 - sigma3*sigma3))
192 else
193
194 ! estimation of invariants
195 invariant1 = sigg11 + sigg22 + sigg33
196 invariant2 = sigg11*sigg22 + sigg11*sigg33 + sigg22*sigg33 - &
197 (sigg12*sigg12 + sigg13*sigg13 + sigg23*sigg23)
198 invariant3 = sigg11*sigg22*sigg33 + &
199 2.0_rp*sigg12*sigg13*sigg23 - &
200 (sigg11*sigg23*sigg23 + sigg22*sigg13*sigg13 + &
201 sigg33*sigg12*sigg12)
202
203 ! G is symmetric semi-definite positive matrix:
204 ! the invariants have to be larger-equal zero
205 ! which is obtained via forcing
206 invariant1 = max(invariant1, 0.0_rp)
207 invariant2 = max(invariant2, 0.0_rp)
208 invariant3 = max(invariant3, 0.0_rp)
209
210 ! compute the following angles from the invariants
211 alpha1 = invariant1*invariant1/9.0_rp - invariant2/3.0_rp
212
213 ! since alpha1 is always positive (see Hasan et al. (2001))
214 ! forcing is applied
215 alpha1 = max(alpha1, 0.0_rp)
216
217 alpha2 = invariant1*invariant1*invariant1/27.0_rp - &
218 invariant1*invariant2/6.0_rp + invariant3/2.0_rp
219
220 ! since acos(alpha2/(alpha1^(3/2)))/3.0_rp only valid for
221 ! alpha2^2 < alpha1^3.0_rp and arccos(x) only valid for -1<=x<=1
222 ! alpha3 is between 0 and pi/3
223 tmp1 = alpha2/sqrt(alpha1 * alpha1 * alpha1)
224
225 if (tmp1 .le. -1.0_rp) then
226 ! alpha3=pi/3 -> cos(alpha3)=0.5
227 ! compute the singular values
228 sigma1 = sqrt(max(invariant1/3.0_rp + sqrt(alpha1), 0.0_rp))
229 sigma2 = sigma1
230 sigma3 = sqrt(invariant1/3.0_rp - 2.0_rp*sqrt(alpha1))
231
232 elseif (tmp1 .ge. 1.0_rp) then
233 ! alpha3=0.0_rp -> cos(alpha3)=1.0
234 sigma1 = sqrt(max(invariant1/3.0_rp + 2.0_rp*sqrt(alpha1), &
235 0.0_rp))
236 sigma2 = sqrt(invariant1/3.0_rp - sqrt(alpha1))
237 sigma3 = sigma2
238 else
239 alpha3 = acos(tmp1)/3.0_rp
240
241 if (abs(invariant3) .lt. eps) then
242 ! In case of Invariant3=0, one or more eigenvalues are equal
243 ! to zero. Therefore force sigma3 to 0 and compute sigma1 and
244 ! sigma2
245 sigma1 = sqrt(max(invariant1/3.0_rp + &
246 2.0_rp*sqrt(alpha1)*cos(alpha3), 0.0_rp))
247 sigma2 = sqrt(abs(invariant1 - sigma1*sigma1))
248 sigma3 = 0.0_rp
249 else
250 sigma1 = sqrt(max(invariant1/3.0_rp + &
251 2.0_rp*sqrt(alpha1)*cos(alpha3), 0.0_rp))
252 sigma2 = sqrt(invariant1/3.0_rp - &
253 2.0_rp*sqrt(alpha1)*cos(pi_3 + alpha3))
254 sigma3 = sqrt(abs(invariant1 - &
255 sigma1*sigma1-sigma2*sigma2))
256 end if ! Invariant3=0 ?
257 end if ! tmp1
258 end if ! G diagonal ?
259
260 ! Estimate Dsigma
261 if (sigma1 .gt. 0.0_rp) then
262 dsigma = &
263 sigma3*(sigma1 - sigma2)*(sigma2 - sigma3)/(sigma1*sigma1)
264 else
265 dsigma = 0.0_rp
266 end if
267
268 !clipping to avoid negative values
269 dsigma = max(dsigma, 0.0_rp)
270
271 ! estimate turbulent viscosity
272
273 nut%x(i,1,1,e) = (c*delta%x(i,1,1,e))**2 * dsigma &
274 * coef%mult(i,1,1,1)
275
276 end do
277 end do
278 !$omp end parallel do
279
280 call coef%gs_h%op(nut, gs_op_add)
281 call col2(nut%x, coef%mult, nut%dof%size())
282
283 call neko_scratch_registry%relinquish_field(temp_indices)
284 end subroutine sigma_compute_cpu
285
286end module sigma_cpu
287
Compute derivative of a scalar field along a single direction.
Definition operators.f90:78
Coefficients.
Definition coef.f90:34
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
Definition math.f90:60
subroutine, public col2(a, b, n)
Vector multiplication .
Definition math.f90:1046
real(kind=rp), parameter, public neko_eps
Machine epsilon .
Definition math.f90:70
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
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:144
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.
Implements the CPU kernel for the sigma_t type. Following Nicoud et al. "Using singular values to bui...
Definition sigma_cpu.f90:38
subroutine, public sigma_compute_cpu(if_ext, t, tstep, coef, nut, delta, c)
Compute eddy viscosity on the CPU.
Definition sigma_cpu.f90:64
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:63
field_list_t, To be able to group fields together
#define max(a, b)
Definition tensor.cu:40