Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Native solver and OpenFOAM on the lid-driven cavity: measured cost

Both backends solve the supported Re=100 lid-driven cavity on the same machine, one solver thread each, on two hosts. The first host ran an earlier script of the same procedure; the second, a GitHub runner, ran validation/compare_backends.py with the current repository. This compares configured, accepted workflows; it is not a fixed operation count or a ranking of Rust against C++.

Result

On this case OpenFOAM is faster and closer to the Ghia reference. Native steady mode costs about half as much as the native transient run to 30 s, but OpenFOAM’s whole workflow is still 4.7–5.5 times faster than native steady mode on the two hosts, and its solver process about 9 times faster than the native steady solver.

First host: AMD EPYC 9V74 virtual machine, Linux x86_64, Python 3.12. One warmup per method, then the six orders of the three methods once each.

ConfigurationWorkflow median (range), sSolver median, sSteps or iterationsCellsMaximum centerline u error / lid speed
OpenFOAM steady SIMPLE/GAMG1.2622 (1.2091–1.5991)0.77646965760.00896632
Native steady6.9443 (6.8714–7.0333)6.9060201011520.02756134
Native transient to 30 s13.9984 (13.7937–14.0767)13.9303409311520.02754881
Native / OpenFOAMWorkflow, ratio of mediansWorkflow, median within roundsSolver, ratio of medians
Native steady5.5025.4558.895
Native transient11.09010.98917.942

GitHub runner: AMD EPYC 9V45, 4 CPUs, ubuntu-24.04, Python 3.12, workflow run 41195406078. One warmup per method, then the six orders twice (12 rounds).

ConfigurationWorkflow median (range), sSolver median, sSteps or iterationsCellsMaximum centerline u error / lid speed
OpenFOAM steady SIMPLE/GAMG0.89909 (0.89281–1.0084)0.472096965760.00896632
Native steady4.2183 (4.1309–4.3696)4.1921201011520.0275613
Native transient to 30 s8.7101 (8.4174–8.8005)8.6833409311520.0275488
Native / OpenFOAMWorkflow, ratio of mediansWorkflow, median within roundsSolver, ratio of medians
Native steady4.6924.6758.88
Native transient9.6889.54918.39

The solver ratios agree closely between the hosts (8.9 and 8.9 for steady, 17.9 and 18.4 for transient). The workflow ratios differ more (5.5 and 4.7), because OpenFOAM’s fixed workflow overhead, about 0.4–0.5 s, is a larger share of its shorter workflow.

All runs on both hosts passed their numerical checks, their independent audits and the frozen 0.06 Ghia screen, and each method repeated its work count and sampled profile exactly in every round. The first host’s native build has a different source identity from the current repository, but its native fields are byte-identical to those of the current build (checked separately on a third machine), so both hosts measure the same native numerics.

What is held fixed and what differs

Both solve a unit square cavity with lid speed 1 m/s, viscosity 0.01 m²/s (Re=100), zero initial velocity and 24×24 cells in the flow plane. The native case is x/z with two periodic span cells (24×2×24, 1152 cells), because native validation then rejected a one-cell axis (periodic axes accept one cell since performance iteration 6; compare_backends.py --grid-sweep --native-span 1); OpenFOAM uses one empty span cell (24×24×1, 576 cells, 0.1 m deep). Both are nominally two-dimensional, but the native solver computes both span layers.

OpenFOAMNative steadyNative transient
Casegenerated cavity recipe, unchangedcases/verification/lid-cavity.json, one thread, run.mode = steadythe same case, one thread
Algorithmsteady SIMPLE (consistent), GAMG pressure, bounded linear-upwind momentumexplicit SSPRK2 pseudo-time steps with two pressure projections per step (PCG with IC(0)), donor-cell momentumthe same steps, in physical time
Stopping1e-7 initial residuals plus independent stored-flux checksthe existing momentum and monitor gates (momentum residual 8.85e-6 at 2010 steps, pseudo-time 14.81 s)the end time of 30 s (momentum residual 3.88e-10)
Ghia error0.00900.02760.0275

The residual definitions of the two backends are not interchangeable. The Ghia profile is a numerical reference, not an experiment, and the error is one sampled velocity component, not a full-field assessment.

Where the time goes

Per cell and step, native costs about 1.5 times as much as OpenFOAM per cell and SIMPLE iteration on both hosts. Most of the factor of about 9 comes from how many steps the native method needs and from its second span layer:

Solver timeFirst hostGitHub runner
OpenFOAM, per SIMPLE iteration1.12 ms0.68 ms
Native steady, per step3.44 ms2.09 ms
OpenFOAM, per cell and iteration1.94 µs1.18 µs
Native steady, per cell and step2.98 µs1.81 µs

Native steady takes 2.9 times as many steps as OpenFOAM takes SIMPLE iterations, on twice the cells, and each native step runs about 102 PCG iterations in its two projections (204,850 over 2010 steps). The OpenFOAM time includes process start-up and file input and output, so its per-iteration cost is overstated here. This decomposition explains the measured numbers on this case; it is not a measured attribution of what a different algorithm would save.

Timing definitions

  • Workflow time encloses case preparation, the solve, the independent audit and the centerline evaluation. For OpenFOAM that includes copying the case, the runtime check (which hashes the runtime’s binaries and libraries), blockMesh, checkMesh, foamRun, sampling and archive verification, each child polled every 50 ms. For native it includes writing the case, the CLI run and its output, check_fields.py and reading the fields. Installation and compilation are excluded.
  • Solver time is the foamRun process for OpenFOAM and the native solver’s own timer (elapsed_s, without process start) for native. The two are similar in scope but not identical.
  • One unscored warmup per method precedes the timed rounds; every order of the three methods is used, so each method runs first, second and last equally often. The runs are serial with one solver thread and BLAS and OpenMP limited to one thread. No CPU frequency pinning or host isolation was established.

Consequences

  1. There is no measured native speed advantage over OpenFOAM on this shared case. The native performance results compare the native solver with its own previous version, not with OpenFOAM.
  2. The native cost is dominated by the number of explicit pseudo-time steps and by the pressure solve in each. A steady algorithm and a multigrid pressure solver or preconditioner are the natural next native experiments; this comparison does not measure what they would save.
  3. Ranking the backends for the urban canyon needs the same 3D canyon with compatible physical assumptions, accepted fields, cost at comparable observable error and complete campaigns. The backstep and native canyon results solve different problems and cannot supply that ranking.
  4. Large-case scaling and memory are not measured head to head. OpenFOAM supports MPI domain decomposition, but the CFD-craft adapter runs it serially; the native solver uses shared-memory threads on uniform grids. Nothing about multi-core speedups follows from these single-thread runs.

Reproduce

With the pinned runtime installed as in guide chapter 15 and a release build:

cargo build --release --locked
python validation/compare_backends.py --foam-root ROOT --output runs/backend-comparison

--repeats N runs the six orders N times (default 1). A manual CI dispatch with external=comparison runs two passes on a GitHub runner, publishes the medians and ratios as notices and uploads the report. Exit 0 means every run passed and the comparison completed; any failed run, changed input or unrepeated result exits 1 with a coded CFD-B002 comparison.<field> error.