COLEBROOK

Overview

The COLEBROOK function calculates the Darcy friction factor for turbulent flow in pipes using the Colebrook equation, a fundamental correlation in fluid mechanics for determining pressure drop due to friction. This function provides three solution methods: an exact analytical solution using the Lambert W function (default), a high-precision mpmath solution, or a numerical iterative solution.

The Colebrook equation was originally published in 1939 by C.F. Colebrook and is widely considered the most accurate implicit correlation for turbulent pipe friction. The equation relates the friction factor to both the Reynolds number and the relative roughness of the pipe wall:

\frac{1}{\sqrt{f}} = -2\log_{10}\left(\frac{\epsilon/D}{3.7} + \frac{2.51}{Re\sqrt{f}}\right)

where f is the Darcy friction factor, \epsilon/D is the relative roughness (absolute roughness divided by pipe diameter), and Re is the Reynolds number.

This implementation uses the fluids library, a Python package for fluid dynamics and engineering thermodynamics calculations. The analytical solution is derived using a computer algebra system (CAS) and expressed in terms of the Lambert W function:

f_d = \frac{\ln(10)^2 \cdot 3.7^2 \cdot 2.51^2}{\left(\ln(10)\epsilon/D \cdot Re - 2 \cdot 2.51 \cdot 3.7 \cdot \text{lambertW}\left[\frac{\ln(10)}{10^{(\epsilon Re)/(2.51 \cdot 3.7 D)}} \cdot \frac{Re^2}{2.51^2}\right]\right)^2}

For more details, see the Colebrook function documentation and the friction factor overview.

This example function is provided as-is without any representation of accuracy.

Excel Usage

=COLEBROOK(Re, eD, tol)
  • Re (float, required): Reynolds number, [-]
  • eD (float, required): Relative roughness (roughness/diameter), [-]
  • tol (float, optional, default: null): Solution tolerance. None = analytical (default), 0 = mpmath exact, user value = numerical solution, [-]

Returns (float): Darcy friction factor, [-], or error message (str) if input is invalid.

Examples

Example 1: Standard turbulent flow case

Inputs:

Re eD
100000 0.0001

Excel formula:

=COLEBROOK(100000, 0.0001)

Expected output:

0.01851

Example 2: Smooth pipe (very low roughness)

Inputs:

Re eD
100000 0.000001

Excel formula:

=COLEBROOK(100000, 0.000001)

Expected output:

0.018

Example 3: Rough pipe (higher roughness)

Inputs:

Re eD
100000 0.01

Excel formula:

=COLEBROOK(100000, 0.01)

Expected output:

0.0385

Example 4: High Reynolds number flow

Inputs:

Re eD
1000000 0.0001

Excel formula:

=COLEBROOK(1000000, 0.0001)

Expected output:

0.01344

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.0185

Python 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 tolerance. None = analytical (default), 0 = mpmath exact, user value = numerical solution, [-] Default is None.

    Returns:
        float: Darcy friction factor, [-], or error message (str) if input is invalid.
    """
    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)}"

Online Calculator