[Kinetics] Move stoich manager and related functions up to Kinetics

This commit is contained in:
Ray Speth 2014-10-29 23:32:07 +00:00
parent 5ca49efff1
commit d5262e8bee
8 changed files with 108 additions and 261 deletions

View file

@ -75,21 +75,6 @@ public:
//! @name Reaction Rates Of Progress
//@{
virtual void getFwdRatesOfProgress(doublereal* fwdROP) {
updateROP();
std::copy(m_ropf.begin(), m_ropf.end(), fwdROP);
}
virtual void getRevRatesOfProgress(doublereal* revROP) {
updateROP();
std::copy(m_ropr.begin(), m_ropr.end(), revROP);
}
virtual void getNetRatesOfProgress(doublereal* netROP) {
updateROP();
std::copy(m_ropnet.begin(), m_ropnet.end(), netROP);
}
virtual void getEquilibriumConstants(doublereal* kc);
virtual void getDeltaGibbs(doublereal* deltaG);
@ -100,25 +85,6 @@ public:
virtual void getDeltaSSEnthalpy(doublereal* deltaH);
virtual void getDeltaSSEntropy(doublereal* deltaS);
//! @}
//! @name Species Production Rates
//! @{
virtual void getNetProductionRates(doublereal* net) {
updateROP();
m_rxnstoich.getNetProductionRates(m_kk, &m_ropnet[0], net);
}
virtual void getCreationRates(doublereal* cdot) {
updateROP();
m_rxnstoich.getCreationRates(m_kk, &m_ropf[0], &m_ropr[0], cdot);
}
virtual void getDestructionRates(doublereal* ddot) {
updateROP();
m_rxnstoich.getDestructionRates(m_kk, &m_ropf[0], &m_ropr[0], ddot);
}
//! @}
//! @name Reaction Mechanism Informational Query Routines
//! @{
@ -173,16 +139,11 @@ protected:
std::vector<size_t> m_irrev;
ReactionStoichMgr m_rxnstoich;
std::vector<size_t> m_fwdOrder;
size_t m_nirrev;
size_t m_nrev;
std::vector<std::map<size_t, doublereal> > m_rrxn;
std::vector<std::map<size_t, doublereal> > m_prxn;
/**
* Difference between the input global reactants order
* and the input global products order. Changed to a double
@ -197,9 +158,6 @@ protected:
//! @name Aqueous kinetics data
//!@{
vector_fp m_ropf;
vector_fp m_ropr;
vector_fp m_ropnet;
bool m_ROP_ok;
doublereal m_temp;

View file

@ -52,33 +52,10 @@ public:
return cGasKinetics;
}
virtual doublereal reactantStoichCoeff(size_t k, size_t i) const {
return getValue(m_rrxn[k], i, 0.0);
}
virtual doublereal productStoichCoeff(size_t k, size_t i) const {
return getValue(m_prxn[k], i, 0.0);
}
//! @}
//! @name Reaction Rates Of Progress
//! @{
virtual void getFwdRatesOfProgress(doublereal* fwdROP) {
updateROP();
std::copy(m_ropf.begin(), m_ropf.end(), fwdROP);
}
virtual void getRevRatesOfProgress(doublereal* revROP) {
updateROP();
std::copy(m_ropr.begin(), m_ropr.end(), revROP);
}
virtual void getNetRatesOfProgress(doublereal* netROP) {
updateROP();
std::copy(m_ropnet.begin(), m_ropnet.end(), netROP);
}
virtual void getEquilibriumConstants(doublereal* kc);
virtual void getDeltaGibbs(doublereal* deltaG);
virtual void getDeltaEnthalpy(doublereal* deltaH);
@ -88,14 +65,6 @@ public:
virtual void getDeltaSSEnthalpy(doublereal* deltaH);
virtual void getDeltaSSEntropy(doublereal* deltaS);
//! @}
//! @name Species Production Rates
//! @{
virtual void getNetProductionRates(doublereal* net);
virtual void getCreationRates(doublereal* cdot);
virtual void getDestructionRates(doublereal* ddot);
//! @}
//! @name Reaction Mechanism Informational Query Routines
//! @{
@ -154,16 +123,11 @@ protected:
Rate1<Plog> m_plog_rates;
Rate1<ChebyshevRate> m_cheb_rates;
ReactionStoichMgr m_rxnstoich;
std::vector<size_t> m_fwdOrder;
size_t m_nirrev;
size_t m_nrev;
std::vector<std::map<size_t, doublereal> > m_rrxn;
std::vector<std::map<size_t, doublereal> > m_prxn;
/**
* Difference between the input global reactants order
* and the input global products order. Changed to a double
@ -178,9 +142,6 @@ protected:
doublereal m_logp_ref;
doublereal m_logc_ref;
doublereal m_logStandConc;
vector_fp m_ropf;
vector_fp m_ropr;
vector_fp m_ropnet;
vector_fp m_rfn_low;
vector_fp m_rfn_high;
bool m_ROP_ok;

View file

@ -14,7 +14,6 @@
#include "cantera/base/utilities.h"
#include "RateCoeffMgr.h"
#include "ReactionStoichMgr.h"
namespace Cantera
{
@ -123,10 +122,6 @@ public:
//! @name Reaction Rates Of Progress
//! @{
virtual void getFwdRatesOfProgress(doublereal* fwdROP);
virtual void getRevRatesOfProgress(doublereal* revROP);
virtual void getNetRatesOfProgress(doublereal* netROP);
virtual void getEquilibriumConstants(doublereal* kc);
/** values needed to convert from exchange current density to surface reaction rate.
@ -153,39 +148,12 @@ public:
virtual void getDeltaSSEnthalpy(doublereal* deltaH);
virtual void getDeltaSSEntropy(doublereal* deltaS);
//! @}
//! @name Species Production Rates
//! @{
virtual void getCreationRates(doublereal* cdot);
virtual void getDestructionRates(doublereal* ddot);
virtual void getNetProductionRates(doublereal* net);
//! @}
//! @name Reaction Mechanism Informational Query Routines
//! @{
//! Provide a reactant stoichiometric coefficient
/*!
* @param[in] kSpecKin Species index within the kinetics object
* @param[in] irxn Reaction index
*
* @return Returns the reactant stoichiometic coefficient within the reaction
*/
virtual doublereal reactantStoichCoeff(size_t kSpecKin, size_t irxn) const;
//! Provide a product stoichiometric coefficient
/*!
* @param[in] kSpecKin Species index within the kinetics object
* @param[in] irxn Reaction index
*
* @return Returns the product stoichiometic coefficient within the reaction
*/
virtual doublereal productStoichCoeff(size_t kSpecKin, size_t irxn) const;
virtual void getActivityConcentrations(doublereal* const conc);
//! Return the charge transfer rxn Beta parameter for the ith reaction
/*!
* Returns the beta parameter for a charge transfer reaction. This
@ -449,40 +417,12 @@ protected:
*/
std::vector<size_t> m_irrev;
//! Stoichiometric manager for the reaction mechanism
/*!
* This is the manager for the kinetics mechanism that handles turning
* reaction extents into species production rates and also handles
* turning thermo properties into reaction thermo properties.
*/
ReactionStoichMgr m_rxnstoich;
//! Number of irreversible reactions in the mechanism
size_t m_nirrev;
//! Number of reversible reactions in the mechanism
size_t m_nrev;
//! m_rrxn is a vector of maps, containing the reactant
//! stoichiometric coefficient information
/*!
* m_rrxn has a length equal to the total number of species in the
* kinetics object. For each species, there exists a map, with the
* reaction number being the key, and the reactant stoichiometric
* coefficient for the species being the value.
*/
std::vector<std::map<size_t, doublereal> > m_rrxn;
//! m_prxn is a vector of maps, containing the reactant
//! stoichiometric coefficient information
/**
* m_prxn is a vector of maps. m_prxn has a length equal to the total
* number of species in the kinetics object. For each species, there
* exists a map, with the reaction number being the key, and the product
* stoichiometric coefficient for the species being the value.
*/
std::vector<std::map<size_t, doublereal> > m_prxn;
public:
//! Vector of additional information about each reaction
/*!
@ -688,9 +628,6 @@ protected:
doublereal m_logp0;
doublereal m_logc0;
vector_fp m_ropf;
vector_fp m_ropr;
vector_fp m_ropnet;
bool m_ROP_ok;

View file

@ -11,6 +11,7 @@
#define CT_KINETICS_H
#include "cantera/thermo/ThermoPhase.h"
#include "ReactionStoichMgr.h"
#include "cantera/thermo/mix_defs.h"
namespace Cantera
@ -401,9 +402,7 @@ public:
* @param fwdROP Output vector containing forward rates
* of progress of the reactions. Length: m_ii.
*/
virtual void getFwdRatesOfProgress(doublereal* fwdROP) {
throw NotImplementedError("Kinetics::getFwdRatesOfProgress");
}
virtual void getFwdRatesOfProgress(doublereal* fwdROP);
//! Return the Reverse rates of progress of the reactions
/*!
@ -413,9 +412,7 @@ public:
* @param revROP Output vector containing reverse rates
* of progress of the reactions. Length: m_ii.
*/
virtual void getRevRatesOfProgress(doublereal* revROP) {
throw NotImplementedError("Kinetics::getRevRatesOfProgress");
}
virtual void getRevRatesOfProgress(doublereal* revROP);
/**
* Net rates of progress. Return the net (forward - reverse) rates of
@ -424,9 +421,7 @@ public:
*
* @param netROP Output vector of the net ROP. Length: m_ii.
*/
virtual void getNetRatesOfProgress(doublereal* netROP) {
throw NotImplementedError("Kinetics::getNetRatesOfProgress");
}
virtual void getNetRatesOfProgress(doublereal* netROP);
//! Return a vector of Equilibrium constants.
/*!
@ -567,9 +562,7 @@ public:
*
* @param cdot Output vector of creation rates. Length: m_kk.
*/
virtual void getCreationRates(doublereal* cdot) {
throw NotImplementedError("Kinetics::getCreationRates");
}
virtual void getCreationRates(doublereal* cdot);
/**
* Species destruction rates [kmol/m^3/s or kmol/m^2/s]. Return the
@ -578,9 +571,7 @@ public:
*
* @param ddot Output vector of destruction rates. Length: m_kk.
*/
virtual void getDestructionRates(doublereal* ddot) {
throw NotImplementedError("Kinetics::getDestructionRates");
}
virtual void getDestructionRates(doublereal* ddot);
/**
* Species net production rates [kmol/m^3/s or kmol/m^2/s]. Return
@ -590,9 +581,7 @@ public:
*
* @param wdot Output vector of net production rates. Length: m_kk.
*/
virtual void getNetProductionRates(doublereal* wdot) {
throw NotImplementedError("Kinetics::getNetProductionRates");
}
virtual void getNetProductionRates(doublereal* wdot);
//! @}
//! @name Reaction Mechanism Informational Query Routines
@ -604,19 +593,14 @@ public:
* @param k kinetic species index
* @param i reaction index
*/
virtual doublereal reactantStoichCoeff(size_t k, size_t i) const {
throw NotImplementedError("Kinetics::reactantStoichCoeff");
}
virtual double reactantStoichCoeff(size_t k, size_t i) const;
/**
* Stoichiometric coefficient of species k as a product in reaction i.
*
* @param k kinetic species index
* @param i reaction index
*/
virtual doublereal productStoichCoeff(size_t k, size_t i) const {
throw NotImplementedError("Kinetics::productStoichCoeff");
}
virtual double productStoichCoeff(size_t k, size_t i) const;
//! Reactant order of species k in reaction i.
/*!
@ -872,6 +856,19 @@ public:
doublereal* phase_data);
protected:
// Update internal rate-of-progress variables #m_ropf and #m_ropr.
virtual void updateROP() {
throw NotImplementedError("Kinetics::updateROP");
}
//! Stoichiometric manager for the reaction mechanism
/*!
* This is the manager for the kinetics mechanism that handles turning
* reaction extents into species production rates and also handles
* turning thermo properties into reaction thermo properties.
*/
ReactionStoichMgr m_rxnstoich;
//! Number of reactions in the mechanism
size_t m_ii;
@ -909,6 +906,26 @@ protected:
*/
std::vector<std::vector<size_t> > m_products;
//! m_rrxn is a vector of maps, containing the reactant
//! stoichiometric coefficient information
/*!
* m_rrxn has a length equal to the total number of species in the
* kinetics object. For each species, there exists a map, with the
* reaction number being the key, and the reactant stoichiometric
* coefficient for the species being the value.
*/
std::vector<std::map<size_t, doublereal> > m_rrxn;
//! m_prxn is a vector of maps, containing the reactant
//! stoichiometric coefficient information
/**
* m_prxn is a vector of maps. m_prxn has a length equal to the total
* number of species in the kinetics object. For each species, there
* exists a map, with the reaction number being the key, and the product
* stoichiometric coefficient for the species being the value.
*/
std::vector<std::map<size_t, doublereal> > m_prxn;
std::vector<int> m_rxntype;
//! m_thermo is a vector of pointers to ThermoPhase objects that are
@ -967,6 +984,15 @@ protected:
//! Representation of the product side of each reaction equation
std::vector<std::string> m_productStrings;
//! Forward rate-of-progress for each reaction
vector_fp m_ropf;
//! Reverse rate-of-progress for each reaction
vector_fp m_ropr;
//! Net rate-of-progress for each reaction
vector_fp m_ropnet;
private:
std::map<size_t, std::vector<grouplist_t> > m_rgroups;
std::map<size_t, std::vector<grouplist_t> > m_pgroups;

View file

@ -57,20 +57,13 @@ AqueousKinetics& AqueousKinetics::operator=(const AqueousKinetics& right)
m_rates = right.m_rates;
m_irrev = right.m_irrev;
m_rxnstoich = right.m_rxnstoich;
m_fwdOrder = right.m_fwdOrder;
m_nirrev = right.m_nirrev;
m_nrev = right.m_nrev;
m_rxntype = right.m_rxntype;
m_rrxn = right.m_rrxn;
m_prxn = right.m_prxn;
m_dn = right.m_dn;
m_revindex = right.m_revindex;
m_ropf = right.m_ropf;
m_ropr = right.m_ropr;
m_ropnet = right.m_ropnet;
m_ROP_ok = right.m_ROP_ok;
m_temp = right.m_temp;
m_rfn = right.m_rfn;
@ -371,10 +364,6 @@ void AqueousKinetics::addElementaryReaction(ReactionData& r)
void AqueousKinetics::installReagents(const ReactionData& r)
{
m_ropf.push_back(0.0); // extend by one for new rxn
m_ropr.push_back(0.0);
m_ropnet.push_back(0.0);
size_t n, ns, m;
doublereal nsFlt;
doublereal reactantGlobalOrder = 0.0;

View file

@ -68,8 +68,6 @@ GasKinetics& GasKinetics::operator=(const GasKinetics& right)
m_plog_rates = right.m_plog_rates;
m_cheb_rates = right.m_cheb_rates;
m_rxnstoich = right.m_rxnstoich;
m_fwdOrder = right.m_fwdOrder;
m_nirrev = right.m_nirrev;
m_nrev = right.m_nrev;
@ -81,9 +79,6 @@ GasKinetics& GasKinetics::operator=(const GasKinetics& right)
m_logp_ref = right.m_logp_ref;
m_logc_ref = right.m_logc_ref;
m_logStandConc = right.m_logStandConc;
m_ropf = right.m_ropf;
m_ropr = right.m_ropr;
m_ropnet = right.m_ropnet;
m_rfn_low = right.m_rfn_low;
m_rfn_high = right.m_rfn_high;
m_ROP_ok = right.m_ROP_ok;
@ -315,24 +310,6 @@ void GasKinetics::getDeltaSSEntropy(doublereal* deltaS)
m_rxnstoich.getReactionDelta(m_ii, &m_grt[0], deltaS);
}
void GasKinetics::getNetProductionRates(doublereal* net)
{
updateROP();
m_rxnstoich.getNetProductionRates(m_kk, &m_ropnet[0], net);
}
void GasKinetics::getCreationRates(doublereal* cdot)
{
updateROP();
m_rxnstoich.getCreationRates(m_kk, &m_ropf[0], &m_ropr[0], cdot);
}
void GasKinetics::getDestructionRates(doublereal* ddot)
{
updateROP();
m_rxnstoich.getDestructionRates(m_kk, &m_ropf[0], &m_ropr[0], ddot);
}
void GasKinetics::processFalloffReactions()
{
// use m_ropr for temporary storage of reduced pressure
@ -581,9 +558,6 @@ void GasKinetics::addChebyshevReaction(ReactionData& r)
void GasKinetics::installReagents(const ReactionData& r)
{
m_ropf.push_back(0.0); // extend by one for new rxn
m_ropr.push_back(0.0);
m_ropnet.push_back(0.0);
size_t n, ns, m;
doublereal nsFlt;
doublereal reactantGlobalOrder = 0.0;

View file

@ -122,11 +122,8 @@ InterfaceKinetics& InterfaceKinetics::operator=(const InterfaceKinetics& right)
m_rates = right.m_rates;
m_redo_rates = right.m_redo_rates;
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_conc = right.m_conc;
m_actConc = right.m_actConc;
m_mu0 = right.m_mu0;
@ -148,9 +145,6 @@ InterfaceKinetics& InterfaceKinetics::operator=(const InterfaceKinetics& right)
m_ProdStanConcReac = right.m_ProdStanConcReac;
m_logp0 = right.m_logp0;
m_logc0 = right.m_logc0;
m_ropf = right.m_ropf;
m_ropr = right.m_ropr;
m_ropnet = right.m_ropnet;
m_ROP_ok = right.m_ROP_ok;
m_temp = right.m_temp;
m_logtemp = right.m_logtemp;
@ -377,24 +371,6 @@ void InterfaceKinetics::checkPartialEquil()
}
}
void InterfaceKinetics::getFwdRatesOfProgress(doublereal* fwdROP)
{
updateROP();
std::copy(m_ropf.begin(), m_ropf.end(), fwdROP);
}
void InterfaceKinetics::getRevRatesOfProgress(doublereal* revROP)
{
updateROP();
std::copy(m_ropr.begin(), m_ropr.end(), revROP);
}
void InterfaceKinetics::getNetRatesOfProgress(doublereal* netROP)
{
updateROP();
std::copy(m_ropnet.begin(), m_ropnet.end(), netROP);
}
void InterfaceKinetics::getEquilibriumConstants(doublereal* kc)
{
updateMu0();
@ -445,24 +421,6 @@ void InterfaceKinetics::updateExchangeCurrentQuantities()
m_rxnstoich.multiplyReactants(DATA_PTR(m_StandardConc), DATA_PTR(m_ProdStanConcReac));
}
void InterfaceKinetics::getCreationRates(doublereal* cdot)
{
updateROP();
m_rxnstoich.getCreationRates(m_kk, &m_ropf[0], &m_ropr[0], cdot);
}
void InterfaceKinetics::getDestructionRates(doublereal* ddot)
{
updateROP();
m_rxnstoich.getDestructionRates(m_kk, &m_ropf[0], &m_ropr[0], ddot);
}
void InterfaceKinetics::getNetProductionRates(doublereal* net)
{
updateROP();
m_rxnstoich.getNetProductionRates(m_kk, &m_ropnet[0], net);
}
void InterfaceKinetics::applyVoltageKfwdCorrection(doublereal* const kf)
{
// Compute the electrical potential energy of each species
@ -1074,9 +1032,6 @@ void InterfaceKinetics::installReagents(const ReactionData& r)
/*
* extend temporary storage by one for this rxn.
*/
m_ropf.push_back(0.0);
m_ropr.push_back(0.0);
m_ropnet.push_back(0.0);
m_rkcn.push_back(0.0);
/*
@ -1312,16 +1267,6 @@ int InterfaceKinetics::phaseStability(const size_t iphase) const
return m_phaseIsStable[iphase];
}
doublereal InterfaceKinetics::reactantStoichCoeff(size_t kSpecKin, size_t irxn) const
{
return getValue(m_rrxn[kSpecKin], irxn, 0.0);
}
doublereal InterfaceKinetics::productStoichCoeff(size_t kSpecKin, size_t irxn) const
{
return getValue(m_prxn[kSpecKin], irxn, 0.0);
}
void InterfaceKinetics::setPhaseStability(const size_t iphase, const int isStable)
{
if (iphase >= m_thermo.size()) {

View file

@ -60,11 +60,14 @@ Kinetics& Kinetics::operator=(const Kinetics& right)
return *this;
}
m_rxnstoich = right.m_rxnstoich;
m_ii = right.m_ii;
m_kk = right.m_kk;
m_perturb = right.m_perturb;
m_reactants = right.m_reactants;
m_products = right.m_products;
m_rrxn = right.m_rrxn;
m_prxn = right.m_prxn;
m_rxntype = right.m_rxntype;
m_thermo = right.m_thermo; // DANGER -> shallow pointer copy
@ -79,6 +82,9 @@ Kinetics& Kinetics::operator=(const Kinetics& right)
m_productStrings = right.m_productStrings;
m_rgroups = right.m_rgroups;
m_pgroups = right.m_pgroups;
m_ropf = right.m_ropf;
m_ropr = right.m_ropr;
m_ropnet = right.m_ropnet;
return *this;
}
@ -249,6 +255,54 @@ size_t Kinetics::speciesPhaseIndex(size_t k)
return npos;
}
double Kinetics::reactantStoichCoeff(size_t kSpec, size_t irxn) const
{
return getValue(m_rrxn[kSpec], irxn, 0.0);
}
double Kinetics::productStoichCoeff(size_t kSpec, size_t irxn) const
{
return getValue(m_prxn[kSpec], irxn, 0.0);
}
void Kinetics::getFwdRatesOfProgress(doublereal* fwdROP)
{
updateROP();
std::copy(m_ropf.begin(), m_ropf.end(), fwdROP);
}
void Kinetics::getRevRatesOfProgress(doublereal* revROP)
{
updateROP();
std::copy(m_ropr.begin(), m_ropr.end(), revROP);
}
void Kinetics::getNetRatesOfProgress(doublereal* netROP)
{
updateROP();
std::copy(m_ropnet.begin(), m_ropnet.end(), netROP);
}
void Kinetics::getCreationRates(double* cdot)
{
updateROP();
m_rxnstoich.getCreationRates(m_kk, &m_ropf[0], &m_ropr[0], cdot);
}
void Kinetics::getDestructionRates(doublereal* ddot)
{
updateROP();
m_rxnstoich.getDestructionRates(m_kk, &m_ropf[0], &m_ropr[0], ddot);
}
void Kinetics::getNetProductionRates(doublereal* net)
{
updateROP();
m_rxnstoich.getNetProductionRates(m_kk, &m_ropnet[0], net);
}
void Kinetics::addPhase(thermo_t& thermo)
{
// if not the first thermo object, set the start position
@ -301,6 +355,9 @@ void Kinetics::addReaction(ReactionData& r) {
m_reactantStrings.push_back(r.reactantString);
m_productStrings.push_back(r.productString);
m_rxntype.push_back(r.reactionType);
m_ropf.push_back(0.0);
m_ropr.push_back(0.0);
m_ropnet.push_back(0.0);
}
void Kinetics::installGroups(size_t irxn, const vector<grouplist_t>& r,