bloc.converter#
BlocConverter — DualCanteraConverter subclass pre-loaded with Bloc plugins.
Every BlocConverter instance:
Carries all Bloc Design* reactor builders and post-build hooks via
_register_bloc_solver_plugins.Resolves mechanism paths through Bloc’s
get_mechanism_pathsearch hierarchy (working dir, calling-script dir, Bloc data dir, Cantera data dir). This override is honored at every resolution point:__init__,_get_gas_for_mech, and the staged-solver helpers — thanks to theresolve_mechanismhook introduced in Boulder 0.5.0.
Classes#
Cantera converter pre-loaded with Bloc Design* reactors and hooks. |
Module Contents#
- class bloc.converter.BlocConverter(mechanism=None, plugins=None)#
Bases:
boulder.cantera_converter.DualCanteraConverterCantera converter pre-loaded with Bloc Design* reactors and hooks.
- Parameters:
mechanism – Raw mechanism name/path (not yet path-resolved). Resolution is performed by
resolve_mechanismduring construction.plugins – Optional pre-built plugin container. Bloc solver plugins are registered into this container (idempotent) regardless of whether it is provided or freshly created.
- SCRIPT_EMITTER_CLASS: type#
- resolve_mechanism(name)#
Resolve name using Bloc’s mechanism search hierarchy.
Called from every site that turns a mechanism string into a
ct.Solution— both the top-level default mechanism (in__init__) and per-node mechanism overrides (in_get_gas_for_mech). Ifget_mechanism_pathcannot locate the file, returns name unchanged so Cantera can handle bare built-in names (e.g."gri30.yaml").
- script_load_lines(config_path, plan=None)#
Emit a Bloc-aware Cantera-native staged-solve script.
The generated file uses module-level
reactors/connections/wallsregistries, directDesign*construction, and namednetwork_<stage>.advance(...)calls — noBlocConvertershell.
- mechanism = 'gri30.yaml'#
- plugins#
- reactors: Dict[str, cantera.ReactorBase]#
- reactor_meta: Dict[str, Dict[str, Any]]#
- connections: Dict[str, cantera.FlowDevice]#
- walls: Dict[str, Any]#
- network: cantera.ReactorNet | None = None#
- code_lines: List[str] = []#
- last_network: cantera.ReactorNet | None = None#
- parse_composition(comp_str)#
- set_reactor_volume(reactor, props, reactor_id)#
Set reactor volume if specified in properties.
- create_reactor_from_node(node, gas_for_node)#
Instantiate a Cantera reactor from a normalized node dict.
Uses the plugin reactor builder registry when the type matches a registered custom builder; otherwise falls back to the standard Cantera reactor types.
- Parameters:
node – Normalized node dict with
id,type, andproperties.gas_for_node – The
Solutioncarrying the initial state.
- Returns:
The newly created reactor (not yet added to any network).
- Return type:
ct.Reactor
- build_connection(conn)#
Create and register one Cantera flow device or wall from a connection dict.
The connection is added to
self.connections(forFlowDevicesubtypes) orself.walls(forWall).- Parameters:
conn – Normalized connection dict with
id,type,source,target, andproperties.
- apply_flow_conservation()#
Resolve unset MFC flow rates via mass conservation, then reset tracking state.
Called after all connections for a network (or sub-network stage) have been built. MFCs without an explicit
mass_flow_ratein the YAML config are resolved by enforcing steady-state mass conservation at each non-Reservoir reactor node. Resolved values are also appended tocode_linesso the--downloadscript reflects the actual flow rates.- Raises:
ValueError – Propagated from
resolve_unset_flow_rates()if any flow rate cannot be uniquely determined.
- post_build(config)#
Run registered post-build hooks on a (sub-)config.
Called once per stage (with the stage subset config) and once after the full viz network is built. Default iterates
plugins.post_build_hooks. Subclasses may override to add behavior without touching the plugin list.
- build_sub_network(stage_nodes, stage_connections, stage_mechanism, inlet_states, stage_id='', stage=None)#
Build (and solve) a
ReactorNetfor one stage.Reactors whose IDs appear in inlet_states are initialised from the provided
Solution(upstream outlet, already mechanism-switched) instead of from the YAML properties.- Parameters:
stage_nodes – Normalized node dicts for this stage only.
stage_connections – Intra-stage normalized connection dicts.
stage_mechanism – Default kinetic mechanism for the stage.
inlet_states –
{node_id: ct.Solution}mapping inlet conditions for reactors that receive inter-stage flow.stage_id – For logging/error messages.
stage –
Stagedataclass; used to set the solve directive (advance_to_steady_statevsadvance).
- Returns:
networkis the solvedReactorNet.stage_reactorsis a{node_id: ct.ReactorBase}dict for this stage (a subset ofself.reactors).- Return type:
(network,stage_reactors)
- build_viz_network(all_connections, built_conn_ids=None)#
Build a visualization-only
ReactorNet.Uses all reactor objects already in
self.reactors(which carry converged states after a staged solve) and adds any inter-stage connections that were not built during the per-stage solve.The returned network is initialized with
advance(0.0)so flow-device properties (mass_flow_rate) are ready for downstream reporting.- Parameters:
all_connections – The full list of normalized connection dicts (including inter-stage ones).
built_conn_ids – Set of connection IDs already built (intra-stage). Inter-stage connections not in this set will be created now.
- Return type:
ct.ReactorNet
- build_network(config, progress_callback=None)#
Build and solve the Cantera network through the staged solver.
normalize_configguarantees that the config has a top-levelgroupssection (synthesising a singledefaultgroup when the YAML does not declare one), so this method always delegates tosolve_staged(). It builds one sub-ReactorNetper stage, solves each according to itssolve_directiveand returns a visualization ReactorNet with all reactors in their converged state. The Lagrangian trajectory is stored onself._staged_trajectory.- Parameters:
config – Normalised and validated configuration dict.
progress_callback – Optional
(stage_id: str, n_done: int, n_total: int) -> Nonecalled after each stage completes. Forwarded tosolve_staged().
- run_streaming_simulation(simulation_time=10.0, time_step=1.0, progress_callback=None, config=None)#
Run simulation with streaming progress updates.
- finalize_results(times, reactors_series)#
Finalize simulation results with post-processing.
- build_network_and_code(config)#
Build+solve the network and return
(network, results, code_str).build_networknow solves the whole network through the staged solver, soresultsonly reports what the staged path already produced: the converged per-reactor states (as a single-time-point SolutionArray) and any scalars stored by post-build hooks.