Fleshed out the type() and ID() member functions.

started adding a duplMyselfAsKinetics() capability. This is unfinished.
Doxygen updates
This commit is contained in:
Harry Moffat 2008-12-16 20:32:18 +00:00
parent 8f92e6da10
commit 70fb26459e
7 changed files with 1261 additions and 1035 deletions

View file

@ -41,13 +41,13 @@ namespace Cantera {
* Identifies the subclass of the Kinetics manager type.
* These are listed in mix_defs.h.
*/
virtual int ID() { return cEdgeKinetics; }
virtual int ID() const { return cEdgeKinetics; }
/**
* Identifies the subclass of the Kinetics manager type.
* These are listed in mix_defs.h.
*/
virtual int type() { return cEdgeKinetics; }
virtual int type() const { return cEdgeKinetics; }
// defined in InterfaceKinetics.cpp
virtual void finalize();

View file

@ -30,7 +30,8 @@ namespace Cantera {
/// Destructor.
virtual ~GRI_30_Kinetics(){}
virtual int ID() { return cGRI_30_Kinetics; }
virtual int ID() const { return cGRI_30_Kinetics; }
virtual int type() const { return cGRI_30_Kinetics; }
virtual void getNetProductionRates(doublereal* net) {
gri30_updateROP();

View file

@ -89,7 +89,8 @@ namespace Cantera {
/// Destructor.
virtual ~GasKinetics();
virtual int ID() { return cGasKinetics; }
virtual int ID() const { return cGasKinetics; }
virtual int type() const { return cGasKinetics; }
virtual doublereal reactantStoichCoeff(int k, int i) const {
return m_rrxn[k][i];

View file

@ -65,6 +65,94 @@ namespace Cantera {
}
}
// Copy Constructor for the %InterfaceKinetics object.
/*
* Currently, this is not fully implemented. If called it will
* throw an exception.
*/
InterfaceKinetics::InterfaceKinetics(const InterfaceKinetics &right) :
Kinetics(),
m_kk(0),
m_redo_rates(false),
m_nirrev(0),
m_nrev(0),
m_surf(0),
m_integrator(0),
m_finalized(false),
m_has_coverage_dependence(false),
m_has_electrochem_rxns(false),
m_ioFlag(0)
{
m_kdata = new InterfaceKineticsData;
m_kdata->m_temp = 0.0;
/*
* Call the assignment operator
*/
*this = operator=(right);
}
// Assignment operator
/*
* This is NOT a virtual function.
*
* @param right Reference to %Kinetics object to be copied into the
* current one.
*/
InterfaceKinetics& InterfaceKinetics::
operator=(const InterfaceKinetics &right) {
/*
* Check for self assignment.
*/
if (this == &right) return *this;
Kinetics::operator=(right);
m_kk = right.m_kk;
m_revindex = right.m_revindex;
m_rates = right.m_rates;
m_redo_rates = right.m_redo_rates;
m_index = right.m_index;
m_irrev = right.m_irrev;
m_rxnstoich = right.m_rxnstoich;
m_nirrev = right.m_nirrev;
m_nrev = right.m_nrev;
m_rrxn = right.m_rrxn;
m_prxn = right.m_prxn;
m_rxneqn = right.m_rxneqn;
*m_kdata = *right.m_kdata; // needs to be developed
m_mu0 = right.m_mu0;
m_phi = right.m_phi;
m_pot = right.m_pot;
m_rwork = right.m_rwork;
m_E = right.m_E;
m_surf = right.m_surf; //DANGER - shallow copy
m_integrator = right.m_integrator; //DANGER - shallow copy
m_beta = right.m_beta;
m_ctrxn = right.m_ctrxn;
m_finalized = right.m_finalized;
m_has_coverage_dependence = right.m_has_coverage_dependence;
m_has_electrochem_rxns = right.m_has_electrochem_rxns;
m_ioFlag = right.m_ioFlag;
return *this;
}
// Duplication routine for objects which inherit from
// Kinetics
/*
* This virtual routine can be used to duplicate %Kinetics objects
* inherited from %Kinetics even if the application only has
* a pointer to %Kinetics to work with.
*
* These routines are basically wrappers around the derived copy
* constructor.
*/
Kinetics *InterfaceKinetics::duplMyselfAsKinetics() const {
InterfaceKinetics* tp = new InterfaceKinetics(*this);
return dynamic_cast<Kinetics *>(tp);
}
/**
* Update properties that depend on temperature

View file

@ -88,8 +88,38 @@ namespace Cantera {
/// Destructor.
virtual ~InterfaceKinetics();
virtual int ID() { return cInterfaceKinetics; }
virtual int type() { return cInterfaceKinetics; }
//! Copy Constructor for the %Kinetics object.
/*!
* Currently, this is not fully implemented. If called it will
* throw an exception.
*/
InterfaceKinetics(const InterfaceKinetics &right);
//! Assignment operator
/*!
* This is NOT a virtual function.
*
* @param right Reference to %Kinetics object to be copied into the
* current one.
*/
InterfaceKinetics& operator=(const InterfaceKinetics &right);
//! Duplication routine for objects which inherit from
//! Kinetics
/*!
* This virtual routine can be used to duplicate %InterfaceKinetics objects
* inherited from %Kinetics even if the application only has
* a pointer to %Kinetics to work with.
*
* These routines are basically wrappers around the derived copy
* constructor.
*/
virtual Kinetics *duplMyselfAsKinetics() const;
virtual int ID() const { return cInterfaceKinetics; }
virtual int type() const { return cInterfaceKinetics; }
/**
* Set the electric potential in the nth phase
@ -487,6 +517,7 @@ namespace Cantera {
* product stoichiometric coefficient for the species being the value.
*/
mutable std::vector<std::map<int, doublereal> > m_prxn;
//! String expression for each rxn
/*!
* Vector of strings of length m_ii, the number of
@ -525,7 +556,7 @@ namespace Cantera {
* for all of the species in the kinetics object
*
* Length = m_k
* units = J/kmol
* units = J/kmol
*/
vector_fp m_mu0;

View file

@ -6,11 +6,15 @@
*
* Kinetics managers calculate rates of progress of species due to homogeneous or heterogeneous kinetics.
*/
/*
* $Date$
* $Revision$
*/
// Copyright 2001-2004 California Institute of Technology
#include "InterfaceKinetics.h"
#include "SurfPhase.h"
#include "StoichManager.h"
@ -25,197 +29,261 @@ using namespace std;
namespace Cantera {
Kinetics::Kinetics() : m_ii(0), m_thermo(0),
m_index(-1), m_surfphase(-1), m_rxnphase(-1),
m_mindim(4) {}
Kinetics::Kinetics() : m_ii(0), m_thermo(0),
m_index(-1), m_surfphase(-1), m_rxnphase(-1),
m_mindim(4) {}
Kinetics::~Kinetics(){}
// Copy Constructor for the %Kinetics object.
/*
* Currently, this is not fully implemented. If called it will
* throw an exception.
*/
Kinetics::Kinetics(const Kinetics &right) :
m_ii(0),
m_thermo(0),
m_index(-1),
m_surfphase(-1),
m_rxnphase(-1),
m_mindim(4)
{
/*
Kinetics::Kinetics(thermo_t* thermo) :
m_ii(0),
m_index(-1),
m_surfphase(-1) ,
m_rxnphase(0), m_mindim(4)
{
if (thermo) {
addPhase(*thermo);
}
deprecatedMethod("Kinetics","Kinetics(thermo_t*)","Kinetics()");
removeAtVersion("Kinetics(thermo_t*)","1.6.0");
}
*/
Kinetics::~Kinetics(){}
/**
* Takes as input an array of properties for all species in the
* mechanism and copies those values beloning to a particular
* phase to the output array.
* @param data Input data array.
* @param phase Pointer to one of the phase objects participating
* in this reaction mechanism
* @param phase_data Output array where the values for the the
* specified phase are to be written.
* Call the assignment operator
*/
void Kinetics::selectPhase(const doublereal* data, const thermo_t* phase,
doublereal* phase_data) {
int n, nsp, np = nPhases();
for (n = 0; n < np; n++) {
if (phase == m_thermo[n]) {
nsp = phase->nSpecies();
copy(data + m_start[n],
data + m_start[n] + nsp, phase_data);
return;
}
}
throw CanteraError("Kinetics::selectPhase", "Phase not found.");
}
/**
* kineticsSpeciesName():
*
* Return the string name of the kth species in the kinetics
* manager. k is an integer from 0 to ktot - 1, where ktot is
* the number of species in the kinetics manager, which is the
* sum of the number of species in all phases participating in
* the kinetics manager. If k is out of bounds, the string
* "<unknown>" is returned.
*this = operator=(right);
}
// Assignment operator
/*
* This is NOT a virtual function.
*
* @param right Reference to %Kinetics object to be copied into the
* current one.
*/
Kinetics& Kinetics::
operator=(const Kinetics &right) {
/*
* Check for self assignment.
*/
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 "<unknown>";
if (this == &right) return *this;
m_ii = right.m_ii;
m_perturb = right.m_perturb;
m_reactants = right.m_reactants;
m_products = right.m_products;
m_thermo = right.m_thermo; // DANGER -> shallow pointer copy
m_start = right.m_start;
m_phaseindex = right.m_phaseindex;
m_index = right.m_index;
m_surfphase = right.m_surfphase;
m_rxnphase = right.m_rxnphase;
m_mindim = right.m_mindim;
m_dummygroups = right.m_dummygroups;
return *this;
}
// Duplication routine for objects which inherit from
// Kinetics
/*
* This virtual routine can be used to duplicate %Kinetics objects
* inherited from %Kinetics even if the application only has
* a pointer to %Kinetics to work with.
*
* These routines are basically wrappers around the derived copy
* constructor.
*/
Kinetics *Kinetics::duplMyselfAsKinetics() const {
Kinetics* tp = new Kinetics(*this);
return tp;
}
int Kinetics::ID() const {
return 0;
}
int Kinetics::type() const {
return 0;
}
/**
* Takes as input an array of properties for all species in the
* mechanism and copies those values beloning to a particular
* phase to the output array.
* @param data Input data array.
* @param phase Pointer to one of the phase objects participating
* in this reaction mechanism
* @param phase_data Output array where the values for the the
* specified phase are to be written.
*/
void Kinetics::selectPhase(const doublereal* data, const thermo_t* phase,
doublereal* phase_data) {
int n, nsp, np = nPhases();
for (n = 0; n < np; n++) {
if (phase == m_thermo[n]) {
nsp = phase->nSpecies();
copy(data + m_start[n],
data + m_start[n] + nsp, phase_data);
return;
}
}
throw CanteraError("Kinetics::selectPhase", "Phase not found.");
}
/**
* kineticsSpeciesName():
*
* Return the string name of the kth species in the kinetics
* manager. k is an integer from 0 to ktot - 1, where ktot is
* the number of species in the kinetics manager, which is the
* sum of the number of species in all phases participating in
* the kinetics manager. If k is out of bounds, the string
* "<unknown>" is returned.
*/
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 "<unknown>";
}
/**
* kineticsSpeciesIndex():
*
* This routine will look up a species number based on
* the input string nm. The lookup of species will
* occur for all phases listed in the kinetics object,
* unless the string ph refers to a specific phase of
* the object.
*
* return
* - If a match is found, the position in the species list
* is returned.
* - If a specific phase is specified and no match is found,
* the value -1 is returned.
* - If no match is found in any phase, the value -2 is returned.
*/
int Kinetics::kineticsSpeciesIndex(std::string nm, std::string ph) const {
int np = static_cast<int>(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 == "<any>") {
/*
* 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;
}
/**
* This function looks up the string name of a species and
* returns a reference to the ThermoPhase object of the
* phase where the species resides.
* Will throw an error if the species string doesn't match.
*/
thermo_t& Kinetics::speciesPhase(std::string nm) {
int np = static_cast<int>(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);
}
/**
* This function takes as an argument the kineticsSpecies index
* (i.e., the list index in the list of species in the kinetics
* manager) and returns the index of the phase owning the
* species.
*/
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));
}
/*
* Add a phase to the kinetics manager object. This must
* be done before the function init() is called or
* before any reactions are input.
* The following fields are updated:
* m_start -> vector of integers, containing the
* starting position of the species for
* each phase in the kinetics mechanism.
* m_surfphase -> index of the surface phase.
* m_thermo -> vector of pointers to ThermoPhase phases
* that participate in the kinetics
* mechanism.
* m_phaseindex -> map containing the string id of each
* ThermoPhase phase as a key and the
* index of the phase within the kinetics
* manager object as the value.
*/
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);
}
/**
* kineticsSpeciesIndex():
*
* This routine will look up a species number based on
* the input string nm. The lookup of species will
* occur for all phases listed in the kinetics object,
* unless the string ph refers to a specific phase of
* the object.
*
* return
* - If a match is found, the position in the species list
* is returned.
* - If a specific phase is specified and no match is found,
* the value -1 is returned.
* - If no match is found in any phase, the value -2 is returned.
*/
int Kinetics::kineticsSpeciesIndex(std::string nm, std::string ph) const {
int np = static_cast<int>(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 == "<any>") {
/*
* 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;
// the phase with lowest dimensionality is assumed to be the
// phase/interface at which reactions take place
if (thermo.nDim() <= m_mindim) {
m_mindim = thermo.nDim();
m_rxnphase = nPhases();
}
/**
* This function looks up the string name of a species and
* returns a reference to the ThermoPhase object of the
* phase where the species resides.
* Will throw an error if the species string doesn't match.
*/
thermo_t& Kinetics::speciesPhase(std::string nm) {
int np = static_cast<int>(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);
}
/**
* This function takes as an argument the kineticsSpecies index
* (i.e., the list index in the list of species in the kinetics
* manager) and returns the index of the phase owning the
* species.
*/
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));
}
/**
* Add a phase to the kinetics manager object. This must
* be done before the function init() is called or
* before any reactions are input.
* The following fields are updated:
* m_start -> vector of integers, containing the
* starting position of the species for
* each phase in the kinetics mechanism.
* m_surfphase -> index of the surface phase.
* m_thermo -> vector of pointers to ThermoPhase phases
* that participate in the kinetics
* mechanism.
* m_phaseindex -> map containing the string id of each
* ThermoPhase phase as a key and the
* index of the phase within the kinetics
* manager object as the value.
*/
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);
}
// the phase with lowest dimensionality is assumed to be the
// phase/interface at which reactions take place
if (thermo.nDim() <= m_mindim) {
m_mindim = thermo.nDim();
m_rxnphase = nPhases();
}
// 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_rxnphase = nPhases();
}
m_thermo.push_back(&thermo);
m_phaseindex[m_thermo.back()->id()] = nPhases();
// 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_rxnphase = nPhases();
}
m_thermo.push_back(&thermo);
m_phaseindex[m_thermo.back()->id()] = nPhases();
}
//! Private function of the class Kinetics, indicating that a function

File diff suppressed because it is too large Load diff