Neko 1.99.7
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
lambda2_kernel.h
Go to the documentation of this file.
1#ifndef __MATH_LAMBDA2_KERNEL_H__
2#define __MATH_LAMBDA2_KERNEL_H__
3
4#include "elem_block.h"
5/*
6 Copyright (c) 2021-2023, The Neko Authors
7 All rights reserved.
8
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions
11 are met:
12
13 * Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
15
16 * Redistributions in binary form must reproduce the above
17 copyright notice, this list of conditions and the following
18 disclaimer in the documentation and/or other materials provided
19 with the distribution.
20
21 * Neither the name of the authors nor the names of its
22 contributors may be used to endorse or promote products derived
23 from this software without specific prior written permission.
24
25 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 POSSIBILITY OF SUCH DAMAGE.
37*/
38
44
45template< typename T>
48 T grad31, T grad32, T grad33) {
49 T s11 = grad11;
50 T s22 = grad22;
51 T s33 = grad33;
52 T s12 = 0.5*(grad12+grad21);
53 T s13 = 0.5*(grad13+grad31);
54 T s23 = 0.5*(grad23+grad32);
55
56 T o12 = 0.5*(grad12-grad21);
57 T o13 = 0.5*(grad13-grad31);
58 T o23 = 0.5*(grad23-grad32);
59
60 T a11 = s11*s11 + s12*s12 + s13*s13 - o12*o12 - o13*o13;
61 T a12 = s11 * s12 + s12 * s22 + s13 * s23 - o13 * o23;
62 T a13 = s11 * s13 + s12 * s23 + s13 * s33 + o12 * o23;
63
64 T a22 = s12*s12 + s22*s22 + s23*s23 - o12*o12 - o23*o23;
65 T a23 = s12 * s13 + s22 * s23 + s23 * s33 - o12 * o13;
66 T a33 = s13*s13 + s23*s23 + s33*s33 - o13*o13 - o23*o23;
67
68
69 T B = -(a11 + a22 + a33);
70 T C = -(a12*a12 + a13*a13 + a23*a23 - a11 * a22 - a11 * a33 - a22 * a33);
71 T D = -(2.0 * a12 * a13 * a23 - a11 * a23*a23 - a22 * a13*a13
72 - a33 * a12*a12 + a11 * a22 * a33);
73
74
75 T q = (3.0 * C - B*B) / 9.0;
76 T r = (9.0 * C * B - 27.0 * D - 2.0 * B*B*B) / 54.0;
77
78 T theta = acos( r / sqrt(-q*q*q) );
79 T pi = 4.0*atan(1.0);
80 T eigen1 = 2.0 * sqrt(-q) * cos(theta / 3.0) - B / 3.0;
81 T eigen2 = 2.0 * sqrt(-q) * cos((theta + 2.0 * pi) / 3.0) - B / 3.0;
82 T eigen3 = 2.0 * sqrt(-q) * cos((theta + 4.0 * pi) / 3.0) - B / 3.0;
83
84 if (eigen1 <= eigen2 && eigen2 <= eigen3)
85 return eigen2;
86 else if (eigen3 <= eigen2 && eigen2 <= eigen1)
87 return eigen2;
88 else if (eigen1 <= eigen3 && eigen3 <= eigen2)
89 return eigen3;
90 else if (eigen2 <= eigen3 && eigen3 <= eigen1)
91 return eigen3;
92 else if (eigen2 <= eigen1 && eigen1 <= eigen3)
93 return eigen1;
94 else if (eigen3 <= eigen1 && eigen1 <= eigen2)
95 return eigen1;
96 return 0.0;
97}
98
99
100template< typename T, const int LX, const int CHUNKS >
102 const T * __restrict__ u,
103 const T * __restrict__ v,
104 const T * __restrict__ w,
105 const T * __restrict__ dx,
106 const T * __restrict__ dy,
107 const T * __restrict__ dz,
108 const T * __restrict__ drdx,
109 const T * __restrict__ dsdx,
110 const T * __restrict__ dtdx,
111 const T * __restrict__ drdy,
112 const T * __restrict__ dsdy,
113 const T * __restrict__ dtdy,
114 const T * __restrict__ drdz,
115 const T * __restrict__ dsdz,
116 const T * __restrict__ dtdz,
117 const T * __restrict__ jacinv) {
118
119 __shared__ T shu[LX * LX * LX];
120 __shared__ T shv[LX * LX * LX];
121 __shared__ T shw[LX * LX * LX];
122
123 __shared__ T shdx[LX * LX];
124 __shared__ T shdy[LX * LX];
125 __shared__ T shdz[LX * LX];
126
127
128
129
130 int i,j,k;
131
132 const int e = blockIdx.x;
133 const int ele = blockIdx.x*LX*LX*LX;
134 const int iii = threadIdx.x;
135 const int nchunks = (LX * LX * LX - 1) / CHUNKS + 1;
136
137
138 if (iii < (LX * LX)) {
139 shdx[iii] = dx[iii];
140 shdy[iii] = dy[iii];
141 shdz[iii] = dz[iii];
142 }
143
144 j = iii;
145 while(j < (LX * LX * LX)) {
146 shu[j] = u[j + ele];
147 shv[j] = v[j + ele];
148 shw[j] = w[j + ele];
149 j = j + CHUNKS;
150 }
151
153
154 for (int n = 0; n < nchunks; n++) {
155 const int ijk = iii + n * CHUNKS;
156 const int jk = ijk / LX;
157 i = ijk - jk * LX;
158 k = jk / LX;
159 j = jk - k * LX;
160 if ( i < LX && j < LX && k < LX ) {
161 T rtmpu = 0.0;
162 T stmpu = 0.0;
163 T ttmpu = 0.0;
164
165 T rtmpv = 0.0;
166 T stmpv = 0.0;
167 T ttmpv = 0.0;
168
169 T rtmpw = 0.0;
170 T stmpw = 0.0;
171 T ttmpw = 0.0;
172 for (int l = 0; l < LX; l++) {
173 rtmpu += shdx[i + l * LX] * shu[l + j * LX + k * LX * LX];
174 stmpu += shdy[j + l * LX] * shu[i + l * LX + k * LX * LX];
175 ttmpu += shdz[k + l * LX] * shu[i + j * LX + l * LX * LX];
176
177 rtmpv += shdx[i + l * LX] * shv[l + j * LX + k * LX * LX];
178 stmpv += shdy[j + l * LX] * shv[i + l * LX + k * LX * LX];
179 ttmpv += shdz[k + l * LX] * shv[i + j * LX + l * LX * LX];
180
181 rtmpw += shdx[i + l * LX] * shw[l + j * LX + k * LX * LX];
182 stmpw += shdy[j + l * LX] * shw[i + l * LX + k * LX * LX];
183 ttmpw += shdz[k + l * LX] * shw[i + j * LX + l * LX * LX];
184 }
185
186 T jinv = jacinv[ijk + ele];
187
188 T grad11 = jinv
189 * (drdx[ijk + ele] * rtmpu
190 + dsdx[ijk + ele] * stmpu
191 + dtdx[ijk + ele] * ttmpu);
192
193 T grad12 = jinv
194 * (drdy[ijk + ele] * rtmpu
195 + dsdy[ijk + ele] * stmpu
196 + dtdy[ijk + ele] * ttmpu);
197
198 T grad13 = jinv
199 * (drdz[ijk + ele] * rtmpu
200 + dsdz[ijk + ele] * stmpu
201 + dtdz[ijk + ele] * ttmpu);
202
203 T grad21 = jinv
204 * (drdx[ijk + ele] * rtmpv
205 + dsdx[ijk + ele] * stmpv
206 + dtdx[ijk + ele] * ttmpv);
207
208 T grad22 = jinv
209 * (drdy[ijk + ele] * rtmpv
210 + dsdy[ijk + ele] * stmpv
211 + dtdy[ijk + ele] * ttmpv);
212
213 T grad23 = jinv
214 * (drdz[ijk + ele] * rtmpv
215 + dsdz[ijk + ele] * stmpv
216 + dtdz[ijk + ele] * ttmpv);
217
218
219 T grad31 = jinv
220 * (drdx[ijk + ele] * rtmpw
221 + dsdx[ijk + ele] * stmpw
222 + dtdx[ijk + ele] * ttmpw);
223
224 T grad32 = jinv
225 * (drdy[ijk + ele] * rtmpw
226 + dsdy[ijk + ele] * stmpw
227 + dtdy[ijk + ele] * ttmpw);
228
229 T grad33 = jinv
230 * (drdz[ijk + ele] * rtmpw
231 + dsdz[ijk + ele] * stmpw
232 + dtdz[ijk + ele] * ttmpw);
236 }
237 }
238
239}
240
241template< typename T, const int LX, const int EB >
244 const T * __restrict__ u,
245 const T * __restrict__ v,
246 const T * __restrict__ w,
260 const int nelv) {
261
262 __shared__ T shu[EB * LX * LX];
265
269
270 static_assert(sizeof(shu) +
271 sizeof(shv) +
272 sizeof(shw) +
273 sizeof(shdx) +
274 sizeof(shdy) +
275 sizeof(shdz)
277 "kstep block exceeds the shared memory budget");
278
279 const int eb = (EB == 1) ? 0 : threadIdx.z;
280 const int e_blk = blockIdx.x * EB + eb;
281 /* Threads past the last element still have to reach the barriers in
282 the k loop, so clamp their reads and drop their stores rather than
283 returning early. At EB == 1 this all constant folds away */
284 const bool active = (EB == 1) ? true : (e_blk < nelv);
285 const int e = active ? e_blk : (nelv - 1);
286 const int sh = eb * LX * LX;
287 const int j = threadIdx.y;
288 const int i = threadIdx.x;
289 const int ij = i + j * LX;
290 const int ele = e*LX*LX*LX;
291
292 if (eb == 0) {
293 shdx[ij] = dx[ij];
294 shdy[ij] = dy[ij];
295 shdz[ij] = dz[ij];
296 }
297
301
302#pragma unroll LX
303 for (int k = 0; k < LX; ++k) {
304 ru[k] = u[ij + k*LX*LX + ele];
305 rv[k] = v[ij + k*LX*LX + ele];
306 rw[k] = w[ij + k*LX*LX + ele];
307 }
308
310
311 #pragma unroll
312 for (int k = 0; k < LX; ++k) {
313 const int ijk = ij + k*LX*LX;
314 const T jinv = jacinv[ijk+ele];
315 T ttmpu = 0.0;
316 T ttmpv = 0.0;
317 T ttmpw = 0.0;
318 shu[sh + ij] = ru[k];
319 shv[sh + ij] = rv[k];
320 shw[sh + ij] = rw[k];
321#pragma unroll
322 for (int l = 0; l < LX; l++) {
323 ttmpu += shdz[k+l*LX] * ru[l];
324 ttmpv += shdz[k+l*LX] * rv[l];
325 ttmpw += shdz[k+l*LX] * rw[l];
326 }
328
329 T rtmpu = 0.0;
330 T stmpu = 0.0;
331 T rtmpv = 0.0;
332 T stmpv = 0.0;
333 T rtmpw = 0.0;
334 T stmpw = 0.0;
335#pragma unroll
336 for (int l = 0; l < LX; l++) {
337 rtmpu += shdx[i+l*LX] * shu[sh + l+j*LX];
338 stmpu += shdy[j+l*LX] * shu[sh + i+l*LX];
339 rtmpv += shdx[i+l*LX] * shv[sh + l+j*LX];
340 stmpv += shdy[j+l*LX] * shv[sh + i+l*LX];
341 rtmpw += shdx[i+l*LX] * shw[sh + l+j*LX];
342 stmpw += shdy[j+l*LX] * shw[sh + i+l*LX];
343 }
344
345 T grad11 = jinv * (drdx[ijk + ele] * rtmpu
346 + dsdx[ijk + ele] * stmpu
347 + dtdx[ijk + ele] * ttmpu);
348
349 T grad12 = jinv * (drdy[ijk + ele] * rtmpu
350 + dsdy[ijk + ele] * stmpu
351 + dtdy[ijk + ele] * ttmpu);
352
353 T grad13 = jinv * (drdz[ijk + ele] * rtmpu
354 + dsdz[ijk + ele] * stmpu
355 + dtdz[ijk + ele] * ttmpu);
356 T grad21 = jinv * (drdx[ijk + ele] * rtmpv
357 + dsdx[ijk + ele] * stmpv
358 + dtdx[ijk + ele] * ttmpv);
359
360 T grad22 = jinv * (drdy[ijk + ele] * rtmpv
361 + dsdy[ijk + ele] * stmpv
362 + dtdy[ijk + ele] * ttmpv);
363
364 T grad23 = jinv * (drdz[ijk + ele] * rtmpv
365 + dsdz[ijk + ele] * stmpv
366 + dtdz[ijk + ele] * ttmpv);
367 T grad31 = jinv * (drdx[ijk + ele] * rtmpw
368 + dsdx[ijk + ele] * stmpw
369 + dtdx[ijk + ele] * ttmpw);
370
371 T grad32 = jinv * (drdy[ijk + ele] * rtmpw
372 + dsdy[ijk + ele] * stmpw
373 + dtdy[ijk + ele] * ttmpw);
374
375 T grad33 = jinv * (drdz[ijk + ele] * rtmpw
376 + dsdz[ijk + ele] * stmpw
377 + dtdz[ijk + ele] * ttmpw);
378 if (active) {
382 }
384 }
385}
386
387
388#endif // __MATH_LAMBDA2_KERNEL_H__
__global__ void ale_add_kinematics_kernel(const int n, T *__restrict__ wx, T *__restrict__ wy, T *__restrict__ wz, const T *__restrict__ x_ref, const T *__restrict__ y_ref, const T *__restrict__ z_ref, const T *__restrict__ phi, const T *__restrict__ x, const T *__restrict__ y, const T *__restrict__ z, const kinematics_params_t kin_params)
__shared__ T shu[LX *LX]
#define NEKO_EB_MAX_SMEM
Definition elem_block.h:60
#define NEKO_EB_BOUNDS(NT)
Definition elem_block.h:95
const bool active
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dsdx
__shared__ T shv[EB *LX *LX]
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dsdy
__global__ void lambda2_kernel_1d(T *__restrict__ lambda2, const T *__restrict__ u, const T *__restrict__ v, const T *__restrict__ w, const T *__restrict__ dx, const T *__restrict__ dy, const T *__restrict__ dz, const T *__restrict__ drdx, const T *__restrict__ dsdx, const T *__restrict__ dtdx, const T *__restrict__ drdy, const T *__restrict__ dsdy, const T *__restrict__ dtdy, const T *__restrict__ drdz, const T *__restrict__ dsdz, const T *__restrict__ dtdz, const T *__restrict__ jacinv)
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dsdz
const int sh
T ru[LX]
const int eb
T rv[LX]
__shared__ T shdy[LX *LX]
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ drdz
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dtdz
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ jacinv
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ drdx
const int i
const int ij
T rw[LX]
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dx
__shared__ T shdx[LX *LX]
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dy
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dz
__shared__ T shw[EB *LX *LX]
const int e
__shared__ T shdz[LX *LX]
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dtdy
const int e_blk
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ drdy
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ w
__inline__ __device__ T eigen_val_calc(T grad11, T grad12, T grad13, T grad21, T grad22, T grad23, T grad31, T grad32, T grad33)
const int ele
__global__ void const T *__restrict__ u
const int j
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dtdx
__syncthreads()
__global__ void const T *__restrict__ const T *__restrict__ v
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const int nelv
A simulation component that computes lambda2 The values are stored in the field registry under the na...
Definition lambda2.f90:37