From dafd2ad41192300f6dc696409e2e1be868b23c8b Mon Sep 17 00:00:00 2001 From: Dave Goodwin Date: Tue, 22 May 2007 20:16:47 +0000 Subject: [PATCH] *** empty log message *** --- Cantera/clib/src/ct.cpp | 12 +++++++ Cantera/clib/src/ct.h | 3 ++ Cantera/cxx/demos/demos.cpp | 12 ++++--- Cantera/cxx/demos/flamespeed.cpp | 21 +++++++++-- Cantera/python/Cantera/Kinetics.py | 15 ++++++-- Cantera/python/src/ctkinetics_methods.cpp | 22 ++++++++++++ Cantera/python/src/methods.h | 3 ++ Cantera/src/kinetics/InterfaceKinetics.cpp | 15 ++++++-- Cantera/src/kinetics/importKinetics.cpp | 42 +++++++++++----------- Cantera/src/oneD/StFlow.h | 5 ++- data/inputs/h2o2.cti | 8 +++++ 11 files changed, 124 insertions(+), 34 deletions(-) diff --git a/Cantera/clib/src/ct.cpp b/Cantera/clib/src/ct.cpp index 47928fc3f..e3919abaa 100755 --- a/Cantera/clib/src/ct.cpp +++ b/Cantera/clib/src/ct.cpp @@ -746,6 +746,18 @@ extern "C" { return kin(n)->nReactions(); } + int DLL_EXPORT kin_nPhases(int n) { + return kin(n)->nPhases(); + } + + int DLL_EXPORT kin_phaseIndex(int n, char* ph) { + return kin(n)->phaseIndex(string(ph)); + } + + int DLL_EXPORT kin_reactionPhaseIndex(int n) { + return kin(n)->reactionPhaseIndex(); + } + double DLL_EXPORT kin_reactantStoichCoeff(int n, int k, int i) { return kin(n)->reactantStoichCoeff(k,i); } diff --git a/Cantera/clib/src/ct.h b/Cantera/clib/src/ct.h index f3ae40cf6..b23723ed9 100755 --- a/Cantera/clib/src/ct.h +++ b/Cantera/clib/src/ct.h @@ -100,6 +100,9 @@ extern "C" { char* default_phase); int DLL_IMPORT kin_nSpecies(int n); int DLL_IMPORT kin_nReactions(int n); + int DLL_IMPORT kin_nPhases(int n); + int DLL_IMPORT kin_phaseIndex(int n, char* ph); + int DLL_IMPORT kin_reactionPhaseIndex(int n); double DLL_IMPORT kin_reactantStoichCoeff(int n, int i, int k); double DLL_IMPORT kin_productStoichCoeff(int n, int i, int k); int DLL_IMPORT kin_reactionType(int n, int i); diff --git a/Cantera/cxx/demos/demos.cpp b/Cantera/cxx/demos/demos.cpp index 244af345d..bade25691 100644 --- a/Cantera/cxx/demos/demos.cpp +++ b/Cantera/cxx/demos/demos.cpp @@ -6,6 +6,7 @@ #define CXX_DEMO #include "rankine.cpp" #include "flamespeed.cpp" +#include "hydrogen_flamespeed.cpp" #include "kinetics1.cpp" #include @@ -13,16 +14,17 @@ typedef int (*exfun)(int, void*); // array of demo functions -exfun fex[] = {kinetics1, openRankine, flamespeed}; +exfun fex[] = {kinetics1, openRankine, flamespeed, h2_flamespeed}; string demostr[] = {"zero-D kinetics ", "open Rankine cycle ", - "flamespeed "}; + "CH4 flamespeed ", + "H2 flamespeed "}; -int np[] = {0, 0, 1}; -double p[] = {0, 0, 0.9}; +int np[] = {0, 0, 1, 1}; +double p[] = {0, 0, 0.9, 0.9}; -#define NDEMOS 3 +#define NDEMOS 4 int mainmenu() { int i, idemo; diff --git a/Cantera/cxx/demos/flamespeed.cpp b/Cantera/cxx/demos/flamespeed.cpp index fe86657dd..3f723b841 100644 --- a/Cantera/cxx/demos/flamespeed.cpp +++ b/Cantera/cxx/demos/flamespeed.cpp @@ -98,8 +98,10 @@ int flamespeed(int np, void* p) { // specify the objects to use to compute kinetic rates and // transport properties - Transport* tr = newTransportMgr("Mix", &gas); - flow.setTransport(*tr); + Transport* trmix = newTransportMgr("Mix", &gas); + Transport* trmulti = newTransportMgr("Multi", &gas); + + flow.setTransport(*trmix); flow.setKinetics(gas); flow.setPressure(pressure); @@ -192,7 +194,22 @@ int flamespeed(int np, void* p) { refine_grid = true; flow.solveEnergyEqn(); flame.solve(loglevel,refine_grid); + cout << "Flame speed with mixture-averaged transport: " << + flame.value(flowdomain,flow.componentIndex("u"),0) << " m/s" << endl; + // now switch to multicomponent transport + flow.setTransport(*trmulti); + flame.solve(loglevel, refine_grid); + cout << "Flame speed with multicomponent transport: " << + flame.value(flowdomain,flow.componentIndex("u"),0) << " m/s" << endl; + + // now enable Soret diffusion + flow.enableSoret(true); + flame.solve(loglevel, refine_grid); + cout << "Flame speed with multicomponent transport + Soret: " << + flame.value(flowdomain,flow.componentIndex("u"),0) << " m/s" << endl; + + // int np=flow.nPoints(); vector zvec,Tvec,COvec,CO2vec,Uvec; diff --git a/Cantera/python/Cantera/Kinetics.py b/Cantera/python/Cantera/Kinetics.py index 7bb706f1d..3ab2897be 100755 --- a/Cantera/python/Cantera/Kinetics.py +++ b/Cantera/python/Cantera/Kinetics.py @@ -28,7 +28,7 @@ class Kinetics: the specification of the parameters. """ np = len(phases) - self._np = np + #self._np = np self._sp = [] self._phnum = {} @@ -54,9 +54,10 @@ class Kinetics: self.ckin = _cantera.KineticsFromXML(xml_phase, p0, p1, p2, p3, p4) - + + self._np = self.nPhases() for nn in range(self._np): - p = phases[nn] # self.phase(nn) + p = self.phase(nn) self._phnum[p.thermophase()] = nn self._end.append(self._end[-1]+p.nSpecies()) for k in range(p.nSpecies()): @@ -101,6 +102,14 @@ class Kinetics: """The starting location of phase n in production rate arrays.""" return _cantera.kin_start(self.ckin, n) + def nPhases(self): + """Number of phases.""" + return _cantera.kin_nPhases(self.ckin) + + def reactionPhaseIndex(self): + """The phase in which the reactions take place.""" + return _cantera.kin_reactionPhaseIndex(self) + def phase(self, n): """Return an object representing the nth phase.""" return ThermoPhase(index = _cantera.kin_phase(self.ckin, n)) diff --git a/Cantera/python/src/ctkinetics_methods.cpp b/Cantera/python/src/ctkinetics_methods.cpp index 6f0fbdd25..038aad9be 100644 --- a/Cantera/python/src/ctkinetics_methods.cpp +++ b/Cantera/python/src/ctkinetics_methods.cpp @@ -57,6 +57,28 @@ kin_nrxns(PyObject *self, PyObject *args) { return Py_BuildValue("i",kin_nReactions(kin)); } +static PyObject* +kin_nPhases(PyObject *self, PyObject *args) { + int kin; + if (!PyArg_ParseTuple(args, "i:kin_nPhases", &kin)) return NULL; + return Py_BuildValue("i",kin_nPhases(kin)); +} + +static PyObject* +kin_phaseIndex(PyObject *self, PyObject *args) { + int kin; + char* ph; + if (!PyArg_ParseTuple(args, "is:kin_phaseIndex", &kin, &ph)) return NULL; + return Py_BuildValue("i",kin_phaseIndex(kin, ph)); +} + +static PyObject* +kin_reactionPhaseIndex(PyObject *self, PyObject *args) { + int kin; + if (!PyArg_ParseTuple(args, "i:kin_reactionPhaseIndex", &kin)) return NULL; + return Py_BuildValue("i",kin_reactionPhaseIndex(kin)); +} + static PyObject* kin_isrev(PyObject *self, PyObject *args) { int kin, i; diff --git a/Cantera/python/src/methods.h b/Cantera/python/src/methods.h index e29d89adc..084232126 100644 --- a/Cantera/python/src/methods.h +++ b/Cantera/python/src/methods.h @@ -57,6 +57,9 @@ static PyMethodDef ct_methods[] = { {"kin_delete", kin_delete, METH_VARARGS}, {"kin_nspecies", kin_nspecies, METH_VARARGS}, {"kin_nreactions", kin_nrxns, METH_VARARGS}, + {"kin_nPhases", kin_nPhases, METH_VARARGS}, + {"kin_phaseIndex", kin_phaseIndex, METH_VARARGS}, + {"kin_reactionPhaseIndex", kin_reactionPhaseIndex, METH_VARARGS}, {"kin_isreversible", kin_isrev, METH_VARARGS}, {"kin_rstoichcoeff", kin_rstoichcoeff, METH_VARARGS}, {"kin_pstoichcoeff", kin_pstoichcoeff, METH_VARARGS}, diff --git a/Cantera/src/kinetics/InterfaceKinetics.cpp b/Cantera/src/kinetics/InterfaceKinetics.cpp index d2271890a..6d217be5c 100644 --- a/Cantera/src/kinetics/InterfaceKinetics.cpp +++ b/Cantera/src/kinetics/InterfaceKinetics.cpp @@ -194,7 +194,7 @@ namespace Cantera { nsp = thermo(n).nSpecies(); for (k = 0; k < nsp; k++) { delta = Faraday * m_phi[n] * thermo(n).charge(k); - cout << thermo(n).speciesName(k) << " " << (delta+dmu[ik])/rt << " " << dmu[ik]/rt << endl; + //cout << thermo(n).speciesName(k) << " " << (delta+dmu[ik])/rt << " " << dmu[ik]/rt << endl; dmu[ik] += delta; ik++; } @@ -336,8 +336,15 @@ namespace Cantera { ea = GasConstant * m_E[i]; if (eamod + ea < 0.0) { writelog("Warning: act energy mod too large!\n"); - eamod = -ea; + writelog(" Delta phi = "+fp2str(m_rwork[irxn]/Faraday)+"\n"); + writelog(" Delta Ea = "+fp2str(eamod)+"\n"); + writelog(" Ea = "+fp2str(ea)+"\n"); + for (n = 0; n < np; n++) { + writelog("Phase "+int2str(n)+": phi = " + +fp2str(m_phi[n])+"\n"); + } } + //eamod = -ea; kf[irxn] *= exp(-eamod*rrt); } } @@ -463,6 +470,10 @@ namespace Cantera { for (n = 0; n < np; n++) { thermo(n).getChemPotentials(DATA_PTR(m_grt) + m_start[n]); } + //for (n = 0; n < m_grt.size(); n++) { + // cout << n << "G_RT = " << m_grt[n] << endl; + //} + /* * Use the stoichiometric manager to find deltaG for each * reaction. diff --git a/Cantera/src/kinetics/importKinetics.cpp b/Cantera/src/kinetics/importKinetics.cpp index 3ca21cbd5..5fea2b760 100644 --- a/Cantera/src/kinetics/importKinetics.cpp +++ b/Cantera/src/kinetics/importKinetics.cpp @@ -263,28 +263,28 @@ public: } /* - * Check to see if reactant reaction orders have been specified. + * Check to see if reaction orders have been specified. */ if (rp == 1 && rxn.hasChild("order")) { - vector ord; - rxn.getChildren("order",ord); - int norder = static_cast(ord.size()); - int loc; - doublereal forder; - for (int nn = 0; nn < norder; nn++) { - const XML_Node& oo = *ord[nn]; - string sp = oo["species"]; - loc = speciesMap[sp]; - if (loc == 0) - throw CanteraError("getReagents", - "reaction order specified for non-reactant: " - +sp); - forder = fpValue(oo()); - if (forder < 0.0) { - throw CanteraError("getReagents", - "reaction order must be non-negative"); - } - // replace the forward stoichiometric coefficient + vector ord; + rxn.getChildren("order",ord); + int norder = static_cast(ord.size()); + int loc; + doublereal forder; + for (int nn = 0; nn < norder; nn++) { + const XML_Node& oo = *ord[nn]; + string sp = oo["species"]; + loc = speciesMap[sp]; + if (loc == 0) + throw CanteraError("getReagents", + "reaction order specified for non-reactantt: " + +sp); + forder = fpValue(oo()); + if (forder < 0.0) { + throw CanteraError("getReagents", + "reaction order must be non-negative"); + } + // replace the stoichiometric coefficient // stored above in 'order' with the specified // reaction order order[loc-1] = forder; @@ -655,7 +655,7 @@ public: * Get the products. We store the id of products in rdata.products */ ok = ok && getReagents(r, kin, -1, default_phase, rdata.products, - rdata.pstoich, dummy, rule); + rdata.pstoich, rdata.pstoich, rule); // if there was a problem getting either the reactants or the products, // then abort. diff --git a/Cantera/src/oneD/StFlow.h b/Cantera/src/oneD/StFlow.h index a0da24293..c9cb3d482 100644 --- a/Cantera/src/oneD/StFlow.h +++ b/Cantera/src/oneD/StFlow.h @@ -488,7 +488,10 @@ namespace Cantera { class FreeFlame : public StFlow { public: FreeFlame(igthermo_t* ph = 0, int nsp = 1, int points = 1) : - StFlow(ph, nsp, points) { m_dovisc = false; } + StFlow(ph, nsp, points) { + m_dovisc = false; + setID("flame"); + } virtual ~FreeFlame() {} virtual void eval(int j, doublereal* x, doublereal* r, integer* mask, doublereal rdt); diff --git a/data/inputs/h2o2.cti b/data/inputs/h2o2.cti index 1d997f2fa..809d55d60 100644 --- a/data/inputs/h2o2.cti +++ b/data/inputs/h2o2.cti @@ -15,6 +15,14 @@ ideal_gas(name = "ohmech", initial_state = state(temperature = 300.0, pressure = OneAtm) ) +ideal_gas(name = "ohmech-multi", + elements = " O H Ar ", + species = """ H2 H O O2 OH H2O HO2 H2O2 AR """, + reactions = "all", + transport = "Multi", + initial_state = state(temperature = 300.0, + pressure = OneAtm) ) + #-------------------------------------------------------------------------------