Development
conda env create -f environment.yml && conda activate csdl-dafoam # full stack
# or, for everything except DAFoam itself:
pip install -r requirements-lab.txt && pip install -e ".[geometry,opt,test,docs]"
pytest
Test strategy
DAFoam cannot run in ordinary CI, but what this package contributes is wiring: which arrays go to which DAFoam call, which transpose is applied, which seed multiplies what. Wiring errors give plausible-looking numbers and wrong gradients, so the tests are built to make the right answer known exactly.
tests/fakes.py provides stand-ins for DAFoam, IDWarp and PETSc with linear physics:
flow residual
R(w; x, v, p, T) = A w - (Bx x + Bv v + Bp p + BT T)and functionsF = c.w + d.x + e.v, so the states, function values and every total derivative are available in closed form;an identity or random linear mesh warp.
Test module |
What it establishes |
|---|---|
|
primal, and reverse-mode totals through the implicit operation, match the closed form for both the fixed-point and Krylov adjoints; DAFoam calls run in the case directory; failure policies |
|
the Fortran-IDWarp wrapper: warp and its adjoint (the Jacobian equals the warp matrix) |
|
real IDWarp-JAX on the real bundled mesh: wall follows the prescribed surface, no inverted cells (signed cell volumes), VJP vs finite differences, decomposed-mesh point matching, seed accumulation across ranks |
|
input mapping, Mach-to-airspeed, unsupported types, force scaling |
|
ISA (with the 300 K sea-level reference) and Sutherland formulas |
|
real |
|
the whole |
|
the example scripts, end to end, on the fake solver, for each warper/optimizer combination |
|
bundled data integrity, safe case copying (never deletes a directory it did not create) |
|
importable without the heavy stack; helpful errors; the doctor |
|
real OpenFOAM v2506: IDWarp-JAX meshes through |
|
the flow-solution reader on a real 4-rank DAFoam snapshot of the coarse mesh (100 KB) (reassembly on the global mesh, deformed points, ordering of the surface distribution) and on synthetic serial fields; plots and the VTK export |
|
the bundled 336-cell mesh equals what |
|
static guards on the build and VM scripts: no host mounts (an earlier version exposed the home directory), provisioning present, same package list as the prerequisites script, every download checksummed, pinned sources, stage order |
|
real DAFoam: sane CL/CD, adjoint vs finite differences. Marked |
The first run of a test that “passes” is worth a mutation check: while writing test_solver.py, flipping the sign of
the residual Jacobian-vector product and dropping the adjoint hand-back were both caught.
Run the real-DAFoam tests inside an environment where DAFoam works (the VM, see Installing on an Apple-silicon Mac). They use the 336-cell test mesh by default,
so they take seconds; CSDL_DAFOAM_TEST_CASE=naca0012_euler uses the 4,032-cell mesh of the examples:
pytest -m dafoam
mpirun -np 4 python -m pytest -m dafoam -p no:cacheprovider
The whole suite takes about a minute and a half; -m "not slow" takes about 25 seconds. For a quick loop, pytest -m "not slow" skips the handful of tests that take several seconds each
(the example scripts and finite-difference checks); CI runs everything.
Continuous integration
.github/workflows/tests.yml: pure-pip job (no DAFoam) running the suite on Python 3.9 and 3.12, a wheel check, a docs build, and static checks of the recipes..github/workflows/pages.yml: builds the docs (warnings are errors) and publishes them to GitHub Pages on every push tomainthat touchesdocs/,src/orpyproject.toml..github/workflows/conda-release.yml: buildsrecipe/recipe.yamlon a release and publishescsdl_dafoam..github/workflows/conda-stack.yml: manual dispatch that buildsrecipes/*in dependency order and, withpublish: true, uploads them to thelsdolabchannel. A full run is several hours.
Docs
pip install -e ".[docs]"
sphinx-build -b html -W --keep-going docs docs/_build/html # then open docs/_build/html/index.html
The API reference is generated by sphinx-autoapi from the source without importing it, so the docs build with none of the heavy stack installed.
The site is published at https://lsdolab.github.io/csdl_dafoam/ by pages.yml; someone with admin rights must set Settings, Pages, Source:
“GitHub Actions” once.
The videos live in docs/_static/ (optimization.mp4 for the docs, optimization.gif for the README, which GitHub cannot play as a video).
To regenerate them, and the figures in docs/images/, run examples/airfoil_optimization.py --maxiter 100 on a DAFoam machine (about 37 minutes) and
copy history.png, movie.gif, movie.mp4 from the working directory.
Releasing
bump
__version__insrc/csdl_dafoam/__init__.pyandcontext.versioninrecipe/recipe.yaml;pytest(andpytest -m dafoamin the conda environment);publish a GitHub release;
conda-release.ymlbuilds and uploads the package.