Neko 1.99.4
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
ale_kinematics_kernel.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2026, The Neko Authors
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above
13 copyright notice, this list of conditions and the following
14 disclaimer in the documentation and/or other materials provided
15 with the distribution.
16
17 * Neither the name of the authors nor the names of its
18 contributors may be used to endorse or promote products derived
19 from this software without specific prior written permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 POSSIBILITY OF SUCH DAMAGE.
33*/
34
35#ifndef __COMMON_ALE_KINEMATICS_KERNEL_H__
36#define __COMMON_ALE_KINEMATICS_KERNEL_H__
37
38#include <cmath>
39#include <algorithm>
40
41#ifndef KINEMATICS_PARAMS_T_DEFINED
42#define KINEMATICS_PARAMS_T_DEFINED
43typedef struct {
44 real cx, cy, cz;
45 real vtx, vty, vtz;
46 real vax, vay, vaz;
47 real px, py, pz;
48 real r11, r12, r13;
49 real r21, r22, r23;
50 real r31, r32, r33;
52#endif
53
54template< typename T >
56 T * __restrict__ wx,
57 T * __restrict__ wy,
58 T * __restrict__ wz,
59 const T * __restrict__ x_ref,
60 const T * __restrict__ y_ref,
61 const T * __restrict__ z_ref,
62 const T * __restrict__ phi,
63 const T * __restrict__ x,
64 const T * __restrict__ y,
65 const T * __restrict__ z,
67
68 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
69 const int str = blockDim.x * gridDim.x;
70 const T one = 1.0;
71 const T tol = 1e-6;
72
73 for (int i = idx; i < n; i += str) {
74 const T p_val = phi[i];
76
77 if (fabs(p_val - one) < tol) {
78 const T rx = x[i] - kin_params.cx;
79 const T ry = y[i] - kin_params.cy;
80 const T rz = z[i] - kin_params.cz;
81
82 v_tan_x = kin_params.vay * rz - kin_params.vaz * ry;
83 v_tan_y = kin_params.vaz * rx - kin_params.vax * rz;
84 v_tan_z = kin_params.vax * ry - kin_params.vay * rx;
85 }
86 else {
87 const T dx_ref = x_ref[i] - kin_params.px;
88 const T dy_ref = y_ref[i] - kin_params.py;
89 const T dz_ref = z_ref[i] - kin_params.pz;
90
91 const T rx_target = kin_params.r11*dx_ref +
92 kin_params.r12*dy_ref +
94
95 const T ry_target = kin_params.r21*dx_ref +
96 kin_params.r22*dy_ref +
98
99 const T rz_target = kin_params.r31*dx_ref +
100 kin_params.r32*dy_ref +
101 kin_params.r33*dz_ref;
102
106 }
107
108 wx[i] += (kin_params.vtx + v_tan_x) * p_val;
109 wy[i] += (kin_params.vty + v_tan_y) * p_val;
110 wz[i] += (kin_params.vtz + v_tan_z) * p_val;
111 }
112}
113
114template <typename T>
116 T* __restrict__ d,
117 const T* __restrict__ x,
118 const T* __restrict__ y,
119 const T* __restrict__ z,
120 const int lx, const int ly, const int lz,
121 const int nel, const int local_iters,
123{
124 int e = blockIdx.x * blockDim.x + threadIdx.x;
125 if (e >= nel) return;
126
127 int iter = 1;
128 bool element_changed_ever = false;
129 bool changed_local = true;
130
131 const int lxy = lx * ly;
132 const int lxyz = lx * ly * lz;
133 const int e_offset = e * lxyz;
134
135 while (changed_local && iter <= local_iters) {
136 changed_local = false;
137
138 // Loop over GLL nodes in this element
139 for (int k = 0; k < lz; ++k) {
140 for (int j = 0; j < ly; ++j) {
141 for (int i = 0; i < lx; ++i) {
142 int idx1 = i + j * lx + k * lxy + e_offset;
143 T x1 = x[idx1];
144 T y1 = y[idx1];
145 T z1 = z[idx1];
146 T d1 = d[idx1];
147
148 int i0 = max(0, i - 1);
149 int i1 = min(lx - 1, i + 1);
150 int j0 = max(0, j - 1);
151 int j1 = min(ly - 1, j + 1);
152 int k0 = max(0, k - 1);
153 int k1 = min(lz - 1, k + 1);
154
155 // Neighbor check
156 for (int kk = k0; kk <= k1; ++kk) {
157 for (int jj = j0; jj <= j1; ++jj) {
158 for (int ii = i0; ii <= i1; ++ii) {
159 if (ii == i && jj == j && kk == k) continue;
160
161 int idx2 = ii + jj * lx + kk * lxy + e_offset;
162 T x2 = x[idx2];
163 T y2 = y[idx2];
164 T z2 = z[idx2];
165 T d2 = d[idx2];
166
167 T dist = sqrt((x1 - x2)*(x1 - x2) +
168 (y1 - y2)*(y1 - y2) +
169 (z1 - z2)*(z1 - z2));
170 T dtmp = d2 + dist;
171
172 if (dtmp < d1) {
173 d1 = dtmp;
174 d[idx1] = d1; // Update locally
175 changed_local = true;
176 }
177 }
178 }
179 }
180 }
181 }
182 }
184 iter++;
185 }
186
188 atomicAdd(nchange, 1);
189 }
190}
191
192#endif // __COMMON_ALE_KINEMATICS_KERNEL_H__
__global__ void compute_cheap_dist_kernel(T *__restrict__ d, const T *__restrict__ x, const T *__restrict__ y, const T *__restrict__ z, const int lx, const int ly, const int lz, const int nel, const int local_iters, int *__restrict__ nchange)
__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)
const int i
const int e
const int j
__global__ void const T *__restrict__ x
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ cz
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ cx
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ cy
double real
#define max(a, b)
Definition tensor.cu:40