updated tutorials
This commit is contained in:
parent
b65540f514
commit
84232c56f9
3 changed files with 64 additions and 26 deletions
|
|
@ -1,12 +1,15 @@
|
|||
####################################################################
|
||||
#
|
||||
# Tutorial 2: Using your own reaction mechanism files
|
||||
#
|
||||
print """
|
||||
|
||||
Tutorial 2: Using your own reaction mechanism files
|
||||
|
||||
"""
|
||||
####################################################################
|
||||
from time import clock
|
||||
|
||||
# You can build a gas mixture object by importing element, species,
|
||||
# and reaction definitions from input files in the format described in
|
||||
# the document "Defining Phases and Interfaces"). A set of input files
|
||||
# the document "Defining Phases and Interfaces". A set of input files
|
||||
# in this format is contained in the data folder.
|
||||
|
||||
# Many existing reaction mechanism files are in "CK format," by
|
||||
|
|
@ -21,32 +24,53 @@
|
|||
# Cantera format.
|
||||
|
||||
from Cantera import *
|
||||
gas1 = IdealGasMix('gri30.cti')
|
||||
t0 = clock()
|
||||
gas1 = importPhase('gri30.cti')
|
||||
print 'time to create gas1 = ',clock() - t0
|
||||
|
||||
# This statement creates a mixture that implements GRI-Mech 3.0, much
|
||||
# like function GRI30 does. File 'gri30.cti' is in the 'data'
|
||||
# directory. Under Windows, this directory is in
|
||||
# C:\Program Files\Common Files\Cantera.
|
||||
# directory. Under Windows, this directory is in C:\Program
|
||||
# Files\Common Files\Cantera and/or C:\CANTERA\DATA. On most other
|
||||
# platforms, it is usually in /usr/local/cantera/data.
|
||||
|
||||
# A Cantera input file may contain more than one phase specification, or may
|
||||
# contain specifications of interfaces (surfaces).
|
||||
|
||||
# Use importPhase to import a phase:
|
||||
t0 = clock()
|
||||
gas2 = importPhase('diamond.cti', 'gas') # a gas
|
||||
print 'time to create gas2 = ',clock() - t0
|
||||
|
||||
t0 = clock()
|
||||
diamond = importPhase('diamond.cti','diamond') # bulk diamond
|
||||
print 'time to create diamond = ',clock() - t0
|
||||
|
||||
# Use importInterface to import a surface:
|
||||
t0 = clock()
|
||||
diamonnd_surf = importInterface('diamond.cti','diamond_100',
|
||||
phases = [gas2, diamond])
|
||||
# Note that the bulk (i.e., 3D) phases that participate in the surface reactions
|
||||
# must also be passed as arguments to importInterface.
|
||||
print 'time to create diamond_surf = ',clock() - t0
|
||||
|
||||
# Note that the bulk (i.e., 3D) phases that participate in the surface
|
||||
# reactions must also be passed as arguments to importInterface.
|
||||
|
||||
# Multiple phases defined in the same input file can be imported with
|
||||
# one statement:
|
||||
t0 = clock()
|
||||
[gas3, diamond2] = importPhases('diamond.cti', ['gas','diamond'])
|
||||
print 'time to create both gas3 and diamond2 = ',clock() - t0
|
||||
|
||||
# Note that importing from a file is much faster the second time. This
|
||||
# is because the file is only read and converted to XML once. The XML
|
||||
# tree is kept in memory once it is read in case it is needed later.
|
||||
|
||||
# How does Cantera find input files like diamond.cti? Cantera always
|
||||
# looks in the local directory first. If it is not there, Cantera
|
||||
# looks for it on its search path. It looks for it in the data
|
||||
# directory specified when Cantera was built (by default this is
|
||||
# /usr/local/cantera/data on unix systems). If you define environment
|
||||
# variable CANTERA_DATA_DIR, it will also look there, or else you can
|
||||
# variable CANTERA_DATA, it will also look there, or else you can
|
||||
# call function addDirectory to add a directory to the search path.
|
||||
|
||||
# Warning: when Cantera reads a .cti input file, wherever it is
|
||||
|
|
@ -56,5 +80,13 @@ diamonnd_surf = importInterface('diamond.cti','diamond_100',
|
|||
# you can use it instead of the .cti file, which will result in
|
||||
# somewhat faster startup.
|
||||
|
||||
gas4 = IdealGasMix('gri30.xml')
|
||||
# Note that the function 'IdealGasMix' simply calls 'importPhase', and
|
||||
# checks that the phase represents an ideal gas mixture
|
||||
|
||||
# Interfaces can be imported from XML files too.
|
||||
diamonnd_surf2 = importInterface('diamond.xml','diamond_100',
|
||||
phases = [gas2, diamond])
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
######################################################
|
||||
#
|
||||
# Getting Help
|
||||
#
|
||||
print """
|
||||
|
||||
Tutorial 3: Getting Help
|
||||
|
||||
"""
|
||||
######################################################
|
||||
|
||||
# Python has a built-in help facility. To get help on any class or
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
#################################################################
|
||||
#
|
||||
# Tutorial 4: Chemical Equilibrium
|
||||
#
|
||||
print """
|
||||
|
||||
Tutorial 4: Chemical Equilibrium
|
||||
|
||||
"""
|
||||
#################################################################
|
||||
|
||||
# To set a gas mixture to a state of chemical equilibrium, use the
|
||||
|
|
@ -9,15 +11,15 @@
|
|||
#
|
||||
from Cantera import *
|
||||
g = GRI30()
|
||||
set(g,T=300.0,P=OneAtm,X='CH4:0.95,O2:2,N2:7.52')
|
||||
g.set(T = 300.0, P = OneAtm, X = 'CH4:0.95,O2:2,N2:7.52')
|
||||
g.equilibrate('TP')
|
||||
|
||||
# The above statement sets the state of object 'g' to the state of
|
||||
# chemical equilibrium holding temperature and pressure
|
||||
# fixed. Alternatively, the specific enthalpy and pressure can be
|
||||
# held fixed:
|
||||
# fixed. Alternatively, the specific enthalpy and pressure can be held
|
||||
# fixed:
|
||||
|
||||
set(g,T=300.0,P=OneAtm,X='CH4:0.95,O2:2,N2:7.52')
|
||||
g.set(T = 300.0, P = OneAtm, X = 'CH4:0.95,O2:2,N2:7.52')
|
||||
g.equilibrate('HP')
|
||||
|
||||
# Other options are
|
||||
|
|
@ -25,15 +27,15 @@ g.equilibrate('HP')
|
|||
# 'SV' fixed specific entropy and specific volume
|
||||
# 'SP' fixed specific entropy and pressure
|
||||
|
||||
set(g,T=300.0,P=OneAtm,X='CH4:0.95,O2:2,N2:7.52')
|
||||
g.set(T = 300.0, P = OneAtm, X = 'CH4:0.95,O2:2,N2:7.52')
|
||||
g.equilibrate('UV')
|
||||
print g
|
||||
|
||||
set(g,T=300.0,P=OneAtm,X='CH4:0.95,O2:2,N2:7.52')
|
||||
g.set(T = 300.0, P = OneAtm, X = 'CH4:0.95,O2:2,N2:7.52')
|
||||
g.equilibrate('SV')
|
||||
print g
|
||||
|
||||
set(g,T=300.0,P=OneAtm,X='CH4:0.95,O2:2,N2:7.52')
|
||||
g.set(T = 300.0, P = OneAtm, X = 'CH4:0.95,O2:2,N2:7.52')
|
||||
g.equilibrate('SP')
|
||||
print g
|
||||
|
||||
|
|
@ -42,15 +44,17 @@ print g
|
|||
# progress of all reversible reactions are zero.
|
||||
|
||||
# Here is the code to do this:
|
||||
set(g,T=300.0,P=OneAtm,X='CH4:0.95,O2:2,N2:7.52')
|
||||
g.set(T = 300.0, P = OneAtm, X = 'CH4:0.95,O2:2,N2:7.52')
|
||||
g.equilibrate('HP')
|
||||
|
||||
rf = g.fwdRatesOfProgress()
|
||||
rr = g.revRatesOfProgress()
|
||||
for i in range(g.nReactions()):
|
||||
if g.isReversible(i) and rf[i] <> 0.0:
|
||||
print ' %4i %10.4g %10.4g %10.4g ' % (i, rf[i], rr[i], (rf[i] - rr[i])/rf[i])
|
||||
|
||||
print ' %4i %10.4g ' % (i, (rf[i] - rr[i])/rf[i])
|
||||
# If the magnitudes of the numbers in this list are all very small,
|
||||
# then each reversible reaction is very nearly equilibrated, which
|
||||
# only occurs if the gas is in chemical equilibrium.
|
||||
|
||||
# You might be wondering how 'equilibrate' works. (Then again, you might
|
||||
# not, in which case you can go on to the next tutorial now.) Method
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue