|
core
Shared MPI block decomposition + asynchronous ghost-layer exchange (header-only C++20)
|
#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< double > | debugSou (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< double > | velocity (int c) const |
| Copy a velocity component back to host (single D2H, no host loop — S2a). | |
| std::vector< double > | pressure () const |
| Copy the pressure field back to host (single D2H), (num_leaves,) — the incremental-rotational p. | |
| std::vector< double > | velocities () 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< double > | faceField () 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). | |
| using peclet::core::amr::AmrFlow< Bits >::Octree = BlockOctree<3, Bits> |
|
inline |
|
inline |
|
inline |
|
inline |
|
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).
|
inline |
|
inline |
|
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).
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
inline |
Build the cut-cell operators (host) + upload all device structures.
Requires the density / viscosity / dt to be set first (the momentum operator carries ρ/dt and μ).
Definition at line 496 of file flow.hpp.
References peclet::core::amr::MomentumOp::advCoef, peclet::core::amr::MomentumOp::advDiag, peclet::core::amr::MomentumOp::advNbr, peclet::core::amr::MomentumOp::advStart, peclet::core::amr::AmrPoisson< Dim, Bits >::buildOpenness(), peclet::core::amr::FaceGeom::fluid, peclet::core::amr::MomentumOp::hasAdv, peclet::core::amr::AmrPoisson< Dim, Bits >::init(), peclet::core::amr::FaceGeom::nbr, peclet::core::amr::AmrFlow< Bits >::runMgVcycle(), peclet::core::amr::AmrPoisson< Dim, Bits >::setOrigin(), peclet::core::amr::FaceGeom::start, peclet::core::toDevice(), and peclet::core::amr::BlockOctreeView< Dim, Bits >::upload().
|
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().
|
inline |
Pressure projection of the current velocity in place.
Definition at line 697 of file flow.hpp.
References peclet::core::amr::buildFaceField(), peclet::core::amr::correct(), peclet::core::amr::divergence(), peclet::core::amr::grad3(), and peclet::core::amr::presUpdate().
Referenced by peclet::core::amr::AmrFlow< Bits >::step().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |