HAALAND
Overview
The HAALAND function calculates the Darcy friction factor for turbulent flow in pipes using the Haaland approximation, an explicit formula developed by Professor S.E. Haaland of the Norwegian Institute of Technology in 1983. The Darcy friction factor is a dimensionless quantity used in the Darcy–Weisbach equation to calculate pressure losses due to friction in pipe flow.
The Haaland equation provides a direct, explicit solution that approximates the implicit Colebrook–White equation, which otherwise requires iterative numerical methods to solve. The formula is expressed as:
\frac{1}{\sqrt{f}} = -1.8 \log_{10} \left[ \left( \frac{\varepsilon / D}{3.7} \right)^{1.11} + \frac{6.9}{\text{Re}} \right]
where f is the Darcy friction factor, \varepsilon / D is the relative roughness (ratio of pipe surface roughness to diameter), and \text{Re} is the Reynolds number.
This implementation uses the fluids library, a comprehensive Python package for fluid dynamics calculations. For more details, see the fluids friction factor documentation.
The Haaland equation is valid for Reynolds numbers between 4 \times 10^3 and 10^8, and relative roughness values between 10^{-6} and 0.05. The discrepancy from the Colebrook equation is typically less than 1.5%, which is well within the accuracy of experimental friction factor data (±5% for smooth pipes, ±10% for rough pipes according to Moody’s original work).
This example function is provided as-is without any representation of accuracy.
Excel Usage
=HAALAND(Re, eD)
Re(float, required): Reynolds number, [-]eD(float, required): Relative roughness, [-]
Returns (float): Darcy friction factor, [-] or str error message if input is invalid.
Examples
Example 1: Smooth pipe with small relative roughness
Inputs:
| Re | eD |
|---|---|
| 100000 | 0.0001 |
Excel formula:
=HAALAND(100000, 0.0001)
Expected output:
0.0183
Example 2: Rough pipe with higher relative roughness
Inputs:
| Re | eD |
|---|---|
| 100000 | 0.01 |
Excel formula:
=HAALAND(100000, 0.01)
Expected output:
0.0385
Example 3: Lower Reynolds number in valid range
Inputs:
| Re | eD |
|---|---|
| 5000 | 0.001 |
Excel formula:
=HAALAND(5000, 0.001)
Expected output:
0.0386
Example 4: Upper Reynolds number in valid range
Inputs:
| Re | eD |
|---|---|
| 10000000 | 0.00001 |
Excel formula:
=HAALAND(10000000, 0.00001)
Expected output:
0.009
Python Code
import micropip
await micropip.install(["fluids"])
from fluids.friction import Haaland as fluids_haaland
def haaland(Re, eD):
"""
Calculate Darcy friction factor using the Haaland (1983) approximation.
See: https://fluids.readthedocs.io/fluids.friction.html#fluids.friction.Haaland
This example function is provided as-is without any representation of accuracy.
Args:
Re (float): Reynolds number, [-]
eD (float): Relative roughness, [-]
Returns:
float: Darcy friction factor, [-] or str error message if input is invalid.
"""
# Validate and convert inputs
try:
Re = float(Re)
except (ValueError, TypeError):
return "Error: Re must be a number."
try:
eD = float(eD)
except (ValueError, TypeError):
return "Error: eD must be a number."
# Validate Reynolds number
if Re <= 0:
return "Error: Re must be positive."
# Validate relative roughness
if eD < 0:
return "Error: eD must be non-negative."
try:
result = fluids_haaland(Re=Re, eD=eD)
# Handle NaN and infinity
if result != result: # NaN check
return "nan"
if result == float('inf'):
return "inf"
if result == float('-inf'):
return "-inf"
return float(result)
except Exception as e:
return f"Error computing haaland: {str(e)}"