From charlesreid1

Cantera Evaluation of Properties

Some notes, from an algorithmic perspective, on hooking up Cantera with a finite-volume solver for computing solutions.

Using the Python interface to Cantera, if I create a gas phase object, I can see all the methods available for that gas phase:

In [1]: from Cantera import *

In [2]: g = GRI30()

In [3]: dir(g)
Out[3]:
['_Transport__tr_id',
 '__del__',
 '__doc__',
 '__init__',
 '__module__',
 '__repr__',
 '_end',
 '_equilmap',
 '_models',
 '_name',
 '_np',
 '_owner',
 '_phase_id',
 '_phnum',
 '_sp',
 'activationEnergies',
 'addTransportModel',
 'advanceCoverages',
 'atomicWeights',
 'binaryDiffCoeffs',
 'chemPotentials',
 'ckin',
 'clear',
 'cp_R',
 'cp_mass',
 'cp_mole',
 'creationRates',
 'cv_mass',
 'cv_mole',
 'delta_G',
 'delta_G0',
 'delta_H',
 'delta_H0',
 'delta_S',
 'delta_S0',
 'density',
 'desc',
 'destructionRates',
 'diffusionCoeffs',
 'electricPotential',
 'elementIndex',
 'elementName',
 'elementNames',
 'elementPotentials',
 'enthalpies_RT',
 'enthalpy_mass',
 'enthalpy_mole',
 'entropies_R',
 'entropy_mass',
 'entropy_mole',
 'equilibrate',
 'equilibriumConstants',
 'fwdRateConstants',
 'fwdRatesOfProgress',
 'gibbs_RT',
 'gibbs_mass',
 'gibbs_mole',
 'idtag',
 'intEnergy_mass',
 'intEnergy_mole',
 'isReversible',
 'kin_index',
 'kineticsSpeciesIndex',
 'kineticsStart',
 'kineticsType',
 'kinetics_hndl',
 'massFluxes',
 'massFraction',
 'massFractions',
 'maxTemp',
 'meanMolarMass',
 'meanMolecularWeight',
 'minTemp',
 'mixDiffCoeffs',
 'model',
 'molarDensity',
 'molarFluxes',
 'molarMasses',
 'moleFraction',
 'moleFractions',
 'molecularWeights',
 'multiDiffCoeffs',
 'multiplier',
 'nAtoms',
 'nElements',
 'nPhases',
 'nReactions',
 'nSpecies',
 'name',
 'netProductionRates',
 'netRatesOfProgress',
 'phase',
 'phase_id',
 'pressure',
 'productStoichCoeff',
 'productStoichCoeffs',
 'reactantStoichCoeff',
 'reactantStoichCoeffs',
 'reactionEqn',
 'reactionPhaseIndex',
 'reactionString',
 'reactionType',
 'refPressure',
 'restoreState',
 'revRateConstants',
 'revRatesOfProgress',
 'saveState',
 'selectElements',
 'selectSpecies',
 'set',
 'setDensity',
 'setElectricPotential',
 'setMassFractions',
 'setMolarDensity',
 'setMoleFractions',
 'setMultiplier',
 'setName',
 'setParameters',
 'setPressure',
 'setState_HP',
 'setState_PX',
 'setState_PY',
 'setState_SP',
 'setState_SV',
 'setState_TNX',
 'setState_TP',
 'setState_TPX',
 'setState_TPY',
 'setState_TR',
 'setState_TRX',
 'setState_TRY',
 'setState_UV',
 'setTemperature',
 'sourceTerms',
 'speciesIndex',
 'speciesName',
 'speciesNames',
 'switchTransportModel',
 'temperature',
 'thermalConductivity',
 'thermalDiffCoeffs',
 'thermo_hndl',
 'thermophase',
 'transport_hndl',
 'transport_id',
 'trnsp',
 'verbose',
 'viscosity',
 'volume_mass']

Wow. That's a lot of methods. And that's exactly why we want to interface with Cantera from an equation solver.

The Cantera Outline page contains a comprehensive list of pages on Cantera and its formulations. Those pages cover how to do things with these gas objects.

Diffusion

Covered here:

Called through the methods:

  • g.mixDiffCoeffs()
  • g.multiDiffCoeffs()

Note that if we use multicomponent diffusion coefficients, we have to specify that when we create the gas:

Wrong:

In [4]: g = GRI30()

In [5]: g.multiDiffCoeffs()
---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-5-c8f3cc1dc781> in <module>()
----> 1 g.multiDiffCoeffs()

/Users/charlesreid/codes/cantalysis/build/lib/python2.7/site-packages/Cantera/Transport.pyc in multiDiffCoeffs(self)
    156         coefficients. Not implemented in all transport managers."""
    157         return _cantera.tran_multiDiffCoeffs(self.__tr_id,
--> 158                                            self.trnsp)
    159
    160     def setParameters(self, type, k, params):

error:

************************************************
                Cantera Error!
************************************************


Procedure: Transport Base Class
Error:


**** Method getMultiDiffCoeffs not implemented in model 0 ****
(Did you forget to specify a transport model?)

Correct:

In [6]: g = GRI30('Multi')

In [7]: g.multiDiffCoeffs()
Out[7]:
array([[  0.00000000e+00,   2.16211927e-04,   1.08401378e-04, ...,
          4.68401619e-05,   5.73411067e-05,   5.73117527e-05],
       [  2.16211927e-04,   0.00000000e+00,   2.16802755e-04, ...,
          9.36803238e-05,   1.14682213e-04,   1.14623505e-04],
       [  1.08401378e-04,   2.72421028e-05,   0.00000000e+00, ...,
          5.90173041e-06,   7.22482032e-06,   7.22112180e-06],
       ...,
       [  4.68401619e-05,   9.88416546e-06,   4.95558763e-06, ...,
          0.00000000e+00,   2.62135856e-06,   2.62001664e-06],
       [  5.73411067e-05,   1.01255679e-05,   5.07661871e-06, ...,
          2.19360351e-06,   0.00000000e+00,   2.68400570e-06],
       [  5.73117527e-05,   9.89389411e-06,   4.96046525e-06, ...,
          2.14341368e-06,   2.62393867e-06,   0.00000000e+00]])

Fipy-Only Pieces

A simple transient problem with Fipy:

0D Reaction Equation

A Fipy script that will solve a very simple 0D reaction equation:


\frac{d C_j }{dt} = \sum_{i=1}^{N_{rxns}} r_{ij}

with reaction source terms computed by Cantera.

Fipy and Cantera/0D Reaction

0D Reaction Model: Batch Reactor

Filpy script that solves the 0D reaction equation, as well as other governing equations, for a 0D batch reactor model.

Fipy and Cantera/Batch Reactor

1D Convection-Reaction Equation

Using Fipy+Cantera to solve the one-dimensional convection reaction equation:

Fipy and Cantera/1D Convection Reaction

1D Convection-Reaction Model: Axial Profile

Once you can solve the one-dimensional convection reaction equation, you can reproduce an axial profile model for a PFR.

Fipy and Cantera/PFR Axial Profile Model

1D Diffusion Equation

A 1D diffusion problem solved by Fipy, with diffusion coefficients computed by Cantera. Illustrates how to solve a variable-diffusivity problem and sweep over the solution.

Fipy and Cantera/1D Diffusion

1D Diffusion Model: Boundary Value Problem

Fipy and Cantera/PFR Boundary Value Problem