
: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/matlab/rankine.m"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

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

        :ref:`Go to the end <sphx_glr_download_examples_matlab_rankine.m>`
        to download the full example code.

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

.. _sphx_glr_examples_matlab_rankine.m:

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


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

Requires: cantera >= 3.2.0

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

.. GENERATED FROM PYTHON SOURCE LINES 9-10

.. code-block:: Matlab

    help rankine

.. GENERATED FROM PYTHON SOURCE LINES 11-12

Initialize parameters

.. GENERATED FROM PYTHON SOURCE LINES 13-17

.. code-block:: Matlab

    eta_pump = 0.6;
    eta_turbine = 0.8;
    p_max = 8.0 * ct.OneAtm;
    t1 = 300.0;

.. GENERATED FROM PYTHON SOURCE LINES 18-19

Create a saturated liquid water object at t1

.. GENERATED FROM PYTHON SOURCE LINES 20-25

.. code-block:: Matlab

    w = ct.Water();
    basis = 'mass';
    w.TQ = {t1, 0};
    h1 = w.H;
    p1 = w.P;

.. GENERATED FROM PYTHON SOURCE LINES 26-27

Pump it to p2

.. GENERATED FROM PYTHON SOURCE LINES 28-30

.. code-block:: Matlab

    pump_work = pump(w, p_max, eta_pump);
    h2 = w.H;

.. GENERATED FROM PYTHON SOURCE LINES 31-32

Heat to saturated vapor

.. GENERATED FROM PYTHON SOURCE LINES 33-37

.. code-block:: Matlab

    w.PQ = {p_max, 1.0};
    h3 = w.H;

    heat_added = h3 - h2;

.. GENERATED FROM PYTHON SOURCE LINES 38-39

Expand adiabatically back to the initial pressure

.. GENERATED FROM PYTHON SOURCE LINES 40-41

.. code-block:: Matlab

    turbine_work = expand(w, p1, eta_turbine);

.. GENERATED FROM PYTHON SOURCE LINES 42-43

Compute the efficiency

.. GENERATED FROM PYTHON SOURCE LINES 44-46

.. code-block:: Matlab

    efficiency = (turbine_work - pump_work) / heat_added;
    disp(sprintf('efficiency = %.2f%%', efficiency*100));

.. GENERATED FROM PYTHON SOURCE LINES 47-49

Local Functions
---------------

.. GENERATED FROM PYTHON SOURCE LINES 50-80

.. code-block:: Matlab

    function work = pump(fluid, pfinal, eta)
        % PUMP - Adiabatically pump a fluid to pressure pfinal, using a pump
        % with isentropic efficiency eta.

        fluid.basis = 'mass';
        h0 = fluid.H;
        s0 = fluid.S;
        fluid.SP = {s0, pfinal};
        h1s = fluid.H;
        isentropic_work = h1s - h0;
        actual_work = isentropic_work / eta;
        h1 = h0 + actual_work;
        fluid.HP = {h1, pfinal};
        work = actual_work;
    end

    function work = expand(fluid, pfinal, eta)
        % EXPAND - Adiabatically expand a fluid to pressure pfinal, using a
        % turbine with isentropic efficiency eta.

        fluid.basis = 'mass';
        h0 = fluid.H;
        s0 = fluid.S;
        fluid.SP = {s0, pfinal};
        h1s = fluid.H;
        isentropic_work = h0 - h1s;
        actual_work = isentropic_work * eta;
        h1 = h0 - actual_work;
        fluid.HP = {h1, pfinal};
        work = actual_work;
    end

.. _sphx_glr_download_examples_matlab_rankine.m:

.. only:: html

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

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

      :download:`Download Matlab source code: rankine.m <rankine.m>`

    .. 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>`_
