PANHANDLE_A
Overview
Calculate gas flow rate in a pipeline using the Panhandle A formula.
Excel Usage
=PANHANDLE_A(sg, temp_avg, length, diameter, p_inlet, p_outlet, comp_factor, efficiency)
sg(float, required): Specific gravity of gas relative to air [-]temp_avg(float, required): Average temperature of gas in pipeline [K]length(float, required): Length of pipe [m]diameter(float, required): Diameter of pipe [m]p_inlet(float, required): Inlet pressure [Pa]p_outlet(float, required): Outlet pressure [Pa]comp_factor(float, optional, default: 1): Average compressibility factor [-]efficiency(float, optional, default: 1): Pipeline efficiency factor [-]
Returns (float): Gas flow rate at reference conditions [m³/s]
Examples
Example 1: Standard natural gas pipeline
Inputs:
| sg | temp_avg | length | diameter | p_inlet | p_outlet |
|---|---|---|---|---|---|
| 0.693 | 277.15 | 160000 | 0.34 | 9000000 | 2000000 |
Excel formula:
=PANHANDLE_A(0.693, 277.15, 160000, 0.34, 9000000, 2000000)
Expected output:
46.261761426042696
Example 2: Short pipeline section
Inputs:
| sg | temp_avg | length | diameter | p_inlet | p_outlet |
|---|---|---|---|---|---|
| 0.65 | 290 | 10000 | 0.5 | 5000000 | 4500000 |
Excel formula:
=PANHANDLE_A(0.65, 290, 10000, 0.5, 5000000, 4500000)
Expected output:
126.73065254006985
Example 3: Pipeline with 92% efficiency
Inputs:
| sg | temp_avg | length | diameter | p_inlet | p_outlet | efficiency |
|---|---|---|---|---|---|---|
| 0.7 | 280 | 50000 | 0.4 | 7000000 | 3000000 | 0.92 |
Excel formula:
=PANHANDLE_A(0.7, 280, 50000, 0.4, 7000000, 3000000, 0.92)
Expected output:
84.81141033072883
Example 4: Large diameter pipeline
Inputs:
| sg | temp_avg | length | diameter | p_inlet | p_outlet |
|---|---|---|---|---|---|
| 0.6 | 285 | 100000 | 1 | 8000000 | 4000000 |
Excel formula:
=PANHANDLE_A(0.6, 285, 100000, 1, 8000000, 4000000)
Expected output:
819.5524717631372
Python Code
import micropip
await micropip.install(["fluids"])
from fluids.compressible import Panhandle_A as fluids_panhandle_a
def panhandle_a(sg, temp_avg, length, diameter, p_inlet, p_outlet, comp_factor=1, efficiency=1):
"""
Calculate gas flow rate in a pipeline using the Panhandle A formula.
See: https://fluids.readthedocs.io/fluids.compressible.html#fluids.compressible.Panhandle_A
This example function is provided as-is without any representation of accuracy.
Args:
sg (float): Specific gravity of gas relative to air [-]
temp_avg (float): Average temperature of gas in pipeline [K]
length (float): Length of pipe [m]
diameter (float): Diameter of pipe [m]
p_inlet (float): Inlet pressure [Pa]
p_outlet (float): Outlet pressure [Pa]
comp_factor (float, optional): Average compressibility factor [-] Default is 1.
efficiency (float, optional): Pipeline efficiency factor [-] Default is 1.
Returns:
float: Gas flow rate at reference conditions [m³/s]
"""
# Validate and convert inputs
try:
sg = float(sg)
except (ValueError, TypeError):
return "Invalid input: sg must be a number."
try:
temp_avg = float(temp_avg)
except (ValueError, TypeError):
return "Invalid input: temp_avg must be a number."
try:
length = float(length)
except (ValueError, TypeError):
return "Invalid input: length must be a number."
try:
diameter = float(diameter)
except (ValueError, TypeError):
return "Invalid input: diameter must be a number."
try:
p_inlet = float(p_inlet)
except (ValueError, TypeError):
return "Invalid input: p_inlet must be a number."
try:
p_outlet = float(p_outlet)
except (ValueError, TypeError):
return "Invalid input: p_outlet must be a number."
try:
comp_factor = float(comp_factor)
except (ValueError, TypeError):
return "Invalid input: comp_factor must be a number."
try:
efficiency = float(efficiency)
except (ValueError, TypeError):
return "Invalid input: efficiency must be a number."
# Validation
if sg <= 0:
return "Invalid input: sg must be positive."
if temp_avg <= 0:
return "Invalid input: temp_avg must be positive."
if length <= 0:
return "Invalid input: length must be positive."
if diameter <= 0:
return "Invalid input: diameter must be positive."
if p_inlet <= 0:
return "Invalid input: p_inlet must be positive."
if p_outlet < 0:
return "Invalid input: p_outlet must be non-negative."
if p_outlet >= p_inlet:
return "Invalid input: p_outlet must be less than p_inlet."
if comp_factor <= 0:
return "Invalid input: comp_factor must be positive."
if efficiency <= 0 or efficiency > 1:
return "Invalid input: efficiency must be between 0 and 1."
try:
result = fluids_panhandle_a(SG=sg, Tavg=temp_avg, L=length, D=diameter,
P1=p_inlet, P2=p_outlet, Zavg=comp_factor, E=efficiency)
return float(result)
except Exception as e:
return f"Error: Failed to compute Panhandle A flow rate: {str(e)}"