Fluids

Overview

Fluid mechanics is the branch of physics and engineering concerned with the behavior of fluids (liquids and gases) at rest and in motion. It provides the theoretical foundation for understanding and predicting fluid flow, pressure distribution, drag forces, and heat transfer in countless engineering applications—from pipelines and HVAC systems to aircraft design and chemical processing.

At its core, fluid mechanics combines conservation principles (mass, momentum, and energy) with empirical correlations to solve practical problems. These problems span multiple scales: from predicting atmospheric density at 80 km altitude, to sizing industrial control valves, to calculating pressure drop in miles of natural gas pipeline.

This collection of Python functions provides engineering-grade implementations for critical domains: atmospheric modeling, compressible flow, control valve design, dimensionless numbers, drag analysis, and pipe friction.

Figure 1: Fundamental fluid mechanics relationships: (Left) The Moody diagram showing friction factor dependence on Reynolds number and roughness; (Center) Standard atmospheric temperature and pressure profiles; (Right) The sphere drag coefficient curve illustrating the Stokes regime and the drag crisis.

Atmospheric Modeling

The atmosphere is a complex, stratified fluid system where temperature, pressure, and density vary dramatically with altitude. Accurate atmospheric models are essential for aerospace engineering, satellite trajectory prediction, and high-altitude telecommunications.

  • Standard atmosphere models like the U.S. Standard Atmosphere 1976 provide temperature and pressure profiles from sea level to 1000 km altitude. These models divide the atmosphere into distinct layers (troposphere, stratosphere, mesosphere, etc.) with different temperature gradients.
  • NRLMSISE-00 is a more sophisticated empirical model developed by the Naval Research Laboratory that accounts for solar activity, geographic location, and time-of-day effects. It’s the current standard for satellite drag calculations and atmospheric re-entry analysis.
  • Airmass calculations quantify the optical path length through the atmosphere at various angles, crucial for astronomical observations and solar radiation modeling. See AIRMASS.

The ATMOSPHERE_1976 function implements the standard model, while ATMOS_NRLMSISE00 provides the advanced capability for mission-critical aerospace applications.

Control Valve Sizing and Acoustics

Control valves regulate fluid flow in industrial processes by varying the flow resistance. Proper valve sizing is critical—an undersized valve cannot provide adequate flow capacity, while an oversized valve operates near closure where control is unstable and wear is accelerated.

Valve sizing follows international standards like IEC 60534, which define the relationship between flow rate, pressure drop, and the valve flow coefficient (K_v or C_v). The calculations differ significantly between liquids and gases:

  • Liquid valves must account for cavitation (formation of vapor bubbles when pressure drops below saturation pressure) and choked flow. The SIZE_CV_LIQUID function handles these phenomena using pressure recovery factors (F_L) and valve style modifiers.
  • Gas valves require compressibility corrections and may experience sonic (choked) flow when the pressure ratio exceeds critical limits. SIZE_CV_GAS implements the full thermodynamic model with real gas effects.

Valve noise is a major concern in industrial facilities, potentially causing hearing damage, structural vibration, and equipment fatigue. The IEC 60534-8 standards provide detailed methods to predict A-weighted sound pressure levels:

  • CV_NOISE_LIQ_2015 calculates liquid valve noise according to IEC 60534-8-4:2015, accounting for cavitation, mechanical vibration transmission through pipe walls, and hydrodynamic noise.
  • CV_NOISE_GAS_2011 predicts gas valve noise per IEC 60534-8-3:2011, modeling shock cell structure in turbulent jets and acoustic transmission.

These calculations require detailed valve geometry, fluid properties, and piping configuration—inputs typically provided by valve manufacturers.

Dimensionless Numbers

Dimensionless numbers are ratios of physical forces or rates that characterize fluid flow regimes. They enable scaling laws, allowing laboratory experiments to predict full-scale behavior, and determine which terms in the governing equations dominate.

Key dimensionless numbers include:

  • Reynolds number (Re = \rho V D / \mu): Ratio of inertial to viscous forces. The most important parameter in fluid mechanics, it distinguishes laminar flow (Re < 2300 in pipes) from turbulent flow (Re > 4000). Functions like DEAN extend Reynolds number concepts to curved geometries.

  • Froude number (Fr = V / \sqrt{gL}): Ratio of inertial to gravitational forces. Critical for free-surface flows (rivers, ship wakes, hydraulic jumps). See FROUDE.

  • Bond number (Bo = \Delta \rho g L^2 / \sigma): Ratio of gravitational to surface tension forces, determining whether bubbles or droplets remain spherical. Calculated by BOND.

  • Weber number, Capillary number**: Additional surface tension effects in atomization and porous media flow (see CAPILLARY).

  • Mach number, Eckert number**: Compressibility and viscous heating in high-speed gas flows. ECKERT quantifies the conversion of kinetic energy to thermal energy.

  • Heat and mass transfer numbers: FOURIER_HEAT and FOURIER_MASS characterize transient diffusion processes.

  • Other key numbers: The Archimedes number (ARCHIMEDES) characterizes particle motion in fluids, while the Cavitation number (CAVITATION) predicts phase change in low-pressure regions.

These numbers appear in empirical correlations (e.g., Nusselt number for heat transfer) and provide immediate physical insight into flow behavior.

Pipe Friction and Pressure Drop

Predicting pressure drop in pipes is fundamental to designing fluid distribution systems, from water networks to oil pipelines. The challenge lies in accurately determining the friction factor—a dimensionless parameter that depends on Reynolds number and relative pipe roughness.

Friction factor correlations have evolved over a century of research:

  • Darcy-Weisbach equation: \Delta p = f \frac{L}{D} \frac{\rho V^2}{2}, where f is the friction factor. Universal formula applicable to all Newtonian fluids and flow regimes.

  • Laminar flow (Re < 2300): Exact analytical solution f = 64/Re. See FRICTION_LAMINAR.

  • Turbulent flow: No exact solution exists. The Colebrook equation (implicit, iterative) is considered most accurate. COLEBROOK and CLAMOND provide solutions.

  • Explicit approximations: Avoid iteration with slight accuracy trade-offs. Popular options include Swamee-Jain, Haaland, Churchill, and Moody.

The FRICTION_FACTOR function automatically selects the appropriate method based on flow regime, while ONE_PHASE_DP directly calculates pressure drop for single-phase flows. For non-horizontal pipes, DP_GRAV calculates the hydrostatic pressure change due to elevation.

Special geometries require modified correlations:

Compressible Flow

Compressible flow deals with fluids (typically gases) where density changes significantly with pressure and temperature. This is critical for high-speed aerodynamics and long-distance gas transmission.

  • Pipeline Flow: Specialized empirical equations like PANHANDLE_A, PANHANDLE_B, and WEYMOUTH_FLOW are used for sizing natural gas transmission lines.
  • Isentropic and Polytropic Processes: For gas compression and expansion, functions like ISENTROPIC_WORK and POLYTROPIC_EXP calculate the energy requirements and efficiency transitions.
  • Stagnation Properties: When a fluid is brought to rest, its kinetic energy is converted to internal energy. Functions like P_STAGNATION and T_STAGNATION calculate these reference states.
  • Choked Flow: In many industrial relief systems, flow becomes “choked” when it reaches the speed of sound. IS_CHOKED_FLOW determines if this critical condition is met.

Drag and Terminal Velocity

Drag is the force acting opposite to the relative motion of any object moving with respect to a surrounding fluid.

  • Drag Coefficients: The DRAG_SPHERE function provides a unified interface to dozens of correlations (like CD_MORRISON or CD_ALMEDEIJ) for predicting the drag on spherical particles across all Reynolds numbers.
  • Terminal Velocity: For particles settling in a fluid, the V_TERMINAL function calculates the steady-state velocity where drag and buoyancy balance gravity—a fundamental calculation in wastewater treatment and chemical processing.

Fittings, Filters, and Flow Measurement

Real-world piping systems consist of more than just straight pipe; they include elbows, tees, valves, and meters that introduce additional pressure losses.

  • Loss Coefficients (K): The “K-factor” method quantifies the resistance of fittings. Functions like K_GATE_VALVE and BEND_ROUNDED implement the Crane Technical Paper 410 methods.
  • Filters and Screens: Perforated plates, wire meshes, and grills introduce pressure drops that depend on their open area ratio and edge geometry. Functions like SQ_EDGE_SCREEN and RND_EDGE_GRILL provide loss coefficients for these components.
  • Flow Meters: Differential pressure meters (orifice plates, venturis) are the most common industrial flow measurement devices. ORIFICE_DISCHARGE_C implements the rigorous ISO 5167 standard for discharge coefficients.
  • Coefficient Conversion: Engineers often need to convert between metric K_v, imperial C_v, and dimensionless K. Functions like CV_TO_K and K_TO_KV handle these conversions accurately.

Native Excel Capabilities

Excel offers limited built-in support for fluid mechanics calculations:

  • Formulas: Users can manually implement basic equations (Bernoulli, Reynolds number, Darcy-Weisbach) using standard arithmetic and lookup functions. This requires finding and encoding correlations from handbooks or literature.

  • Solver Add-in: Can solve implicit equations like the Colebrook equation by iterating to find the friction factor that satisfies f = f(Re, \varepsilon/D, f). However, this is manual, slow, and error-prone for large datasets.

  • No native fluid property database: Excel lacks built-in access to temperature-dependent viscosity, density, or thermodynamic properties, forcing users to manually enter data or build lookup tables.

  • No standard atmosphere models: Atmospheric calculations require custom VBA code or extensive manual interpolation of tabulated data.

The Python functions in this library provide validated, peer-reviewed implementations of complex correlations (like NRLMSISE-00 or IEC 60534 valve noise) that would take weeks to properly implement and verify in Excel. They handle edge cases, unit conversions, and numerical stability automatically.

Third-party Excel add-ins

Several commercial and open-source add-ins extend Excel’s fluid mechanics capabilities:

  • AFT Fathom / Arrow: Industry-standard software for incompressible and compressible pipe flow analysis. While standalone, they offer Excel integration for data input and results reporting.

  • PIPE-FLO: A comprehensive fluid flow analysis and design tool that allows users to model entire piping systems and integrate with Excel for automated calculations.

  • NIST REFPROP: The industry standard for high-accuracy thermophysical fluid properties. While a paid product, it is the gold standard for refrigerant and hydrocarbon properties.

  • FluidFlow: Comprehensive pipe network analysis software with Excel integration. Models single-phase and two-phase flows, pump systems, and compressible gases.

  • CoolProp Excel Add-in: Open-source thermodynamic property library providing access to fluid properties (density, viscosity, enthalpy, etc.) for 100+ pure fluids and mixtures. Essential for accurate fluid mechanics calculations.

  • DNV Synergi Gas: Specialized for natural gas network modeling and simulation, often used in utility-scale pipeline engineering.

  • Engineers Edge: Provides a wide array of online calculators and Excel templates for fluid flow, pressure drop, and heat transfer.

While these tools are valuable, they typically operate as “black boxes” with limited transparency into the underlying calculations. The Python functions in this library provide full source code visibility and can be easily integrated into automated workflows, web applications, or cloud-based engineering platforms.

Atmosphere

Tool Description
AIRMASS Calculate the mass of air per square meter in the atmosphere along a given angle using a density profile.
ATMOS_NRLMSISE00 Compute temperature, density, and pressure using the NRLMSISE-00 atmospheric model.
ATMOSPHERE_1976 Calculate standard atmospheric properties at a given altitude using the US Standard Atmosphere 1976 model.

Compressible

Tool Description
FRITZSCHE_FLOW Calculate gas flow rate using the Fritzsche formula.
IGT_FLOW Calculate gas flow rate using the IGT (Institute of Gas Technology) formula.
IS_CHOKED_FLOW Determine if a flow is choked (critical) based on pressure ratio.
ISENTROPIC_EFF Convert between isentropic and polytropic efficiency for compression.
ISENTROPIC_T_RISE Calculate the temperature rise for isentropic compression or expansion.
ISENTROPIC_WORK Calculate work of compression or expansion for a gas in an isentropic process.
ISOTHERMAL_GAS Calculate mass flow rate for isothermal compressible gas flow in a pipe.
ISOTHERMAL_WORK Calculate work of compression or expansion for a gas in an isothermal process.
MULLER_FLOW Calculate gas flow rate using the Muller formula.
P_CRITICAL_FLOW Calculate critical flow pressure for a fluid at Mach 1.
P_STAGNATION Calculate stagnation pressure from static conditions.
PANHANDLE_A Calculate gas flow rate in a pipeline using the Panhandle A formula.
PANHANDLE_B Calculate gas flow rate in a pipeline using the Panhandle B formula.
POLYTROPIC_EXP Calculate polytropic exponent or polytropic efficiency for compression.
STAGNATION_ENERGY Calculate the increase in enthalpy due to fluid velocity.
T_CRITICAL_FLOW Calculate critical flow temperature for a fluid at Mach 1.
T_STAG_IDEAL Calculate ideal stagnation temperature from velocity and heat capacity.
T_STAGNATION Calculate stagnation temperature from pressure ratio.
WEYMOUTH_FLOW Calculate gas flow rate in a pipeline using the Weymouth formula.

Control Valve

Tool Description
CV_CAV_INDEX Calculates the cavitation index of a control valve.
CV_CHAR_EQ_PERC Calculates the flow coefficient characteristic for an equal percentage control valve.
CV_CHAR_LINEAR Calculates the flow coefficient characteristic for a linear control valve.
CV_CHAR_QUICK_OP Calculates the flow coefficient characteristic for a quick opening control valve.
CV_CHOKE_PRESS_GAS Calculates the pressure at which choked flow occurs in a gas control valve.
CV_CHOKE_PRESS_LIQ Calculates the pressure at which choked flow occurs in a liquid control valve.
CV_CONVERT_COEFF Converts between different flow coefficient scales (Kv, Cv, Av).
CV_NOISE_GAS_2011 Calculate the A-weighted sound pressure level for gas flow through a control valve per IEC 60534-8-3 (2011).
CV_NOISE_LIQ_2015 Calculates the sound made by a liquid flowing through a control valve according to the standard IEC 60534-8-4 (2015) using fluids.control_valve.control_valve_noise_l_2015.
FF_CRIT_PRESS_L Calculates FF, the liquid critical pressure ratio factor, for use in IEC 60534 liquid valve sizing calculations using fluids.control_valve.FF_critical_pressure_ratio_l. See https://fluids.readthedocs.io/fluids.control_valve.html#fluids.control_valve.FF_critical_pressure_ratio_l for details.
IS_CHOKED_GAS Determines if a gas flow in a control valve is choked (critical) or not according to IEC 60534.
IS_CHOKED_LIQ Determines if a liquid flow in a control valve is choked (critical) or not according to IEC 60534.
LOSS_COEFF_PIPING Calculates the sum of loss coefficients for reducers/expanders around a control valve.
REYNOLDS_FACTOR Calculates the Reynolds number factor FR for a valve according to IEC 60534.
REYNOLDS_VALVE Calculates the Reynolds number of a control valve according to IEC 60534.
SIZE_CV_GAS Calculates flow coefficient of a control valve passing a gas according to IEC 60534 using fluids.control_valve.size_control_valve_g.
SIZE_CV_LIQUID Calculates the flow coefficient (Kv) of a control valve passing a liquid according to IEC 60534.

Dimensionless

Tool Description
ARCHIMEDES Calculate the Archimedes number (Ar) for a fluid and particle.
BEJAN Compute the Bejan number (length-based or permeability-based).
BOILING Calculate the Boiling number (Bg), a dimensionless number for boiling heat transfer.
BOND Calculate the Bond number using fluids.core.Bond.
CAPILLARY Calculate the Capillary number (Ca) for a fluid system using fluids.core.Capillary.
CAVITATION Calculate the Cavitation number (Ca) for a flowing fluid.
CONFINEMENT Calculate the Confinement number (Co) for two-phase flow in a channel.
DEAN Calculate the Dean number (De) for flow in a curved pipe or channel.
DRAG Calculate the drag coefficient (dimensionless) for an object in a fluid.
ECKERT Calculate the Eckert number using fluids.core.Eckert.
EULER Calculate the Euler number (Eu) for a fluid flow.
FOURIER_HEAT Calculate the Fourier number for heat transfer.
FOURIER_MASS Calculate the Fourier number for mass transfer (Fo).
FROUDE Calculate the Froude number (Fr) for a given velocity, length, and gravity.

Drag

Tool Description
CD_ALMEDEIJ Calculate drag coefficient of a sphere using the Almedeij correlation.
CD_BARATI Calculate drag coefficient of a sphere using the Barati correlation.
CD_BARATI_HIGH Calculate drag coefficient of a sphere using the Barati high-Re correlation (valid to Re=1E6).
CD_CEYLAN Calculate drag coefficient of a sphere using the Ceylan correlation.
CD_CHENG Calculate drag coefficient of a sphere using the Cheng correlation.
CD_CLIFT Calculate drag coefficient of a sphere using the Clift correlation.
CD_CLIFT_GAUVIN Calculate drag coefficient of a sphere using the Clift-Gauvin correlation.
CD_ENGELUND Calculate drag coefficient of a sphere using the Engelund-Hansen correlation.
CD_FLEMMER_BANKS Calculate drag coefficient of a sphere using the Flemmer-Banks correlation.
CD_GRAF Calculate drag coefficient of a sphere using the Graf correlation.
CD_HAIDER_LEV Calculate drag coefficient of a sphere using the Haider-Levenspiel correlation.
CD_KHAN_RICH Calculate drag coefficient of a sphere using the Khan-Richardson correlation.
CD_MIKHAILOV Calculate drag coefficient of a sphere using the Mikhailov-Freire correlation.
CD_MORRISON Calculate drag coefficient of a sphere using the Morrison correlation.
CD_MORSI_ALEX Calculate drag coefficient of a sphere using the Morsi-Alexander correlation.
CD_ROUSE Calculate drag coefficient of a sphere using the Rouse correlation.
CD_SONG_XU Calculate drag coefficient of a particle using the Song-Xu correlation for spherical and non-spherical particles.
CD_STOKES Calculate drag coefficient of a sphere using Stokes law (Cd = 24/Re).
CD_SWAMEE_OJHA Calculate drag coefficient of a sphere using the Swamee-Ojha correlation.
CD_TERFOUS Calculate drag coefficient of a sphere using the Terfous correlation.
CD_YEN Calculate drag coefficient of a sphere using the Yen correlation.
DRAG_SPHERE Calculate the drag coefficient of a sphere using various correlations based on Reynolds number.
SPHERE_FALL_DIST Calculate distance traveled by a falling sphere after a given time.
SPHERE_VEL_AT_T Calculate the velocity of a falling sphere after a given time.
TIME_V_TERMINAL Calculate time for a particle in Stokes regime to reach terminal velocity.
V_TERMINAL Calculate terminal velocity of a falling sphere using drag coefficient correlations.

Filters

Tool Description
RND_EDGE_GRILL Calculate the loss coefficient for a rounded edge grill or perforated plate.
RND_EDGE_MESH Calculate the loss coefficient for a round edged open net or screen mesh.
RND_EDGE_SCREEN Calculate the loss coefficient for a round edged wire screen or bar screen.
SQ_EDGE_GRILL Calculate the loss coefficient for a square edged grill or perforated plate.
SQ_EDGE_SCREEN Calculate the loss coefficient for a square edged wire screen, bar screen, or perforated plate.

Fittings

Tool Description
BEND_MITER Calculate the loss coefficient (K) for a single-joint miter bend in a pipe.
BEND_ROUNDED Calculate the loss coefficient (K) for a rounded pipe bend (elbow) using various methods.
CONTRACTION_ROUND Calculate the loss coefficient (K) for a rounded pipe contraction (reducer).
CONTRACTION_SHARP Calculate the loss coefficient (K) for a sharp edged pipe contraction (reducer).
CV_TO_K Convert imperial valve flow coefficient (Cv) to loss coefficient (K).
DIFFUSER_CONICAL Calculate the loss coefficient (K) for a conical pipe expansion (diffuser).
DIFFUSER_SHARP Calculate the loss coefficient (K) for a sudden pipe expansion (diffuser).
ENTRANCE_ANGLED Calculate the loss coefficient (K) for an angled sharp entrance to a pipe flush with a reservoir wall.
ENTRANCE_BEVELED Calculate the loss coefficient (K) for a beveled or chamfered entrance to a pipe flush with a reservoir wall.
ENTRANCE_ROUNDED Calculate the loss coefficient (K) for a rounded entrance to a pipe flush with a reservoir wall.
ENTRANCE_SHARP Calculate the loss coefficient (K) for a sharp entrance to a pipe flush with a reservoir wall.
EXIT_NORMAL Calculate the loss coefficient (K) for a normal pipe exit discharging into a reservoir.
HELIX Calculate the loss coefficient (K) for a helical coil pipe section.
K_BALL_VALVE Calculate the loss coefficient (K) for a ball valve using the Crane method.
K_BUTTERFLY_VALVE Calculate the loss coefficient (K) for a butterfly valve using the Crane method.
K_GATE_VALVE Calculate the loss coefficient (K) for a gate valve using the Crane method.
K_GLOBE_VALVE Calculate the loss coefficient (K) for a globe valve using the Crane method.
K_SWING_CHECK_VALVE Calculate the loss coefficient (K) for a swing check valve using the Crane method.
K_TO_CV Convert loss coefficient (K) to imperial valve flow coefficient (Cv).
K_TO_KV Convert loss coefficient (K) to metric valve flow coefficient (Kv).
KV_TO_K Convert metric valve flow coefficient (Kv) to loss coefficient (K).
SPIRAL Calculate the loss coefficient (K) for a spiral coil pipe section.

Flow Meter

Tool Description
DIFF_PRESS_BETA Calculate the beta ratio (diameter ratio) for a differential pressure flow meter.
DIFF_PRESS_C_EPS Calculate discharge coefficient and expansibility factor for differential pressure flow meters.
DIFF_PRESS_DP Calculate non-recoverable pressure drop across a differential pressure flow meter.
FLOW_METER_DISCH Calculate mass flow rate through a differential pressure flow meter based on measured pressures and meter geometry.
ORIFICE_DISCHARGE_C Calculate the discharge coefficient for an orifice plate using the Reader-Harris-Gallagher correlation (ISO 5167 standard).
ORIFICE_EXPAND Calculate the expansibility factor for an orifice plate based on geometry and pressure conditions.
ORIFICE_PRESS_DROP Calculate non-recoverable pressure drop across an orifice plate based on geometry and discharge coefficient.

Friction

Tool Description
BLASIUS Calculates Darcy friction factor for turbulent flow in smooth pipes using the Blasius correlation.
CHURCHILL Calculate Darcy friction factor using the Churchill (1977) universal equation for all flow regimes.
CLAMOND Calculate Darcy friction factor using Clamond’s high-precision solution accurate to nearly machine precision.
COLEBROOK Calculate Darcy friction factor using exact solution to the Colebrook equation.
DP_GRAV Calculate gravitational pressure drop component for single-phase flow in inclined pipes.
FF_CURVED Calculate friction factor for fluid flowing in a curved pipe or helical coil, supporting both laminar and turbulent regimes.
FP_MARTIN Calculate Darcy friction factor for single-phase flow in Chevron-style plate heat exchangers using Martin (1999) correlation.
FP_MULEY_MANGLIK Calculate Darcy friction factor for single-phase flow in Chevron-style plate heat exchangers using Muley-Manglik correlation.
FRICTION_FACTOR Calculate the Darcy friction factor for fluid flow in a pipe using various correlations, automatically selecting appropriate method based on Reynolds number and relative roughness.
FRICTION_LAMINAR Calculate the Darcy friction factor for laminar flow using the theoretical solution fd = 64/Re.
FT_CRANE Calculate the Crane fully turbulent Darcy friction factor for flow in commercial pipe.
HAALAND Calculate Darcy friction factor using the Haaland (1983) approximation.
HELICAL_RE_CRIT Calculate the transition Reynolds number for fluid flowing in a curved or helical pipe between laminar and turbulent flow.
MOODY Calculate Darcy friction factor using the Moody (1947) correlation.
ONE_PHASE_DP Calculate single-phase pressure drop in a pipe using the Darcy-Weisbach equation.
SWAMEE_JAIN Calculate Darcy friction factor using the Swamee-Jain (1976) equation.
TRANS_FACTOR Convert between Darcy friction factor and transmission factor for compressible gas pipeline flow.
VON_KARMAN Calculate Darcy friction factor for rough pipes at infinite Reynolds number from the von Karman equation.