22#ifndef PECLET_VORO_ENERGY_LLOYD_HPP
23#define PECLET_VORO_ENERGY_LLOYD_HPP
25#include <Kokkos_Core.hpp>
35 const Kokkos::View<Real*, peclet::core::MemSpace>& pos,
36 const Kokkos::View<Real*, peclet::core::MemSpace>& out) {
37 using Exec = peclet::core::ExecSpace;
40 "energy.centroid", Kokkos::RangePolicy<Exec>(0, N), KOKKOS_LAMBDA(
const int i) {
41 Real m[3] = {0, 0, 0}, V = 0;
43 const Real ax = view.
area(f, 0), ay = view.
area(f, 1), az = view.
area(f, 2);
44 const Real A = Kokkos::sqrt(ax * ax + ay * ay + az * az);
48 const Real rl = Kokkos::sqrt(rx * rx + ry * ry + rz * rz);
49 const Real h = Real(0.5) * rl;
50 const Real s = rl / A;
51 const Real cx = rx - view.
connect(f, 0) * s, cy = ry - view.
connect(f, 1) * s,
52 cz = rz - view.
connect(f, 2) * s;
53 const Real Vf = h * A / Real(3);
55 m[0] += Vf * Real(0.75) * cx;
56 m[1] += Vf * Real(0.75) * cy;
57 m[2] += Vf * Real(0.75) * cz;
59 const Real iv = V > Real(0) ? Real(1) / V : Real(0);
60 for (
int c = 0; c < 3; ++c)
61 out(3 * i + c) = pos(3 * i + c) + m[c] * iv;
69 [[maybe_unused]]
const Kokkos::View<Real*, peclet::core::MemSpace>& pos,
70 Real gamma,
const Kokkos::View<Real*, peclet::core::MemSpace>& force) {
71 using Exec = peclet::core::ExecSpace;
75 Kokkos::parallel_reduce(
76 "energy.lloyd", Kokkos::RangePolicy<Exec>(0, N),
77 KOKKOS_LAMBDA(
const int i, Real& acc) {
78 Real m[3] = {0, 0, 0}, V = 0, e = 0;
80 const Real ax = view.
area(f, 0), ay = view.
area(f, 1), az = view.
area(f, 2);
81 const Real A = Kokkos::sqrt(ax * ax + ay * ay + az * az);
85 const Real rl = Kokkos::sqrt(rx * rx + ry * ry + rz * rz);
86 const Real h = Real(0.5) * rl;
87 const Real s = rl / A;
88 const Real cx = rx - view.
connect(f, 0) * s, cy = ry - view.
connect(f, 1) * s,
89 cz = rz - view.
connect(f, 2) * s;
90 const Real Vf = h * A / Real(3);
92 m[0] += Vf * Real(0.75) * cx;
93 m[1] += Vf * Real(0.75) * cy;
94 m[2] += Vf * Real(0.75) * cz;
96 e += h * (h * h * A + view.
moment2(f)) / Real(5);
99 for (
int c = 0; c < 3; ++c)
100 Kokkos::atomic_add(&force(3 * i + c), Real(-2) * gamma * m[c]);
104 return haveM2 ? E : Real(-1);
Definition interface.hpp:23
void cellCentroids(const TessellationView< Real > &view, const Kokkos::View< Real *, peclet::core::MemSpace > &pos, const Kokkos::View< Real *, peclet::core::MemSpace > &out)
Cell centroids (3N, world = seed + relative) from the facet CSR. pos supplies the seeds.
Definition lloyd.hpp:34
Real lloydEnergyForce(const TessellationView< Real > &view, const Kokkos::View< Real *, peclet::core::MemSpace > &pos, Real gamma, const Kokkos::View< Real *, peclet::core::MemSpace > &force)
Definition lloyd.hpp:68
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 moment2(int f) const
Definition tessellation_view.hpp:162
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 Real connVec(int f, int c) const
Definition tessellation_view.hpp:188
KOKKOS_INLINE_FUNCTION bool hasMoments() const
Definition tessellation_view.hpp:161
KOKKOS_INLINE_FUNCTION int facetBegin(int i) const
Definition tessellation_view.hpp:181
KOKKOS_INLINE_FUNCTION int numCells() const
Definition tessellation_view.hpp:173
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).