diff --git a/toolchain/mfc/params/definitions.py b/toolchain/mfc/params/definitions.py index 18f107df74..e41acff235 100644 --- a/toolchain/mfc/params/definitions.py +++ b/toolchain/mfc/params/definitions.py @@ -13,22 +13,28 @@ from .schema import ParamDef, ParamType # Index limits — sourced from Fortran compile-time constants (m_constants.fpp). -# These must stay in sync with Fortran; we error if the source can't be parsed. +# Falls back to the inline default when src/ is unavailable (e.g. Homebrew). +# Default must match src/common/m_constants.fpp — enforced by co-location. _FC = get_fortran_constants() -def _fc(name: str) -> int: - """Get a required Fortran constant, raising if unavailable.""" - if name not in _FC: - raise RuntimeError(f"Fortran constant '{name}' not found in m_constants.fpp. Toolchain is out of sync with Fortran source.") - return _FC[name] +def _fc(name: str, default: int) -> int: + """Get a Fortran constant, using the inline default when m_constants.fpp is unavailable.""" + if _FC: + if name not in _FC: + raise RuntimeError( + f"Fortran constant '{name}' not found in m_constants.fpp. " + f"Toolchain is out of sync with Fortran source." + ) + return _FC[name] + return default -NF = _fc("num_fluids_max") # fluid_pp -NPR = _fc("num_probes_max") # probe, acoustic, integral -NB = _fc("num_bc_patches_max") # patch_bc -NUM_PATCHES_MAX = _fc("num_patches_max") # patch_icpp (Fortran array bound) -NIB = _fc("num_ib_patches_max") # patch_ib (Fortran array bound) +NF = _fc("num_fluids_max", 10) # fluid_pp +NPR = _fc("num_probes_max", 10) # probe, acoustic, integral +NB = _fc("num_bc_patches_max", 10) # patch_bc +NUM_PATCHES_MAX = _fc("num_patches_max", 10) # patch_icpp (Fortran array bound) +NIB = _fc("num_ib_patches_max", 50000) # patch_ib (Fortran array bound) # Enumeration limits for families not yet converted to IndexedFamily. # These are smaller than the Fortran array bounds to keep the registry compact. # The CONSTRAINTS dict below uses the Fortran constants for validation. diff --git a/toolchain/mfc/params/namelist_parser.py b/toolchain/mfc/params/namelist_parser.py index fdcb21d38a..52385255d3 100644 --- a/toolchain/mfc/params/namelist_parser.py +++ b/toolchain/mfc/params/namelist_parser.py @@ -492,29 +492,18 @@ def get_fortran_constants() -> Dict[str, int]: """ Get Fortran compile-time constants from m_constants.fpp. - Cached after first call. Falls back to built-in defaults when the Fortran - source is unavailable (e.g. Homebrew installs where src/ is not shipped). + Cached after first call. Returns an empty dict when the Fortran source is + unavailable (e.g. Homebrew installs where src/ is not shipped); callers + supply their own inline defaults via _fc(name, default) in definitions.py. """ global _FORTRAN_CONSTANTS_CACHE # noqa: PLW0603 if _FORTRAN_CONSTANTS_CACHE is None: root = get_mfc_root() path = root / "src" / "common" / "m_constants.fpp" _FORTRAN_CONSTANTS_CACHE = parse_fortran_constants(path) - if not _FORTRAN_CONSTANTS_CACHE: - _FORTRAN_CONSTANTS_CACHE = _FALLBACK_CONSTANTS.copy() return _FORTRAN_CONSTANTS_CACHE -# Fallback values for when m_constants.fpp is not available at runtime. -# Keep in sync with src/common/m_constants.fpp. -_FALLBACK_CONSTANTS: Dict[str, int] = { - "num_fluids_max": 10, - "num_probes_max": 10, - "num_patches_max": 1000, - "num_bc_patches_max": 10, -} - - def get_mfc_root() -> Path: """Get the MFC root directory from this file's location.""" # This file is at toolchain/mfc/params/namelist_parser.py