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

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

.. _sphx_glr_examples_python_thermo_mixing.py:


Mixing using `Quantity` objects
===============================

In this example, air and methane are mixed in stoichiometric proportions. This is a
simpler, steady-state version of the example :doc:`mix1.py <../reactors/mix1>`.

Since the goal is to simulate a continuous flow system, the mixing takes place
at constant enthalpy and pressure.

Requires: cantera >= 2.5.0

.. tags:: Python, thermodynamics, mixture

.. GENERATED FROM PYTHON SOURCE LINES 17-19

Set up streams
--------------

.. GENERATED FROM PYTHON SOURCE LINES 19-38

.. code-block:: Python


    import cantera as ct

    gas = ct.Solution('gri30.yaml')

    # Stream A (air)
    A = ct.Quantity(gas, constant='HP')
    A.TPX = 300.0, ct.one_atm, 'O2:0.21, N2:0.78, AR:0.01'

    # Stream B (methane)
    B = ct.Quantity(gas, constant='HP')
    B.TPX = 300.0, ct.one_atm, 'CH4:1'

    # Set the molar flow rates corresponding to stoichiometric reaction,
    # CH4 + 2 O2 -> CO2 + 2 H2O
    A.moles = 1
    nO2 = A.X[A.species_index('O2')]
    B.moles = nO2 * 0.5








.. GENERATED FROM PYTHON SOURCE LINES 39-41

Compute the mixed state
-----------------------

.. GENERATED FROM PYTHON SOURCE LINES 41-44

.. code-block:: Python

    M = A + B
    print(M.report())





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

 .. code-block:: none


      gri30:

           temperature   300 K
              pressure   1.0133e+05 Pa
               density   1.1269 kg/m^3
      mean mol. weight   27.742 kg/kmol
       phase of matter   gas

                              1 kg             1 kmol     
                         ---------------   ---------------
              enthalpy       -2.5351e+05       -7.0327e+06  J
       internal energy       -3.4342e+05       -9.5271e+06  J
               entropy            7221.9        2.0035e+05  J/K
        Gibbs function       -2.4201e+06       -6.7137e+07  J
     heat capacity c_p            1070.4             29695  J/K
     heat capacity c_v            770.71             21381  J/K

                          mass frac. Y      mole frac. X     chem. pot. / RT
                         ---------------   ---------------   ---------------
                    O2            0.2192           0.19005           -26.334
                   CH4          0.054952          0.095023           -54.676
                    N2           0.71281           0.70588           -23.381
                    AR          0.013032         0.0090498           -23.315
         [  +49 minor]                 0                 0  





.. GENERATED FROM PYTHON SOURCE LINES 45-47

Show that this state corresponds to stoichiometric combustion
-------------------------------------------------------------

.. GENERATED FROM PYTHON SOURCE LINES 47-49

.. code-block:: Python

    M.equilibrate('TP')
    print(M.report())




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

 .. code-block:: none


      gri30:

           temperature   300 K
              pressure   1.0133e+05 Pa
               density   1.1269 kg/m^3
      mean mol. weight   27.742 kg/kmol
       phase of matter   gas

                              1 kg             1 kmol     
                         ---------------   ---------------
              enthalpy       -3.0024e+06       -8.3292e+07  J
       internal energy       -3.0923e+06       -8.5786e+07  J
               entropy            7204.2        1.9986e+05  J/K
        Gibbs function       -5.1637e+06       -1.4325e+08  J
     heat capacity c_p            1104.2             30633  J/K
     heat capacity c_v            804.53             22319  J/K

                          mass frac. Y      mole frac. X     chem. pot. / RT
                         ---------------   ---------------   ---------------
                   H2O           0.12341           0.19005           -121.32
                   CO2           0.15074          0.095023           -185.83
                    N2           0.71281           0.70588           -23.381
                    AR          0.013032         0.0090498           -23.315
         [  +49 minor]        2.0428e-19        1.7711e-19  






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

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


.. _sphx_glr_download_examples_python_thermo_mixing.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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