20#ifndef PECLET_VORO_VERLET_SKIN_HPP
21#define PECLET_VORO_VERLET_SKIN_HPP
23#include <Kokkos_Core.hpp>
26#include "peclet/core/common/view.hpp"
43 using Mem = peclet::core::MemSpace;
44 using Exec = peclet::core::ExecSpace;
45 Kokkos::View<Real*, Mem>
xRef;
49 void alloc(
int n, Real skinWidth) {
52 xRef = Kokkos::View<Real*, Mem>(
53 Kokkos::view_alloc(std::string(
"verlet.xRef"), Kokkos::WithoutInitializing), (
size_t)n * 3);
57 void reset(
const Kokkos::View<Real*, Mem>& pos) { Kokkos::deep_copy(
xRef, pos); }
66 const Kokkos::View<Real*, peclet::core::MemSpace>& xRef, Real skin,
67 const Real L[3],
const Kokkos::View<int*, peclet::core::MemSpace>& outFlags) {
68 using Exec = peclet::core::ExecSpace;
69 const int N = (int)outFlags.extent(0);
70 const Real half2 = Real(0.25) * skin * skin;
71 const Real Lx = L[0], Ly = L[1], Lz = L[2];
72 const Real Lxh = Real(0.5) * Lx, Lyh = Real(0.5) * Ly, Lzh = Real(0.5) * Lz;
74 Kokkos::parallel_reduce(
75 "verlet.flag", Kokkos::RangePolicy<Exec>(0, N),
76 KOKKOS_LAMBDA(
const int i,
int& acc) {
77 Real dx = pos(3 * i + 0) - xRef(3 * i + 0);
78 Real dy = pos(3 * i + 1) - xRef(3 * i + 1);
79 Real dz = pos(3 * i + 2) - xRef(3 * i + 2);
80 dx = dx > Lxh ? dx - Lx : (dx < -Lxh ? dx + Lx : dx);
81 dy = dy > Lyh ? dy - Ly : (dy < -Lyh ? dy + Ly : dy);
82 dz = dz > Lzh ? dz - Lz : (dz < -Lzh ? dz + Lz : dz);
83 const Real d2 = dx * dx + dy * dy + dz * dz;
84 const bool mover = d2 > half2;
97 const Kokkos::View<Real*, peclet::core::MemSpace>& xRef,
const Real L[3]) {
98 using Exec = peclet::core::ExecSpace;
99 const int N = (int)(xRef.extent(0) / 3);
100 const Real Lx = L[0], Ly = L[1], Lz = L[2];
101 const Real Lxh = Real(0.5) * Lx, Lyh = Real(0.5) * Ly, Lzh = Real(0.5) * Lz;
103 Kokkos::parallel_reduce(
104 "verlet.maxDisp", Kokkos::RangePolicy<Exec>(0, N),
105 KOKKOS_LAMBDA(
const int i, Real& lm) {
106 Real dx = pos(3 * i + 0) - xRef(3 * i + 0);
107 Real dy = pos(3 * i + 1) - xRef(3 * i + 1);
108 Real dz = pos(3 * i + 2) - xRef(3 * i + 2);
109 dx = dx > Lxh ? dx - Lx : (dx < -Lxh ? dx + Lx : dx);
110 dy = dy > Lyh ? dy - Ly : (dy < -Lyh ? dy + Ly : dy);
111 dz = dz > Lzh ? dz - Lz : (dz < -Lzh ? dz + Lz : dz);
112 const Real d2 = dx * dx + dy * dy + dz * dz;
116 Kokkos::Max<Real>(m2));
117 return Kokkos::sqrt(m2);
Definition convex_cell.hpp:40
int flagSkinMovers(const Kokkos::View< Real *, peclet::core::MemSpace > &pos, const Kokkos::View< Real *, peclet::core::MemSpace > &xRef, Real skin, const Real L[3], const Kokkos::View< int *, peclet::core::MemSpace > &outFlags)
Definition verlet_skin.hpp:65
Real maxDisplacement(const Kokkos::View< Real *, peclet::core::MemSpace > &pos, const Kokkos::View< Real *, peclet::core::MemSpace > &xRef, const Real L[3])
Definition verlet_skin.hpp:96
SkinTrigger
Definition verlet_skin.hpp:33
@ kSkinNone
Definition verlet_skin.hpp:34
@ kSkinMover
Definition verlet_skin.hpp:35
Definition verlet_skin.hpp:42
void alloc(int n, Real skinWidth)
Definition verlet_skin.hpp:49
Real skin
skin width in absolute length units (caller picks vs spacing)
Definition verlet_skin.hpp:46
Kokkos::View< Real *, Mem > xRef
3N: seed positions at the last rebuild
Definition verlet_skin.hpp:45
void reset(const Kokkos::View< Real *, Mem > &pos)
Capture the reference configuration (call immediately after a full (re)build).
Definition verlet_skin.hpp:57
peclet::core::MemSpace Mem
Definition verlet_skin.hpp:43
int N
Definition verlet_skin.hpp:47
peclet::core::ExecSpace Exec
Definition verlet_skin.hpp:44