.. 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_06_moody_diagram.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_06_moody_diagram.py: Moody's diagram (1944) ====================== Lewis Moody, a Princeton professor of hydraulics, plotted Colebrook's equation for the roughness of commercial pipes in 1944, together with the laminar line, on one log-log chart (:func:`~engineeringkit.fluid_engineering.visualizers.plot_moody_diagram`). Engineers read friction factors from it for the next half-century. Moody also showed how to solve the three classic pipe problems with it: find the head loss, the flow, or the diameter. This example draws the chart and solves the third, which needs iteration even with :func:`~engineeringkit.fluid_engineering.colebrook_friction_factor` in hand. .. GENERATED FROM PYTHON SOURCE LINES 17-24 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from scipy import optimize from engineeringkit.fluid_engineering import colebrook_friction_factor, darcy_head_loss, reynolds_number from engineeringkit.fluid_engineering.visualizers import plot_moody_diagram .. GENERATED FROM PYTHON SOURCE LINES 25-27 The chart --------- .. GENERATED FROM PYTHON SOURCE LINES 27-32 .. code-block:: Python ax = plot_moody_diagram() ax.figure.set_size_inches(7, 5) ax.figure.tight_layout() .. image-sg:: /api/gallery/fluid_engineering/pipe_flow/images/sphx_glr_plot_06_moody_diagram_001.png :alt: Moody diagram :srcset: /api/gallery/fluid_engineering/pipe_flow/images/sphx_glr_plot_06_moody_diagram_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 33-38 Reading the chart: water in commercial steel -------------------------------------------- Commercial steel has :math:`\varepsilon = 0.045` mm. Water at 2 m/s in a 200 mm main has :math:`Re \approx 4\times10^5`. .. GENERATED FROM PYTHON SOURCE LINES 38-45 .. code-block:: Python rho, mu, eps = 998.0, 1.0e-3, 0.045e-3 Re = reynolds_number(rho, 2.0, 0.2, mu) f = colebrook_friction_factor(Re, eps / 0.2) ax.plot(Re, f, "k*", ms=12) print(f"Re = {Re:.2e}, ε/D = {eps / 0.2:.2e}: f = {f:.4f}") .. rst-class:: sphx-glr-script-out .. code-block:: none Re = 3.99e+05, ε/D = 2.25e-04: f = 0.0160 .. GENERATED FROM PYTHON SOURCE LINES 46-52 Moody's third problem: choose the diameter ------------------------------------------ Which steel pipe carries 50 L/s over 1 km with no more than 10 m of head loss? The friction factor depends on the diameter through both :math:`Re` and :math:`\varepsilon/D`, so the loss is solved for D. .. GENERATED FROM PYTHON SOURCE LINES 52-64 .. code-block:: Python Q, L, h_max = 0.050, 1000.0, 10.0 def loss(D): v = Q / (np.pi * D**2 / 4) return darcy_head_loss(colebrook_friction_factor(reynolds_number(rho, v, D, mu), eps / D), L, D, v) D = optimize.brentq(lambda D: loss(D) - h_max, 0.05, 1.0) print(f"smallest diameter: {1e3 * D:.1f} mm (loss at D: {loss(D):.3f} m)") .. rst-class:: sphx-glr-script-out .. code-block:: none smallest diameter: 202.2 mm (loss at D: 10.000 m) .. GENERATED FROM PYTHON SOURCE LINES 65-68 At fixed flow the loss falls roughly as :math:`D^{-5}`: a pipe 10% wider loses :math:`1.1^{-5} = 0.62` of the head, a little less still because the friction factor falls too. .. GENERATED FROM PYTHON SOURCE LINES 68-75 .. code-block:: Python print(f"10% larger pipe: loss {loss(1.1 * D):.2f} m") assert np.isclose(loss(D), h_max) assert 0.55 < loss(1.1 * D) / h_max < 0.65 assert colebrook_friction_factor(1000.0, 0.01) == 64 / 1000 plt.show() .. rst-class:: sphx-glr-script-out .. code-block:: none 10% larger pipe: loss 6.22 m .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.096 seconds) .. _sphx_glr_download_api_gallery_fluid_engineering_pipe_flow_plot_06_moody_diagram.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_06_moody_diagram.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_06_moody_diagram.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_06_moody_diagram.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_06_moody_diagram.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_