Skip to content

Commit 1965f97

Browse files
authored
Share the global-parameters core across executables; generate MPI broadcasts; build hygiene (#1552)
1 parent bbdf806 commit 1965f97

21 files changed

Lines changed: 2150 additions & 2049 deletions

.claude/rules/common-pitfalls.md

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ covered in `docs/documentation/contributing.md`.
1414
bubbles and IB. Read that routine for the current value rather than assuming one.
1515
- Riemann solvers: left state at `j`, right state at `j+1`.
1616
- All equation indices live in the `eqn_idx` struct (`eqn_idx_info` in
17-
`m_derived_types.fpp`, populated in `m_global_parameters.fpp`): `%cont`, `%mom`, `%E`,
17+
`m_derived_types.fpp`, populated by `s_initialize_eqn_idx` in `m_global_parameters_common.fpp`): `%cont`, `%mom`, `%E`,
1818
`%adv`, plus optional ranges (`%bub`, `%stress`, `%species`, `%B`, ...). The old
1919
`contxb`/`momxb` shorthands are gone. Index positions depend on `model_eqns` and
2020
enabled features — changing either moves ALL indices; never hard-code one.
@@ -42,21 +42,33 @@ covered in `docs/documentation/contributing.md`.
4242
- Adding one: `_r()` definition + `_nv()` `NAMELIST_VARS` registration in
4343
`toolchain/mfc/params/definitions.py`; `case_validator.py` only if physics-constrained
4444
(with a `PHYSICS_DOCS` entry). Fortran declarations and namelist bindings are
45-
auto-generated at CMake configure time — re-run cmake (or `./mfc.sh build`) after editing.
45+
auto-generated at build time (ninja-tracked custom command) — re-run cmake (or `./mfc.sh build`) after editing.
4646
- Still manual: derived-type `TYPE` member definitions in `src/common/m_derived_types.fpp`;
4747
default-value assignments in `s_assign_default_values_to_user_inputs`; the
4848
`CASE_OPT_EXTRA_LINES` literal in `toolchain/mfc/params/generators/fortran_gen.py` (covers `num_dims`,
4949
`num_vels`, `weno_polyn`, `muscl_polyn`, `weno_num_stencils`, `wenojs`);
5050
multi-variable declaration lines (`bc_x/y/z`, `x/y/z_domain`, `x/y/z_output`, post's
51-
`G`); and MPI broadcast lists in `m_mpi_proxy`. Everything else — scalar declarations,
52-
plain arrays (`FORTRAN_ARRAY_DIMS` table in `definitions.py`), derived-type namelist
53-
declarations including `GPU_DECLARE` lines and Doxygen descs (`TYPED_DECLS` table in
54-
`definitions.py`), and the simulation case-optimization declaration block — is
55-
auto-generated at CMake configure time.
56-
Gotcha: after editing a generator or table, force regen via `cmake_gen.py` into
57-
`build/staging/*/` or simply reconfigure (`./mfc.sh build`) — cached builds compile
58-
stale includes. Under `--case-optimization` the baked-in constants are dropped from the
51+
`G`); and the MPI broadcast residue in `m_mpi_proxy` (computed variables that are not
52+
namelist-bound: `m_glb`/`n_glb`/`p_glb`, `cfl_dt`, `bc_io`, and complex struct-member
53+
array loops — these cannot be auto-generated and stay hand-listed). Everything else — scalar declarations, plain arrays (`FORTRAN_ARRAY_DIMS`
54+
table in `definitions.py`), derived-type namelist declarations including `GPU_DECLARE`
55+
lines and Doxygen descs (`TYPED_DECLS` table in `definitions.py`), the simulation
56+
case-optimization declaration block, and the per-target MPI broadcast lists for all
57+
namelist-registry scalars (`generated_bcast.fpp`) — is regenerated at build time by a
58+
ninja-tracked custom command (editing `params/*.py` triggers regeneration automatically).
59+
Gotcha: ADDING a new file under `toolchain/mfc/params/` needs one reconfigure
60+
(the custom command's DEPENDS list is globbed at configure time). Under `--case-optimization` the baked-in constants are dropped from the
5961
namelist, so changing one needs a *rebuild*, not a case edit.
62+
- Shared-state pattern: namelist declarations (`#:include 'generated_decls.fpp'`), the
63+
`eqn_idx`/`sys_size`/`b_size`/`tensor_size` state variables, and the common defaults
64+
core all live in `src/common/m_global_parameters_common.fpp`. Each per-target
65+
`m_global_parameters.fpp` does `use m_global_parameters_common` (default-public), so
66+
`use m_global_parameters` continues to work for all downstream modules without change.
67+
Sim-only declarations (GPU_DECLARE, Re_idx allocation) stay in
68+
`m_global_parameters_common` behind `#ifdef MFC_SIMULATION`. Generated includes
69+
(`generated_decls.fpp`, `generated_bcast.fpp`, `generated_case_opt_decls.fpp`) must exist for every target — the build
70+
emits stubs where the content is sim-only, so a common file that includes one will
71+
compile for pre/post too.
6072
- Runtime checks (`@:PROHIBIT`) go where they run: shared →
6173
`src/common/m_checker_common.fpp`; simulation-only → `src/simulation/m_checker.fpp`;
6274
pre/post-only → `src/{pre,post}_process/m_checker.fpp` (their `s_check_inputs` are

0 commit comments

Comments
 (0)