.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/mixture/adiabaticflametemperature.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_adiabaticflametemperature.py: .. _ref_adiabatic_flame_temperature: ========================================================= Estimate the adiabatic flame temperature of a gas mixture ========================================================= This example shows how to find the equilibrium state of a mixture. It uses the ``equilibrium()`` method with the ``constant pressure and enthalpy`` option to estimate the adiabatic flame temperature of a methane-oxygen mixture. This example also explores the influence of the equivalence ratio on the predicted adiabatic flame temperature. .. GENERATED FROM PYTHON SOURCE LINES 35-37 .. code-block:: Python :dedent: 1 .. GENERATED FROM PYTHON SOURCE LINES 39-41 Import PyChemkin packages and start the logger ============================================== .. GENERATED FROM PYTHON SOURCE LINES 41-61 .. 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 62-67 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 67-80 .. 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 the GRI 3.0 methane combustion mechanism 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") # skip the transport data file where is not needed by this example .. GENERATED FROM PYTHON SOURCE LINES 81-83 Preprocess the chemistry set ============================ .. GENERATED FROM PYTHON SOURCE LINES 83-87 .. code-block:: Python # preprocess the mechanism files ierror = MyGasMech.preprocess() .. GENERATED FROM PYTHON SOURCE LINES 88-95 Set up gas mixtures =================== Set up gas mixtures based on the species in this chemistry set. PyChemkin has a few methods for creating a gas mixture. Here, the equivalence ratio method is used to set up the combustible mixture so that you can easily change the mixture composition by assigning a different equivalence ratio value. .. GENERATED FROM PYTHON SOURCE LINES 95-127 .. code-block:: Python # create an "oxid" mixture associated with the 'MyGasMech' chemistry set oxid = ck.Mixture(MyGasMech) # use a "recipe" to set the mole fractions of the mixture # the "oxid" mixture consists of 100% O2 oxid.x = [("O2", 1.0)] oxid.temperature = 295.15 # [K] oxid.pressure = ck.P_ATM # 1 atm # create the "fuel" mixture fuel = ck.Mixture(MyGasMech) # set the "fuel" molar composition to 100% CH4 fuel.x = [("CH4", 1.0)] fuel.temperature = oxid.temperature fuel.pressure = oxid.pressure # create the final fuel-oxidizer mixture mixture = ck.Mixture(MyGasMech) mixture.pressure = oxid.pressure mixture.temperature = oxid.temperature # the use of equivalence ratio requires the definition of the complete combustion # products of the fuel-oxidizer pair: # CH4 + 2O2 => CO2 + 2H2O products = ["CO2", "H2O"] # create an array to specify the composition of the additives to # the fuel-oxidizer mixture For example, a diluent such as argon or # helium might be added to the fuel-oxidizer mixture Use an all-zero array # if there is no additive add_frac = np.zeros(MyGasMech.kk, dtype=np.double) .. GENERATED FROM PYTHON SOURCE LINES 128-133 Set up the parameter study ========================== Set up a parameter study to find out the impact of the equivalence ratio on the adiabatic flame temperature of the fuel-oxidizer mixture. The equivalence ratio varies from 0.5 to 1.6 with an increment of 0.1. .. GENERATED FROM PYTHON SOURCE LINES 133-142 .. code-block:: Python points = 12 deq = 0.1 equiv_ini = 0.5 # create the solution arrays as double arrays t = np.zeros(points, dtype=np.double) equiv = np.zeros_like(t, dtype=np.double) .. GENERATED FROM PYTHON SOURCE LINES 143-159 Run the parameter study ======================= Use the ``equilibrium()`` method to estimate the adiabatic flame temperature of the fuel-oxidizer mixture. Choose the option corresponding to constant pressure and constant enthalpy for the equilibrium calculation because you are finding the adiabatic temperature. The ``equilibrium()`` method returns a mixture object representing the mixture at the equilibrium state. Use the ``temperature()`` method to get the equilibrium temperature. To see all available options for this method, use the ``ck.help(topic="equilibrium")`` method. This example uses the ``x_by_equivalence_ratio()`` method to set the fuel-oxidizer composition with the given equivalence ratios because the composition of both the fuel and oxidizer mixtures is specified in mole fractions. .. GENERATED FROM PYTHON SOURCE LINES 159-186 .. code-block:: Python for i in range(points): # set the current mixture equivalence ratio equiv_current = equiv_ini # create the fuel-oxidizer mixture with the given equivalence ratio ierror = mixture.x_by_equivalence_ratio( MyGasMech, fuel.x, oxid.x, add_frac, products, equivalenceratio=equiv_current ) # check fuel-oxidizer mixture creation status if ierror != 0: print("Error: Failed to create the fuel-oxidizer mixture.") print(f" Equivalence ratio = {equiv_current}.") exit() # use "equilibrium()" method to calculate the gas mixture at the equilibrium state # Option #5 ("opt=5") corresponds to the constant pressure and constant-enthalpy # constraints of the equilibrium state # "EQ_mixture" is the gas mixture at the equilibrium state EQ_mixture = ck.equilibrium(mixture, opt=5) # save the results to the solution arrays # use "temperature" to obtain the temperature of the equilibrium state t[i] = EQ_mixture.temperature equiv[i] = equiv_current equiv_ini = equiv_ini + deq .. GENERATED FROM PYTHON SOURCE LINES 187-191 Plot the result from the parameter study ======================================== When you plot the result from the parameter study, the adiabatic flame temperature should exhibit a peak at around the stoichiometric, that is, equivalence ratio = 1. .. GENERATED FROM PYTHON SOURCE LINES 191-202 .. code-block:: Python # plot equilibrium/adiabatic temperatures against mixture equivalence ratios plt.plot(equiv, t, "bs--") # set up axis labels plt.xlabel("Equivalence ratio") plt.ylabel("Temperature [K]") # display or save the plot if interactive: plt.show() else: plt.savefig("plot_adiabatic_flame_temperature.png", bbox_inches="tight") .. _sphx_glr_download_examples_mixture_adiabaticflametemperature.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: adiabaticflametemperature.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: adiabaticflametemperature.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: adiabaticflametemperature.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_