peclet.voro 1.0.4
Device-native moving-particle Voronoi dynamics
Loading...
Searching...
No Matches
volume.hpp
Go to the documentation of this file.
1
12#ifndef PECLET_VORO_ENERGY_VOLUME_HPP
13#define PECLET_VORO_ENERGY_VOLUME_HPP
14
15#include <Kokkos_Core.hpp>
16
19
20namespace peclet::voro::energy {
21
23template <class Real>
24KOKKOS_INLINE_FUNCTION Real dTargetVolume(Real V, Real Vref) {
25 return Real(2) * (V / Vref - Real(1)) / Vref;
26}
28template <class Real>
29KOKKOS_INLINE_FUNCTION Real dLogBarrier(Real V, Real mu) {
30 return V > Real(0) ? -mu / V : Real(0);
31}
33template <class Real>
34KOKKOS_INLINE_FUNCTION Real dFreeEnergy(Real V, Real Vref) {
35 return V > Real(0) ? -Vref / V : Real(0);
36}
37
40template <class Real, class Policy = Voronoi, class Sdf = NoSdf>
42 const Kokkos::View<Real*, peclet::core::MemSpace>& dEdV,
43 const Kokkos::View<Real*, peclet::core::MemSpace>& pos,
44 const Kokkos::View<Real*, peclet::core::MemSpace>& weight, Real L,
45 const Kokkos::View<Real*, peclet::core::MemSpace>& force,
46 const Kokkos::View<Real*, peclet::core::MemSpace>& forceW = {},
47 const Sdf& sdf = Sdf{}) {
48 using Exec = peclet::core::ExecSpace;
49 const int N = view.numCells();
50 Kokkos::parallel_for(
51 "energy.volume", Kokkos::RangePolicy<Exec>(0, N), KOKKOS_LAMBDA(const int i) {
52 const Real de = dEdV(i);
53 if (de == Real(0))
54 return;
55 Real gl[detail::kMaxLocalFacets * 3] = {}; // value-init: -Wmaybe-uninitialized
56 const int b = view.facetBegin(i), nf = view.facetEnd(i) - b;
58 return;
59 const bool fd = view.hasWallFD(); // exact wall part (sdfWallFD) instead of the chain
60 for (int k = 0; k < nf; ++k) {
61 const int f = b + k;
62 if (view.facetNbr(f) == kBoundaryFacet) {
63 for (int c = 0; c < 3; ++c)
64 gl[3 * k + c] = fd ? Real(0) : de * view.area(f, c);
65 } else {
66 for (int c = 0; c < 3; ++c)
67 gl[3 * k + c] = Real(2) * de * view.connect(f, c);
68 }
69 }
70 detail::routeCellGradient<Real, Policy>(view, i, gl, nf, pos, weight, L, sdf, force,
71 forceW);
72 if (fd)
73 for (int c = 0; c < 3; ++c)
74 Kokkos::atomic_add(&force(3 * i + c), de * view.wallDV(i, c));
75 });
76}
77
78} // namespace peclet::voro::energy
79
80#endif // PECLET_VORO_ENERGY_VOLUME_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
KOKKOS_INLINE_FUNCTION Real dLogBarrier(Real V, Real mu)
e(V) = −μ log(V/Vref) (log-barrier against collapse): e' = −μ/V.
Definition volume.hpp:29
void volumeGradientForce(const TessellationView< Real > &view, const Kokkos::View< Real *, peclet::core::MemSpace > &dEdV, 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 volume.hpp:41
KOKKOS_INLINE_FUNCTION Real dTargetVolume(Real V, Real Vref)
e(V) = (V/Vref − 1)²: e' = 2 (V/Vref − 1)/Vref.
Definition volume.hpp:24
KOKKOS_INLINE_FUNCTION Real dFreeEnergy(Real V, Real Vref)
e(V) = −Vref log V (ideal-gas free energy; equilibrium at equal pressure Vref/V): e' = −Vref/V.
Definition volume.hpp:34
constexpr int kBoundaryFacet
Definition sdf.hpp:36
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 facetBegin(int i) const
Definition tessellation_view.hpp:181
KOKKOS_INLINE_FUNCTION bool hasWallFD() const
Definition tessellation_view.hpp:153
KOKKOS_INLINE_FUNCTION int numCells() const
Definition tessellation_view.hpp:173
KOKKOS_INLINE_FUNCTION Real wallDV(int i, int c) const
Definition tessellation_view.hpp:154
KOKKOS_INLINE_FUNCTION Real connect(int f, int c) const
Definition tessellation_view.hpp:187
Published, read-only device data layer for the tessellation (migration §2.1, §3).