示例#1
0
static PyObject*
py_mixDiffCoeffs(PyObject *self, PyObject *args) {
    int n, id;
    if (!PyArg_ParseTuple(args, "ii:py_mixDiffCoeffs", &n, &id)) 
        return NULL;
#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);
}
示例#2
0
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;
}
示例#3
0
void transportmethods(int nlhs, mxArray* plhs[],
                      int nrhs, const mxArray* prhs[])
{
    double vv = 0.0;
    int n = getInt(prhs[1]);
    int job = getInt(prhs[2]);
    double* h;
    int iok = 0;
    int nsp;

    if (job == -1) {
        char* model = getString(prhs[3]);
        int loglevel = getInt(prhs[4]);
        int m = -2;
        m = (int) newTransport(model, n, loglevel);
        if (m < 0) {
            reportError();
        }

        // Create matrix for the return argument.
        plhs[0] = mxCreateDoubleMatrix(1,1, mxREAL);
        double* x = mxGetPr(plhs[0]);
        *x = m;
        return;
    }


    if (job < 10) {
        switch (job) {
        case 0:
            delTransport(n);
            vv = 0.0;
            break;
        case 1:
            vv = trans_viscosity(n);
            break;
        case 2:
            vv = trans_thermalConductivity(n);
        case 3:
            vv = trans_electricalConductivity(n);
            break;
        default:
            mexErrMsgTxt("unknown Transport method");
        }
        if (vv < 0.0) {
            reportError();
        }
        plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL);
        h = mxGetPr(plhs[0]);
        *h = vv;
        return;
    } else if (job < 20) {
        nsp = getInt(prhs[3]);
        plhs[0] = mxCreateNumericMatrix(nsp,1,mxDOUBLE_CLASS,mxREAL);
        h = mxGetPr(plhs[0]);

        switch (job) {
        case 11:
            iok = trans_getMixDiffCoeffs(n, nsp, h);
            break;
        case 12:
            iok = trans_getThermalDiffCoeffs(n, nsp, h);
            break;
        default:
            mexErrMsgTxt("unknown Transport method");
        }
    }

    else if (job < 30) {
        nsp = getInt(prhs[3]);
        plhs[0] = mxCreateNumericMatrix(nsp,nsp,mxDOUBLE_CLASS,mxREAL);
        h = mxGetPr(plhs[0]);
        switch (job) {
        case 21:
            iok = trans_getBinDiffCoeffs(n, nsp, h);
            break;
        case 22:
            iok = trans_getMultiDiffCoeffs(n, nsp, h);
            break;
        default:
            mexErrMsgTxt("unknown Transport method");
        }
    }

    // set parameters
    else if (job < 40) {
        double* params;
        int typ, k;
        switch (job) {
        case 31:
            typ = getInt(prhs[3]);
            k = getInt(prhs[4]);
            params = mxGetPr(prhs[5]);
            iok = trans_setParameters(n, typ, k, params);
            break;
        default:
            mexErrMsgTxt("unknown Transport method");
        }
        plhs[0] = mxCreateNumericMatrix(1,1,mxDOUBLE_CLASS,mxREAL);
        h = mxGetPr(plhs[0]);
        *h = double(iok);
    } else {
        mexErrMsgTxt("unknown Transport method");
    }
    if (iok < 0) {
        reportError();
    }
}