*** empty log message ***

This commit is contained in:
Dave Goodwin 2003-04-25 11:57:40 +00:00
parent 58bd132445
commit cc5e3c0495
4 changed files with 123 additions and 12 deletions

View file

@ -3,7 +3,7 @@
The classes in this module are designed to allow constructing
user-defined functions of one variable in Python that can be used with the
Cantera C++ kernel. These classes are mostly shadow classes for
corresponding classes in the C++ kernel.
corresponding classes in the C++ kernel.
"""
@ -14,37 +14,58 @@ import types
class Func1:
"""Base class for functions of one variable."""
def __init__(self, typ, n, coeffs=[]):
self.n = n
self.coeffs = asarray(coeffs,'d')
self._func_id = ctfunc.func_new(typ, n, self.coeffs)
self._func_id = _cantera.func_new(typ, n, self.coeffs)
def __del__(self):
ctfunc.func_del(self._func_id)
_cantera.func_del(self._func_id)
def __call__(self, t):
return ctfunc.func_value(self._func_id, t)
"""Implements function syntax, so that F(t) is equivalent to
F.value(t)."""
return _cantera.func_value(self._func_id, t)
def __add__(self, other):
"""Overloads operator '+'
Returns a new function self(t) + other(t)"""
if type(other) == types.FloatType:
return SumFunction(self, Const(other))
return SumFunction(self, other)
def __radd__(self, other):
"""Overloads operator '+'
Returns a new function other(t) + self(t)"""
if type(other) == types.FloatType:
return SumFunction(Const(other),self)
return SumFunction(other, self)
def __mul__(self, other):
"""Overloads operator '*'
Return a new function self(t)*other(t)"""
return ProdFunction(self, other)
def __rmul__(self, other):
"""Overloads operator '*'
Returns a new function other(t)*self(t)"""
return ProdFunction(other, self)
def __div__(self, other):
"""Overloads operator '/'
Returns a new function self(t)/other(t)"""
return RatioFunction(self, other)
def __rdiv__(self, other):
"""Overloads operator '/'
Returns a new function other(t)/self(t)"""
return RatioFunction(other, self)
def func_id(self):
@ -53,9 +74,10 @@ class Func1:
class Polynomial(Func1):
"""A polynomial. The degree is determined by the number of coefficients
supplied. Example:
supplied. Examples:
p = Polynomial([1.0, -2.0, 3.0]) # 3t^2 - 2t + 1
p1 = Polynomial([1.0, -2.0, 3.0]) # 3t^2 - 2t + 1
p2 = Polynomial([6.0, 8.0]) # 8t + 6
"""
def __init__(self, coeffs=[]):
Func1.__init__(self, 2, len(coeffs)-1, coeffs)
@ -70,6 +92,11 @@ class Fourier(Func1):
Note that b[0] must be specified for symmetry with 'a', but is not
used.
Example:
coeffs = [(a0, b0), (a1, b1), (a2, b2)]
f = Fourier(omega, coeffs)
"""
def __init__(self, omega, c):
@ -82,6 +109,15 @@ class Fourier(Func1):
class Arrhenius(Func1):
"""Sum of modified Arrhenius terms.
f(T) = \sum_{i=1}^n A_n T^{b_n}\exp(-E_n/T)
Example:
f = Arrhenius([(a0, b0, e0), (a1, b1, e1)])
"""
def __init__(self, c):
cc = asarray(c,'d')
n, m = cc.shape
@ -92,6 +128,7 @@ class Arrhenius(Func1):
def Const(value):
"""Constant function."""
return Polynomial([value])
@ -99,24 +136,27 @@ def Const(value):
# functions that combine two functions
class SumFunction(Func1):
"""f = f1 + f2"""
def __init__(self, f1, f2):
self.f1 = f1
self.f2 = f2
self.n = -1
self._func_id = ctfunc.func_newcombo(20, f1.func_id(), f2.func_id())
self._func_id = _cantera.func_newcombo(20, f1.func_id(), f2.func_id())
class ProdFunction(Func1):
"""f = f1 * f2"""
def __init__(self, f1, f2):
self.f1 = f1
self.f2 = f2
self.n = -1
self._func_id = ctfunc.func_newcombo(30, f1.func_id(), f2.func_id())
self._func_id = _cantera.func_newcombo(30, f1.func_id(), f2.func_id())
class RatioFunction(Func1):
"""f = f1 / f2"""
def __init__(self, f1, f2):
self.f1 = f1
self.f2 = f2
self.n = -1
self._func_id = ctfunc.func_newcombo(40, f1.func_id(), f2.func_id())
self._func_id = _cantera.func_newcombo(40, f1.func_id(), f2.func_id())

View file

@ -1,13 +1,25 @@
import _cantera
class Transport:
"""Transport property manager.
"""Transport property manager. In most cases, this class is used
as a base class to provide transport properties, and is not
instantiated directly.
A transport property manager is responsible for computing transport
properties.
"""
def __init__(self, xml_phase=None,
phase=None, model = "", loglevel=0):
"""Create a transport property manager.
xml_phase --- XML phase element
phase --- ThermoPhase instance representing phase transport
properties are for
model --- transport model
loglevel --- controls amount of diagnostic output
"""
self._phase = phase
if model == "" or model == "Default":
try:

View file

@ -1,13 +1,29 @@
"""This module defines classes and functions used to model gas mixtures."""
"""Gas mixtures.
These functions all return instances of class Solution that represent
gas mixtures.
"""
# for pydoc
import solution, constants, ck2ctml
from constants import *
from solution import Solution
from Cantera.solution import Solution
from ck2ctml import ck2ctml
#import _cantera
import os
def IdealGasMix(src="", root=None, transport='None',
thermo = "", trandb = ""):
"""Return a Solution object representing an ideal gas mixture.
src --- input file
root --- root of an XML tree containing the phase specification.
Specify src or root but not both.
thermo --- auxiliary thermo database
transport --- transport model
trandb --- transport database
"""
p = os.path.normpath(os.path.dirname(src))
fname = os.path.basename(src)
ff = os.path.splitext(fname)
@ -27,12 +43,18 @@ def IdealGasMix(src="", root=None, transport='None',
return Solution(src=src, root=root, transport=transport)
def GRI30(transport='None'):
"""Return a Solution instance implementing reaction mechanism
GRI-Mech 3.0."""
return Solution(src="gri30.xml#gri30_hw", transport=transport)
def Air():
"""Return a Solution instance implementing the O/N/Ar portion of
reaction mechanism GRI-Mech 3.0. The initial composition is set to
that of air"""
return Solution(src="air.xml#air")
def Argon():
"""Return a Solution instance representing pure argon."""
return Solution(src="argon.xml#argon")
## def H_O_AR(transport=None, chem = 1):

37
tools/doc/python/makedoc Executable file
View file

@ -0,0 +1,37 @@
pydoc -w Cantera
pydoc -w Cantera.Flow
pydoc -w Cantera.FlowBoundary
pydoc -w Cantera.FlowPlotter
pydoc -w Cantera.Func
pydoc -w Cantera.Interface
pydoc -w Cantera.Kinetics
pydoc -w Cantera.OneDim
pydoc -w Cantera.Phase
pydoc -w Cantera.Reactor
pydoc -w Cantera.SurfWriter
pydoc -w Cantera.SurfacePhase
pydoc -w Cantera.Thermo
pydoc -w Cantera.ThermoPhase
pydoc -w Cantera.Transport
pydoc -w Cantera.XML
pydoc -w Cantera.__init__
pydoc -w Cantera.boundaries1D
pydoc -w Cantera.ck2ctml
pydoc -w Cantera.constants
pydoc -w Cantera.elements
pydoc -w Cantera.excel
pydoc -w Cantera.exceptions
pydoc -w Cantera.flame
pydoc -w Cantera.gases
pydoc -w Cantera.importFromFile
pydoc -w Cantera.interp
pydoc -w Cantera.refine
pydoc -w Cantera.rxnpath
pydoc -w Cantera.schem
pydoc -w Cantera.set
pydoc -w Cantera.solids
pydoc -w Cantera.solution
pydoc -w Cantera.solve
pydoc -w Cantera.stoich
pydoc -w Cantera.tecplot
pydoc -w Cantera.units