Skip to content

Commit

Permalink
[Kinetics] rename Reaction2::setup to Reaction2::setParameters
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Mar 19, 2021
1 parent 5369f51 commit b770450
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 55 deletions.
6 changes: 3 additions & 3 deletions include/cantera/kinetics/Reaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class Reaction2 : public Reaction
}

//! Set up reaction based on AnyMap node
virtual void setup(const AnyMap& node, const Kinetics& kin);
virtual void setParameters(const AnyMap& node, const Kinetics& kin);

protected:
//! Reaction rate used by generic reactions
Expand Down Expand Up @@ -281,7 +281,7 @@ class CustomFunc1Reaction : public Reaction2
public:
CustomFunc1Reaction();

virtual void setup(const AnyMap& node, const Kinetics& kin);
virtual void setParameters(const AnyMap& node, const Kinetics& kin);

virtual std::string type() const {
return "custom-rate-function";
Expand All @@ -306,7 +306,7 @@ class TestReaction : public Reaction2
return "elementary-new";
}

virtual void setup(const AnyMap& node, const Kinetics& kin);
virtual void setParameters(const AnyMap& node, const Kinetics& kin);

bool allow_negative_pre_exponential_factor;
};
Expand Down
13 changes: 4 additions & 9 deletions include/cantera/kinetics/ReactionRate.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ class ReactionRate : public ReactionRateBase
public:
ReactionRate() = default;

ReactionRate(const AnyMap& node, const Units& rc_units) {
throw CanteraError("ReactionRate::ReactionRate",
"Constructor needs to be implemented by derived classes.");
}

//! Update information specific to reaction
//! @param shared_data data shared by all reactions of a given type
virtual void update(const DataType& shared_data, const ThermoPhase& bulk) {}
Expand Down Expand Up @@ -148,8 +143,8 @@ class ArrheniusRate final : public ReactionRate<ArrheniusData>, public Arrhenius

//! Constructor
//! @param node AnyMap object containing reaction rate specification
//! @param rc_units Description of units used for rate parameters
ArrheniusRate(const AnyMap& node, const Units& rc_units);
//! @param rate_units Description of units used for rate parameters
ArrheniusRate(const AnyMap& node, const Units& rate_units);

virtual std::string type() const override { return "ArrheniusRate"; }

Expand Down Expand Up @@ -182,8 +177,8 @@ class CustomFunc1Rate final : public ReactionRate<CustomFunc1Data>

//! Constructor does nothing, as there is no formalized parameterization
//! @param node AnyMap object containing reaction rate specification
//! @param rc_units Description of units used for rate parameters
CustomFunc1Rate(const AnyMap& rate, const Units& rc_units) {}
//! @param rate_units Description of units used for rate parameters
CustomFunc1Rate(const AnyMap& rate, const Units& rate_units) {}

virtual std::string type() const override { return "custom-function"; }

Expand Down
4 changes: 2 additions & 2 deletions include/cantera/kinetics/RxnRates.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class Arrhenius
Arrhenius(doublereal A, doublereal b, doublereal E);

//! Run object setup based on AnyMap node information
void setup(const AnyValue& rate,
const UnitSystem& units, const Units& rc_units);
void setParameters(const AnyValue& rate,
const UnitSystem& units, const Units& rate_units);

//! Update concentration-dependent parts of the rate coefficient.
/*!
Expand Down
66 changes: 33 additions & 33 deletions src/kinetics/Reaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,29 +98,6 @@ void Reaction::validate()
}
}

void Reaction2::setup(const AnyMap& node, const Kinetics& kin)
{
parseReactionEquation(*this, node["equation"], kin);
// Non-stoichiometric reaction orders
std::map<std::string, double> orders;
if (node.hasKey("orders")) {
for (const auto& order : node["orders"].asMap<double>()) {
orders[order.first] = order.second;
if (kin.kineticsSpeciesIndex(order.first) == npos) {
setValid(false);
}
}
}

// Flags
id = node.getString("id", "");
duplicate = node.getBool("duplicate", false);
allow_negative_orders = node.getBool("negative-orders", false);
allow_nonreactant_orders = node.getBool("nonreactant-orders", false);

input = node;
}

std::string Reaction::reactantString() const
{
std::ostringstream result;
Expand Down Expand Up @@ -320,18 +297,41 @@ ChebyshevReaction::ChebyshevReaction(const Composition& reactants_,
reaction_type = CHEBYSHEV_RXN;
}

void Reaction2::setParameters(const AnyMap& node, const Kinetics& kin)
{
parseReactionEquation(*this, node["equation"], kin);
// Non-stoichiometric reaction orders
std::map<std::string, double> orders;
if (node.hasKey("orders")) {
for (const auto& order : node["orders"].asMap<double>()) {
orders[order.first] = order.second;
if (kin.kineticsSpeciesIndex(order.first) == npos) {
setValid(false);
}
}
}

// Flags
id = node.getString("id", "");
duplicate = node.getBool("duplicate", false);
allow_negative_orders = node.getBool("negative-orders", false);
allow_nonreactant_orders = node.getBool("nonreactant-orders", false);

input = node;
}

CustomFunc1Reaction::CustomFunc1Reaction()
: Reaction2()
{
reaction_type = CUSTOMPY_RXN;
}

void CustomFunc1Reaction::setup(const AnyMap& node, const Kinetics& kin)
void CustomFunc1Reaction::setParameters(const AnyMap& node, const Kinetics& kin)
{
Reaction2::setup(node, kin);
Units rc_units; // @todo Not needed once `rate_units` is implemented.
Reaction2::setParameters(node, kin);
Units rate_units; // @todo Not needed once `rate_units` is implemented.
setRate(
std::shared_ptr<CustomFunc1Rate>(new CustomFunc1Rate(node, rc_units)));
std::shared_ptr<CustomFunc1Rate>(new CustomFunc1Rate(node, rate_units)));
}

TestReaction::TestReaction()
Expand All @@ -340,15 +340,15 @@ TestReaction::TestReaction()
{
}

void TestReaction::setup(const AnyMap& node, const Kinetics& kin)
void TestReaction::setParameters(const AnyMap& node, const Kinetics& kin)
{
Reaction2::setup(node, kin);
Reaction2::setParameters(node, kin);

// @todo Rate units will become available as `rate_units` after
// serialization is fully implemented.
Units rc_units = rateCoeffUnits(*this, kin);
Units rate_units = rateCoeffUnits(*this, kin);
setRate(
std::shared_ptr<ArrheniusRate>(new ArrheniusRate(node, rc_units)));
std::shared_ptr<ArrheniusRate>(new ArrheniusRate(node, rate_units)));
allow_negative_pre_exponential_factor = node.getBool("negative-A", false);
}

Expand Down Expand Up @@ -434,9 +434,9 @@ Arrhenius readArrhenius(const Reaction& R, const AnyValue& rate,
const Kinetics& kin, const UnitSystem& units,
int pressure_dependence=0)
{
Units rc_units = rateCoeffUnits(R, kin, pressure_dependence);
Units rate_units = rateCoeffUnits(R, kin, pressure_dependence);
Arrhenius arr;
arr.setup(rate, units, rc_units);
arr.setParameters(rate, units, rate_units);
return arr;
}

Expand Down
4 changes: 2 additions & 2 deletions src/kinetics/ReactionFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ ReactionFactory::ReactionFactory()
});
reg_AnyMap("custom-rate-function",
[](Reaction* R, const AnyMap& node, const Kinetics& kin) {
((Reaction2*)R)->setup(node, kin);
((Reaction2*)R)->setParameters(node, kin);
});

// register custom Python reactions
Expand All @@ -117,7 +117,7 @@ ReactionFactory::ReactionFactory()
});
reg_AnyMap("elementary-new",
[](Reaction* R, const AnyMap& node, const Kinetics& kin) {
(dynamic_cast<Reaction2*>(R))->setup(node, kin);
(dynamic_cast<Reaction2*>(R))->setParameters(node, kin);
});

// register interface reactions
Expand Down
4 changes: 2 additions & 2 deletions src/kinetics/ReactionRate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ ArrheniusRate::ArrheniusRate(double A, double b, double E)
: Arrhenius(A, b, E) {
}

ArrheniusRate::ArrheniusRate(const AnyMap& node, const Units& rc_units) {
setup(node["rate-constant"], node.units(), rc_units);
ArrheniusRate::ArrheniusRate(const AnyMap& node, const Units& rate_units) {
setParameters(node["rate-constant"], node.units(), rate_units);
}

CustomFunc1Rate::CustomFunc1Rate() : m_ratefunc(0) {}
Expand Down
8 changes: 4 additions & 4 deletions src/kinetics/RxnRates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ Arrhenius::Arrhenius(doublereal A, doublereal b, doublereal E)
}
}

void Arrhenius::setup(const AnyValue& rate,
const UnitSystem& units, const Units& rc_units)
void Arrhenius::setParameters(const AnyValue& rate,
const UnitSystem& units, const Units& rate_units)
{
if (rate.is<AnyMap>()) {
auto& rate_map = rate.as<AnyMap>();
m_A = units.convert(rate_map["A"], rc_units);
m_A = units.convert(rate_map["A"], rate_units);
m_b = rate_map["b"].asDouble();
m_E = units.convertActivationEnergy(rate_map["Ea"], "K");
} else {
auto& rate_vec = rate.asVector<AnyValue>(3);
m_A = units.convert(rate_vec[0], rc_units);
m_A = units.convert(rate_vec[0], rate_units);
m_b = rate_vec[1].asDouble();
m_E = units.convertActivationEnergy(rate_vec[2], "K");
}
Expand Down

0 comments on commit b770450

Please sign in to comment.