// string attributes static PyObject* kin_getstring(PyObject *self, PyObject *args) { int kin, job, i, iok = -3; int buflen; char* output_buf = 0; if (!PyArg_ParseTuple(args, "iii:kin_getstring", &kin, &job, &i)) return NULL; switch (job) { case 1: buflen = 80; output_buf = new char[buflen]; iok = kin_getReactionString(kin, i, 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; } }
int main(int argc, char** argv) { int ret; int xml_file = xml_get_XML_File("gri30.xml", 0); assert(xml_file > 0); int phase_node = xml_findID(xml_file, "gri30_mix"); assert(phase_node > 0); int thermo = thermo_newFromXML(phase_node); assert(thermo > 0); int nsp = thermo_nSpecies(thermo); assert(nsp == 53); ret = thermo_setTemperature(thermo, 500); assert(ret == 0); ret = thermo_setPressure(thermo, 5 * 101325); assert(ret == 0); ret = thermo_setMoleFractionsByName(thermo, "CH4:1.0, O2:2.0, N2:7.52"); assert(ret == 0); ret = thermo_equilibrate(thermo, "HP", 0, 1e-9, 50000, 1000, 0); assert(ret == 0); double T = thermo_temperature(thermo); assert(T > 2200 && T < 2300); ret = thermo_print(thermo, 1, 0); assert(ret == 0); int kin = kin_newFromXML(phase_node, thermo, 0, 0, 0, 0); assert(kin > 0); size_t nr = kin_nReactions(kin); assert(nr == 325 ); ret = thermo_setTemperature(thermo, T - 200); assert(ret == 0); char buf [1000]; double ropf[325]; printf("\n Reaction Forward ROP\n"); kin_getFwdRatesOfProgress(kin, 325, ropf); size_t n; // declare this here for C89 compatibility for (n = 0; n < nr; n++) { kin_getReactionString(kin, n, 1000, buf); printf("%35s %8.6e\n", buf, ropf[n]); } printf("\n Species Mix diff coeff\n"); int tran = trans_new("Mix", thermo, 0); double dkm[53]; trans_getMixDiffCoeffs(tran, 53, dkm); int k; // declare this here for C89 compatibility for (k = 0; k < nsp; k++) { thermo_getSpeciesName(thermo, k, 1000, buf); printf("%10s %8.6e\n", buf, dkm[k]); } ret = thermo_setTemperature(thermo, 1050); assert(ret == 0); ret = thermo_setPressure(thermo, 5 * 101325); assert(ret == 0); ret = thermo_setMoleFractionsByName(thermo, "CH4:1.0, O2:2.0, N2:7.52"); assert(ret == 0); printf("\ntime Temperature\n"); int reactor = reactor_new(5); int net = reactornet_new(); ret = reactor_setThermoMgr(reactor, thermo); assert(ret == 0); ret = reactor_setKineticsMgr(reactor, kin); assert(ret == 0); ret = reactornet_addreactor(net, reactor); assert(ret == 0); double t = 0.0; while (t < 0.1 && ret == 0) { double T = reactor_temperature(reactor); t = reactornet_time(net); printf("%.2e %.3f\n", t, T); ret = reactornet_advance(net, t + 5e-3); assert(ret == 0); } ct_appdelete(); return 0; }
void kineticsmethods(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) { double vv = 0.0; int job = getInt(prhs[2]); int kin, irxn; // construct a new instance if (job == 0) { checkNArgs(8, nrhs); int root = getInt(prhs[1]); int iph = getInt(prhs[3]); int in1 = getInt(prhs[4]); int in2 = getInt(prhs[5]); int in3 = getInt(prhs[6]); int in4 = getInt(prhs[7]); vv = static_cast<int>(kin_newFromXML(root, iph, in1, in2, in3, in4)); plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL); double* h = mxGetPr(plhs[0]); *h = vv; return; } else if (job > 0) { // methods int isp = 1; if (job < 5 || job > 6) { checkNArgs(4,nrhs); } else { checkNArgs(5,nrhs); isp = getInt(prhs[4]); } kin = getInt(prhs[1]); irxn = getInt(prhs[3]); // get scalar attributes if (job < 10) { switch (job) { case 1: vv = (double) kin_nReactions(kin); break; case 2: vv = kin_multiplier(kin, irxn-1); break; case 3: vv = (double) kin_nSpecies(kin); break; case 4: vv = kin_isReversible(kin,irxn-1); break; case 5: vv = kin_reactantStoichCoeff(kin, isp - 1, irxn-1); break; case 6: vv = kin_productStoichCoeff(kin, isp - 1, irxn-1); break; default: mexErrMsgTxt("unknown job"); } plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL); double* h = mxGetPr(plhs[0]); *h = vv; return; } else if (job < 20) { // get reaction array attributes mwSize nr = (mwSize) kin_nReactions(kin); plhs[0] = mxCreateNumericMatrix(nr,1,mxDOUBLE_CLASS,mxREAL); double* h = mxGetPr(plhs[0]); int ok = -10; switch (job) { case 11: ok = kin_getFwdRatesOfProgress(kin,nr,h); break; case 12: ok = kin_getRevRatesOfProgress(kin,nr,h); break; case 13: ok = kin_getNetRatesOfProgress(kin,nr,h); break; case 14: ok = kin_getEquilibriumConstants(kin,nr,h); break; case 15: ok = kin_getFwdRateConstants(kin,nr,h); break; case 16: ok = kin_getRevRateConstants(kin,1,nr,h); break; default: ; } if (ok < 0) { mexErrMsgTxt("error computing rates of progress"); } } else if (job < 30) { mwSize nsp = (mwSize) kin_nSpecies(kin); plhs[0] = mxCreateNumericMatrix(nsp,1,mxDOUBLE_CLASS,mxREAL); double* h = mxGetPr(plhs[0]); int ok = -10; switch (job) { case 21: ok = kin_getCreationRates(kin,nsp,h); break; case 22: ok = kin_getDestructionRates(kin,nsp,h); break; case 23: ok = kin_getNetProductionRates(kin,nsp,h); break; case 24: ok = kin_getSourceTerms(kin, nsp, h); break; default: ; } if (ok < 0) { mexErrMsgTxt("error computing production rates"); } } else if (job < 40) { char* buf; int iok = -1, buflen; switch (job) { case 31: buflen = kin_getReactionString(kin, irxn-1, 0, 0); if (buflen > 0) { buf = (char*) mxCalloc(buflen, sizeof(char)); iok = kin_getReactionString(kin, irxn-1, buflen, buf); } break; default: ; } if (iok == 0) { plhs[0] = mxCreateString(buf); return; } else { reportError(); } } } else { // set attributes int iok = -1; job = -job; kin = getInt(prhs[1]); irxn = getInt(prhs[3]); if (job < 10) { checkNArgs(5,nrhs); double v = getDouble(prhs[4]); switch (job) { case 1: iok = kin_setMultiplier(kin,irxn-1,v); break; case 3: iok = kin_del(kin); break; case 5: iok = kin_advanceCoverages(kin,v); break; default: mexErrMsgTxt("unknown job"); } } if (iok < 0) { reportError(); } } }