STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
feedtwin.props.fluid.Fluid Class Reference
Collaboration diagram for feedtwin.props.fluid.Fluid:
[legend]

Public Member Functions

None __init__ (self, str name, Sequence[ChainEntry]|None chain=None)
str name (self)
SpeciesSpec species (self)
tuple[str,...] chain (self)
float get (self, str prop, **float state)
ThermoState state (self, **float state)
dict[str, float] constants (self)
float critical_pressure (self)
float critical_temperature (self)
Phase phase (self, **float state)
Callable[[float, float], float] accessor (self, str prop, str first, str second)
str __repr__ (self)

Protected Member Functions

tuple[StatePair, float, float] _resolve (self, dict[str, float] state)
tuple[PropertyBackend, list[str]] _settle (self, StatePair pair, float v1, float v2, Iterable[str] needs)
tuple[PropertyBackend,...] _eligible (self, tuple[str,...] required)
PropertyBackend _backend (self, ChainEntry entry)

Protected Attributes

SpeciesSpec _species = get_species(name)
tuple[ChainEntry,...] _chain
 _local = threading.local()

Detailed Description

One species, backed by an ordered chain of property sources.

Args:
    name: Species name or alias -- ``"nitrogen"``, ``"gn2"``, ``"LOX"``.
    chain: Backends to try in order. Defaults to the species' own chain
        from ``species.toml``, which defaults to ``("bicubic", "heos")``.

Definition at line 146 of file fluid.py.

Constructor & Destructor Documentation

◆ __init__()

None feedtwin.props.fluid.Fluid.__init__ ( self,
str name,
Sequence[ChainEntry] | None chain = None )

Definition at line 155 of file fluid.py.

Member Function Documentation

◆ __repr__()

str feedtwin.props.fluid.Fluid.__repr__ ( self)

Definition at line 504 of file fluid.py.

◆ _backend()

PropertyBackend feedtwin.props.fluid.Fluid._backend ( self,
ChainEntry entry )
protected
This thread's instance of one chain entry, built on first use.

Definition at line 485 of file fluid.py.

References _local, feedtwin.props.backends.coolprop.CoolPropBackend._species, and _species.

Referenced by _eligible(), and constants().

◆ _eligible()

tuple[PropertyBackend, ...] feedtwin.props.fluid.Fluid._eligible ( self,
tuple[str, ...] required )
protected
This thread's chain, filtered to backends that can compute ``required``.

Cached per thread and per property set. Which backends *can* compute a
property depends only on the backends and the property -- never on the
state point -- so this is a loop invariant, and recomputing it per call
cost more than the property read it guarded.

Filtering here rather than mid-chain also keeps the answer independent
of the order properties were asked for: a backend that can reach the
state point but not answer the question is skipped before it is moved,
so it can never become the one that serves a later, easier property.

Definition at line 454 of file fluid.py.

References feedtwin.props.backends.coolprop.CoolPropBackend._backend, _backend(), _chain, and _local.

Referenced by _settle(), and accessor().

◆ _resolve()

tuple[StatePair, float, float] feedtwin.props.fluid.Fluid._resolve ( self,
dict[str, float] state )
protected

Definition at line 383 of file fluid.py.

References feedtwin.props.fluid._validate().

Referenced by get(), phase(), and state().

◆ _settle()

tuple[PropertyBackend, list[str]] feedtwin.props.fluid.Fluid._settle ( self,
StatePair pair,
float v1,
float v2,
Iterable[str] needs )
protected
Move the first backend that can serve this point and these properties.

``needs`` is checked *before* updating so a backend that could reach the
state point but not answer the question is skipped rather than moved and
then found wanting -- which would leave the chain's answer depending on
the order the caller asked for properties.

Definition at line 411 of file fluid.py.

References _eligible().

Referenced by accessor(), get(), phase(), and state().

◆ accessor()

Callable[[float, float], float] feedtwin.props.fluid.Fluid.accessor ( self,
str prop,
str first,
str second )
A bound, positional getter for one property over one state pair.

    rho = n2.accessor("rho", "p", "T")
    rho(1.0e7, 300.0)

Same answer as :meth:`get`, roughly three times faster, because
everything that does not change between calls is done once: which state
pair the inputs form, which properties the chain's backends support,
and the keyword unpacking. In a solve those are loop invariants, and
:meth:`get` re-derives all of them on every evaluation.

Use this wherever a property is read in a loop -- assembling a Jacobian,
marching a transient. Use :meth:`get` for one-off queries where clarity
beats a few hundred nanoseconds.

The returned callable is safe to share across threads; it resolves its
backend through the same per-thread cache the rest of the class uses.

Definition at line 298 of file fluid.py.

References _eligible(), _local, _settle(), and feedtwin.props.fluid._validate().

◆ chain()

tuple[str, ...] feedtwin.props.fluid.Fluid.chain ( self)
Names of the backends in this fluid's chain, in order.

Definition at line 173 of file fluid.py.

References _chain.

◆ constants()

dict[str, float] feedtwin.props.fluid.Fluid.constants ( self)
Critical point and molar mass -- properties of the substance.

Cached: they do not depend on a state point, so they are read once per
fluid and never again. Components need the critical pressure for the
IEC 60534 choking correlation, and this is how they get it without
reaching past the property layer.

Sought along the chain rather than taken from its head, for the same
reason every other query is: a measured table has no critical point to
report, and asking only the first backend meant that putting measured
data in front -- the entire point of the feature -- broke every
component evaluation downstream.

Definition at line 248 of file fluid.py.

References feedtwin.props.backends.coolprop.CoolPropBackend._backend, _backend(), _chain, and _local.

Referenced by critical_pressure(), and critical_temperature().

◆ critical_pressure()

float feedtwin.props.fluid.Fluid.critical_pressure ( self)
Thermodynamic critical pressure [Pa].

Definition at line 284 of file fluid.py.

References feedtwin.props.backends.coolprop.CoolPropBackend.constants(), and constants().

◆ critical_temperature()

float feedtwin.props.fluid.Fluid.critical_temperature ( self)
Thermodynamic critical temperature [K].

Definition at line 289 of file fluid.py.

References feedtwin.props.backends.coolprop.CoolPropBackend.constants(), and constants().

◆ get()

float feedtwin.props.fluid.Fluid.get ( self,
str prop,
**float state )
One property at one state point. The solver's hot path.

Specify the state with exactly two of ``p``, ``T``, ``h``, ``s``, ``q``,
``rho`` -- ``fluid.get("rho", p=..., T=...)``.

Tries each backend in order, moving to the next on
:class:`OutOfRange` or :class:`UnsupportedProperty`. Raises
:class:`PropertyError` if the whole chain declines, with what each one
said -- so a failure names the reason rather than the last exception to
survive.

Definition at line 179 of file fluid.py.

References _local, _resolve(), and _settle().

◆ name()

str feedtwin.props.fluid.Fluid.name ( self)

◆ phase()

Phase feedtwin.props.fluid.Fluid.phase ( self,
**float state )

Definition at line 293 of file fluid.py.

References _resolve(), and _settle().

◆ species()

SpeciesSpec feedtwin.props.fluid.Fluid.species ( self)

◆ state()

ThermoState feedtwin.props.fluid.Fluid.state ( self,
**float state )
A full immutable snapshot. For reports, frames and diagnostics.

About eight backend reads rather than one, so prefer :meth:`get` inside
a solve. Backends are moved once and read repeatedly, so this is
cheaper than eight separate :meth:`get` calls.

Definition at line 230 of file fluid.py.

References _resolve(), _settle(), feedtwin.props.backends.coolprop.CoolPropBackend._species, and _species.

Member Data Documentation

◆ _chain

feedtwin.props.fluid.Fluid._chain
protected
Initial value:
= tuple(
chain if chain is not None else self._species.chain
)

Definition at line 157 of file fluid.py.

Referenced by _eligible(), chain(), and constants().

◆ _local

feedtwin.props.fluid.Fluid._local = threading.local()
protected

Definition at line 162 of file fluid.py.

Referenced by _backend(), _eligible(), accessor(), constants(), and get().

◆ _species

SpeciesSpec feedtwin.props.fluid.Fluid._species = get_species(name)
protected

Definition at line 156 of file fluid.py.

Referenced by _backend(), name(), species(), and state().


The documentation for this class was generated from the following file: