Neko 1.99.6
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
lpt_periodic_bc_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 __LPT_PERIODIC_BC_KERNEL_H__
36#define __LPT_PERIODIC_BC_KERNEL_H__
37
38#include <math.h>
39
40template<typename T>
41__device__ inline void lpt_rotate_xy(T *x, T *y, const int i, const T theta) {
42 const T x_old = x[i];
43 const T y_old = y[i];
44 const T cos_theta = cos(theta);
45 const T sin_theta = sin(theta);
46
48 y[i] = sin_theta * x_old + cos_theta * y_old;
49}
50
51template<typename T>
54 T * __restrict__ y,
55 T * __restrict__ z,
56 const int n,
57 const int n_periodic_dirs,
58 const T periodic_dir_x1,
59 const T periodic_dir_y1,
60 const T periodic_dir_z1,
61 const T periodic_dir_x2,
62 const T periodic_dir_y2,
63 const T periodic_dir_z2,
64 const T periodic_dir_x3,
65 const T periodic_dir_y3,
66 const T periodic_dir_z3,
67 const T periodic_min1,
68 const T periodic_min2,
69 const T periodic_min3,
70 const T periodic_max1,
71 const T periodic_max2,
72 const T periodic_max3,
73 const T periodic_shift_x1,
74 const T periodic_shift_y1,
75 const T periodic_shift_z1,
76 const T periodic_shift_x2,
77 const T periodic_shift_y2,
78 const T periodic_shift_z2,
79 const T periodic_shift_x3,
80 const T periodic_shift_y3,
81 const T periodic_shift_z3,
82 const T periodic_len1,
83 const T periodic_len2,
84 const T periodic_len3) {
85
86 const T tol = 1.0e-8;
87 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
88 const int str = blockDim.x * gridDim.x;
89
90 for (int i = idx; i < n; i += str) {
91 T point0 = x[i];
92 T point1 = y[i];
93 T point2 = z[i];
94
95 for (int j = 0; j < n_periodic_dirs; j++) {
96 T dir0 = periodic_dir_x1;
97 T dir1 = periodic_dir_y1;
98 T dir2 = periodic_dir_z1;
99 T min = periodic_min1;
100 T max = periodic_max1;
101 T shift0 = periodic_shift_x1;
102 T shift1 = periodic_shift_y1;
103 T shift2 = periodic_shift_z1;
104 T len = periodic_len1;
105
106 switch (j) {
107 case 1:
108 dir0 = periodic_dir_x2;
109 dir1 = periodic_dir_y2;
110 dir2 = periodic_dir_z2;
111 min = periodic_min2;
112 max = periodic_max2;
113 shift0 = periodic_shift_x2;
114 shift1 = periodic_shift_y2;
115 shift2 = periodic_shift_z2;
116 len = periodic_len2;
117 break;
118 case 2:
119 dir0 = periodic_dir_x3;
120 dir1 = periodic_dir_y3;
121 dir2 = periodic_dir_z3;
122 min = periodic_min3;
123 max = periodic_max3;
124 shift0 = periodic_shift_x3;
125 shift1 = periodic_shift_y3;
126 shift2 = periodic_shift_z3;
127 len = periodic_len3;
128 break;
129 default:
130 break;
131 }
132
133 T coord = point0 * dir0 + point1 * dir1 + point2 * dir2;
134
135 while (coord < min - tol) {
136 point0 += shift0;
137 point1 += shift1;
138 point2 += shift2;
139 coord += len;
140 }
141
142 while (coord > max + tol) {
143 point0 -= shift0;
144 point1 -= shift1;
145 point2 -= shift2;
146 coord -= len;
147 }
148 }
149
150 x[i] = point0;
151 y[i] = point1;
152 z[i] = point2;
153 }
154}
155
156template<typename T>
158 T * __restrict__ x,
159 T * __restrict__ y,
160 T * __restrict__ z,
161 const int n,
162 const T theta_min,
163 const T theta_max,
164 const T theta_len,
165 T * __restrict__ u,
166 T * __restrict__ v,
167 T * __restrict__ w,
168 T * __restrict__ u_lag,
169 T * __restrict__ v_lag,
170 T * __restrict__ w_lag,
171 T * __restrict__ u_laglag,
172 T * __restrict__ v_laglag,
173 T * __restrict__ w_laglag,
174 T * __restrict__ acc_xlag,
175 T * __restrict__ acc_ylag,
176 T * __restrict__ acc_zlag,
177 T * __restrict__ acc_xlaglag,
178 T * __restrict__ acc_ylaglag,
179 T * __restrict__ acc_zlaglag) {
180
181 const T tol = 1.0e-8;
182 const T pi = acos((T) -1.0);
183 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
184 const int str = blockDim.x * gridDim.x;
185
186 for (int i = idx; i < n; i += str) {
187 const T radius = sqrt(x[i] * x[i] + y[i] * y[i]);
188 const T theta_old = fmod(atan2(y[i], x[i]) + 2.0 * pi, 2.0 * pi);
189 T theta = theta_old;
190
191 while (theta < theta_min - tol) {
192 theta += theta_len;
193 }
194
195 while (theta > theta_max + tol) {
196 theta -= theta_len;
197 }
198
199 const T dtheta = theta - theta_old;
200 x[i] = radius * cos(theta);
201 y[i] = radius * sin(theta);
202 if (fabs(dtheta) <= tol) {
203 continue;
204 }
205
206 if (u && v) {
208 }
209 if (u_lag && v_lag) {
210 lpt_rotate_xy(u_lag, v_lag, i, dtheta);
211 }
212 if (u_laglag && v_laglag) {
213 lpt_rotate_xy(u_laglag, v_laglag, i, dtheta);
214 }
215 if (acc_xlag && acc_ylag) {
216 lpt_rotate_xy(acc_xlag, acc_ylag, i, dtheta);
217 }
218 if (acc_xlaglag && acc_ylaglag) {
219 lpt_rotate_xy(acc_xlaglag, acc_ylaglag, i, dtheta);
220 }
221 }
222}
223
224#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__ w
const int i
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ u
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ v
const int j
__global__ void const T *__restrict__ x
__device__ void lpt_rotate_xy(T *x, T *y, const int i, const T theta)
__global__ void lpt_periodic_bc_wrap_translational_kernel(T *__restrict__ x, T *__restrict__ y, T *__restrict__ z, const int n, const int n_periodic_dirs, const T periodic_dir_x1, const T periodic_dir_y1, const T periodic_dir_z1, const T periodic_dir_x2, const T periodic_dir_y2, const T periodic_dir_z2, const T periodic_dir_x3, const T periodic_dir_y3, const T periodic_dir_z3, const T periodic_min1, const T periodic_min2, const T periodic_min3, const T periodic_max1, const T periodic_max2, const T periodic_max3, const T periodic_shift_x1, const T periodic_shift_y1, const T periodic_shift_z1, const T periodic_shift_x2, const T periodic_shift_y2, const T periodic_shift_z2, const T periodic_shift_x3, const T periodic_shift_y3, const T periodic_shift_z3, const T periodic_len1, const T periodic_len2, const T periodic_len3)
__global__ void lpt_periodic_bc_wrap_rotational_kernel(T *__restrict__ x, T *__restrict__ y, T *__restrict__ z, const int n, const T theta_min, const T theta_max, const T theta_len, T *__restrict__ u, T *__restrict__ v, T *__restrict__ w, T *__restrict__ u_lag, T *__restrict__ v_lag, T *__restrict__ w_lag, T *__restrict__ u_laglag, T *__restrict__ v_laglag, T *__restrict__ w_laglag, T *__restrict__ acc_xlag, T *__restrict__ acc_ylag, T *__restrict__ acc_zlag, T *__restrict__ acc_xlaglag, T *__restrict__ acc_ylaglag, T *__restrict__ acc_zlaglag)
#define max(a, b)
Definition tensor.cu:40