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

Continue a solve, start a finer mesh

This chapter shows the two ways to reuse an OpenFOAM result of the backend: continue a steady solve on the same mesh in a fresh, bounded stage, and start the next finer mesh from an accepted coarse solution. Both start new local work, and both need the unchanged final gates again. You need the runtime of chapter 15 and a checkout with the validation requirements.

A single run of the adapter is limited to 3,600 s and 20,000 iterations. Continuation lets a long steady solve progress in separately bounded, auditable stages; mapping lets a finer mesh start from a converged coarse field. Neither restores a transient time history.

Setup

Run all commands from the root of a checkout, with the runtime at runs/openfoam13/runtime/opt/openfoam13. Both sections start from the cold level-1 cavity of chapter 15:

mkdir -p runs
python integrations/openfoam_backend.py prepare --case cavity --level 1 \
  --iterations 3000 --output runs/foam-cavity-input
python integrations/openfoam_backend.py run --case runs/foam-cavity-input \
  --foam-root runs/openfoam13/runtime/opt/openfoam13 \
  --timeout-s 180 --output runs/foam-cavity

Continue on the same mesh

python integrations/openfoam_backend.py prepare-restart --source runs/foam-cavity \
  --iterations 3000 --output runs/foam-continuation-input
python integrations/openfoam_backend.py run --case runs/foam-continuation-input \
  --foam-root runs/openfoam13/runtime/opt/openfoam13 \
  --timeout-s 180 --output runs/foam-continuation

prepare-restart turns a completed archive into the input of a fresh steady stage: the source’s verified final fields and face flux become the initial state, and the case, mesh and controls stay the source’s. The new stage starts its local pseudo-time and residual history at zero. --iterations (default 6,000) is the new stage’s limit. Eligibility to continue is separate from final numerical or measurement acceptance: the continued run must pass every gate on its own.

Which sources are eligible

A source must be a complete archive (case, mesh, final fields, logs, summary, manifest and completion marker); a summary or a log alone cannot supply a restart. It is eligible when:

  • its seals verify and its execution completed with a final field; failed, timed-out and canceled runs are rejected, including any older snapshots they contain;
  • its final fields are finite, with nonnegative k and nut and positive omega;
  • it was generated by the current case generator, with the generated steady controls;
  • its stored face flux passes the auditor’s independent local gate, max abs(div(phi)) * H / U <= 1e-4.

A completed but unconverged stage can be eligible: report then exits 2, and the source is still accepted. prepare-restart exits 0 for a prepared stage and 1 otherwise, with a coded field path: CFD-X012 at initial_state.* for eligibility and receipt errors, CFD-X006 for an archive that fails verification or an invalid final field, and CFD-E062 or CFD-E063 for the output path. A failed preparation leaves no partial stage.

The flux gate is strict for early stages. It follows the last pressure solve’s relative tolerance and tightens with refinement. In the continuation record (the record gives no date) the wall-resolved simplec backstep scores 0.0048 at iteration 500 (rejected), 2.7e-9 at 6,000 and 6.6e-10 at 10,000, and a cold start scores 5.6; use stages of thousands of iterations. Whether this gate suits continuation is recorded there as an open decision.

The general form, for any completed source (SOURCE_RUN, NEW_* and ROOT are placeholders):

python integrations/openfoam_backend.py report SOURCE_RUN
python integrations/openfoam_backend.py prepare-restart --source SOURCE_RUN \
  --iterations 6000 --output NEW_INPUT
python integrations/openfoam_backend.py run --case NEW_INPUT \
  --foam-root ROOT --timeout-s 3500 --output-mib 512 --output NEW_RUN
python validation/audit_openfoam_mesh.py --run NEW_RUN --output NEW_AUDIT.json

No change of physics, mesh or solver profile is accepted; prepare an ordinary cold case for another model. The exact runtime and the rebuilt mesh must match the recorded identities before the solve.

What is carried forward

U, p and phi and, for SST, k, omega and nut are copied byte for byte from the source’s final field directory into the new 0 directory, with their boundary definitions; their headers keep the source time as location, which the receipt checks. The physics, mesh and sampling dictionaries keep their source identities. The new controls are the source’s with only endTime and writeInterval replaced.

numerical.iterations counts the new stage only; the receipt’s source_completed_iterations plus it counts solver work along the chain, not physical time. In the continuation record a laminar cavity split into 400 and 200 iterations reproduces the uninterrupted 600 to round-off (1.03e-15 m/s in U). In the SST backstep the residuals of the restarted iteration differ by about 1e-4 relative, where some turbulence-model state is not carried by the copied fields; a converged staged solve still ends within about 2e-12 in U of the single run.

The receipt in case.json and summary.json records the parent case and manifest, source acceptance and work, source metadata and controls, copied field hashes, the actual mesh, fixed inputs, runtime identity and the source flux check. They are checked before the solve and when an archive is verified. Keep the parent archives: the parent hash alone does not hold their contents. Checksums establish consistency, not authenticity.

Start a finer mesh

python integrations/openfoam_backend.py prepare-mapped --source runs/foam-cavity \
  --level 2 --iterations 3000 \
  --foam-root runs/openfoam13/runtime/opt/openfoam13 \
  --output runs/foam-finer-input

Run the prepared level-2 case like any other, into a new directory:

python integrations/openfoam_backend.py run --case runs/foam-finer-input \
  --foam-root runs/openfoam13/runtime/opt/openfoam13 \
  --timeout-s 180 --output runs/foam-finer

This is a new-mesh start, not a continuation. The source must be a cold-generated case that is numerically accepted and independently audited; a restarted or mapped source is refused. Level 1 maps to level 2 and level 2 to level 3; the case, mesh family, turbulence model and solver profile cannot change, and the source inputs must equal what the current generator writes for that recipe (with the verified measurement files for the backstep). The fine case starts at local pseudo-time zero and must earn its own numerical and measurement results; the thresholds do not change.

prepare-mapped exits 0 when the case is prepared and 1 otherwise; exit 0 says nothing about the fine flow. Checks of the source and runtime run before the output is created. A later failure leaves a directory without case.json, which cannot run, holding mapping-failure.json and the logs of the utilities that ran.

The general form for the backstep, which also audits the fine run and compares it with the measurements (placeholders as above; VERIFIED_DATA is a directory from validation/backstep_data.py):

python integrations/openfoam_backend.py prepare-mapped --source COARSE_RUN \
  --level 2 --iterations 3000 --foam-root ROOT --data VERIFIED_DATA \
  --timeout-s 600 --output-mib 1024 --output NEW_FINE_INPUT
python integrations/openfoam_backend.py run --case NEW_FINE_INPUT \
  --foam-root ROOT --timeout-s 3500 --output-mib 1024 --output NEW_FINE_RUN
python validation/audit_openfoam_mesh.py --run NEW_FINE_RUN --output NEW_AUDIT.json
python validation/compare_backstep.py --run NEW_FINE_RUN --data VERIFIED_DATA \
  --output NEW_COMPARISON

For the cavity omit --data. The accepted wall-resolved simplec level-1 backstep of chapter 18 is a valid source.

What is mapped and how it is checked

Foundation 13’s mapFields -consistent -mapMethod mapNearest runs on checked copies of the source and of the generated target case. Only the mapped internal U and p and, for SST, k, omega and nut enter the fine case. The target’s boundary conditions, dimensions and controls are written by the generator and kept byte for byte; the mapper’s boundary values are discarded. Field counts, finite values and turbulence signs are checked. Nearest-cell initialization is not conservative interpolation and makes no accuracy claim.

There is no fine 0/phi: a coarse face flux means nothing on another mesh. The solver builds phi from the new U and corrects it as usual.

case.json carries a mesh_initialization receipt (cfd-craft.mesh-initialization/0.2), and the consumed inputs include mapping_evidence/: the checked source copy, the generated target templates, the mapper’s output and mesh, and the utility logs and arguments. Before every solve and when an archive is verified, the adapter:

  • checks the source chain: manifest, summary, case record, audit, field identities and snapshot times, acceptance, work and runtime;
  • checks that the utilities ran in order on this case’s own copies, with the recorded source time, -consistent and mapNearest, and that the mapper’s log names Foundation 13, the method and every field;
  • replays the mapping with its own mesh reader: each consumed internal value must equal the value of the source cell whose center is nearest to the target cell’s center;
  • rebuilds each consumed field from its stored template and the mapper output, and compares the controls with the generator.

A mapped run can later be continued with prepare-restart under the unchanged flux gate. Its parent identity binds the mapping history; the coarse work is recorded as source_iterations and not counted as fine-grid work.

Budgets

Preparation of a mapped case defaults to 300 s, 512 MiB of output and a 2,048 MiB child address space (--timeout-s, --output-mib, --memory-mib); the limits are 3,600 s, 2,048 MiB and 8,192 MiB. The mapping evidence counts toward the output and is copied into the run, so a mapped run needs more output room than a cold one: validation/mapped_start.py gives both level-2 runs 1,024 MiB.

A run that stops at its iteration limit writes a final field only when the limit is a multiple of the write cadence. Preparation therefore uses the largest divisor of the limit up to 250 as the cadence and rejects limits without a divisor between 50 and 250. Multiples of 50 are always accepted.

Four operations compared

OperationMeaningNew final gates required?
Native checkpoint (chapter 8)Compatible discrete state and cumulative budgets, same grid and physicsYes
External steady restart (prepare-restart)Fresh steady stage, same mesh, physics and runtimeYes
External mapNearest (prepare-mapped)Fresh target mesh, mapped volume initial guessYes
Refinement campaign (chapter 19)Bounded composition with complete provenanceYes

In the mapping record (the record gives no date) a mapped and a cold level-2 cavity converged to the same fields (5.1e-9 in U) and passed every declared check. Two accepted meshes allow an observable comparison, not a claim of mesh independence or a GCI.

Check the tools themselves

python validation/restart_equivalence.py --case backstep --solver-profile simple \
  --first 250 --second 250 --timeout-s 600 --data VERIFIED_DATA \
  --foam-root ROOT --output NEW_EQUIVALENCE
python validation/compare_restart.py --run NEW_RUN --control CONTROL_RUN \
  --mode fixed-work --output NEW_COMPARISON
python validation/mapping_equivalence.py --foam-root ROOT --timeout-s 120 \
  --output NEW_CAVITY_EXPERIMENT
python validation/mapped_start.py --source COARSE_RUN --iterations 3000 \
  --timeout-s 3500 --data VERIFIED_DATA --foam-root ROOT --output NEW_REPORT
CFD_OPENFOAM_ROOT=ROOT python validation/test_restart.py -v
CFD_OPENFOAM_ROOT=ROOT python validation/test_mapping.py -v
  • restart_equivalence.py (shown with the fixed-work check the external-backend job runs) runs FIRST iterations, continues them for SECOND, runs FIRST + SECOND uninterrupted, and compares the two final fields.
  • compare_restart.py compares any continued run with a control: --mode fixed-work for equal work (both final face fluxes must also pass the local continuity gate) and --mode converged for two converged runs, including their work, audits and measurement metrics. Invalid input is CFD-X013 at comparison.*.
  • mapping_equivalence.py compares a converged mapped level-2 cavity with a cold one, with bounds declared before the runs; it exits 0 when they hold, 2 for unaccepted runs and 1 for an input, workflow or archive error.
  • mapped_start.py runs a mapped and a cold start of the next level with equal limits and reports both; it applies no gate.
  • The tests run without a runtime; with CFD_OPENFOAM_ROOT they add real cavity continuations and mappings, and map synthetic SST fields between the real level-1 and level-2 backstep meshes (a utility check, not a turbulent solve). Run each normally and under -O.

The continuation record and the mapping record keep software equivalence, nonlinear convergence, measurement screening and physical qualification apart.

Next

  • Chapter 18: audit a wall-resolved backstep and continue it in bounded stages.
  • Chapter 19: map once and continue on the fine mesh until the gates pass or the budget ends.