:orphan: .. _examples: Examples ======== This section shows how to use PyChemkin utilities and reactor models to perform different types of simulations. Early examples demonstrate how to perform essential operations, such as loading and preprocessing the chemistry set. Later examples explain how to tackle more complex simulations, such as running an ignition delay parameter study. Thus, you should go through the examples in the order listed. .. note:: When you use the Jupyter Notebook version of the example projects (``*.ipynb``), please remember to *close the project after you finish viewing and/or running the project*. When the project is open, it might hold on to your Ansys license. If you have too many Jupyter Notebook projects active, you might run out of your Ansys licenses. Closing the Jupyter Notebook project will release the license. If the *Jupyter Notebook web interface* is used to load the PyChemkin example projects, you can navigate to the top menu bar and select ``File > Close and Shut Down Notebook`` to close the project and release the license. If the *VS Code* is used, you can simply close the tab associated with the example. .. raw:: html
.. thumbnail-parent-div-open .. thumbnail-parent-div-close .. raw:: html
Chemistry ========= PyChemkin examples to demonstrate basic operations for instantiating *Chemistry Set* from the gas-phase mechanism and the thermodynamic/transport data files. The examples walk through the steps about how to pre-process the *Chemistry Set*, retrieve mechanism information and the species properties, as well as how to handle multiple *Chemistry Sets* in a **Python Chemkin** project. .. raw:: html
.. thumbnail-parent-div-open .. raw:: html
.. only:: html .. image:: /examples/chemistry/images/thumb/sphx_glr_loadmechanism_thumb.png :alt: :doc:`/examples/chemistry/loadmechanism` .. raw:: html
Preprocess a gas-phase mechanism
.. raw:: html
.. only:: html .. image:: /examples/chemistry/images/thumb/sphx_glr_multiplemechanisms_thumb.png :alt: :doc:`/examples/chemistry/multiplemechanisms` .. raw:: html
Work with multiple mechanisms
.. raw:: html
.. only:: html .. image:: /examples/chemistry/images/thumb/sphx_glr_simple_thumb.png :alt: :doc:`/examples/chemistry/simple` .. raw:: html
Set up a PyChemkin project
.. raw:: html
.. only:: html .. image:: /examples/chemistry/images/thumb/sphx_glr_speciesproperties_thumb.png :alt: :doc:`/examples/chemistry/speciesproperties` .. raw:: html
Evaluate gas species properties
.. thumbnail-parent-div-close .. raw:: html
Mixture ======= *Mixture* is the "core" token in **PyChemkin**. It represents a gas-phase mixture by storing its pressure, temperature, and species composition. *Stream* is an extended "Class" of *Mixture* with the additional attribute of "mass/volumetric flow rate". *Mixture* and *Stream* include utilities that can be used to evaluate the mixture properties (density, mixture enthalpy, mixture viscosity, ...) and the reaction rates. There are also methods to manipulate the *Mixture*/*Stream* such as merging two mixtures adiabatically. The examples demonstrate how to instantiate the *Mixture*/*Stream* objects, how to extract information and properties of a *Mixture*/*Stream*, and how to manipulate *Mixture*/*Stream* objects. .. raw:: html
.. thumbnail-parent-div-open .. raw:: html
.. only:: html .. image:: /examples/mixture/images/thumb/sphx_glr_adiabaticflametemperature_thumb.png :alt: :doc:`/examples/mixture/adiabaticflametemperature` .. raw:: html
Estimate the adiabatic flame temperature of a gas mixture
.. raw:: html
.. only:: html .. image:: /examples/mixture/images/thumb/sphx_glr_createmixture_thumb.png :alt: :doc:`/examples/mixture/createmixture` .. raw:: html
Create a mixture
.. raw:: html
.. only:: html .. image:: /examples/mixture/images/thumb/sphx_glr_detonation_thumb.png :alt: :doc:`/examples/mixture/detonation` .. raw:: html
Calculate the detonation wave speed of a real-gas mixture
.. raw:: html
.. only:: html .. image:: /examples/mixture/images/thumb/sphx_glr_equilibriumcomposition_thumb.png :alt: :doc:`/examples/mixture/equilibriumcomposition` .. raw:: html
Estimate the steady-state NO emission level of a complete burned fuel-air mixture
.. raw:: html
.. only:: html .. image:: /examples/mixture/images/thumb/sphx_glr_heatingvalues_thumb.png :alt: :doc:`/examples/mixture/heatingvalues` .. raw:: html
Calculate the heating values of fuel mixtures
.. raw:: html
.. only:: html .. image:: /examples/mixture/images/thumb/sphx_glr_mixturemixing_thumb.png :alt: :doc:`/examples/mixture/mixturemixing` .. raw:: html
Combine gas mixtures
.. raw:: html
.. only:: html .. image:: /examples/mixture/images/thumb/sphx_glr_reactionrates_thumb.png :alt: :doc:`/examples/mixture/reactionrates` .. raw:: html
Rank reaction rates
.. thumbnail-parent-div-close .. raw:: html
Batch reactor ============= The *batch reactor* is an idealized 0-D transient closed reactor model in which the gas inside the reactor is assumed to be homogeneous. When the pressure of the *batch reactor* is constrained, the reactor volume would vary to conserve the total gas mass. Likewise, the reactor pressure might change when the reactor volume is "given". The gas temperature can be "given" by piecewise linear profile data or solved by the energy equation. The examples consist of projects that utilize the *batch reactor* model to perform simulations of various complexities, from tracking the evolution of the mixture properties to the A-factor sensitivity analysis. .. raw:: html
.. thumbnail-parent-div-open .. raw:: html
.. only:: html .. image:: /examples/batch/images/thumb/sphx_glr_closed_homogeneous__transient_thumb.png :alt: :doc:`/examples/batch/closed_homogeneous__transient` .. raw:: html
Simulate hydrogen combustion in a constant-pressure reactor
.. raw:: html
.. only:: html .. image:: /examples/batch/images/thumb/sphx_glr_ignitiondelay_thumb.png :alt: :doc:`/examples/batch/ignitiondelay` .. raw:: html
Predict the ignition delay time of a combustible mixture
.. raw:: html
.. only:: html .. image:: /examples/batch/images/thumb/sphx_glr_rcm_thumb.png :alt: :doc:`/examples/batch/rcm` .. raw:: html
Simulate a rapid compression machine
.. raw:: html
.. only:: html .. image:: /examples/batch/images/thumb/sphx_glr_sensitivity_thumb.png :alt: :doc:`/examples/batch/sensitivity` .. raw:: html
Perform brute-force sensitivity analysis
.. raw:: html
.. only:: html .. image:: /examples/batch/images/thumb/sphx_glr_vapor_thumb.png :alt: :doc:`/examples/batch/vapor` .. raw:: html
Explore cooling water vapor
.. thumbnail-parent-div-close .. raw:: html
0-D engine models ================= **PyChemkin** offers two types of 0-D engine models: the *Homogeneous Charged Compression Ignition (HCCI)* engine model and the *Spark Ignition (SI)* engine model. These 0-D engine models simulate the combustion process (or the lack of, in case of a misfire) inside an engine cylinder between the *Intake Valve Close (IVC)* and the *Exhaust Valve Open (EVO)* when the cylinder is considered as a closed system. The Chemkin *Theory* manual has detailed descriptions of these 0-D engine models. The examples show the steps of setting up simulations with different *Chemkin* engine models. .. raw:: html
.. thumbnail-parent-div-open .. raw:: html
.. only:: html .. image:: /examples/engine/images/thumb/sphx_glr_hcciengine_thumb.png :alt: :doc:`/examples/engine/hcciengine` .. raw:: html
Simulate a single-zone HCCI engine
.. raw:: html
.. only:: html .. image:: /examples/engine/images/thumb/sphx_glr_multizone_thumb.png :alt: :doc:`/examples/engine/multizone` .. raw:: html
Simulate a multi-zone HCCI engine
.. raw:: html
.. only:: html .. image:: /examples/engine/images/thumb/sphx_glr_sparkignitioengine_thumb.png :alt: :doc:`/examples/engine/sparkignitioengine` .. raw:: html
Simulate a spark ignition engine
.. thumbnail-parent-div-close .. raw:: html
Perfectly stirred reactor ========================= The *perfectly Stirred reactor (PSR)* model is a 0-D steady-state reactor. This ideal reactor model assumes the gas mixture inside is uniform and the properties of the outlet stream are exactly the same as the gas properties inside the reactor. A PSR can have either its pressure or its volume "specified", and the reactor temperature can either be solved from the energy equation or be "given" as an input parameter. The examples will show the procedures of setting up single PSR simulations with different constraints and with multiple inlet streams. .. raw:: html
.. thumbnail-parent-div-open .. raw:: html
.. only:: html .. image:: /examples/PSR/images/thumb/sphx_glr_PSRgas_thumb.png :alt: :doc:`/examples/PSR/PSRgas` .. raw:: html
Set up a PSR parameter study for the inlet stream equivalence ratio
.. raw:: html
.. only:: html .. image:: /examples/PSR/images/thumb/sphx_glr_jetstirredreactor_thumb.png :alt: :doc:`/examples/PSR/jetstirredreactor` .. raw:: html
Run PSR calculations for mechanism validation
.. raw:: html
.. only:: html .. image:: /examples/PSR/images/thumb/sphx_glr_multi-inletPSR_thumb.png :alt: :doc:`/examples/PSR/multi-inletPSR` .. raw:: html
Determine the impact of residence time on combustion in a PSR
.. thumbnail-parent-div-close .. raw:: html
Plug-flow reactor ================= *Plug-Flow Reactor (PFR)* model is an idealized 1-D steady-state flow reactor model with single inlet stream. The reactor pressure is assumed to be given, and the mass (flow rate) conservation is maintained by the velocity change. The gas temperature along the reactor can be either specified or solved by the energy equation. .. raw:: html
.. thumbnail-parent-div-open .. raw:: html
.. only:: html .. image:: /examples/PFR/images/thumb/sphx_glr_plugflow_thumb.png :alt: :doc:`/examples/PFR/plugflow` .. raw:: html
Simulate NO reduction in combustion exhaust
.. thumbnail-parent-div-close .. raw:: html
Shock tube reactor =================== The *shock tube reactor* model is a 0-D transient reactor. This ideal reactor model is normally used to reproduce the shock tube experiments for chemical kinetics researches. The *incident shock* model predicts species profiles behind the incident shock front which can be used to compare against corresponding experimental data. Similarly, the *reflected shock* model complements the experiments for kinetics researches at the high temperature conditions behind a reflected shock front. The examples will show the procedures of setting up an incident shock (with boundary layer correction) simulation and a Zeldovich-von Neumann-Deoring (ZND) analysis of a combustible gas mixture. .. raw:: html
.. thumbnail-parent-div-open .. raw:: html
.. only:: html .. image:: /examples/shock_tube/images/thumb/sphx_glr_ZND_thumb.png :alt: :doc:`/examples/shock_tube/ZND` .. raw:: html
Perform ZND analysis of a combustible hydrogen mixture
.. raw:: html
.. only:: html .. image:: /examples/shock_tube/images/thumb/sphx_glr_incidentshock_thumb.png :alt: :doc:`/examples/shock_tube/incidentshock` .. raw:: html
Nitric oxide formation in air heated by an incident shock wave
.. raw:: html
.. only:: html .. image:: /examples/shock_tube/images/thumb/sphx_glr_reflectedshock_thumb.png :alt: :doc:`/examples/shock_tube/reflectedshock` .. raw:: html
Dissociation of nitrous oxide behind a reflected shock wave
.. thumbnail-parent-div-close .. raw:: html
PSR network =========== **PyChemkin** can be used to create an *Equivalence Reactor Network (ERN)* as a reduced-order (in geometry) model for complex combustion applications such as gas turbine combustor. Each reactor in the network represents a sub-region (zone) in the actual equipment. Normally these zones are created according to specific criteria such as temperature, equivalence ratio, or location; and the gas flow (mean, turbulent, and diffusive) between the zones becomes the internal streams between the reactors. There are several ways to build an *ERN* in **PyChemkin**. The first method is to create and solve the reactors one-by-one starting from the most upstream (first) reactor. Adjust/manipulate the external and outlet streams from connected reactors (that is, solutions from the reactors) using the *Mixture*/*Stream* utilities and apply the desired stream as the inlet for the downstream reactors. The second method takes advantage of the *hybridreactornetwork* "model" of **PyChemkin**. Simply defined the reactors with the associated external inlets and add the reactors to the *hybridreactornetwork*. If there are *recycling* streams from the downstream reactor to the upstream ones, the *hybridreactornetwork* will solve the entire *ERN* iteratively. In this case, a *tear point* must be explicitly specified. The last method, the coupled method, is to create the network and its connectivity first, and the entire *ERN* will be solved in a coupled manner. This method is the default method in Chemkin GUI and is available as the *PSRCluster* "model" in **PyChemkin**. Chemkin *ERN* has a few limitations: * The first reactor of the reactor network must have at least one external inlet. * when using the *coupled* model, the entire reactor network can have only one outlet to the surroundings, and the outlet must be attached to the last reactor in the network. * PSR is the only reactor model allowed in the *PSRCluster* and the *hybridreactornetwork* reactor networks. The *PSRChain_xxx* examples show the two methods to build and run a series of linked PSRs (no stream recycling) can be modeled in **PyChemkin**. The *PSRnetwork* example goes over the steps of creating and running an *ERN* with recycling streams by using the *hybridreactornetwork* method. The *PSRnetwork_coupled* example solves the same *ERN* as the *PSRnetwork* example but utilizes the *coupled* method. Because the sole outlet from the *coupled ERN* must be attached to the last reactor, the order of the downstream zones is different from the *PSRnetwork* example. .. raw:: html
.. thumbnail-parent-div-open .. raw:: html
.. only:: html .. image:: /examples/reactor_network/images/thumb/sphx_glr_PSRChain_declustered_thumb.png :alt: :doc:`/examples/reactor_network/PSRChain_declustered` .. raw:: html
Use a chain of individual reactors to model a gas combustor
.. raw:: html
.. only:: html .. image:: /examples/reactor_network/images/thumb/sphx_glr_PSRChain_network_thumb.png :alt: :doc:`/examples/reactor_network/PSRChain_network` .. raw:: html
Use a chain reactor network to model a gas combustor
.. raw:: html
.. only:: html .. image:: /examples/reactor_network/images/thumb/sphx_glr_PSRChain_network_heat_exchange_thumb.png :alt: :doc:`/examples/reactor_network/PSRChain_network_heat_exchange` .. raw:: html
A simple reactor network with heat exchange
.. raw:: html
.. only:: html .. image:: /examples/reactor_network/images/thumb/sphx_glr_PSRChain_network_heat_exchange_coupled_thumb.png :alt: :doc:`/examples/reactor_network/PSRChain_network_heat_exchange_coupled` .. raw:: html
A PSR cluster with heat exchange
.. raw:: html
.. only:: html .. image:: /examples/reactor_network/images/thumb/sphx_glr_PSRnetwork_thumb.png :alt: :doc:`/examples/reactor_network/PSRnetwork` .. raw:: html
Simulate a combustor using an equivalent reactor network with stream recycling
.. raw:: html
.. only:: html .. image:: /examples/reactor_network/images/thumb/sphx_glr_PSRnetwork_coupled_thumb.png :alt: :doc:`/examples/reactor_network/PSRnetwork_coupled` .. raw:: html
Simulate a combustor using a coupled equivalent reactor network with stream recycling
.. thumbnail-parent-div-close .. raw:: html
Premixed flame models ===================== The *Premixed Flame* model is a 1-D steady-state application, and it contains two sub-models: *"flame speed calculator"* (or the freely propagating flame model) and *"flat flame"* model. The *flame speed calculator* is commonly used to calculate the laminar flame speed of a premixed fuel-oxidizer mixture. The predicted/computed flame speeds can be used to validate a combustion mechanism or can serve as a prre-processor to construct a "flame speed table" or a "combustion progress table" for other applications. The *flat flame* burner-stablized model is primarily used to study the flame chemistry in conjunction with the flat flame experiments. The examples show different ways to perform the "premixed flame" calculations. .. raw:: html
.. thumbnail-parent-div-open .. raw:: html
.. only:: html .. image:: /examples/premixed_flame/images/thumb/sphx_glr_flamespeed_thumb.png :alt: :doc:`/examples/premixed_flame/flamespeed` .. raw:: html
Compute the laminar flame speed of diluted hydrogen at low pressure
.. raw:: html
.. only:: html .. image:: /examples/premixed_flame/images/thumb/sphx_glr_methane_flamespeed_table_thumb.png :alt: :doc:`/examples/premixed_flame/methane_flamespeed_table` .. raw:: html
Construct atmospheric methane-air flame speed versus equivalence ratio table
.. raw:: html
.. only:: html .. image:: /examples/premixed_flame/images/thumb/sphx_glr_premixedburnerflame_thumb.png :alt: :doc:`/examples/premixed_flame/premixedburnerflame` .. raw:: html
Simulate a burner stabilized premixed flame
.. thumbnail-parent-div-close .. raw:: html
Opposed-flow flame model ======================== The *opposed-flow Flame* model is a 1-D steady-state application to study the structure of stretched flames in the opposed-flow configuration. It can also be used to generate a "flamelet table" for CFD simulations. See the Chemkin *Theory* manual for additional information about this feature. .. raw:: html
.. thumbnail-parent-div-open .. raw:: html
.. only:: html .. image:: /examples/opposed_flow_flame/images/thumb/sphx_glr_dual_flame_thumb.png :alt: :doc:`/examples/opposed_flow_flame/dual_flame` .. raw:: html
Study flame interactions in an opposed-flow flame configuration
.. thumbnail-parent-div-close .. raw:: html
Surface chemistry ================= The examples in this section demonstrate how *surface chemistry* can be included in a *Chemistry Set* and applied to simulate chemical vapor deposition (CVD) and catalytic combustion processes in **PyChemkin**. .. raw:: html
.. thumbnail-parent-div-open .. raw:: html
.. only:: html .. image:: /examples/surface_chemistry/images/thumb/sphx_glr_SiC_cvd_thumb.png :alt: :doc:`/examples/surface_chemistry/SiC_cvd` .. raw:: html
Simulating the chemical vapor deposition (CVD) process
.. raw:: html
.. only:: html .. image:: /examples/surface_chemistry/images/thumb/sphx_glr_catalytic_combustion_thumb.png :alt: :doc:`/examples/surface_chemistry/catalytic_combustion` .. raw:: html
Simulating CH4 catalytic Combustion process
.. raw:: html
.. only:: html .. image:: /examples/surface_chemistry/images/thumb/sphx_glr_multiple_materials_thumb.png :alt: :doc:`/examples/surface_chemistry/multiple_materials` .. raw:: html
Processing a surface mechanism with multiple materials
.. thumbnail-parent-div-close .. raw:: html
Multiprocessing parameter study =============================== Chemkin application by itself does not support parallel computing, however, in the context of parameter study, each case can run on its own CPU core to make better use of any available computing power. The examples in this section describe the process of applying Python multi-threading and multi-processing packages to **PyChemkin** parameter study to improve the overall simulation performance. .. raw:: html
.. thumbnail-parent-div-open .. raw:: html
.. only:: html .. image:: /examples/multiprocessing/images/thumb/sphx_glr_SI_engine_knock_calculation_multiprocessing_thumb.png :alt: :doc:`/examples/multiprocessing/SI_engine_knock_calculation_multiprocessing` .. raw:: html
SI engine knocking analysis
.. raw:: html
.. only:: html .. image:: /examples/multiprocessing/images/thumb/sphx_glr_flame_speed_calculation_multiprocessing_thumb.png :alt: :doc:`/examples/multiprocessing/flame_speed_calculation_multiprocessing` .. raw:: html
Setting up a multi-process laminar flame speed parameter study
.. raw:: html
.. only:: html .. image:: /examples/multiprocessing/images/thumb/sphx_glr_flame_speed_calculation_threading_thumb.png :alt: :doc:`/examples/multiprocessing/flame_speed_calculation_threading` .. raw:: html
Setting up a multi-thread laminar flame speed parameter study
.. thumbnail-parent-div-close .. raw:: html
Advanced Applications ===================== Examples in this section are to showcase the use of Pychemkin in more complicated applications. You can make improvements to a Pychemkin reactor model by adding new physical processes. Or, you can have Pychemkin interact with other Python applications to address complex problems. .. raw:: html
.. thumbnail-parent-div-open .. raw:: html
.. only:: html .. image:: /examples/advanced/images/thumb/sphx_glr_SI_engine_optimization_thumb.png :alt: :doc:`/examples/advanced/SI_engine_optimization` .. raw:: html
Find the optimal operating parameters for a given SI engine
.. raw:: html
.. only:: html .. image:: /examples/advanced/images/thumb/sphx_glr_pseudo-chastic_HCCI_thumb.png :alt: :doc:`/examples/advanced/pseudo-chastic_HCCI` .. raw:: html
A pseudo stochastic scheme to simulate a stratified-charged compression-ignition engine
.. raw:: html
.. only:: html .. image:: /examples/advanced/images/thumb/sphx_glr_run_chemkin_applications_thumb.png :alt: :doc:`/examples/advanced/run_chemkin_applications` .. raw:: html
Run chemkin applications in Python
.. thumbnail-parent-div-close .. raw:: html
.. toctree:: :hidden: :includehidden: /examples/chemistry/index.rst /examples/mixture/index.rst /examples/batch/index.rst /examples/engine/index.rst /examples/PSR/index.rst /examples/PFR/index.rst /examples/shock_tube/index.rst /examples/reactor_network/index.rst /examples/premixed_flame/index.rst /examples/opposed_flow_flame/index.rst /examples/surface_chemistry/index.rst /examples/multiprocessing/index.rst /examples/advanced/index.rst .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-gallery .. container:: sphx-glr-download sphx-glr-download-python :download:`Download all examples in Python source code: examples_python.zip ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download all examples in Jupyter notebooks: examples_jupyter.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_