[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:
Ray Speth 2015-04-22 17:35:17 -04:00
parent 873724c135
commit 9d4a3e0f75
7 changed files with 48 additions and 41 deletions

View file

@ -11,6 +11,7 @@
#include "cantera/base/FactoryBase.h"
#include "cantera/base/ct_thread.h"
#include "cantera/base/smart_ptr.h"
#include "cantera/kinetics/Falloff.h"
namespace Cantera
@ -71,5 +72,8 @@ private:
static mutex_t falloff_mutex;
};
//! @copydoc FalloffFactory::newFalloff
shared_ptr<Falloff> newFalloff(int type, const vector_fp& c);
}
#endif

View file

@ -9,6 +9,7 @@
#include "reaction_defs.h"
#include "FalloffFactory.h"
#include "cantera/base/global.h"
namespace Cantera
{
@ -29,17 +30,6 @@ public:
//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.
/*
* @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 reactionType Either `FALLOFF_RXN` or `CHEMACT_RXN`
* @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,
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);
Falloff* f = m_factory->newFalloff(falloffType,c);
m_offset.push_back(m_worksize);
m_worksize += f->workSize();
m_falloff.push_back(f);
@ -96,7 +101,7 @@ public:
protected:
std::vector<size_t> m_rxn;
std::vector<Falloff*> m_falloff;
std::vector<shared_ptr<Falloff> > m_falloff;
FalloffFactory* m_factory;
vector_int m_loc;
std::vector<vector_fp::difference_type> m_offset;

View file

@ -8,6 +8,7 @@
#include "cantera/base/utilities.h"
#include "cantera/base/smart_ptr.h"
#include "cantera/kinetics/RxnRates.h"
#include "cantera/kinetics/Falloff.h"
namespace Cantera
{
@ -128,8 +129,7 @@ public:
FalloffReaction();
FalloffReaction(const Composition& reactants, const Composition& products,
const Arrhenius& low_rate, const Arrhenius& high_rate,
const ThirdBody& tbody, int falloff_type,
const vector_fp& falloff_params);
const ThirdBody& tbody);
virtual std::string reactantString() const;
virtual std::string productString() const;
virtual void validate();
@ -143,13 +143,9 @@ public:
//! Relative efficiencies of third-body species in enhancing the reaction rate
ThirdBody third_body;
//! Type of falloff parameterization to use. Values are defined in
//! reaction_defs.h, with names ending in `FALLOFF`.
int falloff_type;
//! Values used in the falloff parameterization. Meaning of each parameter
//! depends on #falloff_type.
vector_fp falloff_parameters;
//! Falloff function which determines how low_rate and high_rate are
//! combined to determine the rate constant for the reaction.
shared_ptr<Falloff> falloff;
};
//! A reaction where the rate decreases as pressure increases due to collisional
@ -162,8 +158,7 @@ public:
ChemicallyActivatedReaction();
ChemicallyActivatedReaction(const Composition& reactants,
const Composition& products, const Arrhenius& low_rate,
const Arrhenius& high_rate, const ThirdBody& tbody, int falloff_type,
const vector_fp& falloff_params);
const Arrhenius& high_rate, const ThirdBody& tbody);
};
//! A pressure-dependent reaction parameterized by logarithmically interpolating

View file

@ -32,4 +32,10 @@ Falloff* FalloffFactory::newFalloff(int type, const vector_fp& c)
return f;
}
shared_ptr<Falloff> newFalloff(int type, const vector_fp& c)
{
shared_ptr<Falloff> f(FalloffFactory::factory()->newFalloff(type, c));
return f;
}
}

View file

@ -361,8 +361,7 @@ void GasKinetics::addFalloffReaction(FalloffReaction& r)
r.third_body.default_efficiency);
// install the falloff function calculator for this reaction
m_falloffn.install(m_nfall, r.falloff_type, r.reaction_type,
r.falloff_parameters);
m_falloffn.install(m_nfall, r.reaction_type, r.falloff);
// increment the falloff reaction counter
++m_nfall;

View file

@ -3,6 +3,7 @@
*/
#include "cantera/kinetics/Reaction.h"
#include "cantera/kinetics/FalloffFactory.h"
#include "cantera/base/ctml.h"
#include "cantera/base/Array.h"
#include <sstream>
@ -157,21 +158,17 @@ std::string ThirdBodyReaction::productString() const {
FalloffReaction::FalloffReaction()
: Reaction(FALLOFF_RXN)
, falloff_type(-1)
{
}
FalloffReaction::FalloffReaction(
const Composition& reactants_, const Composition& products_,
const Arrhenius& low_rate_, const Arrhenius& high_rate_,
const ThirdBody& tbody, int type,
const vector_fp& params)
const ThirdBody& tbody)
: Reaction(FALLOFF_RXN, reactants_, products_)
, low_rate(low_rate_)
, high_rate(high_rate_)
, third_body(tbody)
, falloff_type(type)
, falloff_parameters(params)
{
}
@ -212,10 +209,8 @@ ChemicallyActivatedReaction::ChemicallyActivatedReaction()
ChemicallyActivatedReaction::ChemicallyActivatedReaction(
const Composition& reactants_, const Composition& products_,
const Arrhenius& low_rate_, const Arrhenius& high_rate_,
const ThirdBody& tbody, int falloff_type,
const vector_fp& falloff_params)
: FalloffReaction(reactants_, products_, low_rate, high_rate, tbody,
falloff_type, falloff_params)
const ThirdBody& tbody)
: FalloffReaction(reactants_, products_, low_rate, high_rate, tbody)
{
reaction_type = CHEMACT_RXN;
}
@ -300,26 +295,28 @@ void readFalloff(FalloffReaction& R, const XML_Node& rc_node)
{
XML_Node& falloff = rc_node.child("falloff");
std::vector<std::string> p;
vector_fp falloff_parameters;
getStringArray(falloff, p);
size_t np = p.size();
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") {
R.falloff_type = SIMPLE_FALLOFF;
falloff_type = SIMPLE_FALLOFF;
if (np != 0) {
throw CanteraError("readFalloff", "Lindemann parameterization "
"takes no parameters, but " + int2str(np) + "were given");
}
} else if (lowercase(falloff["type"]) == "troe") {
R.falloff_type = TROE_FALLOFF;
falloff_type = TROE_FALLOFF;
if (np != 3 && np != 4) {
throw CanteraError("readFalloff", "Troe parameterization takes "
"3 or 4 parameters, but " + int2str(np) + "were given");
}
} else if (lowercase(falloff["type"]) == "sri") {
R.falloff_type = SRI_FALLOFF;
falloff_type = SRI_FALLOFF;
if (np != 3 && np != 5) {
throw CanteraError("readFalloff", "SRI parameterization takes "
"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: '" +
falloff["type"] + "'");
}
R.falloff = newFalloff(falloff_type, falloff_parameters);
}
void readEfficiencies(ThirdBody& tbody, const XML_Node& rc_node)

View file

@ -125,8 +125,8 @@ TEST_F(KineticsFromScratch, add_falloff_reaction)
ThirdBody tbody;
tbody.efficiencies = parseCompString("AR:0.7 H2:2.0 H2O:6.0");
shared_ptr<FalloffReaction> R(new FalloffReaction(reac, prod, low_rate,
high_rate, tbody, TROE_FALLOFF,
falloff_params));
high_rate, tbody));
R->falloff = newFalloff(TROE_FALLOFF, falloff_params);
kin.addReaction(R);
kin.finalize();
check_rates(2);