Skip to content

Commit c93ea76

Browse files
committed
[Kinetics] Enable calculations with ThreeBodyArrheniusRate
1 parent f622056 commit c93ea76

File tree

4 files changed

+43
-20
lines changed

4 files changed

+43
-20
lines changed

include/cantera/kinetics/BulkRate.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ class ThreeBodyBase
6969
//! Get the third-body efficiency for species *k*
7070
double efficiency(const std::string& k) const;
7171

72+
//! Get the third-body efficiency for species *k*
73+
void getEfficiencyMap(std::map<size_t, double>& eff) const;
74+
75+
//! Get flag indicating whether third-body participates in the law of mass action
76+
bool massAction() const {
77+
return m_massAction;
78+
}
79+
7280
//! Build rate-specific parameters based on Reaction and Kinetics context
7381
//! @param rxn Associated reaction object
7482
//! @param kin Kinetics object holding the rate evaluator
@@ -79,7 +87,7 @@ class ThreeBodyBase
7987
void updateFromStruct(const BulkData& shared_data) {
8088
if (shared_data.ready) {
8189
m_thirdBodyConc = m_defaultEfficiency * shared_data.molarDensity;
82-
for (const auto& eff : m_efficiencies) {
90+
for (const auto& eff : m_efficiencyMap) {
8391
m_thirdBodyConc += shared_data.concentrations[eff.first] * eff.second;
8492
}
8593
}
@@ -90,14 +98,6 @@ class ThreeBodyBase
9098
return m_thirdBodyConc;
9199
}
92100

93-
//! Apply correction
94-
double applyCorrection(double value) const {
95-
if (m_massAction) {
96-
return value * m_thirdBodyConc;
97-
}
98-
return value;
99-
}
100-
101101
protected:
102102
double m_thirdBodyConc; //!< Effective third-body concentration
103103

@@ -111,11 +111,11 @@ class ThreeBodyBase
111111
//! (`true` for three-body reactions, `false` for falloff reactions)
112112
bool m_massAction;
113113

114-
Composition m_efficiencyMap; //!< Map of species to third body efficiency
114+
Composition m_efficiencies; //!< Composition defining third body efficiency
115115

116116
private:
117117
//! Vector of pairs containing indices and efficiencies
118-
std::vector<std::pair<size_t, double>> m_efficiencies;
118+
std::vector<std::pair<size_t, double>> m_efficiencyMap;
119119
};
120120

121121

@@ -170,7 +170,7 @@ class ThreeBodyRate : public RateType, public ThreeBodyBase
170170
//! Evaluate reaction rate
171171
//! @param shared_data data shared by all reactions of a given type
172172
double evalFromStruct(const DataType& shared_data) const {
173-
return applyCorrection(RateType::evalFromStruct(shared_data));
173+
return RateType::evalFromStruct(shared_data);
174174
}
175175

176176
protected:

include/cantera/kinetics/Reaction.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ class Reaction
119119
//! @param detect Run detection of unmarked third-body collider
120120
bool stripThirdBody(bool detect=true);
121121

122+
std::string thirdBodyCollider() const {
123+
return m_thirdBodyCollider;
124+
}
125+
122126
//! Verify that all species involved in the reaction are defined in the Kinetics
123127
//! object. The function returns true if all species are found, and raises an
124128
//! exception unless the kinetics object is configured to skip undeclared species,

src/kinetics/BulkKinetics.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ bool BulkKinetics::addReaction(shared_ptr<Reaction> r, bool resize)
156156
if (r->thirdBody() != nullptr) {
157157
addThirdBody(r);
158158
}
159+
const auto threeBody = std::dynamic_pointer_cast<ThreeBodyArrheniusRate>(rate);
160+
if (threeBody) {
161+
// preliminary proof-of-concept uses ThirdBodyCalc3
162+
std::map<size_t, double> efficiencies;
163+
threeBody->getEfficiencyMap(efficiencies);
164+
m_multi_concm.install(
165+
nReactions() - 1, efficiencies,
166+
threeBody->defaultEfficiency(), threeBody->massAction());
167+
}
159168
}
160169

161170
m_concm.push_back(NAN);

src/kinetics/BulkRate.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ void ThreeBodyBase::setParameters(const AnyMap& node)
2121
{
2222
m_defaultEfficiency = node.getDouble("default-efficiency", 1.0);
2323
if (node.hasKey("efficiencies")) {
24-
m_efficiencyMap = node["efficiencies"].asMap<double>();
24+
m_efficiencies = node["efficiencies"].asMap<double>();
2525
}
2626
m_specifiedCollisionPartner = node.getBool("specified-collider", false);
27+
m_massAction = node.getBool("mass-action", true);
2728
}
2829

2930
void ThreeBodyBase::getParameters(AnyMap& node) const
3031
{
3132
if (!m_specifiedCollisionPartner) {
32-
if (m_efficiencyMap.size()) {
33-
node["efficiencies"] = m_efficiencyMap;
33+
if (m_efficiencies.size()) {
34+
node["efficiencies"] = m_efficiencies;
3435
node["efficiencies"].setFlowStyle();
3536
}
3637
if (m_defaultEfficiency != 1.0) {
@@ -39,23 +40,32 @@ void ThreeBodyBase::getParameters(AnyMap& node) const
3940
}
4041
}
4142

42-
void ThreeBodyBase::getEfficiencies(AnyMap& efficiencies) const {
43+
void ThreeBodyBase::getEfficiencies(AnyMap& efficiencies) const
44+
{
4345
efficiencies.clear();
44-
for (const auto& eff : m_efficiencyMap) {
46+
for (const auto& eff : m_efficiencies) {
4547
efficiencies[eff.first] = eff.second;
4648
}
4749
}
4850

51+
void ThreeBodyBase::getEfficiencyMap(std::map<size_t, double>& eff) const
52+
{
53+
eff.clear();
54+
for (const auto& item : m_efficiencyMap) {
55+
eff[item.first] = item.second + m_defaultEfficiency;
56+
}
57+
}
58+
4959
double ThreeBodyBase::efficiency(const std::string& k) const {
50-
return getValue(m_efficiencyMap, k, m_defaultEfficiency);
60+
return getValue(m_efficiencies, k, m_defaultEfficiency);
5161
}
5262

5363
void ThreeBodyBase::setContext(const Reaction& rxn, const Kinetics& kin)
5464
{
55-
for (const auto& eff : m_efficiencyMap) {
65+
for (const auto& eff : m_efficiencies) {
5666
size_t k = kin.kineticsSpeciesIndex(eff.first);
5767
if (k != npos) {
58-
m_efficiencies.emplace_back(k, eff.second - m_defaultEfficiency);
68+
m_efficiencyMap.emplace_back(k, eff.second - m_defaultEfficiency);
5969
} else if (!kin.skipUndeclaredThirdBodies()) {
6070
throw CanteraError("ThreeBodyBase::setContext",
6171
"Found third-body efficiency for undeclared species '{}' "

0 commit comments

Comments
 (0)