Neko 1.99.9
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
ax_helm_svv_one_sided_full_kernel.h
Go to the documentation of this file.
1#ifndef __MATH_AX_HELM_SVV_FULL_KERNEL_H__
2#define __MATH_AX_HELM_SVV_FULL_KERNEL_H__
3/*
4 Copyright (c) 2025-2026, The Neko Authors
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions
9 are met:
10
11 * Redistributions of source code must retain the above copyright
12 notice, this list of conditions and the following disclaimer.
13
14 * Redistributions in binary form must reproduce the above
15 copyright notice, this list of conditions and the following
16 disclaimer in the documentation and/or other materials provided
17 with the distribution.
18
19 * Neither the name of the authors nor the names of its
20 contributors may be used to endorse or promote products derived
21 from this software without specific prior written permission.
22
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 POSSIBILITY OF SUCH DAMAGE.
35*/
36
40template<typename T, const int LX>
42 const T * __restrict__ field,
43 const int component,
44 const int i,
45 const int j,
46 const int k,
47 const int elem,
48 const T * __restrict__ dx,
49 const T * __restrict__ dy,
50 const T * __restrict__ dz,
51 const T * __restrict__ drdx,
52 const T * __restrict__ drdy,
53 const T * __restrict__ drdz,
54 const T * __restrict__ dsdx,
55 const T * __restrict__ dsdy,
56 const T * __restrict__ dsdz,
57 const T * __restrict__ dtdx,
58 const T * __restrict__ dtdy,
59 const T * __restrict__ dtdz,
60 const T * __restrict__ jacinv) {
61
62 const int lx2 = LX * LX;
63 const int ij = i + j * LX;
64 const int ijk = ij + k * lx2;
65 const int index = ijk + elem;
66 T ur = 0.0;
67 T us = 0.0;
68 T ut = 0.0;
69
70#pragma unroll
71 for (int l = 0; l < LX; ++l) {
72 ur += dx[i + l * LX] * field[l + j * LX + k * lx2 + elem];
73 us += dy[j + l * LX] * field[i + l * LX + k * lx2 + elem];
74 ut += dz[k + l * LX] * field[ij + l * lx2 + elem];
75 }
76
77 if (component == 0) {
78 return (ur * drdx[index] + us * dsdx[index] +
79 ut * dtdx[index]) * jacinv[index];
80 }
81 if (component == 1) {
82 return (ur * drdy[index] + us * dsdy[index] +
83 ut * dtdy[index]) * jacinv[index];
84 }
85 return (ur * drdz[index] + us * dsdz[index] +
86 ut * dtdz[index]) * jacinv[index];
87}
88
95template<typename T, const int LX>
100 const T * __restrict__ u,
101 const T * __restrict__ v,
102 const T * __restrict__ w,
103 const T * __restrict__ dx,
104 const T * __restrict__ dy,
105 const T * __restrict__ dz,
106 const T * __restrict__ h1,
107 const T * __restrict__ drdx,
108 const T * __restrict__ drdy,
109 const T * __restrict__ drdz,
110 const T * __restrict__ dsdx,
111 const T * __restrict__ dsdy,
112 const T * __restrict__ dsdz,
113 const T * __restrict__ dtdx,
114 const T * __restrict__ dtdy,
115 const T * __restrict__ dtdz,
116 const T * __restrict__ jacinv,
117 const T * __restrict__ w3,
118 const T * __restrict__ h1_svv,
119 const T * __restrict__ filter_r,
120 const T * __restrict__ filter_s,
121 const T * __restrict__ filter_t) {
122
123 extern __shared__ T shared[];
124 T *shfield = shared;
125 T *shwork = shared + LX * LX * LX;
126
127 const int e = blockIdx.x;
128 const int i = threadIdx.x;
129 const int j = threadIdx.y;
130 const int ij = i + j * LX;
131 const int lx2 = LX * LX;
132 const int elem = e * LX * lx2;
133
134#pragma unroll 1
135 for (int k = 0; k < LX; ++k) {
136 const int index = ij + k * lx2 + elem;
137 au[index] = 0.0;
138 av[index] = 0.0;
139 aw[index] = 0.0;
140 }
141
142 // Process s11, s22, s33, s12, s13 and s23 in turn.
143#pragma unroll 1
144 for (int stress = 0; stress < 6; ++stress) {
145
146 // Form one component of grad(u) + grad(u)^T.
147#pragma unroll 1
148 for (int k = 0; k < LX; ++k) {
149 T value;
150 if (stress == 0) {
152 u, 0, i, j, k, elem, dx, dy, dz,
153 drdx, drdy, drdz, dsdx, dsdy, dsdz,
154 dtdx, dtdy, dtdz, jacinv);
155 }
156 else if (stress == 1) {
158 v, 1, i, j, k, elem, dx, dy, dz,
159 drdx, drdy, drdz, dsdx, dsdy, dsdz,
160 dtdx, dtdy, dtdz, jacinv);
161 }
162 else if (stress == 2) {
164 w, 2, i, j, k, elem, dx, dy, dz,
165 drdx, drdy, drdz, dsdx, dsdy, dsdz,
166 dtdx, dtdy, dtdz, jacinv);
167 }
168 else if (stress == 3) {
170 u, 1, i, j, k, elem, dx, dy, dz,
171 drdx, drdy, drdz, dsdx, dsdy, dsdz,
172 dtdx, dtdy, dtdz, jacinv)
174 v, 0, i, j, k, elem, dx, dy, dz,
175 drdx, drdy, drdz, dsdx, dsdy, dsdz,
176 dtdx, dtdy, dtdz, jacinv);
177 }
178 else if (stress == 4) {
180 u, 2, i, j, k, elem, dx, dy, dz,
181 drdx, drdy, drdz, dsdx, dsdy, dsdz,
182 dtdx, dtdy, dtdz, jacinv)
184 w, 0, i, j, k, elem, dx, dy, dz,
185 drdx, drdy, drdz, dsdx, dsdy, dsdz,
186 dtdx, dtdy, dtdz, jacinv);
187 }
188 else {
190 v, 2, i, j, k, elem, dx, dy, dz,
191 drdx, drdy, drdz, dsdx, dsdy, dsdz,
192 dtdx, dtdy, dtdz, jacinv)
194 w, 1, i, j, k, elem, dx, dy, dz,
195 drdx, drdy, drdz, dsdx, dsdy, dsdz,
196 dtdx, dtdy, dtdz, jacinv);
197 }
198 shwork[ij + k * lx2] = value;
199 }
200
201 // Apply the selected tensor-product low-pass filter.
203#pragma unroll 1
204 for (int k = 0; k < LX; ++k) {
205 T value = 0.0;
206#pragma unroll
207 for (int l = 0; l < LX; ++l) {
208 value += filter_r[i + l * LX] *
209 shwork[l + j * LX + k * lx2];
210 }
211 shfield[ij + k * lx2] = value;
212 }
214
215#pragma unroll 1
216 for (int k = 0; k < LX; ++k) {
217 T value = 0.0;
218#pragma unroll
219 for (int l = 0; l < LX; ++l) {
220 value += filter_s[l + j * LX] *
221 shfield[i + l * LX + k * lx2];
222 }
223 shwork[ij + k * lx2] = value;
224 }
226
227#pragma unroll 1
228 for (int k = 0; k < LX; ++k) {
229 T value = 0.0;
230#pragma unroll
231 for (int l = 0; l < LX; ++l) {
232 value += filter_t[l + k * LX] * shwork[ij + l * lx2];
233 }
234 shfield[ij + k * lx2] = value;
235 }
237
238 // Recompute the unfiltered strain and combine both viscosities.
239#pragma unroll 1
240 for (int k = 0; k < LX; ++k) {
241 T value;
242 if (stress == 0) {
244 u, 0, i, j, k, elem, dx, dy, dz,
245 drdx, drdy, drdz, dsdx, dsdy, dsdz,
246 dtdx, dtdy, dtdz, jacinv);
247 }
248 else if (stress == 1) {
250 v, 1, i, j, k, elem, dx, dy, dz,
251 drdx, drdy, drdz, dsdx, dsdy, dsdz,
252 dtdx, dtdy, dtdz, jacinv);
253 }
254 else if (stress == 2) {
256 w, 2, i, j, k, elem, dx, dy, dz,
257 drdx, drdy, drdz, dsdx, dsdy, dsdz,
258 dtdx, dtdy, dtdz, jacinv);
259 }
260 else if (stress == 3) {
262 u, 1, i, j, k, elem, dx, dy, dz,
263 drdx, drdy, drdz, dsdx, dsdy, dsdz,
264 dtdx, dtdy, dtdz, jacinv)
266 v, 0, i, j, k, elem, dx, dy, dz,
267 drdx, drdy, drdz, dsdx, dsdy, dsdz,
268 dtdx, dtdy, dtdz, jacinv);
269 }
270 else if (stress == 4) {
272 u, 2, i, j, k, elem, dx, dy, dz,
273 drdx, drdy, drdz, dsdx, dsdy, dsdz,
274 dtdx, dtdy, dtdz, jacinv)
276 w, 0, i, j, k, elem, dx, dy, dz,
277 drdx, drdy, drdz, dsdx, dsdy, dsdz,
278 dtdx, dtdy, dtdz, jacinv);
279 }
280 else {
282 v, 2, i, j, k, elem, dx, dy, dz,
283 drdx, drdy, drdz, dsdx, dsdy, dsdz,
284 dtdx, dtdy, dtdz, jacinv)
286 w, 1, i, j, k, elem, dx, dy, dz,
287 drdx, drdy, drdz, dsdx, dsdy, dsdz,
288 dtdx, dtdy, dtdz, jacinv);
289 }
290
291 const int ijk = ij + k * lx2;
292 const int index = ijk + elem;
293 shwork[ijk] =
294 w3[ijk] * (h1[index] * value +
295 h1_svv[index] * (value - shfield[ijk]));
296 }
298
299 // A diagonal strain contributes once; a shear strain contributes twice.
300 const int contributions = stress < 3 ? 1 : 2;
301#pragma unroll 1
302 for (int contribution = 0;
304 int output;
305 int physical;
306 if (stress < 3) {
307 output = stress;
309 }
310 else if (stress == 3) {
313 }
314 else if (stress == 4) {
315 output = contribution == 0 ? 0 : 2;
316 physical = contribution == 0 ? 2 : 0;
317 }
318 else {
319 output = contribution == 0 ? 1 : 2;
320 physical = contribution == 0 ? 2 : 1;
321 }
322
323 T *result = output == 0 ? au : (output == 1 ? av : aw);
324
325 // r-direction reference flux and divergence.
326#pragma unroll 1
327 for (int k = 0; k < LX; ++k) {
328 const int ijk = ij + k * lx2;
329 const int index = ijk + elem;
330 T metric = physical == 0 ? drdx[index]
331 : (physical == 1 ? drdy[index] : drdz[index]);
333 }
335
336#pragma unroll 1
337 for (int k = 0; k < LX; ++k) {
338 T value = 0.0;
339#pragma unroll
340 for (int l = 0; l < LX; ++l) {
341 value += dx[l + i * LX] * shfield[l + j * LX + k * lx2];
342 }
343 result[ij + k * lx2 + elem] += value;
344 }
346
347 // s-direction reference flux and divergence.
348#pragma unroll 1
349 for (int k = 0; k < LX; ++k) {
350 const int ijk = ij + k * lx2;
351 const int index = ijk + elem;
352 T metric = physical == 0 ? dsdx[index]
353 : (physical == 1 ? dsdy[index] : dsdz[index]);
355 }
357
358#pragma unroll 1
359 for (int k = 0; k < LX; ++k) {
360 T value = 0.0;
361#pragma unroll
362 for (int l = 0; l < LX; ++l) {
363 value += dy[l + j * LX] * shfield[i + l * LX + k * lx2];
364 }
365 result[ij + k * lx2 + elem] += value;
366 }
368
369 // t-direction reference flux and divergence.
370#pragma unroll 1
371 for (int k = 0; k < LX; ++k) {
372 const int ijk = ij + k * lx2;
373 const int index = ijk + elem;
374 T metric = physical == 0 ? dtdx[index]
375 : (physical == 1 ? dtdy[index] : dtdz[index]);
377 }
379
380#pragma unroll 1
381 for (int k = 0; k < LX; ++k) {
382 T value = 0.0;
383#pragma unroll
384 for (int l = 0; l < LX; ++l) {
385 value += dz[l + k * LX] * shfield[ij + l * lx2];
386 }
387 result[ij + k * lx2 + elem] += value;
388 }
390 }
391 }
392}
393
394#endif
__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)
__global__ void T *__restrict__ 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__ dtdy
__global__ void T *__restrict__ 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__ dtdx
__global__ void T *__restrict__ 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 T *__restrict__ dtdz
__global__ void T *__restrict__ T *__restrict__ aw
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ w
__global__ void T *__restrict__ 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 T *__restrict__ const T *__restrict__ jacinv
const int i
const int ij
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dz
__global__ void T *__restrict__ 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
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dx
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ u
const int e
__global__ void T *__restrict__ av
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dy
__global__ void T *__restrict__ 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 T *__restrict__ 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__ drdx
__global__ void T *__restrict__ 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__ dsdx
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ v
const int j
__syncthreads()
__global__ void T *__restrict__ 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__ dsdy
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ h1
__global__ void T *__restrict__ 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
__device__ __forceinline__ T ax_helm_svv_one_sided_full_derivative(const T *__restrict__ field, const int component, const int i, const int j, const int k, const int elem, const T *__restrict__ dx, const T *__restrict__ dy, const T *__restrict__ dz, const T *__restrict__ drdx, const T *__restrict__ drdy, const T *__restrict__ drdz, const T *__restrict__ dsdx, const T *__restrict__ dsdy, const T *__restrict__ dsdz, const T *__restrict__ dtdx, const T *__restrict__ dtdy, const T *__restrict__ dtdz, const T *__restrict__ jacinv)
__global__ void ax_helm_svv_one_sided_full_kernel(T *__restrict__ au, T *__restrict__ av, T *__restrict__ aw, 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__ h1, const T *__restrict__ drdx, const T *__restrict__ drdy, const T *__restrict__ drdz, const T *__restrict__ dsdx, const T *__restrict__ dsdy, const T *__restrict__ dsdz, const T *__restrict__ dtdx, const T *__restrict__ dtdy, const T *__restrict__ dtdz, const T *__restrict__ jacinv, const T *__restrict__ w3, const T *__restrict__ h1_svv, const T *__restrict__ filter_r, const T *__restrict__ filter_s, const T *__restrict__ filter_t)
__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__ w3
Defines a field.
Definition field.f90:34
Defines an output.
Definition output.f90:34