bloc.chem.network#

ReactorNet topology helpers and network diagram rendering.

Functions#

collect_all_reactors_and_reservoirs(sim)

Collect all Reactors and Reservoirs in a Network.

get_physical_nodes_ordered(sim)

Return physical node names from a ReactorNet in topological (flow-path) order.

draw_network_and_render(sim[, path, view])

Draw the network structure and render it as a PNG file.

collect_node_properties(sim[, node_mass_flow_kg_s])

Collect thermodynamic properties (enthalpy, HHV, LHV, ...) for physical nodes.

collect_energy_flows(sim[, ...])

Collect per-node energy flow breakdown for the network.

derive_outputs_from_sim(sim[, states, config, ...])

Derive a flat scalar outputs dict from a solved ReactorNet and optional states.

Module Contents#

bloc.chem.network.collect_all_reactors_and_reservoirs(sim)#

Collect all Reactors and Reservoirs in a Network.

Parameters:

sim (cantera.ReactorNet)

Return type:

set of cantera.Reactor

bloc.chem.network.get_physical_nodes_ordered(sim)#

Return physical node names from a ReactorNet in topological (flow-path) order.

Physical nodes are reactors/reservoirs that participate in at least one mass-flow connection (MassFlowController). Energy-only nodes (connected only via walls, e.g. Losses, Electricity) are excluded.

The ordering follows a topological sort starting from source nodes (those with no upstream mass-flow connection).

bloc.chem.network.draw_network_and_render(sim, path=None, view=False)#

Draw the network structure and render it as a PNG file.

If path is None then PNG file path is the original file with _sim.png extension.

Parameters:
  • view – If True, open the rendered image with the system default viewer (blocks on some platforms; keep False for scripts, CI, and tests).

  • https (See)

Example

from bloc.chem import draw_network_and_render
# add your simulation code
# ``sim`` is the Cantera simulation object
draw_network_and_render(sim)
bloc.chem.network.collect_node_properties(sim, node_mass_flow_kg_s=None)#

Collect thermodynamic properties (enthalpy, HHV, LHV, …) for physical nodes.

Physical nodes are reactors/reservoirs that participate in at least one mass-flow connection (MassFlowController). Energy-only nodes (connected only via walls, e.g. Losses, Electricity) are excluded.

Parameters:

sim (cantera.ReactorNet) – The reactor network (already advanced/solved).

Returns:

``{node_name: {“enthalpy_mass_J_kg”: float,

”enthalpy_mole_J_kmol”: float, “HHV_MJ_kg”: float, “LHV_MJ_kg”: float, “sensible_heat_MJ_kg”: float, “volume_flow_Nm3_s”: float}}``

Values are nan when the property cannot be computed (e.g. O2 not present in the mechanism for HHV/LHV).

Return type:

dict

bloc.chem.network.collect_energy_flows(sim, connection_mass_flows_kg_s=None, connection_endpoints=None)#

Collect per-node energy flow breakdown for the network.

For each physical node, compute input and output energy components:

Inputs (energy flowing into the node):

  • Power (kW) – wall heat flowing into this node from non-physical sources

  • HHV_in (kW) – HHV carried by upstream mass streams entering this node

  • Sensible_heat_in (kW) – sensible enthalpy of upstream streams above ref.

Outputs (energy flowing out of the node):

  • Heat_losses (kW) – wall heat flowing from this node to loss reservoirs

  • HHV_out (kW) – HHV carried by downstream mass streams leaving this node

  • Sensible_heat_out (kW) – sensible enthalpy of downstream streams above ref.

Parameters:

sim (cantera.ReactorNet) – The solved reactor network.

Returns:

{node_name: {"inputs": {...}, "outputs": {...}}} where each sub-dict maps descriptive keys to values in kW. Keys are ordered following the physical node topological order.

Return type:

dict

bloc.chem.network.derive_outputs_from_sim(sim, states=None, config=None, kpi_extractor=None, sim_extra=None)#

Derive a flat scalar outputs dict from a solved ReactorNet and optional states.

This is the primary extraction path replacing the legacy res_dic. It produces a dict suitable for scenario_results["outputs"] in the Calculation Note pipeline.

Generic thermodynamic outputs are extracted from the network topology (physical node order, outlet node T/P/X/Y, per-node HHV/LHV/flows). Model-specific KPIs (yields, efficiencies, costs) are added by an optional kpi_extractor callable registered per reactor_kind.

Parameters:
  • sim (cantera.ReactorNet) – Solved reactor network.

  • states (cantera.SolutionArray or dict or None) – Time-series solution arrays (optional; forwarded to kpi_extractor).

  • config (parser or None) – ctwrap config object (forwarded to kpi_extractor).

  • kpi_extractor (callable or None) – Model-specific KPI function with signature kpi_extractor(sim, states, config, sim_extra) -> dict. Its output is merged into the result; extractor keys override generic topology keys when they conflict.

  • sim_extra (dict or None) – Supplementary scalar data not accessible from the ReactorNet topology after the advance loop (e.g. tube-furnace E_conv_J, E_rad_J). Forwarded to kpi_extractor unchanged.

Returns:

Flat dict of scalar outputs. Generic keys follow the naming convention T_outlet_C, P_outlet_bar, X_{species}, Y_{species}, HHV_outlet_MJ_kg, etc. Model-specific keys are defined by the kpi_extractor.

Return type:

dict