From charlesreid1

Line 2: Line 2:


=Specifying Thermochemical State=
=Specifying Thermochemical State=
==The Basics==


For a multicomponent mixture of gas containing N components, the thermochemical state of the gas can be specified by specifying N+1 thermodynamic variables.  
For a multicomponent mixture of gas containing N components, the thermochemical state of the gas can be specified by specifying N+1 thermodynamic variables.  
Line 28: Line 30:
g.set(P=OneAtm, Rho=0.10)
g.set(P=OneAtm, Rho=0.10)
</source>
</source>
==Specifying Composition==
Composition can be specified either as a string, or as an array.
Specifying composition as a string is the "human method": it ensures the user can specify which species have which quantities, in an arbitrary order.
Specifying composition as an array is the "machine method": it ensures that scripts can pass composition information quickly and easily to gases, without having to translate back and forth between strings or lose information through string formatting.
Let's make a simple gas from an H2O2 oxidation mechanism:
<pre>
In [11]: g = importPhase('h2o2.cti')
In [12]: g.set(T=298.15,P=OneAtm)
In [13]: g.nSpecies()
Out[13]: 9
In [14]: g.speciesNames()
Out[14]: ['H2', 'H', 'O', 'O2', 'OH', 'H2O', 'HO2', 'H2O2', 'AR']
</pre>
We can specify composition with a string. Using mole fractions first:
<pre>
In [15]: g.set(X="H2:2.0, O2:1.0")
</pre>
Using mass fractions:
<pre>
In [16]: g.set(Y="H2:1.0, O2:8.0")
</pre>


=Code=
=Code=

Revision as of 22:44, 22 January 2014

Some scattered notes on Cantera gas objects.

Specifying Thermochemical State

The Basics

For a multicomponent mixture of gas containing N components, the thermochemical state of the gas can be specified by specifying N+1 thermodynamic variables.

The gas state can be specified using the set method, which takes a couple of keywords for specifying which variable you wish to set. The following parameters are mass-specific, meaning they are specified per unit mass:

  • Pressure P
  • Temperature T
  • Specific volume V
  • Mass density Rho
  • Mass fractions Y
  • Mole fractions X
  • Enthalpy H
  • Entropy S
  • Internal energy U

(Note that if composition is not specified, it remains unchanged.)

These keywords can be used with the phase set method,

from Cantera import *

g = GRI30()

g.set(X="H2:1.0, CO2:3.0", T=298.15, P=OneAtm)
g.set(P=OneAtm, Rho=0.10)

Specifying Composition

Composition can be specified either as a string, or as an array.

Specifying composition as a string is the "human method": it ensures the user can specify which species have which quantities, in an arbitrary order.

Specifying composition as an array is the "machine method": it ensures that scripts can pass composition information quickly and easily to gases, without having to translate back and forth between strings or lose information through string formatting.

Let's make a simple gas from an H2O2 oxidation mechanism:

In [11]: g = importPhase('h2o2.cti')

In [12]: g.set(T=298.15,P=OneAtm)

In [13]: g.nSpecies()
Out[13]: 9

In [14]: g.speciesNames()
Out[14]: ['H2', 'H', 'O', 'O2', 'OH', 'H2O', 'HO2', 'H2O2', 'AR']

We can specify composition with a string. Using mole fractions first:

In [15]: g.set(X="H2:2.0, O2:1.0")

Using mass fractions:

In [16]: g.set(Y="H2:1.0, O2:8.0")

Code

Python Interface

The Python interface implements the set() method as a standalone function, in the following file:

/path/to/cantera/interfaces/python/Cantera/set.py

The set() method is a wrapper function to methods that individually set thermodynamic property, like setTemperature() or setDensity(), or methods that set pairs of properties, like setState_UV() or setState_HP().

These methods, in turn, are defined in the Phase classes, which themselves utilize the C API to specify these thermodynamic properties.