From 5b55f058dd71064de5c41748249cddda28114313 Mon Sep 17 00:00:00 2001 From: Harry Moffat Date: Sun, 19 Apr 2009 21:03:10 +0000 Subject: [PATCH] Finished the numpy port and cleanup of unneeded files in the directory --- Cantera/python/src/canteramodule.cpp | 143 ----- Cantera/python/src/ctflow.cpp | 612 ------------------ Cantera/python/src/ctflow_methods.cpp | 12 + Cantera/python/src/ctkinetics_methods.cpp | 5 + Cantera/python/src/ctmodule.cpp | 118 ---- Cantera/python/src/ctnumerics.cpp | 315 ---------- Cantera/python/src/ctphase.cpp | 417 ------------- Cantera/python/src/ctphase_methods.cpp | 11 + Cantera/python/src/ctpy.cpp | 85 --- Cantera/python/src/ctpybndry.cpp | 180 ------ Cantera/python/src/ctpyfunc.cpp | 108 ---- Cantera/python/src/ctpyreactor.cpp | 685 --------------------- Cantera/python/src/ctpyrpath.cpp | 359 ----------- Cantera/python/src/ctpysurf.cpp | 404 ------------ Cantera/python/src/ctpyxml.cpp | 283 --------- Cantera/python/src/ctsurf.cpp | 575 ----------------- Cantera/python/src/ctsurf_methods.cpp | 10 + Cantera/python/src/ctthermo.cpp | 294 --------- Cantera/python/src/ctthermo_methods.cpp | 7 + Cantera/python/src/cttransport.cpp | 171 ----- Cantera/python/src/cttransport_methods.cpp | 44 +- Cantera/python/src/ctxml_methods.cpp | 8 +- Cantera/python/src/reactionpath.cpp | 71 --- Cantera/python/src/writelog.cpp | 43 -- 24 files changed, 84 insertions(+), 4876 deletions(-) delete mode 100755 Cantera/python/src/canteramodule.cpp delete mode 100755 Cantera/python/src/ctflow.cpp delete mode 100755 Cantera/python/src/ctmodule.cpp delete mode 100755 Cantera/python/src/ctnumerics.cpp delete mode 100755 Cantera/python/src/ctphase.cpp delete mode 100755 Cantera/python/src/ctpy.cpp delete mode 100755 Cantera/python/src/ctpybndry.cpp delete mode 100644 Cantera/python/src/ctpyfunc.cpp delete mode 100755 Cantera/python/src/ctpyreactor.cpp delete mode 100755 Cantera/python/src/ctpyrpath.cpp delete mode 100755 Cantera/python/src/ctpysurf.cpp delete mode 100644 Cantera/python/src/ctpyxml.cpp delete mode 100755 Cantera/python/src/ctsurf.cpp delete mode 100755 Cantera/python/src/ctthermo.cpp delete mode 100755 Cantera/python/src/cttransport.cpp delete mode 100755 Cantera/python/src/reactionpath.cpp delete mode 100644 Cantera/python/src/writelog.cpp diff --git a/Cantera/python/src/canteramodule.cpp b/Cantera/python/src/canteramodule.cpp deleted file mode 100755 index 5427ac409..000000000 --- a/Cantera/python/src/canteramodule.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/** - * @file canteramodule.cpp - * Cantera Python Interface - * - */ - -// copyright 2001 David G. Goodwin - - -// turn off warnings about long names under Windows -#ifdef WIN32 -#pragma warning(disable:4786) -#pragma warning(disable:4503) -#endif - -#include "Python.h" -#include "Cantera.h" -#include -using namespace std; - -// constants defined in the module -static PyObject *ErrorObject; -static PyObject *OneAtmos; -static PyObject *GasCon; - - -local includes -#include "pyutils.h" -#include "CtSubstance.h" -#include "CtRxnPath.h" -#include "CtReactor.h" - - -/* Function of no arguments returning new CtSubstance object */ - -static PyObject * -ct_newSubstance(PyObject *self, PyObject *args) -{ - CtSubstance *rv=0; - char* subtype; - PyObject* params; - if (!PyArg_ParseTuple(args, "sO:newSubstance", &subtype, ¶ms)) - return NULL; - if (!PySequence_Check(params)) { - PyErr_SetString(ErrorObject, - "usage: Substance('', [])"); - return NULL; - } - string stype(subtype); - if (stype == "chemkin") { - rv = newChemkinSubstance(params); - } - if ( rv == NULL ) return NULL; - return (PyObject *)rv; -} - - -static PyObject * -ct_newRxnPath(PyObject *self, PyObject *args) -{ - CtRxnPath *rv; - if (!PyArg_ParseTuple(args, ":newCtRxnPath")) - return NULL; - rv = newCtRxnPath(); - if ( rv == NULL ) return NULL; - return (PyObject *)rv; -} - -static PyObject * -ct_newReactor(PyObject *self, PyObject *args) -{ - CtReactor *rv; - char* s; - if (!PyArg_ParseTuple(args, "s:newCtReactor", &s)) - return NULL; - rv = newCtReactor(s); - if ( rv == NULL ) return NULL; - return (PyObject *)rv; -} - - - -/* List of functions defined in the module */ - -static PyMethodDef ct_methods[] = { - {"Substance", ct_newSubstance, METH_VARARGS}, - {"ReactionPath", ct_newRxnPath, METH_VARARGS}, - {"Reactor", ct_newReactor, METH_VARARGS}, - {"ChemEquil", ct_newChemEquil, METH_VARARGS}, - //{"Integrator", ct_newIntegrator, METH_VARARGS}, - {NULL, NULL} /* sentinel */ -}; - - -extern "C" { - - /* Initialization function for the module (*must* be called initcantera) */ - - DL_EXPORT(void) - initct(void) - { - PyObject *m, *d; - - CtSubstance::init(); - CtRxnPath::init(); - CtReactor::init(); - - /* Initialize the type of the new type object here; doing it here - * is required for portability to Windows without requiring C++. */ - - CtSubstance_Type.ob_type = &PyType_Type; - CtSubstance_Type.tp_dealloc = (destructor)CtSubstance_dealloc; - CtSubstance_Type.tp_getattr = (getattrfunc)CtSubstance_getattr; - CtSubstance_Type.tp_setattr = (setattrfunc)CtSubstance_setattr; - CtSubstance_Type.tp_print = (printfunc)CtSubstance_print; - - CtRxnPath_Type.ob_type = &PyType_Type; - CtRxnPath_Type.tp_dealloc = (destructor)CtRxnPath_dealloc; - CtRxnPath_Type.tp_getattr = (getattrfunc)CtRxnPath_getattr; - CtRxnPath_Type.tp_setattr = (setattrfunc)CtRxnPath_setattr; - - CtReactor_Type.ob_type = &PyType_Type; - CtReactor_Type.tp_dealloc = (destructor)CtReactor_dealloc; - CtReactor_Type.tp_getattr = (getattrfunc)CtReactor_getattr; - CtReactor_Type.tp_setattr = (setattrfunc)CtReactor_setattr; - - /* Create the module and add the functions */ - m = Py_InitModule("cantera", ct_methods); - - /* Add some symbolic constants to the module */ - d = PyModule_GetDict(m); - ErrorObject = PyErr_NewException("cantera.error", NULL, NULL); - PyDict_SetItemString(d, "error", ErrorObject); - - // one atmosphere - OneAtmos = PyFloat_FromDouble(OneAtm); - PyDict_SetItemString(d, "OneAtm", OneAtmos); - - // gas constant - GasCon = PyFloat_FromDouble(GasConstant); - PyDict_SetItemString(d, "GasConstant", GasCon); - } -} diff --git a/Cantera/python/src/ctflow.cpp b/Cantera/python/src/ctflow.cpp deleted file mode 100755 index 582852aa4..000000000 --- a/Cantera/python/src/ctflow.cpp +++ /dev/null @@ -1,612 +0,0 @@ -/** - * @file ctkinetics.cpp - * - */ - -// turn off warnings about long names under Windows -#ifdef WIN32 -#pragma warning(disable:4786) -#pragma warning(disable:4503) -#endif - - -#include "Python.h" -#include "Numeric/arrayobject.h" - -#include "ct.h" -#include "ctstagn.h" -#include -#include -#include - -using namespace std; - -// constants defined in the module -static PyObject *ErrorObject; - -// local includes -#include "pyutils.h" - -static PyObject * -py_flow_new(PyObject *self, PyObject *args) -{ - int itype, iph, np; - if (!PyArg_ParseTuple(args, "iii:flow_new", - &itype, &iph, &np)) - return NULL; - int nn = flow_new(itype,iph,np); - if (nn < 0) return reportError(nn); - return Py_BuildValue("i",nn); -} - -static PyObject* -py_flow_delete(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:flow_delete", &n)) return NULL; - flow_del(n); - return Py_BuildValue("i",0); -} - -static PyObject* -py_flow_setupgrid(PyObject *self, PyObject *args) -{ - int n; - PyObject* grid; - if (!PyArg_ParseTuple(args, "iO:flow_setupgrid", &n, &grid)) - return NULL; - - //vector z; - //int iok = pyNumericSequence_ToVector(grid, z); - PyArrayObject* g = (PyArrayObject*)grid; - double* xd = (double*)g->data; - int glen = g->dimensions[0]; - int - // if (iok == -1) { - // PyErr_SetString(ErrorObject, "Third argument must be a sequence"); - // return NULL; - //} - //if (iok == -2) { - // PyErr_SetString(ErrorObject, - // "Sequence must contain only numeric values"); - // return NULL; - //} - - iok = flow_setupgrid(n, glen, xd); - if (iok == -1) return reportCanteraError(); - else if (iok < 0) return NULL; - return Py_BuildValue("i",0); -} - -static PyObject* -py_flow_setkinetics(PyObject *self, PyObject *args) -{ - int nn,k; - if (!PyArg_ParseTuple(args, "ii:flow_setkinetics", &nn, &k)) return NULL; - return Py_BuildValue("i",flow_setkinetics(nn,k)); -} - -static PyObject* -py_flow_settransport(PyObject *self, PyObject *args) -{ - int nn,k,soret; - if (!PyArg_ParseTuple(args, "iii:flow_settransport", - &nn, &k, &soret)) return NULL; - return Py_BuildValue("i",flow_settransport(nn,k,soret)); -} - -static PyObject* -py_flow_setthermo(PyObject *self, PyObject *args) -{ - int nn,k; - if (!PyArg_ParseTuple(args, "ii:flow_setthermo", &nn, &k)) return NULL; - return Py_BuildValue("i",flow_setthermo(nn,k)); -} - -static PyObject* -py_flow_setpressure(PyObject *self, PyObject *args) -{ - int nn; - double p; - if (!PyArg_ParseTuple(args, "id:flow_setpressure", &nn, &p)) - return NULL; - return Py_BuildValue("i",flow_setpressure(nn,p)); -} - -static PyObject* -py_flow_settemperature(PyObject *self, PyObject *args) -{ - int n, j; - double t; - if (!PyArg_ParseTuple(args, "iid:flow_settemperature", &n, &j, &t)) - return NULL; - return Py_BuildValue("i",flow_settemperature(n,j,t)); -} - -static PyObject* -py_flow_setenergyfactor(PyObject *self, PyObject *args) -{ - int n; - double e; - if (!PyArg_ParseTuple(args, "id:flow_setenergyfactor", &n, &e)) - return NULL; - return Py_BuildValue("i",flow_setenergyfactor(n,e)); -} - -static PyObject* -py_flow_setmassfraction(PyObject *self, PyObject *args) -{ - int n, j, k; - double y; - if (!PyArg_ParseTuple(args, "iiid:flow_setinlet_v", &n, &j, &k, &y)) - return NULL; - return Py_BuildValue("i",flow_setmassfraction(n,j,k,y)); -} - -static PyObject* -py_flow_showsolution(PyObject *self, PyObject *args) -{ - int n; - char* fname; - PyObject* soln; - if (!PyArg_ParseTuple(args, "isO:flow_showsolution", &n, &fname, &soln)) - return NULL; - double* x = (double*)((PyArrayObject*)soln)->data; - return Py_BuildValue("i",flow_showsolution(n,fname,x)); -} - -static PyObject* -py_flow_solvespecies(PyObject *self, PyObject *args) -{ - int n, slen; - PyObject* s; - if (!PyArg_ParseTuple(args, "iiO:flow_solvespecies", &n, &slen, &s)) - return NULL; - double* x = (double*)((PyArrayObject*)s)->data; - for (int i = 0; i < slen; i++) { - if (x[i] <= 0.0) - flow_fixspecies(n, i); - else - flow_solvespecies(n, i); - } - return Py_BuildValue("i",0); -} - -static PyObject* -py_copy(PyObject *self, PyObject *args) -{ - int n; - PyObject *s, *snew; - if (!PyArg_ParseTuple(args, "iOO:copy", &n, &s, &snew)) - return NULL; - double* x = (double*)((PyArrayObject*)s)->data; - double* xnew = (double*)((PyArrayObject*)snew)->data; - for (int i = 0; i < n; i++) xnew[i] = x[i]; - return Py_BuildValue("i",0); -} - - -static PyObject* -py_flow_settolerances(PyObject *self, PyObject *args) -{ - int n, nr, na; - PyObject *prtol, *patol; - if (!PyArg_ParseTuple(args, "iiOiO:flow_solve", &n, &nr, &prtol, - &na, &patol)) - return NULL; - double* rtol = (double*)((PyArrayObject*)prtol)->data; - double* atol = (double*)((PyArrayObject*)patol)->data; - int iok = flow_settolerances(n, nr, rtol, na, atol); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",iok); -} - -// static PyObject* -// py_flow_integratechem(PyObject *self, PyObject *args) -// { -// int n; -// PyObject *px; -// double dt; -// if (!PyArg_ParseTuple(args, "iOd:flow_solve", &n, &px, &dt)) -// return NULL; -// double* x = (double*)((PyArrayObject*)px)->data; -// int iok = flow_integratechem(n, x, dt); -// if (iok < 0) return reportError(iok); -// return Py_BuildValue("i",iok); -// } - -static PyObject* -py_flow_outputtec(PyObject *self, PyObject *args) -{ - int n; - PyObject *px; - char *fname, *title; - int zone; - if (!PyArg_ParseTuple(args, "iOssi:flow_outputtec", &n, &px, - &fname, &title, &zone)) - return NULL; - double* x = (double*)((PyArrayObject*)px)->data; - int iok = flow_outputtec(n, x, fname, title, zone); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",iok); -} - -static PyObject* -py_flow_resize(PyObject *self, PyObject *args) -{ - int n, points; - if (!PyArg_ParseTuple(args, "ii:flow_resize", &n, &points)) - return NULL; - int iok = flow_resize(n, points); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",iok); -} - -static PyObject* -py_flow_energy(PyObject *self, PyObject *args) -{ - int n, j, flag, iok; - if (!PyArg_ParseTuple(args, "iii:flow_energy", &n, &j, &flag)) - return NULL; - if (flag == 1) - iok = flow_solveenergyeqn(n, j); - else - iok = flow_fixtemperature(n, j); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",iok); -} - -static PyObject* -py_flow_setfixedpoint(PyObject *self, PyObject *args) -{ - int n, j0; - double t0; - if (!PyArg_ParseTuple(args, "iid:flow_setfixedpoint", &n, &j0, &t0)) - return NULL; - int iok = flow_setfixedpoint(n, j0, t0); - return Py_BuildValue("i",iok); -} - -// static PyObject* -// py_flow_eval(PyObject *self, PyObject *args) -// { -// int n, j; -// PyObject *px, *pr; -// if (!PyArg_ParseTuple(args, "iiOO:flow_eval", &n, &j, &px, &pr)) -// return NULL; -// double* x = (double*)((PyArrayObject*)px)->data; -// double* r = (double*)((PyArrayObject*)pr)->data; -// int iok = flow_eval(n, j, x, r); -// if (iok < 0) return reportError(iok); -// return Py_BuildValue("i",iok); -// } - -static PyObject* -py_flow_restore(PyObject *self, PyObject *args) -{ - int n, job, iz, isoln; - char *fname, *id; - PyArrayObject *pz, *psoln; - if (!PyArg_ParseTuple(args, "iiss:flow_restore", - &n, &job, &fname, &id)) - return NULL; - int iok; - double *z=0, *soln=0; - iok = flow_restore(n, -1, fname, id, iz, z, isoln, soln); - if (iok < 0) return reportError(iok); - if (job < 0) { - return Py_BuildValue("(ii)",iz,isoln); - } - pz = (PyArrayObject*)PyArray_FromDims(1, &iz, PyArray_DOUBLE); - int sdim[2]; - sdim[0] = iz; - sdim[1] = isoln/iz; - psoln = (PyArrayObject*)PyArray_FromDims(2, sdim, PyArray_DOUBLE); - z = (double*)((PyArrayObject*)pz)->data; - soln = (double*)((PyArrayObject*)psoln)->data; - iok = flow_restore(n, 0, fname, id, iz, z, isoln, soln); - if (iok < 0) return reportError(iok); - return Py_BuildValue("(OO)",pz,psoln); -} - -static PyObject* -py_flow_setboundaries(PyObject *self, PyObject *args) -{ - int n, nleft, nright; - if (!PyArg_ParseTuple(args, "iii:flow_setboundaries", &n, &nleft, - &nright)) - return NULL; - int iok = flow_setboundaries(n, nleft, nright); - return Py_BuildValue("i",iok); -} - - -/* flow boundary objects */ - - -static PyObject * -py_bdry_new(PyObject *self, PyObject *args) -{ - int itype, ip, kin; - if (!PyArg_ParseTuple(args, "iii:bdry_new", &itype, &ip, &kin)) - return NULL; - int nn = bdry_new(itype,ip,kin); - if (nn < 0) return reportError(nn); - return Py_BuildValue("i",nn); -} - -static PyObject* -py_bdry_delete(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:bdry_delete", &n)) return NULL; - bdry_del(n); - return Py_BuildValue("i",0); -} - -static PyObject* -py_bdry_set(PyObject *self, PyObject *args) -{ - int n, i; - double v; - PyObject* px; - double* x; - if (!PyArg_ParseTuple(args, "iidO:bdry_set", &n, &i, &v, &px)) - return NULL; - if (i < 4) - bdry_set(n, i, &v); - else { - x = (double*)((PyArrayObject*)px)->data; - bdry_set(n, i, x); - } - return Py_BuildValue("i",0); -} - -static PyObject * -py_onedim_new(PyObject *self, PyObject *args) -{ - int n; - PyObject *pydom, *pytype; - if (!PyArg_ParseTuple(args, "iOO:onedim_new", &n, &pydom, &pytype)) - return NULL; - int* dom = (int*)((PyArrayObject*)pydom)->data; - int* typ = (int*)((PyArrayObject*)pytype)->data; - int nn = onedim_new(n, dom, typ); - if (nn == -1) return reportCanteraError(); - return Py_BuildValue("i",nn); -} - -static PyObject* -py_onedim_delete(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:onedim_delete", &n)) return NULL; - onedim_del(n); - return Py_BuildValue("i",0); -} - -static PyObject* -py_onedim_solve(PyObject *self, PyObject *args) -{ - int n, loglevel; - PyObject *s, *snew; - if (!PyArg_ParseTuple(args, "iOOi:onedim_solve", &n, &s, &snew, &loglevel)) - return NULL; - double* x = (double*)((PyArrayObject*)s)->data; - double* xnew = (double*)((PyArrayObject*)snew)->data; - int iok = onedim_solve(n,x,xnew,loglevel); - if (iok == -1) return reportCanteraError(); - return Py_BuildValue("i",iok); -} - - -static PyObject* -py_onedim_ssnorm(PyObject *self, PyObject *args) -{ - int n; - PyObject *ps, *pr; - if (!PyArg_ParseTuple(args, "iOO:flow_solve", &n, &ps, &pr)) - return NULL; - double* x = (double*)((PyArrayObject*)ps)->data; - double* r = (double*)((PyArrayObject*)pr)->data; - double ss = onedim_ssnorm(n,x,r); - return Py_BuildValue("d",ss); -} - -static PyObject* -py_onedim_setnewtonoptions(PyObject *self, PyObject *args) -{ - int n, age; - if (!PyArg_ParseTuple(args, "ii:onedim_setnewtonoptions", &n, &age)) - return NULL; - int iok = onedim_setnewtonoptions(n, age); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",iok); -} - -static PyObject* -py_onedim_setsteadymode(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:onedim_setsteadymode", &n)) - return NULL; - int iok = onedim_setsteadymode(n); - return Py_BuildValue("i",iok); -} - -static PyObject* -py_onedim_settransientmode(PyObject *self, PyObject *args) -{ - int n; - double dt; - PyArrayObject* px; - if (!PyArg_ParseTuple(args, "idO:onedim_settransientmode", &n, &dt, &px)) - return NULL; - double* x = (double*)((PyArrayObject*)px)->data; - int iok = onedim_settransientmode(n, dt, x); - return Py_BuildValue("i",iok); -} - - -static PyObject* -py_onedim_eval(PyObject *self, PyObject *args) -{ - int n; - PyObject *px, *pr; - if (!PyArg_ParseTuple(args, "iOO:onedim_eval", &n, &px, &pr)) - return NULL; - double* x = (double*)((PyArrayObject*)px)->data; - double* r = (double*)((PyArrayObject*)pr)->data; - int iok = onedim_eval(n, x, r); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",iok); -} - -static PyObject* -py_onedim_addflow(PyObject *self, PyObject *args) -{ - int n, m; - if (!PyArg_ParseTuple(args, "ii:onedim_addflow", &n, &m)) - return NULL; - int iok = onedim_addFlow(n, m); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",iok); -} - -// static PyObject* -// py_onedim_addsurf(PyObject *self, PyObject *args) -// { -// int n, m; -// if (!PyArg_ParseTuple(args, "ii:onedim_addflow", &n, &m)) -// return NULL; -// int iok = onedim_addSurf(n, m); -// if (iok < 0) return reportError(iok); -// return Py_BuildValue("i",iok); -// } - - -static PyObject* -py_onedim_resize(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:onedim_resize", &n)) - return NULL; - int iok = onedim_resize(n); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",iok); -} - -static PyObject* -py_onedim_writestats(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:onedim_writeStats", &n)) - return NULL; - int iok = onedim_writeStats(n); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",iok); -} - -static PyObject* -py_onedim_timestep(PyObject *self, PyObject *args) -{ - int n, nsteps, loglevel; - double dt; - PyObject *px, *pr; - if (!PyArg_ParseTuple(args, "iidOOi:onedim_timestep", &n, &nsteps, - &dt, &px, &pr, &loglevel)) - return NULL; - double* x = (double*)((PyArrayObject*)px)->data; - double* r = (double*)((PyArrayObject*)pr)->data; - double newdt = onedim_timestep(n, nsteps, dt, x, r, loglevel); - if (newdt < 0.0) return reportError(-1); - return Py_BuildValue("d",newdt); -} - -static PyObject* -py_onedim_save(PyObject *self, PyObject *args) -{ - int n; - char *fname, *id, *desc; - PyArrayObject* px; - if (!PyArg_ParseTuple(args, "isssO:onedim_save", &n, &fname, &id, &desc, &px)) - return NULL; - double* x = (double*)((PyArrayObject*)px)->data; - int iok = onedim_save(n, fname, id, desc, x); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",iok); -} - - -/* List of functions defined in the module */ - -static PyMethodDef ct_methods[] = { - {"Flow", py_flow_new, METH_VARARGS}, - {"flow_delete", py_flow_delete, METH_VARARGS}, - {"flow_setupgrid", py_flow_setupgrid, METH_VARARGS}, - {"flow_setthermo", py_flow_setthermo, METH_VARARGS}, - {"flow_setkinetics", py_flow_setkinetics, METH_VARARGS}, - {"flow_settransport", py_flow_settransport, METH_VARARGS}, - {"flow_setpressure", py_flow_setpressure, METH_VARARGS}, - //{"flow_setinletstate", py_flow_setinletstate, METH_VARARGS}, - // {"flow_setinlet_u", py_flow_setinlet_u, METH_VARARGS}, - //{"flow_setinlet_v", py_flow_setinlet_v, METH_VARARGS}, - //{"flow_setsurface_t", py_flow_setsurface_t, METH_VARARGS}, - {"flow_solvespecies", py_flow_solvespecies, METH_VARARGS}, - {"flow_settemperature", py_flow_settemperature, METH_VARARGS}, - {"flow_setenergyfactor", py_flow_setenergyfactor, METH_VARARGS}, - {"flow_setmassfraction", py_flow_setmassfraction, METH_VARARGS}, - {"flow_settolerances", py_flow_settolerances, METH_VARARGS}, - {"flow_energy", py_flow_energy, METH_VARARGS}, - {"flow_showsolution", py_flow_showsolution, METH_VARARGS}, - // {"flow_integratechem", py_flow_integratechem, METH_VARARGS}, - {"flow_resize", py_flow_resize, METH_VARARGS}, - {"flow_outputtec", py_flow_outputtec, METH_VARARGS}, - // {"flow_eval", py_flow_eval, METH_VARARGS}, - {"flow_restore", py_flow_restore, METH_VARARGS}, - {"flow_setfixedpoint", py_flow_setfixedpoint, METH_VARARGS}, - {"flow_setboundaries", py_flow_setboundaries, METH_VARARGS}, - {"copy", py_copy, METH_VARARGS}, - {"bdry_new", py_bdry_new, METH_VARARGS}, - {"bdry_del", py_bdry_delete, METH_VARARGS}, - {"bdry_set", py_bdry_set, METH_VARARGS}, - {"onedim_solve", py_onedim_solve, METH_VARARGS}, - {"onedim_new", py_onedim_new, METH_VARARGS}, - {"onedim_del", py_onedim_delete, METH_VARARGS}, - {"onedim_setnewtonoptions", py_onedim_setnewtonoptions, METH_VARARGS}, - {"onedim_ssnorm", py_onedim_ssnorm, METH_VARARGS}, - {"onedim_setsteadymode", py_onedim_setsteadymode, METH_VARARGS}, - {"onedim_settransientmode", py_onedim_settransientmode, METH_VARARGS}, - {"onedim_eval", py_onedim_eval, METH_VARARGS}, - {"onedim_addflow", py_onedim_addflow, METH_VARARGS}, - //{"onedim_addsurf", py_onedim_addsurf, METH_VARARGS}, - {"onedim_resize", py_onedim_resize, METH_VARARGS}, - {"onedim_writestats", py_onedim_writestats, METH_VARARGS}, - {"onedim_timestep", py_onedim_timestep, METH_VARARGS}, - {"onedim_save", py_onedim_save, METH_VARARGS}, - {NULL, NULL} /* sentinel */ -}; - - -extern "C" { - - /* Initialization function for the module (*must* be called initctflow) */ - - DL_EXPORT(void) initctflow(void) - { - PyObject *m, *d; - - /* Initialize the type of the new type object here; doing it here - * is required for portability to Windows without requiring C++. */ - - /* Create the module and add the functions */ - m = Py_InitModule("ctflow", ct_methods); - import_array(); - - /* Add some symbolic constants to the module */ - d = PyModule_GetDict(m); - ErrorObject = PyErr_NewException("cantera.error", NULL, NULL); - PyDict_SetItemString(d, "error", ErrorObject); - } - -} diff --git a/Cantera/python/src/ctflow_methods.cpp b/Cantera/python/src/ctflow_methods.cpp index 973ca25da..68b91aec8 100644 --- a/Cantera/python/src/ctflow_methods.cpp +++ b/Cantera/python/src/ctflow_methods.cpp @@ -229,11 +229,23 @@ py_flow_restore(PyObject *self, PyObject *args) if (job < 0) { return Py_BuildValue("(ii)",iz,isoln); } +#ifdef HAS_NUMPY + npy_intp niz = iz; + pz = (PyArrayObject*)PyArray_SimpleNew(1, &niz, PyArray_DOUBLE); +#else pz = (PyArrayObject*)PyArray_FromDims(1, &iz, PyArray_DOUBLE); +#endif +#ifdef HAS_NUMPY + npy_intp sdim[2]; + sdim[0] = iz; + sdim[1] = isoln/iz; + psoln = (PyArrayObject*)PyArray_SimpleNew(2, sdim, PyArray_DOUBLE); +#else int sdim[2]; sdim[0] = iz; sdim[1] = isoln/iz; psoln = (PyArrayObject*)PyArray_FromDims(2, sdim, PyArray_DOUBLE); +#endif z = (double*)((PyArrayObject*)pz)->data; soln = (double*)((PyArrayObject*)psoln)->data; iok = flow_restore(n, 0, fname, id, iz, z, isoln, soln); diff --git a/Cantera/python/src/ctkinetics_methods.cpp b/Cantera/python/src/ctkinetics_methods.cpp index 77889cd83..a9309a4b0 100644 --- a/Cantera/python/src/ctkinetics_methods.cpp +++ b/Cantera/python/src/ctkinetics_methods.cpp @@ -168,8 +168,13 @@ kin_getarray(PyObject *self, PyObject *args) int ix; if (job < 45 || job >= 90) ix = nrxns; else ix = nsp; +#ifdef HAS_NUMPY + npy_intp nix = ix; + PyArrayObject* x = (PyArrayObject*)PyArray_SimpleNew(1, &nix, PyArray_DOUBLE); +#else PyArrayObject* x = (PyArrayObject*)PyArray_FromDims(1, &ix, PyArray_DOUBLE); +#endif double* xd = (double*)x->data; switch (job) { diff --git a/Cantera/python/src/ctmodule.cpp b/Cantera/python/src/ctmodule.cpp deleted file mode 100755 index 258616751..000000000 --- a/Cantera/python/src/ctmodule.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/** - * @file ctmodule.cpp - * Cantera Python Interface - * - */ - - -// turn off warnings about long names under Windows -#ifdef WIN32 -#pragma warning(disable:4786) -#pragma warning(disable:4503) -#endif - -// #define USE_DL_EXPORT - -#include "Python.h" -#include "ct.h" - -// constants defined in the module -static PyObject *ErrorObject; - -#include -#include -using namespace std; - -// local includes -#include "pyutils.h" - -static PyObject * -ct_buildSolutionFromXML(PyObject *self, PyObject *args) -{ - int ixml, ith, ikin; - char *src=0, *id=0; - if (!PyArg_ParseTuple(args, "sisii:buildSolutionFromXML", &src, &ixml, - &id, &ith, &ikin)) - return NULL; - int ok = buildSolutionFromXML(src, ixml, id, ith, ikin); - if (ok == -1) { return reportCanteraError();} - return Py_BuildValue("i",ok); -} - -static PyObject * -ct_get_cantera_error(PyObject *self, PyObject *args) -{ - char* buf = new char[400]; - getCanteraError(400, buf); - PyObject* msg = Py_BuildValue("s",buf); - delete buf; - return msg; -} - -static PyObject * -ct_print(PyObject *self, PyObject *args) -{ - char* msg; - if (!PyArg_ParseTuple(args, "s:print", &msg)) - return NULL; - printf(msg); - return Py_BuildValue("i",0); -} - -static PyObject * -ct_readlog(PyObject *self, PyObject *args) -{ - char* msg = 0; - int n = readlog(-1, msg); - if (n > 0) { - msg = new char[n+1]; - int ok = readlog(n, msg); - PyObject* r = Py_BuildValue("s",msg); - return r; - } - else - return Py_BuildValue("s",""); -} - -static PyObject * -ct_ck2ctml(PyObject *self, PyObject *args) -{ - int iok; - char *infile, *thermo, *tran, *outfile, *idtag; - if (!PyArg_ParseTuple(args, "sssss:ck2ctml", &infile, - &thermo, &tran, &outfile, &idtag)) - return NULL; - iok = ck_to_ctml(infile, thermo, tran, outfile, idtag); - if (iok == -1) { return reportCanteraError();} - return Py_BuildValue("i",iok); -} - -/* List of functions defined in the module */ - -static PyMethodDef ct_methods[] = { - {"get_Cantera_Error", ct_get_cantera_error, METH_VARARGS}, - {"ct_print", ct_print, METH_VARARGS}, - {"readlog", ct_readlog, METH_VARARGS}, - {"ck2ctml", ct_ck2ctml, METH_VARARGS}, - {"buildSolutionFromXML", ct_buildSolutionFromXML, METH_VARARGS}, - {NULL, NULL} /* sentinel */ -}; - - -extern "C" { - - /* Initialization function for the module (*must* be called initctmodule) */ - - DL_EXPORT(void) initctmodule(void) - { - PyObject *m, *d; - - /* Create the module and add the functions */ - m = Py_InitModule("ctmodule", ct_methods); - - /* Add some symbolic constants to the module */ - d = PyModule_GetDict(m); - ErrorObject = PyErr_NewException("cantera.error", NULL, NULL); - PyDict_SetItemString(d, "error", ErrorObject); - } -} diff --git a/Cantera/python/src/ctnumerics.cpp b/Cantera/python/src/ctnumerics.cpp deleted file mode 100755 index 94a7ff304..000000000 --- a/Cantera/python/src/ctnumerics.cpp +++ /dev/null @@ -1,315 +0,0 @@ -/** - * @file ctkinetics.cpp - * - */ - -// turn off warnings about long names under Windows -#ifdef WIN32 -#pragma warning(disable:4786) -#pragma warning(disable:4503) -#endif - - -#include "Python.h" -#include "ct.h" -#include "ctnum.h" -#include -#include -#include -using namespace std; - - -// constants defined in the module -static PyObject *ErrorObject; - -// local includes -#include "pyutils.h" - -static PyObject * -py_new_matrix(PyObject *self, PyObject *args) -{ - int n, m; - if (!PyArg_ParseTuple(args, "ii:ct_newMatrix", &n, &m)) - return NULL; - int nn = newMatrix(n,m); - if (nn < 0) return reportCanteraError(); - return Py_BuildValue("i",nn); -} - -static PyObject* -py_matrix_delete(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:matrix_delete", &n)) return NULL; - delMatrix(n); - return Py_BuildValue("i",0); -} - -static PyObject* -py_matrix_newcopy(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:matrix_newcopy", &n)) return NULL; - return Py_BuildValue("i",matrix_copy(n)); -} - -static PyObject* -py_matrix_assign(PyObject *self, PyObject *args) -{ - int n, m; - if (!PyArg_ParseTuple(args, "ii:matrix_assign", &n, &m)) return NULL; - return Py_BuildValue("i",matrix_assign(n, m)); -} - -static PyObject* -py_matrix_nrows(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:matrix_nrows", &n)) return NULL; - return Py_BuildValue("i",matrix_nRows(n)); -} - -static PyObject* -py_matrix_ncols(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:matrix_ncols", &n)) return NULL; - return Py_BuildValue("i",matrix_nColumns(n)); -} - -static PyObject* -py_matrix_value(PyObject *self, PyObject *args) -{ - int nn,m,n; - if (!PyArg_ParseTuple(args, "iii:matrix_value", &nn, &m, &n)) return NULL; - return Py_BuildValue("d",matrix_value(nn,m,n)); -} - -static PyObject* -py_matrix_setvalue(PyObject *self, PyObject *args) -{ - int nn,m,n; - double v; - if (!PyArg_ParseTuple(args, "iiid:matrix_setvalue", &nn, &m, &n, &v)) return NULL; - return Py_BuildValue("d",matrix_setvalue(nn,m,n,v)); -} - -static PyObject* -py_matrix_solve(PyObject *self, PyObject *args) -{ - int na, nb; - if (!PyArg_ParseTuple(args, "ii:matrix_solve", &na, &nb)) return NULL; - int i = matrix_solve(na, nb); - if (i == -1) return reportCanteraError(); - return Py_BuildValue("i",i); -} - -static PyObject* -py_matrix_mult(PyObject *self, PyObject *args) -{ - int na, nb, np; - if (!PyArg_ParseTuple(args, "iii:matrix_mult", &na, &nb, &np)) return NULL; - int i = matrix_multiply(na, nb, np); - if (i == -1) return reportCanteraError(); - return Py_BuildValue("i",i); -} - -static PyObject* -py_matrix_invert(PyObject *self, PyObject *args) -{ - int na; - if (!PyArg_ParseTuple(args, "i:matrix_invert", &na)) return NULL; - int i = matrix_invert(na); - if (i == -1) return reportCanteraError(); - return Py_BuildValue("i",i); -} - - -static PyObject * -py_bandmatrix_new(PyObject *self, PyObject *args) -{ - int n, kl, ku; - if (!PyArg_ParseTuple(args, "iii:bandmatrix_new", &n, &kl, &ku)) - return NULL; - int nn = bmatrix_new(n,kl,ku); - if (nn < 0) return reportCanteraError(); - return Py_BuildValue("i",nn); -} - -static PyObject* -py_bandmatrix_delete(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:bandmatrix_delete", &n)) return NULL; - bmatrix_del(n); - return Py_BuildValue("i",0); -} - -static PyObject* -py_bandmatrix_newcopy(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:bandmatrix_newcopy", &n)) return NULL; - return Py_BuildValue("i",bmatrix_copy(n)); -} - -static PyObject* -py_bandmatrix_assign(PyObject *self, PyObject *args) -{ - int n, m; - if (!PyArg_ParseTuple(args, "ii:bandmatrix_assign", &n, &m)) return NULL; - return Py_BuildValue("i",bmatrix_assign(n, m)); -} - -static PyObject* -py_bandmatrix_nrows(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:bandmatrix_nrows", &n)) return NULL; - return Py_BuildValue("i",bmatrix_nRows(n)); -} - -static PyObject* -py_bandmatrix_ncols(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:bandmatrix_ncols", &n)) return NULL; - return Py_BuildValue("i",bmatrix_nColumns(n)); -} - -static PyObject* -py_bandmatrix_value(PyObject *self, PyObject *args) -{ - int nn,m,n; - if (!PyArg_ParseTuple(args, "iii:bandmatrix_value", &nn, &m, &n)) return NULL; - return Py_BuildValue("d",bmatrix_value(nn,m,n)); -} - -static PyObject* -py_bandmatrix_setvalue(PyObject *self, PyObject *args) -{ - int nn,m,n; - double v; - if (!PyArg_ParseTuple(args, "iiid:bandmatrix_setvalue", &nn, &m, &n, &v)) - return NULL; - return Py_BuildValue("d",bmatrix_setvalue(nn,m,n,v)); -} - -static PyObject* -py_bandmatrix_solve(PyObject *self, PyObject *args) -{ - int na, nb; - if (!PyArg_ParseTuple(args, "ii:bandmatrix_solve", &na, &nb)) - - return NULL; - int i = bmatrix_solve(na, nb); - if (i == -1) return reportCanteraError(); - return Py_BuildValue("i",i); -} - -static PyObject* -py_bandmatrix_mult(PyObject *self, PyObject *args) -{ - int na, nb, np; - if (!PyArg_ParseTuple(args, "iii:bandmatrix_mult", &na, &nb, &np)) - return NULL; - int i = bmatrix_multiply(na, nb, np); - if (i == -1) return reportCanteraError(); - return Py_BuildValue("i",i); -} - - -// static PyObject* -// num_getarray(PyObject *self, PyObject *args) -// { -// int n; -// int job; - -// if (!PyArg_ParseTuple(args, "ii:num_getarray", &n, &job)) -// return NULL; - -// // array attributes -// int iok = -22; -// int nrxns = kin_nReactions(kin); -// int nsp = phase_nSpecies(kin); -// vector x; -// switch (job) { -// case 1: -// x.resize(nrxns); -// iok = kin_getFwdRatesOfProgress(kin, nrxns, x.begin()); -// break; -// case 2: -// x.resize(nrxns); -// iok = kin_getRevRatesOfProgress(kin, nrxns, x.begin()); -// break; -// case 3: -// x.resize(nrxns); -// iok = kin_getEquilibriumConstants(kin, nrxns, x.begin()); -// break; -// default: -// ; -// } -// if (iok >= 0) { -// return pyNumericTuple_FromVector(x); -// } -// else if (iok == -1) { -// return reportCanteraError(); -// } -// else { -// PyErr_SetString(ErrorObject,"Unknown array attribute"); -// return NULL; -// } -// } - - -/* List of functions defined in the module */ - -static PyMethodDef ct_methods[] = { - {"Matrix", py_new_matrix, METH_VARARGS}, - {"matrix_delete", py_matrix_delete, METH_VARARGS}, - {"matrix_newcopy", py_matrix_newcopy, METH_VARARGS}, - {"matrix_assign", py_matrix_assign, METH_VARARGS}, - {"matrix_nrows", py_matrix_nrows, METH_VARARGS}, - {"matrix_ncols", py_matrix_ncols, METH_VARARGS}, - {"matrix_value", py_matrix_value, METH_VARARGS}, - {"matrix_setvalue", py_matrix_setvalue, METH_VARARGS}, - {"matrix_solve", py_matrix_solve, METH_VARARGS}, - {"matrix_mult", py_matrix_mult, METH_VARARGS}, - {"matrix_invert", py_matrix_invert, METH_VARARGS}, - {"BandMatrix", py_bandmatrix_new, METH_VARARGS}, - {"bandmatrix_delete", py_bandmatrix_delete, METH_VARARGS}, - {"bandmatrix_newcopy", py_bandmatrix_newcopy, METH_VARARGS}, - {"bandmatrix_assign", py_bandmatrix_assign, METH_VARARGS}, - {"bandmatrix_nrows", py_bandmatrix_nrows, METH_VARARGS}, - {"bandmatrix_ncols", py_bandmatrix_ncols, METH_VARARGS}, - {"bandmatrix_value", py_bandmatrix_value, METH_VARARGS}, - {"bandmatrix_setvalue", py_bandmatrix_setvalue, METH_VARARGS}, - {"bandmatrix_solve", py_bandmatrix_solve, METH_VARARGS}, - {"bandmatrix_mult", py_bandmatrix_mult, METH_VARARGS}, - //{"setfp", thermo_setfp, METH_VARARGS}, - //{"equil", thermo_equil, METH_VARARGS}, - {NULL, NULL} /* sentinel */ -}; - - -extern "C" { - - /* Initialization function for the module (*must* be called initctnumerics) */ - - DL_EXPORT(void) initctnumerics(void) - { - PyObject *m, *d; - - /* Initialize the type of the new type object here; doing it here - * is required for portability to Windows without requiring C++. */ - - /* Create the module and add the functions */ - m = Py_InitModule("ctnumerics", ct_methods); - - /* Add some symbolic constants to the module */ - d = PyModule_GetDict(m); - ErrorObject = PyErr_NewException("cantera.error", NULL, NULL); - PyDict_SetItemString(d, "error", ErrorObject); - } - -} diff --git a/Cantera/python/src/ctphase.cpp b/Cantera/python/src/ctphase.cpp deleted file mode 100755 index d36645d0e..000000000 --- a/Cantera/python/src/ctphase.cpp +++ /dev/null @@ -1,417 +0,0 @@ -/** - * @file ctphase.cpp - * Cantera Python Interface - * - */ - -// turn off warnings about long names under Windows -#ifdef WIN32 -#pragma warning(disable:4786) -#pragma warning(disable:4503) -#endif - -#include "Python.h" -#include "Numeric/arrayobject.h" -#include "ct.h" -#include -//#include -#include -using namespace std; - -//#include "Cantera.h" - -// constants defined in the module -static PyObject *ErrorObject; -static PyObject *OneAtmos; -static PyObject *GasCon; - -// local includes -#include "pyutils.h" - - - -// /** -// * Create a new Phase object. -// */ -// static PyObject * -// ct_newPhase(PyObject *self, PyObject *args) { -// int n = newPhase(); -// return Py_BuildValue("i",n); -// } - - -// /** -// * Delete the Phase object. -// */ -// static PyObject* -// phase_delete(PyObject *self, PyObject *args) -// { -// int ph; -// if (!PyArg_ParseTuple(args, "i:phase_delete", &ph)) -// return NULL; -// delPhase(ph); -// return Py_BuildValue("i",0); -// } - - -static PyObject* -py_temperature(PyObject *self, PyObject *args) { - int ph; - if (!PyArg_ParseTuple(args, "i:py_temperature", &ph)) return NULL; - return Py_BuildValue("d",phase_temperature(ph)); -} - -static PyObject* -py_density(PyObject *self, PyObject *args) { - int ph; - if (!PyArg_ParseTuple(args, "i:py_density", &ph)) return NULL; - return Py_BuildValue("d",phase_density(ph)); -} - -static PyObject* -py_molardensity(PyObject *self, PyObject *args) { - int ph; - if (!PyArg_ParseTuple(args, "i:py_molardensity", &ph)) return NULL; - return Py_BuildValue("d",phase_molarDensity(ph)); -} - -static PyObject* -py_meanmolwt(PyObject *self, PyObject *args) { - int ph; - if (!PyArg_ParseTuple(args, "i:py_meanmolwt", &ph)) return NULL; - return Py_BuildValue("d",phase_meanMolecularWeight(ph)); -} - -static PyObject* -py_molefraction(PyObject *self, PyObject *args) { - int ph, k; - if (!PyArg_ParseTuple(args, "ii:py_molefraction", &ph, &k)) return NULL; - return Py_BuildValue("d",phase_moleFraction(ph, k)); -} - -static PyObject* -py_massfraction(PyObject *self, PyObject *args) { - int ph, k; - if (!PyArg_ParseTuple(args, "ii:py_massfraction", &ph, &k)) return NULL; - return Py_BuildValue("d",phase_massFraction(ph, k)); -} - -static PyObject* -py_nelements(PyObject *self, PyObject *args) { - int ph; - if (!PyArg_ParseTuple(args, "i:py_nelements", &ph)) return NULL; - return Py_BuildValue("i",phase_nElements(ph)); -} - -static PyObject* -py_nspecies(PyObject *self, PyObject *args) { - int ph; - if (!PyArg_ParseTuple(args, "i:py_nspecies", &ph)) return NULL; - return Py_BuildValue("i",phase_nSpecies(ph)); -} - -static PyObject* -py_natoms(PyObject *self, PyObject *args) { - int ph, k, m; - if (!PyArg_ParseTuple(args, "iii:py_natoms", &ph, &k, &m)) return NULL; - return Py_BuildValue("d",phase_nAtoms(ph, k, m)); -} - -static PyObject* -py_addelement(PyObject *self, PyObject *args) { - int ph; - char* name; - double wt; - if (!PyArg_ParseTuple(args, "isd:py_addelement", &ph, &name, &wt)) - return NULL; - int ok = phase_addElement(ph, name, wt); - if (ok < 0) return reportError(ok); - else return Py_BuildValue("i",0); -} - -static PyObject* -py_elementindex(PyObject *self, PyObject *args) { - int ph; - char* nm; - if (!PyArg_ParseTuple(args, "is:py_elementindex", &ph, &nm)) return NULL; - int k = phase_elementIndex(ph,nm); - if (k >= 0) - return Py_BuildValue("i",k); - else { - PyErr_SetString(ErrorObject,( - "Unknown element ("+string(nm)+")").c_str()); - return NULL; - } -} - -static PyObject* -py_speciesindex(PyObject *self, PyObject *args) { - int ph; - char* nm; - if (!PyArg_ParseTuple(args, "is:py_speciesindex", &ph, &nm)) return NULL; - int k = phase_speciesIndex(ph,nm); - if (k >= 0) - return Py_BuildValue("i",k); - else { - PyErr_SetString(ErrorObject,( - "Unknown species ("+string(nm)+")").c_str()); - return NULL; - } -} - -static PyObject* -py_report(PyObject *self, PyObject *args) { - int th, show_thermo; - int buflen = 400; - char* output_buf = new char[buflen]; - if (!PyArg_ParseTuple(args, "ii:py_report", &th, &show_thermo)) - return NULL; - int iok = phase_report(th, buflen, output_buf, show_thermo); - if (iok < -1 && iok != -999) { - delete output_buf; - output_buf = new char[-iok]; - iok = phase_report(th, -iok, output_buf, show_thermo); - } - if (iok < 0) return reportError(iok); - PyObject* s = Py_BuildValue("s",output_buf); - delete output_buf; - return s; -} - - -static PyObject* -phase_getarray(PyObject *self, PyObject *args) -{ - int ph; - int job; - - if (!PyArg_ParseTuple(args, "ii:phase_getarray", &ph, &job)) - return NULL; - - // array attributes - int iok = -22; - PyArrayObject* x = 0; - double* xd = 0; - if (job > 10) { - - int nsp = phase_nSpecies(ph); - x = (PyArrayObject*)PyArray_FromDims(1, &nsp, PyArray_DOUBLE); - xd = (double*)x->data; - switch (job) { - case 20: - iok = phase_getMoleFractions(ph,nsp,xd); - break; - case 21: - iok = phase_getMassFractions(ph,nsp,xd); - break; - case 22: - iok = phase_getMolecularWeights(ph,nsp,xd); - break; - default: - ; - } - } - else { - - int nel = phase_nElements(ph); - x = (PyArrayObject*)PyArray_FromDims(1, &nel, PyArray_DOUBLE); - xd = (double*)x->data; - switch (job) { - case 1: - iok = phase_getAtomicWeights(ph,nel,xd); - break; - default: - ; - } - } - - if (iok >= 0) { - return PyArray_Return(x); - } - else { - PyErr_SetString(ErrorObject,"Unknown array attribute"); - return NULL; - } -} - -// string attributes -static PyObject* -phase_getstring(PyObject *self, PyObject *args) -{ - int ph, job, iok = -1; - int k; - int buflen; - char* output_buf = 0; - if (!PyArg_ParseTuple(args, "iii:phase_getstring", &ph, &job, &k)) - return NULL; - switch (job) { - case 1: - buflen = 20; - output_buf = new char[buflen]; - iok = phase_getElementName(ph, k, buflen, output_buf); - break; - case 2: - buflen = 40; - output_buf = new char[buflen]; - iok = phase_getSpeciesName(ph, k, buflen, output_buf); - break; - default: - iok = -10; - } - if (iok >= 0) { - PyObject* str = Py_BuildValue("s",output_buf); - delete output_buf; - return str; - } - delete output_buf; - if (iok == -1) - return reportCanteraError(); - else { - PyErr_SetString(ErrorObject,"Unknown string attribute"); - return NULL; - } -} - -static PyObject* -phase_setfp(PyObject *self, PyObject *args) -{ - double vv; - int iok = -2; - int ph; - int job; - - if (!PyArg_ParseTuple(args, "iid:phase_getfp", &ph, &job, &vv)) - return NULL; - - // set floating-point attributes - switch (job) { - case 1: - iok = phase_setTemperature(ph, vv); break; - case 2: - iok = phase_setDensity(ph, vv); break; - default: - iok = -10; - } - if (iok >= 0) - return Py_BuildValue("i",iok); - else { - PyErr_SetString(ErrorObject,"Unknown floating-point attribute"); - return NULL; - } -} - - -static PyObject* -phase_setarray(PyObject *self, PyObject *args) -{ - int ph; - int job; - int norm; - int iok; - PyObject* seq; - if (!PyArg_ParseTuple(args, "iiiO:phase_setarray", &ph, &job, &norm, &seq)) - return NULL; - //vector_fp v; - PyArrayObject* a = (PyArrayObject*)seq; - //iok = pyNumericSequence_ToVector(seq, v); - double* xd = (double*)a->data; - int len = a->dimensions[0]; - //if (iok == -1) { - // PyErr_SetString(ErrorObject, "Fourth argument must be a sequence"); - // return NULL; - //} - switch (job) { - case 1: - iok = phase_setMoleFractions(ph, len, xd, norm); - break; - case 2: - iok = phase_setMassFractions(ph, len, xd, norm); - break; - default: - iok = -10; - } - if (iok >= 0) - return Py_BuildValue("i",iok); - if (iok == -1) - return reportCanteraError(); - else { - PyErr_SetString(ErrorObject, "Error in phase_setarray"); - return NULL; - } -} - -static PyObject* -phase_setstring(PyObject *self, PyObject *args) -{ - int ph; - int job; - int iok; - char* str; - if (!PyArg_ParseTuple(args, "iis:phase_setstring", &ph, &job, &str)) - return NULL; - switch (job) { - case 1: - iok = phase_setMoleFractionsByName(ph, str); - break; - case 2: - iok = phase_setMassFractionsByName(ph, str); - break; - default: - iok = -10; - } - if (iok >= 0) - return Py_BuildValue("i",iok); - if (iok == -1) - return reportCanteraError(); - else { - PyErr_SetString(ErrorObject, "Error in phase_setstring"); - return NULL; - } -} - -/* List of functions defined in the module */ - -static PyMethodDef ct_methods[] = { - {"temperature", py_temperature, METH_VARARGS}, - {"density", py_density, METH_VARARGS}, - {"molardensity", py_molardensity, METH_VARARGS}, - {"meanmolwt", py_meanmolwt, METH_VARARGS}, - {"molefraction", py_molefraction, METH_VARARGS}, - {"massfraction", py_massfraction, METH_VARARGS}, - {"nelements", py_nelements, METH_VARARGS}, - {"nspecies", py_nspecies, METH_VARARGS}, - {"natoms", py_natoms, METH_VARARGS}, - {"addelement", py_addelement, METH_VARARGS}, - {"elementindex", py_elementindex, METH_VARARGS}, - {"speciesindex", py_speciesindex, METH_VARARGS}, - {"getarray", phase_getarray, METH_VARARGS}, - {"getstring", phase_getstring, METH_VARARGS}, - {"setfp", phase_setfp, METH_VARARGS}, - {"setarray", phase_setarray, METH_VARARGS}, - {"setstring", phase_setstring, METH_VARARGS}, - {"report", py_report, METH_VARARGS}, - {NULL, NULL} /* sentinel */ -}; - - -extern "C" { - - /* Initialization function for the module (*must* be called initctphase) */ - - DL_EXPORT(void) initctphase(void) - { - PyObject *m, *d; - - /* Initialize the type of the new type object here; doing it here - * is required for portability to Windows without requiring C++. */ - - /* Create the module and add the functions */ - m = Py_InitModule("ctphase", ct_methods); - import_array(); - - /* Add some symbolic constants to the module */ - d = PyModule_GetDict(m); - ErrorObject = PyErr_NewException("cantera.error", NULL, NULL); - PyDict_SetItemString(d, "error", ErrorObject); - } -} diff --git a/Cantera/python/src/ctphase_methods.cpp b/Cantera/python/src/ctphase_methods.cpp index 666ca8a56..fea2dcef2 100644 --- a/Cantera/python/src/ctphase_methods.cpp +++ b/Cantera/python/src/ctphase_methods.cpp @@ -128,7 +128,13 @@ phase_getarray(PyObject *self, PyObject *args) if (job > 10) { int nsp = phase_nSpecies(ph); +#ifdef HAS_NUMPY + npy_intp nnn = nsp; + x = (PyArrayObject*)PyArray_SimpleNew(1, &nnn, PyArray_DOUBLE); + Py_INCREF(x); +#else x = (PyArrayObject*)PyArray_FromDims(1, &nsp, PyArray_DOUBLE); +#endif xd = (double*)x->data; switch (job) { case 20: @@ -147,7 +153,12 @@ phase_getarray(PyObject *self, PyObject *args) else { int nel = phase_nElements(ph); +#ifdef HAS_NUMPY + npy_intp nnn = nel; + x = (PyArrayObject*)PyArray_SimpleNew(1, &nnn, PyArray_DOUBLE); +#else x = (PyArrayObject*)PyArray_FromDims(1, &nel, PyArray_DOUBLE); +#endif xd = (double*)x->data; switch (job) { case 1: diff --git a/Cantera/python/src/ctpy.cpp b/Cantera/python/src/ctpy.cpp deleted file mode 100755 index 8e86d4045..000000000 --- a/Cantera/python/src/ctpy.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/** - * @file ctpy.cpp - * Cantera Python Interface - * - */ - -// turn off warnings about long names under Windows -#ifdef WIN32 -#pragma warning(disable:4786) -#pragma warning(disable:4503) -#endif - -#include "Python.h" -#include "ct.h" -#include -using namespace std; - -// constants defined in the module -static PyObject *ErrorObject; -static PyObject *OneAtmos; -static PyObject *GasCon; - -// local includes -#include "pyutils.h" - - -static reportCanteraError() { - PyErr_SetString(ErrorObject, - Cantera::Application::errorMessage.back().c_str()); - return NULL; -} - - -static PyObject * -ct_newPhase(PyObject *self, PyObject *args) -{ - CtPhase *rv=0; - int job; - if (!PyArg_ParseTuple(args, "i:ct_newPhase", &job)) - return NULL; - int n = newPhase(job); - if (n < 0) { - PyErr_SetString(ErrorObject,"Unknown species thermo manager"); - return NULL; - } - return Py_BuildValue("i",n); -} - - -/* List of functions defined in the module */ - -static PyMethodDef ct_methods[] = { - {"Phase", ct_newPhase, METH_VARARGS}, - {NULL, NULL} /* sentinel */ -}; - - -extern "C" { - - /* Initialization function for the module (*must* be called initct) */ - - DL_EXPORT(void) initct(void) - { - PyObject *m, *d; - - /* Initialize the type of the new type object here; doing it here - * is required for portability to Windows without requiring C++. */ - - /* Create the module and add the functions */ - m = Py_InitModule("ct", ct_methods); - - /* Add some symbolic constants to the module */ - d = PyModule_GetDict(m); - ErrorObject = PyErr_NewException("cantera.error", NULL, NULL); - PyDict_SetItemString(d, "error", ErrorObject); - - // one atmosphere - OneAtmos = PyFloat_FromDouble(OneAtm); - PyDict_SetItemString(d, "OneAtm", OneAtmos); - - // gas constant - GasCon = PyFloat_FromDouble(GasConstant); - PyDict_SetItemString(d, "GasConstant", GasCon); - } -} diff --git a/Cantera/python/src/ctpybndry.cpp b/Cantera/python/src/ctpybndry.cpp deleted file mode 100755 index 6197a7e10..000000000 --- a/Cantera/python/src/ctpybndry.cpp +++ /dev/null @@ -1,180 +0,0 @@ - -/** - * @file ctpybndry.cpp - * - */ - -// turn off warnings about long names under Windows -#ifdef WIN32 -#pragma warning(disable:4786) -#pragma warning(disable:4503) -#endif - - -#include "Python.h" -#include "Numeric/arrayobject.h" - -#include "ct.h" -#include "ctbdry.h" - -// constants defined in the module -static PyObject *ErrorObject; - -// local includes -#include "pyutils.h" -#include -using namespace std; - -static PyObject* -py_bndry_new(PyObject *self, PyObject *args) -{ - int itype; - if (!PyArg_ParseTuple(args, "i:bndry_new", &itype)) - return NULL; - int iok = bndry_new(itype); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",iok); -} - -static PyObject* -py_bndry_del(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:bndry_del", &n)) - return NULL; - bndry_del(n); - return Py_BuildValue("i",0); -} - -static PyObject* -py_bndry_temperature(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:bndry_temperature", &n)) - return NULL; - double t = bndry_temperature(n); - return Py_BuildValue("d",t); -} - -static PyObject* -py_bndry_settemperature(PyObject *self, PyObject *args) -{ - int n; - double t; - if (!PyArg_ParseTuple(args, "id:bndry_settemperature", &n, &t)) - return NULL; - int iok = bndry_settemperature(n, t); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_bndry_spreadrate(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:bndry_spreadrate", &n)) - return NULL; - double v = bndry_spreadrate(n); - return Py_BuildValue("d",v); -} - -static PyObject* -py_bndry_setspreadrate(PyObject *self, PyObject *args) -{ - int n; - double v; - if (!PyArg_ParseTuple(args, "id:bndry_setspreadrate", &n, &v)) - return NULL; - int iok = bndry_setspreadrate(n, v); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_bndry_mdot(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:bndry_mdot", &n)) - return NULL; - double mdot = bndry_mdot(n); - return Py_BuildValue("d",mdot); -} - -static PyObject* -py_bndry_setmdot(PyObject *self, PyObject *args) -{ - int n; - double mdot; - if (!PyArg_ParseTuple(args, "id:bndry_setmdot", &n, &mdot)) - return NULL; - int iok = bndry_setmdot(n, mdot); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_bndry_setxinbyname(PyObject *self, PyObject *args) -{ - int n; - char* xin; - //PyObject* o; - if (!PyArg_ParseTuple(args, "is:bndry_setxin", &n, &xin)) - return NULL; - //double* x = (double*)((PyArrayObject*)o)->data; - int iok = bndry_setxinbyname(n, xin); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - - -static PyObject* -py_bndry_setxin(PyObject *self, PyObject *args) -{ - int n; - PyObject* xin; - if (!PyArg_ParseTuple(args, "iO:bndry_setxin", &n, &xin)) - return NULL; - double* x = (double*)((PyArrayObject*)xin)->data; - int iok = bndry_setxin(n, x); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - - -static PyMethodDef ct_methods[] = { - {"bndry_temperature", py_bndry_temperature, METH_VARARGS}, - {"bndry_setxin", py_bndry_setxin, METH_VARARGS}, - {"bndry_setxinbyname", py_bndry_setxinbyname, METH_VARARGS}, - {"bndry_settemperature", py_bndry_settemperature, METH_VARARGS}, - {"bndry_setspreadrate", py_bndry_setspreadrate, METH_VARARGS}, - {"bndry_spreadrate", py_bndry_spreadrate, METH_VARARGS}, - {"bndry_new", py_bndry_new, METH_VARARGS}, - {"bndry_del", py_bndry_del, METH_VARARGS}, - {"bndry_mdot", py_bndry_mdot, METH_VARARGS}, - {"bndry_setmdot", py_bndry_setmdot, METH_VARARGS}, - {NULL, NULL} -}; - -extern "C" { - - /* Initialization function for the module */ - - DL_EXPORT(void) initctbndry(void) - { - PyObject *m, *d; - - /* Initialize the type of the new type object here; doing it here - * is required for portability to Windows without requiring C++. */ - - /* Create the module and add the functions */ - m = Py_InitModule("ctbndry", ct_methods); - import_array(); - - /* Add some symbolic constants to the module */ - d = PyModule_GetDict(m); - ErrorObject = PyErr_NewException("cantera.error", NULL, NULL); - PyDict_SetItemString(d, "error", ErrorObject); - } - -} - diff --git a/Cantera/python/src/ctpyfunc.cpp b/Cantera/python/src/ctpyfunc.cpp deleted file mode 100644 index 43b86eb61..000000000 --- a/Cantera/python/src/ctpyfunc.cpp +++ /dev/null @@ -1,108 +0,0 @@ - -/** - * @file ctpyfunc1.cpp - * - */ - -// turn off warnings about long names under Windows -#ifdef WIN32 -#pragma warning(disable:4786) -#pragma warning(disable:4503) -#endif - -#include -using namespace std; - -#include "Python.h" -#include "Numeric/arrayobject.h" - -#include "ct.h" -#include "ctfunc.h" - -// constants defined in the module -static PyObject *ErrorObject; - -// local includes -#include "pyutils.h" - - -static PyObject* -py_func_new(PyObject *self, PyObject *args) -{ - int type, n; - PyObject* c; - if (!PyArg_ParseTuple(args, "iiO:func_new", &type, &n, &c)) - return NULL; - PyArrayObject* coeffs = (PyArrayObject*)c; - double* xd = (double*)coeffs->data; - int lenc = coeffs->dimensions[0]; - int nn = func_new(type, n, lenc, xd); - if (nn < 0) return reportError(nn); - return Py_BuildValue("i",nn); -} - -static PyObject* -py_func_newcombo(PyObject *self, PyObject *args) -{ - int type, n, m; - if (!PyArg_ParseTuple(args, "iii:func_newcombo", &type, &n, &m)) - return NULL; - int nn = func_new(type, n, m, 0); - if (nn < 0) return reportError(nn); - return Py_BuildValue("i",nn); -} - -static PyObject* -py_func_del(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:func_del", &n)) - return NULL; - int iok = func_del(n); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_func_value(PyObject *self, PyObject *args) -{ - int n; - double t; - if (!PyArg_ParseTuple(args, "id:func_value", &n, &t)) - return NULL; - double r = func_value(n, t); - return Py_BuildValue("d",r); -} - - -static PyMethodDef ct_methods[] = { - {"func_new", py_func_new, METH_VARARGS}, - {"func_newcombo", py_func_newcombo, METH_VARARGS}, - {"func_del", py_func_del, METH_VARARGS}, - {"func_value", py_func_value, METH_VARARGS}, - {NULL, NULL} -}; - -extern "C" { - - /* Initialization function for the module */ - - DL_EXPORT(void) initctfunc(void) - { - PyObject *m, *d; - - /* Initialize the type of the new type object here; doing it here - * is required for portability to Windows without requiring C++. */ - - /* Create the module and add the functions */ - m = Py_InitModule("ctfunc", ct_methods); - import_array(); - - /* Add some symbolic constants to the module */ - d = PyModule_GetDict(m); - ErrorObject = PyErr_NewException("cantera.error", NULL, NULL); - PyDict_SetItemString(d, "error", ErrorObject); - } - -} - diff --git a/Cantera/python/src/ctpyreactor.cpp b/Cantera/python/src/ctpyreactor.cpp deleted file mode 100755 index 680cc65ab..000000000 --- a/Cantera/python/src/ctpyreactor.cpp +++ /dev/null @@ -1,685 +0,0 @@ - -/** - * @file ctpyreactor.cpp - * - */ - -// turn off warnings about long names under Windows -#ifdef WIN32 -#pragma warning(disable:4786) -#pragma warning(disable:4503) -#endif - - -#include "Python.h" -#include "Numeric/arrayobject.h" - -#include "ct.h" -#include "ctreactor.h" - -// constants defined in the module -static PyObject *ErrorObject; - -// local includes -#include "pyutils.h" - - -static PyObject* -py_reactor_new(PyObject *self, PyObject *args) -{ - int type; - if (!PyArg_ParseTuple(args, "i:reactor_new", &type)) - return NULL; - int n = reactor_new(type); - return Py_BuildValue("i",n); -} - -static PyObject* -py_reactor_del(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:reactor_del", &n)) - return NULL; - int iok = reactor_del(n); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_reactor_setInitialVolume(PyObject *self, PyObject *args) -{ - int n; - double v; - if (!PyArg_ParseTuple(args, "id:reactor_setInitialVolume", &n, &v)) - return NULL; - int iok = reactor_setInitialVolume(n,v); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_reactor_setInitialTime(PyObject *self, PyObject *args) -{ - int n; - double t; - if (!PyArg_ParseTuple(args, "id:reactor_setInitialTime", &n, &t)) - return NULL; - int iok = reactor_setInitialTime(n, t); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_reactor_setEnergy(PyObject *self, PyObject *args) -{ - int n, eflag; - if (!PyArg_ParseTuple(args, "ii:reactor_setEnergy", &n, &eflag)) - return NULL; - int iok = reactor_setEnergy(n, eflag); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_reactor_setThermoMgr(PyObject *self, PyObject *args) -{ - int n; - int th; - if (!PyArg_ParseTuple(args, "ii:reactor_setThermoMgr", &n, &th)) - return NULL; - int iok = reactor_setThermoMgr(n, th); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_reactor_setKineticsMgr(PyObject *self, PyObject *args) -{ - int n; - int kin; - if (!PyArg_ParseTuple(args, "ii:reactor_setKineticsMgr", &n, &kin)) - return NULL; - int iok = reactor_setKineticsMgr(n, kin); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_reactor_advance(PyObject *self, PyObject *args) -{ - int n; - double t; - if (!PyArg_ParseTuple(args, "id:reactor_advance", &n, &t)) - return NULL; - int iok = reactor_advance(n, t); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_reactor_step(PyObject *self, PyObject *args) -{ - int n; - double t; - if (!PyArg_ParseTuple(args, "id:reactor_step", &n, &t)) - return NULL; - return Py_BuildValue("d",reactor_step(n, t)); -} - -static PyObject* -py_reactor_time(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:reactor_time", &n)) - return NULL; - double t = reactor_time(n); - return Py_BuildValue("d",t); -} - -static PyObject* -py_reactor_mass(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:reactor_mass", &n)) - return NULL; - double m = reactor_mass(n); - return Py_BuildValue("d",m); -} - -static PyObject* -py_reactor_volume(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:reactor_volume", &n)) - return NULL; - double v = reactor_volume(n); - return Py_BuildValue("d",v); -} - -static PyObject* -py_reactor_density(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:reactor_density", &n)) - return NULL; - double rho = reactor_density(n); - return Py_BuildValue("d",rho); -} - -static PyObject* -py_reactor_temperature(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:reactor_temperature", &n)) - return NULL; - double t = reactor_temperature(n); - return Py_BuildValue("d",t); -} - -static PyObject* -py_reactor_enthalpy_mass(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:reactor_enthalpy_mass", &n)) - return NULL; - double h = reactor_enthalpy_mass(n); - return Py_BuildValue("d",h); -} - -static PyObject* -py_reactor_intEnergy_mass(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:reactor_intEnergy_mass", &n)) - return NULL; - double u = reactor_intEnergy_mass(n); - return Py_BuildValue("d",u); -} - -static PyObject* -py_reactor_pressure(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:reactor_pressure", &n)) - return NULL; - double p = reactor_pressure(n); - return Py_BuildValue("d",p); -} - -static PyObject* -py_reactor_massFraction(PyObject *self, PyObject *args) -{ - int n; - int k; - if (!PyArg_ParseTuple(args, "ii:reactor_massFraction", &n, &k)) - return NULL; - double y = reactor_massFraction(n, k); - return Py_BuildValue("d",y); -} - -// static PyObject* -// py_reactor_setArea(PyObject *self, PyObject *args) -// { -// int n; -// double a; -// if (!PyArg_ParseTuple(args, "id:reactor_setArea", &n, &a)) -// return NULL; -// int iok = reactor_setArea(n,a); -// if (iok < 0) return reportError(iok); -// return Py_BuildValue("i",0); -// } - -// static PyObject* -// py_reactor_setExtTemp(PyObject *self, PyObject *args) -// { -// int n; -// double t; -// if (!PyArg_ParseTuple(args, "id:reactor_setExtTemp", &n, &t)) -// return NULL; -// int iok = reactor_setExtTemp(n, t); -// if (iok < 0) return reportError(iok); -// return Py_BuildValue("i",0); -// } - -// static PyObject* -// py_reactor_setExtRadTemp(PyObject *self, PyObject *args) -// { -// int n; -// double t; -// if (!PyArg_ParseTuple(args, "id:reactor_setExtRadTemp", &n, &t)) -// return NULL; -// int iok = reactor_setExtRadTemp(n, t); -// if (iok < 0) return reportError(iok); -// return Py_BuildValue("i",0); -// } - -// static PyObject* -// py_reactor_setVDotCoeff(PyObject *self, PyObject *args) -// { -// int n; -// double vdt; -// if (!PyArg_ParseTuple(args, "id:reactor_setVDotCoeff", &n, &vdt)) -// return NULL; -// int iok = reactor_setVDotCoeff(n, vdt); -// if (iok < 0) return reportError(iok); -// return Py_BuildValue("i",0); -// } - -// static PyObject* -// py_reactor_setHeatTransferCoeff(PyObject *self, PyObject *args) -// { -// int n; -// double h; -// if (!PyArg_ParseTuple(args, "id:reactor_setHeatTransferCoeff", &n, &h)) -// return NULL; -// int iok = reactor_setHeatTransferCoeff(n, h); -// if (iok < 0) return reportError(iok); -// return Py_BuildValue("i",0); -// } - -// static PyObject* -// py_reactor_setEmissivity(PyObject *self, PyObject *args) -// { -// int n; -// double e; -// if (!PyArg_ParseTuple(args, "id:reactor_setEmissivity", &n, &e)) -// return NULL; -// int iok = reactor_setEmissivity(n, e); -// if (iok < 0) return reportError(iok); -// return Py_BuildValue("i",0); -// } - -// static PyObject* -// py_reactor_setExtPressure(PyObject *self, PyObject *args) -// { -// int n; -// double p; -// if (!PyArg_ParseTuple(args, "id:reactor_setExtPressure", &n, &p)) -// return NULL; -// int iok = reactor_setExtPressure(n,p); -// if (iok < 0) return reportError(iok); -// return Py_BuildValue("i",0); -// } - -static PyObject* -py_flowdev_new(PyObject *self, PyObject *args) -{ - int type; - if (!PyArg_ParseTuple(args, "i:flowdev_new", &type)) - return NULL; - int n = flowdev_new(type); - return Py_BuildValue("i",n); -} - -static PyObject* -py_flowdev_del(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:flowdev_del", &n)) - return NULL; - int iok = flowdev_del(n); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_flowdev_install(PyObject *self, PyObject *args) -{ - int n, r1, r2; - if (!PyArg_ParseTuple(args, "iii:flowdev_install", &n, &r1, &r2)) - return NULL; - int iok = flowdev_install(n, r1, r2); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_flowdev_massFlowRate(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:flowdev_massFlowRate", &n)) - return NULL; - double mdot = flowdev_massFlowRate(n); - return Py_BuildValue("d",mdot); -} - -static PyObject* -py_flowdev_setpoint(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:flowdev_setpoint", &n)) - return NULL; - double v = flowdev_setpoint(n); - return Py_BuildValue("d",v); -} - -static PyObject* -py_flowdev_setSetpoint(PyObject *self, PyObject *args) -{ - int n; - double v; - if (!PyArg_ParseTuple(args, "id:flowdev_setSetpoint", &n, &v)) - return NULL; - int iok = flowdev_setSetpoint(n, v); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -// static PyObject* -// py_flowdev_setGains(PyObject *self, PyObject *args) -// { -// int n, sz; -// PyObject* gains; -// if (!PyArg_ParseTuple(args, "iiO:flowdev_setGains", &n, &sz, &gains)) -// return NULL; -// double* x = (double*)((PyArrayObject*)gains)->data; -// int iok = flowdev_setGains(n, sz, x); -// if (iok < 0) return reportError(iok); -// return Py_BuildValue("i",0); -// } - -static PyObject* -py_flowdev_setParameters(PyObject *self, PyObject *args) -{ - int n, sz; - PyObject* c; - if (!PyArg_ParseTuple(args, "iiO:flowdev_setParameters", &n, &sz, &c)) - return NULL; - double* x = (double*)((PyArrayObject*)c)->data; - int iok = flowdev_setParameters(n, sz, x); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_flowdev_setFunction(PyObject *self, PyObject *args) -{ - int n, m; - if (!PyArg_ParseTuple(args, "ii:flowdev_setFunction", &n, &m)) - return NULL; - int iok = flowdev_setFunction(n, m); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -// static PyObject* -// py_flowdev_getGains(PyObject *self, PyObject *args) -// { -// int n, sz; -// if (!PyArg_ParseTuple(args, "ii:flowdev_getGains", &n, &sz)) -// return NULL; -// PyArrayObject* x = -// (PyArrayObject*)PyArray_FromDims(1, &sz, PyArray_DOUBLE); -// double* xd = (double*)x->data; -// int iok = flowdev_getGains(n, sz, xd); -// if (iok < 0) return reportError(iok); -// return PyArray_Return(x); -// } - -// static PyObject* -// py_flowdev_reset(PyObject *self, PyObject *args) -// { -// int n; -// if (!PyArg_ParseTuple(args, "i:flowdev_reset", &n)) -// return NULL; -// int iok = flowdev_reset(n); -// if (iok < 0) return reportError(iok); -// return Py_BuildValue("i",0); -// } - -// static PyObject* -// py_flowdev_update(PyObject *self, PyObject *args) -// { -// int n; -// if (!PyArg_ParseTuple(args, "i:flowdev_update", &n)) -// return NULL; -// int iok = flowdev_update(n); -// if (iok < 0) return reportError(iok); -// return Py_BuildValue("i",0); -// } - -// static PyObject* -// py_flowdev_maxError(PyObject *self, PyObject *args) -// { -// int n; -// if (!PyArg_ParseTuple(args, "i:flowdev_maxError", &n)) -// return NULL; -// double e = flowdev_maxError(n); -// return Py_BuildValue("d",e); -// } - -static PyObject* -py_flowdev_ready(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:flowdev_ready", &n)) - return NULL; - int iok = flowdev_ready(n); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",iok); -} - - -static PyObject* -py_wall_new(PyObject *self, PyObject *args) -{ - int type; - if (!PyArg_ParseTuple(args, "i:wall_new", &type)) - return NULL; - int n = wall_new(type); - return Py_BuildValue("i",n); -} - -static PyObject* -py_wall_del(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:wall_del", &n)) - return NULL; - int iok = wall_del(n); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_wall_install(PyObject *self, PyObject *args) -{ - int n, r1, r2; - if (!PyArg_ParseTuple(args, "iii:wall_install", &n, &r1, &r2)) - return NULL; - int iok = wall_install(n, r1, r2); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_wall_vdot(PyObject *self, PyObject *args) -{ - int n; - double t; - if (!PyArg_ParseTuple(args, "id:wall_vdot", &n, &t)) - return NULL; - double vdt = wall_vdot(n,t); - return Py_BuildValue("d",vdt); -} - -static PyObject* -py_wall_Q(PyObject *self, PyObject *args) -{ - int n; - double t; - if (!PyArg_ParseTuple(args, "id:wall_Q", &n, &t)) - return NULL; - return Py_BuildValue("d",wall_Q(n, t)); -} - -static PyObject* -py_wall_area(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:wall_area", &n)) - return NULL; - return Py_BuildValue("d",wall_area(n)); -} - -static PyObject* -py_wall_setArea(PyObject *self, PyObject *args) -{ - int n; - double area; - if (!PyArg_ParseTuple(args, "id:wall_setArea", &n, &area)) - return NULL; - int iok = wall_setArea(n, area); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_wall_setThermalResistance(PyObject *self, PyObject *args) -{ - int n; - double rth; - if (!PyArg_ParseTuple(args, "id:wall_setThermalResistance", &n, &rth)) - return NULL; - int iok = wall_setThermalResistance(n,rth); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_wall_setHeatTransferCoeff(PyObject *self, PyObject *args) -{ - int n; - double u; - if (!PyArg_ParseTuple(args, "id:wall_setHeatTransferCoeff", &n, &u)) - return NULL; - int iok = wall_setHeatTransferCoeff(n,u); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_wall_setExpansionRateCoeff(PyObject *self, PyObject *args) -{ - int n; - double k; - if (!PyArg_ParseTuple(args, "id:wall_setExpansionRateCoeff", &n, &k)) - return NULL; - int iok = wall_setExpansionRateCoeff(n,k); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_wall_setExpansionRate(PyObject *self, PyObject *args) -{ - int n, m; - if (!PyArg_ParseTuple(args, "ii:wall_setExpansionRate", &n, &m)) - return NULL; - int iok = wall_setExpansionRate(n,m); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_wall_setHeatFlux(PyObject *self, PyObject *args) -{ - int n, m; - if (!PyArg_ParseTuple(args, "ii:wall_setHeatFlux", &n, &m)) - return NULL; - int iok = wall_setHeatFlux(n,m); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_wall_ready(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:wall_ready", &n)) - return NULL; - int iok = wall_ready(n); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - - -static PyMethodDef ct_methods[] = { - // {"reactor_setExtTemp", py_reactor_setExtTemp, METH_VARARGS}, - {"flowdev_ready", py_flowdev_ready, METH_VARARGS}, - //{"reactor_setEmissivity", py_reactor_setEmissivity, METH_VARARGS}, - {"reactor_setInitialTime", py_reactor_setInitialTime, METH_VARARGS}, - {"flowdev_new", py_flowdev_new, METH_VARARGS}, - {"flowdev_massFlowRate", py_flowdev_massFlowRate, METH_VARARGS}, - {"flowdev_del", py_flowdev_del, METH_VARARGS}, - {"flowdev_setpoint", py_flowdev_setpoint, METH_VARARGS}, - {"reactor_temperature", py_reactor_temperature, METH_VARARGS}, - {"flowdev_setSetpoint", py_flowdev_setSetpoint, METH_VARARGS}, - //{"flowdev_reset", py_flowdev_reset, METH_VARARGS}, - //{"reactor_setExtRadTemp", py_reactor_setExtRadTemp, METH_VARARGS}, - {"flowdev_install", py_flowdev_install, METH_VARARGS}, - {"reactor_setThermoMgr", py_reactor_setThermoMgr, METH_VARARGS}, - {"reactor_setEnergy", py_reactor_setEnergy, METH_VARARGS}, - {"reactor_volume", py_reactor_volume, METH_VARARGS}, - {"reactor_time", py_reactor_time, METH_VARARGS}, - {"reactor_advance", py_reactor_advance, METH_VARARGS}, - {"reactor_step", py_reactor_step, METH_VARARGS}, - //{"reactor_setExtPressure", py_reactor_setExtPressure, METH_VARARGS}, - //{"flowdev_setGains", py_flowdev_setGains, METH_VARARGS}, - {"flowdev_setParameters", py_flowdev_setParameters, METH_VARARGS}, - {"flowdev_setFunction", py_flowdev_setFunction, METH_VARARGS}, - {"reactor_mass", py_reactor_mass, METH_VARARGS}, - {"reactor_new", py_reactor_new, METH_VARARGS}, - //{"reactor_setVDotCoeff", py_reactor_setVDotCoeff, METH_VARARGS}, - //{"reactor_setHeatTransferCoeff", py_reactor_setHeatTransferCoeff, METH_VARARGS}, - {"reactor_enthalpy_mass", py_reactor_enthalpy_mass, METH_VARARGS}, - //{"flowdev_maxError", py_flowdev_maxError, METH_VARARGS}, - //{"flowdev_getGains", py_flowdev_getGains, METH_VARARGS}, - //{"flowdev_update", py_flowdev_update, METH_VARARGS}, - //{"reactor_setArea", py_reactor_setArea, METH_VARARGS}, - {"reactor_pressure", py_reactor_pressure, METH_VARARGS}, - {"reactor_setInitialVolume", py_reactor_setInitialVolume, METH_VARARGS}, - {"reactor_density", py_reactor_density, METH_VARARGS}, - {"reactor_setKineticsMgr", py_reactor_setKineticsMgr, METH_VARARGS}, - {"reactor_del", py_reactor_del, METH_VARARGS}, - {"reactor_intEnergy_mass", py_reactor_intEnergy_mass, METH_VARARGS}, - {"reactor_massFraction", py_reactor_massFraction, METH_VARARGS}, - {"wall_install", py_wall_install, METH_VARARGS}, - {"wall_area", py_wall_area, METH_VARARGS}, - {"wall_setArea", py_wall_setArea, METH_VARARGS}, - {"wall_setThermalResistance", py_wall_setThermalResistance, METH_VARARGS}, - {"wall_setHeatTransferCoeff", py_wall_setHeatTransferCoeff, METH_VARARGS}, - {"wall_setHeatFlux", py_wall_setHeatFlux, METH_VARARGS}, - {"wall_Q", py_wall_Q, METH_VARARGS}, - {"wall_new", py_wall_new, METH_VARARGS}, - {"wall_vdot", py_wall_vdot, METH_VARARGS}, - {"wall_del", py_wall_del, METH_VARARGS}, - {"wall_setExpansionRate", py_wall_setExpansionRate, METH_VARARGS}, - {"wall_setExpansionRateCoeff", py_wall_setExpansionRateCoeff, METH_VARARGS}, - {"wall_ready", py_wall_ready, METH_VARARGS}, - {NULL, NULL} -}; - -extern "C" { - - /* Initialization function for the module */ - - DL_EXPORT(void) initctreactor(void) - { - PyObject *m, *d; - - /* Initialize the type of the new type object here; doing it here - * is required for portability to Windows without requiring C++. */ - - /* Create the module and add the functions */ - m = Py_InitModule("ctreactor", ct_methods); - import_array(); - - /* Add some symbolic constants to the module */ - d = PyModule_GetDict(m); - ErrorObject = PyErr_NewException("cantera.error", NULL, NULL); - PyDict_SetItemString(d, "error", ErrorObject); - } - -} - diff --git a/Cantera/python/src/ctpyrpath.cpp b/Cantera/python/src/ctpyrpath.cpp deleted file mode 100755 index ed525b184..000000000 --- a/Cantera/python/src/ctpyrpath.cpp +++ /dev/null @@ -1,359 +0,0 @@ - -/** - * @file ctpyrpath.cpp - * - */ - -// turn off warnings about long names under Windows -#ifdef WIN32 -#pragma warning(disable:4786) -#pragma warning(disable:4503) -#endif - - -#include "Python.h" -#include "Numeric/arrayobject.h" - -#include "ct.h" -#include "ctrpath.h" - -// constants defined in the module -static PyObject *ErrorObject; - -// local includes -#include "pyutils.h" - - -static PyObject* -py_rdiag_new(PyObject *self, PyObject *args) -{ - int iok = rdiag_new(); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",iok); -} - -static PyObject* -py_rdiag_del(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:rdiag_del", &n)) - return NULL; - int iok = rdiag_del(n); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_rdiag_detailed(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:rdiag_detailed", &n)) - return NULL; - int iok = rdiag_detailed(n); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_rdiag_brief(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:rdiag_brief", &n)) - return NULL; - int iok = rdiag_brief(n); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_rdiag_setThreshold(PyObject *self, PyObject *args) -{ - int n; - double v; - if (!PyArg_ParseTuple(args, "id:rdiag_setThreshold", &n, &v)) - return NULL; - int iok = rdiag_setThreshold(n,v); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_rdiag_setBoldColor(PyObject *self, PyObject *args) -{ - int n; - char* color; - if (!PyArg_ParseTuple(args, "is:rdiag_setBoldColor", &n, &color)) - return NULL; - int iok = rdiag_setBoldColor(n, color); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_rdiag_setNormalColor(PyObject *self, PyObject *args) -{ - int n; - char* color; - if (!PyArg_ParseTuple(args, "is:rdiag_setNormalColor", &n, &color)) - return NULL; - int iok = rdiag_setNormalColor(n, color); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_rdiag_setDashedColor(PyObject *self, PyObject *args) -{ - int n; - char* color; - if (!PyArg_ParseTuple(args, "is:rdiag_setDashedColor", &n, &color)) - return NULL; - int iok = rdiag_setDashedColor(n,color); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_rdiag_setDotOptions(PyObject *self, PyObject *args) -{ - int n; - char* opt; - if (!PyArg_ParseTuple(args, "is:rdiag_setDotOptions", &n, &opt)) - return NULL; - int iok = rdiag_setDotOptions(n,opt); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_rdiag_setBoldThreshold(PyObject *self, PyObject *args) -{ - int n; - double v; - if (!PyArg_ParseTuple(args, "id:rdiag_setBoldThreshold", &n, &v)) - return NULL; - int iok = rdiag_setBoldThreshold(n,v); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_rdiag_setNormalThreshold(PyObject *self, PyObject *args) -{ - int n; - double v; - if (!PyArg_ParseTuple(args, "id:rdiag_setNormalThreshold", &n, &v)) - return NULL; - int iok = rdiag_setNormalThreshold(n,v); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_rdiag_setLabelThreshold(PyObject *self, PyObject *args) -{ - int n; - double v; - if (!PyArg_ParseTuple(args, "id:rdiag_setLabelThreshold", &n, &v)) - return NULL; - int iok = rdiag_setLabelThreshold(n,v); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_rdiag_setScale(PyObject *self, PyObject *args) -{ - int n; - double v; - if (!PyArg_ParseTuple(args, "id:rdiag_setScale", &n, &v)) - return NULL; - int iok = rdiag_setScale(n,v); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_rdiag_setFlowType(PyObject *self, PyObject *args) -{ - int n; - int iflow; - if (!PyArg_ParseTuple(args, "ii:rdiag_setFlowType", &n, &iflow)) - return NULL; - int iok = rdiag_setFlowType(n, iflow); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_rdiag_setArrowWidth(PyObject *self, PyObject *args) -{ - int n; - double v; - if (!PyArg_ParseTuple(args, "id:rdiag_setArrowWidth", &n, &v)) - return NULL; - int iok = rdiag_setArrowWidth(n,v); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - - -static PyObject* -py_rdiag_displayOnly(PyObject *self, PyObject *args) -{ - int n, k; - if (!PyArg_ParseTuple(args, "ii:rdiag_displayOnly", &n, &k)) - return NULL; - int iok = rdiag_displayOnly(n,k); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_rdiag_setTitle(PyObject *self, PyObject *args) -{ - int n; - char* t; - if (!PyArg_ParseTuple(args, "is:rdiag_setTitle", &n, &t)) - return NULL; - int iok = rdiag_setTitle(n,t); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_rdiag_add(PyObject *self, PyObject *args) -{ - int n, m; - if (!PyArg_ParseTuple(args, "ii:rdiag_add", &n, &m)) - return NULL; - int iok = rdiag_add(n,m); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_rdiag_findMajor(PyObject *self, PyObject *args) -{ - int n, m; - double thresh; - PyObject* a; - if (!PyArg_ParseTuple(args, "idO:rdiag_findMajor", &n, &thresh, &a)) - return NULL; - PyArrayObject* aa = (PyArrayObject*)a; - int lda = aa->dimensions[0]; - double* x = (double*)aa->data; - int iok = rdiag_findMajor(n, thresh, lda, x); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_rdiag_write(PyObject *self, PyObject *args) -{ - int n, fmt; - char* nm; - if (!PyArg_ParseTuple(args, "iis:rdiag_write", &n, &fmt, &nm)) - return NULL; - int iok = rdiag_write(n, fmt, nm); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_rbuild_new(PyObject *self, PyObject *args) -{ - int iok = rbuild_new(); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",iok); -} - -static PyObject* -py_rbuild_del(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:rbuild_del", &n)) - return NULL; - int iok = rbuild_del(n); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_rbuild_init(PyObject *self, PyObject *args) -{ - int n; - char* log; - int k; - if (!PyArg_ParseTuple(args, "isi:rbuild_init", &n, &log, &k)) - return NULL; - int iok = rbuild_init(n,log,k); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_rbuild_build(PyObject *self, PyObject *args) -{ - int n; - int k, idiag, iquiet; - char *el, *dotfile; - if (!PyArg_ParseTuple(args, "iissii:rbuild_build", &n, &k, - &el, &dotfile, &idiag, &iquiet)) - return NULL; - int iok = rbuild_build(n,k,el,dotfile,idiag,iquiet); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyMethodDef ct_methods[] = { - {"rdiag_setDashedColor", py_rdiag_setDashedColor, METH_VARARGS}, - {"rbuild_new", py_rbuild_new, METH_VARARGS}, - {"rdiag_write", py_rdiag_write, METH_VARARGS}, - {"rdiag_setDotOptions", py_rdiag_setDotOptions, METH_VARARGS}, - {"rdiag_setScale", py_rdiag_setScale, METH_VARARGS}, - {"rdiag_setTitle", py_rdiag_setTitle, METH_VARARGS}, - {"rdiag_setArrowWidth", py_rdiag_setArrowWidth, METH_VARARGS}, - {"rdiag_displayOnly", py_rdiag_displayOnly, METH_VARARGS}, - {"rdiag_setThreshold", py_rdiag_setThreshold, METH_VARARGS}, - {"rdiag_setBoldThreshold", py_rdiag_setBoldThreshold, METH_VARARGS}, - {"rdiag_new", py_rdiag_new, METH_VARARGS}, - {"rdiag_del", py_rdiag_del, METH_VARARGS}, - {"rdiag_detailed", py_rdiag_detailed, METH_VARARGS}, - {"rdiag_add", py_rdiag_add, METH_VARARGS}, - {"rdiag_findMajor", py_rdiag_findMajor, METH_VARARGS}, - {"rbuild_build", py_rbuild_build, METH_VARARGS}, - {"rdiag_setNormalThreshold", py_rdiag_setNormalThreshold, METH_VARARGS}, - {"rdiag_brief", py_rdiag_brief, METH_VARARGS}, - {"rbuild_del", py_rbuild_del, METH_VARARGS}, - {"rdiag_setNormalColor", py_rdiag_setNormalColor, METH_VARARGS}, - {"rbuild_init", py_rbuild_init, METH_VARARGS}, - {"rdiag_setBoldColor", py_rdiag_setBoldColor, METH_VARARGS}, - {"rdiag_setFlowType", py_rdiag_setFlowType, METH_VARARGS}, - {"rdiag_setLabelThreshold", py_rdiag_setLabelThreshold, METH_VARARGS}, - {NULL, NULL} -}; - -extern "C" { - - /* Initialization function for the module */ - - DL_EXPORT(void) initctrpath(void) - { - PyObject *m, *d; - - /* Initialize the type of the new type object here; doing it here - * is required for portability to Windows without requiring C++. */ - - /* Create the module and add the functions */ - m = Py_InitModule("ctrpath", ct_methods); - import_array(); - - /* Add some symbolic constants to the module */ - d = PyModule_GetDict(m); - ErrorObject = PyErr_NewException("cantera.error", NULL, NULL); - PyDict_SetItemString(d, "error", ErrorObject); - } - -} - diff --git a/Cantera/python/src/ctpysurf.cpp b/Cantera/python/src/ctpysurf.cpp deleted file mode 100755 index cc2528dbc..000000000 --- a/Cantera/python/src/ctpysurf.cpp +++ /dev/null @@ -1,404 +0,0 @@ -/** - * @file ctsurf.cpp - * - */ - -// turn off warnings about long names under Windows -#ifdef WIN32 -#pragma warning(disable:4786) -#pragma warning(disable:4503) -#endif - - -#include "Python.h" -#include "Numeric/arrayobject.h" - -#include "ct.h" -#include "ctsurf.h" -#include -#include -#include - -using namespace std; - -// constants defined in the module -static PyObject *ErrorObject; - -// local includes -#include "pyutils.h" - -static PyObject* -py_surf_setsitedensity(PyObject *self, PyObject *args) -{ - int n; - double s0; - if (!PyArg_ParseTuple(args, "id:surf_setsitedensity", &n, &s0)) - return NULL; - - int iok = surf_setsitedensity(n, s0); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_surf_sitedensity(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:surf_sitedensity", &n)) - return NULL; - - double s0 = surf_sitedensity(n); - return Py_BuildValue("d",s0); -} - - -static PyObject* -py_surf_setcoverages(PyObject *self, PyObject *args) -{ - int n; - PyObject* cov; - if (!PyArg_ParseTuple(args, "iO:surf_setcoverages", &n, &cov)) - return NULL; - double* x = (double*)((PyArrayObject*)cov)->data; - int iok = surf_setcoverages(n, x); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_surf_setconcentrations(PyObject *self, PyObject *args) -{ - int n; - PyObject* c; - if (!PyArg_ParseTuple(args, "iO:surf_setconcentrations", &n, &c)) - return NULL; - double* x = (double*)((PyArrayObject*)c)->data; - int iok = surf_setconcentrations(n, x); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_surf_getcoverages(PyObject *self, PyObject *args) -{ - int n; - PyArrayObject* cov; - if (!PyArg_ParseTuple(args, "i:surf_getcoverages", &n)) - return NULL; - int nsp = th_nSpecies(n); - cov = (PyArrayObject*)PyArray_FromDims(1, &nsp, PyArray_DOUBLE); - double* x = (double*)((PyArrayObject*)cov)->data; - int iok = surf_getcoverages(n, x); - if (iok < 0) return reportError(iok); - return Py_BuildValue("O",cov); -} - -static PyObject* -py_surf_getconcentrations(PyObject *self, PyObject *args) -{ - int n; - PyArrayObject* c; - if (!PyArg_ParseTuple(args, "i:surf_getconcentrations", &n)) - return NULL; - int nsp = th_nSpecies(n); - c = (PyArrayObject*)PyArray_FromDims(1, &nsp, PyArray_DOUBLE); - double* x = (double*)((PyArrayObject*)c)->data; - int iok = surf_getconcentrations(n, x); - if (iok < 0) return reportError(iok); - return Py_BuildValue("O",c); -} - -// static PyObject* -// py_surf_doc(PyObject *self, PyObject *args) -// { -// int n; -// char *k, *v; -// if (!PyArg_ParseTuple(args, "iss:surf_doc", &n, &k, &v)) -// return NULL; -// surf_doc(n, k, v); -// return Py_BuildValue("i",0); -// } - -// static PyObject * -// py_surfkin_new(PyObject *self, PyObject *args) -// { -// int isurf, ib1, ib2; -// if (!PyArg_ParseTuple(args, "iii:surfkin_new", &isurf, &ib1, &ib2)) -// return NULL; -// int nn = surfkin_new(isurf, ib1, ib2); -// if (nn < 0) return reportError(nn); -// return Py_BuildValue("i",nn); -// } - -// static PyObject* -// py_surfkin_delete(PyObject *self, PyObject *args) -// { -// int n; -// if (!PyArg_ParseTuple(args, "i:surfkin_delete", &n)) return NULL; -// surf_del(n); -// return Py_BuildValue("i",0); -// } - - -// static PyObject * -// py_surfkin_addreaction(PyObject *self, PyObject *args) -// { -// int isurf, nr, np, nrate; -// PyObject *pyr, *pyrst, *pyro, *pyp, *pypst, *pyrate; -// if (!PyArg_ParseTuple(args, "iiOOOiOOiO:surfkin_addreaction", -// &isurf, &nr, &pyr, &pyrst, &pyro, &np, &pyp, &pypst, -// &nrate, &pyrate)) -// return NULL; -// int* r = (int*)((PyArrayObject*)pyr)->data; -// int* rst = (int*)((PyArrayObject*)pyrst)->data; -// int* ro = (int*)((PyArrayObject*)pyro)->data; -// int* p = (int*)((PyArrayObject*)pyp)->data; -// int* pst = (int*)((PyArrayObject*)pypst)->data; -// double* rate = (double*)((PyArrayObject*)pyrate)->data; -// int nn = surfkin_addreaction(isurf, nr, r, rst, ro, np, p, pst, -// nrate, rate); -// if (nn < 0) return reportError(nn); -// return Py_BuildValue("i",nn); -// } - -// static PyObject * -// py_surfkin_nreactions(PyObject *self, PyObject *args) -// { -// int isurf; -// if (!PyArg_ParseTuple(args, "i:surfkin_nreactions", &isurf)) -// return NULL; -// int nn = surfkin_nreactions(isurf); -// return Py_BuildValue("i",nn); -// } - -// static PyObject* -// py_surfkin_getratesofprogress(PyObject *self, PyObject *args) -// { -// int n; -// PyArrayObject* rop; -// if (!PyArg_ParseTuple(args, "i:surfkin_getratesofprogress", &n)) -// return NULL; -// int nrxn = surfkin_nreactions(n); -// rop = (PyArrayObject*)PyArray_FromDims(1, &nrxn, PyArray_DOUBLE); -// double* x = (double*)((PyArrayObject*)rop)->data; -// int iok = surfkin_getratesofprogress(n, x); -// if (iok < 0) return reportError(iok); -// return Py_BuildValue("O",rop); -// } - -// static PyObject* -// py_surfkin_getnetproductionrates(PyObject *self, PyObject *args) -// { -// int n, nsp; -// PyArrayObject* sdot; -// if (!PyArg_ParseTuple(args, "ii:surfkin_getnetproductionrates", &n, &nsp)) -// return NULL; -// sdot = (PyArrayObject*)PyArray_FromDims(1, &nsp, PyArray_DOUBLE); -// double* x = (double*)((PyArrayObject*)sdot)->data; -// int iok = surfkin_getnetproductionrates(n, x); -// if (iok < 0) return reportError(iok); -// return Py_BuildValue("O",sdot); -// } - -// static PyObject * -// py_surfkin_integrate(PyObject *self, PyObject *args) -// { -// int isurf; -// double dt; -// if (!PyArg_ParseTuple(args, "id:surfkin_integrate", &isurf, &dt)) -// return NULL; -// int nn = surfkin_integrate(isurf, dt); -// if (nn < 0) return reportError(nn); -// return Py_BuildValue("i",0); -// } - -// static PyObject * -// py_surfkin_save(PyObject *self, PyObject *args) -// { -// int isurf; -// char *fname, *id, *comment; -// if (!PyArg_ParseTuple(args, "isss:surfkin_save", &isurf, &fname, &id, &comment)) -// return NULL; -// int nn = surfkin_save(isurf, fname, id, comment); -// if (nn < 0) return reportError(nn); -// return Py_BuildValue("i",0); -// } - -// static PyObject * -// py_surf1d_new(PyObject *self, PyObject *args) -// { -// int ikin; -// if (!PyArg_ParseTuple(args, "i:surf1d_new", &ikin)) -// return NULL; -// int nn = surface_new(ikin); -// if (nn < 0) return reportError(nn); -// return Py_BuildValue("i",nn); -// } - -// static PyObject* -// py_surf1d_delete(PyObject *self, PyObject *args) -// { -// int n; -// if (!PyArg_ParseTuple(args, "i:surf1d_delete", &n)) return NULL; -// surface_del(n); -// return Py_BuildValue("i",0); -// } - -// static PyObject* -// py_surf1d_settolerances(PyObject *self, PyObject *args) -// { -// int n, nr, na; -// PyObject *prtol, *patol; -// if (!PyArg_ParseTuple(args, "iiOiO:surf1d_settolerances", &n, &nr, &prtol, -// &na, &patol)) -// return NULL; -// double* rtol = (double*)((PyArrayObject*)prtol)->data; -// double* atol = (double*)((PyArrayObject*)patol)->data; -// int iok = surface_settolerances(n, nr, rtol, na, atol); -// if (iok < 0) return reportError(iok); -// return Py_BuildValue("i",iok); -// } - -// static PyObject* -// py_surf1d_settemperature(PyObject *self, PyObject *args) -// { -// int n; -// double t; -// if (!PyArg_ParseTuple(args, "id:surf1d_settemperature", &n, &t)) -// return NULL; -// int iok = surface_settemperature(n, t); -// if (iok < 0) return reportError(iok); -// return Py_BuildValue("i",iok); -// } - -// static PyObject* -// py_surf1d_temperature(PyObject *self, PyObject *args) -// { -// int n; -// if (!PyArg_ParseTuple(args, "i:surf1d_temperature", &n)) -// return NULL; -// return Py_BuildValue("d",surface_temperature(n)); -// } - -// static PyObject* -// py_surf1d_setcoverages(PyObject *self, PyObject *args) -// { -// int n; -// PyObject* cov; -// if (!PyArg_ParseTuple(args, "iO:surf1d_setcoverages", &n, &cov)) -// return NULL; -// double* x = (double*)((PyArrayObject*)cov)->data; -// int iok = surface_setcoverages(n, x); -// if (iok < 0) return reportError(iok); -// return Py_BuildValue("i",0); -// } - -// static PyObject* -// py_surf1d_setmultiplier(PyObject *self, PyObject *args) -// { -// int n, k; -// double f; -// if (!PyArg_ParseTuple(args, "iid:surf1d_setmultiplier", &n, &k, &f)) -// return NULL; -// int iok = surface_setmultiplier(n, k, f); -// if (iok < 0) return reportError(iok); -// return Py_BuildValue("i",iok); -// } - -// static PyObject* -// py_surf1d_multiplier(PyObject *self, PyObject *args) -// { -// int n, k; -// if (!PyArg_ParseTuple(args, "ii:surf1d_multiplier", &n, &k)) -// return NULL; -// return Py_BuildValue("d",surface_multiplier(n, k)); -// } - -// static PyObject* -// py_surf1d_fixspecies(PyObject *self, PyObject *args) -// { -// int n, k; -// double c; -// if (!PyArg_ParseTuple(args, "iid:surf1d_fixspecies", &n, &k, &c)) -// return NULL; -// int iok = surface_fixspecies(n, k, c); -// if (iok < 0) return reportError(iok); -// return Py_BuildValue("i",iok); -// } - -// static PyObject* -// py_surf1d_solvespecies(PyObject *self, PyObject *args) -// { -// int n, slen; -// PyObject* s; -// if (!PyArg_ParseTuple(args, "iiO:surf1d_solvespecies", &n, &slen, &s)) -// return NULL; -// double* x = (double*)((PyArrayObject*)s)->data; -// for (int i = 0; i < slen; i++) { -// if (x[i] <= 0.0) -// surface_fixspecies(n, i); -// else -// surface_solvespecies(n, i); -// } -// return Py_BuildValue("i",0); -// } - - -/* List of functions defined in the module */ - -static PyMethodDef ct_methods[] = { - // {"surf_new", py_surf_new, METH_VARARGS}, - //{"surf_delete", py_surf_delete, METH_VARARGS}, - //{"surf_addspecies", py_surf_addspecies, METH_VARARGS}, - {"surf_setsitedensity", py_surf_setsitedensity, METH_VARARGS}, - {"surf_sitedensity", py_surf_sitedensity, METH_VARARGS}, - //{"surf_nspecies", py_surf_nspecies, METH_VARARGS}, - {"surf_setcoverages", py_surf_setcoverages, METH_VARARGS}, - {"surf_getcoverages", py_surf_getcoverages, METH_VARARGS}, - {"surf_setconcentrations", py_surf_setconcentrations, METH_VARARGS}, - {"surf_getconcentrations", py_surf_getconcentrations, METH_VARARGS}, - //{"surf_doc", py_surf_doc, METH_VARARGS}, -// {"surfkin_new", py_surfkin_new, METH_VARARGS}, -// {"surfkin_delete", py_surfkin_delete, METH_VARARGS}, -// {"surfkin_addreaction", py_surfkin_addreaction, METH_VARARGS}, -// {"surfkin_nreactions", py_surfkin_nreactions, METH_VARARGS}, -// {"surfkin_getratesofprogress", py_surfkin_getratesofprogress, METH_VARARGS}, -// {"surfkin_getsdot", py_surfkin_getnetproductionrates, METH_VARARGS}, -// {"surfkin_integrate", py_surfkin_integrate, METH_VARARGS}, -// {"surfkin_save", py_surfkin_save, METH_VARARGS}, -// {"surf1d_new", py_surf1d_new, METH_VARARGS}, -// {"surf1d_delete", py_surf1d_delete, METH_VARARGS}, -// {"surf1d_settolerances", py_surf1d_settolerances, METH_VARARGS}, -// {"surf1d_settemperature", py_surf1d_settemperature, METH_VARARGS}, -// {"surf1d_temperature", py_surf1d_temperature, METH_VARARGS}, -// {"surf1d_setcoverages", py_surf1d_setcoverages, METH_VARARGS}, -// {"surf1d_setmultiplier", py_surf1d_setmultiplier, METH_VARARGS}, -// {"surf1d_multiplier", py_surf1d_multiplier, METH_VARARGS}, -// {"surf1d_fixspecies", py_surf1d_fixspecies, METH_VARARGS}, -// {"surf1d_solvespecies", py_surf1d_solvespecies, METH_VARARGS}, - {NULL, NULL} /* sentinel */ -}; - - -extern "C" { - - /* Initialization function for the module (*must* be called initctsurf) */ - - DL_EXPORT(void) initctsurf(void) - { - PyObject *m, *d; - - /* Initialize the type of the new type object here; doing it here - * is required for portability to Windows without requiring C++. */ - - /* Create the module and add the functions */ - m = Py_InitModule("ctsurf", ct_methods); - import_array(); - - /* Add some symbolic constants to the module */ - d = PyModule_GetDict(m); - ErrorObject = PyErr_NewException("cantera.error", NULL, NULL); - PyDict_SetItemString(d, "error", ErrorObject); - } - -} diff --git a/Cantera/python/src/ctpyxml.cpp b/Cantera/python/src/ctpyxml.cpp deleted file mode 100644 index 37c0e846a..000000000 --- a/Cantera/python/src/ctpyxml.cpp +++ /dev/null @@ -1,283 +0,0 @@ - -/** - * @file ctpyxml.cpp - * - */ - -// turn off warnings about long names under Windows -#ifdef WIN32 -#pragma warning(disable:4786) -#pragma warning(disable:4503) -#endif - - -#include "Python.h" -#include "Numeric/arrayobject.h" - -#include "ct.h" -#include "ctxml.h" -#include -using namespace std; - -// constants defined in the module -static PyObject *ErrorObject; - -// local includes -#include "pyutils.h" - - -static PyObject* -py_xml_new(PyObject *self, PyObject *args) -{ - char* nm; - if (!PyArg_ParseTuple(args, "s:xml_new", &nm)) - return NULL; - int n = xml_new(nm); - return Py_BuildValue("i",n); -} - -static PyObject* -py_xml_del(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:xml_del", &n)) - return NULL; - int iok = xml_del(n); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_xml_build(PyObject *self, PyObject *args) -{ - int n; - char* file; - if (!PyArg_ParseTuple(args, "is:xml_build", &n, &file)) - return NULL; - int iok = xml_build(n, file); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - -static PyObject* -py_xml_attrib(PyObject *self, PyObject *args) -{ - int n; - char *key; - if (!PyArg_ParseTuple(args, "is:xml_attrib", &n, &key)) - return NULL; - char* val = new char[81]; - int iok = xml_attrib(n, key, val); - if (iok < 0) return reportError(iok); - PyObject* r = Py_BuildValue("s",val); - delete val; - return r; -} - -static PyObject* -py_xml_tag(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:xml_tag", &n)) - return NULL; - char* val = new char[81]; - int iok = xml_tag(n, val); - if (iok < 0) return reportError(iok); - PyObject* r = Py_BuildValue("s",val); - delete val; - return r; -} - -static PyObject* -py_xml_value(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:xml_value", &n)) - return NULL; - char* val = new char[81]; - int iok = xml_value(n, val); - if (iok < 0) return reportError(iok); - PyObject* r = Py_BuildValue("s",val); - delete val; - return r; -} - -static PyObject* -py_xml_child(PyObject *self, PyObject *args) -{ - int n; - char* loc; - if (!PyArg_ParseTuple(args, "is:xml_child", &n, &loc)) - return NULL; - int m = xml_child(n, loc); - if (m < 0) return reportError(m); - return Py_BuildValue("i",m); -} - -static PyObject* -py_xml_childbynumber(PyObject *self, PyObject *args) -{ - int n, k; - if (!PyArg_ParseTuple(args, "ii:xml_childbynumber", &n, &k)) - return NULL; - int m = xml_child_bynumber(n, k); - if (m < 0) return reportError(m); - return Py_BuildValue("i",m); -} - -static PyObject* -py_xml_findID(PyObject *self, PyObject *args) -{ - int n; - char* id; - if (!PyArg_ParseTuple(args, "is:xml_findID", &n, &id)) - return NULL; - int m = xml_findID(n, id); - if (m < 0) return reportError(m); - return Py_BuildValue("i",m); -} - -static PyObject* -py_xml_findByName(PyObject *self, PyObject *args) -{ - int n; - char* nm; - if (!PyArg_ParseTuple(args, "is:xml_findID", &n, &nm)) - return NULL; - int m = xml_findByName(n, nm); - if (m < 0) return reportError(m); - return Py_BuildValue("i",m); -} - -static PyObject* -py_xml_nChildren(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:xml_nChildren", &n)) - return NULL; - int m = xml_nChildren(n); - if (m < 0) return reportError(m); - return Py_BuildValue("i",m); -} - -static PyObject* -py_xml_addChild(PyObject *self, PyObject *args) -{ - int n; - char *name, *value; - if (!PyArg_ParseTuple(args, "iss:xml_addChild", &n, &name, &value)) - return NULL; - int m = xml_addChild(n, name, value); - if (m < 0) return reportError(m); - return Py_BuildValue("i",m); -} - - -static PyObject* -py_xml_addChildNode(PyObject *self, PyObject *args) -{ - int n, j; - if (!PyArg_ParseTuple(args, "ii:xml_addChildNode", &n, &j)) - return NULL; - int m = xml_addChildNode(n, j); - if (m < 0) return reportError(m); - return Py_BuildValue("i",m); -} - - -static PyObject* -py_xml_addAttrib(PyObject *self, PyObject *args) -{ - int n; - char *name, *value; - if (!PyArg_ParseTuple(args, "iss:xml_addAttrib", &n, &name, &value)) - return NULL; - int m = xml_addAttrib(n, name, value); - if (m < 0) return reportError(m); - return Py_BuildValue("i",m); -} - -static PyObject* -py_xml_removeChild(PyObject *self, PyObject *args) -{ - int n, m; - if (!PyArg_ParseTuple(args, "ii:xml_removeChild", &n, &m)) - return NULL; - int iok = xml_removeChild(n, m); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",iok); -} - - -static PyObject* -py_xml_write(PyObject *self, PyObject *args) -{ - int n; - char *file; - if (!PyArg_ParseTuple(args, "is:xml_write", &n, &file)) - return NULL; - int iok = xml_write(n, file); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",iok); -} - -static PyObject* -py_ctml_getFloatArray(PyObject *self, PyObject *args) -{ - int n; - int iconv, ia; - if (!PyArg_ParseTuple(args, "iii", &n, &iconv, &ia)) - return NULL; - - PyArrayObject* a = - (PyArrayObject*)PyArray_FromDims(1, &ia, PyArray_DOUBLE); - double* x = (double*)a->data; - int iok = ctml_getFloatArray(n, ia, x, iconv); - if (iok < 0) return reportError(iok); - return PyArray_Return(a); -} - -static PyMethodDef ct_methods[] = { - {"xml_attrib", py_xml_attrib, METH_VARARGS}, - {"xml_addAttrib", py_xml_addAttrib, METH_VARARGS}, - {"xml_tag", py_xml_tag, METH_VARARGS}, - {"xml_value", py_xml_value, METH_VARARGS}, - {"xml_new", py_xml_new, METH_VARARGS}, - {"xml_del", py_xml_del, METH_VARARGS}, - {"xml_build", py_xml_build, METH_VARARGS}, - {"xml_child", py_xml_child, METH_VARARGS}, - {"xml_childbynumber", py_xml_childbynumber, METH_VARARGS}, - {"xml_findID", py_xml_findID, METH_VARARGS}, - {"xml_findByName", py_xml_findByName, METH_VARARGS}, - {"xml_nChildren", py_xml_nChildren, METH_VARARGS}, - {"xml_addChild", py_xml_addChild, METH_VARARGS}, - {"xml_addChildNode", py_xml_addChildNode, METH_VARARGS}, - {"xml_removeChild", py_xml_removeChild, METH_VARARGS}, - {"xml_write", py_xml_write, METH_VARARGS}, - {"ctml_getFloatArray", py_ctml_getFloatArray, METH_VARARGS}, - {NULL, NULL} -}; - -extern "C" { - - /* Initialization function for the module */ - - DL_EXPORT(void) initctxml(void) - { - PyObject *m, *d; - - /* Initialize the type of the new type object here; doing it here - * is required for portability to Windows without requiring C++. */ - - /* Create the module and add the functions */ - m = Py_InitModule("ctxml", ct_methods); - import_array(); - - /* Add some symbolic constants to the module */ - d = PyModule_GetDict(m); - ErrorObject = PyErr_NewException("cantera.error", NULL, NULL); - PyDict_SetItemString(d, "error", ErrorObject); - } - -} - diff --git a/Cantera/python/src/ctsurf.cpp b/Cantera/python/src/ctsurf.cpp deleted file mode 100755 index 46f2ff7a0..000000000 --- a/Cantera/python/src/ctsurf.cpp +++ /dev/null @@ -1,575 +0,0 @@ -/** - * @file ctkinetics.cpp - * - */ - -// turn off warnings about long names under Windows -#ifdef WIN32 -#pragma warning(disable:4786) -#pragma warning(disable:4503) -#endif - - -#include "Python.h" -#include "Numeric/arrayobject.h" - -#include "ct.h" -#include "ctstagn.h" -#include -#include -#include - -using namespace std; - -// constants defined in the module -static PyObject *ErrorObject; - -// local includes -#include "pyutils.h" - -static PyObject * -py_flow_new(PyObject *self, PyObject *args) -{ - int itype, iph, np; - if (!PyArg_ParseTuple(args, "iii:flow_new", - &itype, &iph, &np)) - return NULL; - int nn = flow_new(itype,iph,np); - if (nn < 0) return reportError(nn); - return Py_BuildValue("i",nn); -} - -static PyObject* -py_flow_delete(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:flow_delete", &n)) return NULL; - flow_del(n); - return Py_BuildValue("i",0); -} - -// static PyObject* -// py_flow_newcopy(PyObject *self, PyObject *args) -// { -// int n; -// if (!PyArg_ParseTuple(args, "i:flow_newcopy", &n)) return NULL; -// return Py_BuildValue("i",flow_copy(n)); -// } - -// static PyObject* -// py_flow_assign(PyObject *self, PyObject *args) -// { -// int n, m; -// if (!PyArg_ParseTuple(args, "ii:flow_assign", &n, &m)) return NULL; -// return Py_BuildValue("i",flow_assign(n, m)); -// } - -// static PyObject* -// py_flow_readinputs(PyObject *self, PyObject *args) -// { -// int n; -// char* infile; -// if (!PyArg_ParseTuple(args, "is:flow_readinputs", &n, &infile)) -// return NULL; -// return Py_BuildValue("i",flow_readinputs(n,infile)); -// } - -static PyObject* -py_flow_setupgrid(PyObject *self, PyObject *args) -{ - int n; - PyObject* grid; - if (!PyArg_ParseTuple(args, "iO:flow_setupgrid", &n, &grid)) - return NULL; - - vector z; - int iok = pyNumericSequence_ToVector(grid, z); - if (iok == -1) { - PyErr_SetString(ErrorObject, "Third argument must be a sequence"); - return NULL; - } - if (iok == -2) { - PyErr_SetString(ErrorObject, - "Sequence must contain only numeric values"); - return NULL; - } - iok = flow_setupgrid(n, z.size(), z.begin()); - if (iok == -1) return reportCanteraError(); - else if (iok < 0) return NULL; - return Py_BuildValue("i",0); -} - -static PyObject* -py_flow_setkinetics(PyObject *self, PyObject *args) -{ - int nn,k; - if (!PyArg_ParseTuple(args, "ii:flow_setkinetics", &nn, &k)) return NULL; - return Py_BuildValue("i",flow_setkinetics(nn,k)); -} - -static PyObject* -py_flow_settransport(PyObject *self, PyObject *args) -{ - int nn,k,soret; - if (!PyArg_ParseTuple(args, "iii:flow_settransport", - &nn, &k, &soret)) return NULL; - return Py_BuildValue("i",flow_settransport(nn,k,soret)); -} - -static PyObject* -py_flow_setthermo(PyObject *self, PyObject *args) -{ - int nn,k; - if (!PyArg_ParseTuple(args, "ii:flow_setthermo", &nn, &k)) return NULL; - return Py_BuildValue("i",flow_setthermo(nn,k)); -} - -static PyObject* -py_flow_setpressure(PyObject *self, PyObject *args) -{ - int nn; - double p; - if (!PyArg_ParseTuple(args, "id:flow_setpressure", &nn, &p)) - return NULL; - return Py_BuildValue("i",flow_setpressure(nn,p)); -} - -static PyObject* -py_flow_setinletstate(PyObject *self, PyObject *args) -{ - int nn,gas; - if (!PyArg_ParseTuple(args, "ii:flow_setinletstate", &nn, &gas)) - return NULL; - return Py_BuildValue("i",flow_setinletstate(nn,gas)); -} - -static PyObject* -py_flow_setinlet_u(PyObject *self, PyObject *args) -{ - int nn; - double u; - if (!PyArg_ParseTuple(args, "id:flow_setinlet_u", &nn, &u)) - return NULL; - return Py_BuildValue("i",flow_setinlet_u(nn,u)); -} - -static PyObject* -py_flow_setinlet_v(PyObject *self, PyObject *args) -{ - int nn; - double v; - if (!PyArg_ParseTuple(args, "id:flow_setinlet_v", &nn, &v)) - return NULL; - return Py_BuildValue("i",flow_setinlet_v(nn,v)); -} - -static PyObject* -py_flow_setsurface_t(PyObject *self, PyObject *args) -{ - int nn; - double t; - if (!PyArg_ParseTuple(args, "id:flow_setsurface_t", &nn, &t)) - return NULL; - return Py_BuildValue("i",flow_setsurface_t(nn,t)); -} - -static PyObject* -py_flow_settemperature(PyObject *self, PyObject *args) -{ - int n, j; - double t; - if (!PyArg_ParseTuple(args, "iid:flow_settemperature", &n, &j, &t)) - return NULL; - return Py_BuildValue("i",flow_settemperature(n,j,t)); -} - -static PyObject* -py_flow_setmassfraction(PyObject *self, PyObject *args) -{ - int n, j, k; - double y; - if (!PyArg_ParseTuple(args, "iiid:flow_setinlet_v", &n, &j, &k, &y)) - return NULL; - return Py_BuildValue("i",flow_setmassfraction(n,j,k,y)); -} - -static PyObject* -py_flow_showsolution(PyObject *self, PyObject *args) -{ - int n; - char* fname; - PyObject* soln; - if (!PyArg_ParseTuple(args, "isO:flow_showsolution", &n, &fname, &soln)) - return NULL; - double* x = (double*)((PyArrayObject*)soln)->data; - return Py_BuildValue("i",flow_showsolution(n,fname,x)); -} - -static PyObject* -py_flow_solvespecies(PyObject *self, PyObject *args) -{ - int n, j, slen; - PyObject* s; - if (!PyArg_ParseTuple(args, "iiO:flow_solvespecies", &n, &slen, &s)) - return NULL; - double* x = (double*)((PyArrayObject*)s)->data; - for (int i = 0; i < slen; i++) { - if (x[i] <= 0.0) - flow_fixspecies(n, i); - else - flow_solvespecies(n, i); - } - return Py_BuildValue("i",0); -} - - -static PyObject* -py_flow_solve(PyObject *self, PyObject *args) -{ - int n, loglevel; - PyObject *s, *snew; - if (!PyArg_ParseTuple(args, "iOOi:flow_solve", &n, &s, &snew, &loglevel)) - return NULL; - double* x = (double*)((PyArrayObject*)s)->data; - double* xnew = (double*)((PyArrayObject*)snew)->data; - int iok = flow_solve(n,x,xnew,loglevel); - if (iok == -1) return reportCanteraError(); - return Py_BuildValue("i",iok); -} - -static PyObject* -py_flow_ssnorm(PyObject *self, PyObject *args) -{ - int n, loglevel; - PyObject *ps, *pr; - if (!PyArg_ParseTuple(args, "iOO:flow_solve", &n, &ps, &pr)) - return NULL; - double* x = (double*)((PyArrayObject*)ps)->data; - double* r = (double*)((PyArrayObject*)pr)->data; - double ss = flow_ssnorm(n,x,r); - return Py_BuildValue("d",ss); -} - - -static PyObject* -py_flow_timeinteg(PyObject *self, PyObject *args) -{ - int n, nsteps, loglevel; - double dt; - PyObject *s, *snew; - if (!PyArg_ParseTuple(args, "iidOOi:flow_solve", &n, &nsteps, &dt, - &s, &snew, &loglevel)) - return NULL; - double* x = (double*)((PyArrayObject*)s)->data; - double* xnew = (double*)((PyArrayObject*)snew)->data; - int iok = flow_timeinteg(n,nsteps,dt,x,xnew,loglevel); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",iok); -} - - -static PyObject* -py_copy(PyObject *self, PyObject *args) -{ - int n; - PyObject *s, *snew; - if (!PyArg_ParseTuple(args, "iOO:copy", &n, &s, &snew)) - return NULL; - double* x = (double*)((PyArrayObject*)s)->data; - double* xnew = (double*)((PyArrayObject*)snew)->data; - for (int i = 0; i < n; i++) xnew[i] = x[i]; - return Py_BuildValue("i",0); -} - - -static PyObject* -py_flow_settolerances(PyObject *self, PyObject *args) -{ - int n, nr, na; - PyObject *prtol, *patol; - if (!PyArg_ParseTuple(args, "iiOiO:flow_solve", &n, &nr, &prtol, - &na, &patol)) - return NULL; - double* rtol = (double*)((PyArrayObject*)prtol)->data; - double* atol = (double*)((PyArrayObject*)patol)->data; - int iok = flow_settolerances(n, nr, rtol, na, atol); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",iok); -} - - -static PyObject* -py_flow_eval(PyObject *self, PyObject *args) -{ - int n, j; - PyObject *px, *pr; - if (!PyArg_ParseTuple(args, "iiOO:flow_solve", &n, &j, &px, &pr)) - return NULL; - double* x = (double*)((PyArrayObject*)px)->data; - double* r = (double*)((PyArrayObject*)pr)->data; - int iok = flow_eval(n, j, x, r); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",iok); -} - - -static PyObject* -py_flow_integratechem(PyObject *self, PyObject *args) -{ - int n, j; - PyObject *px; - double dt; - if (!PyArg_ParseTuple(args, "iOd:flow_solve", &n, &px, &dt)) - return NULL; - double* x = (double*)((PyArrayObject*)px)->data; - int iok = flow_integratechem(n, x, dt); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",iok); -} - -static PyObject* -py_flow_outputtec(PyObject *self, PyObject *args) -{ - int n; - PyObject *px; - char *fname, *title; - int zone; - if (!PyArg_ParseTuple(args, "iOssi:flow_outputtec", &n, &px, - &fname, &title, &zone)) - return NULL; - double* x = (double*)((PyArrayObject*)px)->data; - int iok = flow_outputtec(n, x, fname, title, zone); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",iok); -} - -static PyObject* -py_flow_resize(PyObject *self, PyObject *args) -{ - int n, points; - PyObject *px; - if (!PyArg_ParseTuple(args, "ii:flow_resize", &n, &points)) - return NULL; - int iok = flow_resize(n, points); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",iok); -} - -static PyObject* -py_flow_energy(PyObject *self, PyObject *args) -{ - int n, j, flag, iok; - if (!PyArg_ParseTuple(args, "iii:flow_energy", &n, &j, &flag)) - return NULL; - if (flag == 1) - iok = flow_solveenergyeqn(n, j); - else - iok = flow_fixtemperature(n, j); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",iok); -} - -static PyObject* -py_flow_setnewtonoptions(PyObject *self, PyObject *args) -{ - int n, age; - double ratio; - if (!PyArg_ParseTuple(args, "iid:flow_setnewtonoptions", &n, &age, &ratio)) - return NULL; - int iok = flow_setnewtonoptions(n, age, ratio); - return Py_BuildValue("i",iok); -} - -static PyObject* -py_flow_setsteadymode(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:flow_setsteadymode", &n)) - return NULL; - int iok = flow_setsteadymode(n); - return Py_BuildValue("i",iok); -} - -static PyObject* -py_flow_settransientmode(PyObject *self, PyObject *args) -{ - int n; - double dt; - PyArrayObject* px; - if (!PyArg_ParseTuple(args, "idO:flow_settransientmode", &n, &dt, &px)) - return NULL; - double* x = (double*)((PyArrayObject*)px)->data; - int iok = flow_settransientmode(n, dt, x); - return Py_BuildValue("i",iok); -} - -static PyObject* -py_flow_setfixedpoint(PyObject *self, PyObject *args) -{ - int n, j0; - double t0; - if (!PyArg_ParseTuple(args, "iid:flow_setfixedpoint", &n, &j0, &t0)) - return NULL; - int iok = flow_setfixedpoint(n, j0, t0); - return Py_BuildValue("i",iok); -} - -static PyObject* -py_flow_save(PyObject *self, PyObject *args) -{ - int n; - char *fname, *id; - PyArrayObject* px; - if (!PyArg_ParseTuple(args, "issO:flow_solve", &n, &fname, &id, &px)) - return NULL; - double* x = (double*)((PyArrayObject*)px)->data; - int iok = flow_save(n, fname, id, x); - return Py_BuildValue("i",iok); -} - -static PyObject* -py_flow_restore(PyObject *self, PyObject *args) -{ - int n, job, iz, isoln; - char *fname, *id; - PyArrayObject *pz, *psoln; - if (!PyArg_ParseTuple(args, "iiss:flow_solve", - &n, &job, &fname, &id)) - return NULL; - int iok; - double *z=0, *soln=0; - - iok = flow_restore(n, -1, fname, id, iz, z, isoln, soln); - if (job < 0) { - return Py_BuildValue("(ii)",iz,isoln); - } - pz = (PyArrayObject*)PyArray_FromDims(1, &iz, PyArray_DOUBLE); - vector sdim(2); - sdim[0] = iz; - sdim[1] = isoln/iz; - psoln = (PyArrayObject*)PyArray_FromDims(2, sdim.begin(), PyArray_DOUBLE); - z = (double*)((PyArrayObject*)pz)->data; - soln = (double*)((PyArrayObject*)psoln)->data; - iok = flow_restore(n, 0, fname, id, iz, z, isoln, soln); - - return Py_BuildValue("(OO)",pz,psoln); -} - -static PyObject* -py_flow_setboundaries(PyObject *self, PyObject *args) -{ - int n, nleft, nright; - if (!PyArg_ParseTuple(args, "iii:flow_setboundaries", &n, &nleft, - &nright)) - return NULL; - int iok = flow_setboundaries(n, nleft, nright); - return Py_BuildValue("i",iok); -} - - -/* flow boundary objects */ - - -static PyObject * -py_bdry_new(PyObject *self, PyObject *args) -{ - int itype, ip; - if (!PyArg_ParseTuple(args, "ii:bdry_new", &itype, &ip)) - return NULL; - int nn = bdry_new(itype,ip); - if (nn < 0) return reportError(nn); - return Py_BuildValue("i",nn); -} - -static PyObject* -py_bdry_delete(PyObject *self, PyObject *args) -{ - int n; - if (!PyArg_ParseTuple(args, "i:bdry_delete", &n)) return NULL; - bdry_del(n); - return Py_BuildValue("i",0); -} - -static PyObject* -py_bdry_set(PyObject *self, PyObject *args) -{ - int n, i; - double v; - PyObject* px; - double* x; - if (!PyArg_ParseTuple(args, "iidO:bdry_set", &n, &i, &v, &px)) - return NULL; - if (i < 4) - bdry_set(n, i, &v); - else { - x = (double*)((PyArrayObject*)px)->data; - bdry_set(n, i, x); - } - return Py_BuildValue("i",0); -} - - -/* List of functions defined in the module */ - -static PyMethodDef ct_methods[] = { - {"Flow", py_flow_new, METH_VARARGS}, - {"flow_delete", py_flow_delete, METH_VARARGS}, - {"flow_setupgrid", py_flow_setupgrid, METH_VARARGS}, - {"flow_setthermo", py_flow_setthermo, METH_VARARGS}, - {"flow_setkinetics", py_flow_setkinetics, METH_VARARGS}, - {"flow_settransport", py_flow_settransport, METH_VARARGS}, - {"flow_setpressure", py_flow_setpressure, METH_VARARGS}, - {"flow_setinletstate", py_flow_setinletstate, METH_VARARGS}, - {"flow_setinlet_u", py_flow_setinlet_u, METH_VARARGS}, - {"flow_setinlet_v", py_flow_setinlet_v, METH_VARARGS}, - {"flow_setsurface_t", py_flow_setsurface_t, METH_VARARGS}, - {"flow_solvespecies", py_flow_solvespecies, METH_VARARGS}, - {"flow_settemperature", py_flow_settemperature, METH_VARARGS}, - {"flow_setmassfraction", py_flow_setmassfraction, METH_VARARGS}, - {"flow_settolerances", py_flow_settolerances, METH_VARARGS}, - {"flow_energy", py_flow_energy, METH_VARARGS}, - {"flow_showsolution", py_flow_showsolution, METH_VARARGS}, - {"flow_eval", py_flow_eval, METH_VARARGS}, - {"flow_solve", py_flow_solve, METH_VARARGS}, - {"flow_timeinteg", py_flow_timeinteg, METH_VARARGS}, - {"flow_integratechem", py_flow_integratechem, METH_VARARGS}, - {"flow_setnewtonoptions", py_flow_setnewtonoptions, METH_VARARGS}, - {"flow_resize", py_flow_resize, METH_VARARGS}, - {"flow_outputtec", py_flow_outputtec, METH_VARARGS}, - {"flow_setsteadymode", py_flow_setsteadymode, METH_VARARGS}, - {"flow_settransientmode", py_flow_settransientmode, METH_VARARGS}, - {"flow_save", py_flow_save, METH_VARARGS}, - {"flow_restore", py_flow_restore, METH_VARARGS}, - {"flow_setfixedpoint", py_flow_setfixedpoint, METH_VARARGS}, - {"flow_setboundaries", py_flow_setboundaries, METH_VARARGS}, - {"flow_ssnorm", py_flow_ssnorm, METH_VARARGS}, - {"copy", py_copy, METH_VARARGS}, - {"bdry_new", py_bdry_new, METH_VARARGS}, - {"bdry_del", py_bdry_delete, METH_VARARGS}, - {"bdry_set", py_bdry_set, METH_VARARGS}, - {NULL, NULL} /* sentinel */ -}; - - -extern "C" { - - /* Initialization function for the module (*must* be called initctflow) */ - - DL_EXPORT(void) initctflow(void) - { - PyObject *m, *d; - - /* Initialize the type of the new type object here; doing it here - * is required for portability to Windows without requiring C++. */ - - /* Create the module and add the functions */ - m = Py_InitModule("ctflow", ct_methods); - import_array(); - - /* Add some symbolic constants to the module */ - d = PyModule_GetDict(m); - ErrorObject = PyErr_NewException("cantera.error", NULL, NULL); - PyDict_SetItemString(d, "error", ErrorObject); - } - -} diff --git a/Cantera/python/src/ctsurf_methods.cpp b/Cantera/python/src/ctsurf_methods.cpp index 3d4ad201c..c04cf2d4a 100644 --- a/Cantera/python/src/ctsurf_methods.cpp +++ b/Cantera/python/src/ctsurf_methods.cpp @@ -58,7 +58,12 @@ py_surf_getcoverages(PyObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "i:surf_getcoverages", &n)) return NULL; int nsp = th_nSpecies(n); +#ifdef HAS_NUMPY + npy_intp nnsp = nsp; + cov = (PyArrayObject*)PyArray_SimpleNew(1, &nnsp, PyArray_DOUBLE); +#else cov = (PyArrayObject*)PyArray_FromDims(1, &nsp, PyArray_DOUBLE); +#endif double* x = (double*)((PyArrayObject*)cov)->data; int iok = surf_getcoverages(n, x); if (iok < 0) return reportError(iok); @@ -73,7 +78,12 @@ py_surf_getconcentrations(PyObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "i:surf_getconcentrations", &n)) return NULL; int nsp = th_nSpecies(n); +#ifdef HAS_NUMPY + npy_intp nnsp = nsp; + c = (PyArrayObject*)PyArray_SimpleNew(1, &nnsp, PyArray_DOUBLE); +#else c = (PyArrayObject*)PyArray_FromDims(1, &nsp, PyArray_DOUBLE); +#endif double* x = (double*)((PyArrayObject*)c)->data; int iok = surf_getconcentrations(n, x); if (iok < 0) return reportError(iok); diff --git a/Cantera/python/src/ctthermo.cpp b/Cantera/python/src/ctthermo.cpp deleted file mode 100755 index 6cad25512..000000000 --- a/Cantera/python/src/ctthermo.cpp +++ /dev/null @@ -1,294 +0,0 @@ -/** - * @file ctthermo.cpp - * Cantera Python Interface - * - */ - -// turn off warnings about long names under Windows -#ifdef WIN32 -#pragma warning(disable:4786) -#pragma warning(disable:4503) -#endif - -#include "Python.h" -#include "Numeric/arrayobject.h" -#include "ct.h" -#include -//#include -#include -using namespace std; - - -// constants defined in the module -static PyObject *ErrorObject; - -// local includes -#include "pyutils.h" - -static PyObject * -ct_newThermoFromXML(PyObject *self, PyObject *args) -{ - int mxml; - //char* id; - if (!PyArg_ParseTuple(args, "i:ct_newThermoFromXML", &mxml)) - return NULL; - int n = newThermoFromXML(mxml); - if (n < 0) return reportCanteraError(); - //int p = th_phase(n); - return Py_BuildValue("i",n); -} - -static PyObject* -thermo_delete(PyObject *self, PyObject *args) -{ - int th; - if (!PyArg_ParseTuple(args, "i:thermo_delete", &th)) - return NULL; - delThermo(th); - return Py_BuildValue("i",0); -} - -static PyObject* -thermo_index(PyObject *self, PyObject *args) { - char* id; - if (!PyArg_ParseTuple(args, "s:index", &id)) return NULL; - return Py_BuildValue("i",th_thermoIndex(id)); -} - -static PyObject* -thermo_refpressure(PyObject *self, PyObject *args) { - int th; - if (!PyArg_ParseTuple(args, "i:refpressure", &th)) return NULL; - return Py_BuildValue("d",th_refPressure(th)); -} - -static PyObject* -thermo_mintemp(PyObject *self, PyObject *args) { - int th, k; - if (!PyArg_ParseTuple(args, "ii:mintemp", &th, &k)) return NULL; - return Py_BuildValue("d",th_minTemp(th,k)); -} - -static PyObject* -thermo_maxtemp(PyObject *self, PyObject *args) { - int th, k; - if (!PyArg_ParseTuple(args, "ii:maxtemp", &th, &k)) return NULL; - return Py_BuildValue("d",th_maxTemp(th,k)); -} - -// static PyObject* -// thermo_geteos(PyObject *self, PyObject *args) { -// char *fname, *id; -// if (!PyArg_ParseTuple(args, "ss:geteos", &fname, &id)) return NULL; -// return Py_BuildValue("i",get_eos(fname, id)); -// } - -static PyObject* -thermo_import(PyObject *self, PyObject *args) { - int n, mxml; - char* id; - if (!PyArg_ParseTuple(args, "iis:import", &n, &mxml, &id)) return NULL; - int iok = import_phase(n, mxml, id); - if (iok < 0) return reportError(iok); - return Py_BuildValue("i",0); -} - - -static PyObject* -thermo_getfp(PyObject *self, PyObject *args) -{ - double vv; - bool ok = true; - int th; - int job; - - if (!PyArg_ParseTuple(args, "ii:thermo_getfp", &th, &job)) - return NULL; - - // floating-point attributes - switch (job) { - case 1: - vv = th_enthalpy_mole(th); break; - case 2: - vv = th_intEnergy_mole(th); break; - case 3: - vv = th_entropy_mole(th); break; - case 4: - vv = th_gibbs_mole(th); break; - case 5: - vv = th_cp_mole(th); break; - case 6: - vv = th_cv_mole(th); break; - case 7: - vv = th_pressure(th); break; - case 8: - vv = th_enthalpy_mass(th); break; - case 9: - vv = th_intEnergy_mass(th); break; - case 10: - vv = th_entropy_mass(th); break; - case 11: - vv = th_gibbs_mass(th); break; - case 12: - vv = th_cp_mass(th); break; - case 13: - vv = th_cv_mass(th); break; - default: - ok = false; - } - if (ok) { - if (vv == -999.999) { - return reportCanteraError(); - } - return Py_BuildValue("d",vv); - } - else { - PyErr_SetString(ErrorObject,"Unknown floating-point attribute"); - return NULL; - } -} - -static PyObject* -thermo_setfp(PyObject *self, PyObject *args) -{ - double v1, v2; - int iok = -2; - int th; - int job; - - if (!PyArg_ParseTuple(args, "iidd:thermo_setfp", &th, &job, &v1, &v2)) - return NULL; - - //vector_fp v(2); - double* v = new double[2]; - v[0] = v1; v[1] = v2; - - // set floating-point attributes - switch (job) { - case 1: - iok = th_setPressure(th, v1); break; - case 2: - iok = th_set_HP(th, v); break; - case 3: - iok = th_set_UV(th, v); break; - case 4: - iok = th_set_SV(th, v); break; - case 5: - iok = th_set_SP(th, v); break; - default: - iok = -10; - } - delete v; - if (iok >= 0) - return Py_BuildValue("i",iok); - if (iok == -1) return reportCanteraError(); - else { - PyErr_SetString(ErrorObject,"Error in thermo_setfp"); - return NULL; - } -} - - -static PyObject* -thermo_getarray(PyObject *self, PyObject *args) -{ - int th; - int job; - - if (!PyArg_ParseTuple(args, "ii:thermo_getarray", &th, &job)) - return NULL; - - int nsp = th_nSpecies(th); - - // array attributes - int iok = -22; - PyArrayObject* x = - (PyArrayObject*)PyArray_FromDims(1, &nsp, PyArray_DOUBLE); - double* xd = (double*)x->data; - switch (job) { - case 20: - iok = th_chemPotentials(th,nsp,xd); - break; - case 23: - iok = th_getEnthalpies_RT(th,nsp,xd); - break; - case 24: - iok = th_getEntropies_R(th,nsp,xd); - break; - case 25: - iok = th_getCp_R(th,nsp,xd); - break; - - default: - ; - } - if (iok >= 0) { - return PyArray_Return(x); - } - else { - PyErr_SetString(ErrorObject,"Unknown array attribute"); - return NULL; - } -} - - -static PyObject* -thermo_equil(PyObject *self, PyObject *args) -{ - int iok = -2; - int th; - int XY; - - if (!PyArg_ParseTuple(args, "ii:thermo_equil", &th, &XY)) - return NULL; - - iok = th_equil(th, XY); - if (iok >= 0) - return Py_BuildValue("i",iok); - if (iok == -1) return reportCanteraError(); - else { - PyErr_SetString(ErrorObject,"Error in thermo_equil"); - return NULL; - } -} - -/* List of functions defined in the module */ - -static PyMethodDef ct_methods[] = { - {"ThermoFromXML", ct_newThermoFromXML, METH_VARARGS}, - {"delete", thermo_delete, METH_VARARGS}, - {"mintemp", thermo_mintemp, METH_VARARGS}, - {"maxtemp", thermo_maxtemp, METH_VARARGS}, - {"thermoIndex", thermo_index, METH_VARARGS}, - {"refpressure", thermo_refpressure, METH_VARARGS}, - {"getfp", thermo_getfp, METH_VARARGS}, - {"setfp", thermo_setfp, METH_VARARGS}, - {"getarray", thermo_getarray, METH_VARARGS}, - {"equil", thermo_equil, METH_VARARGS}, - {"import_xml", thermo_import, METH_VARARGS}, - {NULL, NULL} /* sentinel */ -}; - - -extern "C" { - - /* Initialization function for the module (*must* be called initctthermo) */ - - DL_EXPORT(void) initctthermo(void) - { - PyObject *m, *d; - - /* Initialize the type of the new type object here; doing it here - * is required for portability to Windows without requiring C++. */ - - /* Create the module and add the functions */ - m = Py_InitModule("ctthermo", ct_methods); - import_array(); - - /* Add some symbolic constants to the module */ - d = PyModule_GetDict(m); - ErrorObject = PyErr_NewException("cantera.error", NULL, NULL); - PyDict_SetItemString(d, "error", ErrorObject); - } - -} diff --git a/Cantera/python/src/ctthermo_methods.cpp b/Cantera/python/src/ctthermo_methods.cpp index 50dd2fe75..d1a79953b 100644 --- a/Cantera/python/src/ctthermo_methods.cpp +++ b/Cantera/python/src/ctthermo_methods.cpp @@ -194,8 +194,15 @@ thermo_getarray(PyObject *self, PyObject *args) // array attributes int iok = -22; +#ifdef HAS_NUMPY + npy_intp nnn = xlen; + PyArrayObject* x = + (PyArrayObject*)PyArray_SimpleNew(1, &nnn, PyArray_DOUBLE); + Py_INCREF(x); +#else PyArrayObject* x = (PyArrayObject*)PyArray_FromDims(1, &xlen, PyArray_DOUBLE); +#endif double* xd = (double*)x->data; switch (job) { case 20: diff --git a/Cantera/python/src/cttransport.cpp b/Cantera/python/src/cttransport.cpp deleted file mode 100755 index fa9df831e..000000000 --- a/Cantera/python/src/cttransport.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/** - * @file cttransport.cpp - * Cantera Python Interface - * - */ - -// turn off warnings about long names under Windows -#ifdef WIN32 -#pragma warning(disable:4786) -#pragma warning(disable:4503) -#endif - -#include "Python.h" -#include "Numeric/arrayobject.h" -#include "ct.h" -#include -//#include -#include -using namespace std; - -//#include "Cantera.h" - -// constants defined in the module -static PyObject *ErrorObject; - -// local includes -#include "pyutils.h" - - - -/** - * Create a new Transport object. - */ -static PyObject * -py_transport_new(PyObject *self, PyObject *args) { - char* model; - int ph; - int loglevel; - if (!PyArg_ParseTuple(args, "sii:transport_new", &model, - &ph, &loglevel)) - return NULL; - int n = newTransport(model, ph, loglevel); - if (n < 0) return reportError(n); - return Py_BuildValue("i",n); -} - - -/** - * Delete the Phase object. - */ -static PyObject* -py_transport_delete(PyObject *self, PyObject *args) -{ - int tr; - if (!PyArg_ParseTuple(args, "i:transport_delete", &tr)) - return NULL; - delTransport(tr); - return Py_BuildValue("i",0); -} - - -static PyObject* -py_viscosity(PyObject *self, PyObject *args) { - int n; - if (!PyArg_ParseTuple(args, "i:py_viscosity", &n)) return NULL; - double mu = trans_viscosity(n); - if (mu < 0.0) return reportError(int(mu)); - return Py_BuildValue("d",mu); -} - -static PyObject* -py_thermalConductivity(PyObject *self, PyObject *args) { - int n; - if (!PyArg_ParseTuple(args, "i:py_thermalConductivity", &n)) return NULL; - double lambda = trans_thermalConductivity(n); - if (lambda < 0.0) return reportError(int(lambda)); - return Py_BuildValue("d",lambda); -} - -static PyObject* -py_thermalDiffCoeffs(PyObject *self, PyObject *args) { - int n, idt; - if (!PyArg_ParseTuple(args, "ii:py_thermalDiffCoeffs", &n, &idt)) - return NULL; - PyArrayObject* dt = - (PyArrayObject*)PyArray_FromDims(1, &idt, PyArray_DOUBLE); - int iok = trans_getThermalDiffCoeffs(n, idt, (double*)dt->data); - if (iok < 0) return reportError(iok); - return PyArray_Return(dt); -} - -static PyObject* -py_binaryDiffCoeffs(PyObject *self, PyObject *args) { - int n, id; - if (!PyArg_ParseTuple(args, "ii:py_binaryDiffCoeffs", &n, &id)) - return NULL; - int idim[2]; - idim[0] = id; - idim[1] = id; - PyArrayObject* d = - (PyArrayObject*)PyArray_FromDims(2, idim, PyArray_DOUBLE); - int iok = trans_getBinDiffCoeffs(n, id, (double*)d->data); - if (iok < 0) return reportError(iok); - return PyArray_Return(d); -} - -static PyObject* -py_mixDiffCoeffs(PyObject *self, PyObject *args) { - int n, id; - if (!PyArg_ParseTuple(args, "ii:py_mixDiffCoeffs", &n, &id)) - return NULL; - PyArrayObject* d = - (PyArrayObject*)PyArray_FromDims(1, &id, PyArray_DOUBLE); - int iok = trans_getMixDiffCoeffs(n, id, (double*)d->data); - if (iok < 0) return reportError(iok); - return PyArray_Return(d); -} - -static PyObject* -py_multiDiffCoeffs(PyObject *self, PyObject *args) { - int n, id; - if (!PyArg_ParseTuple(args, "ii:py_multiDiffCoeffs", &n, &id)) - return NULL; - //vector_int idim(2,id); - int idim[2]; - idim[0] = id; - idim[1] = id; - PyArrayObject* d = - (PyArrayObject*)PyArray_FromDims(2, idim, PyArray_DOUBLE); - int iok = trans_getMultiDiffCoeffs(n, id, (double*)d->data); - if (iok < 0) return reportError(iok); - return PyArray_Return(d); -} - - -/* List of functions defined in the module */ - -static PyMethodDef ct_methods[] = { - {"Transport", py_transport_new, METH_VARARGS}, - {"delete", py_transport_delete, METH_VARARGS}, - {"viscosity", py_viscosity, METH_VARARGS}, - {"thermalConductivity", py_thermalConductivity, METH_VARARGS}, - {"thermalDiffCoeffs", py_thermalDiffCoeffs, METH_VARARGS}, - {"binaryDiffCoeffs", py_binaryDiffCoeffs, METH_VARARGS}, - {"mixDiffCoeffs", py_mixDiffCoeffs, METH_VARARGS}, - {"multiDiffCoeffs", py_multiDiffCoeffs, METH_VARARGS}, - {NULL, NULL} /* sentinel */ -}; - - -extern "C" { - - /* Initialization function for the module (*must* be called initcttransport) */ - - DL_EXPORT(void) initcttransport(void) - { - PyObject *m, *d; - - /* Initialize the type of the new type object here; doing it here - * is required for portability to Windows without requiring C++. */ - - /* Create the module and add the functions */ - m = Py_InitModule("cttransport", ct_methods); - import_array(); - - /* Add some symbolic constants to the module */ - d = PyModule_GetDict(m); - ErrorObject = PyErr_NewException("cantera.error", NULL, NULL); - PyDict_SetItemString(d, "error", ErrorObject); - } -} diff --git a/Cantera/python/src/cttransport_methods.cpp b/Cantera/python/src/cttransport_methods.cpp index 1f7c0d125..8e10d9001 100644 --- a/Cantera/python/src/cttransport_methods.cpp +++ b/Cantera/python/src/cttransport_methods.cpp @@ -70,8 +70,14 @@ py_thermalDiffCoeffs(PyObject *self, PyObject *args) { int n, idt; if (!PyArg_ParseTuple(args, "ii:py_thermalDiffCoeffs", &n, &idt)) return NULL; +#ifdef HAS_NUMPY + npy_intp nidt = idt; + PyArrayObject* dt = + (PyArrayObject*)PyArray_SimpleNew(1, &nidt, PyArray_DOUBLE); +#else PyArrayObject* dt = (PyArrayObject*)PyArray_FromDims(1, &idt, PyArray_DOUBLE); +#endif int iok = trans_getThermalDiffCoeffs(n, idt, (double*)dt->data); if (iok < 0) return reportError(iok); return PyArray_Return(dt); @@ -82,11 +88,17 @@ py_binaryDiffCoeffs(PyObject *self, PyObject *args) { int n, id; if (!PyArg_ParseTuple(args, "ii:py_binaryDiffCoeffs", &n, &id)) return NULL; +#ifdef HAS_NUMPY + npy_intp idim[2]; + idim[0] = id; + idim[1] = id; + PyArrayObject* d = (PyArrayObject*)PyArray_SimpleNew(2, idim, PyArray_DOUBLE); +#else int idim[2]; idim[0] = id; idim[1] = id; - PyArrayObject* d = - (PyArrayObject*)PyArray_FromDims(2, idim, PyArray_DOUBLE); + PyArrayObject* d = (PyArrayObject*)PyArray_FromDims(2, idim, PyArray_DOUBLE); +#endif int iok = trans_getBinDiffCoeffs(n, id, (double*)d->data); if (iok < 0) return reportError(iok); return PyArray_Return(d); @@ -97,8 +109,12 @@ py_mixDiffCoeffs(PyObject *self, PyObject *args) { int n, id; if (!PyArg_ParseTuple(args, "ii:py_mixDiffCoeffs", &n, &id)) return NULL; - PyArrayObject* d = - (PyArrayObject*)PyArray_FromDims(1, &id, PyArray_DOUBLE); +#ifdef HAS_NUMPY + npy_intp nid = id; + PyArrayObject* d = (PyArrayObject*)PyArray_SimpleNew(1, &nid, PyArray_DOUBLE); +#else + PyArrayObject* d = (PyArrayObject*)PyArray_FromDims(1, &id, PyArray_DOUBLE); +#endif int iok = trans_getMixDiffCoeffs(n, id, (double*)d->data); if (iok < 0) return reportError(iok); return PyArray_Return(d); @@ -110,11 +126,17 @@ py_multiDiffCoeffs(PyObject *self, PyObject *args) { if (!PyArg_ParseTuple(args, "ii:py_multiDiffCoeffs", &n, &id)) return NULL; //vector_int idim(2,id); +#ifdef HAS_NUMPY + npy_intp idim[2]; + idim[0] = id; + idim[1] = id; + PyArrayObject* d = (PyArrayObject*)PyArray_SimpleNew(2, idim, PyArray_DOUBLE); +#else int idim[2]; idim[0] = id; idim[1] = id; - PyArrayObject* d = - (PyArrayObject*)PyArray_FromDims(2, idim, PyArray_DOUBLE); + PyArrayObject* d = (PyArrayObject*)PyArray_FromDims(2, idim, PyArray_DOUBLE); +#endif int iok = trans_getMultiDiffCoeffs(n, id, (double*)d->data); if (iok < 0) return reportError(iok); return PyArray_Return(d); @@ -132,14 +154,14 @@ py_getMolarFluxes(PyObject *self, PyObject *args) { PyArrayObject* state2array = (PyArrayObject*)state2; double* d1 = (double*)state1array->data; double* d2 = (double*)state2array->data; +#ifdef HAS_NUMPY + npy_intp nid = id; + PyArrayObject* f = (PyArrayObject*)PyArray_SimpleNew(1, &nid, PyArray_DOUBLE); +#else PyArrayObject* f = (PyArrayObject*)PyArray_FromDims(1, &id, PyArray_DOUBLE); +#endif double* fd = (double*)f->data; int iok = trans_getMolarFluxes(n, d1, d2, delta, fd); if (iok < 0) return reportError(iok); return PyArray_Return(f); } - - - - - diff --git a/Cantera/python/src/ctxml_methods.cpp b/Cantera/python/src/ctxml_methods.cpp index 6527a1712..518ed6489 100644 --- a/Cantera/python/src/ctxml_methods.cpp +++ b/Cantera/python/src/ctxml_methods.cpp @@ -225,13 +225,17 @@ py_ctml_getFloatArray(PyObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "iii", &n, &iconv, &ia)) return NULL; +#ifdef HAS_NUMPY + npy_intp nia = ia; + PyArrayObject* a = + (PyArrayObject*)PyArray_SimpleNew(1, &nia, PyArray_DOUBLE); +#else PyArrayObject* a = (PyArrayObject*)PyArray_FromDims(1, &ia, PyArray_DOUBLE); +#endif double* x = (double*)a->data; int iok = ctml_getFloatArray(n, ia, x, iconv); if (iok < 0) return reportError(iok); return PyArray_Return(a); } - - diff --git a/Cantera/python/src/reactionpath.cpp b/Cantera/python/src/reactionpath.cpp deleted file mode 100755 index 3e6facb4a..000000000 --- a/Cantera/python/src/reactionpath.cpp +++ /dev/null @@ -1,71 +0,0 @@ - -/* Cantera objects */ - -#ifdef WIN32 -#pragma warning(disable:4786) -#endif - -#include "Python.h" -#include "Cantera.h" -#include -using namespace std; - -static PyObject *ErrorObject; - -#include "pyutils.h" - -static PyObject * -ct_newCtRxnPath(PyObject *self, PyObject *args) -{ - CtRxnPath *rv; - PyObject* s; - if (!PyArg_ParseTuple(args, "O:newCtRxnPath", &s)) - return NULL; - if (!CtSubstance_check(s)) { - PyErr_SetString(ErrorObject, "argument must be of type CtSubstance"); - } - ReactingSubstance* g = s->g; - rv = newCtRxnPath(g); - if ( rv == NULL ) return NULL; - return (PyObject *)rv; -} - - -/* List of functions defined in the module */ - -static PyMethodDef ct_methods[] = { - {"Substance", ct_newSubstance, METH_VARARGS}, - {"CKGas", ct_newSubstance, METH_VARARGS}, - {"Substance", ct_newSubstance, METH_VARARGS}, - {NULL, NULL} /* sentinel */ -}; - - -extern "C" { - - /* Initialization function for the module (*must* be called initcantera) */ - - DL_EXPORT(void) - initcantera(void) - { - PyObject *m, *d; - - CtSubstance::init(); - - /* Initialize the type of the new type object here; doing it here - * is required for portability to Windows without requiring C++. */ - CtSubstance_Type.ob_type = &PyType_Type; - CtSubstance_Type.tp_dealloc = (destructor)CtSubstance_dealloc; - CtSubstance_Type.tp_getattr = (getattrfunc)CtSubstance_getattr; - CtSubstance_Type.tp_setattr = (setattrfunc)CtSubstance_setattr; - - /* Create the module and add the functions */ - m = Py_InitModule("cantera", ct_methods); - - /* Add some symbolic constants to the module */ - d = PyModule_GetDict(m); - ErrorObject = PyErr_NewException("cantera.error", NULL, NULL); - PyDict_SetItemString(d, "error", ErrorObject); - } - -} diff --git a/Cantera/python/src/writelog.cpp b/Cantera/python/src/writelog.cpp deleted file mode 100644 index 745d7d973..000000000 --- a/Cantera/python/src/writelog.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "Python.h" -#include -#include "../../src/logger.h" - -using namespace std; - -static std::string ss = "print \"\"\" "; - -namespace Cantera { - - class Py_Logger : public Logger { - public: - Py_Logger() { cout << "created Py_Logger" << endl;} - virtual ~Py_Logger() {} - - virtual void write(const string& s) { - cout << "write..." << endl; - char ch = s[0]; - int n = 0; - while (ch != '\0') { - if (ch =='\n') { - ss += "\"\"\""; - PyRun_SimpleString((char *)ss.c_str()); - ss = "print \"\"\""; - } - else - ss += ch; - n++; - ch = s[n]; - } - } - - virtual void error(const std::string& msg) { - string err = "raise \""+msg+"\""; - PyRun_SimpleString((char *)err.c_str()); - } - - virtual int env() { - return 2; - } - }; -} -