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
dense_matrix_bytes(num_species)
Per-thread bytes for the three dense N x N micro-matrix buffers.
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
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 196 197 | |
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
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 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
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.
per_thread_matrix_budget(num_species, compact_bytes=None)
Evaluate the documented per-thread memory budget for a mechanism (data-model E4).
Returns a manifest-ready record describing the selected numeric workspace and whether it exceeds the budget. Exceeding the budget emits a generation-time warning: the device instantiation must relocate {J,W,LU}_values to team-scratch and the L/U masks to a device-accessible View rather than per-thread stack arrays / per-TU inline masks.