core
Shared MPI block decomposition + asynchronous ghost-layer exchange (header-only C++20)
Loading...
Searching...
No Matches
peclet::core::amr::AmrFlow< Bits > Class Template Reference

#include <flow.hpp>

Public Types

using Octree = BlockOctree< 3, Bits >
 

Public Member Functions

void init (const Octree &t, Real h0, Vec< 3 > origin=Vec< 3 >{})
 
void setDensity (double rho)
 
void setViscosity (double mu)
 
void setDt (double dt)
 
void setBodyForce (double fx, double fy, double fz)
 
void setPressurePCG (bool on)
 Use MG-preconditioned CG for the pressure solve (default) vs plain V-cycles.
 
void setAdvection (bool on)
 Enable momentum advection ∇·(u u) (default OFF ⇒ Stokes).
 
void setImplicitAdvection (bool on)
 Implicit-FOU deferred correction (default ON).
 
void setAdvectionScheme (int s)
 High-order advection scheme: 0 = second-order upwind (SOU, default), 1 = Koren TVD.
 
void setMomentumTol (double tol)
 Relative tolerance for the per-step momentum BiCGStab solve (default 1e-8).
 
void setMomentumMG (bool on)
 Use the Galerkin velocity multigrid (MomentumMG) as the momentum BiCGStab preconditioner.
 
void setVelocityMGStaircase (bool on)
 Choose the momentum-MG coarse-operator strategy: false (default) = Galerkin (MomentumMG, A_c = R·A·P of the exact cut-cell operator); true = rediscretized staircase (VelocityMG, mirroring flow's VelocityMG).
 
void setVelocityMGMinCoarse (Index m)
 Pore-scale cap for the staircase velocity-MG: the coarsest level keeps ≥ this many cells, so it still resolves the immersed feature (a small object that vanishes from the coarse κ classification leaves an inconsistent operator that diverges).
 
void setMomentumGS (bool on)
 Opt-in: use the multicolour Gauss–Seidel smoother in the momentum MG (Galerkin or staircase) instead of weighted Jacobi — ~2× better smoothing (fewer V-cycles / BiCGStab iters), and the strong fine smoother the staircase needs on the cut band.
 
void setMomentumMGSolver (bool on)
 Opt-in (P4): solve the momentum predictor with the velocity multigrid used as the solver — MG-preconditioned defect correction u ← u + M⁻¹(b − A u) iterated to tolerance — instead of BiCGStab with the same MG as a preconditioner.
 
void setOuterIterations (int n, double tol=1e-6)
 Optional Picard outer loop over the lagged advection (mirror of flow's outerIters_): each outer iteration re-freezes the advecting velocity at the latest u and re-solves the predictor, stopping early when the max |Δu| between successive outer iterates falls below tol.
 
template<class SdfFn >
void setSolid (SdfFn &&sdfFn)
 Build the cut-cell operators (host) + upload all device structures.
 
void step (int momIters=100, int presIters=60)
 One incompressible step on device (Stokes, or Navier–Stokes with setAdvection).
 
void project (int presIters=60)
 Pressure projection of the current velocity in place.
 
std::vector< doubledebugSou (int comp)
 DEBUG: the raw high-order advection ∇·(u u_comp) per cell from the current velocity (== host oracle::AmrFlow::advectTerm).
 
template<class MG >
void runMgVcycle (MG &mg, View< const double > r, View< double > z)
 Run one V-cycle of a momentum MG as a preconditioner: z = M⁻¹ r.
 
void copyToHost (const View< double > &d, std::vector< double > &h) const
 Copy a device View into a host vector (sized n_).
 
void setVelocity (int c, const std::vector< double > &h)
 Set a velocity component from host (testing / initial conditions).
 
std::vector< doublevelocity (int c) const
 Copy a velocity component back to host (single D2H, no host loop — S2a).
 
std::vector< doublepressure () const
 Copy the pressure field back to host (single D2H), (num_leaves,) — the incremental-rotational p.
 
std::vector< doublevelocities () const
 All three velocity components interleaved as a flat (n,3) row-major host buffer (out[i*3+c]) with a single device→host transfer (G6): the three independent component Views are packed on-device first (cheap), so the boundary is crossed once rather than three times as repeated velocity(c) calls would.
 
double divNormL2 ()
 L2 norm of the (openness-weighted) divergence of the current velocity.
 
double divNormFace ()
 L2 norm of the divergence of the ABC face field uf_ (built each project()): the φ-solve residual, far below the cell field's O(h²) divNormL2 — including across 2:1 interfaces.
 
std::vector< doublefaceField () const
 Copy the divergence-free face field to host (one value per CSR (sub)face, forEachFaceFull order).
 
Index numLeaves () const
 
bool isFluid (Index i) const
 Per-leaf fluid mask (false inside the solid) — for host-side post-processing / bindings.
 
int lastMomIters () const
 Total momentum BiCGStab iterations (summed over the 3 components) of the last step.
 
int lastPresIters () const
 Pressure PCG iterations of the last step.
 
int lastOuterIters () const
 Picard outer iterations actually run in the last step (1 unless setOuterIterations(>1)).
 

Static Public Member Functions

static double maxAbsDiff (View< const double > a, View< const double > b, Index n)
 Max |a − b| over all cells (the Picard outer-loop convergence measure).
 

Detailed Description

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

Definition at line 408 of file flow.hpp.

Member Typedef Documentation

◆ Octree

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

Definition at line 410 of file flow.hpp.

Member Function Documentation

◆ init()

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

Definition at line 412 of file flow.hpp.

◆ setDensity()

template<unsigned Bits = 21u>
void peclet::core::amr::AmrFlow< Bits >::setDensity ( double  rho)
inline

Definition at line 417 of file flow.hpp.

◆ setViscosity()

template<unsigned Bits = 21u>
void peclet::core::amr::AmrFlow< Bits >::setViscosity ( double  mu)
inline

Definition at line 418 of file flow.hpp.

◆ setDt()

template<unsigned Bits = 21u>
void peclet::core::amr::AmrFlow< Bits >::setDt ( double  dt)
inline

Definition at line 419 of file flow.hpp.

◆ setBodyForce()

template<unsigned Bits = 21u>
void peclet::core::amr::AmrFlow< Bits >::setBodyForce ( double  fx,
double  fy,
double  fz 
)
inline

Definition at line 420 of file flow.hpp.

◆ setPressurePCG()

template<unsigned Bits = 21u>
void peclet::core::amr::AmrFlow< Bits >::setPressurePCG ( bool  on)
inline

Use MG-preconditioned CG for the pressure solve (default) vs plain V-cycles.

Definition at line 422 of file flow.hpp.

◆ setAdvection()

template<unsigned Bits = 21u>
void peclet::core::amr::AmrFlow< Bits >::setAdvection ( bool  on)
inline

Enable momentum advection ∇·(u u) (default OFF ⇒ Stokes).

The high-order flux is second-order upwind (SOU) by default; the first-order-upwind part is solved implicitly (folded into the momentum operator) and the (SOU−FOU) difference is the explicit deferred correction — unconditionally stable for the FOU part, exact-SOU at steady state. This is the same implicit-FOU + deferred-SOU scheme as the host oracle::AmrFlow and flow's collocated grid (set_implicit_advection).

Definition at line 429 of file flow.hpp.

◆ setImplicitAdvection()

template<unsigned Bits = 21u>
void peclet::core::amr::AmrFlow< Bits >::setImplicitAdvection ( bool  on)
inline

Implicit-FOU deferred correction (default ON).

OFF ⇒ the whole high-order advection is explicit (no FOU in the operator) — only conditionally stable.

Definition at line 432 of file flow.hpp.

◆ setAdvectionScheme()

template<unsigned Bits = 21u>
void peclet::core::amr::AmrFlow< Bits >::setAdvectionScheme ( int  s)
inline

High-order advection scheme: 0 = second-order upwind (SOU, default), 1 = Koren TVD.

Definition at line 434 of file flow.hpp.

◆ setMomentumTol()

template<unsigned Bits = 21u>
void peclet::core::amr::AmrFlow< Bits >::setMomentumTol ( double  tol)
inline

Relative tolerance for the per-step momentum BiCGStab solve (default 1e-8).

The momentum predictor is one step of a pseudo-transient outer iteration to steady state, so it need not be solved to round-off — a looser tolerance bounds the per-step cost. NOTE on the cost regime: the momentum operator is the Helmholtz (ρ/dt)I − μ∇²; for a physical dt the (ρ/dt) mass term dominates and it is cheap (diagonally dominant). At the large dt used for steady drag, ρ/dt → 0 and it degrades to a bare elliptic Laplacian (a saddle-point Stokes problem) — as hard as the pressure Poisson and, unlike the pressure, solved here per velocity component. Bounding the tolerance (this knob) caps the over-solve; making it actually scale needs the velocity multigrid (setMomentumMG).

Definition at line 444 of file flow.hpp.

◆ setMomentumMG()

template<unsigned Bits = 21u>
void peclet::core::amr::AmrFlow< Bits >::setMomentumMG ( bool  on)
inline

Use the Galerkin velocity multigrid (MomentumMG) as the momentum BiCGStab preconditioner.

This is the scalable momentum solver: the coarse operators are the exact assembled cut-cell operator coarsened by R·A·P, so the V-cycle is a consistent preconditioner and the momentum iteration count stays ~flat with N instead of growing like the Jacobi-preconditioned BiCGStab (the dominant cost at scale and large dt). It only changes the preconditioner (the matvec is the exact operator) ⇒ identical converged step. Call before setSolid (the hierarchy is built there). Default ON.

Definition at line 452 of file flow.hpp.

◆ setVelocityMGStaircase()

template<unsigned Bits = 21u>
void peclet::core::amr::AmrFlow< Bits >::setVelocityMGStaircase ( bool  on)
inline

Choose the momentum-MG coarse-operator strategy: false (default) = Galerkin (MomentumMG, A_c = R·A·P of the exact cut-cell operator); true = rediscretized staircase (VelocityMG, mirroring flow's VelocityMG).

Call before setSolid. Both are device-resident BiCGStab preconditioners; this lets the two be benchmarked head-to-head.

Definition at line 458 of file flow.hpp.

◆ setVelocityMGMinCoarse()

template<unsigned Bits = 21u>
void peclet::core::amr::AmrFlow< Bits >::setVelocityMGMinCoarse ( Index  m)
inline

Pore-scale cap for the staircase velocity-MG: the coarsest level keeps ≥ this many cells, so it still resolves the immersed feature (a small object that vanishes from the coarse κ classification leaves an inconsistent operator that diverges).

Feature-dependent — raise it for small immersed objects. Only affects the staircase strategy.

Definition at line 463 of file flow.hpp.

◆ setMomentumGS()

template<unsigned Bits = 21u>
void peclet::core::amr::AmrFlow< Bits >::setMomentumGS ( bool  on)
inline

Opt-in: use the multicolour Gauss–Seidel smoother in the momentum MG (Galerkin or staircase) instead of weighted Jacobi — ~2× better smoothing (fewer V-cycles / BiCGStab iters), and the strong fine smoother the staircase needs on the cut band.

Default off. Call before setSolid.

Definition at line 467 of file flow.hpp.

◆ setMomentumMGSolver()

template<unsigned Bits = 21u>
void peclet::core::amr::AmrFlow< Bits >::setMomentumMGSolver ( bool  on)
inline

Opt-in (P4): solve the momentum predictor with the velocity multigrid used as the solver — MG-preconditioned defect correction u ← u + M⁻¹(b − A u) iterated to tolerance — instead of BiCGStab with the same MG as a preconditioner.

This is the faithful mirror of flow's velocity solve, which uses no Krylov method at all (RB-GS smoother / velocity-MG directly): the momentum operator is diagonally dominant and invertible, so the stationary iteration converges, and unlike BiCGStab it cannot break down on the strongly non-symmetric (D_rescale + FOU) operator (no bi-orthogonal recurrence to lose — the failure mode P5 had to symmetrise the smoother to avoid). With the GS smoother (setMomentumGS) and a velocity-MG (setMomentumMG, default on) this is the full RB-GS/MG flow path; with MG off it degrades to plain damped-Jacobi sweeps (flow's smoothComp). Default off (BiCGStab stays the validated default). Requires setMomentumMG to actually be multigrid-accelerated; otherwise the Richardson iteration converges only slowly.

Definition at line 481 of file flow.hpp.

◆ setOuterIterations()

template<unsigned Bits = 21u>
void peclet::core::amr::AmrFlow< Bits >::setOuterIterations ( int  n,
double  tol = 1e-6 
)
inline

Optional Picard outer loop over the lagged advection (mirror of flow's outerIters_): each outer iteration re-freezes the advecting velocity at the latest u and re-solves the predictor, stopping early when the max |Δu| between successive outer iterates falls below tol.

n = 1 (default) is the single lagged step used until now (no extra cost). Only meaningful with advection on; for Stokes the loop converges in one iteration. n ≥ 1.

Definition at line 488 of file flow.hpp.

◆ setSolid()

◆ step()

template<unsigned Bits = 21u>
void peclet::core::amr::AmrFlow< Bits >::step ( int  momIters = 100,
int  presIters = 60 
)
inline

One incompressible step on device (Stokes, or Navier–Stokes with setAdvection).

momIters BiCGStab iterations for each momentum component; presIters PCG iterations for the pressure solve.

Definition at line 611 of file flow.hpp.

References peclet::core::amr::advectExplicit(), peclet::core::amr::buildFou(), peclet::core::amr::deferredSou(), peclet::core::amr::grad3(), peclet::core::amr::MomentumOp::hasAdv, peclet::core::amr::AmrFlow< Bits >::maxAbsDiff(), peclet::core::amr::momRhs(), and peclet::core::amr::AmrFlow< Bits >::project().

◆ project()

template<unsigned Bits = 21u>
void peclet::core::amr::AmrFlow< Bits >::project ( int  presIters = 60)
inline

◆ debugSou()

template<unsigned Bits = 21u>
std::vector< double > peclet::core::amr::AmrFlow< Bits >::debugSou ( int  comp)
inline

DEBUG: the raw high-order advection ∇·(u u_comp) per cell from the current velocity (== host oracle::AmrFlow::advectTerm).

Isolates the SOU kernel from the solve.

Definition at line 732 of file flow.hpp.

References peclet::core::amr::advectExplicit().

◆ runMgVcycle()

template<unsigned Bits = 21u>
template<class MG >
void peclet::core::amr::AmrFlow< Bits >::runMgVcycle ( MG &  mg,
View< const double r,
View< double z 
)
inline

Run one V-cycle of a momentum MG as a preconditioner: z = M⁻¹ r.

Templated on the MG type (MomentumMG or VelocityMG — both expose b(0)/x(0)/vcycle), so the BiCGStab preconditioner is decoupled from the coarse-operator strategy.

Definition at line 748 of file flow.hpp.

Referenced by peclet::core::amr::AmrFlow< Bits >::setSolid().

◆ maxAbsDiff()

template<unsigned Bits = 21u>
static double peclet::core::amr::AmrFlow< Bits >::maxAbsDiff ( View< const double a,
View< const double b,
Index  n 
)
inlinestatic

Max |a − b| over all cells (the Picard outer-loop convergence measure).

Definition at line 755 of file flow.hpp.

Referenced by peclet::core::amr::AmrFlow< Bits >::step().

◆ copyToHost()

template<unsigned Bits = 21u>
void peclet::core::amr::AmrFlow< Bits >::copyToHost ( const View< double > &  d,
std::vector< double > &  h 
) const
inline

Copy a device View into a host vector (sized n_).

Definition at line 770 of file flow.hpp.

◆ setVelocity()

template<unsigned Bits = 21u>
void peclet::core::amr::AmrFlow< Bits >::setVelocity ( int  c,
const std::vector< double > &  h 
)
inline

Set a velocity component from host (testing / initial conditions).

Definition at line 777 of file flow.hpp.

◆ velocity()

template<unsigned Bits = 21u>
std::vector< double > peclet::core::amr::AmrFlow< Bits >::velocity ( int  c) const
inline

Copy a velocity component back to host (single D2H, no host loop — S2a).

Definition at line 784 of file flow.hpp.

References peclet::core::toVector().

◆ pressure()

template<unsigned Bits = 21u>
std::vector< double > peclet::core::amr::AmrFlow< Bits >::pressure ( ) const
inline

Copy the pressure field back to host (single D2H), (num_leaves,) — the incremental-rotational p.

Definition at line 787 of file flow.hpp.

References peclet::core::toVector().

◆ velocities()

template<unsigned Bits = 21u>
std::vector< double > peclet::core::amr::AmrFlow< Bits >::velocities ( ) const
inline

All three velocity components interleaved as a flat (n,3) row-major host buffer (out[i*3+c]) with a single device→host transfer (G6): the three independent component Views are packed on-device first (cheap), so the boundary is crossed once rather than three times as repeated velocity(c) calls would.

Definition at line 793 of file flow.hpp.

References peclet::core::toVector().

◆ divNormL2()

template<unsigned Bits = 21u>
double peclet::core::amr::AmrFlow< Bits >::divNormL2 ( )
inline

L2 norm of the (openness-weighted) divergence of the current velocity.

Definition at line 806 of file flow.hpp.

References peclet::core::amr::divergence(), and peclet::core::amr::dotPlain().

◆ divNormFace()

template<unsigned Bits = 21u>
double peclet::core::amr::AmrFlow< Bits >::divNormFace ( )
inline

L2 norm of the divergence of the ABC face field uf_ (built each project()): the φ-solve residual, far below the cell field's O(h²) divNormL2 — including across 2:1 interfaces.

Definition at line 813 of file flow.hpp.

References peclet::core::amr::divFaceNorm().

◆ faceField()

template<unsigned Bits = 21u>
std::vector< double > peclet::core::amr::AmrFlow< Bits >::faceField ( ) const
inline

Copy the divergence-free face field to host (one value per CSR (sub)face, forEachFaceFull order).

Definition at line 816 of file flow.hpp.

References peclet::core::toVector().

◆ numLeaves()

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

Definition at line 817 of file flow.hpp.

◆ isFluid()

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

Per-leaf fluid mask (false inside the solid) — for host-side post-processing / bindings.

Definition at line 819 of file flow.hpp.

◆ lastMomIters()

template<unsigned Bits = 21u>
int peclet::core::amr::AmrFlow< Bits >::lastMomIters ( ) const
inline

Total momentum BiCGStab iterations (summed over the 3 components) of the last step.

Definition at line 821 of file flow.hpp.

◆ lastPresIters()

template<unsigned Bits = 21u>
int peclet::core::amr::AmrFlow< Bits >::lastPresIters ( ) const
inline

Pressure PCG iterations of the last step.

Definition at line 823 of file flow.hpp.

◆ lastOuterIters()

template<unsigned Bits = 21u>
int peclet::core::amr::AmrFlow< Bits >::lastOuterIters ( ) const
inline

Picard outer iterations actually run in the last step (1 unless setOuterIterations(>1)).

Definition at line 825 of file flow.hpp.


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