Pipe flow, pump sizing, friction factor, and compressible flow calculations
The fluids library is a comprehensive Python package for mechanical and chemical engineers working with fluid flow problems. It provides validated correlations and functions for:
The library implements over 100 correlations from the literature with extensive validation against published test cases.
pip install fluids
For full functionality including optimization routines:
pip install fluids[complete]
Core utilities and dimensional analysis functions.
Friction factor calculations for pipe flow including:
Pump performance calculations:
Compressible flow calculations:
Pressure drop through valves, fittings, and pipe components.
The Reynolds number (Re) determines flow regime and is fundamental to all pipe flow calculations.
from fluids.core import Reynolds
# For pipe flow: Re = ρVD/μ
Re = Reynolds(V=2.5, D=0.05, rho=1000, mu=0.001)
# Result: 125000 (turbulent flow)
# Interpretation:
# Re < 2300: Laminar flow
# 2300 < Re < 4000: Transition
# Re > 4000: Turbulent flow
The friction factor (f) is used in the Darcy-Weisbach equation: ΔP = f(L/D)(ρV²/2)
from fluids.friction import friction_factor
# Colebrook-White correlation (implicit, most accurate)
f = friction_factor(Re=125000, eD=0.0001) # eD = roughness/diameter
# Result: ~0.0178
# Moody correlation (explicit approximation)
from fluids.friction import friction_factor_Moody
f_moody = friction_factor_Moody(Re=125000, eD=0.0001)
# For laminar flow (Re < 2300):
f_laminar = friction_factor(Re=1500, eD=0.0001)
# Result: 0.0427 (f = 64/Re)
Calculate pressure drop and head loss in piping systems.
from fluids.friction import friction_factor, head_from_P
from fluids.core import Reynolds
# Given: Water flow through steel pipe
D = 0.1 # m, pipe diameter
L = 100 # m, pipe length
V = 2.0 # m/s, velocity
rho = 1000 # kg/m³, density
mu = 0.001 # Pa·s, viscosity
epsilon = 0.000045 # m, roughness (steel)
# Step 1: Calculate Reynolds number
Re = Reynolds(V=V, D=D, rho=rho, mu=mu)
# Step 2: Calculate friction factor
eD = epsilon / D
f = friction_factor(Re=Re, eD=eD)
# Step 3: Calculate pressure drop
# Darcy-Weisbach: ΔP = f(L/D)(ρV²/2)
dP = f * (L/D) * (rho * V**2 / 2)
# Step 4: Convert to head loss
h_loss = head_from_P(dP, rho) # meters of fluid
print(f"Reynolds: {Re:.0f}")
print(f"Friction factor: {f:.5f}")
print(f"Pressure drop: {dP:.0f} Pa")
print(f"Head loss: {h_loss:.2f} m")
Relate pump performance at different speeds and impeller diameters.
from fluids.pump import affinity_law_volume, affinity_law_head, affinity_law_power
# Original pump operating point
Q1 = 100 # m³/h, flow rate
H1 = 50 # m, head
P1 = 20 # kW, power
N1 = 1450 # rpm, speed
D1 = 0.3 # m, impeller diameter
# New speed
N2 = 1750 # rpm
# Affinity laws (constant impeller diameter):
# Q2/Q1 = N2/N1
# H2/H1 = (N2/N1)²
# P2/P1 = (N2/N1)³
Q2 = affinity_law_volume(Q1, N1, N2)
H2 = affinity_law_head(H1, N1, N2)
P2 = affinity_law_power(P1, N1, N2)
print(f"New flow: {Q2:.1f} m³/h")
print(f"New head: {H2:.1f} m")
print(f"New power: {P2:.1f} kW")
Specific speed (Ns) characterizes pump type and efficiency.
from fluids.pump import specific_speed
# Pump operating conditions
Q = 0.05 # m³/s, flow rate
H = 40 # m, head
N = 1450 # rpm, rotational speed
# Calculate specific speed (dimensionless)
Ns = specific_speed(Q, H, N)
# Interpretation:
# Ns < 0.5: Centrifugal (radial flow)
# 0.5 < Ns < 1.0: Francis (mixed flow)
# 1.0 < Ns < 4.0: Propeller (axial flow)
print(f"Specific speed: {Ns:.2f}")
if Ns < 0.5:
pump_type = "Centrifugal (radial flow)"
elif Ns < 1.0:
pump_type = "Francis (mixed flow)"