25#ifndef PECLET_AMR_MOMENTUM_ASSEMBLY_HPP
26#define PECLET_AMR_MOMENTUM_ASSEMBLY_HPP
34#include "peclet/core/common/view.hpp"
45 KOKKOS_INLINE_FUNCTION
void operator()(Index j,
double c)
const { (*sink)(j,
factor* c); }
57template <
unsigned Bits = 21u>
68 KOKKOS_INLINE_FUNCTION
double cellVolume(Index i)
const {
return geom.cellVolume(i); }
73 KOKKOS_INLINE_FUNCTION
void operator()(Index i, Sink& sink)
const {
76 const std::size_t s =
static_cast<std::size_t
>(i);
78 for (
int k = 0; k < 6; ++k) {
79 const double a =
off(s * 6 + k);
82 const Index j =
nbr6(s * 6 + k);
87 const double invV = 1.0 /
geom.cellVolume(i);
100 KOKKOS_INLINE_FUNCTION
double diag(Index i)
const {
107 const double invV = 1.0 /
geom.cellVolume(i);
124template <
unsigned Bits>
126 const View<Index>& nbr6,
const View<char>& fluid,
127 const View<std::uint8_t>& levels, View<double> AC, View<double> off,
128 View<char> cut, View<double> rscale) {
132 const double b0 = betaIn[0], b1 = betaIn[1], b2 = betaIn[2], id0 = idiag;
133 Kokkos::parallel_for(
134 "amr::cut_stencil", n, KOKKOS_LAMBDA(
const Index i) {
135 const double f =
static_cast<double>(Index(1) << levels(i));
136 const double inv = 1.0 / (f * f);
137 const double beta[3] = {b0 * inv, b1 * inv, b2 * inv};
138 const double AC0 = id0 + ((2.0 * beta[0] + 2.0 * beta[1]) + 2.0 * beta[2]);
139 const std::size_t s =
static_cast<std::size_t
>(i);
142 for (
int k = 0; k < 6; ++k)
143 off(s * 6 + k) = 0.0;
149 bool anyGhost =
false;
150 for (
int k = 0; k < 6; ++k) {
151 const Index j = nbr6(s * 6 + k);
152 sdf_n[k] = (j >= 0) ? sdfC(j) : -1.0;
156 cut(i) = anyGhost ? 1 : 0;
157 double AClocal = AC0, offl[6];
158 for (
int k = 0; k < 6; ++k)
159 offl[k] = -beta[k / 2];
160 double rsl = 1.0, inhoml = 0.0;
164 for (
int k = 0; k < 6; ++k)
165 off(s * 6 + k) = offl[k];
175template <
unsigned Bits>
177 bool scaleAdvByRscale =
false) {
180 const Vec<3> betaV = ccop.
beta();
181 const double beta[3] = {betaV[0], betaV[1], betaV[2]};
184 View<double> sdfC = toDevice(ccop.
sdfCRaw(),
"mom::sdfC");
185 View<Index> nbr6 = toDevice(ccop.
nbRaw(),
"mom::nb");
186 View<char> fluid = toDevice(ccop.
fluidRaw(),
"mom::fluid");
187 View<double> AC(Kokkos::view_alloc(
"mom::AC", Kokkos::WithoutInitializing),
188 static_cast<std::size_t
>(n));
189 View<double> off(Kokkos::view_alloc(
"mom::off", Kokkos::WithoutInitializing),
190 static_cast<std::size_t
>(n) * 6);
191 View<char> cut(Kokkos::view_alloc(
"mom::cut", Kokkos::WithoutInitializing),
192 static_cast<std::size_t
>(n));
193 View<double> rscale(Kokkos::view_alloc(
"mom::rscale", Kokkos::WithoutInitializing),
194 static_cast<std::size_t
>(n));
195 rebuildCutStencil<Bits>(n, beta, ccop.
idiag(), sdfC, nbr6, fluid, ov.
levels, AC, off, cut,
201 for (
int d = 0; d < 3; ++d)
202 geom.
h0[d] = ccop.
lap().
h0()[d];
205 for (
int d = 0; d < 3; ++d)
231 op.faceStart = csr.
start;
232 op.faceNbr = csr.
nbr;
233 op.faceCoef = csr.
coef;
235 op.diag = View<double>(Kokkos::view_alloc(
"mom::diag", Kokkos::WithoutInitializing),
236 static_cast<std::size_t
>(n));
237 View<double> diagV = op.diag;
239 Kokkos::parallel_for(
"amr::mom_diag", n, KOKKOS_LAMBDA(
const Index i) { diagV(i) = e.
diag(i); });
const std::vector< double > & advCoefRaw() const
const std::vector< double > & advDiagRaw() const
const std::vector< char > & fluidRaw() const
const std::vector< Index > & nbRaw() const
n·6 periodic face-neighbour indices
const std::vector< Index > & advNbrRaw() const
const AmrPoisson< 3, Bits > & lap() const
α=1 C/F ∇² geometry for regular cells
const std::vector< double > & sdfCRaw() const
per-cell SDF sample (build Pass 1)
static void buildCutStencil(double sdf_c, const double sdf_n[6], const double beta[3], double AC0, double &ACout, double off[6], double &rscaleOut, double &inhomOut)
Phase 3: beta[3] — the viscous coefficient of each AXIS; face k uses beta[k/2].
const std::vector< Index > & advStartRaw() const
Vec< 3 > beta() const
buildCutStencil's β PER AXIS (= mu_/h0_a²) — Phase 3, docs/amr_anisotropic.md §3/§4.
const std::array< Coord, Dim > & fineExt() const
Per-axis fine-grid extent (brick·2^lmax) — the periodic wrap modulus.
const Vec< Dim > & h0() const
void rebuildCutStencil(Index n, const double betaIn[3], double idiag, const View< double > &sdfC, const View< Index > &nbr6, const View< char > &fluid, const View< std::uint8_t > &levels, View< double > AC, View< double > off, View< char > cut, View< double > rscale)
The per-cell ξ-overlay rebuild (build() Pass 2) on device: from the staged cell SDF + neighbour indic...
Csr buildFaceCsr(Index n, const Emit &emit)
Build a face-CSR on device from a per-cell emit functor.
MomentumOp assembleMomentum(const AmrCutCell< Bits > &ccop, const BlockOctreeView< 3, Bits > &ov, bool scaleAdvByRscale=false)
Assemble the MomentumOp entirely on the device from a built host AmrCutCell + a device octree view.
Device mirror of a BlockOctree's leaf arrays + device-callable queries.
View< std::uint8_t > levels
An assembled face-CSR: row offsets (size n+1), neighbour index + coefficient per face (size nFaces).
View< Index > nbr
neighbour leaf per face, size nFaces
View< double > coef
coefficient per face, size nFaces
View< Index > start
CSR row offsets, size n+1; start(n) == nFaces.
Device-callable reproduction of AmrPoisson's per-cell face walk + geometry.
Coord fineExt[Dim]
periodic-wrap modulus per axis
View_t ov
device octree (codes/levels/locate)
Real h0[Dim]
finest cell width PER AXIS (Phase 3); set by the emitters
Device-callable reproduction of AmrCutCell::assembleOperator's per-cell row + diagonal.
void operator()(Index i, Sink &sink) const
Emit the off-diagonal entries of row i (S1 fill order): ξ-overlay for cut cells, −μ·invV·(a·c) for re...
View< const Index > advNbr
View< const Index > nbr6
n·6 periodic face-neighbour indices (cut-stencil order)
View< const Index > advStart
double diag(Index i) const
Diagonal of row i: 1 (solid), AC (cut), or idiag + μ·invV·Σ(a·c) (regular), plus folded advection.
View< const double > advCoef
FvFaceEmit< 3, Bits > geom
α=1 (hasOpen=false) C/F-aware ∇² traversal for regular fluid cells
double cellVolume(Index i) const
View< const double > advDiag
View< const double > rscale
off is n·6 (ξ-overlay), AC/rscale are n
Sink adapter: forwards each face from the FvFaceEmit traversal as (j, factor·coef) to the real CSR si...
void operator()(Index j, double c) const
Sink that just sums the geometric coeffs of a cell's faces (Σ a·c for the regular diagonal).
void operator()(Index, double c)