*** empty log message ***
This commit is contained in:
parent
2745d841dc
commit
275075c895
4 changed files with 99 additions and 25 deletions
|
|
@ -1,12 +1,12 @@
|
|||
"""
|
||||
Zero-dimensional reactors. More text.
|
||||
|
||||
Zero-dimensional reactors.
|
||||
"""
|
||||
|
||||
import _cantera
|
||||
from Numeric import array, zeros
|
||||
import types
|
||||
|
||||
|
||||
class ReactorBase:
|
||||
"""Base class for reactors."""
|
||||
|
||||
|
|
@ -25,11 +25,11 @@ class ReactorBase:
|
|||
self._walls = []
|
||||
self._name = name
|
||||
self._verbose = verbose
|
||||
if contents:
|
||||
self.insert(contents)
|
||||
self.insert(contents)
|
||||
self.setInitialVolume(volume)
|
||||
self.setEnergy(energy)
|
||||
|
||||
|
||||
def __del__(self):
|
||||
"""Delete the reactor instance."""
|
||||
if self._verbose:
|
||||
|
|
@ -37,9 +37,19 @@ class ReactorBase:
|
|||
_cantera.reactor_del(self.__reactor_id)
|
||||
|
||||
def __str__(self):
|
||||
return self._name
|
||||
|
||||
s = self._name
|
||||
if self._contents:
|
||||
s += ": \n"+`self._contents`
|
||||
return s
|
||||
|
||||
def __repr__(self):
|
||||
s = self._name
|
||||
if self._contents:
|
||||
s += ": \n"+`self._contents`
|
||||
return s
|
||||
|
||||
def name(self):
|
||||
"""Reactor name."""
|
||||
return self._name
|
||||
|
||||
def reactor_id(self):
|
||||
|
|
@ -52,14 +62,15 @@ class ReactorBase:
|
|||
Insert 'contents' into the reactor. Sets the objects used to compute
|
||||
thermodynamic properties and kinetic rates.
|
||||
"""
|
||||
self.contents = contents
|
||||
_cantera.reactor_setThermoMgr(self.__reactor_id, contents._phase_id)
|
||||
_cantera.reactor_setKineticsMgr(self.__reactor_id, contents.ckin)
|
||||
self._contents = contents
|
||||
if contents:
|
||||
_cantera.reactor_setThermoMgr(self.__reactor_id, contents._phase_id)
|
||||
_cantera.reactor_setKineticsMgr(self.__reactor_id, contents.ckin)
|
||||
|
||||
|
||||
def setInitialTime(self, t0):
|
||||
"""Set the initial time. Restarts integration from this time
|
||||
using the current state as the initial condition. weDefault: 0.0 s"""
|
||||
using the current state as the initial condition. Default: 0.0 s"""
|
||||
_cantera.reactor_setInitialTime(self.__reactor_id, t0)
|
||||
|
||||
def setInitialVolume(self, t0):
|
||||
|
|
@ -67,8 +78,10 @@ class ReactorBase:
|
|||
_cantera.reactor_setInitialVolume(self.__reactor_id, t0)
|
||||
|
||||
def setEnergy(self, e):
|
||||
"""Turn the energy equation on or off. If off, the reactor
|
||||
temperature is held constant."""
|
||||
"""Turn the energy equation on or off. If the argument is the
|
||||
string 'off' or the number 0, the energy equation is disabled,
|
||||
and the reactor temperature is held constant at its initial
|
||||
value."""
|
||||
ie = 1
|
||||
if e == 'off' or e == 0:
|
||||
ie = 0
|
||||
|
|
@ -113,24 +126,26 @@ class ReactorBase:
|
|||
|
||||
def advance(self, time):
|
||||
"""Advance the state of the reactor in time from the current
|
||||
time to time 'time'. Note: this method is deprecated. See class ReactorNet."""
|
||||
time to time 'time'. Note: this method is deprecated. See
|
||||
class ReactorNet."""
|
||||
return _cantera.reactor_advance(self.__reactor_id, time)
|
||||
|
||||
def step(self, time):
|
||||
"""Advance the state of the reactor in time from the current
|
||||
time to time 'time'. Note: this method is deprecated. See class ReactorNet."""
|
||||
"""Take one internal time step from the current time toward
|
||||
time 'time'. Note: this method is deprecated. See class
|
||||
ReactorNet."""
|
||||
return _cantera.reactor_step(self.__reactor_id, time)
|
||||
|
||||
def massFraction(self, k):
|
||||
"""Mass fraction of species k."""
|
||||
if type(k) == types.StringType:
|
||||
kk = self.contents.speciesIndex(k)
|
||||
kk = self._contents.speciesIndex(k)
|
||||
else:
|
||||
kk = k
|
||||
return _cantera.reactor_massFraction(self.__reactor_id, kk)
|
||||
|
||||
def massFractions(self):
|
||||
nsp = self.contents.nSpecies()
|
||||
nsp = self._contents.nSpecies()
|
||||
y = zeros(nsp,'d')
|
||||
for k in range(nsp):
|
||||
y[k] = self.massFraction(k)
|
||||
|
|
@ -138,40 +153,67 @@ class ReactorBase:
|
|||
|
||||
def moleFractions(self):
|
||||
y = self.massFractions()
|
||||
self.contents.setMassFractions(y)
|
||||
return self.contents.moleFractions()
|
||||
self._contents.setMassFractions(y)
|
||||
return self._contents.moleFractions()
|
||||
|
||||
def inlets(self):
|
||||
"""Return the list of flow devices installed on inlets to this reactor."""
|
||||
return self._inlets
|
||||
|
||||
def outlets(self):
|
||||
"""Return the list of flow devices installed on outlets
|
||||
on this reactor."""
|
||||
return self._outlets
|
||||
|
||||
def walls(self):
|
||||
"""Return the list of walls installed on this reactor."""
|
||||
return self._walls
|
||||
|
||||
def _addInlet(self, inlet):
|
||||
"""For internal use"""
|
||||
"""For internal use. Store a reference to 'inlet'
|
||||
so that it will not be deleted before this object."""
|
||||
self._inlets.append(inlet)
|
||||
|
||||
def _addOutlet(self, outlet):
|
||||
"""For internal use. Store a reference to 'outlet'
|
||||
so that it will not be deleted before this object."""
|
||||
self._outlets.append(outlet)
|
||||
|
||||
def _addWall(self, wall):
|
||||
"""For internal use. Store a reference to 'wall'
|
||||
so that it will not be deleted before this object."""
|
||||
self._walls.append(wall)
|
||||
|
||||
def updateContents(self):
|
||||
"""Set the state of the object representing the reactor contents
|
||||
to the current reactor state."""
|
||||
self._contents.setState_TRY(self.temperature(),
|
||||
self.density(),
|
||||
self.massFractions())
|
||||
|
||||
def contents(self):
|
||||
updateContents()
|
||||
return self._contents
|
||||
|
||||
|
||||
_reactorcount = 0
|
||||
_reserviorcount = 0
|
||||
|
||||
class Reactor(ReactorBase):
|
||||
"""
|
||||
A reactor.
|
||||
"""
|
||||
def __init__(self, contents = None, name = '<reactor>',
|
||||
def __init__(self, contents = None, name = '',
|
||||
volume = 1.0, energy = 'on',
|
||||
verbose = 0):
|
||||
"""
|
||||
Create a Reactor instance, and if 'contents' is specified,
|
||||
insert it.
|
||||
"""
|
||||
global _reactorcount
|
||||
if name == '':
|
||||
name = 'Reactor_'+`_reactorcount`
|
||||
_reactorcount += 1
|
||||
ReactorBase.__init__(self, contents = contents, name = name,
|
||||
volume = volume, energy = energy,
|
||||
verbose = verbose, type = 1)
|
||||
|
|
@ -184,6 +226,10 @@ class Reservoir(ReactorBase):
|
|||
nothing.
|
||||
"""
|
||||
def __init__(self, contents = None, name = '<reservoir>', verbose = 0):
|
||||
global _reservoircount
|
||||
if name == '':
|
||||
name = 'Reservoir_'+`_reservoircount`
|
||||
_reservoircount += 1
|
||||
ReactorBase.__init__(self, contents = contents,
|
||||
name = name, verbose = verbose, type = 2)
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ def thermoIndex(id):
|
|||
return _cantera.thermo_thermoIndex(id)
|
||||
|
||||
class ThermoPhase(Phase):
|
||||
|
||||
""" Class ThermoPhase may be used to represent the intensive state
|
||||
of a homogeneous phase of matter, which might be a gas, liquid, or solid.
|
||||
"""
|
||||
|
|
@ -229,6 +228,7 @@ class ThermoPhase(Phase):
|
|||
_cantera.thermo_setfp(self._phase_id, 5, s, p)
|
||||
|
||||
def setElectricPotential(self, v):
|
||||
"""Set the electric potential."""
|
||||
_cantera.thermo_setfp(self._phase_id, 6, v, 0);
|
||||
|
||||
def equilibrate(self, XY):
|
||||
|
|
@ -263,12 +263,29 @@ class ThermoPhase(Phase):
|
|||
return _cantera.thermo_getfp(self._phase_id,53)
|
||||
|
||||
def setState_Psat(self, p, vaporFraction):
|
||||
"""Set the state of a saturated liquid/vapor mixture by
|
||||
specifying the pressure and vapor fraction."""
|
||||
_cantera.thermo_setfp(self._phase_id,8, p, vaporFraction)
|
||||
|
||||
def setState_Tsat(self, t, vaporFraction):
|
||||
"""Set the state of a saturated liquid/vapor mixture by
|
||||
specifying the temperature and vapor fraction."""
|
||||
_cantera.thermo_setfp(self._phase_id,7, t, vaporFraction)
|
||||
|
||||
|
||||
def saveState(self):
|
||||
"""Return an array with state information that can later be
|
||||
used to restore the state."""
|
||||
state = zeros(self.nSpecies()+2,'d')
|
||||
state[0] = self.temperature()
|
||||
state[1] = self.density()
|
||||
state[2:] = self.massFractions()
|
||||
return state
|
||||
|
||||
def restoreState(self, s):
|
||||
"""Restore the state to that stored in array s."""
|
||||
self.setState_TRY(state[0], state[1], state[2:])
|
||||
|
||||
def thermophase(self):
|
||||
"""Return the integer index that is used to
|
||||
reference the kernel object. For internal use."""
|
||||
|
|
|
|||
|
|
@ -1,7 +1,4 @@
|
|||
"""
|
||||
"""
|
||||
|
||||
#import string
|
||||
import os
|
||||
|
||||
from constants import *
|
||||
|
|
@ -66,5 +63,18 @@ class Solution(ThermoPhase, Kinetics, Transport):
|
|||
return _cantera.phase_report(self._phase_id, self.verbose)
|
||||
|
||||
def set(self, **options):
|
||||
"""Set various properties.
|
||||
T --- temperature [K]
|
||||
P --- pressure [Pa]
|
||||
Rho --- density [kg/m3]
|
||||
V --- specific volume [m3/kg]
|
||||
H --- specific enthalpy [J/kg]
|
||||
U --- specific internal energy [J/kg]
|
||||
S --- specific entropy [J/kg/K]
|
||||
X --- mole fractions (string or array)
|
||||
Y --- mass fractions (string or array)
|
||||
Vapor --- saturated vapor fraction
|
||||
Liquid --- saturated liquid fraction
|
||||
"""
|
||||
setByName(self, options)
|
||||
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ namespace Cantera {
|
|||
return;
|
||||
}
|
||||
m_time = t0;
|
||||
m_mix->restoreState(m_state);
|
||||
|
||||
// total mass
|
||||
doublereal mass = m_mix->density() * m_vol;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue