Skip to content

Commit

Permalink
delete the redundant checks and fix the code format
Browse files Browse the repository at this point in the history
  • Loading branch information
12Chao committed Oct 25, 2021
1 parent d6bf509 commit c1408b4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 106 deletions.
19 changes: 8 additions & 11 deletions include/cantera/kinetics/Reaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ class Reaction
virtual void validate();

//! New validate function takes kinetics object as the input
virtual void validate(Kinetics& kin);
//! Perform validation checks that need access to a complete
//! Kinetics objects, for example to retrieve information about
//! reactant / product species.
virtual void validate(Kinetics& kin){};

//! Return the parameters such that an identical Reaction could be reconstructed
//! using the newReaction() function. Behavior specific to derived classes is
Expand Down Expand Up @@ -191,8 +194,7 @@ class ElementaryReaction2 : public Reaction
const Arrhenius& rate);

virtual void validate();
//! New validate function takes kinetics object as the input
virtual void validate(Kinetics& kin);
virtual void validate(Kinetics& kin){};
virtual void getParameters(AnyMap& reactionNode) const;

virtual std::string type() const {
Expand Down Expand Up @@ -275,8 +277,7 @@ class FalloffReaction : public Reaction
virtual std::string productString() const;

virtual void validate();
//! New validate function takes kinetics object as the input
virtual void validate(Kinetics& kin);
virtual void validate(Kinetics& kin){};
virtual void calculateRateCoeffUnits(const Kinetics& kin);
virtual void getParameters(AnyMap& reactionNode) const;

Expand Down Expand Up @@ -340,8 +341,7 @@ class PlogReaction2 : public Reaction
}

virtual void validate();
//! New validate function takes kinetics object as the input
virtual void validate(Kinetics& kin);
virtual void validate(Kinetics& kin){};
virtual void getParameters(AnyMap& reactionNode) const;

Plog rate;
Expand Down Expand Up @@ -392,8 +392,6 @@ class InterfaceReaction : public ElementaryReaction2
virtual void calculateRateCoeffUnits(const Kinetics& kin);
virtual void getParameters(AnyMap& reactionNode) const;

virtual void validate();
//! New validate function takes kinetics object as the input
virtual void validate(Kinetics& kin);

virtual std::string type() const {
Expand Down Expand Up @@ -448,8 +446,7 @@ class BlowersMaselReaction: public Reaction
virtual void getParameters(AnyMap& reactionNode) const;

virtual void validate();
//! New validate function takes kinetics object as the input
virtual void validate(Kinetics& kin);
virtual void validate(Kinetics& kin){};
virtual std::string type() const {
return "Blowers-Masel";
}
Expand Down
1 change: 0 additions & 1 deletion include/cantera/kinetics/RxnRates.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ class BlowersMasel
return m_w;
}


protected:
doublereal m_logA, m_b, m_A, m_w, m_E0;
};
Expand Down
95 changes: 5 additions & 90 deletions src/kinetics/Reaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,42 +119,6 @@ void Reaction::validate()
}
}

void Reaction::validate(Kinetics& kin)
{
if (!allow_nonreactant_orders) {
for (const auto& order : orders) {
if (reactants.find(order.first) == reactants.end()) {
throw InputFileError("Reaction::validate", input,
"Reaction order specified for non-reactant species '{}'",
order.first);
}
}
}

if (!allow_negative_orders) {
for (const auto& order : orders) {
if (order.second < 0.0) {
throw InputFileError("Reaction::validate", input,
"Negative reaction order specified for species '{}'",
order.first);
}
}
}
// If reaction orders are specified, then this reaction does not follow
// mass-action kinetics, and is not an elementary reaction. So check that it
// is not reversible, since computing the reverse rate from thermochemistry
// only works for elementary reactions.
if (reversible && !orders.empty()) {
throw InputFileError("Reaction::validate", input,
"Reaction orders may only be given for irreversible reactions");
}

// Call validation of reaction rate evaluator
if (!usesLegacy()) {
m_rate->validate(equation());
}
}

AnyMap Reaction::parameters(bool withInput) const
{
AnyMap out;
Expand Down Expand Up @@ -470,17 +434,6 @@ void ElementaryReaction2::validate()
}
}

void ElementaryReaction2::validate(Kinetics& kin)
{
Reaction::validate(kin);
if (!allow_negative_pre_exponential_factor &&
rate.preExponentialFactor() < 0) {
throw InputFileError("ElementaryReaction2::validate", input,
"Undeclared negative pre-exponential factor found in reaction '"
+ equation() + "'");
}
}

void ElementaryReaction2::getParameters(AnyMap& reactionNode) const
{
Reaction::getParameters(reactionNode);
Expand Down Expand Up @@ -654,22 +607,6 @@ void FalloffReaction::validate()
}
}

void FalloffReaction::validate(Kinetics&kin)
{
Reaction::validate(kin);
if (!allow_negative_pre_exponential_factor &&
(low_rate.preExponentialFactor() < 0 ||
high_rate.preExponentialFactor() < 0)) {
throw InputFileError("FalloffReaction::validate", input, "Negative "
"pre-exponential factor found for reaction '" + equation() + "'");
}
if (low_rate.preExponentialFactor() * high_rate.preExponentialFactor() < 0) {
throw InputFileError("FalloffReaction::validate", input, "High and "
"low rate pre-exponential factors must have the same sign."
"Reaction: '{}'", equation());
}
}

void FalloffReaction::calculateRateCoeffUnits(const Kinetics& kin)
{
Reaction::calculateRateCoeffUnits(kin);
Expand Down Expand Up @@ -828,13 +765,8 @@ void InterfaceReaction::getParameters(AnyMap& reactionNode) const
}
}

void InterfaceReaction::validate() {
ElementaryReaction::validate();
}

void InterfaceReaction::validate(Kinetics& kin)
void InterfaceReaction::validate(Kinetics& kin)
{
ElementaryReaction::validate(kin);
if (is_sticking_coefficient) {
fmt::memory_buffer err_reactions;
double T[] = {200.0, 500.0, 1000.0, 2000.0, 5000.0, 10000.0};
Expand Down Expand Up @@ -896,17 +828,6 @@ void BlowersMaselReaction::validate()
}
}

void BlowersMaselReaction::validate(Kinetics& kin)
{
Reaction::validate(kin);
if (!allow_negative_pre_exponential_factor &&
rate.preExponentialFactor() < 0) {
throw InputFileError("BlowersMaselReaction::validate", input,
"Undeclared negative pre-exponential factor found in reaction '"
+ equation() + "'");
}
}

BlowersMaselReaction::BlowersMaselReaction(const Composition& reactants_,
const Composition& products_,
const BlowersMasel& rate_)
Expand Down Expand Up @@ -984,16 +905,16 @@ void BlowersMaselInterfaceReaction::getParameters(AnyMap& reactionNode) const

void BlowersMaselInterfaceReaction::validate(Kinetics& kin)
{
BlowersMaselReaction::validate(kin);
if (is_sticking_coefficient) {
doublereal original_T = kin.thermo().temperature();
doublereal original_P = kin.thermo().pressure();
double original_T = kin.thermo().temperature();
double original_P = kin.thermo().pressure();
fmt::memory_buffer err_reactions;
doublereal T[] = {200.0, 500.0, 1000.0, 2000.0, 5000.0, 10000.0};
size_t length_T = sizeof(T) / sizeof(T[0]);
// auto& interface_kin = dynamic_cast<InterfaceKinetics&>(kin);
for (size_t i=0; i < length_T; i++) {
kin.thermo().setState_TP(T[i], original_P);
double rxn_deltaH = kin.rxn_enthalpy(reactants, products);
double rxn_deltaH = kin.reactionEnthalpy(reactants, products);
double k = rate.updateRC(log(T[i]), 1/T[i], rxn_deltaH);
if (k > 1) {
format_to(err_reactions,
Expand Down Expand Up @@ -1739,12 +1660,6 @@ void PlogReaction2::validate()
rate.validate(equation());
}

void PlogReaction2::validate(Kinetics& kin)
{
Reaction::validate(kin);
rate.validate(equation());
}

void setupChebyshevReaction(ChebyshevReaction2& R, const XML_Node& rxn_node)
{
XML_Node& rc = rxn_node.child("rateCoeff");
Expand Down
4 changes: 0 additions & 4 deletions src/kinetics/RxnRates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

#include "cantera/kinetics/RxnRates.h"
#include "cantera/base/AnyMap.h"
#include "cantera/base/global.h"
#include <math.h>

namespace Cantera
{
Expand Down Expand Up @@ -90,7 +88,6 @@ void Arrhenius::getParameters(AnyMap& rateNode, const Units& rate_units) const
rateNode.setFlowStyle();
}


BlowersMasel::BlowersMasel()
: m_logA(-1.0E300)
, m_b(0.0)
Expand Down Expand Up @@ -131,7 +128,6 @@ void BlowersMasel::getParameters(AnyMap& rateNode, const Units& rate_units) cons
rateNode.setFlowStyle();
}


SurfaceArrhenius::SurfaceArrhenius()
: m_b(0.0)
, m_E(0.0)
Expand Down

0 comments on commit c1408b4

Please sign in to comment.