From b21ad9c412905af321889cd78e12787c7ba00a32 Mon Sep 17 00:00:00 2001 From: Dave Goodwin Date: Tue, 12 Oct 2004 12:56:32 +0000 Subject: [PATCH] *** empty log message *** --- Cantera/fortran/src/cantera.f90 | 10 ++ Cantera/fortran/src/cantera_thermo.f90 | 23 +++++ Cantera/matlab/cantera/examples/surfreactor.m | 2 +- Cantera/src/Kinetics.h | 93 +++---------------- Cantera/src/KineticsFactory.cpp | 93 +++++++++++++++++++ 5 files changed, 138 insertions(+), 83 deletions(-) diff --git a/Cantera/fortran/src/cantera.f90 b/Cantera/fortran/src/cantera.f90 index 2f6a3082d..bfcfc0450 100644 --- a/Cantera/fortran/src/cantera.f90 +++ b/Cantera/fortran/src/cantera.f90 @@ -1,3 +1,8 @@ +! This module is the only 'public' one - i.e., the only one visible in +! an application program. It's primary purpose is to provide generic +! procedure names that map to specific procedures depending on the +! argument types. + MODULE CANTERA USE cantera_thermo @@ -348,6 +353,11 @@ MODULE CANTERA MODULE PROCEDURE ctstring_setState_TPX END INTERFACE setState_TPX + INTERFACE setState_TRY + MODULE PROCEDURE ctthermo_setState_TRY + MODULE PROCEDURE ctstring_setState_TRY + END INTERFACE setState_TRY + INTERFACE setState_UV MODULE PROCEDURE ctthermo_setState_UV END INTERFACE setState_UV diff --git a/Cantera/fortran/src/cantera_thermo.f90 b/Cantera/fortran/src/cantera_thermo.f90 index dd446d616..24a481194 100644 --- a/Cantera/fortran/src/cantera_thermo.f90 +++ b/Cantera/fortran/src/cantera_thermo.f90 @@ -342,6 +342,29 @@ contains call ctthermo_setPressure(self, p) end subroutine ctstring_setState_TPX + subroutine ctthermo_setState_TRY(self, t, rho, y) + implicit none + type(phase_t), intent(inout) :: self + double precision, intent(in) :: t + double precision, intent(in) :: rho + double precision, intent(in) :: y(*) + call ctthermo_setTemperature(self, t) + call ctthermo_setMassFractions(self, y) + call ctthermo_setDensity(self, rho) + end subroutine ctthermo_setState_TRY + + subroutine ctstring_setState_TRY(self, t, rho, y) + implicit none + type(phase_t), intent(inout) :: self + double precision, intent(in) :: t + double precision, intent(in) :: rho + character*(*), intent(in) :: y + call ctthermo_setTemperature(self, t) + call ctthermo_setMassFractionsByName(self, y) + call ctthermo_setDensity(self, rho) + end subroutine ctstring_setState_TRY + + subroutine ctthermo_setState_HP(self, h, p) implicit none type(phase_t), intent(inout) :: self diff --git a/Cantera/matlab/cantera/examples/surfreactor.m b/Cantera/matlab/cantera/examples/surfreactor.m index 695fe3f83..663667331 100644 --- a/Cantera/matlab/cantera/examples/surfreactor.m +++ b/Cantera/matlab/cantera/examples/surfreactor.m @@ -60,7 +60,7 @@ for n = 1:100 tim(n) = t; temp(n) = temperature(r); pres(n) = pressure(r); - cov(n,:) = coverages(surf)'; + cov(n,:) = coverages(surf)'; x(n,:) = moleFraction(gas,names); end disp(['CPU time = ' num2str(cputime - t0)]); diff --git a/Cantera/src/Kinetics.h b/Cantera/src/Kinetics.h index fc6f91910..8828f1999 100755 --- a/Cantera/src/Kinetics.h +++ b/Cantera/src/Kinetics.h @@ -31,6 +31,10 @@ namespace Cantera { /// that manage homogeneous chemistry within one phase, or /// heterogeneous chemistry at one interface. /// + + // Note: Implementations for methods not implemented here may be + // found in KineticsFactory.cpp + class Kinetics { public: @@ -190,15 +194,7 @@ namespace Cantera { * the kinetics manager. If k is out of bounds, the string * "" is returned. */ - string kineticsSpeciesName(int k) const { - int np = m_start.size(); - for (int n = np-1; n >= 0; n--) { - if (k >= m_start[n]) { - return thermo(n).speciesName(k - m_start[n]); - } - } - return ""; - } + string kineticsSpeciesName(int k) const; /** * This routine will look up a species number based on @@ -214,28 +210,7 @@ namespace Cantera { * the value -1 is returned. * - If no match is found in any phase, the value -2 is returned. */ - int kineticsSpeciesIndex(string nm, string ph = "") const { - int np = static_cast(m_thermo.size()); - int k; - string id; - for (int n = 0; n < np; n++) { - id = thermo(n).id(); - if (ph == id) { - k = thermo(n).speciesIndex(nm); - if (k < 0) return -1; - return k + m_start[n]; - } - else if (ph == "") { - /* - * Call the speciesIndex() member function of the - * ThermoPhase object to find a match. - */ - k = thermo(n).speciesIndex(nm); - if (k >= 0) return k + m_start[n]; - } - } - return -2; - } + int kineticsSpeciesIndex(string nm, string ph = "") const; /** * This function looks up the string name of a species and @@ -243,16 +218,7 @@ namespace Cantera { * phase where the species resides. * Will throw an error if the species string doesn't match. */ - thermo_t& speciesPhase(string nm) { - int np = static_cast(m_thermo.size()); - int k; - string id; - for (int n = 0; n < np; n++) { - k = thermo(n).speciesIndex(nm); - if (k >= 0) return thermo(n); - } - throw CanteraError("speciesPhase", "unknown species "+nm); - } + thermo_t& speciesPhase(string nm); /** * This function takes as an argument the kineticsSpecies index @@ -269,16 +235,7 @@ namespace Cantera { * manager) and returns the index of the phase owning the * species. */ - int speciesPhaseIndex(int k) { - int np = m_start.size(); - for (int n = np-1; n >= 0; n--) { - if (k >= m_start[n]) { - return n; - } - } - throw CanteraError("speciesPhaseIndex", - "illegal species index: "+int2str(k)); - } + int speciesPhaseIndex(int k); //@} @@ -561,32 +518,7 @@ namespace Cantera { * index of the phase within the kinetics * manager object as the value. */ - void addPhase(thermo_t& thermo) { - - // if not the first thermo object, set the start position - // to that of the last object added + the number of its species - if (m_thermo.size() > 0) { - m_start.push_back(m_start.back() - + m_thermo.back()->nSpecies()); - } - // otherwise start at 0 - else { - m_start.push_back(0); - } - // there should only be one surface phase - int ptype = -100; - if (type() == cEdgeKinetics) ptype = cEdge; - else if (type() == cInterfaceKinetics) ptype = cSurf; - if (thermo.eosType() == ptype) { - if (m_surfphase >= 0) { - throw CanteraError("Kinetics::addPhase", - "cannot add more than one surface phase"); - } - m_surfphase = nPhases(); - } - m_thermo.push_back(&thermo); - m_phaseindex[m_thermo.back()->id()] = nPhases(); - } + void addPhase(thermo_t& thermo); /** * Prepare the class for the addition of reactions. This function @@ -725,11 +657,8 @@ namespace Cantera { private: vector m_dummygroups; - void err(string m) const { - throw CanteraError("Kinetics::" + m, - "The default Base class method was called, when " - "the inherited class's method should have been called"); - } + void err(string m) const; + }; typedef Kinetics kinetics_t; diff --git a/Cantera/src/KineticsFactory.cpp b/Cantera/src/KineticsFactory.cpp index 0d36aaa1d..b6eff3e50 100644 --- a/Cantera/src/KineticsFactory.cpp +++ b/Cantera/src/KineticsFactory.cpp @@ -25,6 +25,99 @@ namespace Cantera { + + //---------- class Kinetics methods ------------------ + string Kinetics::kineticsSpeciesName(int k) const { + int np = m_start.size(); + for (int n = np-1; n >= 0; n--) { + if (k >= m_start[n]) { + return thermo(n).speciesName(k - m_start[n]); + } + } + return ""; + } + + + int Kinetics::kineticsSpeciesIndex(string nm, string ph) const { + int np = static_cast(m_thermo.size()); + int k; + string id; + for (int n = 0; n < np; n++) { + id = thermo(n).id(); + if (ph == id) { + k = thermo(n).speciesIndex(nm); + if (k < 0) return -1; + return k + m_start[n]; + } + else if (ph == "") { + /* + * Call the speciesIndex() member function of the + * ThermoPhase object to find a match. + */ + k = thermo(n).speciesIndex(nm); + if (k >= 0) return k + m_start[n]; + } + } + return -2; + } + + thermo_t& Kinetics::speciesPhase(string nm) { + int np = static_cast(m_thermo.size()); + int k; + string id; + for (int n = 0; n < np; n++) { + k = thermo(n).speciesIndex(nm); + if (k >= 0) return thermo(n); + } + throw CanteraError("speciesPhase", "unknown species "+nm); + } + + int Kinetics::speciesPhaseIndex(int k) { + int np = m_start.size(); + for (int n = np-1; n >= 0; n--) { + if (k >= m_start[n]) { + return n; + } + } + throw CanteraError("speciesPhaseIndex", + "illegal species index: "+int2str(k)); + } + + void Kinetics::addPhase(thermo_t& thermo) { + + // if not the first thermo object, set the start position + // to that of the last object added + the number of its species + if (m_thermo.size() > 0) { + m_start.push_back(m_start.back() + + m_thermo.back()->nSpecies()); + } + // otherwise start at 0 + else { + m_start.push_back(0); + } + // there should only be one surface phase + int ptype = -100; + if (type() == cEdgeKinetics) ptype = cEdge; + else if (type() == cInterfaceKinetics) ptype = cSurf; + if (thermo.eosType() == ptype) { + if (m_surfphase >= 0) { + throw CanteraError("Kinetics::addPhase", + "cannot add more than one surface phase"); + } + m_surfphase = nPhases(); + } + m_thermo.push_back(&thermo); + m_phaseindex[m_thermo.back()->id()] = nPhases(); + } + + void Kinetics::err(string m) const { + throw CanteraError("Kinetics::" + m, + "The default Base class method was called, when " + "the inherited class's method should have been called"); + } + + //----------------------------------------------------- + KineticsFactory* KineticsFactory::__factory = 0; static int ntypes = 5;