.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/fluid_engineering/pipe_flow/plot_05_colebrook_equation.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via JupyterLite. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_fluid_engineering_pipe_flow_plot_05_colebrook_equation.py: Colebrook's turbulent friction factor (1939) ============================================ Commercial pipes do not behave like Nikuradse's sand: their roughness is uneven, and friction leaves the smooth law gradually rather than with Nikuradse's dip. Cyril Colebrook, after experiments with Cedric White on pipes coated with mixed grains, added the smooth and rough laws inside one logarithm in 1939, .. math:: \frac{1}{\sqrt f} = -2\log_{10}\left(\frac{\varepsilon/D}{3.7} + \frac{2.51}{Re\sqrt f}\right), (:func:`~engineeringkit.fluid_engineering.colebrook_friction_factor`). The equation is implicit in :math:`f`. This example solves it by the fixed-point iteration engineers used by hand and compares it with the two limits it joins. .. GENERATED FROM PYTHON SOURCE LINES 22-31 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from engineeringkit.fluid_engineering import ( colebrook_friction_factor, nikuradse_friction_factor, smooth_pipe_friction_factor, ) .. GENERATED FROM PYTHON SOURCE LINES 32-38 Fixed-point iteration --------------------- With :math:`x = 1/\sqrt f` the equation reads :math:`x = -2\log_{10}(\varepsilon/3.7D + 2.51x/Re)`. The right side changes slowly with :math:`x`, so substitution converges in a few steps. .. GENERATED FROM PYTHON SOURCE LINES 38-53 .. code-block:: Python Re, rel = 2e5, 1e-3 x = [3.0] for _ in range(8): x.append(-2 * np.log10(rel / 3.7 + 2.51 * x[-1] / Re)) f_iter = 1 / np.array(x) ** 2 f_ref = colebrook_friction_factor(Re, rel) for k, fk in enumerate(f_iter[:5]): print(f"step {k}: f = {fk:.6f}") print(f"bracketed root: f = {f_ref:.6f}") fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(9, 3.8)) ax1.semilogy(np.abs(f_iter - f_ref) + 1e-17, marker="o") ax1.set(xlabel="iteration", ylabel="|f - f*|", title="Substitution converges fast") .. image-sg:: /api/gallery/fluid_engineering/pipe_flow/images/sphx_glr_plot_05_colebrook_equation_001.png :alt: Substitution converges fast :srcset: /api/gallery/fluid_engineering/pipe_flow/images/sphx_glr_plot_05_colebrook_equation_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none step 0: f = 0.111111 step 1: f = 0.020274 step 2: f = 0.021057 step 3: f = 0.021033 step 4: f = 0.021034 bracketed root: f = 0.021034 [Text(0.5, 12.633333333333331, 'iteration'), Text(58.222222222222214, 0.5, '|f - f*|'), Text(0.5, 1.0, 'Substitution converges fast')] .. GENERATED FROM PYTHON SOURCE LINES 54-60 A smooth bridge between two laws -------------------------------- Colebrook's curve sits above both the smooth and the fully rough laws and approaches each at its end of the range. The largest excess is in the transition, where both mechanisms count. .. GENERATED FROM PYTHON SOURCE LINES 60-80 .. code-block:: Python Re_range = np.geomspace(4e3, 1e8, 200) cb = colebrook_friction_factor(Re_range, rel) smooth = smooth_pipe_friction_factor(Re_range) rough = nikuradse_friction_factor(rel) ax2.loglog(Re_range, cb, label="Colebrook, ε/D = 0.001") ax2.loglog(Re_range, smooth, "k--", label="smooth") ax2.axhline(rough, color="k", ls=":", label="fully rough") ax2.set(xlabel="Reynolds number", ylabel="friction factor", title="Colebrook joins the limits") ax2.legend(fontsize="small") fig.tight_layout() excess = cb / np.maximum(smooth, rough) - 1 print(f"largest excess over the larger limit: {excess.max():.0%} at Re = {Re_range[excess.argmax()]:.1e}") assert abs(f_iter[-1] - f_ref) < 1e-10 * f_ref assert np.all(cb >= np.maximum(smooth, rough) * (1 - 2e-3)) assert abs(cb[0] / smooth[0] - 1) < 0.12 and abs(cb[-1] / rough - 1) < 0.01 plt.show() .. rst-class:: sphx-glr-script-out .. code-block:: none largest excess over the larger limit: 18% at Re = 6.6e+04 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.080 seconds) .. _sphx_glr_download_api_gallery_fluid_engineering_pipe_flow_plot_05_colebrook_equation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../../../lite/lab/index.html?path=api/gallery/fluid_engineering/pipe_flow/plot_05_colebrook_equation.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_05_colebrook_equation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_05_colebrook_equation.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_05_colebrook_equation.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_