15#ifndef PECLET_VORO_PHYSICS_SIMULATION_HPP
16#define PECLET_VORO_PHYSICS_SIMULATION_HPP
19#include <Kokkos_Core.hpp>
21#include "peclet/core/common/view.hpp"
35 using DView = Kokkos::View<Real*, peclet::core::MemSpace>;
40 const std::array<Real, 3>& L, Real pressEq) {
41 N_ =
static_cast<int>(invMass.extent(0));
48 force_ =
DView(
"force", 3 * N_);
59 viscGrad_ =
DView(Kokkos::view_alloc(
"visc.grad", Kokkos::WithoutInitializing),
60 static_cast<std::size_t
>(9) * N_);
61 viscStress_ =
DView(Kokkos::view_alloc(
"visc.stress", Kokkos::WithoutInitializing),
62 static_cast<std::size_t
>(9) * N_);
66 void step(
int nSteps, Real dt) {
67 using Exec = peclet::core::ExecSpace;
68 const Real halfDt = Real(0.5) * dt;
69 const Real Lx = L_[0], Ly = L_[1], Lz = L_[2];
74 for (
int s = 0; s < nSteps; ++s) {
76 "ee.kick1", Kokkos::RangePolicy<Exec>(0, N_), KOKKOS_LAMBDA(
const int i) {
77 for (
int k = 0; k < 3; ++k)
78 vel(3 * i + k) +=
force(3 * i + k) * im(i) * halfDt;
81 "ee.drift", Kokkos::RangePolicy<Exec>(0, N_), KOKKOS_LAMBDA(
const int i) {
82 Real x = pos(3 * i + 0) + vel(3 * i + 0) * dt;
83 Real y = pos(3 * i + 1) + vel(3 * i + 1) * dt;
84 Real z = pos(3 * i + 2) + vel(3 * i + 2) * dt;
85 pos(3 * i + 0) = x - Lx * Kokkos::floor(x / Lx);
86 pos(3 * i + 1) = y - Ly * Kokkos::floor(y / Ly);
87 pos(3 * i + 2) = z - Lz * Kokkos::floor(z / Lz);
92 "ee.kick2", Kokkos::RangePolicy<Exec>(0, N_), KOKKOS_LAMBDA(
const int i) {
93 for (
int k = 0; k < 3; ++k)
94 vel(3 * i + k) +=
force(3 * i + k) * im(i) * halfDt;
102 using Exec = peclet::core::ExecSpace;
105 Kokkos::parallel_reduce(
106 "ee.ke", Kokkos::RangePolicy<Exec>(0, N_),
107 KOKKOS_LAMBDA(
const int i, Real& acc) {
108 acc += mass(i) * (vel(3 * i + 0) * vel(3 * i + 0) + vel(3 * i + 1) * vel(3 * i + 1) +
109 vel(3 * i + 2) * vel(3 * i + 2));
112 return Real(0.5) * e;
116 using Exec = peclet::core::ExecSpace;
117 auto vol = view_.cellVolume;
118 const Real pe = pressEq_, va = volAvg_;
120 Kokkos::parallel_reduce(
121 "ee.ie", Kokkos::RangePolicy<Exec>(0, N_),
122 KOKKOS_LAMBDA(
const int i, Real& acc) { acc -= pe * va * Kokkos::log(vol(i) / va); }, e);
131 Real
time()
const {
return time_; }
139 bool repair()
const {
return useRepair_; }
142 void buildAndForce() {
143 const Real Larr[3] = {L_[0], L_[1], L_[2]};
150 const double boxVol =
static_cast<double>(L_[0]) * L_[1] * L_[2];
151 const Real spacing =
static_cast<Real
>(std::cbrt(boxVol / (N_ > 0 ? N_ : 1)));
152 mt_.
alloc(N_, Larr, Real(1e-4) * spacing, Real(0.25) * spacing, 4, N_);
158 view_ = peclet::voro::reevalPublish<Real, 64, 112>(mt_.
store, pos_, mt_.
vol, N_, Larr);
164 auto res = peclet::voro::buildTessellation<Real, false, peclet::voro::NoSdf>(
166 true, -1, {}, {}, {},
167 {}, {}, {}, 0, &wlCache_);
171 volAvg_ = (L_[0] * L_[1] * L_[2]) /
static_cast<Real
>(N_);
172 Kokkos::deep_copy(force_, Real(0));
175 viscousForce(view_, aux_.recip, aux_.cellOfFacet, vel_, visc_, bulkVisc_, force_, viscGrad_,
180 std::array<Real, 3> L_{};
181 Real pressEq_ = 0, volAvg_ = 0, time_ = 0;
182 bool viscous_ =
false;
183 DView pos_, vel_, invMass_, w_, force_, visc_, bulkVisc_;
184 DView viscGrad_, viscStress_;
187 TessellationView<Real> view_;
191 bool useRepair_ =
false, mtInit_ =
false;
Definition simulation.hpp:33
int numParticles() const
Definition simulation.hpp:130
void setViscous(const DView &visc, const DView &bulkVisc)
Enable the viscous term (NavierStokes); per-particle viscosities (size N).
Definition simulation.hpp:53
const DView & force() const
Definition simulation.hpp:128
void init(const DView &posFlat, const DView &vel, const DView &invMass, const std::array< Real, 3 > &L, Real pressEq)
Definition simulation.hpp:39
Kokkos::View< Real *, peclet::core::MemSpace > DView
Definition simulation.hpp:35
void setRepair(bool on)
Definition simulation.hpp:138
bool repair() const
Definition simulation.hpp:139
Real internalEnergy() const
Definition simulation.hpp:115
Real time() const
Definition simulation.hpp:131
const DView & velocities() const
Definition simulation.hpp:127
Real kineticEnergy(const DView &mass) const
Definition simulation.hpp:101
void step(int nSteps, Real dt)
Definition simulation.hpp:66
const DView & positions() const
Definition simulation.hpp:126
const TessellationView< Real > & view() const
Definition simulation.hpp:129
Reference physics consumer: compressible-Euler pressure force (Phase 4).
void viscousForce(const TessellationView< Real > &view, const Kokkos::View< int *, peclet::core::MemSpace > &recip, const Kokkos::View< int *, peclet::core::MemSpace > &cellOfFacet, const Kokkos::View< Real *, peclet::core::MemSpace > &vel, const Kokkos::View< Real *, peclet::core::MemSpace > &visc, const Kokkos::View< Real *, peclet::core::MemSpace > &bulkVisc, const Kokkos::View< Real *, peclet::core::MemSpace > &force, const Kokkos::View< Real *, peclet::core::MemSpace > &grad, const Kokkos::View< Real *, peclet::core::MemSpace > &stress)
Definition viscous.hpp:119
void eulerPressureForce(const TessellationView< Real > &view, const Kokkos::View< int *, peclet::core::MemSpace > &recip, const Kokkos::View< int *, peclet::core::MemSpace > &cellOfFacet, Real pressEq, Real volAvg, const Kokkos::View< Real *, peclet::core::MemSpace > &force)
Definition euler_pressure.hpp:40
Definition convex_cell.hpp:40
AuxMaps< Real > buildAuxMaps(const TessellationView< Real > &view)
Build {recip, cellOfFacet} on device from a published view (dense single-domain).
Definition transpose.hpp:33
Definition transpose.hpp:26
Kokkos::View< Real *, Mem > vol
Definition repair.hpp:135
void rebuild(const Kokkos::View< Real *, Mem > &pos, bool eagerAdj=true)
Definition repair.hpp:198
RepairStats step(const Kokkos::View< Real *, Mem > &pos)
One moving-point update step. Updates store + vol in place from pos.
Definition repair.hpp:626
Store store
Definition repair.hpp:134
void alloc(int n, const Real Lbox[3], Real tol_, Real skin_, int sw_=4, int densityCount_=-1, int nProc_=-1)
Definition repair.hpp:153
Sentinel "no geometry" provider — the default; the clip stage is skipped.
Definition sdf.hpp:36
Definition tessellation_view.hpp:111
Definition tess_grid.hpp:82
Viscous Navier-Stokes force over the published view (de-legacy Phase 2).
Kokkos::View< real_t *, peclet::core::MemSpace > DView
Definition voro_bindings.cpp:68