peclet.voro 1.0.4
Device-native moving-particle Voronoi dynamics
Loading...
Searching...
No Matches
tension.hpp
Go to the documentation of this file.
1
8#ifndef PECLET_VORO_ENERGY_TENSION_HPP
9#define PECLET_VORO_ENERGY_TENSION_HPP
10
11#include <Kokkos_Core.hpp>
12
15
16namespace peclet::voro::energy {
17
18template <class Real, class Policy = Voronoi, class Sdf = NoSdf>
20 const Kokkos::View<Real*, peclet::core::MemSpace>& pos,
21 const Kokkos::View<Real*, peclet::core::MemSpace>& weight, Real L,
22 const Kokkos::View<Real*, peclet::core::MemSpace>& force,
23 const Kokkos::View<Real*, peclet::core::MemSpace>& forceW = {},
24 const Sdf& sdf = Sdf{}) {
25 using Exec = peclet::core::ExecSpace;
26 const int N = view.numCells();
27 Real E = 0;
28 Kokkos::parallel_reduce(
29 "energy.tension", Kokkos::RangePolicy<Exec>(0, N),
30 KOKKOS_LAMBDA(const int i, Real& acc) {
31 Real gl[detail::kMaxLocalFacets * 3];
32 const int b = view.facetBegin(i), nf = view.facetEnd(i) - b;
34 return;
35 for (int k = 0; k < 3 * nf; ++k)
36 gl[k] = Real(0);
37 const Real half = Real(0.5) * sigma; // each interior face is seen from both cells
38 bool any = false;
39 for (int f = b; f < b + nf; ++f) {
40 const int j = view.facetNbr(f);
41 if (j < 0 || j >= N)
42 continue;
43 any = true;
44 const Real ax = view.area(f, 0), ay = view.area(f, 1), az = view.area(f, 2);
45 acc += half * Kokkos::sqrt(ax * ax + ay * ay + az * az);
46 for (int e = view.edgeBegin(f); e < view.edgeEnd(f); ++e) {
47 const int p = view.edgePartner(e) - b;
48 for (int c = 0; c < 3; ++c)
49 gl[3 * p + c] += half * view.areaGrad(e, c);
50 }
51 }
52 if (any)
53 detail::routeCellGradient<Real, Policy>(view, i, gl, nf, pos, weight, L, sdf, force,
54 forceW);
55 },
56 E);
57 return E;
58}
59
60} // namespace peclet::voro::energy
61
62#endif // PECLET_VORO_ENERGY_TENSION_HPP
KOKKOS_INLINE_FUNCTION Dual< Real, K > dnum(Real c)
Definition convex_cell.hpp:53
constexpr int kMaxLocalFacets
Facets one cell may publish (CellBuilder::MAXF_TMP); bounds the per-thread gradient array.
Definition route.hpp:29
Definition interface.hpp:23
Real facetTensionEnergyForce(const TessellationView< Real > &view, Real sigma, const Kokkos::View< Real *, peclet::core::MemSpace > &pos, const Kokkos::View< Real *, peclet::core::MemSpace > &weight, Real L, const Kokkos::View< Real *, peclet::core::MemSpace > &force, const Kokkos::View< Real *, peclet::core::MemSpace > &forceW={}, const Sdf &sdf=Sdf{})
Definition tension.hpp:19
Rung A3: route a cell's per-facet geometry gradient to the seed DOFs on the PUBLISHED view — the one ...
Definition tessellation_view.hpp:111
KOKKOS_INLINE_FUNCTION Real area(int f, int c) const
Definition tessellation_view.hpp:186
KOKKOS_INLINE_FUNCTION int facetEnd(int i) const
Definition tessellation_view.hpp:182
KOKKOS_INLINE_FUNCTION gid_t facetNbr(int f) const
Definition tessellation_view.hpp:185
KOKKOS_INLINE_FUNCTION int edgePartner(int e) const
Definition tessellation_view.hpp:168
KOKKOS_INLINE_FUNCTION int facetBegin(int i) const
Definition tessellation_view.hpp:181
KOKKOS_INLINE_FUNCTION int edgeBegin(int f) const
Definition tessellation_view.hpp:166
KOKKOS_INLINE_FUNCTION int numCells() const
Definition tessellation_view.hpp:173
KOKKOS_INLINE_FUNCTION int edgeEnd(int f) const
Definition tessellation_view.hpp:167
KOKKOS_INLINE_FUNCTION Real areaGrad(int e, int c) const
Definition tessellation_view.hpp:169
Published, read-only device data layer for the tessellation (migration §2.1, §3).