Skip to content

Commit

Permalink
[Kinetics] Tweak docstrings/formatting and move code from header
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl authored and speth committed Dec 14, 2021
1 parent 5b2e184 commit 51a92e3
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 64 deletions.
46 changes: 5 additions & 41 deletions include/cantera/kinetics/GasKinetics.h
Expand Up @@ -70,62 +70,26 @@ class GasKinetics : public BulkKinetics
//! reactions.
virtual void update_rates_C();

private:
protected:
//! @name Internal service methods
/*!
* These methods are for @internal use, and seek to avoid code duplication
* while evaluating terms used for rate constants, rates of progress, and
* their derivatives. Frequently used methods are defined in the header
* file and use raw data pointers to allow inlining and avoid overhead.
* their derivatives.
*/
//! @{

//! Calculate rate coefficients
void processFwdRateCoefficients(double* ropf)
{
update_rates_C();
update_rates_T();

// 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];
}
}
void processFwdRateCoefficients(double* ropf);

//! Multiply rate with third-body collider concentrations
void 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());
}
}
void processThirdBodies(double* rop);

//! Multiply rate with inverse equilibrium constant
void processEquilibriumConstants(double* rop)
{
// For reverse rates computed from thermochemistry, multiply the forward
// rate coefficients by the reciprocals of the equilibrium constants
for (size_t i = 0; i < nReactions(); ++i) {
rop[i] *= m_rkcn[i];
}
}
void processEquilibriumConstants(double* rop);

//! @}

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

Expand Down
34 changes: 13 additions & 21 deletions include/cantera/kinetics/ReactionData.h
Expand Up @@ -29,7 +29,7 @@ struct ReactionData
/**
* Only used in conjunction with MultiRateBase::evalSingle / ReactionRate::eval.
* This method allows for testing of a reaction rate expression outside of
* Kinetics reaction rate evaluators. Mainly used for testing purposes.
* Kinetics reaction rate evaluators.
*/
virtual void update(double T) {
temperature = T;
Expand All @@ -41,7 +41,7 @@ struct ReactionData
/**
* Only used in conjunction with MultiRateBase::evalSingle / ReactionRate::eval.
* This method allows for testing of a reaction rate expression outside of
* Kinetics reaction rate evaluators. Mainly used for testing purposes.
* Kinetics reaction rate evaluators.
*/
virtual void update(double T, double extra);

Expand All @@ -51,8 +51,7 @@ struct ReactionData
* @returns A boolean element indicating whether the `evalFromStruct` method
* needs to be called (assuming previously-calculated values were cached)
*/
virtual bool update(const ThermoPhase& bulk,
const Kinetics& kin) = 0;
virtual bool update(const ThermoPhase& bulk, const Kinetics& kin) = 0;

//! Update number of species and reactions
virtual void resize(size_t n_species, size_t n_reactions) {}
Expand All @@ -76,10 +75,9 @@ struct ReactionData
* The data container `ArrheniusData` holds precalculated data common to
* all `ArrheniusRate` objects.
*/
struct ArrheniusData final : public ReactionData
struct ArrheniusData : public ReactionData
{
virtual bool update(const ThermoPhase& bulk,
const Kinetics& kin);
virtual bool update(const ThermoPhase& bulk, const Kinetics& kin);
using ReactionData::update;
};

Expand All @@ -89,12 +87,11 @@ struct ArrheniusData final : public ReactionData
* The data container `BlowersMaselData` holds precalculated data common to
* all `BlowersMaselRate` objects.
*/
struct BlowersMaselData final : public ReactionData
struct BlowersMaselData : public ReactionData
{
BlowersMaselData();

virtual bool update(const ThermoPhase& bulk,
const Kinetics& kin) override;
virtual bool update(const ThermoPhase& bulk, const Kinetics& kin) override;

virtual void update(double T) override;

Expand All @@ -121,12 +118,11 @@ struct BlowersMaselData final : public ReactionData
* The data container `FalloffData` holds precalculated data common to
* all Falloff related reaction rate classes.
*/
struct FalloffData final : public ReactionData
struct FalloffData : public ReactionData
{
FalloffData();

virtual bool update(const ThermoPhase& bulk,
const Kinetics& kin) override;
virtual bool update(const ThermoPhase& bulk, const Kinetics& kin) override;

virtual void update(double T) override;

Expand Down Expand Up @@ -156,10 +152,9 @@ struct FalloffData final : public ReactionData
* The data container `PlogData` holds precalculated data common to
* all `PlogRate` objects.
*/
struct PlogData final : public ReactionData
struct PlogData : public ReactionData
{
PlogData() : pressure(NAN), logP(0.) {}
using ReactionData::update;

virtual void update(double T) override;

Expand All @@ -169,8 +164,7 @@ struct PlogData final : public ReactionData
logP = std::log(P);
}

virtual bool update(const ThermoPhase& bulk,
const Kinetics& kin) override;
virtual bool update(const ThermoPhase& bulk, const Kinetics& kin) override;

virtual void invalidateCache() override {
ReactionData::invalidateCache();
Expand All @@ -187,10 +181,9 @@ struct PlogData final : public ReactionData
* The data container `ChebyshevData` holds precalculated data common to
* all `ChebyshevRate3` objects.
*/
struct ChebyshevData final : public ReactionData
struct ChebyshevData : public ReactionData
{
ChebyshevData() : pressure(NAN), log10P(0.) {}
using ReactionData::update;

virtual void update(double T) override;

Expand All @@ -200,8 +193,7 @@ struct ChebyshevData final : public ReactionData
log10P = std::log10(P);
}

virtual bool update(const ThermoPhase& bulk,
const Kinetics& kin) override;
virtual bool update(const ThermoPhase& bulk, const Kinetics& kin) override;

virtual void invalidateCache() override {
ReactionData::invalidateCache();
Expand Down
4 changes: 2 additions & 2 deletions include/cantera/kinetics/ReactionRate.h
Expand Up @@ -103,7 +103,7 @@ class ReactionRate
//! @param T temperature [K]
//! Used in conjunction with MultiRateBase::evalSingle / ReactionRate::eval.
//! This method allows for testing of a reaction rate expression outside of
//! Kinetics reaction rate evaluators. Mainly used for testing purposes.
//! Kinetics reaction rate evaluators.
double eval(double T) {
_evaluator().update(T);
return _evaluator().evalSingle(*this);
Expand All @@ -116,7 +116,7 @@ class ReactionRate
//! @param extra extra parameter used by parameterization
//! Used in conjunction with MultiRateBase::evalSingle / ReactionRate::eval.
//! This method allows for testing of a reaction rate expression outside of
//! Kinetics reaction rate evaluators. Mainly used for testing purposes.
//! Kinetics reaction rate evaluators.
double eval(double T, double extra) {
_evaluator().update(T, extra);
return _evaluator().evalSingle(*this);
Expand Down
40 changes: 40 additions & 0 deletions src/kinetics/GasKinetics.cpp
Expand Up @@ -132,6 +132,46 @@ void GasKinetics::updateKc()
}
}

void GasKinetics::processFwdRateCoefficients(double* ropf)
{
update_rates_C();
update_rates_T();

// 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];
}
}

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());
}
}

void GasKinetics::processEquilibriumConstants(double* rop)
{
// For reverse rates computed from thermochemistry, multiply the forward
// rate coefficients by the reciprocals of the equilibrium constants
for (size_t i = 0; i < nReactions(); ++i) {
rop[i] *= m_rkcn[i];
}
}

void GasKinetics::getEquilibriumConstants(doublereal* kc)
{
update_rates_T();
Expand Down

0 comments on commit 51a92e3

Please sign in to comment.