[Kinetics] Reaction objects have Falloff objects
This approach actually makes use of the fact that we have a Falloff type.
This commit is contained in:
parent
873724c135
commit
9d4a3e0f75
7 changed files with 48 additions and 41 deletions
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#include "cantera/base/FactoryBase.h"
|
#include "cantera/base/FactoryBase.h"
|
||||||
#include "cantera/base/ct_thread.h"
|
#include "cantera/base/ct_thread.h"
|
||||||
|
#include "cantera/base/smart_ptr.h"
|
||||||
#include "cantera/kinetics/Falloff.h"
|
#include "cantera/kinetics/Falloff.h"
|
||||||
|
|
||||||
namespace Cantera
|
namespace Cantera
|
||||||
|
|
@ -71,5 +72,8 @@ private:
|
||||||
static mutex_t falloff_mutex;
|
static mutex_t falloff_mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//! @copydoc FalloffFactory::newFalloff
|
||||||
|
shared_ptr<Falloff> newFalloff(int type, const vector_fp& c);
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include "reaction_defs.h"
|
#include "reaction_defs.h"
|
||||||
#include "FalloffFactory.h"
|
#include "FalloffFactory.h"
|
||||||
|
#include "cantera/base/global.h"
|
||||||
|
|
||||||
namespace Cantera
|
namespace Cantera
|
||||||
{
|
{
|
||||||
|
|
@ -29,17 +30,6 @@ public:
|
||||||
//else m_factory = f;
|
//else m_factory = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Destructor. Deletes all installed falloff function calculators.
|
|
||||||
virtual ~FalloffMgr() {
|
|
||||||
for (size_t i = 0; i < m_falloff.size(); i++) {
|
|
||||||
delete m_falloff[i];
|
|
||||||
}
|
|
||||||
//if (m_factory) {
|
|
||||||
//FalloffFactory::deleteFalloffFactory();
|
|
||||||
//m_factory = 0;
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Install a new falloff function calculator.
|
//! Install a new falloff function calculator.
|
||||||
/*
|
/*
|
||||||
* @param rxn Index of the falloff reaction. This will be used to
|
* @param rxn Index of the falloff reaction. This will be used to
|
||||||
|
|
@ -47,11 +37,26 @@ public:
|
||||||
* @param falloffType of falloff function to install.
|
* @param falloffType of falloff function to install.
|
||||||
* @param reactionType Either `FALLOFF_RXN` or `CHEMACT_RXN`
|
* @param reactionType Either `FALLOFF_RXN` or `CHEMACT_RXN`
|
||||||
* @param c vector of coefficients for the falloff function.
|
* @param c vector of coefficients for the falloff function.
|
||||||
|
* @deprecated Use install(size_t, int, shared_ptr<Falloff>). To be removed
|
||||||
|
* after Cantera 2.2.
|
||||||
*/
|
*/
|
||||||
void install(size_t rxn, int falloffType, int reactionType,
|
void install(size_t rxn, int falloffType, int reactionType,
|
||||||
const vector_fp& c) {
|
const vector_fp& c) {
|
||||||
|
warn_deprecated("FalloffMgr::install(size_t, int, int, const vector_fp&)",
|
||||||
|
"Use install(size_t, int, shared_ptr<Falloff>). To be removed after Cantera 2.2.");
|
||||||
|
shared_ptr<Falloff> f(m_factory->newFalloff(falloffType,c));
|
||||||
|
install(rxn, reactionType, f);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Install a new falloff function calculator.
|
||||||
|
/*
|
||||||
|
* @param rxn Index of the falloff reaction. This will be used to
|
||||||
|
* determine which array entry is modified in method pr_to_falloff.
|
||||||
|
* @param reactionType Either `FALLOFF_RXN` or `CHEMACT_RXN`
|
||||||
|
* @param f The falloff function.
|
||||||
|
*/
|
||||||
|
void install(size_t rxn, int reactionType, shared_ptr<Falloff> f) {
|
||||||
m_rxn.push_back(rxn);
|
m_rxn.push_back(rxn);
|
||||||
Falloff* f = m_factory->newFalloff(falloffType,c);
|
|
||||||
m_offset.push_back(m_worksize);
|
m_offset.push_back(m_worksize);
|
||||||
m_worksize += f->workSize();
|
m_worksize += f->workSize();
|
||||||
m_falloff.push_back(f);
|
m_falloff.push_back(f);
|
||||||
|
|
@ -96,7 +101,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::vector<size_t> m_rxn;
|
std::vector<size_t> m_rxn;
|
||||||
std::vector<Falloff*> m_falloff;
|
std::vector<shared_ptr<Falloff> > m_falloff;
|
||||||
FalloffFactory* m_factory;
|
FalloffFactory* m_factory;
|
||||||
vector_int m_loc;
|
vector_int m_loc;
|
||||||
std::vector<vector_fp::difference_type> m_offset;
|
std::vector<vector_fp::difference_type> m_offset;
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
#include "cantera/base/utilities.h"
|
#include "cantera/base/utilities.h"
|
||||||
#include "cantera/base/smart_ptr.h"
|
#include "cantera/base/smart_ptr.h"
|
||||||
#include "cantera/kinetics/RxnRates.h"
|
#include "cantera/kinetics/RxnRates.h"
|
||||||
|
#include "cantera/kinetics/Falloff.h"
|
||||||
|
|
||||||
namespace Cantera
|
namespace Cantera
|
||||||
{
|
{
|
||||||
|
|
@ -128,8 +129,7 @@ public:
|
||||||
FalloffReaction();
|
FalloffReaction();
|
||||||
FalloffReaction(const Composition& reactants, const Composition& products,
|
FalloffReaction(const Composition& reactants, const Composition& products,
|
||||||
const Arrhenius& low_rate, const Arrhenius& high_rate,
|
const Arrhenius& low_rate, const Arrhenius& high_rate,
|
||||||
const ThirdBody& tbody, int falloff_type,
|
const ThirdBody& tbody);
|
||||||
const vector_fp& falloff_params);
|
|
||||||
virtual std::string reactantString() const;
|
virtual std::string reactantString() const;
|
||||||
virtual std::string productString() const;
|
virtual std::string productString() const;
|
||||||
virtual void validate();
|
virtual void validate();
|
||||||
|
|
@ -143,13 +143,9 @@ public:
|
||||||
//! Relative efficiencies of third-body species in enhancing the reaction rate
|
//! Relative efficiencies of third-body species in enhancing the reaction rate
|
||||||
ThirdBody third_body;
|
ThirdBody third_body;
|
||||||
|
|
||||||
//! Type of falloff parameterization to use. Values are defined in
|
//! Falloff function which determines how low_rate and high_rate are
|
||||||
//! reaction_defs.h, with names ending in `FALLOFF`.
|
//! combined to determine the rate constant for the reaction.
|
||||||
int falloff_type;
|
shared_ptr<Falloff> falloff;
|
||||||
|
|
||||||
//! Values used in the falloff parameterization. Meaning of each parameter
|
|
||||||
//! depends on #falloff_type.
|
|
||||||
vector_fp falloff_parameters;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//! A reaction where the rate decreases as pressure increases due to collisional
|
//! A reaction where the rate decreases as pressure increases due to collisional
|
||||||
|
|
@ -162,8 +158,7 @@ public:
|
||||||
ChemicallyActivatedReaction();
|
ChemicallyActivatedReaction();
|
||||||
ChemicallyActivatedReaction(const Composition& reactants,
|
ChemicallyActivatedReaction(const Composition& reactants,
|
||||||
const Composition& products, const Arrhenius& low_rate,
|
const Composition& products, const Arrhenius& low_rate,
|
||||||
const Arrhenius& high_rate, const ThirdBody& tbody, int falloff_type,
|
const Arrhenius& high_rate, const ThirdBody& tbody);
|
||||||
const vector_fp& falloff_params);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//! A pressure-dependent reaction parameterized by logarithmically interpolating
|
//! A pressure-dependent reaction parameterized by logarithmically interpolating
|
||||||
|
|
|
||||||
|
|
@ -32,4 +32,10 @@ Falloff* FalloffFactory::newFalloff(int type, const vector_fp& c)
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shared_ptr<Falloff> newFalloff(int type, const vector_fp& c)
|
||||||
|
{
|
||||||
|
shared_ptr<Falloff> f(FalloffFactory::factory()->newFalloff(type, c));
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -361,8 +361,7 @@ void GasKinetics::addFalloffReaction(FalloffReaction& r)
|
||||||
r.third_body.default_efficiency);
|
r.third_body.default_efficiency);
|
||||||
|
|
||||||
// install the falloff function calculator for this reaction
|
// install the falloff function calculator for this reaction
|
||||||
m_falloffn.install(m_nfall, r.falloff_type, r.reaction_type,
|
m_falloffn.install(m_nfall, r.reaction_type, r.falloff);
|
||||||
r.falloff_parameters);
|
|
||||||
|
|
||||||
// increment the falloff reaction counter
|
// increment the falloff reaction counter
|
||||||
++m_nfall;
|
++m_nfall;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "cantera/kinetics/Reaction.h"
|
#include "cantera/kinetics/Reaction.h"
|
||||||
|
#include "cantera/kinetics/FalloffFactory.h"
|
||||||
#include "cantera/base/ctml.h"
|
#include "cantera/base/ctml.h"
|
||||||
#include "cantera/base/Array.h"
|
#include "cantera/base/Array.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
@ -157,21 +158,17 @@ std::string ThirdBodyReaction::productString() const {
|
||||||
|
|
||||||
FalloffReaction::FalloffReaction()
|
FalloffReaction::FalloffReaction()
|
||||||
: Reaction(FALLOFF_RXN)
|
: Reaction(FALLOFF_RXN)
|
||||||
, falloff_type(-1)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
FalloffReaction::FalloffReaction(
|
FalloffReaction::FalloffReaction(
|
||||||
const Composition& reactants_, const Composition& products_,
|
const Composition& reactants_, const Composition& products_,
|
||||||
const Arrhenius& low_rate_, const Arrhenius& high_rate_,
|
const Arrhenius& low_rate_, const Arrhenius& high_rate_,
|
||||||
const ThirdBody& tbody, int type,
|
const ThirdBody& tbody)
|
||||||
const vector_fp& params)
|
|
||||||
: Reaction(FALLOFF_RXN, reactants_, products_)
|
: Reaction(FALLOFF_RXN, reactants_, products_)
|
||||||
, low_rate(low_rate_)
|
, low_rate(low_rate_)
|
||||||
, high_rate(high_rate_)
|
, high_rate(high_rate_)
|
||||||
, third_body(tbody)
|
, third_body(tbody)
|
||||||
, falloff_type(type)
|
|
||||||
, falloff_parameters(params)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -212,10 +209,8 @@ ChemicallyActivatedReaction::ChemicallyActivatedReaction()
|
||||||
ChemicallyActivatedReaction::ChemicallyActivatedReaction(
|
ChemicallyActivatedReaction::ChemicallyActivatedReaction(
|
||||||
const Composition& reactants_, const Composition& products_,
|
const Composition& reactants_, const Composition& products_,
|
||||||
const Arrhenius& low_rate_, const Arrhenius& high_rate_,
|
const Arrhenius& low_rate_, const Arrhenius& high_rate_,
|
||||||
const ThirdBody& tbody, int falloff_type,
|
const ThirdBody& tbody)
|
||||||
const vector_fp& falloff_params)
|
: FalloffReaction(reactants_, products_, low_rate, high_rate, tbody)
|
||||||
: FalloffReaction(reactants_, products_, low_rate, high_rate, tbody,
|
|
||||||
falloff_type, falloff_params)
|
|
||||||
{
|
{
|
||||||
reaction_type = CHEMACT_RXN;
|
reaction_type = CHEMACT_RXN;
|
||||||
}
|
}
|
||||||
|
|
@ -300,26 +295,28 @@ void readFalloff(FalloffReaction& R, const XML_Node& rc_node)
|
||||||
{
|
{
|
||||||
XML_Node& falloff = rc_node.child("falloff");
|
XML_Node& falloff = rc_node.child("falloff");
|
||||||
std::vector<std::string> p;
|
std::vector<std::string> p;
|
||||||
|
vector_fp falloff_parameters;
|
||||||
getStringArray(falloff, p);
|
getStringArray(falloff, p);
|
||||||
size_t np = p.size();
|
size_t np = p.size();
|
||||||
for (size_t n = 0; n < np; n++) {
|
for (size_t n = 0; n < np; n++) {
|
||||||
R.falloff_parameters.push_back(fpValueCheck(p[n]));
|
falloff_parameters.push_back(fpValueCheck(p[n]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int falloff_type = 0;
|
||||||
if (lowercase(falloff["type"]) == "lindemann") {
|
if (lowercase(falloff["type"]) == "lindemann") {
|
||||||
R.falloff_type = SIMPLE_FALLOFF;
|
falloff_type = SIMPLE_FALLOFF;
|
||||||
if (np != 0) {
|
if (np != 0) {
|
||||||
throw CanteraError("readFalloff", "Lindemann parameterization "
|
throw CanteraError("readFalloff", "Lindemann parameterization "
|
||||||
"takes no parameters, but " + int2str(np) + "were given");
|
"takes no parameters, but " + int2str(np) + "were given");
|
||||||
}
|
}
|
||||||
} else if (lowercase(falloff["type"]) == "troe") {
|
} else if (lowercase(falloff["type"]) == "troe") {
|
||||||
R.falloff_type = TROE_FALLOFF;
|
falloff_type = TROE_FALLOFF;
|
||||||
if (np != 3 && np != 4) {
|
if (np != 3 && np != 4) {
|
||||||
throw CanteraError("readFalloff", "Troe parameterization takes "
|
throw CanteraError("readFalloff", "Troe parameterization takes "
|
||||||
"3 or 4 parameters, but " + int2str(np) + "were given");
|
"3 or 4 parameters, but " + int2str(np) + "were given");
|
||||||
}
|
}
|
||||||
} else if (lowercase(falloff["type"]) == "sri") {
|
} else if (lowercase(falloff["type"]) == "sri") {
|
||||||
R.falloff_type = SRI_FALLOFF;
|
falloff_type = SRI_FALLOFF;
|
||||||
if (np != 3 && np != 5) {
|
if (np != 3 && np != 5) {
|
||||||
throw CanteraError("readFalloff", "SRI parameterization takes "
|
throw CanteraError("readFalloff", "SRI parameterization takes "
|
||||||
"3 or 5 parameters, but " + int2str(np) + "were given");
|
"3 or 5 parameters, but " + int2str(np) + "were given");
|
||||||
|
|
@ -328,6 +325,7 @@ void readFalloff(FalloffReaction& R, const XML_Node& rc_node)
|
||||||
throw CanteraError("readFalloff", "Unrecognized falloff type: '" +
|
throw CanteraError("readFalloff", "Unrecognized falloff type: '" +
|
||||||
falloff["type"] + "'");
|
falloff["type"] + "'");
|
||||||
}
|
}
|
||||||
|
R.falloff = newFalloff(falloff_type, falloff_parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
void readEfficiencies(ThirdBody& tbody, const XML_Node& rc_node)
|
void readEfficiencies(ThirdBody& tbody, const XML_Node& rc_node)
|
||||||
|
|
|
||||||
|
|
@ -125,8 +125,8 @@ TEST_F(KineticsFromScratch, add_falloff_reaction)
|
||||||
ThirdBody tbody;
|
ThirdBody tbody;
|
||||||
tbody.efficiencies = parseCompString("AR:0.7 H2:2.0 H2O:6.0");
|
tbody.efficiencies = parseCompString("AR:0.7 H2:2.0 H2O:6.0");
|
||||||
shared_ptr<FalloffReaction> R(new FalloffReaction(reac, prod, low_rate,
|
shared_ptr<FalloffReaction> R(new FalloffReaction(reac, prod, low_rate,
|
||||||
high_rate, tbody, TROE_FALLOFF,
|
high_rate, tbody));
|
||||||
falloff_params));
|
R->falloff = newFalloff(TROE_FALLOFF, falloff_params);
|
||||||
kin.addReaction(R);
|
kin.addReaction(R);
|
||||||
kin.finalize();
|
kin.finalize();
|
||||||
check_rates(2);
|
check_rates(2);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue