Skip to content

Commit

Permalink
[Kinetics] Introduce Reaction::check to clarify API
Browse files Browse the repository at this point in the history
Reaction::check (renamed from no-argument Reaction::validate)
does not require a Kinetics object; nomenclature reflects
ReactionRate::check and ReactionRate::validate.
  • Loading branch information
ischoegl committed May 29, 2022
1 parent d9c4246 commit 64cdc21
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
15 changes: 12 additions & 3 deletions include/cantera/kinetics/Reaction.h
Expand Up @@ -72,9 +72,18 @@ class Reaction
return calculateRateCoeffUnits(kin);
}

//! Ensure that the rate constant and other parameters for this reaction are
//! valid.
virtual void validate();
//! Ensure that the rate constant and other parameters for this reaction are valid.
//! @since New in Cantera 3.0.
virtual void check();

//! Ensure that the rate constant and other parameters for this reaction are valid.
//! @deprecated To be removed after Cantera 3.0. Replaceable by check.
virtual void validate() {
warn_deprecated("Reaction::validate",
"Deprecated in Cantera 3.0 and to be removed thereafter; replaceable "
"by Reaction::check.");
check();
}

//! Perform validation checks that need access to a complete Kinetics objects, for
// example to retrieve information about reactant / product species.
Expand Down
1 change: 0 additions & 1 deletion interfaces/cython/cantera/_cantera.pxd
Expand Up @@ -602,7 +602,6 @@ cdef extern from "cantera/kinetics/Reaction.h" namespace "Cantera":
string equation()
void setEquation(const string&) except +translate_exception
string type()
void validate() except +translate_exception
CxxAnyMap parameters(cbool) except +translate_exception
CxxAnyMap input
Composition reactants
Expand Down
2 changes: 1 addition & 1 deletion src/kinetics/Kinetics.cpp
Expand Up @@ -616,7 +616,7 @@ void Kinetics::resizeSpecies()

bool Kinetics::addReaction(shared_ptr<Reaction> r, bool resize)
{
r->validate();
r->check();
r->validate(*this);

if (m_kk == 0) {
Expand Down
8 changes: 5 additions & 3 deletions src/kinetics/Reaction.cpp
Expand Up @@ -84,9 +84,10 @@ Reaction::Reaction(const AnyMap& node, const Kinetics& kin)
// This route is used by the Python API.
setRate(newReactionRate(node));
}
check();
}

void Reaction::validate()
void Reaction::check()
{
if (!allow_nonreactant_orders) {
for (const auto& order : orders) {
Expand Down Expand Up @@ -117,7 +118,8 @@ void Reaction::validate()
"Reaction orders may only be given for irreversible reactions");
}

// Call validation of reaction rate evaluator
// Check reaction rate evaluator to ensure changes introduced after object
// instantiation are considered.
m_rate->check(equation(), input);
}

Expand Down Expand Up @@ -960,7 +962,7 @@ std::vector<shared_ptr<Reaction>> getReactions(const AnyValue& items,
std::vector<shared_ptr<Reaction>> all_reactions;
for (const auto& node : items.asVector<AnyMap>()) {
shared_ptr<Reaction> R(newReaction(node, kinetics));
R->validate();
R->check();
R->validate(kinetics);
if (R->valid() && R->checkSpecies(kinetics)) {
all_reactions.emplace_back(R);
Expand Down

0 comments on commit 64cdc21

Please sign in to comment.