The pure flow layer: Mach state-setting & isentropic efficiency

Setting a GasState from a Mach number, and specifying a turbomachine by isentropic efficiency — the legacy mutable path beside its zero-allocation, enthalpy-exact pure replacement, with the real code run to back every claim.

branch cleanup_arch · new flow layer = working tree (uncommitted) · legacy pinned @133180c · 2026-06-15

Legacy mutable path — Gas1D + gas_Mach! (turbo.jl) + constant-γ FlowStations
New pure flow layer — speed_of_sound / stagnation_state / static_state over FrozenGas·GasState
derived quantity (pressure rail / second curve)

The new flow.jl answers the two questions the legacy stateful layer could but the pure core could not: set the gas state from a Mach number, and specify a turbomachine by isentropic efficiency. Each row below puts the legacy operation beside its pure replacement; the three figures run the real code to back the exactness, speed, and convention claims. Click any row label (or a node header) to expand the verbatim source behind both cells.

legacy mutable
Gas1D cache · gas_Mach! · constant-γ
src/Gas1D.jl:L6
new pure flow
FrozenGas property + GasState value
src/gasstate.jl:L33 · flow.jl (working tree)
Speed of sound a = √(γRT)
legacy implicit — needs gas.γ at T▶

No speed-of-sound function. The legacy flow code reads gas.γ off the mutable cache (valid only after gas.T has been set) inside the constant-γ ratios.

L3mutable struct FlowStation
L7    V::Float64  # Velocity, Ma*a = Ma*√(γRT)
L20function isenTR(gas::AbstractGas, Ma)
L21    1 + 0.5 * (gas.γ - 1) * Ma^2

⚠ src/FlowStations.jl is untracked scratch (git-ignored, never included in the module) — no permalink. Lines are working-tree.

new speed_of_sound(gas, T)▶

A pure property of (gas, T) — composition and temperature are all it needs, no pressure, no state. Mirrors cp/gamma; forwards through FastFrozenGas; has a GasState accessor.

$$ a(\text{gas}, T) = \sqrt{\gamma(\text{gas},T)\,R\,T} $$
L147@inline speed_of_sound(gas::FrozenGas, T) = sqrt(gamma(gas, T) * gas.R * T)

src/frozengas.jl:L139-L147 (working tree, uncommitted)

Total → static the Mach state-set
legacy gas_Mach!(g, 0, M, 1) for iter = 1:itmax▶

Mutates a Gas1D in place: Newton on the energy balance h + ½u² = const across the Mach change, pressure folded in at the end with a polytropic ηp. Enthalpy-based — so it is exact, but it allocates and carries an efficiency the reference state shouldn't have.

L85function gas_Mach!(gas::AbstractGas, M0::Float64, M::Float64, ηp::Float64 = 1.0)
L99    for iter = 1:itmax
L100        set_TP!(gas, t, gas.P) #keep pressure constant for now; will be changed later
L108        res = gas.h + 0.5 * usq - h0 - 0.5 * uosq
L113        if (abs(dt) < ttol)
L114            P = gas.P * exp(ηp * (gas.ϕ - ϕ0) / R0) #calculate pressure with polytropic efficiency

Termination: abs(dt) < ttol (ttol = 1e-6), capped at itmax = 10.

src/turbo.jl:L85-L121

new static_state(st, M) for _ = 1:NEWTON_MAXITER▶

The static state at Mach M whose isentropic stagnation state is st — a new GasState, the input untouched. Same physics as gas_Mach!(·,0,M,1) but pure and zero-allocation; the speed of sound is evaluated at the static T (the Mach number is defined with the local sound speed), so it is a bounded Newton solve.

$$ h(T) + \tfrac{1}{2}\bigl(M\,a(T)\bigr)^2 = h(\text{st}),\qquad a^2 = \gamma R T $$
L69function static_state(st::GasState, M)
L79    for _ = 1:NEWTON_MAXITER
L84        f = h(gas, T) + halfM2 * γ * Rg * T - ht
L86        dT = -f / df
L88        if abs(dT) ≤ NEWTON_RTOL * abs(T)
L89            Ps = Pt * exp((s0(gas, T) - s0(gas, Tt)) / Rg)

Termination: abs(dT) ≤ NEWTON_RTOL * abs(T) (rtol = 1e-12), capped at NEWTON_MAXITER = 30; errors if not converged.

src/flow.jl:L56-L94 (working tree, uncommitted)

Static → total stagnation reference
legacy get_static / isenPR — constant-γ▶

The only stagnation helpers use the constant-γ relations 1 + ½(γ−1)M² and (…)^(γ/(γ−1)) — γ frozen at one temperature. For a thermally-perfect gas those ratios drift with temperature and Mach (the figure below quantifies it).

$$ \frac{T_t}{T} = 1 + \tfrac{1}{2}(\gamma-1)M^2,\qquad \frac{P_t}{P}=\Bigl(\tfrac{T_t}{T}\Bigr)^{\!\gamma/(\gamma-1)} $$
L12function get_static(FS::FlowStation)
L13    Ps = FS.gas.P / isenPR(FS.gas, FS.Ma)
L14    Ts = FS.gas.T / isenTR(FS.gas, FS.Ma)
L27function isenPR(gas::AbstractGas, Ma)
L29    isenTR(gas, Ma)^(k)

⚠ src/FlowStations.jl — untracked, git-ignored scratch; never in the module.

new stagnation_state(st, M)▶

Brings the static flow isentropically to rest using the enthalpy and entropy curves — exact for a thermally-perfect gas. A loss-free reference: it carries no efficiency (a lossy ram composes separately). Closed form: one enthalpy inversion.

$$ h_t = h(T) + \tfrac{1}{2}V^2,\quad V=M a;\qquad P_t = P\,e^{\,(s^0(T_t)-s^0(T))/R} $$
L46function stagnation_state(st::GasState, M)
L50    V = M * speed_of_sound(gas, st.T)
L51    Tt = T_of_h(gas, h(gas, st.T) + V^2 / 2)
L52    Pt = st.P * exp((s0(gas, Tt) - s0(gas, st.T)) / R(gas))
L53    GasState(gas, Tt, Pt)

src/flow.jl:L31-L54 (working tree, uncommitted)

Compression efficiency spec
legacy compress — polytropic ηp only▶

The legacy ratio process takes a polytropic ηp and nothing else — there is no way to specify a machine by its isentropic efficiency.

L8function PressureRatio(gas::AbstractGas, PR::Float64, ηp::Float64 = 1.0)
L15    Tfinal = T0 * PR^(R / gas.cp / ηp)
L22    for i = 1:20# abs(dT)>ϵ

src/turbo.jl:L8-L49

new compress(gas, T1, PR; ηp | ηs)▶

One verb, the loss model chosen by which keyword is given (at most one — ArgumentError if both). ηs degrades the ideal enthalpy rise to the same pressure ratio, so both conventions land on P·PR; only the temperature differs.

$$ h(T_2) = h(T_1) + \frac{h(T_{2s}) - h(T_1)}{\eta_s},\qquad T_{2s}=\text{loss-free outlet} $$
L164function compress(gas::PureGas, T1, PR; ηp = nothing, ηs = nothing)
L171    _check_one_efficiency(ηp, ηs, "compress")
L172    if ηs === nothing
L173        T_isentropic(gas, T1, PR; ηp = _resolve_ηp(ηp))
L174    else
L175        h1 = h(gas, T1)
L176        T2s = T_isentropic(gas, T1, PR) # loss-free outlet at this PR
L177        T_of_h(gas, h1 + (h(gas, T2s) - h1) / ηs)

src/gasstate.jl:L164-L179 (working tree, uncommitted)

Stagnation / Mach model exactness
✗ constant-γ
1+½(γ−1)M² — drifts to 6.75% (T) by M=3 ↓fig 1
✓ enthalpy/entropy exact
reuses the h/s⁰ inversions — agrees with legacy gas_Mach! to 7.9e-10
Allocations Mach state-set, per call
181
mutable cache churn (gas_Mach!)
0
isbits GasState — stack only
Autodiff ∂/∂M, ∂/∂PR ForwardDiff
✗ blocked
Gas1D fields pinned ::Float64 — Gas1D.jl:L6
✓ analytic
Duals through T_of_h / T_isentropic IFT rules; static_state on the value rail
Efficiency conventions compress / expand
ηp only
polytropic; isentropic spec impossible
ηp or ηs
mutually exclusive keyword (ADR-0005) ↓fig 3
Mach total→static median ns; baseline = gas_Mach!
2709 ns
181 allocs
552 ns4.9×
0 allocs
Speed of sound median ns; baseline = legacy γ-read
291 ns
9 allocs (set T, read γ)
6.4 ns46×
0 allocs
Figure 1 — Exactness: the new pair is enthalpy-exact; the legacy constant-γ model drifts
Total → static of dry air at Tt=1000 K, Pt=8 bar: exact vs constant-γ00.20.40.60.8100.511.522.53Ts/Tt and Ps/PtTs/Tt exact (static_state)Ts/Tt constant-γ (legacy)Ps/Pt exact (static_state)Ps/Pt constant-γ (legacy)Mach number M1.0e-161.0e-151.0e-141.0e-131.0e-121.0e-111.0e-101.0e-091.0e-081.0e-071.0e-061.0e-051.0e-040.0010.010.100.511.522.53rel. error vs exact|ΔT|/T constant-γ|ΔP|/P constant-γ|ΔT|/T legacy gas_Mach!Mach number M

Total→static of dry air (Tt = 1000 K, Pt = 8 bar) over M ∈ [0, 3]. static_state (solid) and the legacy enthalpy-based gas_Mach! agree to the inversion tolerance; the constant-γ FlowStations relations (dashed) diverge, growing with Mach. The residual panel is the relative error of each model against the exact result.

constant-γ error up to 6.75% (T), 2.27% (P) by M=3 · legacy gas_Mach! agrees to 7.9e-10 (T), 3.1e-9 (P)
generated by claude_sandbox/walkthrough/evidence/mach_exact.jl (working tree) · julia --project=claude_sandbox/proto_deriv claude_sandbox/walkthrough/evidence/mach_exact.jl · data: evidence/mach_exact.csv · stats: evidence/mach_exact_stats.json · Julia 1.12.6 · 2026-06-15
Figure 2 — Performance: pure verbs are zero-allocation and faster (median ns, log scale)
Per-call cost: legacy mutable (red) vs new pure (green) — median ns, log scale101001000median time [ns]2709 ns / 181agas_Mach!legacy552 ns / 0astatic_statenew291 ns / 9aa=√γRTlegacy6 ns / 0aspeed_of_soundnew260 ns / 0astagnation_statenew215 ns / 0acompress ηpnew441 ns / 0acompress ηsnew

Per-call cost, legacy mutable (red) vs new pure (green). The headline pair is the Mach state-set: static_state is 4.9× faster than gas_Mach! with 181 → 0 allocations; speed_of_sound is 46× faster. compress with ηs costs ~2× the ηp form — honestly, it runs the loss-free isentrope plus an enthalpy inversion — but is still zero-allocation.

static_state 552 ns / 0 alloc vs gas_Mach! 2709 ns / 181 alloc (4.9×) · speed_of_sound 6.4 ns (46×)
generated by claude_sandbox/walkthrough/evidence/flow_bench.jl (working tree) · BenchmarkTools.jl, min & median over default samples · Apple M2 Pro, arm64-darwin, Julia 1.12.6 · julia --project=claude_sandbox/proto_deriv claude_sandbox/walkthrough/evidence/flow_bench.jl · raw: evidence/flow_bench.json · 2026-06-15
Figure 3 — The efficiency convention changes the answer, and is state-dependent
Compressor outlet from T1=288 K: the efficiency convention changes the answer400500600700800900510152025303540outlet T2 [K]ideal (η = 1)ηp = 0.85 (polytropic)ηs = 0.85 (isentropic)pressure ratio PR0.760.780.80.820.84510152025303540ηs implied by ηp=0.85ηs of the ηp=0.85 processηp = 0.85 (fixed)pressure ratio PR

Compressor outlet from T1 = 288 K over PR ∈ [2, 40]. At a fixed efficiency value 0.85, polytropic (ηp) and isentropic (ηs) give different outlet temperatures, diverging with PR — they are genuinely different loss models. The lower panel shows that a fixed ηp = 0.85 corresponds to a PR-dependent isentropic efficiency (the same "ratios depend on the state, not the ratio alone" lesson as ADR-0004's rejected temp_ratio). The two are reconcilable: measuring the isentropic efficiency of a polytropic outlet and feeding it back as ηs reproduces that outlet.

ηp=0.85 ↔ ηs ∈ [0.767, 0.835] across PR · outlet gap 61.0 K at PR=40 · reconstruction exact to 3.6e-16
generated by claude_sandbox/walkthrough/evidence/eta_convention.jl (working tree) · julia --project=claude_sandbox/proto_deriv claude_sandbox/walkthrough/evidence/eta_convention.jl · data: evidence/eta_convention.csv · stats: evidence/eta_convention_stats.json · Julia 1.12.6 · 2026-06-15