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

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

.. _sphx_glr_examples_python_thermo_plasma_equilibrium.py:


Equilibrium with charged species and multiple condensed phases
==============================================================

An equilibrium example with charged species in the gas phase
and multiple condensed phases.

Requires: cantera >= 2.5.0, matplotlib >= 2.0

.. warning::
   The results of this example are incorrect due to known issues with the multiphase
   equilibrium solver. See GitHub Issue
   `#270 <https://github.com/Cantera/cantera/issues/270>`_.

.. tags:: Python, equilibrium, multiphase, plasma, saving output

.. GENERATED FROM PYTHON SOURCE LINES 17-54




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

 .. code-block:: none

    T = 350.0
    T = 400.0
    T = 450.0
    T = 500.0
    T = 550.0
    T = 600.0
    T = 650.0
    T = 700.0
    T = 750.0
    T = 800.0
    T = 850.0
    T = 900.0
    T = 950.0
    T = 1000.0
    T = 1050.0
    T = 1100.0
    T = 1150.0
    T = 1200.0
    T = 1250.0
    T = 1300.0
    T = 1350.0
    T = 1400.0
    T = 1450.0
    T = 1500.0
    T = 1550.0
    T = 1600.0
    T = 1650.0
    T = 1700.0
    T = 1750.0
    T = 1800.0
    T = 1850.0
    T = 1900.0
    T = 1950.0
    T = 2000.0
    T = 2050.0
    T = 2100.0
    T = 2150.0
    T = 2200.0
    T = 2250.0
    T = 2300.0
    T = 2350.0
    T = 2400.0
    T = 2450.0
    T = 2500.0
    T = 2550.0
    T = 2600.0
    T = 2650.0
    T = 2700.0
    T = 2750.0
    T = 2800.0
    T = 2850.0
    T = 2900.0
    T = 2950.0
    T = 3000.0
    T = 3050.0
    T = 3100.0
    T = 3150.0
    T = 3200.0
    T = 3250.0
    T = 3300.0
    T = 3350.0
    T = 3400.0
    T = 3450.0
    T = 3500.0
    T = 3550.0
    T = 3600.0
    T = 3650.0
    T = 3700.0
    T = 3750.0
    T = 3800.0
    T = 3850.0
    T = 3900.0
    T = 3950.0
    T = 4000.0
    T = 4050.0
    T = 4100.0
    T = 4150.0
    T = 4200.0
    T = 4250.0
    T = 4300.0
    T = 4350.0
    T = 4400.0
    T = 4450.0
    T = 4500.0
    T = 4550.0
    T = 4600.0
    T = 4650.0
    T = 4700.0
    T = 4750.0
    T = 4800.0
    T = 4850.0
    T = 4900.0
    T = 4950.0
    T = 5000.0
    T = 5050.0
    T = 5100.0
    T = 5150.0
    T = 5200.0
    T = 5250.0
    T = 5300.0






|

.. code-block:: Python


    import cantera as ct
    import csv

    # create objects representing the gas phase and the condensed phases. The gas
    # is a mixture of multiple species, and the condensed phases are all modeled
    # as incompressible stoichiometric substances. See file KOH.yaml for more
    # information.
    phase_names = ['K_solid', 'K_liquid', 'KOH_a', 'KOH_b', 'KOH_liquid', 'K2O2_solid',
                   'K2O_solid', 'KO2_solid', 'ice', 'liquid_water', 'KOH_plasma']
    phases = [ct.Solution('KOH.yaml', name) for name in phase_names]

    # create the Mixture object from the list of phases
    mix = ct.Mixture(phases)
    equil_data = []

    # loop over temperature
    for n in range(100):
        t = 350.0 + 50.0*n
        print('T = {0}'.format(t))
        mix.T = t
        mix.P = ct.one_atm
        mix.species_moles = "K:1.03, H2:2.12, O2:0.9"

        # set the mixture to a state of chemical equilibrium holding
        # temperature and pressure fixed
        # mix.equilibrate("TP",maxsteps=10000,loglevel=1)
        mix.equilibrate("TP", max_steps=10000, log_level=0)

        # store the moles of each species
        equil_data.append([t] + list(mix.species_moles))

    with open("equil_koh.csv", "w", newline="") as csvfile:
        writer = csv.writer(csvfile)
        writer.writerow(['T'] + mix.species_names)

        writer.writerows(equil_data)


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

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


.. _sphx_glr_download_examples_python_thermo_plasma_equilibrium.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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