peclet.voro 1.0.0
Device-native moving-particle Voronoi dynamics
Loading...
Searching...
No Matches
plane_policy.hpp
Go to the documentation of this file.
1
29#ifndef PECLET_VORO_PLANE_POLICY_HPP
30#define PECLET_VORO_PLANE_POLICY_HPP
31
32#include <Kokkos_Core.hpp>
33
34namespace peclet::voro {
35
39struct Voronoi {
41 static constexpr bool kHasWeightDof = false;
42
45 template <class Real>
46 KOKKOS_INLINE_FUNCTION static Real offsetFromRel(const Real r[3], Real wSelf, Real wNbr) {
47 (void)wSelf;
48 (void)wNbr;
49 return Real(0.5) * (r[0] * r[0] + r[1] * r[1] + r[2] * r[2]);
50 }
51
57 template <class Real>
58 KOKKOS_INLINE_FUNCTION static Real blockReachSq(Real rSqMax, Real wSelf, Real wMaxAll) {
59 (void)wSelf;
60 (void)wMaxAll;
61 return Real(4) * rSqMax;
62 }
63
66 template <class Real>
67 KOKKOS_INLINE_FUNCTION static void planeFromNeighbour(const Real pSelf[3], const Real pNbr[3],
68 Real wSelf, Real wNbr, Real L, Real pdir[3],
69 Real& off) {
70 const Real Lh = Real(0.5) * L;
71 for (int d = 0; d < 3; ++d) {
72 Real r = pNbr[d] - pSelf[d];
73 r = r > Lh ? r - L : (r < -Lh ? r + L : r);
74 pdir[d] = r;
75 }
76 off = offsetFromRel(pdir, wSelf, wNbr);
77 }
78
81 template <class Real>
82 KOKKOS_INLINE_FUNCTION static void buildNormal(const Real pSelf[3], const Real pNbr[3], Real wSelf,
83 Real wNbr, Real L, Real nOut[3]) {
84 Real pdir[3], off;
85 planeFromNeighbour(pSelf, pNbr, wSelf, wNbr, L, pdir, off);
86 const Real l2 = pdir[0] * pdir[0] + pdir[1] * pdir[1] + pdir[2] * pdir[2];
87 const Real a = l2 > Real(0) ? off / l2 : Real(0);
88 for (int d = 0; d < 3; ++d) nOut[d] = a * pdir[d];
89 }
90
94 template <class Real>
95 KOKKOS_INLINE_FUNCTION static void chain(const Real g[3], const Real r[3], Real rho, Real c,
96 Real fSelf[3], Real fNbr[3], Real& fwSelf, Real& fwNbr) {
97 (void)r;
98 (void)rho;
99 (void)c;
100 for (int d = 0; d < 3; ++d) {
101 fSelf[d] = Real(-0.5) * g[d];
102 fNbr[d] = Real(0.5) * g[d];
103 }
104 fwSelf = Real(0);
105 fwNbr = Real(0);
106 }
107};
108
113struct Power {
114 static constexpr bool kHasWeightDof = true;
115
118 template <class Real>
119 KOKKOS_INLINE_FUNCTION static Real offsetFromRel(const Real r[3], Real wSelf, Real wNbr) {
120 return Real(0.5) * (r[0] * r[0] + r[1] * r[1] + r[2] * r[2] + wSelf - wNbr);
121 }
122
128 template <class Real>
129 KOKKOS_INLINE_FUNCTION static Real blockReachSq(Real rSqMax, Real wSelf, Real wMaxAll) {
130 const Real rm = Kokkos::sqrt(rSqMax);
131 const Real span = wMaxAll - wSelf > Real(0) ? wMaxAll - wSelf : Real(0);
132 const Real t = rm + Kokkos::sqrt(rSqMax + span);
133 return t * t;
134 }
135
138 template <class Real>
139 KOKKOS_INLINE_FUNCTION static void planeFromNeighbour(const Real pSelf[3], const Real pNbr[3],
140 Real wSelf, Real wNbr, Real L, Real pdir[3],
141 Real& off) {
142 const Real Lh = Real(0.5) * L;
143 for (int d = 0; d < 3; ++d) {
144 Real r = pNbr[d] - pSelf[d];
145 r = r > Lh ? r - L : (r < -Lh ? r + L : r);
146 pdir[d] = r;
147 }
148 off = offsetFromRel(pdir, wSelf, wNbr);
149 }
150
152 template <class Real>
153 KOKKOS_INLINE_FUNCTION static void buildNormal(const Real pSelf[3], const Real pNbr[3], Real wSelf,
154 Real wNbr, Real L, Real nOut[3]) {
155 Real pdir[3], off;
156 planeFromNeighbour(pSelf, pNbr, wSelf, wNbr, L, pdir, off);
157 const Real l2 = pdir[0] * pdir[0] + pdir[1] * pdir[1] + pdir[2] * pdir[2];
158 const Real a = l2 > Real(0) ? off / l2 : Real(0);
159 for (int d = 0; d < 3; ++d) nOut[d] = a * pdir[d];
160 }
161
168 template <class Real>
169 KOKKOS_INLINE_FUNCTION static void chain(const Real g[3], const Real r[3], Real rho, Real c,
170 Real fSelf[3], Real fNbr[3], Real& fwSelf, Real& fwNbr) {
171 const Real invRho = rho > Real(0) ? Real(1) / rho : Real(0);
172 const Real alpha = Real(0.5) + Real(0.5) * c * invRho;
173 const Real rg = r[0] * g[0] + r[1] * g[1] + r[2] * g[2];
174 const Real kk = c * invRho * invRho * rg; // (c/ρ²)(r·g)
175 for (int d = 0; d < 3; ++d) {
176 const Real jn = alpha * g[d] - kk * r[d]; // dGeom/dp_nbr component
177 fNbr[d] = jn;
178 fSelf[d] = -jn;
179 }
180 const Real w = Real(0.5) * invRho * rg; // (g·r)/(2ρ)
181 fwSelf = w;
182 fwNbr = -w;
183 }
184};
185
196template <class Policy, class Cell, class Real>
197KOKKOS_INLINE_FUNCTION void chainToDofs(const Cell& c, const Real seed[3], const Real* pos,
198 Real wSelf, const Real* weight, Real L, const Real* gx,
199 const Real* gy, const Real* gz, Real fSelf[3], Real& fwSelf,
200 Real* fnx, Real* fny, Real* fnz, Real* fwn) {
201 fSelf[0] = fSelf[1] = fSelf[2] = Real(0);
202 fwSelf = Real(0);
203 const Real Lh = Real(0.5) * L;
204 for (int k = 0; k < c.np; ++k) {
205 const int j = c.pnbr[k];
206 if (j < 0) { // box (−1) / SDF wall (−2): no particle-DOF dependence here
207 fnx[k] = fny[k] = fnz[k] = Real(0);
208 fwn[k] = Real(0);
209 continue;
210 }
211 const Real g[3] = {gx[k], gy[k], gz[k]};
212 Real r[3] = {Real(0), Real(0), Real(0)}, rho = Real(0), cc = Real(0);
213 if constexpr (Policy::kHasWeightDof) {
214 for (int d = 0; d < 3; ++d) {
215 Real rr = pos[3 * j + d] - seed[d];
216 rr = rr > Lh ? rr - L : (rr < -Lh ? rr + L : rr);
217 r[d] = rr;
218 }
219 rho = r[0] * r[0] + r[1] * r[1] + r[2] * r[2];
220 cc = wSelf - weight[j];
221 }
222 Real fs[3], fn[3], fws = Real(0), fwn1 = Real(0);
223 Policy::template chain<Real>(g, r, rho, cc, fs, fn, fws, fwn1);
224 fSelf[0] += fs[0];
225 fSelf[1] += fs[1];
226 fSelf[2] += fs[2];
227 fwSelf += fws;
228 fnx[k] = fn[0];
229 fny[k] = fn[1];
230 fnz[k] = fn[2];
231 fwn[k] = fwn1;
232 }
233}
234
235} // namespace peclet::voro
236
237#endif // PECLET_VORO_PLANE_POLICY_HPP
Definition convex_cell.hpp:40
KOKKOS_INLINE_FUNCTION void chainToDofs(const Cell &c, const Real seed[3], const Real *pos, Real wSelf, const Real *weight, Real L, const Real *gx, const Real *gy, const Real *gz, Real fSelf[3], Real &fwSelf, Real *fnx, Real *fny, Real *fnz, Real *fwn)
Definition plane_policy.hpp:197
Definition plane_policy.hpp:113
static KOKKOS_INLINE_FUNCTION Real blockReachSq(Real rSqMax, Real wSelf, Real wMaxAll)
Definition plane_policy.hpp:129
static KOKKOS_INLINE_FUNCTION Real offsetFromRel(const Real r[3], Real wSelf, Real wNbr)
Definition plane_policy.hpp:119
static constexpr bool kHasWeightDof
Definition plane_policy.hpp:114
static KOKKOS_INLINE_FUNCTION void buildNormal(const Real pSelf[3], const Real pNbr[3], Real wSelf, Real wNbr, Real L, Real nOut[3])
Foot-point normal n = (off/|pdir|²) pdir = α r.
Definition plane_policy.hpp:153
static KOKKOS_INLINE_FUNCTION void planeFromNeighbour(const Real pSelf[3], const Real pNbr[3], Real wSelf, Real wNbr, Real L, Real pdir[3], Real &off)
Definition plane_policy.hpp:139
static KOKKOS_INLINE_FUNCTION void chain(const Real g[3], const Real r[3], Real rho, Real c, Real fSelf[3], Real fNbr[3], Real &fwSelf, Real &fwNbr)
Definition plane_policy.hpp:169
Definition plane_policy.hpp:39
static KOKKOS_INLINE_FUNCTION void buildNormal(const Real pSelf[3], const Real pNbr[3], Real wSelf, Real wNbr, Real L, Real nOut[3])
Definition plane_policy.hpp:82
static KOKKOS_INLINE_FUNCTION void chain(const Real g[3], const Real r[3], Real rho, Real c, Real fSelf[3], Real fNbr[3], Real &fwSelf, Real &fwNbr)
Definition plane_policy.hpp:95
static KOKKOS_INLINE_FUNCTION Real offsetFromRel(const Real r[3], Real wSelf, Real wNbr)
Definition plane_policy.hpp:46
static KOKKOS_INLINE_FUNCTION Real blockReachSq(Real rSqMax, Real wSelf, Real wMaxAll)
Definition plane_policy.hpp:58
static KOKKOS_INLINE_FUNCTION void planeFromNeighbour(const Real pSelf[3], const Real pNbr[3], Real wSelf, Real wNbr, Real L, Real pdir[3], Real &off)
Definition plane_policy.hpp:67
static constexpr bool kHasWeightDof
Whether cells carry a per-seed weight DOF (Laguerre). Voronoi cells do not.
Definition plane_policy.hpp:41