COLEBROOK
Solves the Colebrook equation for Darcy friction factor from Reynolds number and relative roughness. The optional tolerance parameter controls which solution path the fluids library uses, allowing analytical, numerical, high-fidelity, or Clamond-style accelerated evaluation.
The governing equation is:
\frac{1}{\sqrt{f_d}} = -2\log_{10}\left(\frac{\epsilon/D}{3.7} + \frac{2.51}{Re\sqrt{f_d}}\right)
This function is appropriate when you want a direct Colebrook-based result rather than one of the many explicit approximations.
Excel Usage
=COLEBROOK(Re, eD, tol)
Re(float, required): Reynolds number, [-]eD(float, required): Relative roughness (roughness/diameter), [-]tol(float, optional, default: null): Solution selector. None uses the analytical solution, 0 uses mpmath, -1 applies the Clamond shortcut where valid, and any other value uses a numerical solve [-]
Returns (float): Darcy friction factor from the Colebrook equation [-]
Example 1: Standard turbulent flow case
Inputs:
| Re | eD |
|---|---|
| 100000 | 0.0001 |
Excel formula:
=COLEBROOK(100000, 0.0001)
Expected output:
0.0185139
Example 2: Smooth pipe (very low roughness)
Inputs:
| Re | eD |
|---|---|
| 100000 | 0.000001 |
Excel formula:
=COLEBROOK(100000, 0.000001)
Expected output:
0.0179952
Example 3: Rough pipe (higher roughness)
Inputs:
| Re | eD |
|---|---|
| 100000 | 0.01 |
Excel formula:
=COLEBROOK(100000, 0.01)
Expected output:
0.0385035
Example 4: High Reynolds number flow
Inputs:
| Re | eD |
|---|---|
| 1000000 | 0.0001 |
Excel formula:
=COLEBROOK(1000000, 0.0001)
Expected output:
0.0134414
Example 5: Numerical solution with tolerance
Inputs:
| Re | eD | tol |
|---|---|---|
| 100000 | 0.0001 | 0.0001 |
Excel formula:
=COLEBROOK(100000, 0.0001, 0.0001)
Expected output:
0.0185139
Python Code
Show Code
from fluids.friction import Colebrook as fluids_colebrook
def colebrook(Re, eD, tol=None):
"""
Calculate Darcy friction factor using exact solution to the Colebrook equation.
See: https://fluids.readthedocs.io/fluids.friction.html#fluids.friction.Colebrook
This example function is provided as-is without any representation of accuracy.
Args:
Re (float): Reynolds number, [-]
eD (float): Relative roughness (roughness/diameter), [-]
tol (float, optional): Solution selector. None uses the analytical solution, 0 uses mpmath, -1 applies the Clamond shortcut where valid, and any other value uses a numerical solve [-] Default is None.
Returns:
float: Darcy friction factor from the Colebrook equation [-]
"""
try:
Re = float(Re)
eD = float(eD)
if tol is not None:
tol = float(tol)
if Re <= 0:
return "Error: Reynolds number must be positive."
if eD < 0:
return "Error: Relative roughness must be non-negative."
result = fluids_colebrook(Re=Re, eD=eD, tol=tol)
if result != result:
return "Error: Result is NaN."
if result == float('inf') or result == float('-inf'):
return "Error: Result is not finite."
return float(result)
except OverflowError:
return "Error: Overflow in calculation. Try using numerical solution with tol parameter."
except Exception as e:
return f"Error: {str(e)}"