.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/mixture/equilibriumcomposition.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_mixture_equilibriumcomposition.py: .. _ref_equilibrium_composition: ================================================================================= Estimate the steady-state NO emission level of a complete burned fuel-air mixture ================================================================================= This example shows how to quickly estimate the steady-state NO level that is formed by the combustion of a fuel-air mixture at a given temperature. Without needing any reaction, the NO concentration gets to its steady state (or the maximum level) when the product mixture from the fuel-air combustion reaches the equilibrium state at the given temperature. To find the equilibrium state of the fresh fuel-air mixture, the ``equilibrium()`` method is used with the ``fixed pressure`` and ``fixed temperature`` options. This example explores the influence of temperature on the predicted adiabatic flame temperature. Knowing that nitrogen oxides (NOx) are stable at high temperatures (> 2000 [K]), you can expect that the steady-state NO level should increase sharply when the temperature gets high enough. .. GENERATED FROM PYTHON SOURCE LINES 44-46 .. code-block:: Python :dedent: 1 .. GENERATED FROM PYTHON SOURCE LINES 48-50 Import PyChemkin packages and start the logger ============================================== .. GENERATED FROM PYTHON SOURCE LINES 50-70 .. code-block:: Python from pathlib import Path import matplotlib.pyplot as plt # plotting import numpy as np # number crunching import ansys.chemkin.core as ck # Chemkin from ansys.chemkin.core.logger import logger # check working directory current_dir = str(Path.cwd()) logger.debug("working directory: " + current_dir) # set verbose mode ck.set_verbose(True) # set interactive mode for plotting the results # interactive = True: display plot # interactive = False: save plot as a PNG file global interactive interactive = True .. GENERATED FROM PYTHON SOURCE LINES 71-76 Create a chemistry set ====================== The first mechanism to load is the GRI 3.0 mechanism for methane combustion. This mechanism and its associated data files come with the standard Ansys Chemkin installation in the ``/reaction/data`` directory. .. GENERATED FROM PYTHON SOURCE LINES 76-88 .. code-block:: Python # set mechanism directory (the default Chemkin mechanism data directory) data_dir = Path(ck.ansys_dir) / "reaction" / "data" mechanism_dir = data_dir # create a chemistry set based on GRI 3.0 MyGasMech = ck.Chemistry(label="GRI 3.0") # set mechanism input files # including the full file path is recommended MyGasMech.chemfile = str(mechanism_dir / "grimech30_chem.inp") MyGasMech.thermfile = str(mechanism_dir / "grimech30_thermo.dat") # transport data is not needed .. GENERATED FROM PYTHON SOURCE LINES 89-91 Preprocess the chemistry set ============================ .. GENERATED FROM PYTHON SOURCE LINES 91-95 .. code-block:: Python # preprocess the mechanism files ierror = MyGasMech.preprocess() .. GENERATED FROM PYTHON SOURCE LINES 96-103 Set up gas mixtures =================== Set up gas mixtures based on the species in this chemistry set. PyChemkin provides a few methods for creating a gas mixture. Here, the ``isothermal_mixing()`` method is used to create a ``fuel-air`` mixture by mixing the ``fuel`` and ``air`` mixtures with a predetermined air/fuel rate. .. GENERATED FROM PYTHON SOURCE LINES 105-108 Create a fuel mixture ===================== Create a fuel mixture of 80% methane and 20% hydrogen. .. GENERATED FROM PYTHON SOURCE LINES 108-115 .. code-block:: Python fuel = ck.Mixture(MyGasMech) # set mole fraction fuel.x = [("CH4", 0.8), ("H2", 0.2)] fuel.temperature = 300.0 fuel.pressure = ck.P_ATM # 1 atm .. GENERATED FROM PYTHON SOURCE LINES 116-119 Create an air mixture ===================== Create an air mixture of oxygen and nitrogen. .. GENERATED FROM PYTHON SOURCE LINES 119-127 .. code-block:: Python air = ck.Mixture(MyGasMech) # set mass fraction air.y = [("O2", 0.23), ("N2", 0.77)] air.temperature = 300.0 air.pressure = ck.P_ATM # 1 atm .. GENERATED FROM PYTHON SOURCE LINES 128-135 Create a fuel-air mixture by mixing =================================== Use the ``isothermal_mixing()`` method to mix the ``fuel`` and ``air`` mixtures created earlier. Define the mixing formula using ``mixture_recipe`` with this mass ratio: ``fuel:air=1.00:17.19``. Use the ``finaltemperature`` parameter to set the temperature of the new ``premixed`` mixture to 300 [K]. Set ``mode="mass"`` because the ratios given in ``mixture_recipe`` are mass ratios. .. GENERATED FROM PYTHON SOURCE LINES 135-142 .. code-block:: Python mixture_recipe = [(fuel, 1.0), (air, 17.19)] # create the new mixture (the air-fuel ratio is by mass) premixed = ck.isothermal_mixing( recipe=mixture_recipe, mode="mass", finaltemperature=300.0 ) .. GENERATED FROM PYTHON SOURCE LINES 143-149 Find the equilibrium composition at different temperatures ========================================================== Perform the equilibrium calculation with fixed pressure and fixed temperature. The NO mole fraction of the equilibrium state at each temperature is stored in an array. The gas temperature is increased from 500 to 2480 [K]. .. GENERATED FROM PYTHON SOURCE LINES 149-186 .. code-block:: Python # NO species index no_index = MyGasMech.get_specindex("NO") # set up plotting temperatures temp = 500.0 dtemp = 20.0 points = 100 # curve t = np.zeros(points, dtype=np.double) no = np.zeros_like(t, dtype=np.double) # start the temperature loop for k in range(points): # reset mixture temperature premixed.temperature = temp # find the equilibrium state mixture at the given mixture temperature and pressure eqstate = ck.equilibrium(premixed, opt=1) # no[k] = eqstate.x[no_index] * 1.0e6 # convert to ppm t[k] = temp temp += dtemp ################## # Plot the results # ================ # Plot the equilibrium NO mole fractions versus the temperatures # of the fuel-air mixtures. plt.plot(t, no, "bs--", markersize=3, markevery=4) plt.xlabel("Temperature [K]") plt.ylabel("NO [ppm]") # plot results if interactive: plt.show() else: plt.savefig("plot_equilibrium_composition.png", bbox_inches="tight") .. _sphx_glr_download_examples_mixture_equilibriumcomposition.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: equilibriumcomposition.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: equilibriumcomposition.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: equilibriumcomposition.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_