Cleaned up some of the Matlab extension code

This commit is contained in:
Ray Speth 2012-03-15 19:51:45 +00:00
parent d8edde0264
commit 83e1996295
11 changed files with 52 additions and 116 deletions

View file

@ -61,7 +61,7 @@ std::string ArraySizeError::getMessage() const {
std::string IndexError::getMessage() const {
std::stringstream ss;
ss << "IndexError: " << arrayName_ << "[" << m_ << "]" <<
" outside valid range of 0 to " << (mmax_-1) << ".";
" outside valid range of 0 to " << (mmax_) << ".";
return ss.str();
}

View file

@ -153,28 +153,25 @@ void mixturemethods(int nlhs, mxArray* plhs[],
int iok = 0;
mwSize nsp = (mwSize) mix_nSpecies(i);
double* x = new double[nsp];
std::vector<double> x(nsp);
switch (job) {
case 41:
iok = mix_getChemPotentials(i,nsp,x);
iok = mix_getChemPotentials(i,nsp, &x[0]);
break;
default:
;
}
plhs[0] = mxCreateNumericMatrix(nsp,1,
mxDOUBLE_CLASS,mxREAL);
plhs[0] = mxCreateNumericMatrix(nsp,1, mxDOUBLE_CLASS,mxREAL);
double* h = mxGetPr(plhs[0]);
if (iok >= 0) {
for (int i = 0; i < nsp; i++) {
h[i] = x[i];
}
delete x;
return;
} else {
for (int i = 0; i < nsp; i++) {
h[i] = -999.99;
}
delete x;
mexErrMsgTxt("unknown attribute");
return;
}

View file

@ -5,12 +5,6 @@
#include <clib/ctonedim.h>
using namespace std;
namespace Cantera
{
void writelog(const std::string& s);
}
using namespace Cantera;
void onedimmethods(int nlhs, mxArray* plhs[],
@ -28,12 +22,12 @@ void onedimmethods(int nlhs, mxArray* plhs[],
int idom, icomp, localPoint;
if (job < 10) {
int ph, kin, tr, itype, *ptrs;
int ph, kin, tr, itype;
size_t sz, nd;
switch (job) {
// construct a new stagnation flow instance
// construct a new stagnation flow instance
case 1:
checkNArgs(7, nrhs);
ph = getInt(prhs[3]);
@ -43,40 +37,39 @@ void onedimmethods(int nlhs, mxArray* plhs[],
indx = stflow_new(ph, kin, tr, itype);
break;
// construct a new Inlet1D instance
// construct a new Inlet1D instance
case 2:
checkNArgs(3, nrhs);
indx = inlet_new();
break;
// construct a new Surf1D instance
// construct a new Surf1D instance
case 3:
checkNArgs(3, nrhs);
indx = surf_new();
break;
// construct a new Symm1D instance
// construct a new Symm1D instance
case 4:
checkNArgs(3, nrhs);
indx = symm_new();
break;
// construct a new Outlet1D instance
// construct a new Outlet1D instance
case 5:
checkNArgs(3, nrhs);
indx = outlet_new();
break;
// construct a new ReactingSurf1D instance
// construct a new ReactingSurf1D instance
case 6:
checkNArgs(4, nrhs);
indx = reactingsurf_new();
reactingsurf_setkineticsmgr(indx, getInt(prhs[3]));
break;
// construct a new Sim1D instance
case 8:
//writelog("case 8\n");
// construct a new Sim1D instance
case 8: {
checkNArgs(5, nrhs);
nd = getInt(prhs[3]);
dom_ids = mxGetPr(prhs[4]);
@ -87,20 +80,15 @@ void onedimmethods(int nlhs, mxArray* plhs[],
mexErrMsgTxt("wrong size for domain array");
}
ptrs = new int[sz];
//writelog("allocated ptrs\n");
std::vector<int> ptrs(sz);
for (size_t k = 0; k < sz; k++) {
// writelog("k = ...\n");
ptrs[k] = int(dom_ids[k]);
}
//writelog("calling sim1D_new\n");
indx = sim1D_new(sz, ptrs);
//writelog("deleting ptrs\n");
delete[] ptrs;
//writelog("done\n");
indx = sim1D_new(sz, &ptrs[0]);
break;
}
// construct a new OutletRes1D instance
// construct a new OutletRes1D instance
case -2:
checkNArgs(3,nrhs);
indx = outletres_new();
@ -119,15 +107,11 @@ void onedimmethods(int nlhs, mxArray* plhs[],
return;
}
// methods
else if (job < 40) {
int k;
switch (job) {
case 10:
checkNArgs(3, nrhs);
vv = domain_del(dom);
@ -226,9 +210,7 @@ void onedimmethods(int nlhs, mxArray* plhs[],
}
}
// set parameters
else {
int iok = -1;
double lower, upper, rtol, atol, *grid, *pos, *values,
@ -236,7 +218,7 @@ void onedimmethods(int nlhs, mxArray* plhs[],
rdt, prune;
size_t npts, np, nv;
int comp, localPoint, idom,
loglevel, refine_grid, n, flag, itime, ns, *nsteps, icount,
loglevel, refine_grid, n, flag, itime, ns, icount,
onoff, ss_age, ts_age;
char* xstr, *fname, *id, *desc, *name;
switch (job) {
@ -280,7 +262,6 @@ void onedimmethods(int nlhs, mxArray* plhs[],
xstr = getString(prhs[3]);
iok = bdry_setMoleFractions(dom, xstr);
break;
case 63:
checkNArgs(4, nrhs);
p = getDouble(prhs[3]);
@ -304,7 +285,6 @@ void onedimmethods(int nlhs, mxArray* plhs[],
flag = getInt(prhs[3]);
iok = stflow_solveEnergyEqn(dom, flag);
break;
case 100:
checkNArgs(7, nrhs);
idom = getInt(prhs[3]) - 1;
@ -353,8 +333,7 @@ void onedimmethods(int nlhs, mxArray* plhs[],
slope = getDouble(prhs[5]);
curve = getDouble(prhs[6]);
prune = getDouble(prhs[7]);
iok = sim1D_setRefineCriteria(dom, idom,
ratio, slope, curve, prune);
iok = sim1D_setRefineCriteria(dom, idom, ratio, slope, curve, prune);
break;
case 107:
iok = 0;
@ -387,17 +366,17 @@ void onedimmethods(int nlhs, mxArray* plhs[],
id = getString(prhs[4]);
iok = sim1D_restore(dom, fname, id);
break;
case 112:
case 112: {
tstep = getDouble(prhs[3]);
ns = getInt(prhs[4]);
dts = mxGetPr(prhs[5]);
nsteps = new int[ns];
std::vector<int> nsteps(ns);
for (n = 0; n < ns; n++) {
nsteps[n] = int(dts[n]);
}
iok = sim1D_setTimeStep(dom, tstep, ns, nsteps);
delete[] nsteps;
iok = sim1D_setTimeStep(dom, tstep, ns, &nsteps[0]);
break;
}
case 113:
checkNArgs(5, nrhs);
rdt = getDouble(prhs[3]);
@ -410,11 +389,6 @@ void onedimmethods(int nlhs, mxArray* plhs[],
ts_age = getInt(prhs[4]);
iok = sim1D_setMaxJacAge(dom, ss_age, ts_age);
break;
//case 200:
//iok = domain1D_clear();
//iok = sim1D_clear();
//break;
case 120:
checkNArgs(4, nrhs);
onoff = getInt(prhs[3]);

View file

@ -89,8 +89,7 @@ void phasemethods(int nlhs, mxArray* plhs[],
input_buf = (char*)mxCalloc(buflen, sizeof(char));
status = mxGetString(prhs[3], input_buf, buflen);
if (status != 0)
mexWarnMsgTxt("Not enough space. "
"String is truncated.");
mexWarnMsgTxt("Not enough space. " "String is truncated.");
switch (mjob) {
case 30:
@ -134,18 +133,18 @@ void phasemethods(int nlhs, mxArray* plhs[],
vv = 1.0/phase_density(ph);
break;
case 10:
vv = (double) phase_nElements(ph);
vv = static_cast<int>(phase_nElements(ph));
break;
case 11:
vv = (double) phase_nSpecies(ph);
vv = static_cast<int>(phase_nSpecies(ph));
break;
case 12:
input_buf = getString(prhs[3]);
vv = (double) phase_speciesIndex(ph, input_buf) + 1;
vv = static_cast<int>(phase_speciesIndex(ph, input_buf)) + 1;
break;
case 13:
input_buf = getString(prhs[3]);
vv = (double) phase_elementIndex(ph, input_buf) + 1;
vv = static_cast<int>(phase_elementIndex(ph, input_buf)) + 1;
break;
case 14:
k = getInt(prhs[3]);
@ -160,7 +159,7 @@ void phasemethods(int nlhs, mxArray* plhs[],
ok = false;
}
if (ok) {
if (vv == DERR) {
if (vv == DERR || vv == -1 || vv == ERR) {
reportError();
}
plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL);
@ -169,71 +168,62 @@ void phasemethods(int nlhs, mxArray* plhs[],
return;
}
}
//ok = true;
else if (job < 30) {
iok = 0;
size_t nsp = phase_nSpecies(ph);
double* x = new double[nsp];
std::vector<double> x(nsp);
switch (job) {
case 20:
iok = phase_getMoleFractions(ph,nsp,x);
iok = phase_getMoleFractions(ph,nsp, &x[0]);
break;
case 21:
iok = phase_getMassFractions(ph,nsp,x);
iok = phase_getMassFractions(ph,nsp, &x[0]);
break;
case 22:
iok = phase_getMolecularWeights(ph,nsp,x);
iok = phase_getMolecularWeights(ph,nsp, &x[0]);
break;
default:
;
}
plhs[0] = mxCreateNumericMatrix((mwSize) nsp,1,
mxDOUBLE_CLASS,mxREAL);
plhs[0] = mxCreateNumericMatrix((mwSize) nsp, 1, mxDOUBLE_CLASS, mxREAL);
double* h = mxGetPr(plhs[0]);
if (iok >= 0) {
for (size_t i = 0; i < nsp; i++) {
h[i] = x[i];
}
delete x;
return;
} else {
for (size_t i = 0; i < nsp; i++) {
h[i] = -999.99;
}
delete x;
mexErrMsgTxt("unknown attribute");
return;
}
}
else if (job < 40) {
iok = 0;
size_t nel = phase_nElements(ph);
double* x = new double[nel];
std::vector<double> x(nel);
switch (job) {
case 30:
iok = phase_getAtomicWeights(ph,nel,x);
iok = phase_getAtomicWeights(ph,nel, &x[0]);
break;
default:
;
}
plhs[0] = mxCreateNumericMatrix((mwSize) nel,1,
mxDOUBLE_CLASS,mxREAL);
plhs[0] = mxCreateNumericMatrix((mwSize) nel, 1, mxDOUBLE_CLASS, mxREAL);
double* h = mxGetPr(plhs[0]);
if (iok >= 0) {
for (size_t i = 0; i < nel; i++) {
h[i] = x[i];
}
delete x;
return;
} else {
for (size_t i = 0; i < nel; i++) {
h[i] = -999.99;
}
delete x;
mexErrMsgTxt("unknown attribute");
return;
}
@ -269,7 +259,6 @@ void phasemethods(int nlhs, mxArray* plhs[],
plhs[0] = mxCreateString(output_buf);
return;
} else {
mexErrMsgTxt("error or unknown method.");
reportError();
return;
}

View file

@ -36,7 +36,6 @@ void reactormethods(int nlhs, mxArray* plhs[],
if (job < 20) {
switch (job) {
case 1:
iok = reactor_del(i);
break;
@ -117,7 +116,7 @@ void reactormethods(int nlhs, mxArray* plhs[],
plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL);
double* h = mxGetPr(plhs[0]);
*h = r;
if (r == Undef) {
if (r == DERR) {
reportError();
}
return;

View file

@ -100,7 +100,7 @@ void reactornetmethods(int nlhs, mxArray* plhs[],
plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL);
double* h = mxGetPr(plhs[0]);
*h = r;
if (r == Undef) {
if (r == DERR) {
reportError();
}
return;

View file

@ -7,10 +7,6 @@
using namespace std;
namespace Cantera
{
void writelog(const std::string& s);
}
using namespace Cantera;
void surfmethods(int nlhs, mxArray* plhs[],
@ -69,15 +65,15 @@ void surfmethods(int nlhs, mxArray* plhs[],
// return array parameters
else if (job < 200) {
nsp = phase_nSpecies(surf);
double* x = new double[nsp];
std::vector<double> x(nsp);
switch (job) {
case 101:
checkNArgs(3,nrhs);
iok = surf_getcoverages(surf,x);
iok = surf_getcoverages(surf, &x[0]);
break;
case 103:
iok = surf_getconcentrations(surf,x);
iok = surf_getconcentrations(surf, &x[0]);
break;
default:
;
@ -89,13 +85,11 @@ void surfmethods(int nlhs, mxArray* plhs[],
for (size_t i = 0; i < nsp; i++) {
h[i] = x[i];
}
delete x;
return;
} else {
for (size_t i = 0; i < nsp; i++) {
h[i] = -999.99;
}
delete x;
reportError();
return;
}

View file

@ -8,10 +8,6 @@
static void thermoset(int nlhs, mxArray* plhs[],
int nrhs, const mxArray* prhs[])
{
//if (nrhs != 4) {
// mexErrMsgTxt("wrong number of input parameters.");
//}
int ierr = 0;
int th = getInt(prhs[1]);
int job = -getInt(prhs[2]);
@ -76,7 +72,7 @@ static void thermoset(int nlhs, mxArray* plhs[],
// equilibrate
else if (job == 50) {
char* xy = getString(prhs[3]); //int(*ptr);
char* xy = getString(prhs[3]);
int solver = getInt(prhs[4]);
double rtol = getDouble(prhs[5]);
int maxsteps = getInt(prhs[6]);
@ -102,7 +98,6 @@ static void thermoget(int nlhs, mxArray* plhs[],
int job = getInt(prhs[2]);
if (job < 30) {
bool ok = true;
switch (job) {
case 0:
@ -191,46 +186,42 @@ static void thermoget(int nlhs, mxArray* plhs[],
if (vv == DERR) {
reportError();
}
plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL);
plhs[0] = mxCreateNumericMatrix(1, 1, mxDOUBLE_CLASS, mxREAL);
double* h = mxGetPr(plhs[0]);
*h = vv;
return;
}
} else if (job < 50) {
int iok = 0;
size_t nsp = th_nSpecies(n);
double* x = new double[nsp];
std::vector<double> x(nsp);
switch (job) {
case 32:
iok = th_getEnthalpies_RT(n,nsp,x);
iok = th_getEnthalpies_RT(n, nsp, &x[0]);
break;
case 34:
iok = th_chemPotentials(n,nsp,x);
iok = th_chemPotentials(n, nsp, &x[0]);
break;
case 36:
iok = th_getEntropies_R(n,nsp,x);
iok = th_getEntropies_R(n, nsp, &x[0]);
break;
case 38:
iok = th_getCp_R(n,nsp,x);
iok = th_getCp_R(n, nsp, &x[0]);
break;
default:
;
}
plhs[0] = mxCreateNumericMatrix((mwSize) nsp,1,
mxDOUBLE_CLASS,mxREAL);
plhs[0] = mxCreateNumericMatrix((mwSize) nsp, 1, mxDOUBLE_CLASS, mxREAL);
double* h = mxGetPr(plhs[0]);
if (iok >= 0) {
for (size_t i = 0; i < nsp; i++) {
h[i] = x[i];
}
delete x;
return;
} else {
for (size_t i = 0; i < nsp; i++) {
h[i] = -999.99;
}
delete x;
mexErrMsgTxt("unknown attribute");
return;
}
@ -242,10 +233,8 @@ static void thermoget(int nlhs, mxArray* plhs[],
}
void thermomethods(int nlhs, mxArray* plhs[],
int nrhs, const mxArray* prhs[])
void thermomethods(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[])
{
int job = getInt(prhs[2]);
if (job < 0) {
thermoset(nlhs, plhs, nrhs, prhs);

View file

@ -33,7 +33,6 @@ void transportmethods(int nlhs, mxArray* plhs[],
if (job < 10) {
bool ok = true;
switch (job) {
case 0:

View file

@ -34,10 +34,8 @@ void wallmethods(int nlhs, mxArray* plhs[],
}
// options that do not return a value
if (job < 20) {
switch (job) {
case 1:
iok = wall_del(i);
break;
@ -112,7 +110,7 @@ void wallmethods(int nlhs, mxArray* plhs[],
plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL);
double* h = mxGetPr(plhs[0]);
*h = r;
if (r == Undef) {
if (r == DERR) {
reportError();
}
return;

View file

@ -53,9 +53,7 @@ void xmlmethods(int nlhs, mxArray* plhs[],
mexErrMsgTxt("Too many output arguments");
}
// options that do not return a value
if (job < 20) {
switch (job) {
case 0:
@ -135,7 +133,6 @@ void xmlmethods(int nlhs, mxArray* plhs[],
}
// options that return strings
char* v = (char*)mxCalloc(80, sizeof(char));
switch (job) {
case 20: