Skip to content

Commit 8d781a0

Browse files
sbryngelsonclaude
andcommitted
Auto-generate physics_constraints.md from PHYSICS_DOCS metadata
Replace the hand-written physics constraints page with an auto-generated one that merges PHYSICS_DOCS entries (math, explanations, references) with AST-extracted validation rules (stages, severity, messages). This prevents the documentation from going stale when check methods are added or modified. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2e10911 commit 8d781a0

9 files changed

Lines changed: 458 additions & 347 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ docs/*/result*
4444
docs/documentation/*-example.png
4545
docs/documentation/examples.md
4646
docs/documentation/case_constraints.md
47+
docs/documentation/physics_constraints.md
4748

4849
examples/*batch/*/
4950
examples/**/D/*

CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,17 @@ if (MFC_DOCUMENTATION)
673673
VERBATIM
674674
)
675675

676+
# Generate physics_constraints.md from PHYSICS_DOCS + AST-extracted rules
677+
add_custom_command(
678+
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/docs/documentation/physics_constraints.md"
679+
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/toolchain/mfc/gen_physics_docs.py"
680+
"${CMAKE_CURRENT_SOURCE_DIR}/toolchain/mfc/case_validator.py"
681+
COMMAND "bash" "${CMAKE_CURRENT_SOURCE_DIR}/docs/gen_constraints.sh"
682+
"${CMAKE_CURRENT_SOURCE_DIR}"
683+
COMMENT "Generating physics_constraints.md"
684+
VERBATIM
685+
)
686+
676687
# Generate cli-reference.md from cli/commands.py
677688
add_custom_command(
678689
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/docs/documentation/cli-reference.md"
@@ -732,11 +743,13 @@ if (MFC_DOCUMENTATION)
732743

733744
set(opt_example_dependency "")
734745
set(opt_constraints_dependency "")
746+
set(opt_physics_dependency "")
735747
set(opt_cli_reference_dependency "")
736748
set(opt_parameters_dependency "")
737749
if (${target} STREQUAL documentation)
738750
set(opt_example_dependency "${CMAKE_CURRENT_SOURCE_DIR}/docs/documentation/examples.md")
739751
set(opt_constraints_dependency "${CMAKE_CURRENT_SOURCE_DIR}/docs/documentation/case_constraints.md")
752+
set(opt_physics_dependency "${CMAKE_CURRENT_SOURCE_DIR}/docs/documentation/physics_constraints.md")
740753
set(opt_cli_reference_dependency "${CMAKE_CURRENT_SOURCE_DIR}/docs/documentation/cli-reference.md")
741754
set(opt_parameters_dependency "${CMAKE_CURRENT_SOURCE_DIR}/docs/documentation/parameters.md")
742755
endif()
@@ -749,6 +762,7 @@ if (MFC_DOCUMENTATION)
749762
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${target}-Doxyfile"
750763
"${opt_example_dependency}"
751764
"${opt_constraints_dependency}"
765+
"${opt_physics_dependency}"
752766
"${opt_cli_reference_dependency}"
753767
"${opt_parameters_dependency}"
754768
"${${target}_SRCs}" "${${target}_DOCs}"

docs/documentation/contributing.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ def check_my_feature(self):
274274
self.errors.append("my_param requires other_param to be set")
275275
```
276276

277+
If your check enforces a physics constraint, also add a `PHYSICS_DOCS` entry (see [How to Document Physics Constraints](#how-to-document-physics-constraints) below).
278+
277279
**Step 5: Declare in Fortran** (`src/<target>/m_global_parameters.fpp`)
278280

279281
Add the variable declaration in the appropriate target's global parameters module. Choose the target(s) where the parameter is used:
@@ -659,6 +661,41 @@ Checklist:
659661

660662
See @ref troubleshooting for debugging workflows, profiling tools, GPU diagnostic environment variables, common build/runtime errors, and fixes.
661663

664+
### How to Document Physics Constraints {#how-to-document-physics-constraints}
665+
666+
When adding a new `check_` method to `case_validator.py`, document its physics by adding an entry to the `PHYSICS_DOCS` dict at the top of the file:
667+
668+
```python
669+
PHYSICS_DOCS = {
670+
...
671+
"check_my_feature": {
672+
"title": "My Feature Constraint", # Required: human-readable title
673+
"category": "Thermodynamic Constraints", # Required: groups the constraint in docs
674+
"explanation": "Why this constraint exists.", # Required: plain English
675+
"math": r"\alpha > 0", # Optional: LaTeX formula
676+
"references": ["Wilfong26"], # Optional: BibTeX keys from references.bib
677+
"exceptions": ["IBM cases"], # Optional: when constraint doesn't apply
678+
},
679+
}
680+
```
681+
682+
The @ref physics_constraints "Physics Constraints" page is **auto-generated** — run `./mfc.sh generate` to rebuild it.
683+
The generator merges your `PHYSICS_DOCS` entry with the AST-extracted `prohibit()`/`warn()` calls,
684+
so stage, severity, and parameter information appear automatically.
685+
686+
**Fields:**
687+
688+
| Field | Required | Description |
689+
|-------|----------|-------------|
690+
| `title` | Yes | Section heading in generated docs |
691+
| `category` | Yes | Grouping category (e.g., "Mixture Constraints") |
692+
| `explanation` | Yes | Plain English description of the physics |
693+
| `math` | No | LaTeX formula (rendered by Doxygen's MathJax) |
694+
| `references` | No | List of BibTeX cite keys from `docs/references.bib` |
695+
| `exceptions` | No | List of cases where the constraint doesn't apply |
696+
697+
**Categories:** Thermodynamic Constraints, Mixture Constraints, Domain and Geometry, Velocity and Dimensional Consistency, Model Equations, Boundary Conditions, Bubble Physics, Feature Compatibility, Numerical Schemes, Acoustic Sources, Post-Processing.
698+
662699
## Testing
663700

664701
MFC has 500+ regression tests. See @ref testing for the full guide.

0 commit comments

Comments
 (0)