
:html_theme.sidebar_secondary.remove:

.. py:currentmodule:: cantera


.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "examples/python/thermo/vapordome.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_examples_python_thermo_vapordome.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_examples_python_thermo_vapordome.py:


Vapor Dome
==========

This example generates a saturated steam table and plots the vapor dome. The
steam table corresponds to data typically found in thermodynamic text books
and uses the same customary units.

Requires: Cantera >= 2.5.0, matplotlib >= 2.0, pandas >= 1.1.0

.. tags:: Python, thermodynamics, non-ideal fluid, plotting

.. GENERATED FROM PYTHON SOURCE LINES 13-28

.. code-block:: Python


    import cantera as ct
    import pandas as pd
    import numpy as np
    from matplotlib import pyplot as plt

    w = ct.Water()

    # create columns
    columns = ['T', 'P',
               'vf', 'vfg', 'vg',
               'uf', 'ufg', 'ug',
               'hf', 'hfg', 'hg',
               'sf', 'sfg', 'sg']








.. GENERATED FROM PYTHON SOURCE LINES 29-32

temperatures correspond to Engineering Thermodynamics, Moran et al. (9th ed),
Table A-2; additional data points are added close to the critical point;
w.min_temp is equal to the triple point temperature

.. GENERATED FROM PYTHON SOURCE LINES 32-79

.. code-block:: Python

    degc = np.hstack([np.array([w.min_temp - 273.15, 4, 5, 6, 8]),
                      np.arange(10, 37), np.array([38]),
                      np.arange(40, 100, 5), np.arange(100, 300, 10),
                      np.arange(300, 380, 20), np.arange(370, 374),
                      np.array([w.critical_temperature - 273.15])])

    df = pd.DataFrame(0, index=np.arange(len(degc)), columns=columns)
    df.T = degc

    arr = ct.SolutionArray(w, len(degc))

    # saturated vapor data
    arr.TQ = degc + 273.15, 1
    df.P = arr.P_sat / 1.e5
    df.vg = arr.v
    df.ug = arr.int_energy_mass / 1.e3
    df.hg = arr.enthalpy_mass / 1.e3
    df.sg = arr.entropy_mass / 1.e3

    # saturated liquid data
    arr.TQ = degc + 273.15, 0
    df.vf = arr.v
    df.uf = arr.int_energy_mass / 1.e3
    df.hf = arr.enthalpy_mass / 1.e3
    df.sf = arr.entropy_mass / 1.e3

    # delta values
    df.vfg = df.vg - df.vf
    df.ufg = df.ug - df.uf
    df.hfg = df.hg - df.hf
    df.sfg = df.sg - df.sf

    # reference state (triple point; liquid state)
    w.TQ = w.min_temp, 0
    uf0 = w.int_energy_mass / 1.e3
    hf0 = w.enthalpy_mass / 1.e3
    sf0 = w.entropy_mass / 1.e3
    pv0 = w.P * w.v / 1.e3

    # change reference state
    df.ug -= uf0
    df.uf -= uf0
    df.hg -= hf0 - pv0
    df.hf -= hf0 - pv0
    df.sg -= sf0
    df.sf -= sf0








.. GENERATED FROM PYTHON SOURCE LINES 80-81

print and write saturated steam table to csv file

.. GENERATED FROM PYTHON SOURCE LINES 81-84

.. code-block:: Python

    print(df)
    df.to_csv('saturated_steam_T.csv', index=False)





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

              T           P        vf           vfg          vg           uf          ufg           ug           hf          hfg           hg        sf           sfg        sg
    0     0.010    0.006102  0.001000  2.065326e+02  206.533627     0.000000  2375.337333  2375.337333     0.000610  2501.354572  2501.355182  0.000000  9.157104e+00  9.157104
    1     4.000    0.008116  0.001000  1.575305e+02  157.531546    16.770141  2364.094470  2380.864611    16.770952  2491.939623  2508.710575  0.060949  8.991303e+00  9.052252
    2     5.000    0.008704  0.001000  1.473998e+02  147.400772    20.974982  2361.273574  2382.248556    20.975852  2489.576414  2510.552266  0.076093  8.950481e+00  9.026575
    3     6.000    0.009331  0.001000  1.379966e+02  137.997612    25.179712  2358.452207  2383.631919    25.180645  2487.212546  2512.393191  0.091183  8.909950e+00  9.001133
    4     8.000    0.010704  0.001000  1.211489e+02  121.149900    33.587684  2352.809116  2386.396800    33.588755  2482.483862  2516.072616  0.121196  8.829749e+00  8.950944
    ..      ...         ...       ...           ...         ...          ...          ...          ...          ...          ...          ...       ...           ...       ...
    69  370.000  210.174778  0.002217  2.746754e-03    0.004964  1844.870691   387.400525  2232.271216  1891.467206   445.130357  2336.597563  4.112145  6.921097e-01  4.804255
    70  371.000  212.710748  0.002285  2.425813e-03    0.004711  1863.649757   347.250471  2210.900229  1912.254506   398.850121  2311.104627  4.143554  6.191883e-01  4.762742
    71  372.000  215.280450  0.002376  2.047036e-03    0.004424  1886.671146   297.620998  2184.292145  1937.832031   341.689675  2279.521706  4.182301  5.296283e-01  4.711929
    72  373.000  217.886235  0.002520  1.546784e-03    0.004066  1918.677969   228.632705  2147.310674  1973.575125   262.335010  2235.910134  4.236673  4.059971e-01  4.642670
    73  374.136  220.890000  0.003256  1.824293e-09    0.003256  2044.659183     0.000267  2044.659450  2116.578986     0.000308  2116.579294  4.456452  4.751945e-07  4.456453

    [74 rows x 14 columns]




.. GENERATED FROM PYTHON SOURCE LINES 85-86

illustrate the vapor dome in a P-v diagram

.. GENERATED FROM PYTHON SOURCE LINES 86-93

.. code-block:: Python

    plt.semilogx(df.vf.values, df.P.values, label='Saturated liquid')
    plt.semilogx(df.vg.values, df.P.values, label='Saturated vapor')
    plt.semilogx(df.vg.values[-1], df.P.values[-1], 'o', label='Critical point')
    plt.xlabel(r'Specific volume - $v$ ($\mathrm{m^3/kg}$)')
    plt.ylabel(r'Pressure - $P$ (bar)')
    plt.legend();




.. image-sg:: /examples/python/thermo/images/sphx_glr_vapordome_001.png
   :alt: vapordome
   :srcset: /examples/python/thermo/images/sphx_glr_vapordome_001.png, /examples/python/thermo/images/sphx_glr_vapordome_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. GENERATED FROM PYTHON SOURCE LINES 94-95

illustrate the vapor dome in a T-s diagram

.. GENERATED FROM PYTHON SOURCE LINES 95-104

.. code-block:: Python

    plt.figure()
    plt.plot(df.sf.values, df['T'].values, label='Saturated liquid')
    plt.plot(df.sg.values, df['T'].values, label='Saturated vapor')
    plt.plot(df.sg.values[-1], df['T'].values[-1], 'o', label='Critical point')
    plt.xlabel(r'Specific entropy - $s$ ($\mathrm{kJ/kg-K}$)')
    plt.ylabel(r'Temperature - $T$ (${}^\circ C$)')
    plt.legend()

    plt.show()



.. image-sg:: /examples/python/thermo/images/sphx_glr_vapordome_002.png
   :alt: vapordome
   :srcset: /examples/python/thermo/images/sphx_glr_vapordome_002.png, /examples/python/thermo/images/sphx_glr_vapordome_002_2_00x.png 2.00x
   :class: sphx-glr-single-img






.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 1.693 seconds)


.. _sphx_glr_download_examples_python_thermo_vapordome.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: vapordome.ipynb <vapordome.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: vapordome.py <vapordome.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: vapordome.zip <vapordome.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
