Skip to content

Commit 0c5f183

Browse files
committed
feat(codegen): auto-generate array declarations via FORTRAN_ARRAY_DIMS
Adds fortran_dim support for indexed-family array parameters. fluid_rho (pre) and 9 output arrays (post) no longer need manual Fortran declarations — all are generated from definitions.py. Remaining manual declarations are exclusively Fortran derived-type variables (bc_x, fluid_pp, patch_icpp, etc.) which require type information that lives in m_derived_types.fpp.
1 parent 27476a7 commit 0c5f183

4 files changed

Lines changed: 34 additions & 28 deletions

File tree

src/post_process/m_global_parameters.fpp

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -135,24 +135,10 @@ module m_global_parameters
135135
type(int_bounds_info) :: offset_x, offset_y, offset_z
136136
!> @}
137137

138-
!> @name The list of all possible flow variables that may be written to a database file. It includes partial densities, density,
139-
!! momentum, velocity, energy, pressure, volume fraction(s), specific heat ratio function, specific heat ratio, liquid stiffness
140-
!! function, liquid stiffness, primitive variables, conservative variables, speed of sound, the vorticity, and the numerical
141-
!! Schlieren function.
142-
!> @{
143-
logical, dimension(num_fluids_max) :: alpha_rho_wrt
144-
logical, dimension(3) :: mom_wrt
145-
logical, dimension(3) :: vel_wrt
146-
logical, dimension(3) :: flux_wrt
147-
logical, dimension(num_fluids_max) :: alpha_rho_e_wrt
148-
logical, dimension(num_fluids_max) :: alpha_wrt
149-
logical, dimension(3) :: omega_wrt
150-
logical :: chem_wrt_Y(1:num_species)
151-
!> @}
152-
153-
real(wp), dimension(num_fluids_max) :: schlieren_alpha !< Per-fluid Schlieren intensity amplitude coefficients
154-
integer :: fd_number !< Finite-difference half-stencil size: MAX(1, fd_order/2)
155-
type(chemistry_parameters) :: chem_params
138+
! alpha_rho_wrt, mom_wrt, vel_wrt, flux_wrt, alpha_rho_e_wrt, alpha_wrt,
139+
! omega_wrt, chem_wrt_Y, schlieren_alpha: auto-generated in generated_decls.fpp
140+
integer :: fd_number !< Finite-difference half-stencil size: MAX(1, fd_order/2)
141+
type(chemistry_parameters) :: chem_params
156142
!> @name Bubble modeling variables and parameters
157143
!> @{
158144
real(wp) :: Eu

src/pre_process/m_global_parameters.fpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,9 @@ module m_global_parameters
6565
integer, dimension(3, 2) :: shear_BC_flip_indices !< Shear stress BC reflection indices (1:3, 1:shear_BC_flip_num)
6666
type(simplex_noise_params) :: simplex_params
6767

68-
! Perturb density of surrounding air so as to break symmetry of grid
69-
real(wp), dimension(num_fluids_max) :: fluid_rho
70-
integer, allocatable, dimension(:) :: proc_coords !< Processor coordinates in MPI_CART_COMM
71-
integer, allocatable, dimension(:) :: start_idx !< Starting cell-center index of local processor in global grid
68+
! Perturb density of surrounding air so as to break symmetry of grid fluid_rho: auto-generated in generated_decls.fpp
69+
integer, allocatable, dimension(:) :: proc_coords !< Processor coordinates in MPI_CART_COMM
70+
integer, allocatable, dimension(:) :: start_idx !< Starting cell-center index of local processor in global grid
7271
#ifdef MFC_MPI
7372
type(mpi_io_var), public :: MPI_IO_DATA
7473
character(LEN=name_len) :: mpiiofs

toolchain/mfc/params/definitions.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,22 @@ def _init_registry():
10291029

10301030
NAMELIST_VARS: dict[str, set[str]] = {}
10311031

1032+
# Maps indexed-family base names to their Fortran dimension expression.
1033+
# The generator emits `{type}, dimension({dim}) :: {name}` for each entry.
1034+
# Add here whenever a new array param needs no manual Fortran declaration.
1035+
FORTRAN_ARRAY_DIMS: dict[str, str] = {
1036+
"fluid_rho": "num_fluids_max", # pre
1037+
"alpha_rho_wrt": "num_fluids_max", # post
1038+
"alpha_rho_e_wrt": "num_fluids_max", # post
1039+
"alpha_wrt": "num_fluids_max", # post
1040+
"schlieren_alpha": "num_fluids_max", # post
1041+
"chem_wrt_Y": "num_species", # post (imported from m_thermochem)
1042+
"flux_wrt": "3", # post
1043+
"mom_wrt": "3", # post
1044+
"omega_wrt": "3", # post
1045+
"vel_wrt": "3", # post
1046+
}
1047+
10321048

10331049
def _nv(targets: set, *names: str) -> None:
10341050
for n in names:

toolchain/mfc/params/generators/fortran_gen.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pathlib import Path
44
from typing import List, Tuple
55

6-
from ..definitions import CASE_OPT_PARAMS, NAMELIST_VARS # noqa: F401 - triggers registry population
6+
from ..definitions import CASE_OPT_PARAMS, FORTRAN_ARRAY_DIMS, NAMELIST_VARS # noqa: F401 - triggers registry population
77
from ..registry import REGISTRY
88
from ..schema import ParamDef, ParamType
99

@@ -15,7 +15,8 @@
1515
_FIRST_PREFIX = "namelist /user_inputs/ "
1616
_CONT_PREFIX = " & "
1717
_CONT2_PREFIX = " & " # inside #:if block
18-
_DECL_COL = 24 # '::' column, matches ffmt alignment
18+
_DECL_COL = 24 # '::' column for scalars, matches ffmt alignment
19+
_ARRAY_DECL_COL = 36 # '::' column for array decls
1920

2021
_FORTRAN_TYPES = {
2122
ParamType.INT: "integer",
@@ -98,20 +99,24 @@ def generate_namelist_fpp(target: str) -> str:
9899

99100

100101
def generate_decls_fpp(target: str) -> str:
101-
"""Return simple scalar Fortran declarations for a target as a string."""
102+
"""Return Fortran declarations (scalars + known arrays) for a target."""
102103
assert target in ("pre", "sim", "post")
103104
lines = [_HEADER.rstrip()]
104105
for name in _vars_for_target(target):
105106
if not _is_simple_scalar(name):
106107
continue
107-
# Skip sim case-opt params: declared as compile-time parameters by the
108-
# manual #:if MFC_CASE_OPTIMIZATION / #:else block in m_global_parameters.fpp
109108
if target == "sim" and name in CASE_OPT_PARAMS:
110109
continue
110+
if name in FORTRAN_ARRAY_DIMS:
111+
member = REGISTRY.all_params.get(f"{name}(1)")
112+
if member is not None:
113+
ftype = fortran_type_decl(member)
114+
dim = FORTRAN_ARRAY_DIMS[name]
115+
lines.append(f"{(ftype + ', dimension(' + dim + ')').ljust(_ARRAY_DECL_COL)}:: {name}")
116+
continue
111117
param = REGISTRY.all_params.get(name)
112118
if param is None:
113119
continue
114-
# Skip if also registered as an indexed family — Fortran declares it as an array.
115120
if any(k.startswith(f"{name}(") for k in REGISTRY.all_params):
116121
continue
117122
lines.append(f"{fortran_type_decl(param).ljust(_DECL_COL)}:: {name}")

0 commit comments

Comments
 (0)