MOODY
Overview
The MOODY function calculates the Darcy friction factor for turbulent flow in pipes using the Moody (1947) correlation. The Darcy friction factor is a dimensionless quantity used in the Darcy-Weisbach equation to determine pressure drop due to friction in pipe flow systems.
This implementation uses the fluids library, a comprehensive open-source Python package for fluid dynamics calculations. For more details, see the fluids friction documentation.
The Moody correlation provides an explicit approximation to the implicit Colebrook equation, which is the industry standard for calculating friction factors in turbulent pipe flow. The correlation is expressed as:
f_f = 1.375 \times 10^{-3} \left[ 1 + \left( 2 \times 10^4 \frac{\epsilon}{D} + \frac{10^6}{Re} \right)^{1/3} \right]
where f_f is the Fanning friction factor (the Darcy friction factor f_d = 4f_f), \epsilon/D is the relative roughness (pipe roughness divided by pipe diameter), and Re is the Reynolds number.
The original work was published by Lewis F. Moody, who is best known for creating the Moody chart—a graphical representation of the Colebrook equation widely used in engineering practice. The correlation has a recommended validity range of 4 \times 10^3 \leq Re \leq 10^8 and 0 \leq \epsilon/D < 0.01.
While more accurate methods such as the Clamond algorithm exist for solving the Colebrook equation, the Moody correlation remains useful for quick estimates and educational purposes due to its explicit form.
This example function is provided as-is without any representation of accuracy.
Excel Usage
=MOODY(Re, eD)
Re(float, required): Reynolds number, [-]eD(float, required): Relative roughness, [-]
Returns (float): Darcy friction factor, [-], or error message (str) if input is invalid.
Examples
Example 1: Smooth pipe (eD=0) at high Reynolds number
Inputs:
| Re | eD |
|---|---|
| 100000 | 0 |
Excel formula:
=MOODY(100000, 0)
Expected output:
0.0173
Example 2: Smooth pipe (eD=0) at lower Reynolds number
Inputs:
| Re | eD |
|---|---|
| 10000 | 0 |
Excel formula:
=MOODY(10000, 0)
Expected output:
0.031
Example 3: Rough pipe with typical relative roughness
Inputs:
| Re | eD |
|---|---|
| 100000 | 0.0001 |
Excel formula:
=MOODY(100000, 0.0001)
Expected output:
0.0181
Example 4: Pipe with higher relative roughness
Inputs:
| Re | eD |
|---|---|
| 50000 | 0.005 |
Excel formula:
=MOODY(50000, 0.005)
Expected output:
0.034
Python Code
import micropip
await micropip.install(["fluids"])
from fluids.friction import Moody as fluids_moody
def moody(Re, eD):
"""
Calculate Darcy friction factor using the Moody (1947) correlation.
See: https://fluids.readthedocs.io/fluids.friction.html#fluids.friction.Moody
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 error message (str) if input is invalid.
"""
try:
Re = float(Re)
eD = float(eD)
except (ValueError, TypeError):
return "Error: Could not convert parameters to required types."
try:
result = fluids_moody(Re=Re, eD=eD)
return float(result)
except Exception as e:
return f"Error computing moody: {str(e)}"