"""
Constant-pressure, adiabatic kinetics simulation.
"""
import numpy as np
import cantera as ct
temp = 298.0 #Initial temperature = Atmosphereic temperature in Kelvin
pres = ct.one_atm #Atmospheric pressure
# phases
gas_CH4 = ct.Solution('gri30.cti')
air_O2 = ct.Solution('gri30.cti')
air_N2 = ct.Solution('gri30.cti')
# the phases that will be included in the calculation, and their initial moles
mix_phases = [ (gas_CH4, 16.04),(air_O2, 32.0),(air_N2, 28.0) ]
# gaseous fuel species
fuel_species = 'CH4'
# air composition
air_N2_O2_ratio = 3.76
# equivalence ratio range
phi_min = 0.8
phi_max = 1.2
npoints = 10
##############################################################################
mix = ct.Mixture(mix_phases)
nsp = mix.n_species #Number of species
# create some arrays to hold the data
phi = np.zeros(npoints,'d')
tad = np.zeros(npoints,'d')
xeq = np.zeros([nsp/3,npoints],'d')
# find fuel, nitrogen, and oxygen indices
ifuel= gas_CH4.species_index(fuel_species)
io2= air_O2.species_index('O2')
in2 = air_N2.species_index('N2')
for i in range(npoints):
phi[i] = phi_min + (phi_max - phi_min)*i/(npoints - 1)
X = np.zeros(nsp)
X[ifuel] = phi[i]
X[io2] = 1 #Stoichiometric mixture
X[in2] = 1*air_N2_O2_ratio
# set the gas state
gas_CH4.TPX= temp, pres, 'CH4:phi[i]'
air_O2.TPX=temp,pres,'O2:1.055'
air_N2.TPX=temp,pres,'N2:1.055*air_N2_O2_ratio'
mix_phases = [(gas_CH4, phi[i]),(air_O2, 1),(air_N2,1*air_N2_O2_ratio)]
# create a mixture of 1 mole of gas, and 0 moles of solid carbon.
mix = ct.Mixture(mix_phases)
# equilibrate the mixture adiabatically at constant P
mix.equilibrate('HP')
print 'Methane: CH4'
print '%10s %15s' % ('T [K]', 'h [J/kg]')
print mix.T, gas_CH4.h
gas = ct.Solution('gri30.cti')
gas.TPX = 298, 101325, 'CH4:1,O2:2,N2:7.52'
gas.equilibrate('HP')foo = 3.76
bar = 0.2
X = 'N2:{0}, O2:{1}'.format(foo, 5*bar)