peclet.voro 1.0.4
Device-native moving-particle Voronoi dynamics
Loading...
Searching...
No Matches
route.hpp
Go to the documentation of this file.
1
13#ifndef PECLET_VORO_ENERGY_ROUTE_HPP
14#define PECLET_VORO_ENERGY_ROUTE_HPP
15
16#include <Kokkos_Core.hpp>
17#include <type_traits>
18
19#include "peclet/core/common/view.hpp"
21#include "peclet/voro/sdf.hpp"
23
24namespace peclet::voro::energy {
25
26namespace detail {
27
29constexpr int kMaxLocalFacets = 50;
30
33template <class Real, class Policy, class Sdf>
34KOKKOS_INLINE_FUNCTION void routeCellGradient(
35 const TessellationView<Real>& view, int i, const Real* gl, int nf,
36 const Kokkos::View<Real*, peclet::core::MemSpace>& pos,
37 const Kokkos::View<Real*, peclet::core::MemSpace>& weight, Real L, const Sdf& sdf,
38 const Kokkos::View<Real*, peclet::core::MemSpace>& force,
39 const Kokkos::View<Real*, peclet::core::MemSpace>& forceW) {
40 const int N = view.numCells();
41 const int b = view.facetBegin(i);
42 const Real Lh = Real(0.5) * L;
43 Real fSelf[3] = {Real(0), Real(0), Real(0)};
44 Real fwSelf = Real(0);
45 double gw[3] = {0.0, 0.0, 0.0};
46 Real sx = Real(0), sy = Real(0), sz = Real(0);
47 if constexpr (Policy::kHasWeightDof) {
48 sx = pos(3 * i);
49 sy = pos(3 * i + 1);
50 sz = pos(3 * i + 2);
51 }
52 for (int k = 0; k < nf; ++k) {
53 const Real g[3] = {gl[3 * k], gl[3 * k + 1], gl[3 * k + 2]};
54 if (g[0] == Real(0) && g[1] == Real(0) && g[2] == Real(0))
55 continue;
56 const int j = view.facetNbr(b + k);
57 if (j == kBoundaryFacet) {
58 gw[0] += g[0];
59 gw[1] += g[1];
60 gw[2] += g[2];
61 continue;
62 }
63 if (j < 0 || j >= N)
64 continue; // box facet: no DOF dependence
65 Real r[3] = {Real(0), Real(0), Real(0)}, rho = Real(0), cc = Real(0);
66 if constexpr (Policy::kHasWeightDof) {
67 const Real s[3] = {sx, sy, sz};
68 for (int d = 0; d < 3; ++d) {
69 Real rr = pos(3 * j + d) - s[d];
70 rr = rr > Lh ? rr - L : (rr < -Lh ? rr + L : rr);
71 r[d] = rr;
72 }
73 rho = r[0] * r[0] + r[1] * r[1] + r[2] * r[2];
74 cc = weight(i) - weight(j);
75 }
76 Real fs[3], fn[3], fws = Real(0), fwn = Real(0);
77 Policy::template chain<Real>(g, r, rho, cc, fs, fn, fws, fwn);
78 fSelf[0] += fs[0];
79 fSelf[1] += fs[1];
80 fSelf[2] += fs[2];
81 fwSelf += fws;
82 Kokkos::atomic_add(&force(3 * j), fn[0]);
83 Kokkos::atomic_add(&force(3 * j + 1), fn[1]);
84 Kokkos::atomic_add(&force(3 * j + 2), fn[2]);
85 if constexpr (Policy::kHasWeightDof)
86 if (forceW.extent(0) > 0)
87 Kokkos::atomic_add(&forceW(j), fwn);
88 }
89 if constexpr (!std::is_same_v<Sdf, NoSdf>) {
90 double fw[3] = {0.0, 0.0, 0.0};
91 Real px = pos.extent(0) > 0 ? pos(3 * i) : Real(0);
92 Real py = pos.extent(0) > 0 ? pos(3 * i + 1) : Real(0);
93 Real pz = pos.extent(0) > 0 ? pos(3 * i + 2) : Real(0);
94 sdfWallChain<Real>(sdf, px, py, pz, gw, fw);
95 fSelf[0] += (Real)fw[0];
96 fSelf[1] += (Real)fw[1];
97 fSelf[2] += (Real)fw[2];
98 } else {
99 (void)sdf;
100 }
101 Kokkos::atomic_add(&force(3 * i), fSelf[0]);
102 Kokkos::atomic_add(&force(3 * i + 1), fSelf[1]);
103 Kokkos::atomic_add(&force(3 * i + 2), fSelf[2]);
104 if constexpr (Policy::kHasWeightDof)
105 if (forceW.extent(0) > 0)
106 Kokkos::atomic_add(&forceW(i), fwSelf);
107}
108
109} // namespace detail
110} // namespace peclet::voro::energy
111
112#endif // PECLET_VORO_ENERGY_ROUTE_HPP
constexpr int kMaxLocalFacets
Facets one cell may publish (CellBuilder::MAXF_TMP); bounds the per-thread gradient array.
Definition route.hpp:29
KOKKOS_INLINE_FUNCTION void routeCellGradient(const TessellationView< Real > &view, int i, const Real *gl, int nf, const Kokkos::View< Real *, peclet::core::MemSpace > &pos, const Kokkos::View< Real *, peclet::core::MemSpace > &weight, Real L, const Sdf &sdf, const Kokkos::View< Real *, peclet::core::MemSpace > &force, const Kokkos::View< Real *, peclet::core::MemSpace > &forceW)
Definition route.hpp:34
Definition interface.hpp:23
constexpr int kBoundaryFacet
Definition sdf.hpp:36
Definition tessellation_view.hpp:111
KOKKOS_INLINE_FUNCTION gid_t facetNbr(int f) const
Definition tessellation_view.hpp:185
KOKKOS_INLINE_FUNCTION int facetBegin(int i) const
Definition tessellation_view.hpp:181
KOKKOS_INLINE_FUNCTION int numCells() const
Definition tessellation_view.hpp:173
Published, read-only device data layer for the tessellation (migration §2.1, §3).