*** empty log message ***
This commit is contained in:
parent
6144c6dcd9
commit
df345002cd
24 changed files with 274 additions and 221 deletions
|
|
@ -70,9 +70,9 @@ public:
|
|||
* instance. All access to the Cabinet<M> instance should go
|
||||
* through this function.
|
||||
*/
|
||||
static Cabinet<M>* cabinet() {
|
||||
static Cabinet<M>* cabinet(bool canDelete = true) {
|
||||
if (__storage == 0) {
|
||||
__storage = new Cabinet<M>;
|
||||
__storage = new Cabinet<M>(canDelete);
|
||||
}
|
||||
return __storage;
|
||||
}
|
||||
|
|
@ -124,15 +124,16 @@ public:
|
|||
|
||||
|
||||
/**
|
||||
* Delete all objects.
|
||||
* Delete all objects but the first.
|
||||
*/
|
||||
int clear() {
|
||||
int i, n;
|
||||
n = __table.size();
|
||||
for (i = 1; i < n; i++) {del(i);}
|
||||
delete __table[0];
|
||||
__table = vector<M*>();
|
||||
return 0;
|
||||
if (_can_delete) delete __table[0];
|
||||
__table.clear();
|
||||
add(new M);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -144,7 +145,7 @@ public:
|
|||
void del(int n) {
|
||||
if (n == 0) return;
|
||||
if (__table[n] != __table[0]) {
|
||||
delete __table[n];
|
||||
if (_can_delete) delete __table[n];
|
||||
__table[n] = __table[0];
|
||||
}
|
||||
else {
|
||||
|
|
@ -171,7 +172,7 @@ private:
|
|||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
Cabinet() { add(new M); }
|
||||
Cabinet(bool canDelete = true) : _can_delete(canDelete) { add(new M); }
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -183,6 +184,11 @@ private:
|
|||
* Vector to hold pointers to objects.
|
||||
*/
|
||||
std::vector<M*> __table;
|
||||
|
||||
/**
|
||||
* Set to false if 'clear' should not delete the entries.
|
||||
*/
|
||||
bool _can_delete;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -71,21 +71,24 @@ int Storage::clear() {
|
|||
int i, n;
|
||||
n = __thtable.size();
|
||||
for (i = 1; i < n; i++) {
|
||||
if (__thtable[i] != __thtable[0])
|
||||
if (__thtable[i] != __thtable[0]) {
|
||||
delete __thtable[i];
|
||||
__thtable[i] = __thtable[0];
|
||||
__thtable[i] = __thtable[0];
|
||||
}
|
||||
}
|
||||
n = __ktable.size();
|
||||
for (i = 1; i < n; i++) {
|
||||
if (__ktable[i] != __ktable[0])
|
||||
if (__ktable[i] != __ktable[0]) {
|
||||
delete __ktable[i];
|
||||
__ktable[i] = __ktable[0];
|
||||
__ktable[i] = __ktable[0];
|
||||
}
|
||||
}
|
||||
n = __trtable.size();
|
||||
for (i = 1; i < n; i++) {
|
||||
if (__trtable[i] != __trtable[0])
|
||||
if (__trtable[i] != __trtable[0]) {
|
||||
delete __trtable[i];
|
||||
__trtable[i] = __trtable[0];
|
||||
__trtable[i] = __trtable[0];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
#include "clib_defs.h"
|
||||
|
||||
inline XML_Node* _xml(int i) {
|
||||
return Cabinet<XML_Node>::cabinet()->item(i);
|
||||
return Cabinet<XML_Node>::cabinet(false)->item(i);
|
||||
}
|
||||
|
||||
inline int nThermo() {
|
||||
|
|
@ -844,13 +844,18 @@ extern "C" {
|
|||
|
||||
}
|
||||
int DLL_EXPORT clearStorage() {
|
||||
Storage::__storage->clear();
|
||||
return 0;
|
||||
try {
|
||||
Storage::storage()->clear();
|
||||
return 0;
|
||||
}
|
||||
catch (CanteraError) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int DLL_EXPORT delThermo(int n) {
|
||||
try {
|
||||
Storage::__storage->deleteThermo(n);
|
||||
Storage::storage()->deleteThermo(n);
|
||||
return 0;
|
||||
}
|
||||
catch (CanteraError) {
|
||||
|
|
@ -859,12 +864,12 @@ extern "C" {
|
|||
}
|
||||
|
||||
int DLL_EXPORT delKinetics(int n) {
|
||||
Storage::__storage->deleteKinetics(n);
|
||||
Storage::storage()->deleteKinetics(n);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int DLL_EXPORT delTransport(int n) {
|
||||
Storage::__storage->deleteTransport(n);
|
||||
Storage::storage()->deleteTransport(n);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -880,7 +885,8 @@ extern "C" {
|
|||
Kinetics& kin = *k;
|
||||
XML_Node *x, *r=0;
|
||||
if (root) r = &root->root();
|
||||
x = find_XML(string(src), r, string(id), "", "phase");
|
||||
x = get_XML_Node(string(src), r);
|
||||
//x = find_XML(string(src), r, string(id), "", "phase");
|
||||
if (!x) return false;
|
||||
importPhase(*x, t);
|
||||
kin.addPhase(*t);
|
||||
|
|
|
|||
|
|
@ -67,6 +67,14 @@ inline Transport* _transport(int n) {
|
|||
|
||||
extern "C" {
|
||||
|
||||
int DLL_EXPORT domain_clear() {
|
||||
try {
|
||||
Cabinet<Domain1D>::cabinet()->clear();
|
||||
return 0;
|
||||
}
|
||||
catch (CanteraError) { return -1; }
|
||||
}
|
||||
|
||||
int DLL_EXPORT domain_del(int i) {
|
||||
Cabinet<Domain1D>::cabinet()->del(i);
|
||||
return 0;
|
||||
|
|
@ -334,6 +342,14 @@ extern "C" {
|
|||
catch (CanteraError) { return -1; }
|
||||
}
|
||||
|
||||
int DLL_EXPORT sim1D_clear() {
|
||||
try {
|
||||
Cabinet<Sim1D>::cabinet()->clear();
|
||||
return 0;
|
||||
}
|
||||
catch (CanteraError) { return -1; }
|
||||
}
|
||||
|
||||
int DLL_EXPORT sim1D_del(int i) {
|
||||
Cabinet<Sim1D>::cabinet()->del(i);
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
extern "C" {
|
||||
|
||||
int DLL_IMPORT domain_clear();
|
||||
int DLL_IMPORT domain_del(int i);
|
||||
int DLL_IMPORT domain_type(int i);
|
||||
int DLL_IMPORT domain_index(int i);
|
||||
|
|
@ -42,6 +43,7 @@ extern "C" {
|
|||
int DLL_IMPORT stflow_solveSpeciesEqs(int i, int flag);
|
||||
int DLL_IMPORT stflow_solveEnergyEqn(int i, int flag);
|
||||
|
||||
int DLL_IMPORT sim1D_clear();
|
||||
int DLL_IMPORT sim1D_new(int nd, int* domains);
|
||||
int DLL_IMPORT sim1D_del(int i);
|
||||
int DLL_IMPORT sim1D_setValue(int i, int dom, int comp, int localPoint, double value);
|
||||
|
|
|
|||
|
|
@ -317,6 +317,18 @@ extern "C" {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int DLL_EXPORT wall_setkinetics(int i, int n, int m) {
|
||||
Kinetics *left=0, *right=0;
|
||||
if (n > 0)
|
||||
if (_kin(n)->type() == cInterfaceKinetics)
|
||||
left = _kin(n);
|
||||
if (m > 0)
|
||||
if (_kin(m)->type() == cInterfaceKinetics)
|
||||
right = _kin(m);
|
||||
_wall(i)->setKinetics(left, right);
|
||||
return 0;
|
||||
}
|
||||
|
||||
double DLL_EXPORT wall_vdot(int i, double t) {
|
||||
return _wall(i)->vdot(t);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ extern "C" {
|
|||
int DLL_IMPORT wall_copy(int i);
|
||||
int DLL_IMPORT wall_assign(int i, int j);
|
||||
int DLL_IMPORT wall_install(int i, int n, int m);
|
||||
int DLL_IMPORT wall_setkinetics(int i, int n, int m);
|
||||
double DLL_IMPORT wall_vdot(int i, double t);
|
||||
double DLL_IMPORT wall_Q(int i, double t);
|
||||
double DLL_IMPORT wall_area(int i);
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
Cabinet<XML_Node>* Cabinet<XML_Node>::__storage = 0;
|
||||
|
||||
inline XML_Node* _xml(int i) {
|
||||
return Cabinet<XML_Node>::cabinet()->item(i);
|
||||
return Cabinet<XML_Node>::cabinet(false)->item(i);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
|
@ -33,11 +33,28 @@ extern "C" {
|
|||
x = new XML_Node;
|
||||
else
|
||||
x = new XML_Node(string(name));
|
||||
return Cabinet<XML_Node>::cabinet()->add(x);
|
||||
return Cabinet<XML_Node>::cabinet(true)->add(x);
|
||||
}
|
||||
|
||||
int DLL_EXPORT xml_get_XML_File(const char* file) {
|
||||
try {
|
||||
XML_Node* x = get_XML_File(string(file));
|
||||
return Cabinet<XML_Node>::cabinet(false)->add(x);
|
||||
}
|
||||
catch (CanteraError) { return -1; }
|
||||
}
|
||||
|
||||
int DLL_EXPORT xml_clear() {
|
||||
try {
|
||||
Cabinet<XML_Node>::cabinet(false)->clear();
|
||||
close_XML_File("all");
|
||||
return 0;
|
||||
}
|
||||
catch (CanteraError) { return -1; }
|
||||
}
|
||||
|
||||
int DLL_EXPORT xml_del(int i) {
|
||||
Cabinet<XML_Node>::cabinet()->del(i);
|
||||
Cabinet<XML_Node>::cabinet(false)->del(i);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -47,15 +64,16 @@ extern "C" {
|
|||
}
|
||||
|
||||
int DLL_EXPORT xml_copy(int i) {
|
||||
return Cabinet<XML_Node>::cabinet()->newCopy(i);
|
||||
return Cabinet<XML_Node>::cabinet(false)->newCopy(i);
|
||||
}
|
||||
|
||||
int DLL_EXPORT xml_assign(int i, int j) {
|
||||
return Cabinet<XML_Node>::cabinet()->assign(i,j);
|
||||
return Cabinet<XML_Node>::cabinet(false)->assign(i,j);
|
||||
}
|
||||
|
||||
int DLL_EXPORT xml_build(int i, const char* file) {
|
||||
try {
|
||||
writelog("WARNING: xml_build called. Use get_XML_File instead.");
|
||||
string path = findInputFile(string(file));
|
||||
ifstream f(path.c_str());
|
||||
if (!f) {
|
||||
|
|
@ -77,6 +95,8 @@ extern "C" {
|
|||
catch (CanteraError) { return -1; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
int DLL_EXPORT xml_attrib(int i, const char* key, char* value) {
|
||||
try {
|
||||
string ky = string(key);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,9 @@
|
|||
extern "C" {
|
||||
|
||||
int DLL_IMPORT xml_new(const char* name);
|
||||
int DLL_IMPORT xml_get_XML_File(const char* file);
|
||||
int DLL_IMPORT xml_del(int i);
|
||||
int DLL_IMPORT xml_clear();
|
||||
int DLL_IMPORT xml_copy(int i);
|
||||
int DLL_IMPORT xml_assign(int i, int j);
|
||||
int DLL_IMPORT xml_build(int i, const char* file);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include "mex.h"
|
||||
#include "../../../clib/src/ct.h"
|
||||
#include "../../../clib/src/ctonedim.h"
|
||||
#include "../../../clib/src/ctxml.h"
|
||||
#include "ctmatutils.h"
|
||||
#include <string.h>
|
||||
|
||||
|
|
@ -53,6 +55,14 @@ void ctfunctions( int nlhs, mxArray *plhs[],
|
|||
iok = addCanteraDirectory(strlen(infile), infile);
|
||||
break;
|
||||
|
||||
// clear storage
|
||||
case 4:
|
||||
iok = domain_clear();
|
||||
iok = sim1D_clear();
|
||||
//iok = xml_clear();
|
||||
iok = clearStorage();
|
||||
break;
|
||||
|
||||
default:
|
||||
mexErrMsgTxt("ctfunctions: unknown job");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -362,6 +362,11 @@ void onedimmethods( int nlhs, mxArray *plhs[],
|
|||
icount = getInt(prhs[4]);
|
||||
iok = sim1D_eval(dom, rdt, icount);
|
||||
break;
|
||||
//case 200:
|
||||
//iok = domain1D_clear();
|
||||
//iok = sim1D_clear();
|
||||
//break;
|
||||
|
||||
default:
|
||||
mexPrintf(" job = %d ",job);
|
||||
mexErrMsgTxt("unknown parameter");
|
||||
|
|
|
|||
|
|
@ -344,6 +344,15 @@ class Wall:
|
|||
_cantera.wall_install(self.__wall_id, left.reactor_id(),
|
||||
right.reactor_id())
|
||||
|
||||
def setKinetics(self, left, right):
|
||||
ileft = 0
|
||||
iright = 0
|
||||
if left:
|
||||
ileft = left.kin_index()
|
||||
if right:
|
||||
iright = right.kin_index()
|
||||
_cantera.wall_setkinetics(self.__wall_id, ileft, iright)
|
||||
|
||||
def set(self, **p):
|
||||
for item in p.keys():
|
||||
if item == 'A' or item == 'area':
|
||||
|
|
|
|||
|
|
@ -13,22 +13,31 @@ class XML_Node:
|
|||
def __init__(self, name="--", src="", wrap=0, root=None, preprocess=0):
|
||||
"""
|
||||
Return an instance representing a node in an XML tree.
|
||||
|
||||
If 'src' is specified, then the XML tree found in file 'src' is
|
||||
constructed, and this node forms the root of the tree.
|
||||
Construct a new XML tree, with this node as the root.
|
||||
If 'wrap' is greater than zero, then a
|
||||
constructed, and this node forms the root of the tree. The XML tree
|
||||
is saved, and a second call with the same value for 'src' will use
|
||||
the XML tree already read in, instead of reading it in again.
|
||||
|
||||
If 'wrap' is greater than zero, then only a Python wrapper is
|
||||
created - no new kernel object results.
|
||||
"""
|
||||
|
||||
self.wrap = wrap
|
||||
|
||||
# create a wrapper for an existing kernel object
|
||||
if wrap > 0:
|
||||
self._xml_id = wrap
|
||||
self._root = 0 # root
|
||||
|
||||
# create an XML tree by parsing a file, and possibly
|
||||
# preprocessing it first
|
||||
elif src:
|
||||
self._xml_id = _cantera.xml_get_XML_File(src)
|
||||
self._root = 0
|
||||
self.wrap = 1
|
||||
self.wrap = 1 # disable deleting
|
||||
|
||||
# create a new empty node
|
||||
else:
|
||||
self._xml_id = _cantera.xml_new(name)
|
||||
self._root = 0
|
||||
|
||||
def __del__(self):
|
||||
"""Delete the node. Does nothing if this node is only a wrapper."""
|
||||
|
|
@ -39,37 +48,42 @@ class XML_Node:
|
|||
return _cantera.xml_tag(self._xml_id)
|
||||
|
||||
def id(self):
|
||||
"""Return the id attribute if one exists, or else the empty string."""
|
||||
try:
|
||||
return self['id']
|
||||
except:
|
||||
return ''
|
||||
|
||||
def root(self):
|
||||
return self._root
|
||||
|
||||
def nChildren(self):
|
||||
"""Number of child elements."""
|
||||
return _cantera.xml_nChildren(self._xml_id)
|
||||
|
||||
def children(self,tag=""):
|
||||
"""Return a list of all child elements, or just those with a specified
|
||||
tag name.
|
||||
"""
|
||||
nch = self.nChildren()
|
||||
children = []
|
||||
for n in range(nch):
|
||||
m = _cantera.xml_childbynumber(self._xml_id, n)
|
||||
ch = XML_Node(src="", wrap=m, root=self._root)
|
||||
ch = XML_Node(wrap = m)
|
||||
if (tag == "" or ch.tag() == tag):
|
||||
children.append(ch)
|
||||
return children
|
||||
|
||||
def removeChild(self, child):
|
||||
"""Remove a child and all its descendants."""
|
||||
_cantera.xml_removeChild(self._xml_id, child._xml_id)
|
||||
|
||||
def addChild(self, name, value=""):
|
||||
"""Add a child with tag 'name', and set its value if the value
|
||||
parameter is supplied."""
|
||||
if type(value) <> types.StringType:
|
||||
v = `value`
|
||||
else:
|
||||
v = value
|
||||
m = _cantera.xml_addChild(self._xml_id, name, v)
|
||||
return XML_Node(src="", wrap=m, root=self._root)
|
||||
return XML_Node(wrap = m)
|
||||
|
||||
def hasAttrib(self, key):
|
||||
x = self.attrib(key)
|
||||
|
|
@ -77,18 +91,25 @@ class XML_Node:
|
|||
else: return 0
|
||||
|
||||
def attrib(self, key):
|
||||
"""Return attribute 'key', or the empty string if this attribute
|
||||
does not exist."""
|
||||
try:
|
||||
return _cantera.xml_attrib(self._xml_id, key)
|
||||
except:
|
||||
return ''
|
||||
|
||||
def addAttrib(self, key, value):
|
||||
"""Add attribute 'key' with value 'value'."""
|
||||
_cantera.xml_addAttrib(self._xml_id, key, value)
|
||||
|
||||
def addComment(self, comment):
|
||||
"""Add a comment."""
|
||||
_cantera.xml_addComment(self._xml_id, comment)
|
||||
|
||||
def value(self, loc=""):
|
||||
"""Return the value of this node, or, if
|
||||
the loc argument is supplied, of the node with relative
|
||||
address 'loc'."""
|
||||
if loc:
|
||||
node = self.child(loc)
|
||||
return node.value()
|
||||
|
|
@ -103,19 +124,23 @@ class XML_Node:
|
|||
elif name:
|
||||
m = _cantera.xml_findByName(self._xml_id, name)
|
||||
|
||||
ch = XML_Node(src="", wrap=m, root=self._root)
|
||||
ch = XML_Node(wrap=m)
|
||||
return ch
|
||||
|
||||
def __getitem__(self, key):
|
||||
"""Get an attribute using the syntax node[key]"""
|
||||
return self.attrib(key)
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
"""Set a new attribute using the syntax node[key] = value."""
|
||||
return self.addAttrib(key, value)
|
||||
|
||||
def __int__(self):
|
||||
"""Conversion to integer."""
|
||||
return self._xml_id
|
||||
|
||||
def __call__(self, loc):
|
||||
def __call__(self, loc=''):
|
||||
"""Get the value using the syntax node(loc)."""
|
||||
return self.value(loc)
|
||||
|
||||
def write(self, file):
|
||||
|
|
@ -132,42 +157,42 @@ class XML_Node:
|
|||
s += line
|
||||
return s
|
||||
|
||||
def getRef(self):
|
||||
if not self["idRef"]: return self
|
||||
return find_XML(src = self["src"], root = self.root(),
|
||||
id = self["idRef"])
|
||||
## def getRef(self):
|
||||
## if not self["idRef"]: return self
|
||||
## return find_XML(src = self["src"], root = self.root(),
|
||||
## id = self["idRef"])
|
||||
|
||||
|
||||
def clear_XML():
|
||||
_cantera.xml_clear()
|
||||
|
||||
|
||||
def find_XML(src = "", root = None, id = "", loc = "", name=""):
|
||||
doc = None
|
||||
r = None
|
||||
if src:
|
||||
ihash = string.find(src,'#')
|
||||
if ihash < 0:
|
||||
fname = src
|
||||
else:
|
||||
fname, idnew = string.split(src,'#')
|
||||
if idnew: id = idnew
|
||||
if fname:
|
||||
doc = XML_Node(name="doc", src=fname)
|
||||
root = None
|
||||
elif root:
|
||||
doc = root
|
||||
elif root:
|
||||
doc = root
|
||||
else:
|
||||
raise exceptions.CanteraError("either root or src must be specified.")
|
||||
## def find_XML(src = "", root = None, id = "", loc = "", name=""):
|
||||
## doc = None
|
||||
## r = None
|
||||
## if src:
|
||||
## ihash = string.find(src,'#')
|
||||
## if ihash < 0:
|
||||
## fname = src
|
||||
## else:
|
||||
## fname, idnew = string.split(src,'#')
|
||||
## if idnew: id = idnew
|
||||
## if fname:
|
||||
## doc = XML_Node(name="doc", src=fname)
|
||||
## root = None
|
||||
## elif root:
|
||||
## doc = root
|
||||
## elif root:
|
||||
## doc = root
|
||||
## else:
|
||||
## raise exceptions.CanteraError("either root or src must be specified.")
|
||||
|
||||
## try:
|
||||
if loc or id or name:
|
||||
r = doc.child(loc=loc, id=id, name=name)
|
||||
else:
|
||||
r = doc
|
||||
return r
|
||||
## ## try:
|
||||
## if loc or id or name:
|
||||
## r = doc.child(loc=loc, id=id, name=name)
|
||||
## else:
|
||||
## r = doc
|
||||
## return r
|
||||
|
||||
|
||||
def getFloatArray(node, convert_units=0):
|
||||
|
|
|
|||
|
|
@ -554,6 +554,8 @@ class reaction(writer):
|
|||
if ph.is_ideal_gas():
|
||||
self._igspecies.append(s)
|
||||
break
|
||||
if nm == -999:
|
||||
raise CanteraError("species "+s+" not found")
|
||||
|
||||
mdim += nm*ns
|
||||
ldim += nl*ns
|
||||
|
|
@ -1195,7 +1197,10 @@ if __name__ == "__main__":
|
|||
# $Revision$
|
||||
# $Date$
|
||||
# $Log$
|
||||
# Revision 1.17 2003-08-20 15:35:32 dggoodwin
|
||||
# Revision 1.18 2003-08-21 14:29:53 dggoodwin
|
||||
# *** empty log message ***
|
||||
#
|
||||
# Revision 1.17 2003/08/20 15:35:32 dggoodwin
|
||||
# *** empty log message ***
|
||||
#
|
||||
# Revision 1.16 2003/08/19 22:02:01 hkmoffa
|
||||
|
|
|
|||
|
|
@ -13,8 +13,7 @@ from ck2ctml import ck2ctml
|
|||
#import _cantera
|
||||
import os
|
||||
|
||||
def IdealGasMix(src="", root=None, transport='None',
|
||||
thermo = "", trandb = ""):
|
||||
def IdealGasMix(src="", id = ""):
|
||||
"""Return a Solution object representing an ideal gas mixture.
|
||||
|
||||
src --- input file
|
||||
|
|
@ -24,91 +23,30 @@ def IdealGasMix(src="", root=None, transport='None',
|
|||
transport --- transport model
|
||||
trandb --- transport database
|
||||
"""
|
||||
p = os.path.normpath(os.path.dirname(src))
|
||||
fname = os.path.basename(src)
|
||||
ff = os.path.splitext(fname)
|
||||
nm = ""
|
||||
if len(ff) > 1:
|
||||
nm = ff[0]
|
||||
ext = ff[1]
|
||||
else:
|
||||
nm = ff
|
||||
ext = ''
|
||||
## if ext <> '.xml' and ext <> '.XML' and ext <> '.ctml' and ext <> '.CTML':
|
||||
## outfile = p+os.sep+nm+'.xml'
|
||||
## if ext == '.py':
|
||||
## from Cantera import pip
|
||||
## pip.process(fname)
|
||||
## else:
|
||||
## ck2ctml(infile = src, outfile = outfile, thermo = thermo,
|
||||
## transport = trandb, id = nm)
|
||||
## return Solution(src=outfile, root=None, transport=transport)
|
||||
## p = os.path.normpath(os.path.dirname(src))
|
||||
## fname = os.path.basename(src)
|
||||
## ff = os.path.splitext(fname)
|
||||
## nm = ""
|
||||
## if len(ff) > 1:
|
||||
## nm = ff[0]
|
||||
## ext = ff[1]
|
||||
## else:
|
||||
return Solution(src=src, root=root, transport=transport)
|
||||
## nm = ff
|
||||
## ext = ''
|
||||
return Solution(src=src,id=id)
|
||||
|
||||
def GRI30(transport='None'):
|
||||
def GRI30():
|
||||
"""Return a Solution instance implementing reaction mechanism
|
||||
GRI-Mech 3.0."""
|
||||
return Solution(src="gri30.xml#gri30_hw", transport=transport)
|
||||
return Solution(src="gri30.xml", id="gri30_hw")
|
||||
|
||||
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")
|
||||
return Solution(src="air.xml", id="air")
|
||||
|
||||
def Argon():
|
||||
"""Return a Solution instance representing pure argon."""
|
||||
return Solution(src="argon.xml#argon")
|
||||
|
||||
## def H_O_AR(transport=None, chem = 1):
|
||||
## """
|
||||
## The hydrogen/oxygen/argon portion of GRI-Mech 3.0.
|
||||
|
||||
## Parameters:
|
||||
## transport --- transport model (None, 'Mix,' or 'Multi'). Default: None
|
||||
## chem --- chemistry disabled if chem = 0. Default: enabled.
|
||||
## """
|
||||
## if chem == 1:
|
||||
## return Solution(import_file='h2o2.inp', thermo_db="",
|
||||
## eos=1, kmodel=1, trmodel=transport,
|
||||
## transport_db='gri30_tran.dat',
|
||||
## validate=0)
|
||||
## else:
|
||||
## return Solution(import_file='h2o2_noch.inp', thermo_db="",
|
||||
## eos=1, kmodel=1, trmodel=transport,
|
||||
## transport_db='gri30_tran.dat',
|
||||
## validate=0)
|
||||
|
||||
|
||||
## def GRI30(transport=None):
|
||||
## """
|
||||
## GRI-Mech 3.0.
|
||||
|
||||
## Parameters:
|
||||
## transport --- transport model (None, 'Mix,' or 'Multi'). Default: None
|
||||
## """
|
||||
## return Solution(import_file='gri30.xml', thermo_db="",
|
||||
## eos=1, kmodel=2, trmodel=transport, id="gri30",
|
||||
## transport_db='gri30_tran.dat',
|
||||
## validate=0)
|
||||
|
||||
|
||||
## def Air(transport=None, T=300.0, P=OneAtm):
|
||||
## """
|
||||
## Edited version of GRI-Mech 3.0 containing only O/N/AR species. Initial
|
||||
## composition is set to 21% O2, 78% N2, 1% Ar.
|
||||
|
||||
## Parameters:
|
||||
## transport --- transport model (None, 'Mix,' or 'Multi'). Default: None
|
||||
## T --- temperature
|
||||
## P --- pressure
|
||||
## """
|
||||
## gas = Solution(import_file='air.inp', thermo_db="nasathermo.dat",
|
||||
## eos=1, kmodel=1, trmodel=transport, id="air",
|
||||
## transport_db='gri30_tran.dat',
|
||||
## validate=0)
|
||||
## gas.setState_TPX(T, P, 'O2:0.21, N2:0.78, Ar:0.01')
|
||||
## return gas
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,40 +2,18 @@ import solution
|
|||
import Interface
|
||||
import XML
|
||||
|
||||
def preprocess(f):
|
||||
fn = f.split('.')
|
||||
prepr = 1
|
||||
base = f
|
||||
if len(fn) == 2:
|
||||
base = fn[0]
|
||||
if fn[1] == '.xml' or fn[1] == '.ctml':
|
||||
prepr = 0
|
||||
if prepr:
|
||||
from Cantera import pip
|
||||
pip.process(f)
|
||||
src = base+'.xml'
|
||||
else:
|
||||
src = f
|
||||
return src
|
||||
|
||||
def importPhase(file = '', name = ''):
|
||||
return importPhases(file, [name])[0]
|
||||
|
||||
def importPhases(file = '', names = []):
|
||||
"""Import multiple phase definitions.
|
||||
By importing all required phases in one file with one function call,
|
||||
the preprocessor and CTML parser only need to run once.
|
||||
"""
|
||||
s = []
|
||||
#root = XML.XML_Node(name = 'doc', src = file, preprocess = 1)
|
||||
for nm in names:
|
||||
src = file+'#'+nm
|
||||
s.append(solution.Solution(src))
|
||||
s.append(solution.Solution(src=file,id=nm))
|
||||
return s
|
||||
|
||||
def importInterface(file = '', name = '', phases = []):
|
||||
#file = preprocess(file)
|
||||
#root = XML.XML_Node(name = 'doc', src = file, preprocess = 1)
|
||||
if name:
|
||||
src = file+'#'+name
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -28,38 +28,33 @@ class Solution(ThermoPhase, Kinetics, Transport):
|
|||
|
||||
"""
|
||||
|
||||
def __init__(self, src="", root=None,
|
||||
transport = "", thermo_db = "",
|
||||
transport_db = "", phases=[]):
|
||||
def __init__(self, src="", id=""):
|
||||
|
||||
self.ckin = 0
|
||||
self._owner = 0
|
||||
self.verbose = 1
|
||||
fn = src.split('#')
|
||||
id = ""
|
||||
if len(fn) > 1:
|
||||
id = fn[1]
|
||||
fn = fn[0]
|
||||
fname = os.path.basename(fn)
|
||||
fname = os.path.basename(src)
|
||||
ff = os.path.splitext(fname)
|
||||
|
||||
if src and not root:
|
||||
root = XML.XML_Node(name = 'doc', src = fn, preprocess = 1)
|
||||
if src:
|
||||
root = XML.XML_Node(name = 'doc', src = src, preprocess = 1)
|
||||
|
||||
if id:
|
||||
s = root.child(id = id)
|
||||
|
||||
else:
|
||||
s = root.child(name = "phase")
|
||||
|
||||
# get the equation of state model
|
||||
# initialize the equation of state
|
||||
ThermoPhase.__init__(self, xml_phase=s)
|
||||
|
||||
# get the kinetics model
|
||||
ph = [self]+list(phases)
|
||||
# initialize the kinetics model
|
||||
ph = [self]
|
||||
Kinetics.__init__(self, xml_phase=s, phases=ph)
|
||||
|
||||
# initialize the transport model
|
||||
Transport.__init__(self, xml_phase=s, phase=self,
|
||||
model = transport, loglevel=4)
|
||||
model = '', loglevel=0)
|
||||
|
||||
def __del__(self):
|
||||
Transport.__del__(self)
|
||||
|
|
|
|||
|
|
@ -22,6 +22,16 @@ ct_get_cantera_error(PyObject *self, PyObject *args)
|
|||
return msg;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
ct_refcnt(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject* o;
|
||||
if (!PyArg_ParseTuple(args, "O", &o)) return NULL;
|
||||
cout << "refcnt = " << o->ob_refcnt << endl;
|
||||
PyObject* cnt = Py_BuildValue("i",o->ob_refcnt);
|
||||
return cnt;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
ct_print(PyObject *self, PyObject *args)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -324,6 +324,17 @@ py_wall_install(PyObject *self, PyObject *args)
|
|||
return Py_BuildValue("i",0);
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
py_wall_setkinetics(PyObject *self, PyObject *args)
|
||||
{
|
||||
int n, k1, k2;
|
||||
if (!PyArg_ParseTuple(args, "iii:wall_setkinetics", &n, &k1, &k2))
|
||||
return NULL;
|
||||
int iok = wall_setkinetics(n, k1, k2);
|
||||
if (iok < 0) return reportError(iok);
|
||||
return Py_BuildValue("i",0);
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
py_wall_vdot(PyObject *self, PyObject *args)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,9 +6,23 @@ py_xml_new(PyObject *self, PyObject *args)
|
|||
if (!PyArg_ParseTuple(args, "s:xml_new", &nm))
|
||||
return NULL;
|
||||
int n = xml_new(nm);
|
||||
return Py_BuildValue("i",n);
|
||||
PyObject* pn = Py_BuildValue("i",n);
|
||||
return pn;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
py_xml_get_XML_File(PyObject *self, PyObject *args)
|
||||
{
|
||||
char* file;
|
||||
if (!PyArg_ParseTuple(args, "s:xml_get_XML_File", &file))
|
||||
return NULL;
|
||||
int n = xml_get_XML_File(file);
|
||||
if (n < 0) return reportError(n);
|
||||
PyObject* pn = Py_BuildValue("i",n);
|
||||
return pn;
|
||||
}
|
||||
|
||||
|
||||
static PyObject*
|
||||
py_xml_del(PyObject *self, PyObject *args)
|
||||
{
|
||||
|
|
@ -21,17 +35,9 @@ py_xml_del(PyObject *self, PyObject *args)
|
|||
}
|
||||
|
||||
static PyObject*
|
||||
py_xml_build(PyObject *self, PyObject *args)
|
||||
py_xml_clear(PyObject *self, PyObject *args)
|
||||
{
|
||||
int n, pre;
|
||||
char* file;
|
||||
if (!PyArg_ParseTuple(args, "isi:xml_build", &n, &file, &pre))
|
||||
return NULL;
|
||||
int iok;
|
||||
if (pre > 0)
|
||||
iok = xml_preprocess_and_build(n, file);
|
||||
else
|
||||
iok = xml_build(n, file);
|
||||
int iok = xml_clear();
|
||||
if (iok < 0) return reportError(iok);
|
||||
return Py_BuildValue("i",0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,8 +39,9 @@ static PyMethodDef ct_methods[] = {
|
|||
{"xml_tag", py_xml_tag, METH_VARARGS},
|
||||
{"xml_value", py_xml_value, METH_VARARGS},
|
||||
{"xml_new", py_xml_new, METH_VARARGS},
|
||||
{"xml_get_XML_File", py_xml_get_XML_File, METH_VARARGS},
|
||||
{"xml_del", py_xml_del, METH_VARARGS},
|
||||
{"xml_build", py_xml_build, METH_VARARGS},
|
||||
{"xml_clear", py_xml_clear, METH_VARARGS},
|
||||
{"xml_child", py_xml_child, METH_VARARGS},
|
||||
{"xml_childbynumber", py_xml_childbynumber, METH_VARARGS},
|
||||
{"xml_findID", py_xml_findID, METH_VARARGS},
|
||||
|
|
@ -82,6 +83,7 @@ static PyMethodDef ct_methods[] = {
|
|||
|
||||
{"get_Cantera_Error", ct_get_cantera_error, METH_VARARGS},
|
||||
{"ct_print", ct_print, METH_VARARGS},
|
||||
{"ct_refcnt", ct_refcnt, METH_VARARGS},
|
||||
{"readlog", ct_readlog, METH_VARARGS},
|
||||
{"ck2cti", ct_ck2cti, METH_VARARGS},
|
||||
{"buildSolutionFromXML", ct_buildSolutionFromXML, METH_VARARGS},
|
||||
|
|
@ -193,6 +195,7 @@ static PyMethodDef ct_methods[] = {
|
|||
{"reactor_intEnergy_mass", py_reactor_intEnergy_mass, METH_VARARGS},
|
||||
{"reactor_massFraction", py_reactor_massFraction, METH_VARARGS},
|
||||
{"wall_install", py_wall_install, METH_VARARGS},
|
||||
{"wall_setkinetics", py_wall_setkinetics, METH_VARARGS},
|
||||
{"wall_area", py_wall_area, METH_VARARGS},
|
||||
{"wall_setArea", py_wall_setArea, METH_VARARGS},
|
||||
{"wall_setThermalResistance", py_wall_setThermalResistance, METH_VARARGS},
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ namespace Cantera {
|
|||
Kinetics(thermo_t* thermo)
|
||||
: m_ii(0), m_index(-1), m_surfphase(-1) {
|
||||
if (thermo) {
|
||||
// addPhase(*thermo);
|
||||
addPhase(*thermo);
|
||||
// m_start.push_back(0);
|
||||
// if (thermo->eosType() == cSurf) m_surfphase = nPhases();
|
||||
// m_thermo.push_back(thermo);
|
||||
|
|
@ -148,7 +148,7 @@ namespace Cantera {
|
|||
/**
|
||||
* Returns the starting index of the species in the nth phase
|
||||
* associated with the reaction mechanism. @deprecated. Can be
|
||||
* replaced by kineticsSpeciesIndex(0).
|
||||
* replaced by kineticsSpeciesIndex(0,n).
|
||||
*
|
||||
* @param n Return the index of first species in the nth phase
|
||||
* associated with the reaction mechanism.
|
||||
|
|
|
|||
|
|
@ -75,8 +75,8 @@ namespace Cantera {
|
|||
|
||||
void ReactorBase::addWall(Wall& w, int lr) {
|
||||
m_wall.push_back(&w);
|
||||
if (lr > 0) m_lr.push_back(1);
|
||||
else m_lr.push_back(-1);
|
||||
if (lr == 0) m_lr.push_back(0);
|
||||
else m_lr.push_back(1);
|
||||
m_nwalls++;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* @file ck2ctml.cpp
|
||||
* @file ck2cti.cpp
|
||||
*
|
||||
* Program to convert CK-format reaction mechanism files to CTML format.
|
||||
* Program to convert CK-format reaction mechanism files to Cantera input format.
|
||||
*
|
||||
*/
|
||||
#ifdef WIN32
|
||||
|
|
@ -13,30 +13,29 @@
|
|||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
#include "converters/ck2ctml.h"
|
||||
#include "ct_defs.h"
|
||||
#include "global.h"
|
||||
#include "converters/ck2ct.h"
|
||||
|
||||
using namespace ctml;
|
||||
using namespace Cantera;
|
||||
|
||||
int showHelp() {
|
||||
cout << "\nck2ckml: convert a CK-format reaction mechanism file to CTML.\n"
|
||||
cout << "\nck2cti: convert a CK-format reaction mechanism file to Cantera input format.\n"
|
||||
<< "\n D. G. Goodwin, Caltech \n"
|
||||
<< " Version 1.0, August 2002.\n\n"
|
||||
<< " Version 1.0, August 2003.\n\n"
|
||||
<< endl;
|
||||
cout << "options:" << endl;
|
||||
cout << " -i <input file> \n"
|
||||
<< " -o <output file> \n"
|
||||
<< " -t <thermo database> \n"
|
||||
<< " -tr <transport database> \n"
|
||||
<< " -id <identifier> \n";
|
||||
<< " -id <identifier> \n\n"
|
||||
<< "The results are written to the standard output.\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
string infile="chem.inp", dbfile="", trfile="", logfile, outfile="";
|
||||
string infile="chem.inp", dbfile="", trfile="", logfile;
|
||||
string idtag = "gas";
|
||||
// ckr::CKReader r;
|
||||
//r.validate = true;
|
||||
int i=1;
|
||||
if (argc == 1) return showHelp();
|
||||
|
||||
|
|
@ -47,10 +46,6 @@ int main(int argc, char** argv) {
|
|||
infile = argv[i+1];
|
||||
++i;
|
||||
}
|
||||
else if (arg == "-o") {
|
||||
outfile = argv[i+1];
|
||||
++i;
|
||||
}
|
||||
else if (arg == "-t") {
|
||||
dbfile = argv[i+1];
|
||||
++i;
|
||||
|
|
@ -69,14 +64,9 @@ int main(int argc, char** argv) {
|
|||
++i;
|
||||
}
|
||||
|
||||
#define MAKE_CT_INPUT
|
||||
#ifdef MAKE_CT_INPUT
|
||||
int ierr = pip::convert_ck(infile.c_str(), dbfile.c_str(), trfile.c_str(),
|
||||
idtag.c_str());
|
||||
#else
|
||||
int ierr = convert_ck(infile.c_str(), dbfile.c_str(), trfile.c_str(),
|
||||
outfile.c_str(), idtag.c_str());
|
||||
#endif
|
||||
|
||||
if (ierr < 0) {
|
||||
showErrors(cerr);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue