peclet-amr 0.2.0
Block-local-Morton AMR octree + collocated cut-cell Navier–Stokes solver (header-only C++20, Kokkos + MPI)
Loading...
Searching...
No Matches
peclet::amr::AmrCutCell< Bits > Class Template Reference

#include <cut_cell.hpp>

Classes

struct  Assembled
 The assembled linear operator A as a per-cell diagonal + face CSR: (A u)_i = diag[i]·u_i + Σ_{k∈[start[i],start[i+1])} coef[k]·u[nbr[k]]. More...

Public Types

using Octree = BlockOctree<3, Bits>
using M = typename Octree::M
using Code = typename Octree::Code
using Coord = typename Octree::Coord
using ExtResolver = typename AmrPoisson<3, Bits>::ExtResolver

Public Member Functions

void init (const Octree &t, Real h0, Vec< 3 > origin=Vec< 3 >{})
void init (const Octree &t, const Vec< 3 > &h0, Vec< 3 > origin=Vec< 3 >{})
void setResolver (ExtResolver r)
void setGhosts (std::vector< std::array< long, 3 > > lo, std::vector< unsigned > lv)
 Ghost slots [n, n+nGhost): block-local lo (longs) + covering-leaf level.
Index numGhosts () const
void setFrameShift (const std::array< long, 3 > &s)
Index numLeaves () const
bool isFluid (Index i) const
bool isCut (Index i) const
 True for a cut cell: a fluid cell with at least one solid face neighbour (the row-scaled ξ-overlay band).
Index neighborOf (Index i, int k) const
 Periodic face neighbour of leaf i in direction k (0=+x,1=-x,2=+y,3=-y,4=+z,5=-z).
double kappa (Index i) const
double rhsScale (Index i) 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)
const std::vector< Index > & nbRaw () const
 n·6 periodic face-neighbour indices
const std::vector< char > & fluidRaw () const
const std::vector< char > & cutRaw () const
const std::vector< double > & acRaw () const
const std::vector< double > & offRaw () const
 n·6 ξ-overlay off-diagonals
const std::vector< double > & rscaleRaw () const
double idiag () const
double mu () const
Vec< 3 > beta () const
 buildCutStencil's β PER AXIS (= mu_/h0_a²) — Phase 3, docs/amr_anisotropic.md §3/§4.
bool hasAdv () const
const std::vector< double > & advDiagRaw () const
const std::vector< double > & advCoefRaw () const
const std::vector< Index > & advStartRaw () const
const std::vector< Index > & advNbrRaw () const
template<class SdfFn>
void build (SdfFn &&sdfFn, double idiag, double beta, int nsub=4)
 Build the cut-cell stencils from an SDF callable sdfFn(worldPoint) (>0 fluid, <0 solid).
template<class SdfFn>
void build (SdfFn &&sdfFn, double idiag=0.0, const Vec< 3 > &beta=detail::filledVec< 3 >(1.0), int nsub=4)
 Phase 3: beta[a] = mu/h0_a² (the octree twin of the structured fold's beta_b).
Assembled assembleOperator (bool scaleAdvByRscale=false) const
 scaleAdvByRscale (default false ⇒ reproduces applyOp/gaussSeidel exactly, for the matvec test): when true, the implicit-FOU advection is multiplied by the cut-cell D_rescale row scale, so the entire cut-cell row (base + advection) is scaled consistently.
FaceCsrOpT< HostArr< double >, HostArr< Index > > hostOp (const Assembled &A) const
 View a host Assembled as a backend-agnostic FaceCsrOpT for the shared row kernels.
void applyOp (const std::vector< double > &u, std::vector< double > &out) const
 out = A u, via the shared kernel over the assembled CSR (== device applyMom arithmetic).
double residual (const std::vector< double > &u, const std::vector< double > &b, std::vector< double > &res) const
void gaussSeidel (std::vector< double > &u, const std::vector< double > &b, int sweeps) const
 sweeps true serial Gauss–Seidel sweeps (ω=1, in place) over the assembled CSR using the shared point-update kernel — the host counterpart of the device multicolour GS, same per-cell formula.
void applyOpGeometric (const std::vector< double > &u, std::vector< double > &out) const
 Geometric operator apply (walks the octree live) — the INDEPENDENT reference encoding, kept as the test oracle for the assembled CSR (and hence the device kernels).
void buildAdvectionFou (const std::array< std::vector< double >, 3 > &uadv, double rho, const std::vector< double > &uf, const std::vector< Index > &faceStart, bool useFace)
 Build the implicit first-order-upwind advection operator from a (lagged) advecting velocity field uadv (3 components, cell-centred), scaled by rho.
std::vector< double > makeRhs (const std::vector< double > &src, double u_bc) const
 Effective RHS for source src (≈ -h^2 f at cell centres) and wall value u_bc: row-scaled by D_rescale and shifted by the inhomogeneous boundary term.
double residualGeometric (const std::vector< double > &u, const std::vector< double > &b, std::vector< double > &res) const
void gaussSeidelGeometric (std::vector< double > &u, const std::vector< double > &b, int sweeps) const
double fouApply (Index i, const std::vector< double > &field) const
 The implicit-FOU advection operator applied to field at leaf i: advDiag·field_i + Σ_csr coef·field_nbr (= ρ·∇·(u_adv field) FOU).
bool hasAdvection () const

Static Public Member Functions

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].

Static Public Attributes

static constexpr int Dim = 3
static constexpr int OPP [6] = {1, 0, 3, 2, 5, 4}

Detailed Description

template<unsigned Bits = 21u>
class peclet::amr::AmrCutCell< Bits >

Definition at line 77 of file cut_cell.hpp.

Member Typedef Documentation

◆ Octree

template<unsigned Bits = 21u>
using peclet::amr::AmrCutCell< Bits >::Octree = BlockOctree<3, Bits>

Definition at line 80 of file cut_cell.hpp.

◆ M

template<unsigned Bits = 21u>
using peclet::amr::AmrCutCell< Bits >::M = typename Octree::M

Definition at line 81 of file cut_cell.hpp.

◆ Code

template<unsigned Bits = 21u>
using peclet::amr::AmrCutCell< Bits >::Code = typename Octree::Code

Definition at line 82 of file cut_cell.hpp.

◆ Coord

template<unsigned Bits = 21u>
using peclet::amr::AmrCutCell< Bits >::Coord = typename Octree::Coord

Definition at line 83 of file cut_cell.hpp.

◆ ExtResolver

template<unsigned Bits = 21u>
using peclet::amr::AmrCutCell< Bits >::ExtResolver = typename AmrPoisson<3, Bits>::ExtResolver

Definition at line 107 of file cut_cell.hpp.

Member Function Documentation

◆ init() [1/2]

template<unsigned Bits = 21u>
void peclet::amr::AmrCutCell< Bits >::init ( const Octree & t,
Real h0,
Vec< 3 > origin = Vec<3>{} )
inline

Definition at line 88 of file cut_cell.hpp.

◆ init() [2/2]

template<unsigned Bits = 21u>
void peclet::amr::AmrCutCell< Bits >::init ( const Octree & t,
const Vec< 3 > & h0,
Vec< 3 > origin = Vec<3>{} )
inline

Definition at line 91 of file cut_cell.hpp.

◆ setResolver()

template<unsigned Bits = 21u>
void peclet::amr::AmrCutCell< Bits >::setResolver ( ExtResolver r)
inline

Definition at line 108 of file cut_cell.hpp.

◆ setGhosts()

template<unsigned Bits = 21u>
void peclet::amr::AmrCutCell< Bits >::setGhosts ( std::vector< std::array< long, 3 > > lo,
std::vector< unsigned > lv )
inline

Ghost slots [n, n+nGhost): block-local lo (longs) + covering-leaf level.

build() fills their sdfC/fluid metadata from the same world SdfFn (sampled at the ghost cell centre in the global frame — identical to the owner's sample).

Definition at line 112 of file cut_cell.hpp.

◆ numGhosts()

template<unsigned Bits = 21u>
Index peclet::amr::AmrCutCell< Bits >::numGhosts ( ) const
inline

Definition at line 116 of file cut_cell.hpp.

Referenced by build().

◆ setFrameShift()

template<unsigned Bits = 21u>
void peclet::amr::AmrCutCell< Bits >::setFrameShift ( const std::array< long, 3 > & s)
inline

Definition at line 117 of file cut_cell.hpp.

◆ numLeaves()

template<unsigned Bits = 21u>
Index peclet::amr::AmrCutCell< Bits >::numLeaves ( ) const
inline

◆ isFluid()

template<unsigned Bits = 21u>
bool peclet::amr::AmrCutCell< Bits >::isFluid ( Index i) const
inline

Definition at line 120 of file cut_cell.hpp.

◆ isCut()

template<unsigned Bits = 21u>
bool peclet::amr::AmrCutCell< Bits >::isCut ( Index i) const
inline

True for a cut cell: a fluid cell with at least one solid face neighbour (the row-scaled ξ-overlay band).

Its residual is D_rescale-scaled / inconsistent, so it is excluded from the velocity-MG coarse defect (the clean-fluid mask — see VelocityMG).

Definition at line 124 of file cut_cell.hpp.

◆ neighborOf()

template<unsigned Bits = 21u>
Index peclet::amr::AmrCutCell< Bits >::neighborOf ( Index i,
int k ) const
inline

Periodic face neighbour of leaf i in direction k (0=+x,1=-x,2=+y,3=-y,4=+z,5=-z).

Definition at line 126 of file cut_cell.hpp.

◆ kappa()

template<unsigned Bits = 21u>
double peclet::amr::AmrCutCell< Bits >::kappa ( Index i) const
inline

Definition at line 127 of file cut_cell.hpp.

◆ rhsScale()

template<unsigned Bits = 21u>
double peclet::amr::AmrCutCell< Bits >::rhsScale ( Index i) const
inline

Definition at line 128 of file cut_cell.hpp.

◆ lap()

template<unsigned Bits = 21u>
const AmrPoisson< 3, Bits > & peclet::amr::AmrCutCell< Bits >::lap ( ) const
inline

α=1 C/F ∇² geometry for regular cells

Definition at line 133 of file cut_cell.hpp.

Referenced by peclet::amr::assembleMomentum().

◆ sdfCRaw()

template<unsigned Bits = 21u>
const std::vector< double > & peclet::amr::AmrCutCell< Bits >::sdfCRaw ( ) const
inline

per-cell SDF sample (build Pass 1)

Definition at line 136 of file cut_cell.hpp.

Referenced by peclet::amr::assembleMomentum().

◆ nbRaw()

template<unsigned Bits = 21u>
const std::vector< Index > & peclet::amr::AmrCutCell< Bits >::nbRaw ( ) const
inline

n·6 periodic face-neighbour indices

Definition at line 139 of file cut_cell.hpp.

Referenced by peclet::amr::assembleMomentum().

◆ fluidRaw()

template<unsigned Bits = 21u>
const std::vector< char > & peclet::amr::AmrCutCell< Bits >::fluidRaw ( ) const
inline

Definition at line 140 of file cut_cell.hpp.

Referenced by peclet::amr::assembleMomentum().

◆ cutRaw()

template<unsigned Bits = 21u>
const std::vector< char > & peclet::amr::AmrCutCell< Bits >::cutRaw ( ) const
inline

Definition at line 141 of file cut_cell.hpp.

◆ acRaw()

template<unsigned Bits = 21u>
const std::vector< double > & peclet::amr::AmrCutCell< Bits >::acRaw ( ) const
inline

Definition at line 142 of file cut_cell.hpp.

◆ offRaw()

template<unsigned Bits = 21u>
const std::vector< double > & peclet::amr::AmrCutCell< Bits >::offRaw ( ) const
inline

n·6 ξ-overlay off-diagonals

Definition at line 143 of file cut_cell.hpp.

◆ rscaleRaw()

template<unsigned Bits = 21u>
const std::vector< double > & peclet::amr::AmrCutCell< Bits >::rscaleRaw ( ) const
inline

Definition at line 144 of file cut_cell.hpp.

◆ idiag()

template<unsigned Bits = 21u>
double peclet::amr::AmrCutCell< Bits >::idiag ( ) const
inline

Definition at line 145 of file cut_cell.hpp.

Referenced by peclet::amr::assembleMomentum(), build(), and build().

◆ mu()

template<unsigned Bits = 21u>
double peclet::amr::AmrCutCell< Bits >::mu ( ) const
inline

Definition at line 146 of file cut_cell.hpp.

Referenced by peclet::amr::assembleMomentum().

◆ beta()

template<unsigned Bits = 21u>
Vec< 3 > peclet::amr::AmrCutCell< Bits >::beta ( ) const
inline

buildCutStencil's β PER AXIS (= mu_/h0_a²) — Phase 3, docs/amr_anisotropic.md §3/§4.

Definition at line 148 of file cut_cell.hpp.

Referenced by peclet::amr::assembleMomentum(), build(), build(), and buildCutStencil().

◆ hasAdv()

template<unsigned Bits = 21u>
bool peclet::amr::AmrCutCell< Bits >::hasAdv ( ) const
inline

Definition at line 154 of file cut_cell.hpp.

Referenced by peclet::amr::assembleMomentum().

◆ advDiagRaw()

template<unsigned Bits = 21u>
const std::vector< double > & peclet::amr::AmrCutCell< Bits >::advDiagRaw ( ) const
inline

Definition at line 155 of file cut_cell.hpp.

Referenced by peclet::amr::assembleMomentum().

◆ advCoefRaw()

template<unsigned Bits = 21u>
const std::vector< double > & peclet::amr::AmrCutCell< Bits >::advCoefRaw ( ) const
inline

Definition at line 156 of file cut_cell.hpp.

Referenced by peclet::amr::assembleMomentum().

◆ advStartRaw()

template<unsigned Bits = 21u>
const std::vector< Index > & peclet::amr::AmrCutCell< Bits >::advStartRaw ( ) const
inline

Definition at line 157 of file cut_cell.hpp.

Referenced by peclet::amr::assembleMomentum().

◆ advNbrRaw()

template<unsigned Bits = 21u>
const std::vector< Index > & peclet::amr::AmrCutCell< Bits >::advNbrRaw ( ) const
inline

Definition at line 158 of file cut_cell.hpp.

Referenced by peclet::amr::assembleMomentum().

◆ build() [1/2]

template<unsigned Bits = 21u>
template<class SdfFn>
void peclet::amr::AmrCutCell< Bits >::build ( SdfFn && sdfFn,
double idiag,
double beta,
int nsub = 4 )
inline

Build the cut-cell stencils from an SDF callable sdfFn(worldPoint) (>0 fluid, <0 solid).

Operator A = idiag*I - beta*Laplacian (grid units, dx=1). nsub is the per-axis subsampling for the volume fraction κ.

Definition at line 164 of file cut_cell.hpp.

References beta(), build(), peclet::amr::detail::filledVec(), and idiag().

Referenced by build().

◆ build() [2/2]

template<unsigned Bits = 21u>
template<class SdfFn>
void peclet::amr::AmrCutCell< Bits >::build ( SdfFn && sdfFn,
double idiag = 0.0,
const Vec< 3 > & beta = detail::filledVec<3>(1.0),
int nsub = 4 )
inline

Phase 3: beta[a] = mu/h0_a² (the octree twin of the structured fold's beta_b).

Definition at line 169 of file cut_cell.hpp.

References beta(), buildCutStencil(), peclet::amr::detail::filledVec(), idiag(), numGhosts(), and numLeaves().

◆ assembleOperator()

template<unsigned Bits = 21u>
Assembled peclet::amr::AmrCutCell< Bits >::assembleOperator ( bool scaleAdvByRscale = false) const
inline

scaleAdvByRscale (default false ⇒ reproduces applyOp/gaussSeidel exactly, for the matvec test): when true, the implicit-FOU advection is multiplied by the cut-cell D_rescale row scale, so the entire cut-cell row (base + advection) is scaled consistently.

applyOp scales the base + RHS but not the advection — fine for the host serial GS (which gives a bounded approximation) but the inconsistency leaves a (1−rscale)/rscale·FOU amplification in the exact solution that blows up an accurate device solve at thin cut cells. With the advection scaled, the row is the unscaled equation × rscale and the implicit FOU cancels the (rscale-scaled) explicit deferred-correction FOU at steady state. The collocated device flow uses this; regular fluid cells (rscale=1) are unchanged.

Definition at line 310 of file cut_cell.hpp.

References peclet::amr::AmrCutCell< Bits >::Assembled::coef, peclet::amr::AmrCutCell< Bits >::Assembled::diag, peclet::amr::AmrCutCell< Bits >::Assembled::nbr, numLeaves(), and peclet::amr::AmrCutCell< Bits >::Assembled::start.

Referenced by applyOp(), gaussSeidel(), and residual().

◆ hostOp()

template<unsigned Bits = 21u>
FaceCsrOpT< HostArr< double >, HostArr< Index > > peclet::amr::AmrCutCell< Bits >::hostOp ( const Assembled & A) const
inline

◆ applyOp()

template<unsigned Bits = 21u>
void peclet::amr::AmrCutCell< Bits >::applyOp ( const std::vector< double > & u,
std::vector< double > & out ) const
inline

out = A u, via the shared kernel over the assembled CSR (== device applyMom arithmetic).

Definition at line 386 of file cut_cell.hpp.

References assembleOperator(), hostOp(), and numLeaves().

◆ residual()

template<unsigned Bits = 21u>
double peclet::amr::AmrCutCell< Bits >::residual ( const std::vector< double > & u,
const std::vector< double > & b,
std::vector< double > & res ) const
inline

Definition at line 396 of file cut_cell.hpp.

References assembleOperator(), hostOp(), and numLeaves().

◆ gaussSeidel()

template<unsigned Bits = 21u>
void peclet::amr::AmrCutCell< Bits >::gaussSeidel ( std::vector< double > & u,
const std::vector< double > & b,
int sweeps ) const
inline

sweeps true serial Gauss–Seidel sweeps (ω=1, in place) over the assembled CSR using the shared point-update kernel — the host counterpart of the device multicolour GS, same per-cell formula.

Definition at line 416 of file cut_cell.hpp.

References assembleOperator(), hostOp(), and numLeaves().

◆ applyOpGeometric()

template<unsigned Bits = 21u>
void peclet::amr::AmrCutCell< Bits >::applyOpGeometric ( const std::vector< double > & u,
std::vector< double > & out ) const
inline

Geometric operator apply (walks the octree live) — the INDEPENDENT reference encoding, kept as the test oracle for the assembled CSR (and hence the device kernels).

The runtime applyOp below routes through the shared face_csr.hpp kernels instead, so host and device run identical arithmetic; test_amr_cut_cell asserts the two agree. out = A u. A = idiag·I − μ∇² (C/F-aware) on regular fluid cells; the ξ-overlay stencil on cut cells (finest, same-level); identity on solid cells (held at u_bc).

Definition at line 436 of file cut_cell.hpp.

References numLeaves().

Referenced by residualGeometric().

◆ buildAdvectionFou()

template<unsigned Bits = 21u>
void peclet::amr::AmrCutCell< Bits >::buildAdvectionFou ( const std::array< std::vector< double >, 3 > & uadv,
double rho,
const std::vector< double > & uf,
const std::vector< Index > & faceStart,
bool useFace )
inline

Build the implicit first-order-upwind advection operator from a (lagged) advecting velocity field uadv (3 components, cell-centred), scaled by rho.

C/F-conservative: each face (incl. the 2^(Dim-1) fine sub-faces of a coarse cell, via forEachFaceFull) contributes (1/V)·A·velOut·ρ to the diagonal (outflow) or to a CSR off-diagonal toward the upstream neighbour (inflow); the advecting velocity at a wall (solid neighbour) face is zero (no flow through the immersed boundary). Rebuilt per step. Stable base of the deferred correction. uf/faceStart (+axis face velocity per forEachFaceFull (sub)face, when useFace) is the divergence-free advecting velocity; otherwise the cell average ½(uadv_i+uadv_j) is used (before the first projection has built uf). The implicit FOU and the explicit deferred correction must use the SAME velocity, hence it lives here too — not only in the high-order term.

Definition at line 476 of file cut_cell.hpp.

References numLeaves().

◆ makeRhs()

template<unsigned Bits = 21u>
std::vector< double > peclet::amr::AmrCutCell< Bits >::makeRhs ( const std::vector< double > & src,
double u_bc ) const
inline

Effective RHS for source src (≈ -h^2 f at cell centres) and wall value u_bc: row-scaled by D_rescale and shifted by the inhomogeneous boundary term.

Definition at line 532 of file cut_cell.hpp.

References numLeaves().

◆ residualGeometric()

template<unsigned Bits = 21u>
double peclet::amr::AmrCutCell< Bits >::residualGeometric ( const std::vector< double > & u,
const std::vector< double > & b,
std::vector< double > & res ) const
inline

Definition at line 547 of file cut_cell.hpp.

References applyOpGeometric(), and numLeaves().

◆ gaussSeidelGeometric()

template<unsigned Bits = 21u>
void peclet::amr::AmrCutCell< Bits >::gaussSeidelGeometric ( std::vector< double > & u,
const std::vector< double > & b,
int sweeps ) const
inline

Definition at line 561 of file cut_cell.hpp.

References numLeaves().

◆ fouApply()

template<unsigned Bits = 21u>
double peclet::amr::AmrCutCell< Bits >::fouApply ( Index i,
const std::vector< double > & field ) const
inline

The implicit-FOU advection operator applied to field at leaf i: advDiag·field_i + Σ_csr coef·field_nbr (= ρ·∇·(u_adv field) FOU).

Used by the flow solver for the explicit deferred-correction term (high-order − this).

Definition at line 608 of file cut_cell.hpp.

◆ hasAdvection()

template<unsigned Bits = 21u>
bool peclet::amr::AmrCutCell< Bits >::hasAdvection ( ) const
inline

Definition at line 612 of file cut_cell.hpp.

◆ buildCutStencil()

template<unsigned Bits = 21u>
void peclet::amr::AmrCutCell< Bits >::buildCutStencil ( double sdf_c,
const double sdf_n[6],
const double beta[3],
double AC0,
double & ACout,
double off[6],
double & rscaleOut,
double & inhomOut )
inlinestatic

Phase 3: beta[3] — the viscous coefficient of each AXIS; face k uses beta[k/2].

On a cubic octree all three are the same double and every expression below is the pre-Phase-3 one.

Definition at line 630 of file cut_cell.hpp.

References beta(), peclet::amr::cc::poly_abs(), peclet::amr::cc::poly_D(), peclet::amr::cc::poly_D_sandwich(), peclet::amr::cc::poly_N_c_sandwich(), peclet::amr::cc::poly_N_nb(), peclet::amr::cc::poly_Nbc(), peclet::amr::cc::poly_Nbc_mp_sw(), peclet::amr::cc::poly_Nbc_pp_sw(), and peclet::amr::cc::poly_Nc().

Referenced by build(), and peclet::amr::rebuildCutStencil().

Member Data Documentation

◆ Dim

template<unsigned Bits = 21u>
int peclet::amr::AmrCutCell< Bits >::Dim = 3
staticconstexpr

Definition at line 79 of file cut_cell.hpp.

◆ OPP

template<unsigned Bits = 21u>
int peclet::amr::AmrCutCell< Bits >::OPP[6] = {1, 0, 3, 2, 5, 4}
staticconstexpr

Definition at line 86 of file cut_cell.hpp.


The documentation for this class was generated from the following file: