.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/chemistry/simple.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_chemistry_simple.py: .. _ref_simple: ========================== Set up a PyChemkin project ========================== This example shows how to set up a PyChemkin project and start to use PyChemkin features. You begin by importing the PyChemkin package, which is named ``ansys.chemkin.core``, and optionally the PyChemkin logger package, which is named ``ansys.chemkin.core.logger``. Next, you use the ``Chemistry()`` method to instantiate and preprocess a chemistry set. This requires specifying the file names (with full file paths) of the mechanism file, thermodynamic data file, and optional transport data file. Once the chemistry set instance is instantiated, you use the ``preprocess()`` method to preprocess the mechanism data. You can then start to use PyChemkin features to build your simulation. .. note:: Running PyChemkin requires Ansys 2025 R2 or later. .. GENERATED FROM PYTHON SOURCE LINES 46-48 .. code-block:: Python :dedent: 1 .. GENERATED FROM PYTHON SOURCE LINES 50-54 Import PyChemkin packages ========================= Import the ``ansys.chemkin.core`` package to start using PyChemkin in the project. Importing the ``ansys.chemkin.core.logger`` package is optional. .. GENERATED FROM PYTHON SOURCE LINES 54-60 .. code-block:: Python from pathlib import Path import ansys.chemkin.core # import PyChemkin from ansys.chemkin.core.logger import logger .. GENERATED FROM PYTHON SOURCE LINES 61-74 Set up the file paths of the mechanism and data files ===================================================== The ``ansys_dir`` variable on your local computer specifies the location of your Ansys installation. Use ``os.path`` methods to construct the file names with the full paths. Assign the files to the corresponding chemistry set arguments: - ``mech_file``: Mechanism input file - ``therm_file``: Thermodynamic data file - ``tran_file``: Transport data file (optional) .. GENERATED FROM PYTHON SOURCE LINES 74-82 .. code-block:: Python # create GRI 3.0 mechanism from the data directory mechanism_dir = Path(ansys.chemkin.core.ansys_dir) / "reaction" / "data" # set up mechanism file names mech_file = str(mechanism_dir / "grimech30_chem.inp") therm_file = str(mechanism_dir / "grimech30_thermo.dat") tran_file = str(mechanism_dir / "grimech30_transport.dat") .. GENERATED FROM PYTHON SOURCE LINES 83-86 Instantiate the chemistry set ============================= Use the ``Chemistry()`` method to instantiate a chemistry set named ``GasMech``. .. GENERATED FROM PYTHON SOURCE LINES 86-91 .. code-block:: Python GasMech = ansys.chemkin.core.Chemistry( chem=mech_file, therm=therm_file, tran=tran_file, label="GRI 3.0" ) .. GENERATED FROM PYTHON SOURCE LINES 92-95 Preprocess the chemistry set ============================ Preprocess the GRI 3.0 chemistry set. .. GENERATED FROM PYTHON SOURCE LINES 95-98 .. code-block:: Python status = GasMech.preprocess() .. GENERATED FROM PYTHON SOURCE LINES 99-101 Check the preprocessing status =============================== .. GENERATED FROM PYTHON SOURCE LINES 101-109 .. code-block:: Python if status != 0: # failed print(f"Preprocessing: Error encountered. Code = {status:d}.") print(f"See the summary file {GasMech.summaryfile} for details.") logger.error("Preprocessing failed.") exit() .. GENERATED FROM PYTHON SOURCE LINES 110-115 Start to use PyChemkin features =============================== Start to use PyChemkin features to build your simulation. For example, using the ``Mixture()`` method, create an ``air`` mixture based on the ``GasMech`` chemistry set. .. GENERATED FROM PYTHON SOURCE LINES 115-126 .. code-block:: Python # create 'air' mixture based on 'GasMech' chemistry set air = ansys.chemkin.core.Mixture(GasMech) # set 'air' condition # mixture pressure in [dynes/cm2] air.pressure = 1.0 * ansys.chemkin.core.P_ATM # mixture temperature in [K] air.temperature = 300.0 # mixture composition in mole fractions air.x = [("O2", 0.21), ("N2", 0.79)] .. GENERATED FROM PYTHON SOURCE LINES 127-139 Print the properties of the air mixture for verification ======================================================== .. note:: - The default units of temperature and pressure are [K] and [dynes/cm\ :sup:`2`\ ], respectively. - The constant ``P_ATM`` is a conversion multiplier for pressure. - Transport property methods such as ``mixture_viscosity()`` require transport data. You must include the transport data file when creating the chemistry set. .. GENERATED FROM PYTHON SOURCE LINES 139-149 .. code-block:: Python # print pressure and temperature of the `air` mixture print(f"Pressure = {air.pressure / ansys.chemkin.core.P_ATM} [atm]") print(f"Temperature = {air.temperature} [K]") # print the 'air' composition in mass fractions air.list_composition(mode="mass") # get 'air' mixture density [g/cm3] print(f"Mixture density = {air.rho} [g/cm3]") # get 'air' mixture viscosity [g/cm-sec] or [poise] print(f"Mixture viscosity = {air.mixture_viscosity() * 100.0} [cP]") .. _sphx_glr_download_examples_chemistry_simple.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: simple.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: simple.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: simple.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_