11# Parameter System
22
33## Overview
4- MFC has ~ 3,400 simulation parameters defined in Python and read by Fortran via namelist files.
4+ MFC's simulation parameters are defined in Python and read by Fortran via namelist files.
55
66## Parameter Flow: Python → Fortran
77
@@ -23,20 +23,25 @@ MFC has ~3,400 simulation parameters defined in Python and read by Fortran via n
2323 - Reads ` &user_inputs ` namelist
2424 - Each parameter must be declared in the namelist statement
2525
26- ## Adding a New Parameter (4 -location checklist)
26+ ## Adding a New Parameter (2 -location checklist)
2727
28- YOU MUST update the first 3 locations. Missing any causes silent failures or compile errors.
29- Location 4 is required only if the parameter has physics constraints .
28+ Fortran declarations and namelist bindings are now auto-generated from definitions.py
29+ at CMake configure time — no manual Fortran edits needed for simple scalar parameters .
3030
31- 1 . ** ` toolchain/mfc/params/definitions.py ` ** : Add parameter with type, default, constraints
32- 2 . ** ` src/*/m_global_parameters.fpp ` ** : Declare the Fortran variable in the relevant
33- target(s). If the param is used by simulation only, add it there. If shared, add to
34- all three targets' m_global_parameters.fpp.
35- 3 . ** ` src/*/m_start_up.fpp ` ** : Add to the Fortran ` namelist ` declaration in the relevant
36- target(s).
37- 4 . ** ` toolchain/mfc/case_validator.py ` ** : Add validation rules if the parameter has
31+ 1 . ** ` toolchain/mfc/params/definitions.py ` ** : Add parameter with ` _r() ` (type, default,
32+ constraints) AND add it to ` NAMELIST_VARS ` via ` _nv() ` for the relevant target(s).
33+ After editing, re-run cmake (or ` ./mfc.sh build ` ) to regenerate the Fortran includes.
34+ 2 . ** ` toolchain/mfc/case_validator.py ` ** : Add validation rules if the parameter has
3835 physics constraints. Include ` PHYSICS_DOCS ` entry with title, category, explanation.
3936
37+ ** Exceptions — still require manual Fortran edits:**
38+ - Array variables (e.g. ` logical, dimension(num_fluids_max) ` ) → declare in ` src/*/m_global_parameters.fpp `
39+ - Derived-type members (` fluid_pp%attr ` , ` patch_icpp(i)%attr ` ) → declare in the relevant derived type
40+ - Case-optimization parameters → add to ` CASE_OPT_PARAMS ` and the ` #:else ` block in ` src/simulation/m_global_parameters.fpp ` .
41+ Gotcha: under ` --case-optimization ` these are baked into the binary and dropped from the simulation namelist
42+ (` case_dicts.py ` filters them), so changing one needs a * rebuild* , not just a case edit — and building without
43+ the flag makes them read from ` .inp ` again.
44+
4045## Case Files
4146- Case files are Python scripts (` .py ` ) that define a dict of parameters
4247- Validated with ` ./mfc.sh validate case.py `
@@ -45,15 +50,24 @@ Location 4 is required only if the parameter has physics constraints.
4550- Search parameters with ` ./mfc.sh params <query> `
4651
4752## Fortran-Side Runtime Validation
48- Each target has ` m_checker*.fpp ` files (e.g., ` src/simulation/m_checker.fpp ` ,
49- ` src/common/m_checker_common.fpp ` ) containing runtime parameter validation using
50- ` @:PROHIBIT(condition, message) ` . When adding parameters with physics constraints,
51- add Fortran-side checks here in addition to ` case_validator.py ` .
53+ Runtime parameter validation uses ` @:PROHIBIT(condition, message) ` . Put a check where it runs:
54+ - ** Shared across all three targets** → ` src/common/m_checker_common.fpp ` (` s_check_inputs_common ` ,
55+ with ` #ifndef MFC_* ` gates for target-specific exclusions). This holds most checks.
56+ - ** Simulation-only** → ` src/simulation/m_checker.fpp ` (WENO/MUSCL/IGR/time-stepping/compiler checks).
57+ - ** Pre/post-only** → ` src/{pre,post}_process/m_checker.fpp ` . Note: their ` s_check_inputs ` are
58+ currently empty — that's the right place for a pre/post-only constraint, not ` m_checker_common.fpp ` .
59+
60+ Add Fortran-side checks in addition to ` case_validator.py ` .
5261
5362## Analytical Initial Conditions
5463String expressions in parameters become Fortran code via ` case.py.__get_analytic_ic_fpp() ` .
5564These are compiled into the binary, so syntax errors cause build failures, not runtime errors.
5665
66+ Gotcha: each IC variable (` alpha_rho ` , ` vel ` , ` pres ` , ` alpha ` , ` Y ` , ` Bx ` ...) maps to an ` eqn_idx%… `
67+ expression in ` QPVF_IDX_VARS ` (` case.py ` ). Adding a conserved variable that patches can set means
68+ updating that map * and* the Fortran ` eqn_idx ` builder to agree — a mismatch is a silent wrong-index, not
69+ an error. (This is also why ` Bx ` /` By ` /` Bz ` use ` eqn_idx%B%end-1/%end ` , to stay valid in 1D/2D.)
70+
5771Available variables in analytical IC expressions:
5872- ` x ` , ` y ` , ` z ` — cell-center coordinates (mapped to ` x_cc(i) ` , ` y_cc(j) ` , ` z_cc(k) ` )
5973- ` xc ` , ` yc ` , ` zc ` — patch centroid coordinates
0 commit comments