#### Previous topic

Tutorial: Working with input files

#### Next topic

Interfaces

Warning

This documentation is for an old version of Cantera. You can find docs for newer versions here.

# Importing Phase Objects¶

## Solution¶

class Solution(src, id, trans)

Solution class constructor.

Class Solution() represents solutions of multiple species. A solution is defined as a mixture of two or more constituents (species) that are completely mixed on molecular length scales. The macroscopic intensive thermodynamic state of a solution is specified by two thermodynamic properties (for example, the temperature and pressure), and the relative amounts of each species, which may be given as mole fractions or mass fractions.

>> s = Solution('input.xml'[, phase_name[, transport_model]])


constructs a Solution object from a specification contained in file input.xml. Optionally, the name of the phase to be imported can be specified with phase_name. If a Transport model is included in input.xml, it will be included in the Solution instance with the default transport modeling as set in the input file. To specify the transport modeling, set the input argument trans to one of 'default', 'Mix', or 'Multi'. In this case, the phase name must be specified as well. Alternatively, change the transport node in the CTML file, or transport property inthe CTI file before loading the phase. The transport modeling cannot be changed once the phase is loaded.

Class Solution() derives from three more basic classes, and most of its methods are inherited from these classes. These are:

Parameters: src – Input string of CTI or CTML file name. id – Optional unless trans is specified. ID of the phase to import as specified in the CTML or CTI file. trans – String, transport modeling. Possible values are 'default', 'Mix', or 'Multi'. If not specified, 'default' is used. Instance of class Solution()
IdealGasMix(infile, b, c)

Create a mixture of ideal gases.

Create a Solution() instance representing an ideal gas mixture.

gas1 = IdealGasMix('ctml_file'[,'transport_model'])
gas2 = IdealGasMix('ck_file'[,'thermo_db'[,'tran_db'[,'transport_model']]])


creates an object that represents an ideal gas mixture. The species in the mixture, their properties, and the reactions among the species, if any, are specified in file ‘ctml_file’ and ‘ck_file’. Two input file formats are supported - CTML and CK (CHEMKIN-compatible). Examples:

g1a = IdealGasMix('mech.xml')
g1b = IdealGasMix('mech.xml', 'Multi')
g2 = IdealGasMix('mech2.inp')
g3 = IdealGasMix('mech3.inp', 'therm.dat')
g4 = IdealGasMix('mech4.inp', 'therm.dat', 'tran.dat')


Objects g1a and g1b are created from a CTML file. CTML files contain all data required to build the object, and do not require any additional database files. Objects g2 - g4 are created from CK-format input files. For g2, ‘mech2.inp’ contains all required species thermo data. File ‘mech3.inp’ is missing some or all species thermo data, and requires database file ‘therm.dat.’ Object g4 is created including transport data.

Note that calling IdealGasMix() with a CK-format input file also creates an equivalent CTML file that may be used in future calls. If the initial call includes a transport database, then the CTML file will contain transport data.

Parameters: infile – Input file, either CTI, CTML, or CHEMKIN format b – If a CTI or CTML file is specified with infile, this can be the transport modeling to be used. If a CHEMKIN format file is specified with infile, this is the filename of the thermodynamic database, if required. c – If a CHEMKIN format file is specified with infile, this is the filename of the transport database, if required. Instance of class Solution()
importPhase(file, name)

Import a phase from a CTI file

Parameters: file – CTI file containing phase definition name – Name of the phase Instance of class Solution()

## Mixture¶

class Mixture(phases)

Multiphase mixture class constructor.

Class Mixture() represents mixtures of one or more phases of matter. To construct a mixture, supply a cell array of phases and mole numbers:

>> gas = importPhase('gas.cti');
>> graphite = importPhase('graphite.cti');
>> mix = Mixture({gas, 1.0; graphite, 0.1});


>> water = importPhase('water.cti');


Note that the objects representing each phase compute only the intensive state of the phase - they do not store any information on the amount of this phase. Mixture objects, on the other hand, represent the full extensive state.

Mixture objects are ‘lightweight’ in the sense that they do not store parameters needed to compute thermodynamic or kinetic properties of the phases. These are contained in the (‘heavyweight’) phase objects. Multiple mixture objects may be constructed using the same set of phase objects. Each one stores its own state information locally, and synchronizes the phase objects whenever it requires phase properties.

Parameters: phases – Cell array of phases and mole numbers Instance of class Mixture()

Add a phase to a mixture.

Parameters: self – Instance of class Mixture() to which phases should be added phase – Instance of class ThermoPhase() which should be added moles – Number of moles of the phase to be added to this mixture. Units: kmol
chemPotentials(self)

Get the chemical potentials of species in a mixture.

Parameters: self – Instance of class Mixture() Vector of chemical potentials. Units: J/kmol
elementIndex(self, name)

Get the index of an element.

Parameters: self – Instance of class Mixture() name – Name of the element whose index is desired Index of element with name name
equilibrate(self, XY, err, maxsteps, maxiter, loglevel)

Set the mixture to a state of chemical equilibrium.

This method uses a version of the VCS algorithm to find the composition that minimizes the total Gibbs free energy of the mixture, subject to element conservation constraints. For a description of the theory, see Smith and Missen, “Chemical Reaction Equilibrium.” The VCS algorithm is implemented in Cantera kernel class MultiPhaseEquil.

The VCS algorithm solves for the equilibrium composition for specified temperature and pressure. If any other property pair other than “TP” is specified, then an outer iteration loop is used to adjust T and/or P so that the specified property values are obtained.

>> equilibrate(mix, 'TP')
>> equilibrate('TP', 1.0e-6, 500)

Parameters: self – Instance of class Mixture() XY – Two-letter string specifying the two properties to hold fixed. Currently, 'TP', 'HP', 'TV', and 'SP' are implemented. Default: 'TP'. err – Error tolerance. Iteration will continue until $$\Delta\mu)/RT$$ is less than this value for each reaction. Default: 1.0e-9. Note that this default is very conservative, and good equilibrium solutions may be obtained with larger error tolerances. maxsteps – Maximum number of steps to take while solving the equilibrium problem for specified T and P. Default: 1000. maxiter – Maximum number of temperature and/or pressure iterations. This is only relevant if a property pair other than (T,P) is specified. Default: 200. loglevel – Set to a value > 0 to write diagnostic output. Larger values generate more detailed information. The error in the solution
nElements(self)

Get the number of elements in a mixture.

Parameters: self – Instance of class Mixture() Number of elements in the input
nPhases(self)

Get the number of phases in a mixture.

Parameters: self – Instance of class Mixture() Number of phases in the input
nSpecies(self)

Get the number of species in a mixture.

Parameters: self – Instance of class Mixture() Number of species in the input
phaseMoles(self, n)

Get the number of moles of a phase in a mixture.

Parameters: self – Instance of class Mixture() n – Integer phase number in the input Moles of phase number n. Units: kmol
pressure(self)

Get the pressure of the mixture.

Parameters: self – Instance of class Mixture() Pressure. Units: Pa
setPhaseMoles(self, n, moles)

Set the number of moles of a phase in a mixture.

Parameters: self – Instance of class Mixture() n – Phase number in the input moles – Number of moles to add. Units: kmol
setPressure(self, P)

Set the pressure of the mixture.

Parameters: self – Instance of class Mixture() P – Pressure. Units: Pa
setSpeciesMoles(self, moles)

Set the moles of the species.

Set the moles of the species in kmol. The moles may be specified either as a string, or as an vector. If a vector is used, it must be dimensioned at least as large as the total number of species in the mixture. Note that the species may belong to any phase, and unspecified species are set to zero.

>> setSpeciesMoles(mix, 'C(s):1.0, CH4:2.0, O2:0.2');

Parameters: self – Instance of class Mixture() moles – Vector or string specifying the moles of species
setTemperature(self, T)

Set the mixture temperature.

Parameters: self – Instance of class Mixture() T – Temperature. Units: K
speciesIndex(self, k, p)

Get the index of a species in a mixture.

Parameters: self – Instance of class Mixture() name – Name of the speces whose index is desired Index of species with name name
temperature(self)

Get the temperature of a mixture.

Parameters: self – Instance of class Mixture() Temperature (K)