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"
35template <
class Real,
class Sdf = peclet::voro::NoSdf>
38 using DView = Kokkos::View<Real*, peclet::core::MemSpace>;
40 void setSdf(
const Sdf& s) { sdf_ = s; }
45 const std::array<Real, 3>& L, Real pressEq) {
46 N_ =
static_cast<int>(invMass.extent(0));
53 force_ =
DView(
"force", 3 * N_);
64 viscGrad_ =
DView(Kokkos::view_alloc(
"visc.grad", Kokkos::WithoutInitializing),
65 static_cast<std::size_t
>(9) * N_);
66 viscStress_ =
DView(Kokkos::view_alloc(
"visc.stress", Kokkos::WithoutInitializing),
67 static_cast<std::size_t
>(9) * N_);
71 void step(
int nSteps, Real dt) {
72 using Exec = peclet::core::ExecSpace;
73 const Real halfDt = Real(0.5) * dt;
74 const Real Lx = L_[0], Ly = L_[1], Lz = L_[2];
79 for (
int s = 0; s < nSteps; ++s) {
81 "ee.kick1", Kokkos::RangePolicy<Exec>(0, N_), KOKKOS_LAMBDA(
const int i) {
82 for (
int k = 0; k < 3; ++k)
83 vel(3 * i + k) +=
force(3 * i + k) * im(i) * halfDt;
86 "ee.drift", Kokkos::RangePolicy<Exec>(0, N_), KOKKOS_LAMBDA(
const int i) {
87 Real x = pos(3 * i + 0) + vel(3 * i + 0) * dt;
88 Real y = pos(3 * i + 1) + vel(3 * i + 1) * dt;
89 Real z = pos(3 * i + 2) + vel(3 * i + 2) * dt;
90 pos(3 * i + 0) = x - Lx * Kokkos::floor(x / Lx);
91 pos(3 * i + 1) = y - Ly * Kokkos::floor(y / Ly);
92 pos(3 * i + 2) = z - Lz * Kokkos::floor(z / Lz);
97 "ee.kick2", Kokkos::RangePolicy<Exec>(0, N_), KOKKOS_LAMBDA(
const int i) {
98 for (
int k = 0; k < 3; ++k)
99 vel(3 * i + k) +=
force(3 * i + k) * im(i) * halfDt;
107 using Exec = peclet::core::ExecSpace;
110 Kokkos::parallel_reduce(
111 "ee.ke", Kokkos::RangePolicy<Exec>(0, N_),
112 KOKKOS_LAMBDA(
const int i, Real& acc) {
113 acc += mass(i) * (vel(3 * i + 0) * vel(3 * i + 0) + vel(3 * i + 1) * vel(3 * i + 1) +
114 vel(3 * i + 2) * vel(3 * i + 2));
117 return Real(0.5) * e;
121 using Exec = peclet::core::ExecSpace;
122 auto vol = view_.cellVolume;
123 const Real pe = pressEq_, va = volAvg_;
125 Kokkos::parallel_reduce(
126 "ee.ie", Kokkos::RangePolicy<Exec>(0, N_),
127 KOKKOS_LAMBDA(
const int i, Real& acc) { acc -= pe * va * Kokkos::log(vol(i) / va); }, e);
136 Real
time()
const {
return time_; }
144 bool repair()
const {
return useRepair_; }
149 void buildAndForce() {
150 const Real Larr[3] = {L_[0], L_[1], L_[2]};
157 const double boxVol =
static_cast<double>(L_[0]) * L_[1] * L_[2];
158 const Real spacing =
static_cast<Real
>(std::cbrt(boxVol / (N_ > 0 ? N_ : 1)));
160 mt_.profile = profile_;
168 view_ = peclet::voro::reevalPublish<Real, kMaxPlanes, kMaxTriangles>(
169 mt_.store, pos_, mt_.vol, N_, Larr, mt_.wall, mt_.xRef);
175 auto res = peclet::voro::buildTessellation<Real, false, Sdf>(
177 true, -1, {}, {}, {},
178 {}, {}, {}, 0, &wlCache_,
180 0, Real(0),
false,
false,
185 volAvg_ = (L_[0] * L_[1] * L_[2]) /
static_cast<Real
>(N_);
186 Kokkos::deep_copy(force_, Real(0));
189 viscousForce(view_, aux_.recip, aux_.cellOfFacet, vel_, visc_, bulkVisc_, force_, viscGrad_,
194 std::array<Real, 3> L_{};
195 Real pressEq_ = 0, volAvg_ = 0, time_ = 0;
196 bool viscous_ =
false;
197 DView pos_, vel_, invMass_, w_, force_, visc_, bulkVisc_;
198 DView viscGrad_, viscStress_;
201 TessellationView<Real> view_;
205 bool useRepair_ =
false, mtInit_ =
false, profile_ =
false;
Definition simulation.hpp:36
void setSdf(const Sdf &s)
Definition simulation.hpp:40
const TessellationView< Real > & view() const
Definition simulation.hpp:134
Real kineticEnergy(const DView &mass) const
Definition simulation.hpp:106
int numParticles() const
Definition simulation.hpp:135
const DView & velocities() const
Definition simulation.hpp:132
const DView & force() const
Definition simulation.hpp:133
Kokkos::View< Real *, peclet::core::MemSpace > DView
Definition simulation.hpp:38
Real internalEnergy() const
Definition simulation.hpp:120
void setViscous(const DView &visc, const DView &bulkVisc)
Enable the viscous term (NavierStokes); per-particle viscosities (size N).
Definition simulation.hpp:58
Real time() const
Definition simulation.hpp:136
void init(const DView &posFlat, const DView &vel, const DView &invMass, const std::array< Real, 3 > &L, Real pressEq)
Definition simulation.hpp:44
bool repair() const
Definition simulation.hpp:144
void setProfile(bool on)
The cold build's timing / over-buffer report on stderr (buildTessellation's profile).
Definition simulation.hpp:146
void step(int nSteps, Real dt)
Definition simulation.hpp:71
const DView & positions() const
Definition simulation.hpp:131
void setRepair(bool on)
Definition simulation.hpp:143
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
Device-native Voronoi tessellation, geometry and finite-volume physics.
Definition convex_cell.hpp:41
AuxMaps< Real > buildAuxMaps(const TessellationView< Real > &view)
Build {recip, cellOfFacet} on device from a published view (dense single-domain).
Definition transpose.hpp:33
constexpr double kSkin
Definition params.hpp:33
constexpr double kCertificateTolerance
Definition params.hpp:32
constexpr int kSearchWindow
Definition params.hpp:28
Definition transpose.hpp:26
Definition tessellation_view.hpp:111
Definition tess_grid.hpp:83
Viscous Navier-Stokes force over the published view (de-legacy Phase 2).
Kokkos::View< real_t *, peclet::core::MemSpace > DView
Definition voro_bindings_common.hpp:39