Cantera

Table Of Contents

Previous topic

Composite Classes

Next topic

One-Dimensional Reacting Flows

This Page

Warning

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

Zero-Dimensional Reactors

Zero-dimensional reactors.

Base Classes

class Cantera.Reactor.ReactorBase(name='', contents=None, volume=1.0, energy='on', type=-1, verbose=0)

Base class for reactors and reservoirs.

Classes Reactor and Reservoir derive from a common base class ReactorBase. They have the same set of methods, which are all inherited from ReactorBase.

(This is not quite true in the corresponding classes in the Cantera C++ kernel. There class Reactor defines some methods that class Reservoir doesn’t. These are used internally by the ReactorNet instance that integrates the system of ODEs describing the network to evaluate the portion of the ODE system associated with that reactor.)

See Reactor for a description of the constructor parameters. The type parameter specifies whether a Reactor (type = 2) or Reservoir (type = 1) will be created.

addSensitivityReaction(reactions=[])
advance(time)

Deprecated. Advance the state of the reactor in time from the current time to time time. Note: this method is deprecated. See ReactorNet.

contents()

Return an object representing the reactor contents, after first synchronizing its state with the current reactor state. This method is useful when some property of the fluid in the reactor is needed that is not provided by a method of Reactor.

>>> r = Reactor(gas)
>>> (statements that change the state of object 'gas')
>>> c = r.contents()
>>> print c.gibbs_mole(), c.chemPotentials()

Note that after calling contents(), object c references the same underlying kernel object as object gas does. Therefore, all properties of c and gas are identical. (Remember that Python objects are really C pointers; at the C level, both point to the same data structure.) It is also allowed to write

>>> gas = r.contents()
density()

The density of the fluid in the reactor [kg/m^3].

enthalpy_mass()

The specific enthalpy of the fluid in the reactor [J/kg].

inlets()

Return the list of flow devices installed on inlets to this reactor. This method can be used to access information about the flows entering the reactor:

>>> for n in r.inlets():
...    print n.name(), n.massFlowRate()

See: MassFlowController, Valve, PressureController.

insert(contents)

Insert contents into the reactor. Sets the objects used to compute thermodynamic properties and kinetic rates.

intEnergy_mass()

The specific internal energy of the fluid in the reactor [J/kg].

mass()

The total mass of fluid in the reactor [kg].

massFraction(s)

The mass fraction of species s, specified either by name or index number.

>>> y1 = r.massFraction(7)
0.02
>>> y2 = r.massFraction('CH3O')
0.02
massFractions()

Return an array of the species mass fractions.

moleFraction(s)

The mole fraction of species s, specified either by name or index number.

>>> x1 = r.moleFraction(9)
0.00012
>>> x2 = r.moleFraction('CH3')
0.00012
moleFractions()

Return an array of the species mole fractions.

nSensParams()

Number of sensitivity parameters for this reactor.

name()

The name of the reactor.

outlets()

Return the list of flow devices installed on outlets on this reactor.

>>> for o in r.outlets():
...    print o.name(), o.massFlowRate()

See: MassFlowController, Valve, PressureController.

pressure()

The pressure in the reactor [Pa].

reactor_id()

The integer index used to access the kernel reactor object. For internal use.

sensParamName(n=-1)
setInitialTime(T0)

Deprecated. Set the initial time. Restarts integration from this time using the current state as the initial condition. Default: 0.0 s

step(time)

Deprecated. Take one internal time step from the current time toward time time. Note: this method is deprecated. See class ReactorNet.

syncContents()

Set the state of the object representing the reactor contents to the current reactor state.

>>> r = Reactor(gas)
>>> (statements that change the state of object 'gas')
>>> r.syncContents()

After this statement, the state of object ‘gas’ is synchronized with the reactor state. See contents().

temperature()

The temperature in the reactor [K].

time()

Deprecated. The current time [s].

volume()

The total reactor volume [m^3]. The volume may change with time if non-rigid walls are installed on the reactor.

walls()

Return the list of walls installed on this reactor.

>>> for w in r.walls():
...    print w.name()

See: Wall.

class Cantera.Reactor.Reactor(contents=None, name='', volume=1.0, energy='on', verbose=0)

Bases: Cantera.Reactor.ReactorBase

Zero-dimensional reactors. Instances of class Reactor represent zero-dimensional reactors. By default, they are closed (no inlets or outlets), have fixed volume, and have adiabatic, chemically-inert walls. These properties may all be changed by adding appropriate components. See Wall, MassFlowController, and Valve.

Parameters:
  • contents – Reactor contents. If not specified, the reactor is initially empty. In this case, call insert() to specify the contents.
  • name – Used only to identify this reactor in output. If not specified, defaults to 'Reactor_n', where n is an integer assigned in the order Reactor objects are created.
  • volume – Initial reactor volume. Defaults to 1 m^3.
  • energy – Set to 'on' or 'off'. If set to 'off', the energy equation is not solved, and the temperature is held at its initial value. The default in 'on'.
  • verbose – If set to a non-zero value, additional diagnostic information will be printed.

Some examples showing how to create Reactor objects are shown below.

>>> gas = GRI30()
>>> r1 = Reactor(gas)

This is equivalent to:

>>> r1 = Reactor()
>>> r1.insert(gas)

Arguments may be specified using keywords in any order:

>>> r2 = Reactor(contents = gas, energy = 'off',
...              name = 'isothermal_reactor')
>>> r3 = Reactor(contents = gas, name = 'adiabatic_reactor')

Here’s an array of reactors:

>>> reactor_array = [Reactor(), Reactor(gas), Reactor(Air())]
class Cantera.Reactor.FlowDevice(type, name, verbose)

Base class for devices that regulate the flow rate in a fluid line.

Create a new instance of type type

flowdev_id()
install(upstream, downstream)

Install the device between the upstream and downstream reactors or reservoirs.

>>> f.install(upstream=reactor1, downstream=reservoir2)
massFlowRate(time=-999.0)

Mass flow rate (kg/s).

name()

The name specified when initially constructed.

ready()

Deprecated. Returns true if the device is ready to use.

setFunction(f)

Reactor Networks

class Cantera.Reactor.ReactorNet(reactorlist=None)

Networks of reactors. ReactorNet objects are used to simultaneously advance the state of a set of coupled reactors.

Example:

>>> r1 = Reactor(gas1)
>>> r2 = Reactor(gas2)
>>> <... install walls, inlets, outlets, etc...>
>>> reactor_network = ReactorNet([r1, r2])
>>> reactor_network.advance(time)

Create a new ReactorNet instance. If a list of reactors is supplied, these will be added to the network.

add(reactor)

Add a reactor to the network.

advance(time)

Advance the state of the reactor network in time from the current time to time ‘time’.

nSensParams()

Number of sensitivity parameters.

reactornet_id()

The integer index used to access the kernel reactornet object. For internal use.

reactors()

Return the list of reactors in the network.

sensitivity(component='', parameter=-1, reactor='')

Sensitivity of solution component component with respect to one or more parameters.

Parameters:
  • component – name of the species or other variable for which sensitivity information is desired.
  • parameter – single integer or sequence of integers specifying the parameters. The parameters are numbered from zero, beginning with the parameters for the first reactor and continuing through those for the last reactor in the network. If omitted, the sensitivity with respect to all parameters will be returned.
  • reactor – reactor containing the desired component.
setInitialTime(t0)

Set the initial time. Restarts integration from this time using the current state as the initial condition. Default: 0.0 s

setTolerances(rtol=1e-09, atol=1e-20, rtolsens=-1.0, atolsens=-1.0)

Set the relative and absolute error tolerances used in integrating the reactor equations.

step(time)

Take a single internal time step toward time time. The time after taking the step is returned.

time()

The current time [s].

Flow Reactors

class Cantera.Reactor.FlowReactor(contents=None, name='', volume=1.0, energy='on', mdot=-1.0, verbose=0)

Bases: Cantera.Reactor.ReactorBase

Parameters:
  • contents – Reactor contents. If not specified, the reactor is initially empty. In this case, call insert() to specify the contents.
  • name – Used only to identify this reactor in output. If not specified, defaults to Reactor_n, where n is an integer assigned in the order Reactor objects are created.
  • volume – Initial reactor volume. Defaults to 1 m^3.
  • energy – Set to 'on' or 'off'. If set to 'off', the energy equation is not solved, and the temperature is held at its initial value. The default in 'on'.
  • verbose – if set to a non-zero value, additional diagnostic information will be printed.
setMassFlowRate(mdot)
class Cantera.Reactor.ConstPressureReactor(contents=None, name='', volume=1.0, energy='on', verbose=0)

Bases: Cantera.Reactor.ReactorBase

Parameters:
  • contents – Reactor contents. If not specified, the reactor is initially empty. In this case, call insert() to specify the contents.
  • name – Used only to identify this reactor in output. If not specified, defaults to 'Reactor_n', where n is an integer assigned in the order Reactor objects are created.
  • volume – Initial reactor volume. Defaults to 1 m^3.
  • energy – Set to 'on' or 'off'. If set to 'off', the energy equation is not solved, and the temperature is held at its initial value. The default in 'on'.
  • verbose – If set to a non-zero value, additional diagnostic information will be printed.
class Cantera.Reactor.Reservoir(contents=None, name='', verbose=0)

Bases: Cantera.Reactor.ReactorBase

A reservoir is a reactor with a constant state. The temperature, pressure, and chemical composition in a reservoir never change from their initial values.

Parameters:
  • contents – Reservoir contents. If not specified, the reservoir is initially empty. In this case, call insert() to specify the contents.
  • name – Used only to identify this reservoir in output. If not specified, defaults to 'Reservoir_n', where n is an integer assigned in the order Reservoir objects are created.
  • verbose – if set to a non-zero value, additional diagnostic information will be printed.

Some examples showing how to create Reservoir objects are shown below.

>>> gas = GRI30()
>>> res1 = Reservoir(gas)

This is equivalent to:

>>> res1 = Reactor()
>>> res1.insert(gas)

Arguments may be specified using keywords in any order:

>>> res2 = Reservoir(contents=Air(), name='environment')
>>> res3 = Reservoir(contents=gas, name='upstream_state')
advance(time)

Deprecated. Do nothing.

Flow Controllers

class Cantera.Reactor.MassFlowController(upstream=None, downstream=None, name='', verbose=0, mdot=0.0)

Bases: Cantera.Reactor.FlowDevice

Mass flow controllers. A mass flow controller maintains a specified mass flow rate independent of upstream and downstream conditions. The equation used to compute the mass flow rate is

\[\dot m = \max(\dot m_0, 0.0),\]

where \(\dot m_0\) is either a constant value or a function of time. Note that if \(\dot m_0 < 0\), the mass flow rate will be set to zero, since reversal of the flow direction is not allowed.

Unlike a real mass flow controller, a MassFlowController object will maintain the flow even if the downstream pressure is greater than the upstream pressure. This allows simple implementation of loops, in which exhaust gas from a reactor is fed back into it through an inlet. But note that this capability should be used with caution, since no account is taken of the work required to do this.

A mass flow controller is assumed to be adiabatic, non-reactive, and have negligible volume, so that it is internally always in steady-state even if the upstream and downstream reactors are not. The fluid enthalpy, chemical composition, and mass flow rate are constant across a mass flow controller, and the pressure difference equals the difference in pressure between the upstream and downstream reactors.

Examples:

>>> mfc1 = MassFlowController(upstream=res1, downstream=reactr,
...                           name='fuel_mfc', mdot = 0.1)
>>> air_mdot = Gaussian(A=0.1, t0=2.0, FWHM=0.1)
>>> mfc2 = MassFlowController(upstream=res2, downstream=reactr,
...                           name='air_mfc', mdot=air_mdot)
Parameters:
  • upstream – upstream reactor or reservoir.
  • downstream – downstream reactor or reservoir.
  • name – name used to identify the mass flow controller in output. If no name is specified, it defaults to MFC_n, where n is an integer assigned in the order the MassFlowController object was created.
  • mdot – Mass flow rate [kg/s]. This mass flow rate, which may be a constant or a function of time, will be maintained, independent of upstream and downstream conditions, unless reset by calling method set().
  • verbose – if set to a positive integer, additional diagnostic information will be printed.
set(mdot=0.0)

Set the mass flow rate [kg/s]. May be called at any time to change the mass flow rate to a new value, or to a new function of time.

>>> mfc.set(mdot = 0.2)
class Cantera.Reactor.Valve(upstream=None, downstream=None, name='', Kv=0.0, mdot0=0.0, verbose=0)

Bases: Cantera.Reactor.FlowDevice

Valves. In Cantera, a Valve object is a flow devices with mass flow rate that is a function of the pressure drop across it. The default behavior is linear:

\[\dot m = K_v (P_1 - P_2)\]

if \(P_1 > P_2.\) Otherwise, \(\dot m = 0\). However, an arbitrary function can also be specified, such that

\[\dot m = F(P_1 - P_2)\]

if \(P_1 > P_2\), or \(\dot m = 0\) otherwise. It is never possible for the flow to reverse and go from the downstream to the upstream reactor/reservoir through a line containing a Valve object.

Valve objects are often used between an upstream reactor and a downstream reactor or reservoir to maintain them both at nearly the same pressure. By setting the constant \(K_v\) to a sufficiently large value, very small pressure differences will result in flow between the reactors that counteracts the pressure difference.

A Valve is assumed to be adiabatic, non-reactive, and have negligible internal volume, so that it is internally always in steady-state even if the upstream and downstream reactors are not. The fluid enthalpy, chemical composition, and mass flow rate are constant across a Valve, and the pressure difference equals the difference in pressure between the upstream and downstream reactors.

Parameters:
  • upstream – upstream reactor or reservoir.
  • downstream – downstream reactor or reservoir.
  • name – name used to identify the valve in output. If no name is specified, it defaults to Valve_n, where n is an integer assigned in the order the Valve object was created.
  • Kv – the constant in the mass flow rate equation.
  • verbose – if set to a positive integer, additional diagnostic information will be printed.
set(Kv=-1.0, F=None)

Set or reset valve properties. All keywords are optional.

Parameters:
  • Kv – constant in linear mass flow rate equation.
  • F – function of \(\Delta P\).
setValveCoeff(Kv=-1.0)

Set or reset the valve coefficient \(K_v\).

class Cantera.Reactor.PressureController(upstream=None, downstream=None, name='', master=None, Kv=0.0, verbose=0)

Bases: Cantera.Reactor.FlowDevice

A PressureController is designed to be used in conjunction with another ‘master’ flow controller, typically a MassFlowController. The master flow controller is installed on the inlet of the reactor, and the corresponding PressureController is installed on on outlet of the reactor. The PressureController mass flow rate is equal to the master mass flow rate, plus a small correction dependent on the pressure difference:

\[\dot m = \dot m_{\rm master} + K_v(P_1 - P_2).\]
Parameters:
  • upstream – upstream reactor or reservoir.
  • downstream – downstream reactor or reservoir.
  • name – name used to identify the pressure controller in output. If no name is specified, it defaults to PressureController_n, where n is an integer assigned in the order the PressureController object was created.
  • Kv – the constant in the mass flow rate equation.
  • verbose – if set to a positive integer, additional diagnostic information will be printed.
set(Kv=-1.0, master=None)
setMaster(master)

Set the master flow controller.

setPressureCoeff(Kv)

Set or reset the pressure coefficient \(K_v\).

class Cantera.Reactor.Wall(left, right, name='', A=1.0, K=0.0, U=0.0, Q=None, velocity=None, kinetics=[None, None])

Reactor walls.

A Wall separates two reactors, or a reactor and a reservoir. A wall has a finite area, may conduct or radiate heat between the two reactors on either side, and may move like a piston.

Walls are stateless objects in Cantera, meaning that no differential equation is integrated to determine any wall property. Since it is the wall (piston) velocity that enters the energy equation, this means that it is the velocity, not the acceleration or displacement, that is specified. The wall velocity is computed from

\[v = K(P_{\rm left} - P_{\rm right}) + v_0(t),\]

where \(K\) is a non-negative constant, and \(v_0(t)\) is a specified function of time. The velocity is positive if the wall is moving to the right.

The heat flux through the wall is computed from

\[q = U(T_{\rm left} - T_{\rm right}) + \epsilon\sigma (T_{\rm left}^4 - T_{\rm right}^4) + q_0(t),\]

where \(U\) is the overall heat transfer coefficient for conduction/convection, and \(\epsilon\) is the emissivity. The function \(q_0(t)\) is a specified function of time. The heat flux is positive when heat flows from the reactor on the left to the reactor on the right.

A heterogeneous reaction mechanism may be specified for one or both of the wall surfaces. The mechanism object (typically an instance of class Interface) must be constructed so that it is properly linked to the object representing the fluid in the reactor the surface in question faces. The surface temperature on each side is taken to be equal to the temperature of the reactor it faces.

Parameters:
  • left – Reactor or reservoir on the left. Required.
  • right – Reactor or reservoir on the right. Required.
  • name – Name string. If omitted, the name is 'Wall_n', where 'n' is an integer assigned in the order walls are created.
  • A – Wall area [m^2]. Defaults to 1.0 m^2.
  • K – Wall expansion rate parameter [m/s/Pa]. Defaults to 0.0.
  • U – Overall heat transfer coefficient [W/m^2]. Defaults to 0.0 (adiabatic wall).
  • Q – Heat flux function \(q_0(t)\) [W/m^2]. Optional. Default: \(q_0(t) = 0.0\).
  • velocity – Wall velocity function \(v_0(t)\) [m/s]. Default: \(v_0(t) = 0.0\).
  • kinetics – Surface reaction mechanisms for the left-facing and right-facing surface, respectively. These must be instances of class Kinetics, or of a class derived from Kinetics, such as Interface. If chemistry occurs on only one side, enter None for the non-reactive side.
addSensitivityReaction(side='unknown', reactions=[])
area()

The wall area (m^2).

heatFlowRate()

Rate of heat flow through the wall. A positive value corresponds to heat flowing from the left-hand reactor to the right-hand one.

heatFlux()
install(left, right)
kinetics(side='left')
ready()

Return 1 if the wall instance is ready for use, 0 otherwise. Deprecated.

set(**p)

Set various wall parameters: A, U, K, Q, velocity. These have the same meanings as in the constructor.

setArea(a)

Set the area (m^2). The wall area may be changed manually at any time during a simulation.

setEmissivity(epsilon)

Set the emissivity.

setExpansionRateCoeff(k)

Set the coefficient K that determines the expansion rate resulting from a unit pressure drop.

setHeatFlux(qfunc)

Specify the time-dependent heat flux function [W/m2]. qfunc must be a functor (an instance of Func1).

setHeatTransferCoeff(u)

Set the overall heat transfer coefficient [W/m^2/K]

setKinetics(left, right)

Specify surface reaction mechanisms for the left and right sides of the wall.

setThermalResistance(rth)

Deprecated.

setVelocity(vfunc)

Specify the velocity function [m/s]. vfunc must be a functor (an instance of Func1)

vdot()

Rate of volume change [m^3]. A positive value corresponds to the left-hand reactor volume increasing, and the right-hand reactor volume decreasing.

velocity()