STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
__init__.py
Go to the documentation of this file.
1"""Real-gas thermophysical properties, fast enough to sit inside a solver.
2
3Everything above this package asks a :class:`Fluid` for numbers and never
4touches an equation-of-state library::
5
6 from feedtwin.props import Fluid
7
8 n2 = Fluid("nitrogen")
9 n2.get("rho", p=3.1e7, T=293.0) # 44.5 kg/m3, ~0.13 us
10 n2.get("Z", p=3.1e7, T=293.0) # 1.150 -- a COPV is not an ideal gas
11 n2.state(p=5e5, q=0.5).phase # Phase.TWO_PHASE
12
13Three ideas carry the whole package:
14
15**A chain, not a branch.** A fluid holds an ordered list of backends. Tabulated
16interpolation answers ordinary states in ~0.13 us; the Helmholtz equation of
17state behind it answers everything the tables refuse. Put measured data at the
18front and it wins wherever it has coverage. Nobody writes the routing.
19
20**Refuse, never extrapolate.** A backend outside its envelope raises
21:class:`OutOfRange` and the chain moves on. No backend in this package will
22return a plausible number for a state point it cannot actually reach.
23
24**Fluids are data.** Species live in ``species.toml``. Adding a propellant is a
25data edit, and :func:`register_species` adds one at runtime without touching
26this package at all.
27
28SI throughout: Pa, K, kg/m3, Pa.s, J/kg, J/(kg.K), W/(m.K), m/s.
29"""
30
31from __future__ import annotations
32
33from feedtwin.props.backend import (
34 PropertyBackend,
35 StatePair,
36 register_backend,
37 registered_backends,
38)
39from feedtwin.props.backends.coolprop import CoolPropBackend, warm_tables
40from feedtwin.props.backends.tabulated import TabulatedProperties
41from feedtwin.props.errors import (
42 OutOfRange,
43 PropertyError,
44 UnknownFluid,
45 UnsupportedProperty,
46)
47from feedtwin.props.fluid import Fluid
48from feedtwin.props.species import (
49 DEFAULT_CHAIN,
50 SpeciesSpec,
51 get_species,
52 load_species_file,
53 register_species,
54 registered_species,
55)
56from feedtwin.props.state import (
57 PROPERTIES,
58 Phase,
59 PropertySpec,
60 ThermoState,
61 register_property,
62)
63
64
65def warmup(fluids: list[str] | None = None) -> dict[str, float]:
66 """Build interpolation tables now rather than inside the first solve.
67
68 Returns seconds spent per fluid. Costs 2-3 s and ~17 MB each the first time
69 on a machine; afterwards CoolProp loads them from its own cache.
70
71 Call this when a process starts if it is going to do physics -- a pool
72 worker, an API container. The reason is the same one EngineDesign's
73 accelerator front-loads its JIT for: paid lazily, the cost lands inside
74 whichever call happens to come first, which is usually one somebody is
75 timing.
76
77 Args:
78 fluids: Names or aliases to warm. Defaults to every declared species.
79 """
80 names = fluids if fluids is not None else registered_species()
81 return {name: warm_tables(get_species(name)) for name in names}
82
83
84__all__ = [
85 "DEFAULT_CHAIN",
86 "PROPERTIES",
87 "CoolPropBackend",
88 "Fluid",
89 "OutOfRange",
90 "Phase",
91 "PropertyBackend",
92 "PropertyError",
93 "PropertySpec",
94 "SpeciesSpec",
95 "StatePair",
96 "TabulatedProperties",
97 "ThermoState",
98 "UnknownFluid",
99 "UnsupportedProperty",
100 "get_species",
101 "load_species_file",
102 "register_backend",
103 "register_property",
104 "register_species",
105 "registered_backends",
106 "registered_species",
107 "warm_tables",
108 "warmup",
109]
dict[str, float] warmup(list[str]|None fluids=None)
Definition __init__.py:65