
: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/reactors/mix1.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_reactors_mix1.py>`
        to download the full example code.

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

.. _sphx_glr_examples_python_reactors_mix1.py:


Mixing two streams
==================

Since reactors can have multiple inlets and outlets, they can be used to
implement mixers, splitters, etc. In this example, air and methane are mixed
in stoichiometric proportions. Due to the low temperature, no reactions occur.
Note that the air stream and the methane stream use *different* reaction
mechanisms, with different numbers of species and reactions. When gas flows
from one reactor or reservoir to another one with a different reaction
mechanism, species are matched by name. If the upstream reactor contains a
species that is not present in the downstream reaction mechanism, it will be
ignored. In general, reaction mechanisms for downstream reactors should
contain all species that might be present in any upstream reactor.

Compare this approach for the transient problem to the method used for the
steady-state problem in :doc:`mixing.py <../thermo/mixing>`.

Requires: cantera >= 3.2, graphviz

.. tags:: Python, thermodynamics, reactor network, mixture

.. GENERATED FROM PYTHON SOURCE LINES 23-26

.. code-block:: Python


    import cantera as ct








.. GENERATED FROM PYTHON SOURCE LINES 27-31

Set up the reactor network
--------------------------

Use air for stream a.

.. GENERATED FROM PYTHON SOURCE LINES 31-35

.. code-block:: Python

    gas_a = ct.Solution('air.yaml')
    gas_a.TPX = 300.0, ct.one_atm, 'O2:0.21, N2:0.78, AR:0.01'
    rho_a = gas_a.density








.. GENERATED FROM PYTHON SOURCE LINES 36-39

Use GRI-Mech 3.0 for stream b (methane) and for the mixer. If it is desired
to have a pure mixer, with no chemistry, use instead a reaction mechanism
for gas_b that has no reactions.

.. GENERATED FROM PYTHON SOURCE LINES 39-43

.. code-block:: Python

    gas_b = ct.Solution('gri30.yaml')
    gas_b.TPX = 300.0, ct.one_atm, 'CH4:1'
    rho_b = gas_b.density








.. GENERATED FROM PYTHON SOURCE LINES 44-50

Create reservoirs for the two inlet streams and for the outlet stream.  The
upstream reservoirs could be replaced by reactors, which might themselves be
connected to reactors further upstream. The outlet reservoir could be
replaced with a reactor with no outlet, if it is desired to integrate the
composition leaving the mixer in time, or by an arbitrary network of
downstream reactors.

.. GENERATED FROM PYTHON SOURCE LINES 50-54

.. code-block:: Python

    res_a = ct.Reservoir(gas_a, name='Air Reservoir', clone=True)
    res_b = ct.Reservoir(gas_b, name='Fuel Reservoir', clone=True)
    downstream = ct.Reservoir(gas_a, name='Outlet Reservoir', clone=True)








.. GENERATED FROM PYTHON SOURCE LINES 55-58

Create a reactor for the mixer. A reactor is required instead of a
reservoir, since the state will change with time if the inlet mass flow
rates change or if there is chemistry occurring.

.. GENERATED FROM PYTHON SOURCE LINES 58-61

.. code-block:: Python

    gas_b.TPX = 300.0, ct.one_atm, 'O2:0.21, N2:0.78, AR:0.01'
    mixer = ct.IdealGasReactor(gas_b, name='Mixer', clone=True)








.. GENERATED FROM PYTHON SOURCE LINES 62-65

Create two mass flow controllers connecting the upstream reservoirs to the
mixer, and set their mass flow rates to values corresponding to
stoichiometric combustion.

.. GENERATED FROM PYTHON SOURCE LINES 65-68

.. code-block:: Python

    mfc1 = ct.MassFlowController(res_a, mixer, mdot=rho_a*2.5/0.21, name="Air Inlet")
    mfc2 = ct.MassFlowController(res_b, mixer, mdot=rho_b*1.0, name="Fuel Inlet")








.. GENERATED FROM PYTHON SOURCE LINES 69-70

Connect the mixer to the downstream reservoir with a valve.

.. GENERATED FROM PYTHON SOURCE LINES 70-74

.. code-block:: Python

    outlet = ct.Valve(mixer, downstream, K=10.0, name="Valve")

    sim = ct.ReactorNet([mixer])








.. GENERATED FROM PYTHON SOURCE LINES 75-79

Get the mixed state
-------------------

Since the mixer is a reactor, we need to solve for the steady state.

.. GENERATED FROM PYTHON SOURCE LINES 79-84

.. code-block:: Python

    sim.solve_steady()

    # view the state of the gas in the mixer
    print(mixer.phase.report())





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

 .. code-block:: none


      gri30:

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

                              1 kg             1 kmol     
                         ---------------   ---------------
              enthalpy        -2.047e+05        -5.725e+06  J
       internal energy       -2.9388e+05       -8.2194e+06  J
               entropy            7158.8        2.0022e+05  J/K
        Gibbs function       -2.3523e+06       -6.5791e+07  J
     heat capacity c_p            1057.5             29578  J/K
     heat capacity c_v            760.26             21263  J/K

                          mass frac. Y      mole frac. X     chem. pot. / RT
                         ---------------   ---------------   ---------------
                    O2           0.22164           0.19373           -26.315
                   CH4           0.04445          0.077491            -54.88
                    N2           0.72073           0.71956           -23.362
                    AR          0.013177         0.0092251           -23.296
         [  +49 minor]       -4.0226e-25        -1.211e-25  





.. GENERATED FROM PYTHON SOURCE LINES 85-87

Show the network structure
--------------------------

.. GENERATED FROM PYTHON SOURCE LINES 87-91

.. code-block:: Python

    try:
        diagram = sim.draw(print_state=True, species="X")
    except ImportError as err:
        print(f"Unable to show network structure:\n{err}")



.. image-sg:: /examples/python/reactors/images/sphx_glr_mix1_001.svg
   :alt: mix1
   :srcset: /examples/python/reactors/images/sphx_glr_mix1_001.svg
   :class: sphx-glr-single-img






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

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


.. _sphx_glr_download_examples_python_reactors_mix1.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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