moonbit-lbm

A D2Q9 lattice Boltzmann fluid simulation core for MoonBit.

lbm
fluid
simulation
d2q9
cfd
moon add zhsyutt/moonbit-lbm@0.2.1
Download zip
Author
Version
0.2.1
License
Apache-2.0
Last updated
3 hours ago
Downloads
4
README

#moonbit-lbm

moonbit-lbm is a reusable two-dimensional lattice Boltzmann method (LBM) core for MoonBit. It provides a dependency-light D2Q9 solver, explicit scalar transport, geometry and mask tools, numerical diagnostics, deterministic benchmark cases, and export formats for downstream applications and notebooks.

The package is designed for small-to-medium incompressible-flow experiments where a compact, inspectable numerical core is more useful than a large external runtime. The solver is intentionally explicit about collision models, boundary behavior, stability checks, and serialized state.

#Core capabilities

  • D2Q9 BGK, regularized, and MRT-style collision operators.
  • Periodic, open, bounce-back, velocity-inlet, pressure-outlet, and labeled boundary workflows.
  • Reusable Simulation and ScalarSolver APIs for fluid and scalar fields.
  • Rectangular masks, circles, boxes, morphology, connected components, boundary layers, and geometric moments.
  • Field and vector-field calculus: interpolation, gradients, divergence, curl, convolution, resampling, and statistics.
  • Checkpoint round trips with a versioned MLBM/1 text format.
  • CSV, PPM, VTK, JSON-lines, and compact ASCII exports.
  • Poiseuille, lid-driven cavity, and cylinder-wake benchmark cases with numerical gates.
  • Pure MoonBit implementation with no runtime service or native library dependency.

#Quick start

Install MoonBit, clone the repository, and run the complete local gate:

git clone https://github.com/zhsyutt/moonbit-lbm.git cd moonbit-lbm moon update moon fmt --check moon check --target all --deny-warn moon test --target all --deny-warn moon run cmd/main

The library package is available as:

///|
import {
"zhsyutt/moonbit-lbm" @lbm,
}

#CLI and examples

The example executable runs the deterministic benchmark suite and a reusable periodic simulation:

moon run cmd/main

The CLI prints CSV benchmark records, the number of stable cases, a compact simulation state summary, and the serialized checkpoint size. The library remains the primary API; applications can construct a simulation directly:

let simulation = @lbm.Simulation::new(
size=@lbm.Size::new(width=128, height=48),
options=@lbm.SimulationOptions::new(
model=@lbm.CollisionModel::bgk(omega=1.0),
boundary=@lbm.BoundaryMode::BounceBack,
force_x=0.000001,
),
)
simulation.set_box_walls()
simulation.set_uniform(rho=1.0, ux=0.0, uy=0.0)
simulation.run(500)
let report = simulation.report(name="channel")

#Architecture

The root package is organized by numerical responsibility:

AreaMain modules
Lattice and solverconstants.mbt, lattice.mbt, solver.mbt, advanced_solver.mbt, collision_models.mbt
Geometry and boundariesgeometry.mbt, geometry_boundaries.mbt, boundary_schemes.mbt, boundary_map.mbt
Fields and analysisgrid.mbt, field_calculus.mbt, flow_derivatives.mbt, analysis_advanced.mbt
Scalar transportscalar_transport.mbt, scalar_analysis.mbt, scalar_pipeline.mbt
Persistence and exportcheckpoint.mbt, export_*.mbt, reporting.mbt
Verification and studiesbenchmarks.mbt, benchmark_*.mbt, numerical_checks.mbt, scheduler.mbt, sweep.mbt
Runnable entry pointcmd/main

The main data path is Simulation -> collision -> streaming -> boundary application -> diagnostics. Field objects expose copies for safe analysis and provide explicit export methods. Checkpoints retain dimensions, options, solid geometry, time-step count, and distribution populations so a run can be resumed or audited without an external database.

#Benchmarks

The built-in suite measures Poiseuille flow, a lid-driven cavity, and a cylinder wake. Each report records grid size, steps, L2 and Linf profile error, mass drift, mean speed, and a stability flag. Run it locally with:

moon run cmd/main

The benchmark implementation is deterministic and the output is intended to be captured in docs/BENCHMARKS.md. Threshold checks are available through BenchmarkGate, while run_resolution_study supports comparing grid sizes without changing the solver API.

#Tests and numerical safeguards

The test suite covers equilibrium and collision behavior, streaming and boundary edge cases, degenerate geometries, morphology, scalar transport, checkpoint corruption, field transforms, exports, benchmark gates, and reusable API round trips. Warning-free checks are part of the normal gate:

moon fmt --check moon check --target all --deny-warn moon test --target all --deny-warn moon info git diff --exit-code

Use validate_options, validate_size, Simulation::health, validate_checkpoint, and BenchmarkGate when integrating the package into a larger application. Stability diagnostics report density bounds, maximum speed, Mach-limit compliance, NaN detection, mass, and density variation.

The Ubuntu CI job also runs native coverage instrumentation and prints a summary so newly added numerical branches remain observable.

#Continuous integration

GitHub Actions runs the warning-free format, interface, check, test, and CLI gates on Ubuntu, macOS, and Windows. The workflow installs the latest stable MoonBit CLI at job start and checks both native and wasm-gc targets. A manually triggered publish workflow validates the package again before publishing the version declared in moon.mod to Mooncakes.

#Package and license

This project is distributed under the Apache License 2.0.

#
CheckpointError

pub(all) suberror CheckpointError {
InvalidHeader
InvalidRecord(String)
InvalidSize
InvalidPayload
}

Errors raised when a simulation checkpoint cannot be trusted.

#
Aabb

pub(all) struct Aabb {
min : Point
max : Point
} derive(
Debug
)

Axis-aligned rectangular bounds.

#
Aabb::contains

fn Aabb::contains(self : Aabb, point : Point) -> Bool

True when a point lies inside or on the bounds.

#
Aabb::new

fn Aabb::new(min~ : Point, max~ : Point) -> Aabb

Construct normalized bounds even when corners are supplied in reverse.

#
Axis

pub(all) enum Axis {
Horizontal
Vertical
} derive(Eq,
Debug
)

Axis used by line-integral and flow-rate helpers.

#
BenchmarkComparison

pub(all) struct BenchmarkComparison {
l2_delta : Double
relative_l2 : Double
linf_delta : Double
mass_delta : Double
} derive(
Debug
)

Comparison between two measured benchmark results.

#
BenchmarkGate

pub(all) struct BenchmarkGate {
max_l2 : Double
max_linf : Double
max_mass_drift : Double
} derive(
Debug
)

Thresholds for a numerical benchmark gate.

#
BenchmarkGate::accepts

fn BenchmarkGate::accepts(self : BenchmarkGate, report : BenchmarkReport) -> Bool

Check a benchmark result against configured thresholds.

#
BenchmarkGate::new

fn BenchmarkGate::new(max_l2~ : Double, max_linf~ : Double, max_mass_drift~ : Double) -> BenchmarkGate

Construct a benchmark gate.

#
BenchmarkReport

pub(all) struct BenchmarkReport {
name : String
cells : Int
steps : Int
l2_error : Double
linf_error : Double
mass_drift : Double
mean_speed : Double
stable : Bool
} derive(
Debug
)

A deterministic numerical benchmark result.

#
BenchmarkReport::to_csv

fn BenchmarkReport::to_csv(self : BenchmarkReport) -> String

Format a benchmark result as one CSV record.

#
BenchmarkReport::to_markdown

fn BenchmarkReport::to_markdown(self : BenchmarkReport) -> String

Format a benchmark result for a human-readable report.

#
BenchmarkStatistics

pub(all) struct BenchmarkStatistics {
count : Int
stable_count : Int
mean_l2 : Double
mean_linf : Double
min_speed : Double
max_speed : Double
quality_score : Double
} derive(
Debug
)

Aggregate quality statistics across benchmark results.

#
BenchmarkStatistics::passes

fn BenchmarkStatistics::passes(self : BenchmarkStatistics, minimum_score? : Double) -> Bool

Return whether an aggregate meets a minimum quality score.

#
BenchmarkStatistics::to_csv

fn BenchmarkStatistics::to_csv(self : BenchmarkStatistics) -> String

Export aggregate benchmark statistics.

#
BoundaryDiagnostics

pub(all) struct BoundaryDiagnostics {
solid_cells : Int
fluid_cells : Int
exposed_faces : Int
corner_cells : Int
periodic_safe : Bool
} derive(
Debug
)

Diagnostics for a solid/fluid interface.

#
BoundaryKind

pub(all) enum BoundaryKind {
NoSlip
VelocityInlet
PressureOutlet
PeriodicX
PeriodicY
Symmetry
} derive(Eq,
Debug
)

Common local boundary schemes.

#
BoundaryLabel

pub(all) enum BoundaryLabel {
Interior
Wall
Inlet
Outlet
Periodic
Obstacle
} derive(Eq,
Debug
)

Semantic labels for boundary patches.

#
BoundaryMap

pub(all) struct BoundaryMap {
size : Size
labels : Array[BoundaryLabel]
} derive(
Debug
)

Row-major boundary label map.

#
BoundaryMap::boundary_count

fn BoundaryMap::boundary_count(self : BoundaryMap) -> Int

Count all non-interior labels.

#
BoundaryMap::boundary_only

fn BoundaryMap::boundary_only(self : BoundaryMap) -> BoundaryMap

Return a map with only labels that are not interior.

#
BoundaryMap::count

fn BoundaryMap::count(self : BoundaryMap, label : BoundaryLabel) -> Int

Count one label.

#
BoundaryMap::get

fn BoundaryMap::get(self : BoundaryMap, x~ : Int, y~ : Int) -> BoundaryLabel

Get a label, treating out-of-domain coordinates as walls.

#
BoundaryMap::new

fn BoundaryMap::new(size~ : Size) -> BoundaryMap

Allocate an interior-filled boundary map.

#
BoundaryMap::open_boundary_count

fn BoundaryMap::open_boundary_count(self : BoundaryMap) -> Int

Return the number of inlet/outlet labels combined.

#
BoundaryMap::set

fn BoundaryMap::set(self : BoundaryMap, x~ : Int, y~ : Int, label~ : BoundaryLabel) -> Unit

Set a boundary label within the map.

#
BoundaryMap::set_inlet_row

fn BoundaryMap::set_inlet_row(self : BoundaryMap, y~ : Int) -> Unit

Mark a horizontal row as an inlet.

#
BoundaryMap::set_outer_walls

fn BoundaryMap::set_outer_walls(self : BoundaryMap) -> Unit

Set the outer frame to wall labels.

#
BoundaryMap::set_outlet_row

fn BoundaryMap::set_outlet_row(self : BoundaryMap, y~ : Int) -> Unit

Mark a horizontal row as an outlet.

#
BoundaryMap::set_periodic_column

fn BoundaryMap::set_periodic_column(self : BoundaryMap, x~ : Int) -> Unit

Mark a vertical column as periodic.

#
BoundaryMap::solid_mask

fn BoundaryMap::solid_mask(self : BoundaryMap) -> DomainMask

Convert an obstacle label map into a solid mask.

#
BoundaryMap::to_ascii

fn BoundaryMap::to_ascii(self : BoundaryMap) -> String

Export a label map as ASCII initials.

#
BoundaryMap::to_csv

fn BoundaryMap::to_csv(self : BoundaryMap) -> String

Export labels as CSV.

#
BoundaryMode

pub(all) enum BoundaryMode {
BounceBack
Periodic
Open
} derive(Eq,
Debug
)

Outer-boundary behavior for the advanced solver.

#
BoundarySpec

pub(all) struct BoundarySpec {
kind : BoundaryKind
value_x : Double
value_y : Double
density : Double
} derive(
Debug
)

Parameters for one boundary patch.

#
BoundarySpec::no_slip

fn BoundarySpec::no_slip() -> BoundarySpec

Construct a no-slip patch.

#
BoundarySpec::pressure

fn BoundarySpec::pressure(density~ : Double, value_x? : Double, value_y? : Double) -> BoundarySpec

Construct a Zou/He pressure patch.

#
BoundarySpec::velocity

fn BoundarySpec::velocity(value_x~ : Double, value_y~ : Double, density? : Double) -> BoundarySpec

Construct a Zou/He velocity patch.

#
Cell

pub(all) struct Cell {
rho : Double
ux : Double
uy : Double
} derive(
Debug
)

A macroscopic cell sampled from the distribution field.

#
Cell::speed

fn Cell::speed(self : Cell) -> Double

Euclidean velocity magnitude.

#
Circle

pub(all) struct Circle {
center : Point
radius : Double
} derive(
Debug
)

Circle geometry primitive.

#
Circle::new

fn Circle::new(center~ : Point, radius~ : Double) -> Circle

Construct a circle.

#
Circle::signed_distance

fn Circle::signed_distance(self : Circle, point : Point) -> Double

Signed distance from a circle boundary; negative means inside.

#
CollisionModel

pub(all) enum CollisionModel {
Bgk(Double)
Regularized(Double)
Mrt(Double)
} derive(
Debug
)

Collision operators supported by the reusable solver.

#
CollisionModel::bgk

fn CollisionModel::bgk(omega~ : Double) -> CollisionModel

Construct a BGK collision model.

#
CollisionModel::mrt

fn CollisionModel::mrt(omega~ : Double) -> CollisionModel

Construct a two-relaxation-time MRT model.

#
CollisionModel::omega

fn CollisionModel::omega(self : CollisionModel) -> Double

Read the shear relaxation parameter from a collision model.

#
CollisionModel::regularized

fn CollisionModel::regularized(omega~ : Double) -> CollisionModel

Construct a regularized collision model.

#
Config

pub(all) struct Config {
omega : Double
force_x : Double
force_y : Double
} derive(
Debug
)

BGK relaxation and forcing configuration.

#
Config::new

fn Config::new(omega~ : Double, force_x? : Double, force_y? : Double) -> Config

Create a BGK config. omega should stay between 0 and 2 for normal use.

#
ConfigAudit

pub(all) struct ConfigAudit {
valid : Bool
model_name : String
viscosity : Double
recommended_dt : Double
relaxation_margin : Double
max_mach : Double
} derive(
Debug
)

Explain the numerical implications of a simulation configuration.

#
ConfigAudit::to_string

fn ConfigAudit::to_string(self : ConfigAudit) -> String

Return a human-readable configuration audit.

#
ConnectedComponent

pub(all) struct ConnectedComponent {
size : Int
cells : Array[GridPoint]
} derive(
Debug
)

A connected solid region in a domain mask.

#
ConvergenceHistory

pub(all) struct ConvergenceHistory {
capacity : Int
samples : Array[ConvergenceSample]
} derive(
Debug
)

Bounded convergence history for iterative solvers.

#
ConvergenceHistory::get

Read a sample safely.

#
ConvergenceHistory::is_converging

fn ConvergenceHistory::is_converging(self : ConvergenceHistory) -> Bool

True when the most recent residual does not increase.

#
ConvergenceHistory::latest_residual

fn ConvergenceHistory::latest_residual(self : ConvergenceHistory) -> Double

Return the latest residual, or zero for an empty history.

#
ConvergenceHistory::length

fn ConvergenceHistory::length(self : ConvergenceHistory) -> Int

Number of observations stored.

#
ConvergenceHistory::new

fn ConvergenceHistory::new(capacity? : Int) -> ConvergenceHistory

Allocate a convergence history.

#
ConvergenceHistory::push

fn ConvergenceHistory::push(self : ConvergenceHistory, step~ : Int, residual~ : Double, mass~ : Double) -> Unit

Append an observation and discard the oldest one after reaching capacity.

#
ConvergenceHistory::residual_ratio

fn ConvergenceHistory::residual_ratio(self : ConvergenceHistory) -> Double

Ratio between the latest and earliest residual.

#
ConvergenceHistory::to_csv

fn ConvergenceHistory::to_csv(self : ConvergenceHistory) -> String

Export a convergence history as CSV.

#
ConvergenceHistory::to_json

fn ConvergenceHistory::to_json(self : ConvergenceHistory) -> String

Export convergence history as a compact JSON-like record.

#
ConvergenceSample

pub(all) struct ConvergenceSample {
step : Int
residual : Double
mass : Double
} derive(
Debug
)

One residual/mass observation.

#
DomainMask

pub(all) struct DomainMask {
size : Size
solid : Array[Bool]
} derive(
Debug
)

A row-major solid-cell mask used by advanced simulations.

#
DomainMask::add_box

fn DomainMask::add_box(self : DomainMask, bounds~ : Aabb) -> Unit

Rasterize normalized rectangular bounds.

#
DomainMask::add_circle

fn DomainMask::add_circle(self : DomainMask, center~ : Point, radius~ : Double) -> Unit

Rasterize a circle using cell-center coordinates.

#
DomainMask::boundary_layer

fn DomainMask::boundary_layer(self : DomainMask) -> DomainMask

Return solid cells that touch at least one fluid neighbor.

#
DomainMask::bounding_box

fn DomainMask::bounding_box(self : DomainMask) -> Aabb

Return an axis-aligned solid bounding box.

#
DomainMask::centroid

fn DomainMask::centroid(self : DomainMask) -> Point

Compute the centroid of solid cells.

#
DomainMask::column_counts

fn DomainMask::column_counts(self : DomainMask) -> Array[Int]

Compute the number of solid cells in each column.

#
DomainMask::connected_components

fn DomainMask::connected_components(self : DomainMask) -> Array[ConnectedComponent]

Find four-neighbor connected solid regions.

#
DomainMask::copy

fn DomainMask::copy(self : DomainMask) -> DomainMask

Return a copy of the mask.

#
DomainMask::dilate

fn DomainMask::dilate(self : DomainMask, iterations? : Int) -> DomainMask

Grow solid cells by a four-neighbor stencil.

#
DomainMask::erode

fn DomainMask::erode(self : DomainMask, iterations? : Int) -> DomainMask

Erode solid cells by a four-neighbor stencil.

#
DomainMask::first_solid

fn DomainMask::first_solid(self : DomainMask) -> GridPoint?

Return the first solid coordinate, if one exists.

#
DomainMask::fluid_boundary

fn DomainMask::fluid_boundary(self : DomainMask) -> DomainMask

Return fluid cells adjacent to a solid cell.

#
DomainMask::fluid_count

fn DomainMask::fluid_count(self : DomainMask) -> Int

Count fluid cells inside the mask.

#
DomainMask::geometric_moments

fn DomainMask::geometric_moments(self : DomainMask) -> GeometricMoments

Compute area, centroid, and second moments of solid cells.

#
DomainMask::invert

fn DomainMask::invert(self : DomainMask) -> DomainMask

Return a mask with all cells inverted within its finite domain.

#
DomainMask::is_solid

fn DomainMask::is_solid(self : DomainMask, x : Int, y : Int) -> Bool

Read a solid flag; outside cells are treated as solid.

#
DomainMask::new

fn DomainMask::new(size~ : Size) -> DomainMask

Allocate an empty mask.

#
DomainMask::perimeter

fn DomainMask::perimeter(self : DomainMask) -> Double

Count fluid-solid interface faces.

#
DomainMask::radius

fn DomainMask::radius(self : DomainMask) -> Double

Return the Euclidean radius of the farthest solid cell from the centroid.

#
DomainMask::report

fn DomainMask::report(self : DomainMask) -> MaskReport

Return a compact summary of a mask.

#
DomainMask::row_counts

fn DomainMask::row_counts(self : DomainMask) -> Array[Int]

Compute the number of solid cells in each row.

#
DomainMask::set

fn DomainMask::set(self : DomainMask, x~ : Int, y~ : Int, solid~ : Bool) -> Unit

Set a solid flag when coordinates are inside the mask.

#
DomainMask::solid_count

fn DomainMask::solid_count(self : DomainMask) -> Int

Count solid cells.

#
DomainMask::to_ascii

fn DomainMask::to_ascii(self : DomainMask) -> String

Render a mask as a compact text image.

#
DomainMask::to_csv

fn DomainMask::to_csv(self : DomainMask) -> String

Export a mask as integer CSV.

#
Field2D

pub(all) struct Field2D {
size : Size
data : Array[Double]
} derive(
Debug
)

A row-major scalar field with clamped interpolation support.

#
Field2D::absolute_integral

fn Field2D::absolute_integral(self : Field2D) -> Double

Integrate absolute values over unit lattice cells.

#
Field2D::add_constant

fn Field2D::add_constant(self : Field2D, amount~ : Double) -> Field2D

Add a constant to every field value.

#
Field2D::boundary_mean

fn Field2D::boundary_mean(self : Field2D) -> Double

Return the mean value of the outermost one-cell ring.

#
Field2D::box_blur

fn Field2D::box_blur(self : Field2D, radius? : Int) -> Field2D

Apply a normalized box blur.

#
Field2D::clamp

fn Field2D::clamp(self : Field2D, low~ : Double, high~ : Double) -> Field2D

Apply a bounded pointwise transform.

#
Field2D::contains

fn Field2D::contains(self : Field2D, x : Int, y : Int) -> Bool

Return whether integer coordinates are inside the field.

#
Field2D::convolve

fn Field2D::convolve(self : Field2D, kernel~ : ArrayView[Double]) -> Field2D

Apply a finite convolution kernel centered at each cell.

#
Field2D::count_above

fn Field2D::count_above(self : Field2D, level~ : Double) -> Int

Count values above a threshold.

#
Field2D::crop

fn Field2D::crop(self : Field2D, x0~ : Int, y0~ : Int, width~ : Int, height~ : Int) -> Field2D

Extract a clipped scalar subfield.

#
Field2D::dimensions

fn Field2D::dimensions(self : Field2D) -> Size

Return the dimensions of a scalar field.

#
Field2D::edge_mask

fn Field2D::edge_mask(self : Field2D, threshold~ : Double) -> DomainMask

Return a mask for high-gradient edge cells.

#
Field2D::fill

fn Field2D::fill(self : Field2D, value~ : Double) -> Unit

Fill all cells with one value.

#
Field2D::flip_horizontal

fn Field2D::flip_horizontal(self : Field2D) -> Field2D

Flip a field horizontally.

#
Field2D::flip_vertical

fn Field2D::flip_vertical(self : Field2D) -> Field2D

Flip a field vertically.

#
Field2D::get

fn Field2D::get(self : Field2D, x : Int, y : Int) -> Double

Read a value, returning zero outside the domain.

#
Field2D::gradient_energy

fn Field2D::gradient_energy(self : Field2D) -> Double

Return the squared gradient energy.

#
Field2D::gradient_magnitude

fn Field2D::gradient_magnitude(self : Field2D, x~ : Int, y~ : Int) -> Double

Return the magnitude of the centered gradient at a cell.

#
Field2D::gradient_x

fn Field2D::gradient_x(self : Field2D, x~ : Int, y~ : Int) -> Double

Return the x component of the centered gradient.

#
Field2D::gradient_y

fn Field2D::gradient_y(self : Field2D, x~ : Int, y~ : Int) -> Double

Return the y component of the centered gradient.

#
Field2D::index

fn Field2D::index(self : Field2D, x : Int, y : Int) -> Int

Convert a coordinate to a row-major index.

#
Field2D::integral

fn Field2D::integral(self : Field2D) -> Double

Integrate a scalar field over unit lattice cells.

#
Field2D::laplacian

fn Field2D::laplacian(self : Field2D) -> Field2D

Apply a five-point discrete Laplacian.

#
Field2D::map

fn Field2D::map(self : Field2D, transform : (Int, Int, Double) -> Double) -> Field2D

Apply a pointwise transformation and return a new field.

#
Field2D::maximum_location

fn Field2D::maximum_location(self : Field2D) -> GridPoint

Return the coordinate of a maximum value, using row-major tie breaking.

#
Field2D::mean_on_mask

fn Field2D::mean_on_mask(self : Field2D, mask~ : DomainMask) -> Double

Compute the mean of values at solid cells.

#
Field2D::minimum_location

fn Field2D::minimum_location(self : Field2D) -> GridPoint

Return the coordinate of a minimum value.

#
Field2D::new

fn Field2D::new(size~ : Size, initial? : Double) -> Field2D

Allocate a scalar field.

#
Field2D::nonzero_count

fn Field2D::nonzero_count(self : Field2D, tolerance? : Double) -> Int

Count values that are not numerically zero.

#
Field2D::normalize

fn Field2D::normalize(self : Field2D, low? : Double, high? : Double) -> Field2D

Normalize a field into a requested range.

#
Field2D::pad

fn Field2D::pad(self : Field2D, border~ : Int, value? : Double) -> Field2D

Pad a field with a constant border.

#
Field2D::radial_average

fn Field2D::radial_average(self : Field2D, center~ : Point, bins~ : Int) -> Array[Double]

Compute a radial average profile around a point.

#
Field2D::region_count

fn Field2D::region_count(self : Field2D, x0~ : Int, y0~ : Int, x1~ : Int, y1~ : Int, level~ : Double) -> Int

Count values in a half-open region that pass a predicate.

#
Field2D::region_mean

fn Field2D::region_mean(self : Field2D, x0~ : Int, y0~ : Int, x1~ : Int, y1~ : Int) -> Double

Average a half-open integer region.

#
Field2D::region_sum

fn Field2D::region_sum(self : Field2D, x0~ : Int, y0~ : Int, x1~ : Int, y1~ : Int) -> Double

Sum a half-open integer region after clipping to the field.

#
Field2D::resample

fn Field2D::resample(self : Field2D, size~ : Size) -> Field2D

Resample a field with nearest-neighbor interpolation.

#
Field2D::rotate90

fn Field2D::rotate90(self : Field2D) -> Field2D

Rotate a field clockwise by ninety degrees.

#
Field2D::sample

fn Field2D::sample(self : Field2D, x~ : Double, y~ : Double) -> Double

Bilinearly sample at floating-point coordinates with edge clamping.

#
Field2D::scale_values

fn Field2D::scale_values(self : Field2D, factor~ : Double) -> Field2D

Scale every field value.

#
Field2D::set

fn Field2D::set(self : Field2D, x~ : Int, y~ : Int, value~ : Double) -> Unit

Write a value when the coordinate is inside the domain.

#
Field2D::smooth

fn Field2D::smooth(self : Field2D, radius? : Int) -> Field2D

Average each cell with a square neighborhood.

#
Field2D::square

fn Field2D::square(self : Field2D) -> Field2D

Return a pointwise square of a scalar field.

#
Field2D::statistics

fn Field2D::statistics(self : Field2D) -> FieldStatistics

Compute unmasked descriptive statistics.

#
Field2D::statistics_masked

fn Field2D::statistics_masked(self : Field2D, mask~ : DomainMask, include_solid? : Bool) -> FieldStatistics

Compute statistics while optionally excluding solid mask cells.

#
Field2D::target_residual

fn Field2D::target_residual(self : Field2D, target~ : Double) -> Double

Compute a scalar field residual against a constant target.

#
Field2D::threshold

fn Field2D::threshold(self : Field2D, level~ : Double) -> DomainMask

Return a threshold mask with high values marked solid.

#
Field2D::to_ascii

fn Field2D::to_ascii(self : Field2D, ramp? : String) -> String

Export a scalar field as a compact ASCII heatmap.

#
Field2D::to_csv

fn Field2D::to_csv(self : Field2D, name? : String) -> String

Export a scalar field as row-major CSV.

#
Field2D::to_json_lines

fn Field2D::to_json_lines(self : Field2D, name? : String) -> String

Export a field as newline-delimited JSON-like points.

#
Field2D::to_ppm

fn Field2D::to_ppm(self : Field2D) -> String

Export a scalar field as an ASCII PPM image.

#
Field2D::to_vtk

fn Field2D::to_vtk(self : Field2D, name? : String) -> String

Export a scalar field in a simple VTK legacy structured-points format.

#
Field2D::transpose

fn Field2D::transpose(self : Field2D) -> Field2D

Transpose a scalar field.

#
Field2D::values

fn Field2D::values(self : Field2D) -> Array[Double]

Copy the underlying data in row-major order.

#
Field2D::variation

fn Field2D::variation(self : Field2D) -> Double

Return the total squared variation between neighboring cells.

#
FieldStatistics

pub(all) struct FieldStatistics {
count : Int
sum : Double
mean : Double
minimum : Double
maximum : Double
variance : Double
l2_norm : Double
} derive(
Debug
)

Summary statistics for a scalar field.

#
GeometricMoments

pub(all) struct GeometricMoments {
area : Int
centroid : Point
second_x : Double
second_y : Double
product_xy : Double
} derive(
Debug
)

Integer geometric moments of a solid mask.

#
GridPoint

pub(all) struct GridPoint {
x : Int
y : Int
} derive(Eq,
Debug
)

Integer coordinate used by connected-component reports.

#
Lattice

pub(all) struct Lattice {
size : Size
config : Config
f : Array[Double]
next : Array[Double]
solid : Array[Bool]
step_count : Int
} derive(
Debug
)

D2Q9 lattice Boltzmann state. Distribution arrays are stored in cell-major order: (y * width + x) * 9 + direction.

#
Lattice::add_cylinder

fn Lattice::add_cylinder(self : Lattice, center_x~ : Int, center_y~ : Int, radius~ : Int) -> Unit

Place a solid circular obstacle.

#
Lattice::apply_mask

fn Lattice::apply_mask(self : Lattice, mask~ : DomainMask) -> Unit

Apply a reusable mask to legacy solid flags.

#
Lattice::cell

fn Lattice::cell(self : Lattice, x : Int, y : Int) -> Cell

Reconstruct density and velocity at a cell from distribution values.

#
Lattice::cell_index

fn Lattice::cell_index(self : Lattice, x : Int, y : Int) -> Int

Convert coordinates to a cell index.

#
Lattice::cells

fn Lattice::cells(self : Lattice) -> Array[Cell]

Return all macroscopic cells in row-major order.

#
Lattice::compressibility_error

fn Lattice::compressibility_error(self : Lattice) -> Double

Return mean absolute divergence for a legacy lattice.

#
Lattice::contains

fn Lattice::contains(self : Lattice, x : Int, y : Int) -> Bool

True when the coordinate is inside the domain.

#
Lattice::density_field

fn Lattice::density_field(self : Lattice) -> Field2D

Convert a legacy lattice density field to a reusable scalar type.

#
Lattice::dimensions

fn Lattice::dimensions(self : Lattice) -> Size

Return the legacy lattice dimensions.

#
Lattice::dist_index

fn Lattice::dist_index(self : Lattice, x : Int, y : Int, d : Int) -> Int

Convert coordinates and direction to a distribution index.

#
Lattice::divergence_field

fn Lattice::divergence_field(self : Lattice) -> Field2D

Return the centered divergence of a legacy velocity field.

#
Lattice::domain_mask

fn Lattice::domain_mask(self : Lattice) -> DomainMask

Copy the legacy solid mask into a reusable domain mask.

#
Lattice::field_statistics

fn Lattice::field_statistics(self : Lattice) -> FieldStatistics

Return a compact field quality summary.

#
Lattice::fluid_count

fn Lattice::fluid_count(self : Lattice) -> Int

Count legacy fluid cells.

#
Lattice::horizontal_profile

fn Lattice::horizontal_profile(self : Lattice, y~ : Int) -> Array[Double]

Sample ux along one horizontal row.

#
Lattice::is_solid

fn Lattice::is_solid(self : Lattice, x : Int, y : Int) -> Bool

Read whether a cell is solid.

#
Lattice::kinetic_energy

fn Lattice::kinetic_energy(self : Lattice) -> Double

Compute legacy kinetic energy.

#
Lattice::mass

fn Lattice::mass(self : Lattice) -> Double

Total mass across fluid cells.

#
Lattice::mass_drift

fn Lattice::mass_drift(self : Lattice, reference~ : Double) -> Double

Compute the absolute mass drift after a run.

#
Lattice::maximum_pressure

fn Lattice::maximum_pressure(self : Lattice) -> Double

Return the maximum legacy pressure.

#
Lattice::maximum_speed_location

fn Lattice::maximum_speed_location(self : Lattice) -> GridPoint

Return the location of the largest legacy speed.

#
Lattice::maximum_strain_rate

fn Lattice::maximum_strain_rate(self : Lattice) -> Double

Return the maximum legacy strain rate.

#
Lattice::mean_pressure

fn Lattice::mean_pressure(self : Lattice) -> Double

Return the mean legacy pressure.

#
Lattice::mean_ux

fn Lattice::mean_ux(self : Lattice) -> Double

Mean horizontal velocity over non-solid cells.

#
Lattice::new

fn Lattice::new(size~ : Size, config~ : Config) -> Lattice

Create an equilibrium lattice with density 1 and zero velocity.

#
Lattice::pressure_field

fn Lattice::pressure_field(self : Lattice) -> Field2D

Return the legacy isothermal pressure field.

#
Lattice::pressure_range

fn Lattice::pressure_range(self : Lattice) -> (Double, Double)

Return the legacy pressure range.

#
Lattice::reset_fluid

fn Lattice::reset_fluid(self : Lattice) -> Unit

Set every legacy fluid cell to equilibrium zero velocity.

#
Lattice::rho_field

fn Lattice::rho_field(self : Lattice) -> Array[Double]

Extract density values in row-major order.

#
Lattice::run

fn Lattice::run(self : Lattice, steps : Int) -> Unit

Run several time steps.

#
Lattice::set_box_walls

fn Lattice::set_box_walls(self : Lattice) -> Unit

Mark the outer box as no-slip walls.

#
Lattice::set_cavity_walls

fn Lattice::set_cavity_walls(self : Lattice) -> Unit

Mark bottom, left, and right walls while leaving the top row for a moving lid.

#
Lattice::set_cell

fn Lattice::set_cell(self : Lattice, x : Int, y : Int, rho~ : Double, ux~ : Double, uy~ : Double) -> Unit

Reset one fluid cell to a chosen macroscopic state.

#
Lattice::set_channel_walls

fn Lattice::set_channel_walls(self : Lattice) -> Unit

Mark only the top and bottom rows as channel walls.

#
Lattice::set_moving_lid

fn Lattice::set_moving_lid(self : Lattice, ux~ : Double, rho? : Double) -> Unit

Initialize the upper row as a moving lid.

#
Lattice::set_poiseuille_profile

fn Lattice::set_poiseuille_profile(self : Lattice, max_ux~ : Double, rho? : Double) -> Unit

Initialize a parabolic channel profile between the solid top and bottom rows.

#
Lattice::set_solid

fn Lattice::set_solid(self : Lattice, x : Int, y : Int, solid~ : Bool) -> Unit

Mark or clear a solid bounce-back cell.

#
Lattice::set_uniform_inlet

fn Lattice::set_uniform_inlet(self : Lattice, x~ : Int, ux~ : Double, rho? : Double) -> Unit

Initialize a vertical inlet stripe with a uniform horizontal velocity.

#
Lattice::solid_count

fn Lattice::solid_count(self : Lattice) -> Int

Count legacy solid cells.

#
Lattice::speed_ascii

fn Lattice::speed_ascii(self : Lattice) -> String

Render a compact text heatmap of velocity magnitude.

#
Lattice::speed_field

fn Lattice::speed_field(self : Lattice) -> Array[Double]

Extract velocity magnitude values in row-major order.

#
Lattice::speed_scalar_field

fn Lattice::speed_scalar_field(self : Lattice) -> Field2D

Return a scalar field of legacy speed magnitudes.

#
Lattice::stability

fn Lattice::stability(self : Lattice) -> Stability

Compute simple stability diagnostics for regression checks and demos.

#
Lattice::step

fn Lattice::step(self : Lattice) -> Unit

Advance the lattice by one collide-stream step.

#
Lattice::strain_rate_field

fn Lattice::strain_rate_field(self : Lattice) -> Field2D

Return the legacy strain-rate magnitude field.

#
Lattice::summary

fn Lattice::summary(self : Lattice, name? : String) -> String

Human-readable one-block simulation summary.

#
Lattice::to_csv

fn Lattice::to_csv(self : Lattice) -> String

Export rho/ux/uy/speed/solid fields as CSV text.

#
Lattice::to_png

fn Lattice::to_png(self : Lattice) -> Bytes

Encode velocity magnitude as a small RGB PNG image.

#
Lattice::ux_field

fn Lattice::ux_field(self : Lattice) -> Array[Double]

Extract horizontal velocity values in row-major order.

#
Lattice::uy_field

fn Lattice::uy_field(self : Lattice) -> Array[Double]

Extract vertical velocity values in row-major order.

#
Lattice::velocity_field

fn Lattice::velocity_field(self : Lattice) -> VectorField2D

Convert a legacy lattice velocity field to the reusable vector type.

#
Lattice::vertical_profile

fn Lattice::vertical_profile(self : Lattice, x~ : Int) -> Array[Double]

Sample ux along one vertical column.

#
Lattice::vorticity_at

fn Lattice::vorticity_at(self : Lattice, x : Int, y : Int) -> Double

Estimate scalar vorticity at one cell, duy/dx - dux/dy.

#
Lattice::vorticity_csv

fn Lattice::vorticity_csv(self : Lattice) -> String

Export vorticity as CSV for quick plotting.

#
Lattice::vorticity_field

fn Lattice::vorticity_field(self : Lattice) -> Array[Double]

Estimate scalar vorticity with centered differences where possible.

#
Lattice::vorticity_l1

fn Lattice::vorticity_l1(self : Lattice) -> Double

Return the total vorticity magnitude.

#
MaskReport

pub(all) struct MaskReport {
total_cells : Int
solid_cells : Int
fluid_cells : Int
solid_fraction : Double
} derive(
Debug
)

A report about the solid mask.

#
MemoryEstimate

pub(all) struct MemoryEstimate {
cells : Int
distribution_bytes : Int
next_bytes : Int
mask_bytes : Int
scalar_field_bytes : Int
vector_field_bytes : Int
total_bytes : Int
} derive(
Debug
)

Estimated memory footprint of row-major simulation arrays.

#
MemoryEstimate::to_string

fn MemoryEstimate::to_string(self : MemoryEstimate) -> String

Format a memory estimate in a readable form.

#
NumericalHealth

pub(all) struct NumericalHealth {
finite : Bool
positive_density : Bool
mass_residual : Double
max_mach : Double
min_density : Double
max_density : Double
pass : Bool
} derive(
Debug
)

Numerical health signals used by reports and quality gates.

#
ParameterSweep

pub(all) struct ParameterSweep {
omegas : Array[Double]
steps : Int
boundary : BoundaryMode
} derive(
Debug
)

A one-dimensional relaxation parameter sweep.

#
ParameterSweep::new

fn ParameterSweep::new(omegas~ : Array[Double], steps~ : Int, boundary? : BoundaryMode) -> ParameterSweep

Build a sweep over supplied relaxation values.

#
Point

pub(all) struct Point {
x : Double
y : Double
} derive(
Debug
)

A two-dimensional point or vector.

#
Point::add

fn Point::add(self : Point, other : Point) -> Point

Add two points as vectors.

#
Point::distance

fn Point::distance(self : Point, other : Point) -> Double

Distance between two points.

#
Point::dot

fn Point::dot(self : Point, other : Point) -> Double

Dot product.

#
Point::length

fn Point::length(self : Point) -> Double

Euclidean length.

#
Point::new

fn Point::new(x~ : Double, y~ : Double) -> Point

Construct a point.

#
Point::scale

fn Point::scale(self : Point, factor : Double) -> Point

Scale a vector.

#
Point::sub

fn Point::sub(self : Point, other : Point) -> Point

Subtract two points as vectors.

#
Preset

pub(all) enum Preset {
Poiseuille
LidDrivenCavity
CylinderWake
ScalarDiffusion
} derive(Eq,
Debug
)

Reusable scenario presets for examples and parameter sweeps.

#
Probe

pub(all) enum Probe {
CellProbe(Int, Int)
PointProbe(Point)
} derive(
Debug
)

A probe location used for diagnostics.

#
Probe::cell

fn Probe::cell(x~ : Int, y~ : Int) -> Probe

Construct an integer-cell probe.

#
Probe::point

fn Probe::point(x~ : Double, y~ : Double) -> Probe

Construct a floating-point probe.

#
RunPlan

pub(all) struct RunPlan {
steps : Int
sample_every : Int
record_initial : Bool
stop_on_unstable : Bool
} derive(
Debug
)

A deterministic simulation run plan.

#
RunPlan::new

fn RunPlan::new(steps~ : Int, sample_every? : Int, record_initial? : Bool, stop_on_unstable? : Bool) -> RunPlan

Build a conservative run plan.

#
RunSummary

pub(all) struct RunSummary {
steps : Int
samples : Int
final_mass : Double
final_max_speed : Double
converged : Bool
stopped_early : Bool
} derive(
Debug
)

Summary returned by a planned run.

#
RunSummary::mass_change

fn RunSummary::mass_change(self : RunSummary, initial_mass~ : Double) -> Double

Return the absolute mass change represented by a run summary.

#
RunSummary::to_csv

fn RunSummary::to_csv(self : RunSummary) -> String

Serialize a run summary as CSV.

#
ScalarBoundary

pub(all) enum ScalarBoundary {
ZeroFlux
Periodic
Fixed(Double)
} derive(
Debug
)

Boundary behavior for a passive scalar.

#
ScalarReport

pub(all) struct ScalarReport {
name : String
size : Size
steps : Int
mass : Double
mean : Double
minimum : Double
maximum : Double
variance : Double
finite : Bool
} derive(
Debug
)

A compact scalar report.

#
ScalarReport::to_csv

fn ScalarReport::to_csv(self : ScalarReport) -> String

Export a scalar report as CSV.

#
ScalarReport::to_markdown

fn ScalarReport::to_markdown(self : ScalarReport) -> String

Export a scalar report as a Markdown row.

#
ScalarSolver

pub(all) struct ScalarSolver {
size : Size
diffusivity : Double
dt : Double
boundary : ScalarBoundary
values : Array[Double]
next : Array[Double]
source : Array[Double]
step_count : Int
} derive(
Debug
)

Explicit finite-difference advection-diffusion solver for one scalar.

#
ScalarSolver::absolute_mass

fn ScalarSolver::absolute_mass(self : ScalarSolver) -> Double

Return the sum of absolute scalar values.

#
ScalarSolver::add_uniform_source

fn ScalarSolver::add_uniform_source(self : ScalarSolver, value~ : Double) -> Unit

Apply a source to every cell.

#
ScalarSolver::clamped_field

fn ScalarSolver::clamped_field(self : ScalarSolver, low~ : Double, high~ : Double) -> Field2D

Return a bounded scalar field with a new lower and upper range.

#
ScalarSolver::clear_sources

fn ScalarSolver::clear_sources(self : ScalarSolver) -> Unit

Clear all source terms.

#
ScalarSolver::count_above

fn ScalarSolver::count_above(self : ScalarSolver, level~ : Double) -> Int

Count cells above a scalar threshold.

#
ScalarSolver::courant_number

fn ScalarSolver::courant_number(self : ScalarSolver, ux~ : Double, uy~ : Double) -> Double

Estimate a scalar Courant number for a uniform velocity.

#
ScalarSolver::diffusion_number

fn ScalarSolver::diffusion_number(self : ScalarSolver) -> Double

Estimate the explicit diffusion stability number.

#
ScalarSolver::domain

fn ScalarSolver::domain(self : ScalarSolver) -> Size

Return the field size.

#
ScalarSolver::explicitly_stable

fn ScalarSolver::explicitly_stable(self : ScalarSolver) -> Bool

Return true when an explicit scalar step is within the five-point limit.

#
ScalarSolver::field

fn ScalarSolver::field(self : ScalarSolver) -> Field2D

Convert the scalar values to a reusable field object.

#
ScalarSolver::fill

fn ScalarSolver::fill(self : ScalarSolver, value~ : Double) -> Unit

Fill the scalar field.

#
ScalarSolver::get

fn ScalarSolver::get(self : ScalarSolver, x~ : Int, y~ : Int) -> Double

Read one scalar value with boundary-aware extension.

#
ScalarSolver::gradient_energy

fn ScalarSolver::gradient_energy(self : ScalarSolver) -> Double

Return the L2 energy of scalar gradients.

#
ScalarSolver::gradient_magnitude

fn ScalarSolver::gradient_magnitude(self : ScalarSolver) -> Field2D

Return the current scalar gradient field magnitude.

#
ScalarSolver::is_above

fn ScalarSolver::is_above(self : ScalarSolver, lower~ : Double) -> Bool

True when no scalar is below a supplied lower bound.

#
ScalarSolver::is_finite

fn ScalarSolver::is_finite(self : ScalarSolver) -> Bool

True when every stored scalar is finite.

#
ScalarSolver::laplacian

fn ScalarSolver::laplacian(self : ScalarSolver) -> Field2D

Return the current scalar Laplacian.

#
ScalarSolver::mass

fn ScalarSolver::mass(self : ScalarSolver) -> Double

Total scalar quantity in the domain.

#
ScalarSolver::mass_ratio

fn ScalarSolver::mass_ratio(self : ScalarSolver, initial_mass~ : Double) -> Double

Return the fraction of the initial mass remaining.

#
ScalarSolver::maximum

fn ScalarSolver::maximum(self : ScalarSolver) -> Double

Return the maximum scalar value.

#
ScalarSolver::maximum_location

fn ScalarSolver::maximum_location(self : ScalarSolver) -> Point

Return the position of the first maximum scalar cell.

#
ScalarSolver::maximum_source

fn ScalarSolver::maximum_source(self : ScalarSolver) -> Double

Return the maximum source magnitude.

#
ScalarSolver::mean

fn ScalarSolver::mean(self : ScalarSolver) -> Double

Return the mean scalar value.

#
ScalarSolver::mean_source

fn ScalarSolver::mean_source(self : ScalarSolver) -> Double

Return the mean source contribution.

#
ScalarSolver::minimum

fn ScalarSolver::minimum(self : ScalarSolver) -> Double

Return the minimum scalar value.

#
ScalarSolver::minimum_location

fn ScalarSolver::minimum_location(self : ScalarSolver) -> Point

Return the position of the first minimum scalar cell.

#
ScalarSolver::new

fn ScalarSolver::new(size~ : Size, diffusivity~ : Double, dt~ : Double, boundary? : ScalarBoundary) -> ScalarSolver

Allocate a scalar transport field.

#
ScalarSolver::normalized_field

fn ScalarSolver::normalized_field(self : ScalarSolver) -> Field2D

Return the scalar state as normalized output.

#
ScalarSolver::report

fn ScalarSolver::report(self : ScalarSolver, name? : String) -> ScalarReport

Build a scalar report.

#
ScalarSolver::set

fn ScalarSolver::set(self : ScalarSolver, x~ : Int, y~ : Int, value~ : Double) -> Unit

Set one scalar value.

#
ScalarSolver::set_source

fn ScalarSolver::set_source(self : ScalarSolver, x~ : Int, y~ : Int, value~ : Double) -> Unit

Set a per-cell source term.

#
ScalarSolver::source_mass

fn ScalarSolver::source_mass(self : ScalarSolver) -> Double

Total absolute source strength currently configured.

#
ScalarSolver::stability_number

fn ScalarSolver::stability_number(self : ScalarSolver) -> Double

Return the dimensionless diffusion stability number.

#
ScalarSolver::statistics

fn ScalarSolver::statistics(self : ScalarSolver) -> FieldStatistics

Return descriptive scalar statistics.

#
ScalarSolver::steady_state_error

fn ScalarSolver::steady_state_error(self : ScalarSolver, target~ : Double) -> Double

Absolute error between the current mean and a target state.

#
ScalarSolver::step

fn ScalarSolver::step(self : ScalarSolver) -> Unit

Advance with a zero velocity field.

#
ScalarSolver::step_many

fn ScalarSolver::step_many(self : ScalarSolver, steps : Int) -> Unit

Advance a scalar solver several times.

#
ScalarSolver::step_with_velocity

fn ScalarSolver::step_with_velocity(self : ScalarSolver, velocity~ : VectorField2D) -> Unit

Set a uniform velocity and advance one advection-diffusion step.

#
ScalarSolver::variance

fn ScalarSolver::variance(self : ScalarSolver) -> Double

Scalar variance over all cells.

#
Scenario

pub(all) enum Scenario {
Poiseuille
LidDrivenCavity
CylinderWake
} derive(Eq,
Debug
)

High level demo scenario.

#
Shape

pub(all) enum Shape {
CircleShape(Circle)
RectangleShape(Aabb)
} derive(
Debug
)

A shape that can be rasterized into a lattice mask.

#
Shape::circle

fn Shape::circle(center~ : Point, radius~ : Double) -> Shape

Build a circle shape.

#
Shape::contains

fn Shape::contains(self : Shape, point : Point) -> Bool

Test a shape using lattice-cell-center coordinates.

#
Shape::rectangle

fn Shape::rectangle(bounds~ : Aabb) -> Shape

Build a rectangle shape.

#
Simulation

pub(all) struct Simulation {
size : Size
options : SimulationOptions
f : Array[Double]
next : Array[Double]
solid : Array[Bool]
step_count : Int
} derive(
Debug
)

A reusable D2Q9 simulation with selectable collision and outer boundaries.

#
Simulation::add_box

fn Simulation::add_box(self : Simulation, bounds~ : Aabb) -> Unit

Add a rectangular obstacle.

#
Simulation::add_circle

fn Simulation::add_circle(self : Simulation, center~ : Point, radius~ : Double) -> Unit

Add a circular obstacle.

#
Simulation::apply_boundary_map

fn Simulation::apply_boundary_map(self : Simulation, labels : BoundaryMap) -> Unit

Apply semantic wall and obstacle labels to a simulation.

#
Simulation::apply_mask

fn Simulation::apply_mask(self : Simulation, mask~ : DomainMask) -> Unit

Apply a reusable geometry mask.

#
Simulation::boundary_map

fn Simulation::boundary_map(self : Simulation) -> BoundaryMap

Build a label map from a simulation's solid geometry.

#
Simulation::boundary_report

fn Simulation::boundary_report(self : Simulation) -> BoundaryDiagnostics

Return a boundary diagnostic report for the current simulation mask.

#
Simulation::cell

fn Simulation::cell(self : Simulation, x~ : Int, y~ : Int) -> Cell

Read the macroscopic state at a cell.

#
Simulation::cells

fn Simulation::cells(self : Simulation) -> Array[Cell]

Return all fluid cells in row-major order.

#
Simulation::checkpoint_size

fn Simulation::checkpoint_size(self : Simulation) -> Int

Return the serialized checkpoint size in bytes.

#
Simulation::compressibility_error

fn Simulation::compressibility_error(self : Simulation) -> Double

Return the mean absolute divergence.

#
Simulation::contains

fn Simulation::contains(self : Simulation, x : Int, y : Int) -> Bool

Return whether integer coordinates are inside the simulation.

#
Simulation::current_mask

fn Simulation::current_mask(self : Simulation) -> DomainMask

Copy the current solid geometry.

#
Simulation::density_csv

fn Simulation::density_csv(self : Simulation) -> String

Export density as a CSV grid.

#
Simulation::density_field

fn Simulation::density_field(self : Simulation) -> Field2D

Build a density field from the simulation state.

#
Simulation::density_variation

fn Simulation::density_variation(self : Simulation) -> Double

Return the normalized density variation.

#
Simulation::distribution_count

fn Simulation::distribution_count(self : Simulation) -> Int

Return the number of stored distribution populations.

#
Simulation::distribution_index

fn Simulation::distribution_index(self : Simulation, x : Int, y : Int, d : Int) -> Int

Convert coordinates and direction to a distribution index.

#
Simulation::distribution_values

fn Simulation::distribution_values(self : Simulation) -> Array[Double]

Copy the distribution payload for diagnostics or persistence adapters.

#
Simulation::divergence_at

fn Simulation::divergence_at(self : Simulation, x~ : Int, y~ : Int) -> Double

Centered divergence of a velocity field.

#
Simulation::divergence_field

fn Simulation::divergence_field(self : Simulation) -> Field2D

Return the divergence field.

#
Simulation::domain

fn Simulation::domain(self : Simulation) -> Size

Return the domain size.

#
Simulation::flow_rate

fn Simulation::flow_rate(self : Simulation, axis~ : Axis, index~ : Int) -> Double

Sum horizontal or vertical velocity along one lattice line.

#
Simulation::fluid_count

fn Simulation::fluid_count(self : Simulation) -> Int

Count fluid cells in an advanced simulation.

#
Simulation::force_on_mask

fn Simulation::force_on_mask(self : Simulation, mask~ : DomainMask) -> Point

Estimate the net force on solid cells from local interface momentum exchange.

#
Simulation::forced_copy

fn Simulation::forced_copy(self : Simulation, force_x~ : Double, force_y~ : Double) -> Simulation

Add a uniform body force to the current velocity state through options.

#
Simulation::from_checkpoint

fn Simulation::from_checkpoint(text : String) -> Simulation raise CheckpointError

Restore a simulation from Simulation::to_checkpoint output.

#
Simulation::health

fn Simulation::health(self : Simulation) -> NumericalHealth

Compute health metrics for a reusable simulation.

#
Simulation::horizontal_profile

fn Simulation::horizontal_profile(self : Simulation, y~ : Int) -> Array[Double]

Return a horizontal velocity profile.

#
Simulation::is_equilibrium

fn Simulation::is_equilibrium(self : Simulation, tolerance? : Double) -> Bool

Return whether the distribution is within tolerance of local equilibrium.

#
Simulation::is_solid

fn Simulation::is_solid(self : Simulation, x~ : Int, y~ : Int) -> Bool

Read a solid flag; outside coordinates are solid.

#
Simulation::kinetic_energy

fn Simulation::kinetic_energy(self : Simulation) -> Double

Total kinetic energy over fluid cells.

#
Simulation::kinetic_energy_field

fn Simulation::kinetic_energy_field(self : Simulation) -> Field2D

Construct a field of local kinetic energy densities.

#
Simulation::mass

fn Simulation::mass(self : Simulation) -> Double

Return the total fluid mass.

#
Simulation::mass_drift

fn Simulation::mass_drift(self : Simulation, reference~ : Double) -> Double

Absolute mass drift from a reference mass.

#
Simulation::max_mach

fn Simulation::max_mach(self : Simulation) -> Double

Return the maximum absolute speed in a simulation.

#
Simulation::maximum_density

fn Simulation::maximum_density(self : Simulation) -> Double

Find the maximum fluid density.

#
Simulation::maximum_strain_rate

fn Simulation::maximum_strain_rate(self : Simulation) -> Double

Return the maximum strain-rate magnitude.

#
Simulation::mean_density

fn Simulation::mean_density(self : Simulation) -> Double

Return the mean density over fluid cells.

#
Simulation::mean_velocity

fn Simulation::mean_velocity(self : Simulation) -> Point

Compute the mean velocity over fluid cells.

#
Simulation::minimum_density

fn Simulation::minimum_density(self : Simulation) -> Double

Find the minimum fluid density.

#
Simulation::momentum

fn Simulation::momentum(self : Simulation) -> Point

Total fluid momentum.

#
Simulation::momentum_x_field

fn Simulation::momentum_x_field(self : Simulation) -> Field2D

Construct the x component of local momentum density.

#
Simulation::momentum_y_field

fn Simulation::momentum_y_field(self : Simulation) -> Field2D

Construct the y component of local momentum density.

#
Simulation::new

fn Simulation::new(size~ : Size, options~ : SimulationOptions) -> Simulation

Allocate an equilibrium advanced simulation.

#
Simulation::payload_bytes

fn Simulation::payload_bytes(self : Simulation) -> Int

Estimate the payload bytes without allocating a checkpoint string.

#
Simulation::pressure_at

fn Simulation::pressure_at(self : Simulation, x~ : Int, y~ : Int) -> Double

Local pressure under the isothermal D2Q9 equation of state.

#
Simulation::pressure_field

fn Simulation::pressure_field(self : Simulation) -> Field2D

Return the pressure field.

#
Simulation::report

fn Simulation::report(self : Simulation, name? : String) -> SimulationReport

Build a report from a reusable simulation.

#
Simulation::run

fn Simulation::run(self : Simulation, steps : Int) -> Unit

Advance several steps.

#
Simulation::run_plan

fn Simulation::run_plan(self : Simulation, plan : RunPlan) -> RunSummary

Execute a run plan and record deterministic observation count.

#
Simulation::same_geometry

fn Simulation::same_geometry(self : Simulation, other : Simulation) -> Bool

Return whether two simulations share dimensions and solid geometry.

#
Simulation::sample_component

fn Simulation::sample_component(self : Simulation, axis~ : Axis, index~ : Int, component~ : String) -> Array[Double]

Sample a line of one scalar component.

#
Simulation::sample_line

fn Simulation::sample_line(self : Simulation, axis~ : Axis, index~ : Int) -> Array[Cell]

Sample a complete line of macroscopic cells.

#
Simulation::sample_line_csv

fn Simulation::sample_line_csv(self : Simulation, axis~ : Axis, index~ : Int, component~ : String) -> String

Export a line profile with a component name.

#
Simulation::sample_probe

fn Simulation::sample_probe(self : Simulation, probe : Probe) -> Cell

Sample one probe using nearest-cell or bilinear interpolation.

#
Simulation::set_box_walls

fn Simulation::set_box_walls(self : Simulation) -> Unit

Mark the four domain walls as solid.

#
Simulation::set_cell

fn Simulation::set_cell(self : Simulation, x~ : Int, y~ : Int, rho~ : Double, ux~ : Double, uy~ : Double) -> Unit

Reset a cell to an equilibrium state.

#
Simulation::set_poiseuille_profile

fn Simulation::set_poiseuille_profile(self : Simulation, max_ux~ : Double, rho? : Double) -> Unit

Apply a parabolic channel profile to an advanced simulation.

#
Simulation::set_pressure_outlet

fn Simulation::set_pressure_outlet(self : Simulation, x~ : Int, density~ : Double, ux? : Double, uy? : Double) -> Unit

Initialize a vertical density outlet stripe.

#
Simulation::set_solid

fn Simulation::set_solid(self : Simulation, x~ : Int, y~ : Int, solid~ : Bool) -> Unit

Set a solid flag inside the simulation.

#
Simulation::set_uniform

fn Simulation::set_uniform(self : Simulation, rho~ : Double, ux~ : Double, uy~ : Double) -> Unit

Initialize all fluid cells to the same macroscopic state.

#
Simulation::set_velocity_inlet

fn Simulation::set_velocity_inlet(self : Simulation, x~ : Int, ux~ : Double, uy~ : Double, rho? : Double) -> Unit

Initialize a vertical velocity inlet stripe.

#
Simulation::solid_count

fn Simulation::solid_count(self : Simulation) -> Int

Count solid cells in an advanced simulation.

#
Simulation::solid_values

fn Simulation::solid_values(self : Simulation) -> Array[Bool]

Copy the solid-cell mask in row-major order.

#
Simulation::speed_csv

fn Simulation::speed_csv(self : Simulation) -> String

Export velocity magnitude as a CSV grid.

#
Simulation::speed_field

fn Simulation::speed_field(self : Simulation) -> Field2D

Return a scalar field of advanced speed magnitude.

#
Simulation::stability

fn Simulation::stability(self : Simulation) -> Stability

Compute stability metrics for an advanced simulation.

#
Simulation::state_checksum

fn Simulation::state_checksum(self : Simulation) -> Double

Compute a deterministic checksum over geometry and populations.

#
Simulation::state_delta

fn Simulation::state_delta(self : Simulation, other : Simulation) -> Double

Compare two states using a normalized distribution L2 error.

#
Simulation::state_fingerprint

fn Simulation::state_fingerprint(self : Simulation) -> String

Produce a compact, deterministic identity for a simulation state.

#
Simulation::state_summary

fn Simulation::state_summary(self : Simulation) -> String

Return a human-readable state summary for logs and notebooks.

#
Simulation::step

fn Simulation::step(self : Simulation) -> Unit

Advance one collision/stream/boundary step.

#
Simulation::steps

fn Simulation::steps(self : Simulation) -> Int

Return the number of completed time steps.

#
Simulation::strain_rate_at

fn Simulation::strain_rate_at(self : Simulation, x~ : Int, y~ : Int) -> Double

Centered strain-rate tensor magnitude.

#
Simulation::strain_rate_field

fn Simulation::strain_rate_field(self : Simulation) -> Field2D

Return the strain-rate magnitude field.

#
Simulation::to_checkpoint

fn Simulation::to_checkpoint(self : Simulation) -> String

Serialize a simulation into a versioned, dependency-free text checkpoint.

#
Simulation::velocity_csv

fn Simulation::velocity_csv(self : Simulation) -> String

Export velocity components as a CSV point table.

#
Simulation::velocity_field

fn Simulation::velocity_field(self : Simulation) -> VectorField2D

Build a velocity field from the simulation state.

#
Simulation::vertical_profile

fn Simulation::vertical_profile(self : Simulation, x~ : Int) -> Array[Double]

Return a vertical velocity profile.

#
Simulation::vorticity_at

fn Simulation::vorticity_at(self : Simulation, x~ : Int, y~ : Int) -> Double

Estimate scalar vorticity with centered differences.

#
Simulation::vorticity_field

fn Simulation::vorticity_field(self : Simulation) -> Field2D

Return a row-major vorticity field.

#
SimulationOptions

pub(all) struct SimulationOptions {
model : CollisionModel
boundary : BoundaryMode
force_x : Double
force_y : Double
density_floor : Double
max_mach : Double
} derive(
Debug
)

Configuration shared by collision, streaming, and stability checks.

#
SimulationOptions::new

fn SimulationOptions::new(model~ : CollisionModel, boundary? : BoundaryMode, force_x? : Double, force_y? : Double, density_floor? : Double, max_mach? : Double) -> SimulationOptions

Build conservative solver options.

#
SimulationReport

pub(all) struct SimulationReport {
name : String
size : Size
steps : Int
mass : Double
max_speed : Double
kinetic_energy : Double
density_variation : Double
stable : Bool
health_pass : Bool
} derive(
Debug
)

Human-facing simulation report.

#
SimulationReport::to_csv

fn SimulationReport::to_csv(self : SimulationReport) -> String

Format a report as CSV.

#
SimulationReport::to_json

fn SimulationReport::to_json(self : SimulationReport) -> String

Format a report as a small JSON object.

#
SimulationReport::to_markdown

fn SimulationReport::to_markdown(self : SimulationReport) -> String

Format a report as a Markdown table row.

#
Size

pub(all) struct Size {
width : Int
height : Int
} derive(Eq,
Debug
)

Integer size of a rectangular simulation domain.

#
Size::new

fn Size::new(width~ : Int, height~ : Int) -> Size

Construct a domain size.

#
Stability

pub(all) struct Stability {
min_rho : Double
max_rho : Double
max_speed : Double
mass : Double
has_nan : Bool
recommended : Bool
} derive(
Debug
)

Runtime stability summary for a lattice.

#
StatisticsAccumulator

pub(all) struct StatisticsAccumulator {
count : Int
sum : Double
sum_squares : Double
minimum : Double
maximum : Double
} derive(
Debug
)

A small online accumulator for streaming diagnostics.

#
StatisticsAccumulator::finish

Convert a streaming accumulator into descriptive statistics.

#
StatisticsAccumulator::new

Create an empty streaming accumulator.

#
StatisticsAccumulator::push

fn StatisticsAccumulator::push(self : StatisticsAccumulator, value : Double) -> Unit

Add one value to a streaming accumulator.

#
SweepResult

pub(all) struct SweepResult {
omega : Double
steps : Int
mass : Double
max_speed : Double
stable : Bool
health_pass : Bool
} derive(
Debug
)

One parameter sweep result.

#
ValidationError

pub(all) enum ValidationError {
InvalidRelaxation(Double)
InvalidDomain(Size)
InvalidDensityFloor(Double)
InvalidMachLimit(Double)
} derive(
Debug
)

Configuration errors are explicit so callers can reject unsafe runs.

#
VectorField2D

pub(all) struct VectorField2D {
size : Size
ux : Array[Double]
uy : Array[Double]
} derive(
Debug
)

A two-component velocity field aligned with a scalar grid.

#
VectorField2D::add

Add two vector fields over their overlapping rectangle.

#
VectorField2D::blend

fn VectorField2D::blend(self : VectorField2D, other : VectorField2D, weight~ : Double) -> VectorField2D

Blend two vector fields using a clamped weight.

#
VectorField2D::clamp_speed

fn VectorField2D::clamp_speed(self : VectorField2D, maximum : Double) -> VectorField2D

Limit vector magnitude while preserving direction.

#
VectorField2D::component_sum

fn VectorField2D::component_sum(self : VectorField2D, component : String) -> Double

Sum one named component, with speed as a useful derived option.

#
VectorField2D::curl_field

fn VectorField2D::curl_field(self : VectorField2D) -> Field2D

Compute the scalar curl (vorticity) field.

#
VectorField2D::curl_l1

fn VectorField2D::curl_l1(self : VectorField2D) -> Double

L1 norm of a derived curl field.

#
VectorField2D::difference

fn VectorField2D::difference(self : VectorField2D, other : VectorField2D) -> VectorField2D

Subtract another vector field from this one.

#
VectorField2D::dimensions

fn VectorField2D::dimensions(self : VectorField2D) -> Size

Return the dimensions carried by a vector field.

#
VectorField2D::divergence_field

fn VectorField2D::divergence_field(self : VectorField2D) -> Field2D

Compute a centered finite-difference divergence field.

#
VectorField2D::divergence_l1

fn VectorField2D::divergence_l1(self : VectorField2D) -> Double

L1 norm of a derived divergence field.

#
VectorField2D::dot

fn VectorField2D::dot(self : VectorField2D, other : VectorField2D) -> Field2D

Compute the pointwise vector dot product.

#
VectorField2D::fill

fn VectorField2D::fill(self : VectorField2D, ux~ : Double, uy~ : Double) -> Unit

Fill a velocity field with a uniform vector.

#
VectorField2D::get

fn VectorField2D::get(self : VectorField2D, x : Int, y : Int) -> Point

Read a velocity with zero extension outside the grid.

#
VectorField2D::gradient_energy

fn VectorField2D::gradient_energy(self : VectorField2D) -> Double

Compute the total squared gradient of vector components.

#
VectorField2D::height

fn VectorField2D::height(self : VectorField2D) -> Int

Return the height of a vector field.

#
VectorField2D::horizontal_field

fn VectorField2D::horizontal_field(self : VectorField2D) -> Field2D

Copy the horizontal component into a scalar field.

#
VectorField2D::is_finite

fn VectorField2D::is_finite(self : VectorField2D) -> Bool

Return whether every stored component is finite.

#
VectorField2D::kinetic_energy

fn VectorField2D::kinetic_energy(self : VectorField2D) -> Double

Return the integrated kinetic energy density.

#
VectorField2D::magnitude_field

fn VectorField2D::magnitude_field(self : VectorField2D) -> Field2D

Convert a vector field to a scalar magnitude field.

#
VectorField2D::max_component

fn VectorField2D::max_component(self : VectorField2D) -> Double

Find the largest absolute component in a vector field.

#
VectorField2D::mean_square_speed

fn VectorField2D::mean_square_speed(self : VectorField2D) -> Double

Compute the mean squared magnitude of a vector field.

#
VectorField2D::momentum

fn VectorField2D::momentum(self : VectorField2D) -> Point

Integrate vector components over the grid.

#
VectorField2D::negate

Return the negative of every vector.

#
VectorField2D::new

fn VectorField2D::new(size~ : Size) -> VectorField2D

Allocate a zero velocity field.

#
VectorField2D::normalized

fn VectorField2D::normalized(self : VectorField2D) -> VectorField2D

Normalize each nonzero vector independently.

#
VectorField2D::sample

fn VectorField2D::sample(self : VectorField2D, x~ : Double, y~ : Double) -> Point

Sample both velocity components bilinearly.

#
VectorField2D::scale

fn VectorField2D::scale(self : VectorField2D, factor : Double) -> VectorField2D

Scale every vector by one factor.

#
VectorField2D::set

fn VectorField2D::set(self : VectorField2D, x~ : Int, y~ : Int, ux~ : Double, uy~ : Double) -> Unit

Set a velocity at one cell.

#
VectorField2D::size

fn VectorField2D::size(self : VectorField2D) -> Int

Return the number of stored cells in a vector field.

#
VectorField2D::speed_statistics

fn VectorField2D::speed_statistics(self : VectorField2D) -> FieldStatistics

Compute descriptive statistics for vector speed.

#
VectorField2D::to_csv

fn VectorField2D::to_csv(self : VectorField2D) -> String

Export a vector field as CSV.

#
VectorField2D::ux_field

fn VectorField2D::ux_field(self : VectorField2D) -> Array[Double]

Copy the x component of a vector field.

#
VectorField2D::uy_field

fn VectorField2D::uy_field(self : VectorField2D) -> Array[Double]

Copy the y component of a vector field.

#
VectorField2D::vertical_field

fn VectorField2D::vertical_field(self : VectorField2D) -> Field2D

Copy the vertical component into a scalar field.

#
VectorField2D::width

fn VectorField2D::width(self : VectorField2D) -> Int

Return the width of a vector field.

#
abs_double

fn abs_double(value : Double) -> Double

Return the absolute value without relying on a target-specific helper.

#
analyze_boundary_mask

fn analyze_boundary_mask(mask : DomainMask) -> BoundaryDiagnostics

Count interface faces and corner cells.

#
apply_boundary

fn apply_boundary(distribution : ArrayView[Double], spec~ : BoundarySpec) -> Array[Double]

Apply a local boundary specification.

#
apply_pressure_boundary

fn apply_pressure_boundary(distribution : ArrayView[Double], density~ : Double, ux~ : Double, uy~ : Double) -> Array[Double]

Reconstruct a pressure boundary and preserve its supplied tangential velocity.

#
apply_velocity_boundary

fn apply_velocity_boundary(distribution : ArrayView[Double], rho~ : Double, ux~ : Double, uy~ : Double) -> Array[Double]

Reconstruct a velocity boundary from its requested equilibrium moments.

#
argmax

fn argmax(values : ArrayView[Double]) -> Int?

Return the index of the first finite maximum.

#
argmin

fn argmin(values : ArrayView[Double]) -> Int?

Return the index of the first minimum.

#
audit_options

fn audit_options(options : SimulationOptions) -> ConfigAudit

Audit options before a long numerical run.

#
benchmark_statistics

fn benchmark_statistics(reports : ArrayView[BenchmarkReport]) -> BenchmarkStatistics

Compute aggregate benchmark statistics.

#
benchmark_suite_csv

fn benchmark_suite_csv(reports : ArrayView[BenchmarkReport]) -> String

Export a suite as CSV with a stable header.

#
benchmark_suite_is_usable

fn benchmark_suite_is_usable(reports : ArrayView[BenchmarkReport]) -> Bool

Return true when every report is stable and finite.

#
benchmark_suite_markdown

fn benchmark_suite_markdown(reports : ArrayView[BenchmarkReport]) -> String

Export a suite as a Markdown table.

#
best_benchmark

fn best_benchmark(reports : ArrayView[BenchmarkReport]) -> BenchmarkReport?

Return the report with the smallest L2 error.

#
best_sweep_result

fn best_sweep_result(results : ArrayView[SweepResult]) -> SweepResult?

Return the stable sweep result with the smallest maximum speed.

#
better_report

fn better_report(left : BenchmarkReport, right : BenchmarkReport) -> BenchmarkReport

Return the better of two stable reports by L2 error.

#
bounce_direction

fn bounce_direction(direction : Int) -> Int

Return the opposite direction used by a bounce-back link.

#
boundary_label_name

fn boundary_label_name(label : BoundaryLabel) -> String

Convert a label to a stable string.

#
bundle_memory_bytes

fn bundle_memory_bytes(size : Size, checkpoints? : Int) -> Int

Return an upper bound on bytes for a scalar/vector/checkpoint bundle.

#
bytes_to_mebibytes

fn bytes_to_mebibytes(bytes : Int) -> Double

Convert bytes to mebibytes.

#
central_difference

fn central_difference(values : ArrayView[Double], index~ : Int) -> Double

Central difference at an index, with one-sided edge handling.

#
clamp_double

fn clamp_double(value : Double, low~ : Double, high~ : Double) -> Double

Clamp a floating-point value to a closed interval.

#
clamp_int

fn clamp_int(value : Int, low~ : Int, high~ : Int) -> Int

Clamp an integer to a closed interval.

#
collide_distribution

fn collide_distribution(distribution : ArrayView[Double], rho~ : Double, ux~ : Double, uy~ : Double, model~ : CollisionModel) -> Array[Double]

Apply BGK, regularized, or MRT collision while preserving mass and momentum.

#
collision_model_name

fn collision_model_name(model : CollisionModel) -> String

Return a stable model name.

#
compare_reports

fn compare_reports(left : BenchmarkReport, right : BenchmarkReport) -> BenchmarkComparison

Compare the error and conservation fields of two reports.

#
cosine_similarity

fn cosine_similarity(left : ArrayView[Double], right : ArrayView[Double]) -> Double

Compute a normalized cosine similarity.

#
cumulative_distribution

fn cumulative_distribution(values : ArrayView[Double]) -> Array[Double]

Compute a normalized cumulative distribution.
let cx : Array[Int]

Lattice velocity x components for D2Q9.
let cy : Array[Int]

Lattice velocity y components for D2Q9.

#
cylinder_wake

fn cylinder_wake(width~ : Int, height~ : Int, radius? : Int, omega? : Double, inlet_velocity? : Double) -> Lattice

Build a channel with a circular obstacle for wake experiments.

#
distance_to_solid

fn distance_to_solid(mask : DomainMask) -> Field2D

Return a scalar field of solid-cell distance in four-neighbor steps.

#
distribution_cell

fn distribution_cell(distribution : ArrayView[Double]) -> Cell

Reconstruct macroscopic quantities from one distribution vector.

#
distribution_is_physical

fn distribution_is_physical(distribution : ArrayView[Double]) -> Bool

Check a distribution vector for finite and nonnegative populations.

#
distribution_length

fn distribution_length(size : Size) -> Int

Return the number of distribution values in a domain.

#
distribution_mass

fn distribution_mass(distribution : ArrayView[Double]) -> Double

Return the zeroth moment of a distribution vector.

#
distribution_momentum_x

fn distribution_momentum_x(distribution : ArrayView[Double]) -> Double

Return the x momentum of a distribution vector.

#
distribution_momentum_y

fn distribution_momentum_y(distribution : ArrayView[Double]) -> Double

Return the y momentum of a distribution vector.

#
dot_product

fn dot_product(left : ArrayView[Double], right : ArrayView[Double]) -> Double

Dot product of two numeric vectors.

#
equilibrium

fn equilibrium(d : Int, rho : Double, ux : Double, uy : Double) -> Double

D2Q9 equilibrium distribution for a direction.

#
equilibrium_distribution

fn equilibrium_distribution(rho~ : Double, ux~ : Double, uy~ : Double) -> Array[Double]

Build a D2Q9 equilibrium vector.

#
equilibrium_error

fn equilibrium_error(distribution : ArrayView[Double], rho~ : Double, ux~ : Double, uy~ : Double) -> Double

Maximum absolute deviation from equilibrium moments.

#
error_improved

fn error_improved(earlier : BenchmarkReport, later : BenchmarkReport) -> Bool

Return true when a later report has lower L2 error.

#
error_trend

fn error_trend(earlier : BenchmarkReport, later : BenchmarkReport) -> Double

Return an error trend between two reports.

#
field_blend

fn field_blend(left : Field2D, right : Field2D, weight~ : Double) -> Field2D

Blend two fields with a scalar weight.

#
field_difference

fn field_difference(left : Field2D, right : Field2D) -> Field2D

Compute a field difference.

#
field_dot

fn field_dot(left : Field2D, right : Field2D) -> Double

Compute the covariance-like dot product of two equal-sized fields.

#
field_is_nonnegative

fn field_is_nonnegative(field : Field2D, tolerance? : Double) -> Bool

Check that a field has no negative values below a tolerance.

#
field_residual

fn field_residual(left : Field2D, right : Field2D) -> Double

Compute a finite residual between two scalar fields.

#
fields_are_finite

fn fields_are_finite(density : Field2D, velocity : VectorField2D) -> Bool

Check density/velocity fields for finite values.

#
finite_fraction

fn finite_fraction(field : Field2D) -> Double

Return the fraction of finite values in a scalar field.

#
finite_or

fn finite_or(value : Double, fallback~ : Double) -> Double

Return a fallback when a value is NaN or infinite.

#
fluid_neighbor_count

fn fluid_neighbor_count(mask : DomainMask, x~ : Int, y~ : Int) -> Int

Count the number of fluid neighbors of a lattice cell.

#
force_limit_from_density

fn force_limit_from_density(density~ : Double, max_mach~ : Double) -> Double

Return a stable force magnitude bound.

#
forward_differences

fn forward_differences(values : ArrayView[Double]) -> Array[Double]

Return a forward difference vector.

#
gradient_at

fn gradient_at(field : Field2D, x~ : Int, y~ : Int) -> Point

Compute a central-difference gradient at one scalar cell.

#
histogram

fn histogram(values : ArrayView[Double], bins~ : Int, low~ : Double, high~ : Double) -> Array[Int]

Return a normalized histogram with a fixed number of bins.

#
kinematic_viscosity

fn kinematic_viscosity(model : CollisionModel) -> Double

Estimate the kinematic viscosity of a D2Q9 shear mode.

#
l2_error

fn l2_error(expected : ArrayView[Double], actual : ArrayView[Double]) -> Double

Absolute L2 error normalized by the number of samples.

#
laplacian_at

fn laplacian_at(field : Field2D, x~ : Int, y~ : Int) -> Double

Compute the scalar Laplacian at one cell.

#
lattice_sound_speed

fn lattice_sound_speed() -> Double

Estimate the lattice sound speed.

#
legacy_preset

fn legacy_preset(preset : Preset) -> Lattice?

Build the matching high-level legacy scenario.

#
lerp

fn lerp(a : Double, b : Double, t : Double) -> Double

Linear interpolation between two values.

#
lid_driven_cavity

fn lid_driven_cavity(size~ : Int, omega? : Double, lid_velocity? : Double) -> Lattice

Build a square cavity with a moving lid encoded as initial velocity near the top.

#
linf_error

fn linf_error(expected : ArrayView[Double], actual : ArrayView[Double]) -> Double

Maximum absolute error over the overlapping samples.

#
mach_number

fn mach_number(ux~ : Double, uy~ : Double) -> Double

Compute the lattice Mach number of a velocity vector.

#
mask_intersection

fn mask_intersection(left : DomainMask, right : DomainMask) -> DomainMask

Intersect two masks over their shared domain.

#
mask_union

fn mask_union(left : DomainMask, right : DomainMask) -> DomainMask

Union two masks over their shared domain.

#
max_speed

fn max_speed(velocity : VectorField2D) -> Double

Return the maximum speed in a vector field.

#
maximum_mass_drift

fn maximum_mass_drift(reports : ArrayView[BenchmarkReport]) -> Double

Return the largest mass drift in a report set.

#
mean_value

fn mean_value(values : ArrayView[Double]) -> Double

Arithmetic mean, returning zero for an empty vector.

#
memory_estimate

fn memory_estimate(size : Size) -> MemoryEstimate

Estimate payload memory without hiding allocation overhead.

#
min_max

fn min_max(values : ArrayView[Double]) -> (Double, Double)

Return the smallest and largest finite values in a vector.

#
momentum_exchange

fn momentum_exchange(direction~ : Int, population~ : Double) -> Point

Compute the local momentum exchange of a reflected population.

#
nearly_zero

fn nearly_zero(value : Double, tolerance? : Double) -> Bool

True when a value is close to zero under an absolute tolerance.

#
omega_grid

fn omega_grid(start~ : Double, end~ : Double, count~ : Int) -> Array[Double]

Create a regular relaxation grid, inclusive of its endpoints.

#
opposite

let opposite : Array[Int]

Opposite direction indices used by bounce-back boundaries.

#
periodic_coordinate

fn periodic_coordinate(value : Int, extent : Int) -> Int

Return a periodic coordinate for a lattice extent.

#
poiseuille

fn poiseuille(width~ : Int, height~ : Int, omega? : Double, force_x? : Double) -> Lattice

Build a pressure-driven channel with no-slip top and bottom walls.

#
poiseuille_reference_profile

fn poiseuille_reference_profile(height~ : Int, max_velocity~ : Double) -> Array[Double]

Build the analytical channel profile used by the Poiseuille comparison.

#
prefix_sums

fn prefix_sums(values : ArrayView[Double]) -> Array[Double]

Return cumulative sums.

#
preset_description

fn preset_description(preset : Preset) -> String

Return a compact preset description.

#
preset_name

fn preset_name(preset : Preset) -> String

Return a stable human-readable preset name.

#
preset_options

fn preset_options(preset : Preset) -> SimulationOptions

Return conservative collision settings for a preset.

#
preset_output_kind

fn preset_output_kind(preset : Preset) -> String

Return the expected output family for a preset.

#
preset_size

fn preset_size(preset : Preset) -> Size

Return default lattice dimensions for a preset.

#
preset_velocity

fn preset_velocity(preset : Preset) -> Double

Return the estimated characteristic velocity of a preset.
let q : Int

Number of directions in the D2Q9 lattice.

#
rasterize_shape

fn rasterize_shape(size~ : Size, shape~ : Shape) -> DomainMask

Rasterize a shape into a new mask.
fn recommended_steps(preset : Preset) -> Int

Return a demonstration step count.

#
regularized_stress

fn regularized_stress(distribution : ArrayView[Double], rho~ : Double, ux~ : Double, uy~ : Double) -> Array[Double]

A second-order regularized non-equilibrium stress estimate.

#
relative_l2_error

fn relative_l2_error(expected : ArrayView[Double], actual : ArrayView[Double]) -> Double

Relative L2 error with a stable zero-reference convention.

#
relaxation_from_viscosity

fn relaxation_from_viscosity(viscosity : Double) -> Double

Estimate a relaxation parameter from a target viscosity.

#
relaxation_is_stable

fn relaxation_is_stable(omega : Double) -> Bool

Return whether a relaxation value is in the open stable interval.

#
reports_are_healthy

fn reports_are_healthy(reports : ArrayView[SimulationReport]) -> Bool

Return true when every report passes its numerical health gate.

#
reports_to_markdown

fn reports_to_markdown(reports : ArrayView[SimulationReport]) -> String

Combine several reports into a Markdown table.

#
resize_vector

fn resize_vector(values : ArrayView[Double], length~ : Int, fill? : Double) -> Array[Double]

Return a vector with a fixed length and a fill value.

#
rms_value

fn rms_value(values : ArrayView[Double]) -> Double

Root-mean-square magnitude.

#
run_benchmark_suite

fn run_benchmark_suite() -> Array[BenchmarkReport]

Run the three reference cases used by the CLI and documentation.

#
run_cavity_benchmark

fn run_cavity_benchmark(size~ : Int, steps~ : Int) -> BenchmarkReport

Run a cavity benchmark against a zero-velocity interior reference.

#
run_completed

fn run_completed(summary : RunSummary, plan : RunPlan) -> Bool

Return true when a run summary reached its planned length.

#
run_cylinder_benchmark

fn run_cylinder_benchmark(width~ : Int, height~ : Int, steps~ : Int) -> BenchmarkReport

Run an obstacle-wake benchmark and report a vorticity magnitude summary.

#
run_parameter_sweep

fn run_parameter_sweep(size~ : Size, sweep~ : ParameterSweep) -> Array[SweepResult]

Execute every point in a relaxation sweep.

#
run_poiseuille_benchmark

fn run_poiseuille_benchmark(width~ : Int, height~ : Int, steps~ : Int) -> BenchmarkReport

Run a measured Poiseuille profile comparison.

#
run_resolution_study

fn run_resolution_study(resolutions~ : Array[Int], steps~ : Int) -> Array[BenchmarkReport]

Run a small resolution study for Poiseuille flow.

#
run_summary_distance

fn run_summary_distance(left : RunSummary, right : RunSummary) -> Double

Compare two run summaries by final mass and speed.

#
safe_divide

fn safe_divide(numerator : Double, denominator : Double, fallback~ : Double) -> Double

A division that returns a caller-selected value for a zero denominator.

#
safest_report

fn safest_report(reports : ArrayView[BenchmarkReport]) -> BenchmarkReport?

Return the most stable report by maximum speed.

#
sample_polyline

fn sample_polyline(field : Field2D, points : ArrayView[Point]) -> Array[Double]

Sample a scalar field along a polyline.

#
scalar_diffusion_time

fn scalar_diffusion_time(length~ : Double, diffusivity~ : Double) -> Double

Compute the scalar diffusion time for a characteristic length.

#
scalar_finite_or

fn scalar_finite_or(value : Double, fallback~ : Double) -> Double

Return a finite scalar value or a fallback for diagnostics.

#
scalar_mass_change

fn scalar_mass_change(before : ScalarSolver, after : ScalarSolver) -> Double

Return the sum of scalar changes between two solver states.

#
scalar_peclet_number

fn scalar_peclet_number(velocity~ : Double, length~ : Double, diffusivity~ : Double) -> Double

Compute the scalar Péclet number for a characteristic length.

#
scalar_state_error

fn scalar_state_error(left : ScalarSolver, right : ScalarSolver) -> Double

Difference between two scalar solver states.

#
scenario

fn scenario(kind : Scenario) -> Lattice

Build a named demo scenario with conservative default dimensions.

#
schedule_intervals

fn schedule_intervals(total_steps~ : Int, levels~ : Int) -> Array[Int]

Plan a geometrically increasing sequence of sample intervals.

#
signum

fn signum(value : Double) -> Int

Return -1, 0, or 1 according to the sign of a value.

#
simulation_report_header

fn simulation_report_header() -> String

Report CSV header.

#
size_is_allocatable

fn size_is_allocatable(size : Size) -> Bool

Return true when a domain has a safe positive allocation size.

#
smoothstep

fn smoothstep(edge0~ : Double, edge1~ : Double, value~ : Double) -> Double

Cubic smoothstep interpolation on an unclamped parameter.

#
speed_limit_from_mach

fn speed_limit_from_mach(max_mach~ : Double) -> Double

Return a conservative inlet speed bound for a Mach limit.

#
square_memory_estimate

fn square_memory_estimate(side : Int) -> MemoryEstimate

Return an upper bound on a square simulation footprint.

#
stable_benchmark_count

fn stable_benchmark_count(reports : ArrayView[BenchmarkReport]) -> Int

Return the number of stable reports in a suite.

#
stable_relaxation_range

fn stable_relaxation_range() -> (Double, Double)

Return the relaxation range that passes the ordinary BGK stability criterion.

#
sum_values

fn sum_values(values : ArrayView[Double]) -> Double

Sum a vector without changing its order.

#
sweep_results_csv

fn sweep_results_csv(results : ArrayView[SweepResult]) -> String

Serialize sweep results as CSV.

#
sweep_stability_fraction

fn sweep_stability_fraction(results : ArrayView[SweepResult]) -> Double

Return the stable fraction of a sweep.

#
trace_streamline

fn trace_streamline(velocity : VectorField2D, start~ : Point, step_size~ : Double, max_steps~ : Int) -> Array[Point]

Trace a streamline with first-order Euler integration.

#
validate_checkpoint

fn validate_checkpoint(text : String) -> Result[Unit, CheckpointError]

Validate a checkpoint without retaining the restored simulation.

#
validate_options

fn validate_options(options : SimulationOptions) -> Result[Unit, ValidationError]

Validate solver options before allocating a simulation.

#
validate_size

fn validate_size(size : Size) -> Result[Unit, ValidationError]

Validate a rectangular domain size.

#
variance_value

fn variance_value(values : ArrayView[Double]) -> Double

Population variance, returning zero for fewer than two values.

#
viscosity_from_relaxation

fn viscosity_from_relaxation(omega : Double) -> Double

Estimate the BGK viscosity for an omega value.

#
weighted_mean

fn weighted_mean(values : ArrayView[Double], weights_values : ArrayView[Double]) -> Double

Compute a weighted mean with a zero-weight fallback.

#
weights

let weights : Array[Double]

D2Q9 quadrature weights.