Expand description
The core library of CFD-craft: a bounded, inspectable CPU research solver for incompressible flow on uniform Cartesian grids and conservative dispersion of passive gases and particle size classes, built to be driven and checked by programs and agents.
A case is data: one strict JSON document (case::Case) declares the
domain, grid, boundaries, flow model, solid boxes and polygon prisms,
vegetation, constituents, sources, receptors, numerics and every budget. A run reports why it stopped, what
its recomputed numerical checks support, the model scope, and the identity
of its input, initial state and build.
§Status
Version 0.2.0 is a research prototype. The coarse finite-canyon
examples converge under independent continuity and mass checks.
Experimental canyon validation (blocked by access to raw benchmark data)
and a successful fine-grid resolution study remain open; the first
finer-grid study exceeded its compute budgets. These are
physical-qualification gates: a numerically accepted run is not
experimentally validated urban CFD, and every result says so in
Summary::experimental_validation.
The 0.2.0 scope is uniform grids, buildings as boxes and polygon prisms, passive gases, particle size classes with settling and deposition, porous vegetation, and CPU execution. These features are numerically verified and not experimentally validated. LES, chemistry, annual statistics, stretched grids and GPU execution are not implemented. See the roadmap, the recorded results and the model cards.
§What is implemented
- Staggered finite volumes with face velocities, masks of boxes and
polygon prisms rasterized by cell centers, and fluid-component discovery
(
grid,geometry). - Matrix-free pressure projection with one gauge per closed fluid
component, IC(0)-preconditioned PCG by default and opt-in symmetric
multigrid, also on grids with buildings (
pressure,multigrid). - Laminar flow, moving walls and one neutral k-epsilon package with
rough-wall functions (
flow); donor-cell or opt-in conservative second-order momentum advection; SSPRK2 pseudo-time or opt-in implicit steady algorithms (momentum_solve,turbulence_solve). - Passive gases and particle size classes (Stokes settling with Cunningham
correction, ground, roof and leaf deposition) with point, line and volume
sources and point, volume-average or path receptors, by first-order
upwind or bounded MUSCL transport (
transport). - Porous vegetation with leaf drag and canopy turbulence terms
(
vegetation). - Source responses on one accepted, frozen flow: one transport run per
source group without a flow update (
mobile_response). - Explicit step, time, memory and output budgets, cooperative
cancellation, transactional steps, checksummed restarts and run archives
(
solver,output), and opt-in phase profiling (profiling).
§Entry points
| Task | API |
|---|---|
| Parse a case strictly, with JSON paths in errors | input::parse_case |
| Check a case (coded diagnostics, estimates) | Case::check, Case::validate, input::full_check |
| Run a case within limits | solver::run with a Control |
| Read the outcome | RunResult: Summary, State |
| Save and resume | output::checkpoint_bytes, output::read_checkpoint |
| Publish or verify a run archive | output::create_run_dir, output::write_run, output::read_verified |
| Measure solver phases | Control::with_profiling, profiling::Profile |
For ordinary applications prefer these to the low-level modules. Grid, face and state vectors can be used directly, but they carry invariants (layout, gauges, fixed boundary faces) that the module docs state.
§Quickstart
A point source in a uniform 1 m/s flow, solved to a steady state on a 32-cell grid:
use cfd_craft::{input, solver::{self, Control}};
let json = r#"{
"schema_version": "cfd-craft.case/0.1", "name": "quickstart",
"domain": {"size_m": [4.0, 1.0, 1.0]}, "grid": {"cells": [8, 2, 2]},
"boundaries": {"x": "open", "y": "periodic", "z": "periodic"},
"flow": {"kind": "prescribed_uniform", "velocity_m_s": [1.0, 0.0, 0.0]},
"constituents": [{"id": "tracer", "diffusivity_m2_s": 0.01}],
"sources": [{"kind": "point", "id": "S0", "constituent": "tracer",
"point_m": [0.5, 0.5, 0.5], "rate_kg_s": 1e-6}],
"receptors": [{"kind": "point", "id": "R1", "point_m": [3.0, 0.5, 0.5]}],
"numerics": {"transport": "linear_upwind", "max_time_step_s": 1.0,
"advective_cfl_max": 0.4, "pressure_relative_tolerance": 1e-10,
"pressure_max_iterations": 100, "steady_residual_tolerance": 1e-5,
"steady_monitor_tolerance": 1e-3, "monitor_window": 10},
"run": {"mode": "steady", "end_time_s": 1.0, "max_steps": 2000,
"wall_time_limit_s": 30.0, "threads": 1, "memory_limit_mib": 64},
"output": {"fields": false, "checkpoint": false, "max_total_mib": 4}
}"#;
// Strict parsing: an unknown field fails as CFD-E000 with its JSON path.
let case = input::parse_case(json.as_bytes())
.map_err(|report| serde_json::to_string(&report).unwrap())?;
// Semantic checks: ranges, units, budgets and geometry.
case.validate()?;
let control = Control::new(case.run.wall_time_limit_s);
let result = solver::run(&case, &control, None)?;
let summary = &result.summary;
// Ok(..) can still be cancelled or incomplete: read both verdicts.
assert_eq!(summary.termination, "completed");
assert_eq!(summary.assessment, "steady_discrete_solution");
assert!(summary.checks.iter().all(|check| check.passed));
// Look receptors up by ID. Downstream, the plume has mixed over the
// 1 m2 cross-section, so the concentration approaches rate / (U A).
let tracer = summary.constituents.iter().find(|c| c.id == "tracer").unwrap();
let r1 = tracer.receptors_kg_m3["R1"];
assert!((r1 - 1e-6).abs() < 1e-8);
println!("R1 = {:.3} micrograms/m3 after {} steps", r1 * 1e9, summary.steps);The library does not create a Rayon thread pool from run.threads; run
solver::run inside pool.install when thread accounting matters. The
CLI and the Python binding do this, and also own signal handling, host
memory preflight and archive provenance.
§Conventions
- SI units, named in the field suffixes (
_m,_m_s,_kg_s,_kg_m3). Concentrations are kg/m3; multiply by 1e9 for micrograms/m3. Pressure is kinematic, m2/s2. - Coordinates are local east (x), north (y) and up (z). Wind directions are meteorological: where the wind blows from, clockwise from north.
- Cells are ordered x fastest, index
(k * ny + j) * nx + i; face arrays are concatenated by axis (seegrid::Grid). - Errors are
Resultwith aStringmessage that starts with a stable code such asCFD-E033, listed in the diagnostics catalog. Match the code, not the English text.
§Related crates and documents
cfd-craft-cli: thecfd-craftcommand (describe,check,run,profile,preview,report,verify) with checksummed archives, restarts and signals.cfd-crafton PyPI: the Python binding (check,simulate,describe), see the Python chapter.- The guide explains the numerical and evidence concepts in worked chapters, ordered by difficulty; its Rust library chapter covers this crate.
- The result contract defines termination, assessment, archives and identities; the flow and transport model cards state the numerical methods and their limits.
- Runnable library examples and the repository with its verification cases, independent checkers and recorded evidence.
Modules§
- case
- The case contract
cfd-craft.case/0.1: the typed JSON input of a native run, its semantic checks and its identities. - flow
- Momentum and turbulence terms of the flow model: the steady momentum right-hand side, wall treatment, momentum advection schemes and the neutral k-epsilon package.
- geometry
- Polygon-prism geometry and grid-resolution evidence. Simple polygon prisms use the same cell-center mask and face operators as boxes.
- grid
- The uniform staggered grid of a case: cells, faces, the solid mask and the fluid components.
- input
- Shared strict JSON parsing and complete case preflight for all interfaces.
- mobile_
response - Fixed-flow scalar responses for mobile-receptor inference studies. Frozen-flow source responses: one accepted flow preparation per wind, then cold scalar-only solves.
- momentum_
solve - Matrix-free linear operators on the face-velocity unknowns, for implicit steady pseudo-time (stages P4 and P5a of the accuracy and steady-solver plan).
- multigrid
- Fixed symmetric multigrid for the unchanged Cartesian pressure equation. This is an original implementation; no external CFD implementation is used.
- output
- Checkpoints and run archives: publication, integrity and restart.
- pressure
- The matrix-free pressure operator, its gauges, the PCG solve and the projection.
- profiling
- Opt-in wall-time accounting at solver phase boundaries.
- solver
- The native solve: bounded execution of a
Case, its state, and the result contractcfd-craft.result/0.1. - transport
- Conservative transport of passive gases and particle size classes: source densities, receptor weights, initial fields and the finite-volume right-hand side.
- turbulence_
solve - Implicit k–ε pseudo-time steps in delta form for the implicit steady iteration with RANS (stage P5c of the accuracy and steady-solver plan).
- vegetation
- Opt-in porous vegetation drag, canopy turbulence and leaf deposition. Porous canopy sources on the unchanged uniform-grid pressure operator. Green1992 and Sanz2003 select source coefficients only; see the flow model card.
- verification
- Numerical verification fixtures that run on a case’s own grid, used by
cfd-craft verify.
Constants§
- RUSTC_
VERSION - Compiler used to build the core: the
rustc --versionline, part of the summary’sbuild_version. - SOURCE_
SHA256 - Fingerprint of the core package sources and its build lockfile.
Type Aliases§
- Result
- Result of the fallible library functions. The error is a message that
normally starts with a stable code (
CFD-E…: …). For an invalid case,case::Case::validateand the functions that call it, such asgrid::Grid::buildandsolver::run, return the serializedcase::CheckReportinstead.