Skip to content

Commit

Permalink
[Kinetics] Remove vestigial legacy code in GasKinetics
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl authored and bryanwweber committed May 28, 2022
1 parent 2b6d882 commit a384352
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 200 deletions.
3 changes: 1 addition & 2 deletions include/cantera/kinetics/BulkKinetics.h
Expand Up @@ -53,7 +53,6 @@ class BulkKinetics : public Kinetics
std::vector<unique_ptr<MultiRateBase>> m_bulk_rates;
std::map<std::string, size_t> m_bulk_types; //!< Mapping of rate handlers

Rate1<Arrhenius2> m_rates; //!< @deprecated (legacy only)
std::vector<size_t> m_revindex; //!< Indices of reversible reactions
std::vector<size_t> m_irrev; //!< Indices of irreversible reactions

Expand All @@ -62,7 +61,7 @@ class BulkKinetics : public Kinetics
//! valued stoichiometries.
vector_fp m_dn;

ThirdBodyCalc3 m_multi_concm; //!< used with MultiRate evaluator
ThirdBodyCalc m_multi_concm; //!< used with MultiRate evaluator

//! Third body concentrations
vector_fp m_concm;
Expand Down
36 changes: 0 additions & 36 deletions include/cantera/kinetics/GasKinetics.h
Expand Up @@ -139,46 +139,16 @@ class GasKinetics : public BulkKinetics

//! Helper function ensuring that all rate derivatives can be calculated
//! @param name method name used for error output
//! @throw CanteraError if legacy rates are present
void assertDerivativesValid(const std::string& name);

//! @}

//! Reaction index of each falloff reaction
std::vector<size_t> m_fallindx; //!< @deprecated (legacy only)

//! Reaction index of each legacy reaction (old framework)
std::vector<size_t> m_legacy;

//! Map of reaction index to falloff reaction index (i.e indices in
//! #m_falloff_low_rates and #m_falloff_high_rates)
std::map<size_t, size_t> m_rfallindx; //!< @deprecated (legacy only)

//! Rate expressions for falloff reactions at the low-pressure limit
Rate1<Arrhenius2> m_falloff_low_rates; //!< @deprecated (legacy only)

//! Rate expressions for falloff reactions at the high-pressure limit
Rate1<Arrhenius2> m_falloff_high_rates; //!< @deprecated (legacy only)

FalloffMgr m_falloffn; //!< @deprecated (legacy only)

ThirdBodyCalc m_3b_concm; //!< @deprecated (legacy only)
ThirdBodyCalc m_falloff_concm; //!< @deprecated (legacy only)

Rate1<Plog> m_plog_rates; //!< @deprecated (legacy only)
Rate1<ChebyshevRate> m_cheb_rates; //!< @deprecated (legacy only)

//! @name Reaction rate data
//! @{

doublereal m_logStandConc;
vector_fp m_rfn_low; //!< @deprecated (legacy only)
vector_fp m_rfn_high; //!< @deprecated (legacy only)

doublereal m_pres; //!< Last pressure at which rates were evaluated
vector_fp falloff_work; //!< @deprecated (legacy only)
vector_fp concm_3b_values; //!< @deprecated (legacy only)
vector_fp concm_falloff_values; //!< @deprecated (legacy only)

//! @}

Expand All @@ -194,12 +164,6 @@ class GasKinetics : public BulkKinetics
bool m_jac_skip_falloff;
double m_jac_rtol_delta;

// functions marked as deprecated below are only used for XML import and
// transitional reaction types that are marked as '-legacy'

//! @deprecated To be removed after Cantera 2.6 (replaced by MultiRate approach)
void processFalloffReactions(double* ropf);

//! Update the equilibrium constants in molar units.
void updateKc();
};
Expand Down
74 changes: 2 additions & 72 deletions include/cantera/kinetics/ThirdBodyCalc.h
Expand Up @@ -15,80 +15,10 @@ namespace Cantera

//! Calculate and apply third-body effects on reaction rates, including non-
//! unity third-body efficiencies.
//! Used by legacy reactions
class ThirdBodyCalc
{
public:
void install(size_t rxnNumber, const std::map<size_t, double>& enhanced,
double dflt=1.0, size_t rxnIndex=npos) {
m_reaction_index.push_back(rxnNumber);
m_default.push_back(dflt);

m_species.emplace_back();
m_eff.emplace_back();
for (const auto& eff : enhanced) {
AssertTrace(eff.first != npos);
m_species.back().push_back(eff.first);
m_eff.back().push_back(eff.second - dflt);
}
if (rxnIndex == npos) {
m_true_index.push_back(rxnNumber);
} else {
m_true_index.push_back(rxnIndex);
}
}

void update(const vector_fp& conc, double ctot, double* work) {
for (size_t i = 0; i < m_species.size(); i++) {
double sum = 0.0;
for (size_t j = 0; j < m_species[i].size(); j++) {
sum += m_eff[i][j] * conc[m_species[i][j]];
}
work[i] = m_default[i] * ctot + sum;
}
}

//! Update third-body concentrations in full vector
void copy(const vector_fp& work, double* concm) {
for (size_t i = 0; i < m_true_index.size(); i++) {
concm[m_true_index[i]] = work[i];
}
}

void multiply(double* output, const double* work) {
for (size_t i = 0; i < m_reaction_index.size(); i++) {
output[m_reaction_index[i]] *= work[i];
}
}

size_t workSize() {
return m_reaction_index.size();
}

protected:
//! Indices of reactions that use third-bodies within vector of concentrations
std::vector<size_t> m_reaction_index;

//! Actual index of reaction within the full reaction array
std::vector<size_t> m_true_index;

//! m_species[i][j] is the index of the j-th species in reaction i.
std::vector<std::vector<size_t> > m_species;

//! m_eff[i][j] is the efficiency of the j-th species in reaction i.
std::vector<vector_fp> m_eff;

//! The default efficiency for each reaction
vector_fp m_default;
};


//! Calculate and apply third-body effects on reaction rates, including non-
//! unity third-body efficiencies.
class ThirdBodyCalc3
{
public:
//! Install reaction that uses third-body effects in ThirdBodyCalc3 manager
//! Install reaction that uses third-body effects in ThirdBodyCalc manager
void install(size_t rxnNumber, const std::map<size_t, double>& efficiencies,
double default_efficiency, bool mass_action) {
m_reaction_index.push_back(rxnNumber);
Expand Down Expand Up @@ -187,7 +117,7 @@ class ThirdBodyCalc3
}
}

//! Return boolean indicating whether ThirdBodyCalc3 is empty
//! Return boolean indicating whether ThirdBodyCalc is empty
bool empty() const {
return m_reaction_index.empty();
}
Expand Down
90 changes: 0 additions & 90 deletions src/kinetics/GasKinetics.cpp
Expand Up @@ -42,23 +42,8 @@ void GasKinetics::update_rates_T()
double T = thermo().temperature();
double P = thermo().pressure();
m_logStandConc = log(thermo().standardConcentration());
double logT = log(T);

if (T != m_temp) {
// Update forward rate constant for each reaction
if (!m_rfn.empty()) {
m_rates.update(T, logT, m_rfn.data());
}

// Falloff reactions (legacy)
if (!m_rfn_low.empty()) {
m_falloff_low_rates.update(T, logT, m_rfn_low.data());
m_falloff_high_rates.update(T, logT, m_rfn_high.data());
}
if (!falloff_work.empty()) {
m_falloffn.updateTemp(T, falloff_work.data());
}

updateKc();
m_ROP_ok = false;
}
Expand All @@ -71,19 +56,6 @@ void GasKinetics::update_rates_T()
m_ROP_ok = false;
}
}
if (T != m_temp || P != m_pres) {
// P-log reactions (legacy)
if (m_plog_rates.nReactions()) {
m_plog_rates.update(T, logT, m_rfn.data());
m_ROP_ok = false;
}

// Chebyshev reactions (legacy)
if (m_cheb_rates.nReactions()) {
m_cheb_rates.update(T, logT, m_rfn.data());
m_ROP_ok = false;
}
}
m_pres = P;
m_temp = T;
}
Expand All @@ -96,31 +68,6 @@ void GasKinetics::update_rates_C()

// Third-body objects interacting with MultiRate evaluator
m_multi_concm.update(m_phys_conc, ctot, m_concm.data());

// 3-body reactions (legacy)
if (!concm_3b_values.empty()) {
m_3b_concm.update(m_phys_conc, ctot, concm_3b_values.data());
m_3b_concm.copy(concm_3b_values, m_concm.data());
}

// Falloff reactions (legacy)
if (!concm_falloff_values.empty()) {
m_falloff_concm.update(m_phys_conc, ctot, concm_falloff_values.data());
m_falloff_concm.copy(concm_falloff_values, m_concm.data());
}

// P-log reactions (legacy)
if (m_plog_rates.nReactions()) {
double logP = log(thermo().pressure());
m_plog_rates.update_C(&logP);
}

// Chebyshev reactions (legacy)
if (m_cheb_rates.nReactions()) {
double log10P = log10(thermo().pressure());
m_cheb_rates.update_C(&log10P);
}

m_ROP_ok = false;
}

Expand Down Expand Up @@ -153,10 +100,6 @@ void GasKinetics::processFwdRateCoefficients(double* ropf)
// copy rate coefficients into ropf
copy(m_rfn.begin(), m_rfn.end(), ropf);

if (m_falloff_high_rates.nReactions()) {
processFalloffReactions(ropf);
}

// Scale the forward rate coefficient by the perturbation factor
for (size_t i = 0; i < nReactions(); ++i) {
ropf[i] *= m_perturb[i];
Expand All @@ -165,11 +108,6 @@ void GasKinetics::processFwdRateCoefficients(double* ropf)

void GasKinetics::processThirdBodies(double* rop)
{
// multiply rop by enhanced 3b conc for all 3b rxns
if (!concm_3b_values.empty()) {
m_3b_concm.multiply(rop, concm_3b_values.data());
}

// reactions involving third body
if (!m_concm.empty()) {
m_multi_concm.multiply(rop, m_concm.data());
Expand Down Expand Up @@ -201,29 +139,6 @@ void GasKinetics::getEquilibriumConstants(doublereal* kc)
}
}

void GasKinetics::processFalloffReactions(double* ropf)
{
// use m_ropr for temporary storage of reduced pressure
vector_fp& pr = m_ropr;

for (size_t i = 0; i < m_falloff_low_rates.nReactions(); i++) {
pr[i] = concm_falloff_values[i] * m_rfn_low[i] / (m_rfn_high[i] + SmallNumber);
AssertFinite(pr[i], "GasKinetics::processFalloffReactions",
"pr[{}] is not finite.", i);
}

m_falloffn.pr_to_falloff(pr.data(), falloff_work.data());

for (size_t i = 0; i < m_falloff_low_rates.nReactions(); i++) {
if (reactionTypeStr(m_fallindx[i]) == "falloff-legacy") {
pr[i] *= m_rfn_high[i];
} else { // CHEMACT_RXN
pr[i] *= m_rfn_low[i];
}
ropf[m_fallindx[i]] = pr[i];
}
}

void GasKinetics::updateROP()
{
processFwdRateCoefficients(m_ropf.data());
Expand Down Expand Up @@ -286,11 +201,6 @@ void GasKinetics::setDerivativeSettings(const AnyMap& settings)

void GasKinetics::assertDerivativesValid(const std::string& name)
{
if (m_legacy.size()) {
// Do not support legacy CTI/XML-based reaction rate evaluators
throw CanteraError(name, "Not supported for legacy (CTI/XML) input format.");
}

if (!thermo().isIdeal()) {
throw NotImplementedError(name,
"Not supported for non-ideal ThermoPhase models.");
Expand Down

0 comments on commit a384352

Please sign in to comment.