Skip to content

Commit

Permalink
[Kinetics] simplify newReaction
Browse files Browse the repository at this point in the history
  • Loading branch information
Ingmar Schoegl committed Dec 28, 2019
1 parent 11b7892 commit 7c62752
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 75 deletions.
33 changes: 33 additions & 0 deletions include/cantera/kinetics/Reaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,39 @@ bool isElectrochemicalReaction(Reaction& R, const Kinetics& kin);
//! Parse reaction equation
void parseReactionEquation(Reaction& R, const AnyValue& equation,
const Kinetics& kin);

// declarations of setup functions
void setupElementaryReaction(ElementaryReaction&, const XML_Node&);
void setupElementaryReaction(ElementaryReaction&, const AnyMap&,
const Kinetics&);

void setupThreeBodyReaction(ThreeBodyReaction&, const XML_Node&);
void setupThreeBodyReaction(ThreeBodyReaction&, const AnyMap&,
const Kinetics&);

void setupFalloffReaction(FalloffReaction&, const XML_Node&);
void setupFalloffReaction(FalloffReaction&, const AnyMap&,
const Kinetics&);

void setupChemicallyActivatedReaction(ChemicallyActivatedReaction&,
const XML_Node&);

void setupPlogReaction(PlogReaction&, const XML_Node&);
void setupPlogReaction(PlogReaction&, const AnyMap&, const Kinetics&);

void setupChebyshevReaction(ChebyshevReaction&, const XML_Node&);
void setupChebyshevReaction(ChebyshevReaction&, const AnyMap&,
const Kinetics&);

void setupInterfaceReaction(InterfaceReaction&, const XML_Node&);
void setupInterfaceReaction(InterfaceReaction&, const AnyMap&,
const Kinetics&);

void setupElectrochemicalReaction(ElectrochemicalReaction&,
const XML_Node&);
void setupElectrochemicalReaction(ElectrochemicalReaction&,
const AnyMap&, const Kinetics&);

}

#endif
33 changes: 13 additions & 20 deletions include/cantera/kinetics/ReactionFactory.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @file ReactionFactory.h
* Parameterizations for reaction reaction functions. Used by classes
* that implement gas-phase kinetics (GasKinetics, GRI_30_Kinetics)
* Factory class for reaction functions. Used by classes
* that implement kinetics
* (see \ref reactionGroup and class \link Cantera::Reaction Reaction\endlink).
*/

Expand Down Expand Up @@ -49,23 +49,6 @@ class ReactionFactory : public Factory<Reaction>
s_factory = 0;
}

virtual Reaction* newReaction(const std::string& type);

//! Return a pointer to a new reaction function calculator.
/*!
* @param type Integer flag specifying the type of reaction function. The
* standard types are defined in file reaction_defs.h. A
* factory class derived from ReactionFactory may define other
* types as well.
* @param c input vector of doubles which populates the reaction
* parameterization.
* @returns a pointer to a new Reaction class.
*/
virtual Reaction* newReaction(const XML_Node& rxn_node);

virtual Reaction* newReaction(const AnyMap& rxn_node,
const Kinetics& kin);

void setup_XML(std::string name,
Reaction* R, const XML_Node& rxn_node) {
try {
Expand Down Expand Up @@ -118,13 +101,23 @@ class ReactionFactory : public Factory<Reaction>
};

//! Create a new empty Reaction object
/*!
* @param type string identifying type of reaction.
*/
unique_ptr<Reaction> newReaction(const std::string& type);

//! Create a new Reaction object for the reaction defined in `rxn_node`
/*!
* @param rxn_node XML node describing reaction.
*/
unique_ptr<Reaction> newReaction(const XML_Node& rxn_node);

//! Create a new Reaction object using the specified parameters
unique_ptr<Reaction> newReaction(const AnyMap& rxn_node,
/*!
* @param node AnyMap node describing reaction.
* @param kin kinetics manager
*/
unique_ptr<Reaction> newReaction(const AnyMap& node,
const Kinetics& kin);
}
#endif
1 change: 0 additions & 1 deletion src/kinetics/Reaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ namespace ba = boost::algorithm;
namespace Cantera
{


Reaction::Reaction(int type)
: reaction_type(type)
, reversible(true)
Expand Down
67 changes: 13 additions & 54 deletions src/kinetics/ReactionFactory.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/**
* @file ReactionFactory.cpp
*/

Expand All @@ -23,13 +23,10 @@ ReactionFactory::ReactionFactory()
reg("elementary", []() { return new ElementaryReaction(); });
m_synonyms["arrhenius"] = "elementary";
m_synonyms[""] = "elementary";
void setupElementaryReaction(ElementaryReaction&, const XML_Node&);
reg_XML("elementary",
[](Reaction* R, const XML_Node& node) {
setupElementaryReaction(*(ElementaryReaction*)R, node);
});
void setupElementaryReaction(ElementaryReaction&, const AnyMap&,
const Kinetics&);
reg_AnyMap("elementary",
[](Reaction* R, const AnyMap& node, const Kinetics& kin) {
setupElementaryReaction(*(ElementaryReaction*)R, node, kin);
Expand All @@ -39,27 +36,21 @@ ReactionFactory::ReactionFactory()
reg("three-body", []() { return new ThreeBodyReaction(); });
m_synonyms["threebody"] = "three-body";
m_synonyms["three_body"] = "three-body";
void setupThreeBodyReaction(ThreeBodyReaction&, const XML_Node&);
reg_XML("three-body",
[](Reaction* R, const XML_Node& node) {
setupThreeBodyReaction(*(ThreeBodyReaction*)R, node);
});
void setupThreeBodyReaction(ThreeBodyReaction&, const AnyMap&,
const Kinetics&);
reg_AnyMap("three-body",
[](Reaction* R, const AnyMap& node, const Kinetics& kin) {
setupThreeBodyReaction(*(ThreeBodyReaction*)R, node, kin);
});

// register falloff reactions
reg("falloff", []() { return new FalloffReaction(); });
void setupFalloffReaction(FalloffReaction&, const XML_Node&);
reg_XML("falloff",
[](Reaction* R, const XML_Node& node) {
setupFalloffReaction(*(FalloffReaction*)R, node);
});
void setupFalloffReaction(FalloffReaction&, const AnyMap&,
const Kinetics&);
reg_AnyMap("falloff",
[](Reaction* R, const AnyMap& node, const Kinetics& kin) {
setupFalloffReaction(*(FalloffReaction*)R, node, kin);
Expand All @@ -69,8 +60,6 @@ ReactionFactory::ReactionFactory()
reg("chemically-activated", []() { return new ChemicallyActivatedReaction(); });
m_synonyms["chemact"] = "chemically-activated";
m_synonyms["chemically_activated"] = "chemically-activated";
void setupChemicallyActivatedReaction(ChemicallyActivatedReaction&,
const XML_Node&);
reg_XML("chemically-activated",
[](Reaction* R, const XML_Node& node) {
setupChemicallyActivatedReaction(*(ChemicallyActivatedReaction*)R, node);
Expand All @@ -82,15 +71,12 @@ ReactionFactory::ReactionFactory()

// register pressure-depdendent-Arrhenius reactions
reg("pressure-dependent-Arrhenius", []() { return new PlogReaction(); });
m_synonyms["pressure-dependent-arrhenius"] = "pressure-dependent-Arrhenius";
m_synonyms["plog"] = "pressure-dependent-Arrhenius";
m_synonyms["pdep_arrhenius"] = "pressure-dependent-Arrhenius";
void setupPlogReaction(PlogReaction&, const XML_Node&);
reg_XML("pressure-dependent-Arrhenius",
[](Reaction* R, const XML_Node& node) {
setupPlogReaction(*(PlogReaction*)R, node);
});
void setupPlogReaction(PlogReaction&, const AnyMap&, const Kinetics&);
reg_AnyMap("pressure-dependent-Arrhenius",
[](Reaction* R, const AnyMap& node, const Kinetics& kin) {
setupPlogReaction(*(PlogReaction*)R, node, kin);
Expand All @@ -99,13 +85,10 @@ ReactionFactory::ReactionFactory()
// register Chebyshev reactions
reg("Chebyshev", []() { return new ChebyshevReaction(); });
m_synonyms["chebyshev"] = "Chebyshev";
void setupChebyshevReaction(ChebyshevReaction&, const XML_Node&);
reg_XML("Chebyshev",
[](Reaction* R, const XML_Node& node) {
setupChebyshevReaction(*(ChebyshevReaction*)R, node);
});
void setupChebyshevReaction(ChebyshevReaction&, const AnyMap&,
const Kinetics&);
reg_AnyMap("Chebyshev",
[](Reaction* R, const AnyMap& node, const Kinetics& kin) {
setupChebyshevReaction(*(ChebyshevReaction*)R, node, kin);
Expand All @@ -116,13 +99,10 @@ ReactionFactory::ReactionFactory()
m_synonyms["surface"] = "interface";
m_synonyms["edge"] = "interface";
m_synonyms["global"] = "interface";
void setupInterfaceReaction(InterfaceReaction&, const XML_Node&);
reg_XML("interface",
[](Reaction* R, const XML_Node& node) {
setupInterfaceReaction(*(InterfaceReaction*)R, node);
});
void setupInterfaceReaction(InterfaceReaction&, const AnyMap&,
const Kinetics&);
reg_AnyMap("interface",
[](Reaction* R, const AnyMap& node, const Kinetics& kin) {
setupInterfaceReaction(*(InterfaceReaction*)R, node, kin);
Expand All @@ -133,27 +113,23 @@ ReactionFactory::ReactionFactory()
m_synonyms["butlervolmer_noactivitycoeffs"] = "electrochemical";
m_synonyms["butlervolmer"] = "electrochemical";
m_synonyms["surfaceaffinity"] = "electrochemical";
void setupElectrochemicalReaction(ElectrochemicalReaction&,
const XML_Node&);
reg_XML("electrochemical",
[](Reaction* R, const XML_Node& node) {
setupElectrochemicalReaction(*(ElectrochemicalReaction*)R, node);
});
void setupElectrochemicalReaction(ElectrochemicalReaction&,
const AnyMap&, const Kinetics&);
reg_AnyMap("electrochemical",
[](Reaction* R, const AnyMap& node, const Kinetics& kin) {
setupElectrochemicalReaction(*(ElectrochemicalReaction*)R, node, kin);
});
}

Reaction* ReactionFactory::newReaction(const std::string& type)
unique_ptr<Reaction> newReaction(const std::string& type)
{
Reaction* R = create(toLowerCopy(type));
unique_ptr<Reaction> R(ReactionFactory::factory()->create(type));
return R;
}

Reaction* ReactionFactory::newReaction(const XML_Node& rxn_node)
unique_ptr<Reaction> newReaction(const XML_Node& rxn_node)
{
std::string type = toLowerCopy(rxn_node["type"]);

Expand All @@ -166,17 +142,18 @@ Reaction* ReactionFactory::newReaction(const XML_Node& rxn_node)

Reaction* R;
try {
R = create(type);
R = ReactionFactory::factory()->create(type);
} catch (CanteraError& err) {
throw CanteraError("newReaction",
"Unknown reaction type '" + rxn_node["type"] + "'");
}
setup_XML(R->type(), R, rxn_node);
return R;
ReactionFactory::factory()->setup_XML(R->type(), R, rxn_node);

return unique_ptr<Reaction>(R);
}

Reaction* ReactionFactory::newReaction(const AnyMap& node,
const Kinetics& kin)
unique_ptr<Reaction> newReaction(const AnyMap& node,
const Kinetics& kin)
{
std::string type = "elementary";
if (node.hasKey("type")) {
Expand All @@ -196,32 +173,14 @@ Reaction* ReactionFactory::newReaction(const AnyMap& node,

Reaction* R;
try {
R = create(type);
R = ReactionFactory::factory()->create(type);
} catch (CanteraError& err) {
throw InputFileError("ReactionFactory::newReaction", node["type"],
"Unknown reaction type '{}'", type);
}
setup_AnyMap(type, R, node, kin);
return R;
}

unique_ptr<Reaction> newReaction(const std::string& type)
{
unique_ptr<Reaction> R(ReactionFactory::factory()->newReaction(type));
return R;
}

unique_ptr<Reaction> newReaction(const XML_Node& rxn_node)
{
unique_ptr<Reaction> R(ReactionFactory::factory()->newReaction(rxn_node));
return R;
}
ReactionFactory::factory()->setup_AnyMap(type, R, node, kin);

unique_ptr<Reaction> newReaction(const AnyMap& rxn_node,
const Kinetics& kin)
{
unique_ptr<Reaction> R(ReactionFactory::factory()->newReaction(rxn_node, kin));
return R;
return unique_ptr<Reaction>(R);
}

}

0 comments on commit 7c62752

Please sign in to comment.