peclet.voro 1.0.4
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],
83 Real wSelf, 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)
89 nOut[d] = a * pdir[d];
90 }
91
95 template <class Real>
96 KOKKOS_INLINE_FUNCTION static void chain(const Real g[3], const Real r[3], Real rho, Real c,
97 Real fSelf[3], Real fNbr[3], Real& fwSelf, Real& fwNbr) {
98 (void)r;
99 (void)rho;
100 (void)c;
101 for (int d = 0; d < 3; ++d) {
102 fSelf[d] = Real(-0.5) * g[d];
103 fNbr[d] = Real(0.5) * g[d];
104 }
105 fwSelf = Real(0);
106 fwNbr = Real(0);
107 }
108};
109
115struct Power {
116 static constexpr bool kHasWeightDof = true;
117
120 template <class Real>
121 KOKKOS_INLINE_FUNCTION static Real offsetFromRel(const Real r[3], Real wSelf, Real wNbr) {
122 return Real(0.5) * (r[0] * r[0] + r[1] * r[1] + r[2] * r[2] + wSelf - wNbr);
123 }
124
130 template <class Real>
131 KOKKOS_INLINE_FUNCTION static Real blockReachSq(Real rSqMax, Real wSelf, Real wMaxAll) {
132 const Real rm = Kokkos::sqrt(rSqMax);
133 const Real span = wMaxAll - wSelf > Real(0) ? wMaxAll - wSelf : Real(0);
134 const Real t = rm + Kokkos::sqrt(rSqMax + span);
135 return t * t;
136 }
137
140 template <class Real>
141 KOKKOS_INLINE_FUNCTION static void planeFromNeighbour(const Real pSelf[3], const Real pNbr[3],
142 Real wSelf, Real wNbr, Real L, Real pdir[3],
143 Real& off) {
144 const Real Lh = Real(0.5) * L;
145 for (int d = 0; d < 3; ++d) {
146 Real r = pNbr[d] - pSelf[d];
147 r = r > Lh ? r - L : (r < -Lh ? r + L : r);
148 pdir[d] = r;
149 }
150 off = offsetFromRel(pdir, wSelf, wNbr);
151 }
152
154 template <class Real>
155 KOKKOS_INLINE_FUNCTION static void buildNormal(const Real pSelf[3], const Real pNbr[3],
156 Real wSelf, Real wNbr, Real L, Real nOut[3]) {
157 Real pdir[3], off;
158 planeFromNeighbour(pSelf, pNbr, wSelf, wNbr, L, pdir, off);
159 const Real l2 = pdir[0] * pdir[0] + pdir[1] * pdir[1] + pdir[2] * pdir[2];
160 const Real a = l2 > Real(0) ? off / l2 : Real(0);
161 for (int d = 0; d < 3; ++d)
162 nOut[d] = a * pdir[d];
163 }
164
171 template <class Real>
172 KOKKOS_INLINE_FUNCTION static void chain(const Real g[3], const Real r[3], Real rho, Real c,
173 Real fSelf[3], Real fNbr[3], Real& fwSelf, Real& fwNbr) {
174 const Real invRho = rho > Real(0) ? Real(1) / rho : Real(0);
175 const Real alpha = Real(0.5) + Real(0.5) * c * invRho;
176 const Real rg = r[0] * g[0] + r[1] * g[1] + r[2] * g[2];
177 const Real kk = c * invRho * invRho * rg; // (c/ρ²)(r·g)
178 for (int d = 0; d < 3; ++d) {
179 const Real jn = alpha * g[d] - kk * r[d]; // dGeom/dp_nbr component
180 fNbr[d] = jn;
181 fSelf[d] = -jn;
182 }
183 const Real w = Real(0.5) * invRho * rg; // (g·r)/(2ρ)
184 fwSelf = w;
185 fwNbr = -w;
186 }
187};
188
199template <class Policy, class Cell, class Real>
200KOKKOS_INLINE_FUNCTION void chainToDofs(const Cell& c, const Real seed[3], const Real* pos,
201 Real wSelf, const Real* weight, Real L, const Real* gx,
202 const Real* gy, const Real* gz, Real fSelf[3], Real& fwSelf,
203 Real* fnx, Real* fny, Real* fnz, Real* fwn) {
204 fSelf[0] = fSelf[1] = fSelf[2] = Real(0);
205 fwSelf = Real(0);
206 const Real Lh = Real(0.5) * L;
207 for (int k = 0; k < c.np; ++k) {
208 const int j = c.pnbr[k];
209 if (j < 0) { // box (−1) / SDF wall (−2): no particle-DOF dependence here
210 fnx[k] = fny[k] = fnz[k] = Real(0);
211 fwn[k] = Real(0);
212 continue;
213 }
214 const Real g[3] = {gx[k], gy[k], gz[k]};
215 Real r[3] = {Real(0), Real(0), Real(0)}, rho = Real(0), cc = Real(0);
216 if constexpr (Policy::kHasWeightDof) {
217 for (int d = 0; d < 3; ++d) {
218 Real rr = pos[3 * j + d] - seed[d];
219 rr = rr > Lh ? rr - L : (rr < -Lh ? rr + L : rr);
220 r[d] = rr;
221 }
222 rho = r[0] * r[0] + r[1] * r[1] + r[2] * r[2];
223 cc = wSelf - weight[j];
224 }
225 Real fs[3], fn[3], fws = Real(0), fwn1 = Real(0);
226 Policy::template chain<Real>(g, r, rho, cc, fs, fn, fws, fwn1);
227 fSelf[0] += fs[0];
228 fSelf[1] += fs[1];
229 fSelf[2] += fs[2];
230 fwSelf += fws;
231 fnx[k] = fn[0];
232 fny[k] = fn[1];
233 fnz[k] = fn[2];
234 fwn[k] = fwn1;
235 }
236}
237
238} // namespace peclet::voro
239
240#endif // PECLET_VORO_PLANE_POLICY_HPP
Device-native Voronoi tessellation, geometry and finite-volume physics.
Definition convex_cell.hpp:41
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:200
Definition plane_policy.hpp:115
static KOKKOS_INLINE_FUNCTION Real blockReachSq(Real rSqMax, Real wSelf, Real wMaxAll)
Definition plane_policy.hpp:131
static KOKKOS_INLINE_FUNCTION Real offsetFromRel(const Real r[3], Real wSelf, Real wNbr)
Definition plane_policy.hpp:121
static constexpr bool kHasWeightDof
Definition plane_policy.hpp:116
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:155
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:141
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:172
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:96
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