
: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/rankine.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_rankine.py>`
        to download the full example code.

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

.. _sphx_glr_examples_python_thermo_rankine.py:


Rankine cycle
=============

Calculate the efficiency of a Rankine vapor power cycle using a pure fluid model
for water.

Requires: Cantera >= 2.5.0

.. tags:: Python, thermodynamics, thermodynamic cycle, non-ideal fluid

.. GENERATED FROM PYTHON SOURCE LINES 12-15

.. code-block:: Python


    import cantera as ct








.. GENERATED FROM PYTHON SOURCE LINES 16-18

Parameters
----------

.. GENERATED FROM PYTHON SOURCE LINES 18-22

.. code-block:: Python

    eta_pump = 0.6  # pump isentropic efficiency
    eta_turbine = 0.8  # turbine isentropic efficiency
    p_max = 8.0e5  # maximum pressure








.. GENERATED FROM PYTHON SOURCE LINES 23-25

Helper Functions
----------------

.. GENERATED FROM PYTHON SOURCE LINES 25-57

.. code-block:: Python

    def pump(fluid, p_final, eta):
        """Adiabatically pump a fluid to pressure p_final, using
        a pump with isentropic efficiency eta."""
        h0 = fluid.h
        s0 = fluid.s
        fluid.SP = s0, p_final
        h1s = fluid.h
        isentropic_work = h1s - h0
        actual_work = isentropic_work / eta
        h1 = h0 + actual_work
        fluid.HP = h1, p_final
        return actual_work


    def expand(fluid, p_final, eta):
        """Adiabatically expand a fluid to pressure p_final, using
        a turbine with isentropic efficiency eta."""
        h0 = fluid.h
        s0 = fluid.s
        fluid.SP =s0, p_final
        h1s = fluid.h
        isentropic_work = h0 - h1s
        actual_work = isentropic_work * eta
        h1 = h0 - actual_work
        fluid.HP = h1, p_final
        return actual_work


    def printState(n, fluid):
        print('\n***************** State {0} ******************'.format(n))
        print(fluid.report())








.. GENERATED FROM PYTHON SOURCE LINES 58-60

Evaluate Rankine Cycle
----------------------

.. GENERATED FROM PYTHON SOURCE LINES 60-64

.. code-block:: Python


    # Create an object representing water:
    w = ct.Water()








.. GENERATED FROM PYTHON SOURCE LINES 65-66

Start with saturated liquid water at 300 K:

.. GENERATED FROM PYTHON SOURCE LINES 66-71

.. code-block:: Python

    w.TQ = 300.0, 0.0
    h1 = w.h
    p1 = w.P
    printState(1, w)





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

 .. code-block:: none


    ***************** State 1 ******************

      water:

           temperature   300 K
              pressure   3528.2 Pa
               density   996.59 kg/m^3
      mean mol. weight   18.016 kg/kmol
        vapor fraction   0
       phase of matter   liquid-gas-mix

                              1 kg             1 kmol     
                         ---------------   ---------------
              enthalpy       -1.5858e+07        -2.857e+08  J
       internal energy       -1.5858e+07        -2.857e+08  J
               entropy            3913.2             70500  J/K
        Gibbs function       -1.7032e+07       -3.0685e+08  J
     heat capacity c_p            4181.3             75330  J/K
     heat capacity c_v              4131             74425  J/K





.. GENERATED FROM PYTHON SOURCE LINES 72-73

Pump it adiabatically to ``p_max``:

.. GENERATED FROM PYTHON SOURCE LINES 73-77

.. code-block:: Python

    pump_work = pump(w, p_max, eta_pump)
    h2 = w.h
    printState(2, w)





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

 .. code-block:: none


    ***************** State 2 ******************

      water:

           temperature   300.14 K
              pressure   8e+05 Pa
               density   996.91 kg/m^3
      mean mol. weight   18.016 kg/kmol
        vapor fraction   0
       phase of matter   liquid

                              1 kg             1 kmol     
                         ---------------   ---------------
              enthalpy       -1.5857e+07       -2.8568e+08  J
       internal energy       -1.5858e+07       -2.8569e+08  J
               entropy              3915             70532  J/K
        Gibbs function       -1.7032e+07       -3.0685e+08  J
     heat capacity c_p            4178.6             75282  J/K
     heat capacity c_v            4127.9             74368  J/K





.. GENERATED FROM PYTHON SOURCE LINES 78-80

Heat it at constant pressure until it reaches the saturated vapor state
at this pressure:

.. GENERATED FROM PYTHON SOURCE LINES 80-85

.. code-block:: Python

    w.PQ = p_max, 1.0
    h3 = w.h
    heat_added = h3 - h2
    printState(3, w)





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

 .. code-block:: none


    ***************** State 3 ******************

      water:

           temperature   443.62 K
              pressure   8e+05 Pa
               density   4.1587 kg/m^3
      mean mol. weight   18.016 kg/kmol
        vapor fraction   1
       phase of matter   liquid-gas-mix

                              1 kg             1 kmol     
                         ---------------   ---------------
              enthalpy       -1.3202e+07       -2.3784e+08  J
       internal energy       -1.3394e+07       -2.4131e+08  J
               entropy             10183        1.8346e+05  J/K
        Gibbs function       -1.7719e+07       -3.1922e+08  J
     heat capacity c_p            2464.4             44399  J/K
     heat capacity c_v            1764.5             31790  J/K





.. GENERATED FROM PYTHON SOURCE LINES 86-87

expand back to ``p1``:

.. GENERATED FROM PYTHON SOURCE LINES 87-90

.. code-block:: Python

    turbine_work = expand(w, p1, eta_turbine)
    printState(4, w)





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

 .. code-block:: none


    ***************** State 4 ******************

      water:

           temperature   300 K
              pressure   3528.2 Pa
               density   0.030558 kg/m^3
      mean mol. weight   18.016 kg/kmol
        vapor fraction   0.83516
       phase of matter   liquid-gas-mix

                              1 kg             1 kmol     
                         ---------------   ---------------
              enthalpy       -1.3822e+07       -2.4902e+08  J
       internal energy       -1.3938e+07        -2.511e+08  J
               entropy             10700        1.9277e+05  J/K
        Gibbs function       -1.7032e+07       -3.0685e+08  J
     heat capacity c_p   inf               inf              J/K
     heat capacity c_v   nan               nan              J/K





.. GENERATED FROM PYTHON SOURCE LINES 91-92

Calculate the efficiency:

.. GENERATED FROM PYTHON SOURCE LINES 92-94

.. code-block:: Python

    eff = (turbine_work - pump_work)/heat_added
    print('efficiency = ', eff)




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

 .. code-block:: none

    efficiency =  0.23320858648784495





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

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


.. _sphx_glr_download_examples_python_thermo_rankine.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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