mirror of
https://github.com/Cantera/cantera.git
synced 2025-02-25 18:55:29 -06:00
cmake files
This commit is contained in:
1
Cantera/python/CMakeLists.txt
Normal file
1
Cantera/python/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
||||
add_subdirectory (src)
|
||||
@@ -19,7 +19,7 @@ class Func1:
|
||||
A Functor is an object that behaves like a function. Class 'Func1'
|
||||
is the base class from which several functor classes derive. These
|
||||
classes are designed to allow specifying functions of time from Python
|
||||
that can be used by the C++ kernel.
|
||||
that can be used by the C++ kernel.
|
||||
|
||||
Functors can be added, multiplied, and divided to yield new functors.
|
||||
>>> f1 = Polynomial([1.0, 0.0, 3.0]) # 3*t*t + 1
|
||||
@@ -147,7 +147,7 @@ class Func1:
|
||||
|
||||
def write(self, arg = 'x', length = 1000):
|
||||
return _cantera.func_write(self._func_id, length, arg)
|
||||
|
||||
|
||||
|
||||
class Sin(Func1):
|
||||
def __init__(self,omega=1.0):
|
||||
@@ -249,6 +249,15 @@ class Fourier(Func1):
|
||||
Func1.__init__(self, 1, n-1, ravel(transpose(cc)))
|
||||
|
||||
|
||||
##Sum of modified Arrhenius terms. Instances of class 'Arrhenius' evaluate
|
||||
# \f[
|
||||
# f(T) = \sum_{n=1}^N A_n T^{b_n}\exp(-E_n/T)
|
||||
# \f]
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# >>> f = Arrhenius([(a0, b0, e0), (a1, b1, e1)])
|
||||
#
|
||||
class Arrhenius(Func1):
|
||||
"""Sum of modified Arrhenius terms. Instances of class 'Arrhenius' evaluate
|
||||
\f[
|
||||
@@ -306,6 +315,11 @@ class PeriodicFunction(Func1):
|
||||
# functions that combine two functions
|
||||
|
||||
class ComboFunc1(Func1):
|
||||
"""
|
||||
Combines two functions.
|
||||
This class is the base class for functors that combine two
|
||||
other functors in a binary operation.
|
||||
"""
|
||||
|
||||
def __init__(self, typ, f1, f2):
|
||||
self._own = 1
|
||||
@@ -407,19 +421,21 @@ class RatioFunction(ComboFunc1):
|
||||
"""
|
||||
ComboFunc1.__init__(self, 40, f1, f2)
|
||||
|
||||
## Function of a function.
|
||||
# Instances of class CompositeFunction evaluate f(g(t)) for two supplied
|
||||
# functors f and g. It is not necessary to explicitly create an instance
|
||||
# of 'CompositeFunction', since the () operator of the base class is
|
||||
# overloaded to return a CompositeFunction when called with a functor
|
||||
# argument.
|
||||
# @example
|
||||
# >>> f1 = Polynomial([2.0, 1.0])
|
||||
# >>> f2 = Polynomial([3.0, -5.0])
|
||||
# >>> f3 = f1(f2) # functor to evaluate 2(3t - 5) + 1
|
||||
# In this example, object 'f3' is a functor of class'CompositeFunction'
|
||||
# that calls f1 and f2 and returns f1(f2(t)).
|
||||
|
||||
class CompositeFunction(ComboFunc1):
|
||||
"""Function of a function.
|
||||
Instances of class CompositeFunction evaluate f(g(t)) for two supplied
|
||||
functors f and g. It is not necessary to explicitly create an instance
|
||||
of 'CompositeFunction', since the () operator of the base class is
|
||||
overloaded to return a CompositeFunction when called with a functor
|
||||
argument.
|
||||
>>> f1 = Polynomial([2.0, 1.0])
|
||||
>>> f2 = Polynomial([3.0, -5.0])
|
||||
>>> f3 = f1(f2) # functor to evaluate 2(3t - 5) + 1
|
||||
In this example, object 'f3' is a functor of class'CompositeFunction'
|
||||
that calls f1 and f2 and returns f1(f2(t)).
|
||||
"""
|
||||
|
||||
def __init__(self, f1, f2):
|
||||
"""
|
||||
f1 - first functor.
|
||||
@@ -427,6 +443,7 @@ class CompositeFunction(ComboFunc1):
|
||||
f2 - second functor.
|
||||
"""
|
||||
ComboFunc1.__init__(self, 60, f1, f2)
|
||||
|
||||
|
||||
class DerivativeFunction(Func1):
|
||||
def __init__(self, f):
|
||||
@@ -435,9 +452,11 @@ class DerivativeFunction(Func1):
|
||||
self._own = 1
|
||||
self._func_id = _cantera.func_derivative(f.func_id())
|
||||
|
||||
##
|
||||
# The derivative of f
|
||||
#
|
||||
def derivative(f):
|
||||
return DerivativeFunction(f)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -28,13 +28,11 @@ class Kinetics:
|
||||
the specification of the parameters.
|
||||
"""
|
||||
np = len(phases)
|
||||
#self._np = np
|
||||
self._sp = []
|
||||
self._phnum = {}
|
||||
|
||||
# p0 through p4 are the integer indices of the phase objects
|
||||
# corresponding to the input sequence of phases
|
||||
|
||||
self._end = [0]
|
||||
p0 = phases[0].thermophase()
|
||||
p1 = -1
|
||||
|
||||
@@ -1,180 +0,0 @@
|
||||
"""
|
||||
Write C functions implementing a surface reaction mechanism.
|
||||
NOT CURRENTLY FUNCTIONAL
|
||||
"""
|
||||
|
||||
from Cantera import CanteraError
|
||||
from Cantera import units
|
||||
from Numeric import array
|
||||
from Cantera import constants
|
||||
import math
|
||||
import types
|
||||
|
||||
hdr = """
|
||||
/*
|
||||
|
||||
The identity of the species in each phase is as listed below.
|
||||
"""
|
||||
|
||||
ropheader = """
|
||||
|
||||
/*
|
||||
Get the reaction rates of progress given the concentrations.
|
||||
|
||||
conc --- concentrations in kmol/m^3 or kmol/m^2. Array c
|
||||
must be dimensioned at least KB1 + KB2 + KS. The first
|
||||
KB1 entries are the concentrations of species in bulk phase 1,
|
||||
the next KB2 entries are the concentrations of species in bulk
|
||||
phase 2, and the final KS entries are the concentrations of the
|
||||
surface species.
|
||||
|
||||
ropf --- rates of progress of the surface reactions in kmol/m^2/s.
|
||||
Must be dimensioned at least NSR, the number of surface reactions.
|
||||
|
||||
*/
|
||||
|
||||
void get_rop(double* c, double* kf, double* ropf) {
|
||||
"""
|
||||
|
||||
sdotheader = """
|
||||
|
||||
void get_sdot(double* r, double* sdot) {
|
||||
"""
|
||||
|
||||
rateheader = """
|
||||
|
||||
/* get the forward reaction rates */
|
||||
void get_kf(double T, double* kf) {
|
||||
double logT = log(T);
|
||||
double rt = 1.0/T;
|
||||
"""
|
||||
|
||||
finaltxt = """
|
||||
}
|
||||
"""
|
||||
|
||||
class SurfWriter:
|
||||
|
||||
def __init__(self, iface, mechname):
|
||||
self.bulk1 = iface.p1
|
||||
self.bulk2 = iface.p2
|
||||
self.surf = iface
|
||||
self.sp = {}
|
||||
self.f = open(mechname+'.c', 'w')
|
||||
self.write_top()
|
||||
self.f.write('\n#ifdef __cplusplus\nextern "C" {\n#endif')
|
||||
self.rop = ropheader
|
||||
self.rate = rateheader
|
||||
self.nrxns = 0
|
||||
self.sdot = {}
|
||||
|
||||
def write(self):
|
||||
self.f.write(self.rop)
|
||||
self.f.write(' }\n\n')
|
||||
self.f.write(sdotheader)
|
||||
for k in self.sdot.keys():
|
||||
self.f.write('\n /* '+self.sp[k]+' */\n')
|
||||
self.f.write(' sdot['+`k`+'] = '+self.sdot[k]+';\n')
|
||||
self.f.write(' }\n\n')
|
||||
self.f.write(self.rate)
|
||||
self.f.write(' }\n')
|
||||
self.f.write('#ifdef __cplusplus\n}\n#endif\n')
|
||||
self.f.close()
|
||||
|
||||
def write_top(self):
|
||||
self.f.write(hdr)
|
||||
n1 = self.bulk1.nSpecies()
|
||||
self.f.write('Bulk phase 1 species: '+`n1`+' total.\n')
|
||||
|
||||
sp = self.bulk1.speciesNames()
|
||||
i = 0
|
||||
k = 0
|
||||
for s in sp:
|
||||
self.f.write('%3d %s\n' % (i, s))
|
||||
i += 1
|
||||
self.sp[k] = s
|
||||
k += 1
|
||||
self.f.write('\n\n')
|
||||
|
||||
if self.bulk2:
|
||||
n2 = self.bulk2.nSpecies()
|
||||
self.f.write('Bulk phase 2 species: '+`n2`+' total.\n')
|
||||
|
||||
sp = self.bulk2.speciesNames()
|
||||
i = 0
|
||||
for s in sp:
|
||||
self.f.write('%3d %s\n' % (i, s))
|
||||
i += 1
|
||||
self.sp[k] = s
|
||||
k += 1
|
||||
self.f.write('\n\n')
|
||||
|
||||
else:
|
||||
self.f.write('No second bulk phase.\n\n')
|
||||
|
||||
ns = self.surf.nSpecies()
|
||||
self.f.write('Surface species: '+`ns`+' total.\n')
|
||||
sp = self.surf.speciesNames()
|
||||
i = 0
|
||||
for s in sp:
|
||||
self.f.write('%3d %s\n' % (i, s))
|
||||
i += 1
|
||||
self.sp[k] = s
|
||||
k += 1
|
||||
self.f.write('\n\n*/')
|
||||
|
||||
self.f.write('\n\n')
|
||||
|
||||
|
||||
def write_update_rate(self, rate):
|
||||
i = self.nrxns
|
||||
self.rate += ' kf['+`i`+'] = '+'%17.10e' % (rate[0],)
|
||||
if rate[1] == 0.0 and rate[2] == 0.0:
|
||||
self.rate += ';\n'
|
||||
return
|
||||
self.rate += ' * exp('
|
||||
if rate[1] <> 0.0:
|
||||
self.rate += '%f * logT' % (rate[1],)
|
||||
if rate[2] <> 0.0:
|
||||
self.rate += '- %f * rt' % (rate[2],)
|
||||
self.rate += ');\n'
|
||||
|
||||
|
||||
def write_ROP(self, rindex, rstoich, rorder,
|
||||
pindex, pstoich, rate):
|
||||
f = ''
|
||||
i = self.nrxns
|
||||
f += ' ropf['+`i`+'] = kf['+`i`+']*'
|
||||
nr = len(rindex)
|
||||
for n in range(nr):
|
||||
k = rindex[n]
|
||||
if rorder[n] == rstoich[n]:
|
||||
for j in range(rstoich[n]):
|
||||
f +='c['+`k`+']*'
|
||||
else:
|
||||
f += 'pow(c['+`k`+'], '+`rorder[n]`+')*'
|
||||
f = f[:-1]+';\n'
|
||||
self.rop += f
|
||||
|
||||
def write_sdot(self, rindex, rstoich, pindex, pstoich):
|
||||
i = self.nrxns
|
||||
nr = len(rindex)
|
||||
for n in range(nr):
|
||||
k = rindex[n]
|
||||
if rstoich[n] == 1: st = ''
|
||||
else: st = `rstoich[n]`+'*'
|
||||
if not self.sdot.has_key(k):
|
||||
self.sdot[k] = ' -'+st+'r['+`i`+']'
|
||||
else:
|
||||
self.sdot[k] += ' - '+st+'r['+`i`+']'
|
||||
|
||||
np = len(pindex)
|
||||
for n in range(np):
|
||||
k = pindex[n]
|
||||
if pstoich[n] == 1: st = ''
|
||||
else: st = `pstoich[n]`+'*'
|
||||
if not self.sdot.has_key(k):
|
||||
self.sdot[k] = st+'r['+`i`+']'
|
||||
else:
|
||||
self.sdot[k] += ' + '+st+'r['+`i`+']'
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
""" This module implements class ThermoPhase, a class representing
|
||||
thermodynamic phases. """
|
||||
|
||||
"""
|
||||
This module implements class ThermoPhase, a class representing
|
||||
thermodynamic phases.
|
||||
"""
|
||||
from Cantera.num import zeros
|
||||
|
||||
from Cantera.Phase import Phase
|
||||
|
||||
|
||||
import _cantera
|
||||
import types
|
||||
|
||||
@@ -13,7 +12,8 @@ def thermoIndex(id):
|
||||
return _cantera.thermo_thermoIndex(id)
|
||||
|
||||
class ThermoPhase(Phase):
|
||||
""" A phase with an equation of state.
|
||||
"""
|
||||
A phase with an equation of state.
|
||||
|
||||
Class ThermoPhase may be used to represent the intensive
|
||||
thermodynamic state of a phase of matter, which might be a gas,
|
||||
@@ -23,10 +23,10 @@ class ThermoPhase(Phase):
|
||||
Class ThermoPhase is not usually instantiated directly. It is used
|
||||
as base class for classes Solution and Interface.
|
||||
|
||||
See: Solution, Interface
|
||||
@see Solution, Interface
|
||||
"""
|
||||
|
||||
#used in the 'equilibrate' method
|
||||
# used in the 'equilibrate' method
|
||||
_equilmap = {'TP':104,'TV':100,'HP':101,'SP':102,'SV':107,'UV':105,
|
||||
'PT':104,'VT':100,'PH':101,'PS':102,'VS':107,'VU':105}
|
||||
|
||||
@@ -46,8 +46,8 @@ class ThermoPhase(Phase):
|
||||
self.idtag = ""
|
||||
|
||||
if index >= 0:
|
||||
# create a Python wrapper for an existing kernel
|
||||
# ThermoPhase instance
|
||||
# create a Python wrapper for an existing kernel
|
||||
# ThermoPhase instance
|
||||
self._phase_id = index
|
||||
|
||||
elif xml_phase:
|
||||
@@ -67,9 +67,14 @@ class ThermoPhase(Phase):
|
||||
_cantera.thermo_delete(self._phase_id)
|
||||
|
||||
def name(self):
|
||||
"""The name assigned to the phase. The default value is the name
|
||||
attribute from the CTI file. But method setName can be used to
|
||||
set the name to anything desired, e.g. 'gas at inlet' or 'exhaust'
|
||||
"""
|
||||
return self.idtag
|
||||
|
||||
def setName(self, name):
|
||||
""" Set the name attribute. This can be any string"""
|
||||
self.idtag = name
|
||||
|
||||
def refPressure(self):
|
||||
@@ -157,14 +162,14 @@ class ThermoPhase(Phase):
|
||||
return self.selectElements(lamb, elements)
|
||||
|
||||
def enthalpies_RT(self, species = []):
|
||||
"""Pure species non-dimensional enthalpies.
|
||||
"""Pure species non-dimensional reference state enthalpies.
|
||||
|
||||
This method returns an array containing the pure-species
|
||||
standard-state enthalpies divided by RT. For gaseous species,
|
||||
these values are ideal gas enthalpies."""
|
||||
hrt = _cantera.thermo_getarray(self._phase_id,23)
|
||||
return self.selectSpecies(hrt, species)
|
||||
|
||||
|
||||
def entropies_R(self, species = []):
|
||||
"""Pure species non-dimensional entropies.
|
||||
|
||||
@@ -278,40 +283,39 @@ class ThermoPhase(Phase):
|
||||
|
||||
def equilibrate(self, XY, solver = -1, rtol = 1.0e-9,
|
||||
maxsteps = 1000, maxiter = 100, loglevel = 0):
|
||||
"""Set to a state of chemical equilibrium holding property pair
|
||||
'XY' constant.
|
||||
|
||||
XY -- A two-letter string, which must be one of the set
|
||||
['TP','TV','HP','SP','SV','UV','PT','VT','PH','PS','VS','VU'].
|
||||
If H, U, S, or V is specified, the value must be the specific
|
||||
value (per unit mass).
|
||||
|
||||
solver -- specifies the equilibrium solver to use. If solver =
|
||||
0, a fast solver using the element potential method will be
|
||||
used. If solver > 0, a slower but more robust Gibbs
|
||||
minimization solver will be used. If solver < 0 or
|
||||
unspecified, the fast solver will be tried first, then if it
|
||||
fails the other will be tried.
|
||||
|
||||
rtol -- the relative error tolerance.
|
||||
|
||||
maxsteps -- maximum number of steps in composition to take to
|
||||
find a converged solution.
|
||||
|
||||
maxiter -- for the Gibbs minimization solver only, this
|
||||
specifies the number of 'outer' iterations on T or P when some
|
||||
property pair other than TP is specified.
|
||||
|
||||
loglevel -- set to a value > 0 to write diagnostic output to a
|
||||
file in HTML format. Larger values generate more detailed
|
||||
information. The file will be named 'equilibrate_log.html.'
|
||||
Subsequent files will be named 'equillibrate_log1.html', etc.,
|
||||
so that log files are not overwritten.
|
||||
|
||||
"""
|
||||
""" Set to a state of chemical equilibrium holding property pair
|
||||
'XY' constant.
|
||||
|
||||
XY --- A two-letter string, which must be one of the set
|
||||
['TP','TV','HP','SP','SV','UV','PT','VT','PH','PS','VS','VU'].
|
||||
If H, U, S, or V is specified, the value must be the specific
|
||||
value (per unit mass)
|
||||
|
||||
solver --- Specifies the equilibrium solver to use. If solver =
|
||||
0, a fast solver using the element potential method will be
|
||||
used. If solver > 0, a slower but more robust Gibbs
|
||||
minimization solver will be used. If solver < 0 or
|
||||
unspecified, the fast solver will be tried first, then if it
|
||||
fails the other will be tried.
|
||||
|
||||
rtol -- the relative error tolerance.
|
||||
|
||||
maxsteps -- maximum number of steps in composition to take to
|
||||
find a converged solution.
|
||||
|
||||
maxiter -- for the Gibbs minimization solver only, this
|
||||
specifies the number of 'outer' iterations on T or P when some
|
||||
property pair other than TP is specified.
|
||||
|
||||
loglevel -- set to a value > 0 to write diagnostic output to a
|
||||
file in HTML format. Larger values generate more detailed
|
||||
information. The file will be named 'equilibrate_log.html.'
|
||||
Subsequent files will be named 'equillibrate_log1.html', etc.,
|
||||
so that log files are not overwritten.
|
||||
|
||||
"""
|
||||
_cantera.thermo_equil(self._phase_id, XY, solver,
|
||||
rtol, maxsteps, maxiter, loglevel)
|
||||
|
||||
|
||||
def saveState(self):
|
||||
"""Return an array with state information that can later be
|
||||
|
||||
@@ -139,6 +139,11 @@ class Transport:
|
||||
return _cantera.tran_binaryDiffCoeffs(self.__tr_id,
|
||||
self.trnsp)
|
||||
|
||||
def diffusionCoeffs(self):
|
||||
"""Species diffusion coefficients. (m^2/s)."""
|
||||
return self.mixDiffCoeffs()
|
||||
|
||||
|
||||
def mixDiffCoeffs(self):
|
||||
"""Mixture-averaged diffusion coefficients."""
|
||||
return _cantera.tran_mixDiffCoeffs(self.__tr_id,
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
import types
|
||||
import _cantera
|
||||
from num import *
|
||||
from constants import *
|
||||
from exceptions import *
|
||||
from gases import *
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# homogeneous equilibrium of a gas
|
||||
# homogeneous equilibrium of a gas.
|
||||
|
||||
from Cantera import *
|
||||
|
||||
|
||||
Reference in New Issue
Block a user