peclet.voro 1.0.4
Device-native moving-particle Voronoi dynamics
Loading...
Searching...
No Matches
wall.hpp
Go to the documentation of this file.
1
22#ifndef PECLET_VORO_ENERGY_WALL_HPP
23#define PECLET_VORO_ENERGY_WALL_HPP
24
25#include <Kokkos_Core.hpp>
26#include <type_traits>
27
29#include "peclet/voro/sdf.hpp"
30
31namespace peclet::voro::energy {
32
39template <class Real, class Policy = Voronoi, class Sdf = NoSdf>
41 const Kokkos::View<int*, peclet::core::MemSpace>& types,
42 const Kokkos::View<Real*, peclet::core::MemSpace>& sigmaS, const Sdf& sdf,
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 using Exec = peclet::core::ExecSpace;
48 const int N = view.numCells();
49 Real E = 0;
50 Kokkos::parallel_reduce(
51 "energy.wall", Kokkos::RangePolicy<Exec>(0, N),
52 KOKKOS_LAMBDA(const int i, Real& acc) {
53 const Real sig = sigmaS(types(i));
54 if (sig == Real(0))
55 return;
56 Real gl[detail::kMaxLocalFacets * 3];
57 const int b = view.facetBegin(i), nf = view.facetEnd(i) - b;
59 return;
60 for (int k = 0; k < 3 * nf; ++k)
61 gl[k] = Real(0);
62 bool any = false;
63 const bool fd = view.hasWallFD(); // exact wall-plane part (sdfWallFD) instead of the chain
64 for (int f = b; f < b + nf; ++f) {
65 if (view.facetNbr(f) != kBoundaryFacet)
66 continue;
67 any = true;
68 const Real ax = view.area(f, 0), ay = view.area(f, 1), az = view.area(f, 2);
69 acc += sig * Kokkos::sqrt(ax * ax + ay * ay + az * az);
70 for (int e = view.edgeBegin(f); e < view.edgeEnd(f); ++e) {
71 const int p = view.edgePartner(e) - b;
72 if (fd && view.facetNbr(b + p) == kBoundaryFacet)
73 continue; // wall-plane dependence comes from the FD part below
74 for (int c = 0; c < 3; ++c)
75 gl[3 * p + c] += sig * view.areaGrad(e, c);
76 }
77 }
78 if (any) {
79 detail::routeCellGradient<Real, Policy>(view, i, gl, nf, pos, weight, L, sdf, force,
80 forceW);
81 if (fd)
82 for (int c = 0; c < 3; ++c)
83 Kokkos::atomic_add(&force(3 * i + c), sig * view.wallDA(i, c));
84 }
85 },
86 E);
87 return E;
88}
89
90} // namespace peclet::voro::energy
91
92#endif // PECLET_VORO_ENERGY_WALL_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 wallEnergyForce(const TessellationView< Real > &view, const Kokkos::View< int *, peclet::core::MemSpace > &types, const Kokkos::View< Real *, peclet::core::MemSpace > &sigmaS, const Sdf &sdf, 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={})
Definition wall.hpp:40
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 wallDA(int i, int c) const
Definition tessellation_view.hpp:155
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 bool hasWallFD() const
Definition tessellation_view.hpp:153
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