peclet.voro 1.0.4
Device-native moving-particle Voronoi dynamics
Loading...
Searching...
No Matches
interface.hpp
Go to the documentation of this file.
1
15#ifndef PECLET_VORO_ENERGY_INTERFACE_HPP
16#define PECLET_VORO_ENERGY_INTERFACE_HPP
17
18#include <Kokkos_Core.hpp>
19
22
24
28template <class Real, class Policy = Voronoi, class Sdf = NoSdf>
30 const Kokkos::View<int*, peclet::core::MemSpace>& types,
31 const Kokkos::View<Real*, peclet::core::MemSpace>& tension, int nTypes,
32 const Kokkos::View<Real*, peclet::core::MemSpace>& pos,
33 const Kokkos::View<Real*, peclet::core::MemSpace>& weight, Real L,
34 const Kokkos::View<Real*, peclet::core::MemSpace>& force,
35 const Kokkos::View<Real*, peclet::core::MemSpace>& forceW = {},
36 const Sdf& sdf = Sdf{}) {
37 using Exec = peclet::core::ExecSpace;
38 const int N = view.numCells();
39 Real E = 0;
40 Kokkos::parallel_reduce(
41 "energy.interface", Kokkos::RangePolicy<Exec>(0, N),
42 KOKKOS_LAMBDA(const int i, Real& acc) {
43 Real gl[detail::kMaxLocalFacets * 3];
44 const int b = view.facetBegin(i), nf = view.facetEnd(i) - b;
46 return;
47 for (int k = 0; k < 3 * nf; ++k)
48 gl[k] = Real(0);
49 const int ti = types(i);
50 bool any = false;
51 for (int f = b; f < b + nf; ++f) {
52 const int j = view.facetNbr(f);
53 if (j < 0 || j >= N)
54 continue;
55 const int tj = types(j);
56 if (tj == ti)
57 continue;
58 const Real sig = Real(0.5) * tension(ti * nTypes + tj);
59 if (sig == Real(0))
60 continue;
61 any = true;
62 const Real ax = view.area(f, 0), ay = view.area(f, 1), az = view.area(f, 2);
63 acc += sig * Kokkos::sqrt(ax * ax + ay * ay + az * az);
64 for (int e = view.edgeBegin(f); e < view.edgeEnd(f); ++e) {
65 const int p = view.edgePartner(e) - b;
66 for (int c = 0; c < 3; ++c)
67 gl[3 * p + c] += sig * view.areaGrad(e, c);
68 }
69 }
70 if (any)
71 detail::routeCellGradient<Real, Policy>(view, i, gl, nf, pos, weight, L, sdf, force,
72 forceW);
73 },
74 E);
75 return E;
76}
77
78} // namespace peclet::voro::energy
79
80#endif // PECLET_VORO_ENERGY_INTERFACE_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 interfaceEnergyForce(const TessellationView< Real > &view, const Kokkos::View< int *, peclet::core::MemSpace > &types, const Kokkos::View< Real *, peclet::core::MemSpace > &tension, int nTypes, 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 interface.hpp:29
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).