peclet.voro 1.0.0
Device-native moving-particle Voronoi dynamics
Loading...
Searching...
No Matches
verlet_skin.hpp
Go to the documentation of this file.
1
20#ifndef PECLET_VORO_VERLET_SKIN_HPP
21#define PECLET_VORO_VERLET_SKIN_HPP
22
23#include <Kokkos_Core.hpp>
24#include <string>
25
26#include "peclet/core/common/view.hpp"
27
28namespace peclet::voro {
29
33enum SkinTrigger : int {
36 // kSkinBoundary = 2, // DEFERRED (Risk 1d): |SDF(p)| < security radius contact-status change.
37};
38
41template <class Real>
42struct VerletSkin {
43 using Mem = peclet::core::MemSpace;
44 using Exec = peclet::core::ExecSpace;
45 Kokkos::View<Real*, Mem> xRef;
46 Real skin = 0;
47 int N = 0;
48
49 void alloc(int n, Real skinWidth) {
50 N = n;
51 skin = skinWidth;
52 xRef = Kokkos::View<Real*, Mem>(
53 Kokkos::view_alloc(std::string("verlet.xRef"), Kokkos::WithoutInitializing), (size_t)n * 3);
54 }
55
57 void reset(const Kokkos::View<Real*, Mem>& pos) { Kokkos::deep_copy(xRef, pos); }
58};
59
64template <class Real>
65int flagSkinMovers(const Kokkos::View<Real*, peclet::core::MemSpace>& 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; // (skin/2)^2
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;
73 int count = 0;
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;
85 outFlags(i) = mover ? kSkinMover : kSkinNone;
86 if (mover)
87 ++acc;
88 },
89 count);
90 return count;
91}
92
95template <class Real>
96Real maxDisplacement(const Kokkos::View<Real*, peclet::core::MemSpace>& pos,
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;
102 Real m2 = 0;
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;
113 if (d2 > lm)
114 lm = d2;
115 },
116 Kokkos::Max<Real>(m2));
117 return Kokkos::sqrt(m2);
118}
119
120} // namespace peclet::voro
121
122#endif // PECLET_VORO_VERLET_SKIN_HPP
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