35#ifndef __COMMON_ALE_KINEMATICS_KERNEL_H__
36#define __COMMON_ALE_KINEMATICS_KERNEL_H__
41#ifndef KINEMATICS_PARAMS_T_DEFINED
42#define KINEMATICS_PARAMS_T_DEFINED
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,
68 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
69 const int str = blockDim.x * gridDim.x;
73 for (
int i = idx;
i < n;
i += str) {
74 const T p_val = phi[
i];
75 T v_tan_x, v_tan_y, v_tan_z;
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;
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;
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;
91 const T rx_target = kin_params.
r11*dx_ref +
92 kin_params.
r12*dy_ref +
93 kin_params.
r13*dz_ref;
95 const T ry_target = kin_params.
r21*dx_ref +
96 kin_params.
r22*dy_ref +
97 kin_params.
r23*dz_ref;
99 const T rz_target = kin_params.
r31*dx_ref +
100 kin_params.
r32*dy_ref +
101 kin_params.
r33*dz_ref;
103 v_tan_x = kin_params.
vay * rz_target - kin_params.
vaz * ry_target;
104 v_tan_y = kin_params.
vaz * rx_target - kin_params.
vax * rz_target;
105 v_tan_z = kin_params.
vax * ry_target - kin_params.
vay * rx_target;
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;
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,
122 int* __restrict__ nchange)
124 int e = blockIdx.x * blockDim.x + threadIdx.x;
125 if (
e >= nel)
return;
128 bool element_changed_ever =
false;
129 bool changed_local =
true;
131 const int lxy = lx * ly;
132 const int lxyz = lx * ly * lz;
133 const int e_offset =
e * lxyz;
135 while (changed_local && iter <= local_iters) {
136 changed_local =
false;
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;
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);
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;
161 int idx2 = ii + jj * lx + kk * lxy + e_offset;
167 T dist = sqrt((x1 - x2)*(x1 - x2) +
168 (y1 - y2)*(y1 - y2) +
169 (z1 - z2)*(z1 - z2));
175 changed_local =
true;
183 if (changed_local) element_changed_ever =
true;
187 if (element_changed_ever) {
188 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)
__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