bloc.chem.state#
Reactor lookup and cached-Solution state helpers.
Loading mechanisms lives in bloc.io.mechanisms; this module is about
using the phases it hands back.
Functions#
|
Get a reactor from a ReactorNet by name. |
|
Calculate thermodynamic property at specific conditions. |
|
Get a cached Solution object configured to specific thermodynamic state. |
Module Contents#
- bloc.chem.state.get_reactor_by_name(sim, name)#
Get a reactor from a ReactorNet by name.
- Parameters:
sim (
ct.ReactorNet) – The reactor network simulationname (
str) – Name of the reactor to find
- Returns:
The reactor with the given name, or None if not found
- Return type:
ct.ReactororNone
Examples
>>> import cantera as ct >>> gas = ct.Solution("gri30.yaml") >>> reactor = ct.IdealGasConstPressureReactor(gas, name="test_reactor") >>> sim = ct.ReactorNet([reactor]) >>> found_reactor = get_reactor_by_name(sim, "test_reactor") >>> print(found_reactor.name) test_reactor
- bloc.chem.state.get_property_at_conditions(mechanism_source, T, P, composition, property_name='h', use_cache=True)#
Calculate thermodynamic property at specific conditions.
This function can either use a cached Solution object (default, most efficient) or create a new temporary Solution object for each call. The cached approach uses MECHANISM_SOLUTION_CACHE to avoid object creation overhead and is recommended for most use cases.
- Parameters:
mechanism_source (
str) – The mechanism source (e.g., from gas.source)T (
float) – Temperature in KP (
float) – Pressure in Pacomposition (
strordict) – Composition as string (e.g., “H2:1”) or dictionaryproperty_name (
str, optional) – Property to calculate. Default is “h” (enthalpy). Options: “h”, “s”, “cp”, “cv”, “density”, etc.use_cache (
bool, optional) – Whether to use cached Solution objects. Default is True (recommended). Set to False to create a new temporary Solution object for each call.
- Returns:
The requested property value
- Return type:
float
Examples
>>> import cantera as ct >>> gas = ct.Solution("gri30.yaml") >>> # Get enthalpy of H2 at 1000K, 1atm using cached Solution (default) >>> h_ref = get_property_at_conditions(gas.source, 1000, ct.one_atm, "H2:1", "h") >>> # Get enthalpy without caching (creates new Solution object) >>> h_ref = get_property_at_conditions( ... gas.source, 1000, ct.one_atm, "H2:1", "h", use_cache=False ... )
- bloc.chem.state.get_cached_solution_at_state(mechanism_source, T, P, X)#
Get a cached Solution object configured to specific thermodynamic state.
This unified function uses the MECHANISM_SOLUTION_CACHE to avoid creating new Solution objects when configuring Solutions for plotting, post-processing, or other temporary operations.
WARNING: This function returns a mutable cached object that shares state across calls. Only use for operations where state mutation is acceptable.
SAFE USAGE: - Reactor/Reservoir creation (state is copied during instantiation) - Post-processing and visualization (single-use operations) - Final state analysis and composition extraction
UNSAFE USAGE: - Iterative property calculations (use fresh ct.Solution() instead) - Multiple property evaluations within same computational loop - Any operation requiring state isolation between calls
- Parameters:
mechanism_source (
str) – The mechanism source (e.g., from gas.source or state.source)T (
float) – Temperature in KP (
float) – Pressure in PaX (
dictorarray) – Composition as dictionary or array
- Returns:
A cached Solution object configured to the specified state. WARNING: This object is shared across all calls with the same mechanism.
- Return type:
ct.Solution
Examples
>>> # SAFE: Reactor creation (state copied) >>> gas_upstream = get_cached_solution_at_state(mechanism, T, P, X) >>> reservoir = ct.Reservoir(gas_upstream) # Safe - state copied
>>> # SAFE: Post-processing (single use) >>> gas_final = get_cached_solution_at_state( ... reactor_states.source, ... reactor_states.T[-1], ... reactor_states.P[-1], ... reactor_states.X[-1], ... ) >>> Y_out = get_gas_phase_composition(gas_final).mass_fraction_dict()
>>> # UNSAFE: Property calculations (use fresh Solution instead) >>> # gas = get_cached_solution_at_state(mechanism, T, P, X) # DON'T DO THIS >>> # h = gas.h # UNSAFE - contamination risk >>> gas = ct.Solution(mechanism) # DO THIS INSTEAD >>> gas.TPX = T, P, X >>> h = gas.h # SAFE - isolated object