# Gas Discharge
This guide describes the FX-EML chain: source inputs → classification → gas discharge → atmospheric expansion → release duration → final airborne mass. Thermodynamic functions are evaluated by the selected thermodynamics backend. The equations describe the local implementation, including its numerical choices.
## FX-EML Input Preparation
The source editor uses gauge pressure in psig, temperature in °F, hole diameter in inches, volume in US gallons, and duration in minutes. Internally:
$
P_a=6894.757293P_{a,\mathrm{psi}},\quad P_0=6894.757293P_{0,\mathrm{psig}}+P_a,
\quad T_0=(T_{0,\mathrm{F}}-32)\frac59+273.15
$
$
d=0.0254d_{\mathrm{in}},\quad V_0=0.003785411784V_{0,\mathrm{gal}},\quad M_0=\rho(T_0,P_0)V_0.
$
`PhaseClassifier.ClassifyStoragePath` selects this chain for `gas`, `supercritical_gas`, or `supercritical`. Liquid, supercritical-liquid, and two-phase storage use the [liquid chain](Liquid%20Discharge.md). Solid and unsupported states fail. All equation pressures are absolute, velocities m/s, densities kg/m³, enthalpies J/kg, and rates kg/s. The chemical record determines which thermodynamics backend supplies the fluid properties.
FX-EML uses a constant initial-state discharge rate. It does not integrate changing vessel pressure, temperature, or level. Leak Type and Short Pipe Equil. Model do not change the gas branch.
## Inputs and Symbols
The model inputs are leak diameter $d$, storage absolute pressure $P_0$, storage temperature $T_0$, and atmospheric pressure $P_a$. The default atmospheric pressure is $101325\ \mathrm{Pa}$. The model is applicable when the storage state is gas, supercritical gas, or supercritical.
If the storage pressure is not above atmospheric pressure, the model returns a no-flow result:
<span id="eq-gas-no-flow"></span>
$
P_0 \le P_a \Rightarrow G_o=0,\quad C_d=0,\quad \dot{m}=0,\quad U_o=0
\tag{1}
$
The no-flow path still evaluates the storage density so that the returned state is physically defined:
<span id="eq-gas-no-flow-density"></span>
$
\rho_o=\rho(T_0,P_0)
\tag{2}
$
## Homogeneous Direct Integration
For flowing gas releases, `GasDischarge` calls `DischargeIntegrationSolver`. The integration is isentropic from the storage state. The storage entropy is:
<span id="eq-gas-storage-entropy"></span>
$
s_0=s(T_0,P_0)
\tag{3}
$
The pressure interval from $P_0$ to $P_a$ is divided into uniform steps, with $N=100$ requested by `GasDischarge`:
<span id="eq-gas-pressure-step"></span>
$
\Delta P=\frac{P_0-P_a}{N}
\tag{4}
$
At each pressure grid point,
<span id="eq-gas-pressure-grid"></span>
$
P_i=P_0-i\Delta P
\tag{5}
$
the isentropic density and temperature are:
<span id="eq-gas-density-ps"></span>
$
\rho_i=\rho(P_i,s_0)
\tag{6}
$
<span id="eq-gas-temperature-ps"></span>
$
T_i=T(P_i,s_0)
\tag{7}
$
Using the densities from [Equation 6](#eq-gas-density-ps), the pressure-volume integral is accumulated with a trapezoidal rule:
<span id="eq-gas-integral-increment"></span>
$
\Delta I_i=
\frac{|P_i-P_{i-1}|}{2}
\left(
\frac{1}{\rho_i}+\frac{1}{\rho_{i-1}}
\right)
\tag{8}
$
<span id="eq-gas-integral-sum"></span>
$
I_i=I_{i-1}+\Delta I_i,\qquad I_0=0
\tag{9}
$
The mass flux at each pressure is then:
<span id="eq-gas-mass-flux-grid"></span>
$
G_i=\rho_i\sqrt{2I_i}
\tag{10}
$
The coarse orifice pressure is the pressure that maximizes [Equation 10](#eq-gas-mass-flux-grid):
<span id="eq-gas-orifice-pressure-coarse"></span>
$
P_o=\underset{P_i\in[P_a,P_0]}{\arg\max}\ G_i
\tag{11}
$
If the maximum is bracketed by neighboring grid points, the solver refines [Equation 11](#eq-gas-orifice-pressure-coarse) with a golden-section search. Let $P_A=P_{j-1}$ and $\rho_A=\rho(P_A,s_0)$ be the upper-pressure side of the bracket. For a trial pressure $P_x$ in the bracket,
<span id="eq-gas-refined-integral"></span>
$
I(P_x)=I_A+
\frac{|P_A-P_x|}{2}
\left(
\frac{1}{\rho_A}+\frac{1}{\rho(P_x,s_0)}
\right)
\tag{12}
$
<span id="eq-gas-refined-mass-flux"></span>
$
G(P_x)=\rho(P_x,s_0)\sqrt{2I(P_x)}
\tag{13}
$
The refined orifice pressure is:
<span id="eq-gas-orifice-pressure-refined"></span>
$
P_o=\underset{P_x}{\arg\max}\ G(P_x)
\tag{14}
$
The orifice state returned to `GasDischarge` is:
<span id="eq-gas-orifice-state"></span>
$
T_o=T(P_o,s_0),\qquad
\rho_o=\rho(P_o,s_0),\qquad
G_o=G(P_o)
\tag{15}
$
## Discharge Coefficient
After the HDI solution in [Equation 15](#eq-gas-orifice-state), the heat-capacity ratio is evaluated at storage conditions:
<span id="eq-gas-k"></span>
$
k=\frac{C_p(T_0,P_0)}{C_v(T_0,P_0)}
\tag{16}
$
The ideal-gas critical pressure ratio is:
<span id="eq-gas-critical-ratio"></span>
$
\eta_c=
\left(
\frac{2}{k+1}
\right)^{k/(k-1)}
\tag{17}
$
The actual pressure ratio is:
<span id="eq-gas-actual-ratio"></span>
$
\eta_a=\frac{P_a}{P_0}
\tag{18}
$
The critical pressure is:
<span id="eq-gas-critical-pressure"></span>
$
P_c=\eta_cP_0
\tag{19}
$
When [Equation 19](#eq-gas-critical-pressure) gives $P_c>P_a$, the flow is treated as choked. Otherwise, it is treated as unchoked.
Both gas discharge-coefficient correlations use the incompressible base coefficient:
<span id="eq-gas-cdi"></span>
$
C_{d,i}=0.61
\tag{20}
$
<span id="eq-gas-jobson-f"></span>
$
f=\frac{1}{C_{d,i}}-\frac{1}{2C_{d,i}^{2}}
\tag{21}
$
For choked gas flow, the Jobson coefficient uses:
<span id="eq-gas-choked-kn"></span>
$
K_n=
\sqrt{
\frac{2k}{k-1}
\eta_c^{2/k}
\left(
1-\eta_c^{(k-1)/k}
\right)
}
\tag{22}
$
<span id="eq-gas-choked-b"></span>
$
B=
1+
\frac{
(\eta_c-\eta_a)\eta_c^{1/k}
}{
K_n^2
}
\tag{23}
$
<span id="eq-gas-choked-cd"></span>
$
C_d=
\frac{
B-
\sqrt{
B^2-
\left(2\eta_c^{1/k}\right)^2
(1-\eta_a)
\frac{f}{K_n^2}
}
}{
2f\eta_c^{1/k}
}
\tag{24}
$
For unchoked gas flow, the Jobson coefficient uses:
<span id="eq-gas-unchoked-kn"></span>
$
K_n=
\sqrt{
\frac{2k}{k-1}
\eta_a^{2/k}
\left(
1-\eta_a^{(k-1)/k}
\right)
}
\tag{25}
$
<span id="eq-gas-unchoked-cd"></span>
$
C_d=
\frac{
1-
\sqrt{
1-
\left(2\eta_a^{1/k}\right)^2
(1-\eta_a)
\frac{f}{K_n^2}
}
}{
2f\eta_a^{1/k}
}
\tag{26}
$
## Orifice Mass Rate and Velocity
The leak area is:
<span id="eq-gas-leak-area"></span>
$
A=\frac{\pi d^2}{4}
\tag{27}
$
The gas mass flow rate uses the HDI mass flux from [Equation 15](#eq-gas-orifice-state), the selected discharge coefficient from [Equation 24](#eq-gas-choked-cd) or [Equation 26](#eq-gas-unchoked-cd), and the area from [Equation 27](#eq-gas-leak-area):
<span id="eq-gas-mdot"></span>
$
\dot{m}=G_oC_dA
\tag{28}
$
The vena-contracta velocity is:
<span id="eq-gas-orifice-velocity"></span>
$
U_o=\frac{\dot{m}}{\rho_oC_dA}
\tag{29}
$
The orifice vapor quality is evaluated from the same isentropic entropy basis used in [Equation 3](#eq-gas-storage-entropy):
<span id="eq-gas-orifice-quality"></span>
$
X_o=\operatorname{clamp}\left(Q(P_o,s_0),0,1\right)
\tag{30}
$
When pressure-quality lookup is not meaningful for the state, the implementation reports:
<span id="eq-gas-orifice-quality-fallback"></span>
$
X_o=1
\tag{31}
$
## Gas Expansion
`GasDischarge` next calls `GasExpansion`. If the orifice pressure is at or below atmospheric pressure within the 1 Pa numerical tolerance, no expansion is applied:
<span id="eq-gas-no-expansion"></span>
$
P_o\le P_a+1\ \mathrm{Pa}
\Rightarrow
(P_f,T_f,U_f,d_f,\rho_f)=(P_o,T_o,U_o,d,\rho_o)
\tag{32}
$
For underexpanded jets, the final pressure is atmospheric:
<span id="eq-gas-expanded-pressure"></span>
$
P_f=P_a
\tag{33}
$
The orifice enthalpy is resolved at the orifice state:
<span id="eq-gas-orifice-enthalpy"></span>
$
h_o=h(P_o,s_0)
\tag{34}
$
If the orifice equilibrium state is two phase, the liquid fraction is:
<span id="eq-gas-orifice-liquid-fraction"></span>
$
L_o=1-X_o
\tag{35}
$
The stagnation enthalpy diagnostic is:
<span id="eq-gas-orifice-stagnation-enthalpy"></span>
$
h_{0,o}=h_o+\frac{1}{2}U_o^2
\tag{36}
$
### Isentropic Expansion Option
The isentropic expansion option conserves entropy:
<span id="eq-gas-isentropic-entropy"></span>
$
s_f=s_0
\tag{37}
$
For a two-phase final state with vapor quality $X_f$, homogeneous mixture density is:
<span id="eq-gas-two-phase-density"></span>
$
\rho_f=
\left(
\frac{1-X_f}{\rho_l}+
\frac{X_f}{\rho_v}
\right)^{-1}
\tag{38}
$
The corresponding homogeneous mixture enthalpy is:
<span id="eq-gas-two-phase-enthalpy"></span>
$
h_f=(1-X_f)h_l+X_fh_v
\tag{39}
$
The isentropic final velocity is calculated from the energy balance using [Equation 34](#eq-gas-orifice-enthalpy):
<span id="eq-gas-isentropic-velocity"></span>
$
U_f=
\sqrt{
\max\left(
0,\,
U_o^2+2(h_o-h_f)
\right)
}
\tag{40}
$
### Conservation-of-Momentum Expansion Option
The momentum expansion option first calculates the orifice mass flux:
<span id="eq-gas-momentum-mass-flux"></span>
$
G_{\mathrm{mom}}=\rho_oU_o
\tag{41}
$
The final velocity is:
<span id="eq-gas-momentum-velocity"></span>
$
U_f=
U_o+
\frac{P_o-P_a}{\rho_oU_o}
\tag{42}
$
The final enthalpy is then calculated from the energy balance:
<span id="eq-gas-momentum-enthalpy"></span>
$
h_f=
h_o-
\frac{1}{2}
\left(
U_f^2-U_o^2
\right)
\tag{43}
$
The atmospheric state is then flashed isenthalpically at $P_a$ using [Equation 43](#eq-gas-momentum-enthalpy). If the state is two phase, [Equation 38](#eq-gas-two-phase-density) is used for density.
### Closest-to-Initial Selection
The default `ClosestToInitialConditions` method evaluates both [Equation 40](#eq-gas-isentropic-velocity) and [Equation 42](#eq-gas-momentum-velocity). The selected state is the one with the higher final temperature:
<span id="eq-gas-closest-temperature"></span>
$
\mathrm{selected}=
\underset{m\in\{\mathrm{isentropic},\mathrm{momentum}\}}{\arg\max}\ T_{f,m}
\tag{44}
$
When final temperatures are equal within tolerance, the tie is broken by the final liquid fraction closest to [Equation 35](#eq-gas-orifice-liquid-fraction):
<span id="eq-gas-closest-liquid-fraction"></span>
$
\mathrm{selected}=
\underset{m}{\arg\min}\,
\left|
(1-X_{f,m})-L_o
\right|
\tag{45}
$
## Velocity Cap and Expanded Diameter
After the expansion state is selected, `GasExpansion` may cap the reported velocity. If the real-gas speed of sound is available, it is used:
<span id="eq-gas-real-sonic"></span>
$
a=a(T_f,P_a)
\tag{46}
$
If [Equation 46](#eq-gas-real-sonic) is unavailable for a single-phase state, the ideal-gas fallback is:
<span id="eq-gas-ideal-sonic"></span>
$
a=
\sqrt{
k\frac{\bar{R}}{MW}T_f
}
\tag{47}
$
The reported velocity is:
<span id="eq-gas-reported-velocity"></span>
$
U_{\mathrm{rep}}=
\min(U_f,U_{\max},a)
\tag{48}
$
FX-EML enables one cap mode at a time. **Fixed Velocity** includes $U_{\max}$ and disables the sonic cap; **Sonic Velocity** includes an available $a$ and removes the user cap. The sonic cap is unavailable for a two-phase state with $0<X_f<1$. Capping does not recalculate temperature or equilibrium. The default fixed cap is effectively inactive at ordinary release velocities.
The expanded diameter is recomputed from continuity using [Equation 28](#eq-gas-mdot) and [Equation 48](#eq-gas-reported-velocity):
<span id="eq-gas-expanded-diameter"></span>
$
d_f=
\sqrt{
\frac{4\dot{m}}{\pi\rho_fU_{\mathrm{rep}}}
}
\tag{49}
$
The expanded gas and liquid mass flow rates are:
<span id="eq-gas-expanded-gas-mdot"></span>
$
\dot{m}_{g,f}=X_f\dot{m}
\tag{50}
$
<span id="eq-gas-expanded-liquid-mdot"></span>
$
\dot{m}_{l,f}=(1-X_f)\dot{m}
\tag{51}
$
## FX-EML Release Duration and Final Airborne Mass
For positive discharge rate, the effective duration is:
$
t_r=\min\left(60t_{\max,\mathrm{min}},\frac{M_0}{\dot m}\right).
\tag{52}
$
The gas branch currently does not invoke GDM (Generalized Dispersion Model), atomization, or a rainout pool. Therefore:
$
\dot m_{r,\mathrm{final}}=0,\quad \dot m_{p,\mathrm{pickup}}=0,\quad \dot m_{\mathrm{air}}=\dot m,
\tag{53}
$
$
M_{\mathrm{air}}=\dot m t_r=\min\left(\dot m\,60t_{\max,\mathrm{min}},M_0\right).
\tag{54}
$
The common FX-EML mass equation is $M_{\mathrm{air}}=(\dot m-\dot m_{r,\mathrm{final}}+\dot m_{p,\mathrm{pickup}})t_r$; the extra terms are supplied only by the liquid/GDM chain. Surface and pool-area settings do not affect gas-path mass.
Gas expansion can report condensed liquid in Equation 51. **FX-EML still treats the full gas-path rate as airborne**: it does not create droplets or calculate rainout for that condensate. Its summary labels the full rate “Flash Rate” and reports zero aerosol contribution. This is an application convention, not a statement that the expanded phase must be entirely vapor.
Equations 52–54 apply to positive flow. For $P_0\le P_a$, the engine returns zero flow. The application still divides inventory by rate to determine duration: positive inventory and zero rate give zero airborne mass under its floating-point calculation, but simultaneous zero inventory and zero rate are an undefined numerical edge case.
## Results and Failure Handling
FX-EML retains `GasDischargeResults`, storage inventory, final airborne rate and mass, and timestamp in memory for reporting and consequence calculations. Results are not saved in the project file. Property, discharge, or license failures return failure without replacing an existing successful source result.
## Notes and Assumptions
- Source pressure is absolute pressure.
- The leak area in [Equation 27](#eq-gas-leak-area) assumes a circular opening.
- HDI mass flux is based on isentropic equilibrium thermodynamic properties from the selected backend.
- The discharge coefficient is selected from [Equation 24](#eq-gas-choked-cd) or [Equation 26](#eq-gas-unchoked-cd) based on [Equation 19](#eq-gas-critical-pressure).
- Velocity capping changes the reported expanded velocity and diameter in [Equation 48](#eq-gas-reported-velocity) and [Equation 49](#eq-gas-expanded-diameter); it does not re-flash the expanded thermodynamic state after kinetic energy removal.
- Two-phase expansion states use homogeneous equilibrium mixture density and enthalpy.
## Implementation Trace
Reviewed against `FX-EML/Services/DischargeSolver.cs` and the adjacent Infer project's `Infer.Discharge/PhaseClassifier.cs`, `GasDischarge.cs`, `Discharge.cs` (integration and contraction coefficients), and `GasExpansion.cs`. Existing equation anchors are retained for help links. This is an implementation description, not a claim of numerical validation against an external program.