C++ Header Code Generation (mkpp.codegen)
mkpp.codegen
MKPP Code Generation Orchestrator.
This module provides the top-level generate_headers function that emits
Kokkos C++ solver headers from a parsed mechanism definition. It delegates
to the Jinja2 template engine for C++ emission and to focused submodules
for tableau definitions and expression formatting.
Public API (backward-compatible): - generate_headers - generate_host_api_headers - SOLVER_COEFFICIENTS - RosenbrockTableau - format_eqn - get_A, get_C
RosenbrockTableau
dataclass
Immutable coefficient tableau for a Rosenbrock solver.
Source code in src/mkpp/rosenbrock.py
format_eqn(eqn_str, species_list, state_var='state', use_parentheses=True, keep_env_symbols=False, temperature=300.0, air_density=2.4476e+19)
Convert a symbolic ODE expression string into a C++ code string.
Parameters
eqn_str : str
SymPy-parseable expression string (e.g., from KPP rate law).
species_list : list
Ordered species definitions used to map C_X symbols to state indices.
state_var : str
Name of the state array variable in generated C++ code.
use_parentheses : bool
If True, emit state(idx); if False, emit state_idx.
keep_env_symbols : bool
If False (default), environmental parameters (Temp, RH) are substituted
with constants (Temp=300.0). This produces isothermal code suitable only
for constant-temperature simulations.
If True, Temp and RH are emitted as C++ variable references, and the
generated function MUST accept temp/rh as parameters.
WARNING
The current default (keep_env_symbols=False) silently folds temperature to 300 K. For temperature-dependent chemistry, callers MUST pass keep_env_symbols=True and ensure the generated C++ function accepts temp/rh as parameters.
.. deprecated:: planned for MKPP 2.0
The default will be inverted to keep_env_symbols=True for physical
correctness. This requires all generated function signatures to accept
a temp parameter unconditionally.
Source code in src/mkpp/format_eqn.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
generate_headers(mech, out_dir='src/solvers', suffix='', solver_name='ros3', adjoint=False, generate_host_api=False, simd_backend='native', emit_reference_backend=False)
Emit the Kokkos headers and manifest artifact.
Source code in src/mkpp/codegen.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
generate_host_api_headers(mech, out_dir='src/solvers', solver_name='ros3')
Emit the C, C++, and Fortran host API headers and wrappers for a mechanism.
Source code in src/mkpp/codegen.py
get_A(tableau, i, j)
Get A(i,j) from row-wise lower-triangular storage. i,j are 1-indexed; i > j.
get_C(tableau, i, j)
Get C(i,j) from row-wise lower-triangular storage. i,j are 1-indexed; i > j.