35#ifndef __LPT_WALL_COLLISION_KERNEL_H__
36#define __LPT_WALL_COLLISION_KERNEL_H__
48 return (
i - 1) + lx * ((
j - 1) + ly * ((k - 1) + lz * (
e - 1)));
54 return (facet - 1) + n_facets * (el - 1);
62__device__
inline T
lpt_norm3(
const T
x,
const T y,
const T z) {
63 return sqrt(
x *
x + y * y + z * z);
68 const T * __restrict__ dm_x,
69 const T * __restrict__ dm_y,
70 const T * __restrict__ dm_z,
117 const T * __restrict__ nx,
118 const T * __restrict__ ny,
119 const T * __restrict__ nz,
135 coef_get_normal_device(nx, ny, nz, 1, jc, kc, el, facet, lx, normal_x,
140 coef_get_normal_device(nx, ny, nz, ic, 1, kc, el, facet, lx, normal_x,
145 coef_get_normal_device(nx, ny, nz, ic, jc, 1, el, facet, lx, normal_x,
166 const T eps = (T) 1.0e-12;
167 const T nmag =
lpt_norm3(normal_x, normal_y, normal_z);
172 return ((
x - wall_x) * normal_x + (y - wall_y) * normal_y +
173 (z - wall_z) * normal_z) / nmag;
178 const int * __restrict__ wall_facet_mask,
179 const T * __restrict__ dm_x,
180 const T * __restrict__ dm_y,
181 const T * __restrict__ dm_z,
182 const T * __restrict__ nx,
183 const T * __restrict__ ny,
184 const T * __restrict__ nz,
198 const int n_facets = 2 * gdim;
199 const T tol = (T) 1.0e-8;
200 T normal_x, normal_y, normal_z;
201 T wall_x, wall_y, wall_z;
203 if (facet < 1 || facet > n_facets) {
212 if (
lpt_norm3(normal_x, normal_y, normal_z) <= (T) 1.0e-12) {
219 wall_y, wall_z, normal_x,
222 wall_z, normal_x, normal_y,
224 const T penetration = dist_new + radius;
226 if (penetration <= tol) {
229 if (dist_new <= dist_old + tol) {
247 const T eps = (T) 1.0e-12;
248 const T nmag =
lpt_norm3(normal_x, normal_y, normal_z);
253 const T nhat_x = normal_x / nmag;
254 const T nhat_y = normal_y / nmag;
255 const T nhat_z = normal_z / nmag;
256 const T signed_contact_distance =
257 (
x - wall_x) * nhat_x + (y - wall_y) * nhat_y +
258 (z - wall_z) * nhat_z + radius;
260 if (signed_contact_distance <= 0.0) {
264 x -= 2.0 * signed_contact_distance * nhat_x;
265 y -= 2.0 * signed_contact_distance * nhat_y;
266 z -= 2.0 * signed_contact_distance * nhat_z;
276 const T eps = (T) 1.0e-12;
277 const T nmag =
lpt_norm3(normal_x, normal_y, normal_z);
282 const T nhat_x = normal_x / nmag;
283 const T nhat_y = normal_y / nmag;
284 const T nhat_z = normal_z / nmag;
285 const T vn =
x * nhat_x + y * nhat_y + z * nhat_z;
287 x -= 2.0 * vn * nhat_x;
288 y -= 2.0 * vn * nhat_y;
289 z -= 2.0 * vn * nhat_z;
294 const int * __restrict__ wall_facet_mask,
295 const int * __restrict__ el_list,
296 const T * __restrict__ x_old,
297 const T * __restrict__ y_old,
298 const T * __restrict__ z_old,
302 const T * __restrict__ d,
306 T * __restrict__ u_lag,
307 T * __restrict__ v_lag,
308 T * __restrict__ w_lag,
309 T * __restrict__ u_laglag,
310 T * __restrict__ v_laglag,
311 T * __restrict__ w_laglag,
312 T * __restrict__ acc_xlag,
313 T * __restrict__ acc_ylag,
314 T * __restrict__ acc_zlag,
315 T * __restrict__ acc_xlaglag,
316 T * __restrict__ acc_ylaglag,
317 T * __restrict__ acc_zlaglag,
318 T * __restrict__ u_old,
319 T * __restrict__ v_old,
320 T * __restrict__ w_old,
321 T * __restrict__ acc_x,
322 T * __restrict__ acc_y,
323 T * __restrict__ acc_z,
324 const T * __restrict__ dm_x,
325 const T * __restrict__ dm_y,
326 const T * __restrict__ dm_z,
327 const T * __restrict__ nx,
328 const T * __restrict__ ny,
329 const T * __restrict__ nz,
337 const int idx = blockIdx.x * blockDim.x + threadIdx.x;
338 const int str = blockDim.x * gridDim.x;
339 const int n_facets = 2 * gdim;
341 for (
int p = idx; p < n; p += str) {
342 const int el = el_list[p];
347 const int el_mesh = el + 1;
348 if (el_mesh >
nelv) {
352 const T radius = 0.5 * d[p];
356 for (
int candidate = 1; candidate <= n_facets; candidate++) {
358 nz, lx, ly, lz, el_mesh, candidate, gdim,
359 x_old[p], y_old[p], z_old[p],
x[p], y[p],
361 hit_facets[hit_count] = candidate;
366 if (hit_count == 0) {
374 for (
int hit_idx = 0; hit_idx < hit_count; hit_idx++) {
375 const int facet = hit_facets[hit_idx];
376 T normal_x, normal_y, normal_z;
377 T wall_x, wall_y, wall_z;
380 normal_x, normal_y, normal_z);
381 if (
lpt_norm3(normal_x, normal_y, normal_z) <= (T) 1.0e-12) {
386 wall_x, wall_y, wall_z);
388 normal_x, normal_y, normal_z, radius);
398 normal_x, normal_y, normal_z);
400 normal_x, normal_y, normal_z);
405 normal_x, normal_y, normal_z);
407 acc_zlaglag[p], normal_x, normal_y,
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ w
__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__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const int *__restrict__ const int nelv
__global__ void const T *__restrict__ u
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ v
__global__ void const T *__restrict__ x
__device__ void coef_get_normal_device(const T *__restrict__ nx, const T *__restrict__ ny, const T *__restrict__ nz, const int i, const int j, const int k, const int e, const int facet, const int lx, T &normal_x, T &normal_y, T &normal_z)
__device__ int lpt_wall_dof_idx(const int i, const int j, const int k, const int e, const int lx, const int ly, const int lz)
__device__ T lpt_signed_plane_distance(const T x, const T y, const T z, const T wall_x, const T wall_y, const T wall_z, const T normal_x, const T normal_y, const T normal_z)
__device__ int lpt_wall_imax(const int a, const int b)
__device__ void lpt_wall_facet_normal(const T *__restrict__ nx, const T *__restrict__ ny, const T *__restrict__ nz, const int lx, const int ly, const int lz, const int el, const int facet, T &normal_x, T &normal_y, T &normal_z)
__device__ void lpt_reflect_position(T &x, T &y, T &z, const T wall_x, const T wall_y, const T wall_z, const T normal_x, const T normal_y, const T normal_z, const T radius)
__device__ int lpt_wall_mask_idx(const int facet, const int el, const int n_facets)
__device__ void lpt_wall_facet_center(const T *__restrict__ dm_x, const T *__restrict__ dm_y, const T *__restrict__ dm_z, const int lx, const int ly, const int lz, const int el, const int facet, T &wall_x, T &wall_y, T &wall_z)
__device__ T lpt_norm3(const T x, const T y, const T z)
__device__ bool lpt_wall_facet_is_hit(const int *__restrict__ wall_facet_mask, const T *__restrict__ dm_x, const T *__restrict__ dm_y, const T *__restrict__ dm_z, const T *__restrict__ nx, const T *__restrict__ ny, const T *__restrict__ nz, const int lx, const int ly, const int lz, const int el, const int facet, const int gdim, const T x_old, const T y_old, const T z_old, const T x, const T y, const T z, const T radius)
__device__ void lpt_reflect_vector_components(T &x, T &y, T &z, const T normal_x, const T normal_y, const T normal_z)
__global__ void lpt_handle_elastic_wall_collisions_kernel(const int *__restrict__ wall_facet_mask, const int *__restrict__ el_list, const T *__restrict__ x_old, const T *__restrict__ y_old, const T *__restrict__ z_old, T *__restrict__ x, T *__restrict__ y, T *__restrict__ z, const T *__restrict__ d, 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, T *__restrict__ u_old, T *__restrict__ v_old, T *__restrict__ w_old, T *__restrict__ acc_x, T *__restrict__ acc_y, T *__restrict__ acc_z, const T *__restrict__ dm_x, const T *__restrict__ dm_y, const T *__restrict__ dm_z, const T *__restrict__ nx, const T *__restrict__ ny, const T *__restrict__ nz, const int n, const int gdim, const int nelv, const int lx, const int ly, const int lz, const int lag_len)