.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/thermodynamics/laws/plot_03_maxwell_relations.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_thermodynamics_laws_plot_03_maxwell_relations.py: Maxwell's thermodynamic relations (1871) ======================================== In his *Theory of Heat* (1871) James Clerk Maxwell drew a small cycle on the pressure-volume diagram and read off four relations between the derivatives of :math:`p`, :math:`v`, :math:`T` and :math:`s`. In modern form they say that the mixed second derivatives of :math:`u`, :math:`h`, :math:`a` and :math:`g` are equal. One of them, :math:`(\partial s/\partial p)_T = -(\partial v/\partial T)_p`, trades an unmeasurable entropy derivative for a measurable expansion coefficient. From it follow the difference of the specific heats (:func:`~engineeringkit.thermodynamics.cp_minus_cv`) and the Joule-Thomson coefficient of any fluid (:func:`~engineeringkit.thermodynamics.joule_thomson_coefficient`). The example checks both against IAPWS-IF97 steam, which is itself built from a Gibbs function. .. GENERATED FROM PYTHON SOURCE LINES 21-26 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from engineeringkit.thermodynamics import cp_minus_cv, joule_thomson_coefficient, steam_properties .. GENERATED FROM PYTHON SOURCE LINES 27-32 The Maxwell relation on superheated steam ----------------------------------------- Differentiate IF97 numerically at 2 MPa and 600 K: the entropy lost per pascal of compression equals the volume gained per kelvin of heating. .. GENERATED FROM PYTHON SOURCE LINES 32-39 .. code-block:: Python p, T, dT, dp = 2e6, 600.0, 0.01, 100.0 ds_dp = (steam_properties(p + dp, T).s - steam_properties(p - dp, T).s) / (2 * dp) dv_dT = (steam_properties(p, T + dT).v - steam_properties(p, T - dT).v) / (2 * dT) print(f"(ds/dp)_T = {ds_dp:.6e} m³/(kg K); -(dv/dT)_p = {-dv_dT:.6e} m³/(kg K)") assert np.isclose(ds_dp, -dv_dT, rtol=1e-5) .. rst-class:: sphx-glr-script-out .. code-block:: none (ds/dp)_T = -2.610761e-04 m³/(kg K); -(dv/dT)_p = -2.610761e-04 m³/(kg K) .. GENERATED FROM PYTHON SOURCE LINES 40-46 Two consequences ---------------- The expansivity :math:`\beta` and compressibility :math:`\kappa_T` give :math:`c_p - c_v = Tv\beta^2/\kappa_T`, which is :math:`R` for an ideal gas, and :math:`\mu_{JT} = v(T\beta - 1)/c_p`, which is zero for one. .. GENERATED FROM PYTHON SOURCE LINES 46-56 .. code-block:: Python st = steam_properties(p, T) beta = dv_dT / st.v kappa = -(steam_properties(p + dp, T).v - steam_properties(p - dp, T).v) / (2 * dp) / st.v mu = joule_thomson_coefficient(T, st.v, beta, st.cp) throttled = steam_properties(p - 10e3, h=st.h) print(f"cp - cv = {cp_minus_cv(T, st.v, beta, kappa):.1f} J/(kg K) (ideal steam: 461.5)") print(f"Joule-Thomson coefficient {mu * 1e6:.3f} K/MPa; a 10 kPa throttle cools by {(T - throttled.T) * 1e3:.2f} mK") assert np.isclose((T - throttled.T) / 10e3, mu, rtol=2e-3) .. rst-class:: sphx-glr-script-out .. code-block:: none cp - cv = 589.5 J/(kg K) (ideal steam: 461.5) Joule-Thomson coefficient 10.630 K/MPa; a 10 kPa throttle cools by 106.33 mK .. GENERATED FROM PYTHON SOURCE LINES 57-59 Across the vapour region the coefficient falls towards zero as the steam approaches an ideal gas at high temperature and low pressure. .. GENERATED FROM PYTHON SOURCE LINES 59-75 .. code-block:: Python temps = np.linspace(560.0, 1000.0, 23) # above the 537 K boiling point at 5 MPa fig, ax = plt.subplots(figsize=(6, 3.5)) for pressure in (0.5e6, 2e6, 5e6): values = [] for Ti in temps: here = steam_properties(pressure, Ti) b = (steam_properties(pressure, Ti + dT).v - steam_properties(pressure, Ti - dT).v) / (2 * dT) / here.v values.append(joule_thomson_coefficient(Ti, here.v, b, here.cp) * 1e6) ax.plot(temps - 273.15, values, label=f"{pressure / 1e6:g} MPa") ax.set(xlabel="temperature [°C]", ylabel="μ_JT [K/MPa]", title="Joule-Thomson coefficient of steam from Maxwell's relation") ax.legend() fig.tight_layout() assert values[0] > values[-1] > 0 plt.show() .. image-sg:: /api/gallery/thermodynamics/laws/images/sphx_glr_plot_03_maxwell_relations_001.png :alt: Joule-Thomson coefficient of steam from Maxwell's relation :srcset: /api/gallery/thermodynamics/laws/images/sphx_glr_plot_03_maxwell_relations_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.126 seconds) .. _sphx_glr_download_api_gallery_thermodynamics_laws_plot_03_maxwell_relations.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/thermodynamics/laws/plot_03_maxwell_relations.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_maxwell_relations.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_maxwell_relations.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_03_maxwell_relations.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_