56 const T * __restrict__ x_ref,
57 const T * __restrict__ y_ref,
58 const T * __restrict__ z_ref,
59 const T * __restrict__ phi,
60 const T * __restrict__
x,
61 const T * __restrict__ y,
62 const T * __restrict__ z,
65 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
66 const int str = blockDim.x * gridDim.x;
70 for (
int i = idx;
i < n;
i += str) {
71 const T p_val = phi[
i];
72 T v_tan_x, v_tan_y, v_tan_z;
74 if (fabs(p_val - one) < tol) {
75 const T rx =
x[
i] - kin_params.
cx;
76 const T ry = y[
i] - kin_params.
cy;
77 const T rz = z[
i] - kin_params.
cz;
79 v_tan_x = kin_params.
vay * rz - kin_params.
vaz * ry;
80 v_tan_y = kin_params.
vaz * rx - kin_params.
vax * rz;
81 v_tan_z = kin_params.
vax * ry - kin_params.
vay * rx;
84 const T dx_ref = x_ref[
i] - kin_params.
px;
85 const T dy_ref = y_ref[
i] - kin_params.
py;
86 const T dz_ref = z_ref[
i] - kin_params.
pz;
88 const T rx_target = kin_params.
r11*dx_ref +
89 kin_params.
r12*dy_ref +
90 kin_params.
r13*dz_ref;
92 const T ry_target = kin_params.
r21*dx_ref +
93 kin_params.
r22*dy_ref +
94 kin_params.
r23*dz_ref;
96 const T rz_target = kin_params.
r31*dx_ref +
97 kin_params.
r32*dy_ref +
98 kin_params.
r33*dz_ref;
100 v_tan_x = kin_params.
vay * rz_target - kin_params.
vaz * ry_target;
101 v_tan_y = kin_params.
vaz * rx_target - kin_params.
vax * rz_target;
102 v_tan_z = kin_params.
vax * ry_target - kin_params.
vay * rx_target;
105 wx[
i] += (kin_params.
vtx + v_tan_x) * p_val;
106 wy[
i] += (kin_params.
vty + v_tan_y) * p_val;
107 wz[
i] += (kin_params.
vtz + v_tan_z) * p_val;
114 const T * __restrict__
x,
115 const T * __restrict__ y,
116 const T * __restrict__ z,
117 const int lx,
const int ly,
const int lz,
118 const int nel,
const int local_iters,
119 int* __restrict__ nchange)
121 int e = blockIdx.x * blockDim.x + threadIdx.x;
122 if (
e >= nel)
return;
125 bool element_changed_ever =
false;
126 bool changed_local =
true;
128 const int lxy = lx * ly;
129 const int lxyz = lx * ly * lz;
130 const int e_offset =
e * lxyz;
132 while (changed_local && iter <= local_iters) {
133 changed_local =
false;
136 for (
int k = 0; k < lz; ++k) {
137 for (
int j = 0;
j < ly; ++
j) {
138 for (
int i = 0;
i < lx; ++
i) {
139 int idx1 =
i +
j * lx + k * lxy + e_offset;
145 int i0 =
max(0,
i - 1);
146 int i1 = min(lx - 1,
i + 1);
147 int j0 =
max(0,
j - 1);
148 int j1 = min(ly - 1,
j + 1);
149 int k0 =
max(0, k - 1);
150 int k1 = min(lz - 1, k + 1);
153 for (
int kk = k0; kk <= k1; ++kk) {
154 for (
int jj = j0; jj <= j1; ++jj) {
155 for (
int ii = i0; ii <= i1; ++ii) {
156 if (ii ==
i && jj ==
j && kk == k)
continue;
158 int idx2 = ii + jj * lx + kk * lxy + e_offset;
164 T dist = sqrt((x1 - x2)*(x1 - x2) +
165 (y1 - y2)*(y1 - y2) +
166 (z1 - z2)*(z1 - z2));
172 changed_local =
true;
180 if (changed_local) element_changed_ever =
true;
184 if (element_changed_ever) {
185 atomicAdd(nchange, 1);
__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)