FRICTION_FACTOR
Overview
The FRICTION_FACTOR function calculates the Darcy friction factor for fluid flow in a pipe, a dimensionless quantity used in the Darcy-Weisbach equation to determine pressure loss due to friction in pipe systems. This implementation leverages the fluids library, which provides 29 different approximation methods plus an exact solution for computing friction factors across both laminar and turbulent flow regimes.
For laminar flow (Re < 2040), the friction factor follows the well-known relationship:
f_d = \frac{64}{Re}
For turbulent flow, the friction factor depends on both the Reynolds number and the pipe’s relative roughness (ε/D). The classic Colebrook equation, published in 1939, is an implicit equation that requires iterative solution:
\frac{1}{\sqrt{f}} = -2 \log_{10}\left(\frac{\varepsilon/D}{3.7} + \frac{2.51}{Re\sqrt{f}}\right)
The default method, Clamond, provides an explicit solution accurate to nearly machine precision using an efficient algorithm described by Clamond (2009). This method is approximately 4 times faster than solutions using the Lambert W function while maintaining excellent accuracy for Re > 10 and relative roughness values from 0 to 0.01.
The function supports 30+ correlation methods including Churchill (1977), Haaland, Swamee-Jain, and many others, each with different ranges of validity and computational characteristics. For most engineering applications, the default Clamond method is recommended. The function can return either the Darcy friction factor (default) or the Fanning friction factor (1/4 of the Darcy value) by setting the Darcy parameter to False.
For more details on available methods and their validity ranges, see the fluids friction documentation.
This example function is provided as-is without any representation of accuracy.
Excel Usage
=FRICTION_FACTOR(Re, eD, friction_method, Darcy)
Re(float, required): Reynolds number, [-]eD(float, optional, default: 0): Relative roughness (roughness/diameter), [-]friction_method(str, optional, default: “Clamond”): Calculation method for friction factorDarcy(bool, optional, default: true): If true, returns Darcy friction factor; otherwise Fanning factor (1/4 of Darcy)
Returns (float): Friction factor, [-] str: Error message if inputs are invalid.
Examples
Example 1: Laminar flow (Re < 2040)
Inputs:
| Re | eD |
|---|---|
| 1000 | 0 |
Excel formula:
=FRICTION_FACTOR(1000, 0)
Expected output:
0.064
Example 2: Turbulent flow in smooth pipe
Inputs:
| Re | eD |
|---|---|
| 100000 | 0.0001 |
Excel formula:
=FRICTION_FACTOR(100000, 0.0001)
Expected output:
0.0185
Example 3: Turbulent flow with Haaland method
Inputs:
| Re | eD | friction_method |
|---|---|---|
| 100000 | 0.001 | Haaland |
Excel formula:
=FRICTION_FACTOR(100000, 0.001, "Haaland")
Expected output:
0.022
Example 4: Return Fanning friction factor
Inputs:
| Re | eD | Darcy |
|---|---|---|
| 100000 | 0.0001 | false |
Excel formula:
=FRICTION_FACTOR(100000, 0.0001, FALSE)
Expected output:
0.0046
Python Code
import micropip
await micropip.install(["fluids"])
from fluids.friction import friction_factor as fluids_friction_factor
def friction_factor(Re, eD=0, friction_method='Clamond', Darcy=True):
"""
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.
See: https://fluids.readthedocs.io/fluids.friction.html#fluids.friction.friction_factor
This example function is provided as-is without any representation of accuracy.
Args:
Re (float): Reynolds number, [-]
eD (float, optional): Relative roughness (roughness/diameter), [-] Default is 0.
friction_method (str, optional): Calculation method for friction factor Valid options: Clamond, Colebrook, Moody, Churchill_1977, Haaland, Swamee_Jain_1976, Jain_1976, Alshul_1952, Wood_1966, Churchill_1973, Eck_1973, Chen_1979, Round_1980, Shacham_1980, Barr_1981, Zigrang_Sylvester_1, Zigrang_Sylvester_2, Serghides_1, Serghides_2, Tsal_1989, Manadilli_1997, Romeo_2002, Sonnad_Goudar_2006, Rao_Kumar_2007, Buzzelli_2008, Avci_Karagoz_2009, Papaevangelo_2010, Brkic_2011_1, Brkic_2011_2, Fang_2011. Default is 'Clamond'.
Darcy (bool, optional): If true, returns Darcy friction factor; otherwise Fanning factor (1/4 of Darcy) Default is True.
Returns:
float: Friction factor, [-] str: Error message if inputs are invalid.
"""
try:
Re = float(Re)
eD = float(eD)
friction_method = str(friction_method)
Darcy = bool(Darcy)
except (ValueError, TypeError):
return "Error: Could not convert parameters to required types."
# Validate Reynolds number
if Re <= 0:
return "Error: Reynolds number must be positive."
# Validate relative roughness
if eD < 0:
return "Error: Relative roughness must be non-negative."
try:
result = fluids_friction_factor(Re=Re, eD=eD, Method=friction_method, Darcy=Darcy)
# 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 friction_factor: {str(e)}"