[Kinetics] Eliminate need for 'finalize' method
All reaction-sized arrays are now allocated as reactions are added, which means that the finalize() method is unnecessary and reactions can be continuously added, even after the Kinetics object has been used for rate calculations.
This commit is contained in:
parent
4428a62f3c
commit
1f231d1dd0
13 changed files with 28 additions and 117 deletions
|
|
@ -36,8 +36,6 @@ public:
|
|||
|
||||
virtual bool addReaction(shared_ptr<Reaction> r);
|
||||
virtual void init();
|
||||
virtual void finalize();
|
||||
virtual bool ready() const;
|
||||
|
||||
virtual void setMultiplier(size_t i, double f);
|
||||
virtual void invalidateCache();
|
||||
|
|
|
|||
|
|
@ -21,7 +21,9 @@ class EdgeKinetics : public InterfaceKinetics
|
|||
{
|
||||
public:
|
||||
//! Constructor
|
||||
EdgeKinetics() : InterfaceKinetics() {}
|
||||
EdgeKinetics() : InterfaceKinetics() {
|
||||
m_nDim = 1;
|
||||
}
|
||||
|
||||
EdgeKinetics(const EdgeKinetics& right) :
|
||||
InterfaceKinetics(right) {
|
||||
|
|
@ -44,8 +46,6 @@ public:
|
|||
virtual int type() const {
|
||||
return cEdgeKinetics;
|
||||
}
|
||||
|
||||
virtual void finalize();
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,8 +53,6 @@ public:
|
|||
virtual void init();
|
||||
virtual bool addReaction(shared_ptr<Reaction> r);
|
||||
virtual void modifyReaction(size_t i, shared_ptr<Reaction> rNew);
|
||||
virtual void finalize();
|
||||
virtual bool ready() const;
|
||||
virtual void invalidateCache();
|
||||
//@}
|
||||
|
||||
|
|
|
|||
|
|
@ -200,8 +200,6 @@ public:
|
|||
virtual void init();
|
||||
virtual bool addReaction(shared_ptr<Reaction> r);
|
||||
virtual void modifyReaction(size_t i, shared_ptr<Reaction> rNew);
|
||||
virtual void finalize();
|
||||
virtual bool ready() const;
|
||||
//! @}
|
||||
|
||||
//! Internal routine that updates the Rates of Progress of the reactions
|
||||
|
|
@ -674,6 +672,10 @@ protected:
|
|||
void applyStickingCorrection(double* kf);
|
||||
|
||||
int m_ioFlag;
|
||||
|
||||
//! Number of dimensions of reacting phase (2 for InterfaceKinetics, 1 for
|
||||
//! EdgeKinetics)
|
||||
size_t m_nDim;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -730,6 +730,7 @@ public:
|
|||
* The base class method does nothing, but derived classes may use this to
|
||||
* perform any initialization (allocating arrays, etc.) that must be done
|
||||
* after the reactions are entered.
|
||||
* @deprecated No longer needed. To be removed after Cantera 2.3.
|
||||
*/
|
||||
virtual void finalize();
|
||||
|
||||
|
|
@ -810,9 +811,12 @@ public:
|
|||
/**
|
||||
* Returns true if the kinetics manager has been properly initialized and
|
||||
* finalized.
|
||||
* @deprecated Object is always ready. To be removed after Cantera 2.3.
|
||||
*/
|
||||
virtual bool ready() const {
|
||||
return false;
|
||||
warn_deprecated("Kinetics::ready",
|
||||
"Object is always ready. To be removed after Cantera 2.3.");
|
||||
return true;
|
||||
}
|
||||
|
||||
//! Check for duplicate reactions.
|
||||
|
|
|
|||
|
|
@ -361,7 +361,6 @@ cdef extern from "cantera/kinetics/Kinetics.h" namespace "Cantera":
|
|||
void init() except +
|
||||
void skipUndeclaredThirdBodies(cbool)
|
||||
void addReaction(shared_ptr[CxxReaction]) except +
|
||||
void finalize() except +
|
||||
void modifyReaction(int, shared_ptr[CxxReaction]) except +
|
||||
void invalidateCache() except +
|
||||
|
||||
|
|
|
|||
|
|
@ -102,7 +102,6 @@ cdef class _SolutionBase:
|
|||
self.kinetics.skipUndeclaredThirdBodies(True)
|
||||
for reaction in reactions:
|
||||
self.kinetics.addReaction(reaction._reaction)
|
||||
self.kinetics.finalize()
|
||||
|
||||
|
||||
def __getitem__(self, selection):
|
||||
|
|
|
|||
|
|
@ -144,16 +144,6 @@ void BulkKinetics::init()
|
|||
m_grt.resize(m_kk);
|
||||
}
|
||||
|
||||
void BulkKinetics::finalize()
|
||||
{
|
||||
m_finalized = true;
|
||||
}
|
||||
|
||||
bool BulkKinetics::ready() const
|
||||
{
|
||||
return m_finalized;
|
||||
}
|
||||
|
||||
void BulkKinetics::setMultiplier(size_t i, double f) {
|
||||
Kinetics::setMultiplier(i, f);
|
||||
m_ROP_ok = false;
|
||||
|
|
|
|||
|
|
@ -294,9 +294,11 @@ void GasKinetics::addFalloffReaction(FalloffReaction& r)
|
|||
}
|
||||
m_falloff_concm.install(nfall, efficiencies,
|
||||
r.third_body.default_efficiency);
|
||||
concm_falloff_values.resize(m_falloff_concm.workSize());
|
||||
|
||||
// install the falloff function calculator for this reaction
|
||||
m_falloffn.install(nfall, r.reaction_type, r.falloff);
|
||||
falloff_work.resize(m_falloffn.workSize());
|
||||
}
|
||||
|
||||
void GasKinetics::addThreeBodyReaction(ThreeBodyReaction& r)
|
||||
|
|
@ -315,6 +317,7 @@ void GasKinetics::addThreeBodyReaction(ThreeBodyReaction& r)
|
|||
}
|
||||
m_3b_concm.install(nReactions()-1, efficiencies,
|
||||
r.third_body.default_efficiency);
|
||||
concm_3b_values.resize(m_3b_concm.workSize());
|
||||
}
|
||||
|
||||
void GasKinetics::addPlogReaction(PlogReaction& r)
|
||||
|
|
@ -389,19 +392,6 @@ void GasKinetics::init()
|
|||
m_logp_ref = log(thermo().refPressure()) - log(GasConstant);
|
||||
}
|
||||
|
||||
void GasKinetics::finalize()
|
||||
{
|
||||
BulkKinetics::finalize();
|
||||
falloff_work.resize(m_falloffn.workSize());
|
||||
concm_3b_values.resize(m_3b_concm.workSize());
|
||||
concm_falloff_values.resize(m_falloff_concm.workSize());
|
||||
}
|
||||
|
||||
bool GasKinetics::ready() const
|
||||
{
|
||||
return m_finalized;
|
||||
}
|
||||
|
||||
void GasKinetics::invalidateCache()
|
||||
{
|
||||
BulkKinetics::invalidateCache();
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
// Copyright 2002 California Institute of Technology
|
||||
|
||||
#include "cantera/kinetics/InterfaceKinetics.h"
|
||||
#include "cantera/kinetics/EdgeKinetics.h"
|
||||
#include "cantera/kinetics/RateCoeffMgr.h"
|
||||
#include "cantera/kinetics/ImplicitSurfChem.h"
|
||||
#include "cantera/thermo/SurfPhase.h"
|
||||
|
|
@ -31,7 +30,8 @@ InterfaceKinetics::InterfaceKinetics(thermo_t* thermo) :
|
|||
m_has_electrochem_rxns(false),
|
||||
m_has_exchange_current_density_formulation(false),
|
||||
m_phaseExistsCheck(false),
|
||||
m_ioFlag(0)
|
||||
m_ioFlag(0),
|
||||
m_nDim(2)
|
||||
{
|
||||
if (thermo != 0) {
|
||||
addPhase(*thermo);
|
||||
|
|
@ -708,6 +708,12 @@ bool InterfaceKinetics::addReaction(shared_ptr<Reaction> r_base)
|
|||
size_t p = speciesPhaseIndex(k);
|
||||
m_rxnPhaseIsProduct[i][p] = true;
|
||||
}
|
||||
|
||||
deltaElectricEnergy_.push_back(0.0);
|
||||
m_deltaG0.push_back(0.0);
|
||||
m_deltaG.push_back(0.0);
|
||||
m_ProdStanConcReac.push_back(0.0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -828,38 +834,25 @@ void InterfaceKinetics::init()
|
|||
}
|
||||
m_actConc.resize(m_kk);
|
||||
m_conc.resize(m_kk);
|
||||
m_StandardConc.resize(m_kk, 0.0);
|
||||
m_mu0.resize(m_kk);
|
||||
m_mu.resize(m_kk);
|
||||
m_mu0_Kc.resize(m_kk);
|
||||
m_grt.resize(m_kk);
|
||||
m_pot.resize(m_kk, 0.0);
|
||||
m_phi.resize(nPhases(), 0.0);
|
||||
}
|
||||
|
||||
void InterfaceKinetics::finalize()
|
||||
{
|
||||
Kinetics::finalize();
|
||||
deltaElectricEnergy_.resize(nReactions());
|
||||
size_t ks = reactionPhaseIndex();
|
||||
if (ks == npos) throw CanteraError("InterfaceKinetics::finalize",
|
||||
"no surface phase is present.");
|
||||
|
||||
// Check to see that the interface routine has a dimension of 2
|
||||
m_surf = (SurfPhase*)&thermo(ks);
|
||||
if (m_surf->nDim() != 2) {
|
||||
if (m_surf->nDim() != m_nDim) {
|
||||
throw CanteraError("InterfaceKinetics::finalize",
|
||||
"expected interface dimension = 2, but got dimension = {}",
|
||||
m_surf->nDim());
|
||||
}
|
||||
m_StandardConc.resize(m_kk, 0.0);
|
||||
m_deltaG0.resize(nReactions(), 0.0);
|
||||
m_deltaG.resize(nReactions(), 0.0);
|
||||
m_ProdStanConcReac.resize(nReactions(), 0.0);
|
||||
|
||||
if (m_thermo.size() != m_phaseExists.size()) {
|
||||
throw CanteraError("InterfaceKinetics::finalize", "internal error");
|
||||
}
|
||||
m_finalized = true;
|
||||
}
|
||||
|
||||
doublereal InterfaceKinetics::electrochem_beta(size_t irxn) const
|
||||
|
|
@ -872,11 +865,6 @@ doublereal InterfaceKinetics::electrochem_beta(size_t irxn) const
|
|||
return 0.0;
|
||||
}
|
||||
|
||||
bool InterfaceKinetics::ready() const
|
||||
{
|
||||
return m_finalized;
|
||||
}
|
||||
|
||||
void InterfaceKinetics::advanceCoverages(doublereal tstep)
|
||||
{
|
||||
if (m_integrator == 0) {
|
||||
|
|
@ -1013,48 +1001,4 @@ void InterfaceKinetics::applyStickingCorrection(double* kf)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void EdgeKinetics::finalize()
|
||||
{
|
||||
// Note we can't call the Interface::finalize() routine because we need to
|
||||
// check for a dimension of 1 below. Therefore, we have to malloc room in
|
||||
// arrays that would normally be handled by the
|
||||
// InterfaceKinetics::finalize() call.
|
||||
Kinetics::finalize();
|
||||
|
||||
size_t safe_reaction_size = std::max<size_t>(nReactions(), 1);
|
||||
deltaElectricEnergy_.resize(safe_reaction_size);
|
||||
size_t ks = reactionPhaseIndex();
|
||||
if (ks == npos) throw CanteraError("EdgeKinetics::finalize",
|
||||
"no surface phase is present.");
|
||||
|
||||
// Check to see edge phase has a dimension of 1
|
||||
m_surf = (SurfPhase*)&thermo(ks);
|
||||
if (m_surf->nDim() != 1) {
|
||||
throw CanteraError("EdgeKinetics::finalize",
|
||||
"expected interface dimension = 1, but got dimension = {}",
|
||||
m_surf->nDim());
|
||||
}
|
||||
m_StandardConc.resize(m_kk, 0.0);
|
||||
m_deltaG0.resize(safe_reaction_size, 0.0);
|
||||
m_deltaG.resize(safe_reaction_size, 0.0);
|
||||
|
||||
m_ProdStanConcReac.resize(safe_reaction_size, 0.0);
|
||||
|
||||
if (m_thermo.size() != m_phaseExists.size()) {
|
||||
throw CanteraError("InterfaceKinetics::finalize", "internal error");
|
||||
}
|
||||
|
||||
// Guarantee that these arrays can be converted to double* even in the
|
||||
// special case where there are no reactions defined.
|
||||
if (!nReactions()) {
|
||||
m_perturb.resize(1, 1.0);
|
||||
m_ropf.resize(1, 0.0);
|
||||
m_ropr.resize(1, 0.0);
|
||||
m_ropnet.resize(1, 0.0);
|
||||
m_rkcn.resize(1, 0.0);
|
||||
}
|
||||
m_finalized = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -513,15 +513,13 @@ void Kinetics::addPhase(thermo_t& thermo)
|
|||
}
|
||||
m_thermo.push_back(&thermo);
|
||||
m_phaseindex[m_thermo.back()->id()] = nPhases();
|
||||
m_kk += thermo.nSpecies();
|
||||
}
|
||||
|
||||
void Kinetics::finalize()
|
||||
{
|
||||
m_kk = 0;
|
||||
for (size_t n = 0; n < nPhases(); n++) {
|
||||
size_t nsp = m_thermo[n]->nSpecies();
|
||||
m_kk += nsp;
|
||||
}
|
||||
warn_deprecated("Kinetics::finalize",
|
||||
"No longer needed. To be removed after Cantera 2.3.");
|
||||
}
|
||||
|
||||
bool Kinetics::addReaction(shared_ptr<Reaction> r)
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ bool installReactionArrays(const XML_Node& p, Kinetics& kin,
|
|||
// purely additive.
|
||||
vector<XML_Node*> rarrays = p.getChildren("reactionArray");
|
||||
if (rarrays.empty()) {
|
||||
kin.finalize();
|
||||
return false;
|
||||
}
|
||||
for (size_t n = 0; n < rarrays.size(); n++) {
|
||||
|
|
@ -122,9 +121,6 @@ bool installReactionArrays(const XML_Node& p, Kinetics& kin,
|
|||
kin.checkDuplicates();
|
||||
}
|
||||
|
||||
// Finalize the installation of the kinetics, now that we know the true
|
||||
// number of reactions in the mechanism, itot.
|
||||
kin.finalize();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,6 @@ TEST_F(KineticsFromScratch, add_elementary_reaction)
|
|||
auto R = make_shared<ElementaryReaction>(reac, prod, rate);
|
||||
|
||||
kin.addReaction(R);
|
||||
kin.finalize();
|
||||
check_rates(0);
|
||||
}
|
||||
|
||||
|
|
@ -74,7 +73,6 @@ TEST_F(KineticsFromScratch, add_three_body_reaction)
|
|||
auto R = make_shared<ThreeBodyReaction>(reac, prod, rate, tbody);
|
||||
|
||||
kin.addReaction(R);
|
||||
kin.finalize();
|
||||
check_rates(1);
|
||||
}
|
||||
|
||||
|
|
@ -123,7 +121,6 @@ TEST_F(KineticsFromScratch, add_falloff_reaction)
|
|||
auto R = make_shared<FalloffReaction>(reac, prod, low_rate, high_rate, tbody);
|
||||
R->falloff = newFalloff(TROE_FALLOFF, falloff_params);
|
||||
kin.addReaction(R);
|
||||
kin.finalize();
|
||||
check_rates(2);
|
||||
}
|
||||
|
||||
|
|
@ -146,7 +143,6 @@ TEST_F(KineticsFromScratch, add_plog_reaction)
|
|||
|
||||
auto R = make_shared<PlogReaction>(reac, prod, Plog(rates));
|
||||
kin.addReaction(R);
|
||||
kin.finalize();
|
||||
check_rates(3);
|
||||
}
|
||||
|
||||
|
|
@ -194,7 +190,6 @@ TEST_F(KineticsFromScratch, add_chebyshev_reaction)
|
|||
|
||||
auto R = make_shared<ChebyshevReaction>(reac, prod, rate);
|
||||
kin.addReaction(R);
|
||||
kin.finalize();
|
||||
check_rates(4);
|
||||
}
|
||||
|
||||
|
|
@ -369,7 +364,6 @@ TEST_F(InterfaceKineticsFromScratch, add_surface_reaction)
|
|||
|
||||
auto R = make_shared<InterfaceReaction>(reac, prod, rate);
|
||||
kin.addReaction(R);
|
||||
kin.finalize();
|
||||
check_rates(3);
|
||||
}
|
||||
|
||||
|
|
@ -384,6 +378,5 @@ TEST_F(InterfaceKineticsFromScratch, add_sticking_reaction)
|
|||
|
||||
auto R = make_shared<InterfaceReaction>(reac, prod, rate, true);
|
||||
kin.addReaction(R);
|
||||
kin.finalize();
|
||||
check_rates(0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue