tpt-sci-cfd-core
Core incompressible Navier–Stokes finite-volume solver for the
tpt-science pillar, built from scratch (pravash was audited and rejected:
GPL-3.0-only).
Features
CollocatedGrid— uniform 2-D collocated grid (nx × ny, physical sizelx × ly) with cell-centred velocity storage (idx,len).Step— fractional-step (Chorin) scheme: explicit advection–diffusion (momentum) plus a pressure-Poisson projection (project) that enforces∇·u = 0.advance()runs one full fractional step;max_divergence()is a quality metric.Boundarywalls withStep::set_boundaryfor moving-lid / no-slip conditions.Step::apply_wallscurrently enforcesTop/Bottom;Left/Rightvalues are accepted by the API but not yet applied.turbulence::eddy_viscosity— algebraic Smagorinsky eddy-viscosity estimate. ReturnsResult<f64, CfdError>.scalar::ScalarTransport— scalar transport on the collocated grid.SimpleSolver— SIMPLE/PISO-style implicit pressure-correction on the same structured grid. [SimpleSolver::predict] does an explicit momentum step, [SimpleSolver::solve_pressure] builds the pressure Poisson equation and solves it withtpt-sci-grid's sparse conjugate-gradient solver, and [SimpleSolver::correct] subtracts the pressure gradient to enforce∇·u = 0. [SimpleSolver::advance] runs a full step.KOmegaSst— full two-equationk-ωSST (Menter, 2003) closure:k/ωtransport with the SSTF1/F2blend,a1production limiter, and thek-ω/k-εcross-diffusion term. [KOmegaSst::eddy_viscosity_at] returns the blended eddy viscosity; [KOmegaSst::step] advances the model.UnstructuredMesh— additive unstructured finite-volume path: triangular cells in 2-D (tetrahedra extend analogously), with a gradient/reconstruction helper ([UnstructuredMesh::cell_gradient]) and a diffusion + upwind advection residual ([UnstructuredMesh::residual]). [UnstructuredMesh::solve_poisson] converges to the analytic solution on a triangulated unit square.
The structured explicit scheme and algebraic turbulence model remain the
teaching / coupling primitive; the three additions above close the v1
"out of scope" items. The solver is not a production CFD code. It is the
foundation tpt-sci-hemodynamics and tpt-sci-ocean build on.
Example
use ;
// 32×32 cavity, lid moving at u = 1.0 on the top wall.
let grid = new.unwrap;
let mut step = new;
step.set_boundary;
assert!;
The cavity example (cargo run --example cavity -p tpt-sci-cfd-core) drives a
lid-driven cavity to steady state.
Scope (v1)
2-D, uniform collocated grid. The following are now implemented (v1):
- Implicit pressure-correction —
SimpleSolver(SIMPLE/PISO-style) solves the pressure Poisson equation with the sparse conjugate-gradient solver and corrects the velocity to enforce continuity. - Two-equation
k-ωSST turbulence —KOmegaSst(Menter SST), running alongside the algebraicturbulence::eddy_viscosity. - Unstructured (triangular) finite-volume —
UnstructuredMeshwith gradient reconstruction and a diffusion + upwind-advection residual assembly, alongside the structuredCollocatedGrid.
Still out of scope for v1: 3-D tetrahedral assembly (the 2-D triangle code is
structured to extend analogously), moving Left/Right wall enforcement, and
parallel / production-grade solvers.
License
Licensed under either of MIT or Apache-2.0 at your option.