# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # CANTERA MANIPULATION : 1
# required librairies import

# %matplotlib notebook
import cantera as ct
import numpy as np
import matplotlib.pyplot as plt

# ## gas manipulation
# gri30 is the mechanism file : and you can found a copy in "cantara/data" directory. You can use anyother mechanism file by uploading it on the server.

# When using Cantera, the first thing you usually need is an object representing some phase of matter.
# Here, we'll create a gas mixture:
gas1 = ct.Solution('gri30.cti')
# To view the state of the mixture, *call* the `gas1` object as if it were a function:
gas1()

# to get temperature
gas1.T

# to get enthalpie
gas1.h

# to change the state
gas1.TP = 500, 101325
gas1()

#The composition can be set in terms of either mole fractions (X) or mass fractions (Y):
gas1.X = 'CH4:1, O2:2, N2:7.52'
gas1()

# ## Chemical Equilibrium
# The chemical represents the burnt gas state (more precision will be given in a following courses)

# the enthalpie of the system and pressure is considered constant --> the temperature increases.
gas1.equilibrate('HP')
gas1()

# As this last command generates many species (all the sepcies present in the chemcial file).
# It is possible to force the program to work only with a few set of species:
#major = ['CH4','O2','CO2','H2O','N2']
#gas2 = ct.Solution(thermo='IdealGas', species=major)
majorspeciesname = {S.name: S for S in ct.Species.listFromFile('gri30.cti')}
majorspecies = [majorspeciesname[S] for S in ('CH4','O2','N2','CO2','H2O')]
gas1 = ct.Solution(thermo='IdealGas', species=majorspecies)
gas1.TPX = 500, 101325,'CH4:1, O2:2, N2:7.52'
gas1.equilibrate('HP')
#gas1()



StarcoderdataJupyterScriptsDedupFiltered