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.
Gas1D + gas_Mach! (turbo.jl) + constant-γ FlowStationsspeed_of_sound / stagnation_state / static_state over FrozenGas·GasState
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.
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.
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.
L147@inline speed_of_sound(gas::FrozenGas, T) = sqrt(gamma(gas, T) * gas.R * T)
src/frozengas.jl:L139-L147 (working tree, uncommitted)
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.
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.
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)
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).
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.
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.
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)
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)>ϵ
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.
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)
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.
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
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.
julia --project=claude_sandbox/proto_deriv claude_sandbox/walkthrough/evidence/flow_bench.jl ·
raw: evidence/flow_bench.json · 2026-06-15
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.
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