Skip to content

Commit

Permalink
Eliminate unnecessary counter variable Kinetics::m_ii
Browse files Browse the repository at this point in the history
  • Loading branch information
speth committed Jul 16, 2015
1 parent 571eaed commit 761f54f
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 58 deletions.
4 changes: 2 additions & 2 deletions include/cantera/kinetics/InterfaceKinetics.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ class InterfaceKinetics : public Kinetics
*
* units = J kmol-1
*
* @param deltaG Output vector of deltaG's for reactions Length: m_ii.
* If 0, this updates the internally stored values only.
* @param deltaG Output vector of deltaG's for reactions Length:
* nReactions(). If 0, this updates the internally stored values only.
*/
virtual void getDeltaGibbs(doublereal* deltaG);

Expand Down
47 changes: 21 additions & 26 deletions include/cantera/kinetics/Kinetics.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class Kinetics

//! Number of reactions in the reaction mechanism.
size_t nReactions() const {
return m_ii;
return m_reactions.size();
}

//! Check that the specified reaction index is in range
Expand Down Expand Up @@ -401,7 +401,7 @@ class Kinetics
* least as large as the total number of reactions.
*
* @param fwdROP Output vector containing forward rates
* of progress of the reactions. Length: m_ii.
* of progress of the reactions. Length: nReactions().
*/
virtual void getFwdRatesOfProgress(doublereal* fwdROP);

Expand All @@ -411,7 +411,7 @@ class Kinetics
* dimensioned at least as large as the total number of reactions.
*
* @param revROP Output vector containing reverse rates
* of progress of the reactions. Length: m_ii.
* of progress of the reactions. Length: nReactions().
*/
virtual void getRevRatesOfProgress(doublereal* revROP);

Expand All @@ -420,7 +420,7 @@ class Kinetics
* progress in array netROP, which must be dimensioned at least as large
* as the total number of reactions.
*
* @param netROP Output vector of the net ROP. Length: m_ii.
* @param netROP Output vector of the net ROP. Length: nReactions().
*/
virtual void getNetRatesOfProgress(doublereal* netROP);

Expand All @@ -435,7 +435,7 @@ class Kinetics
* \f]
*
* @param kc Output vector containing the equilibrium constants.
* Length: m_ii.
* Length: nReactions().
*/
virtual void getEquilibriumConstants(doublereal* kc) {
throw NotImplementedError("Kinetics::getEquilibriumConstants");
Expand All @@ -455,7 +455,7 @@ class Kinetics
* reaction.
*
* @param property Input vector of property value. Length: m_kk.
* @param deltaProperty Output vector of deltaRxn. Length: m_ii.
* @param deltaProperty Output vector of deltaRxn. Length: nReactions().
*/
virtual void getReactionDelta(const doublereal* property,
doublereal* deltaProperty);
Expand All @@ -479,7 +479,8 @@ class Kinetics
*
* units = J kmol-1
*
* @param deltaG Output vector of deltaG's for reactions Length: m_ii.
* @param deltaG Output vector of deltaG's for reactions Length:
* nReactions().
*/
virtual void getDeltaGibbs(doublereal* deltaG) {
throw NotImplementedError("Kinetics::getDeltaGibbs");
Expand All @@ -493,7 +494,8 @@ class Kinetics
*
* units = J kmol-1
*
* @param deltaM Output vector of deltaM's for reactions Length: m_ii.
* @param deltaM Output vector of deltaM's for reactions Length:
* nReactions().
*/
virtual void getDeltaElectrochemPotentials(doublereal* deltaM) {
throw NotImplementedError("Kinetics::getDeltaElectrochemPotentials");
Expand All @@ -505,7 +507,8 @@ class Kinetics
*
* units = J kmol-1
*
* @param deltaH Output vector of deltaH's for reactions Length: m_ii.
* @param deltaH Output vector of deltaH's for reactions Length:
* nReactions().
*/
virtual void getDeltaEnthalpy(doublereal* deltaH) {
throw NotImplementedError("Kinetics::getDeltaEnthalpy");
Expand All @@ -517,7 +520,8 @@ class Kinetics
*
* units = J kmol-1 Kelvin-1
*
* @param deltaS Output vector of deltaS's for reactions Length: m_ii.
* @param deltaS Output vector of deltaS's for reactions Length:
* nReactions().
*/
virtual void getDeltaEntropy(doublereal* deltaS) {
throw NotImplementedError("Kinetics::getDeltaEntropy");
Expand All @@ -530,7 +534,8 @@ class Kinetics
*
* units = J kmol-1
*
* @param deltaG Output vector of ss deltaG's for reactions Length: m_ii.
* @param deltaG Output vector of ss deltaG's for reactions Length:
* nReactions().
*/
virtual void getDeltaSSGibbs(doublereal* deltaG) {
throw NotImplementedError("Kinetics::getDeltaSSGibbs");
Expand All @@ -543,7 +548,8 @@ class Kinetics
*
* units = J kmol-1
*
* @param deltaH Output vector of ss deltaH's for reactions Length: m_ii.
* @param deltaH Output vector of ss deltaH's for reactions Length:
* nReactions().
*/
virtual void getDeltaSSEnthalpy(doublereal* deltaH) {
throw NotImplementedError("Kinetics::getDeltaSSEnthalpy");
Expand All @@ -556,7 +562,8 @@ class Kinetics
*
* units = J kmol-1 Kelvin-1
*
* @param deltaS Output vector of ss deltaS's for reactions Length: m_ii.
* @param deltaS Output vector of ss deltaS's for reactions Length:
* nReactions().
*/
virtual void getDeltaSSEntropy(doublereal* deltaS) {
throw NotImplementedError("Kinetics::getDeltaSSEntropy");
Expand Down Expand Up @@ -695,7 +702,7 @@ class Kinetics
* length is the number of reactions. units depends on many issues.
*
* @param kfwd Output vector containing the forward reaction rate
* constants. Length: m_ii.
* constants. Length: nReactions().
*/
virtual void getFwdRateConstants(doublereal* kfwd) {
throw NotImplementedError("Kinetics::getFwdRateConstants");
Expand Down Expand Up @@ -842,15 +849,6 @@ class Kinetics

//@}

/**
* Increment the number of reactions in the mechanism by one.
* @todo Should be protected?
*/
void incrementRxnCount() {
m_ii++;
m_perturb.push_back(1.0);
}

/**
* Returns true if the kinetics manager has been properly
* initialized and finalized.
Expand Down Expand Up @@ -929,9 +927,6 @@ class Kinetics
StoichManagerN m_irrevProductStoich;
//@}

//! Number of reactions in the mechanism
size_t m_ii;

//! The number of species in all of the phases
//! that participate in this kinetics mechanism.
size_t m_kk;
Expand Down
6 changes: 3 additions & 3 deletions src/kinetics/AqueousKinetics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void AqueousKinetics::getEquilibriumConstants(doublereal* kc)
getReactionDelta(&m_grt[0], &m_rkcn[0]);

doublereal rrt = 1.0/(GasConstant * thermo().temperature());
for (size_t i = 0; i < m_ii; i++) {
for (size_t i = 0; i < nReactions(); i++) {
kc[i] = exp(-m_rkcn[i]*rrt);
}

Expand Down Expand Up @@ -124,7 +124,7 @@ void AqueousKinetics::updateROP()
// for reversible reactions, multiply ropr by concentration products
m_revProductStoich.multiply(&m_conc[0], &m_ropr[0]);

for (size_t j = 0; j != m_ii; ++j) {
for (size_t j = 0; j != nReactions(); ++j) {
m_ropnet[j] = m_ropf[j] - m_ropr[j];
}

Expand All @@ -142,7 +142,7 @@ void AqueousKinetics::getFwdRateConstants(doublereal* kfwd)
// multiply by perturbation factor
multiply_each(m_ropf.begin(), m_ropf.end(), m_perturb.begin());

for (size_t i = 0; i < m_ii; i++) {
for (size_t i = 0; i < nReactions(); i++) {
kfwd[i] = m_ropf[i];
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/kinetics/BulkKinetics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ void BulkKinetics::getRevRateConstants(doublereal* krev, bool doIrreversible)

if (doIrreversible) {
getEquilibriumConstants(&m_ropnet[0]);
for (size_t i = 0; i < m_ii; i++) {
for (size_t i = 0; i < nReactions(); i++) {
krev[i] /= m_ropnet[i];
}
} else {
// m_rkcn[] is zero for irreversible reactions
for (size_t i = 0; i < m_ii; i++) {
for (size_t i = 0; i < nReactions(); i++) {
krev[i] *= m_rkcn[i];
}
}
Expand Down Expand Up @@ -168,7 +168,7 @@ void BulkKinetics::finalize()

// Guarantee that these arrays can be converted to double* even in the
// special case where there are no reactions defined.
if (!m_ii) {
if (!nReactions()) {
m_perturb.resize(1, 1.0);
m_ropf.resize(1, 0.0);
m_ropr.resize(1, 0.0);
Expand Down
6 changes: 3 additions & 3 deletions src/kinetics/GasKinetics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void GasKinetics::getEquilibriumConstants(doublereal* kc)
getReactionDelta(&m_grt[0], &m_rkcn[0]);

doublereal rrt = 1.0/(GasConstant * thermo().temperature());
for (size_t i = 0; i < m_ii; i++) {
for (size_t i = 0; i < nReactions(); i++) {
kc[i] = exp(-m_rkcn[i]*rrt + m_dn[i]*m_logStandConc);
}

Expand Down Expand Up @@ -199,7 +199,7 @@ void GasKinetics::updateROP()
// for reversible reactions, multiply ropr by concentration products
m_revProductStoich.multiply(&m_conc[0], &m_ropr[0]);

for (size_t j = 0; j != m_ii; ++j) {
for (size_t j = 0; j != nReactions(); ++j) {
m_ropnet[j] = m_ropf[j] - m_ropr[j];
}

Expand Down Expand Up @@ -235,7 +235,7 @@ void GasKinetics::getFwdRateConstants(doublereal* kfwd)
// multiply by perturbation factor
multiply_each(m_ropf.begin(), m_ropf.end(), m_perturb.begin());

for (size_t i = 0; i < m_ii; i++) {
for (size_t i = 0; i < nReactions(); i++) {
kfwd[i] = m_ropf[i];
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/kinetics/InterfaceKinetics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,11 @@ void InterfaceKinetics::getEquilibriumConstants(doublereal* kc)
updateMu0();
doublereal rrt = 1.0 / (GasConstant * thermo(0).temperature());

std::fill(kc, kc + m_ii, 0.0);
std::fill(kc, kc + nReactions(), 0.0);

getReactionDelta(DATA_PTR(m_mu0_Kc), kc);

for (size_t i = 0; i < m_ii; i++) {
for (size_t i = 0; i < nReactions(); i++) {
kc[i] = exp(-kc[i]*rrt);
}
}
Expand Down Expand Up @@ -333,7 +333,7 @@ void InterfaceKinetics::updateExchangeCurrentQuantities()
getReactionDelta(DATA_PTR(m_mu0), DATA_PTR(m_deltaG0));

// Calculate the product of the standard concentrations of the reactants
for (size_t i = 0; i < m_ii; i++) {
for (size_t i = 0; i < nReactions(); i++) {
m_ProdStanConcReac[i] = 1.0;
}
m_reactantStoich.multiply(DATA_PTR(m_StandardConc), DATA_PTR(m_ProdStanConcReac));
Expand Down Expand Up @@ -463,7 +463,7 @@ void InterfaceKinetics::getRevRateConstants(doublereal* krev, bool doIrreversibl
getFwdRateConstants(krev);
if (doIrreversible) {
getEquilibriumConstants(&m_ropnet[0]);
for (size_t i = 0; i < m_ii; i++) {
for (size_t i = 0; i < nReactions(); i++) {
krev[i] /= m_ropnet[i];
}
} else {
Expand Down Expand Up @@ -506,7 +506,7 @@ void InterfaceKinetics::updateROP()

// Fix up these calculations for cases where the above formalism doesn't hold
double OCV = 0.0;
for (size_t jrxn = 0; jrxn != m_ii; ++jrxn) {
for (size_t jrxn = 0; jrxn != nReactions(); ++jrxn) {
int reactionType = m_rxntype[jrxn];
if (reactionType == BUTLERVOLMER_RXN) {
//
Expand Down Expand Up @@ -543,7 +543,7 @@ void InterfaceKinetics::updateROP()
}
}

for (size_t j = 0; j != m_ii; ++j) {
for (size_t j = 0; j != nReactions(); ++j) {
m_ropnet[j] = m_ropf[j] - m_ropr[j];
}

Expand All @@ -553,7 +553,7 @@ void InterfaceKinetics::updateROP()
* phases that are stoichiometric phases containing one species with a unity activity
*/
if (m_phaseExistsCheck) {
for (size_t j = 0; j != m_ii; ++j) {
for (size_t j = 0; j != nReactions(); ++j) {
if ((m_ropr[j] > m_ropf[j]) && (m_ropr[j] > 0.0)) {
for (size_t p = 0; p < nPhases(); p++) {
if (m_rxnPhaseIsProduct[j][p]) {
Expand Down Expand Up @@ -624,7 +624,7 @@ void InterfaceKinetics::getDeltaGibbs(doublereal* deltaG)
// Use the stoichiometric manager to find deltaG for each reaction.
getReactionDelta(DATA_PTR(m_mu), DATA_PTR(m_deltaG));
if (deltaG != 0 && (DATA_PTR(m_deltaG) != deltaG)) {
for (size_t j = 0; j < m_ii; ++j) {
for (size_t j = 0; j < nReactions(); ++j) {
deltaG[j] = m_deltaG[j];
}
}
Expand Down Expand Up @@ -967,7 +967,7 @@ void InterfaceKinetics::init()
void InterfaceKinetics::finalize()
{
Kinetics::finalize();
size_t safe_reaction_size = std::max<size_t>(m_ii, 1);
size_t safe_reaction_size = std::max<size_t>(nReactions(), 1);
deltaElectricEnergy_.resize(safe_reaction_size);
size_t ks = reactionPhaseIndex();
if (ks == npos) throw CanteraError("InterfaceKinetics::finalize",
Expand All @@ -992,7 +992,7 @@ void InterfaceKinetics::finalize()

// Guarantee that these arrays can be converted to double* even in the
// special case where there are no reactions defined.
if (!m_ii) {
if (!nReactions()) {
m_perturb.resize(1, 1.0);
m_ropf.resize(1, 0.0);
m_ropr.resize(1, 0.0);
Expand Down Expand Up @@ -1170,7 +1170,7 @@ void EdgeKinetics::finalize()
// handled by the InterfaceKinetics::finalize() call.
Kinetics::finalize();

size_t safe_reaction_size = std::max<size_t>(m_ii, 1);
size_t safe_reaction_size = std::max<size_t>(nReactions(), 1);
deltaElectricEnergy_.resize(safe_reaction_size);
size_t ks = reactionPhaseIndex();
if (ks == npos) throw CanteraError("EdgeKinetics::finalize",
Expand All @@ -1195,7 +1195,7 @@ void EdgeKinetics::finalize()

// Guarantee that these arrays can be converted to double* even in the
// special case where there are no reactions defined.
if (!m_ii) {
if (!nReactions()) {
m_perturb.resize(1, 1.0);
m_ropf.resize(1, 0.0);
m_ropr.resize(1, 0.0);
Expand Down
Loading

0 comments on commit 761f54f

Please sign in to comment.