[Kinetics] Automatically generate reaction equation strings
This commit is contained in:
parent
f51ed2aa02
commit
c39b93c424
2 changed files with 69 additions and 13 deletions
|
|
@ -24,9 +24,9 @@ public:
|
|||
const Composition& products);
|
||||
virtual ~Reaction() {}
|
||||
|
||||
virtual std::string reactantString() { return ""; } //!< @todo: implement
|
||||
virtual std::string productString() { return ""; } //!< @todo: implement
|
||||
std::string equation() { return ""; } //!< @todo: implement
|
||||
virtual std::string reactantString() const;
|
||||
virtual std::string productString() const;
|
||||
std::string equation() const;
|
||||
|
||||
//! Type of the reaction. The valid types are listed in the file,
|
||||
//! reaction_defs.h, with constants ending in `RXN`.
|
||||
|
|
@ -95,8 +95,8 @@ public:
|
|||
ThirdBodyReaction();
|
||||
ThirdBodyReaction(const Composition& reactants, const Composition& products,
|
||||
const Arrhenius& rate, const ThirdBody& tbody);
|
||||
virtual std::string reactantString();
|
||||
virtual std::string productString();
|
||||
virtual std::string reactantString() const;
|
||||
virtual std::string productString() const;
|
||||
|
||||
ThirdBody third_body;
|
||||
};
|
||||
|
|
@ -110,8 +110,8 @@ public:
|
|||
const Arrhenius& low_rate, const Arrhenius& high_rate,
|
||||
const ThirdBody& tbody, int falloff_type,
|
||||
const vector_fp& falloff_params);
|
||||
virtual std::string reactantString();
|
||||
virtual std::string productString();
|
||||
virtual std::string reactantString() const;
|
||||
virtual std::string productString() const;
|
||||
|
||||
Arrhenius low_rate;
|
||||
Arrhenius high_rate;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include "cantera/kinetics/Reaction.h"
|
||||
#include "cantera/base/ctml.h"
|
||||
#include "cantera/base/Array.h"
|
||||
#include <sstream>
|
||||
|
||||
using namespace ctml;
|
||||
|
||||
|
|
@ -30,6 +31,49 @@ Reaction::Reaction(int type, const Composition& reactants_,
|
|||
{
|
||||
}
|
||||
|
||||
std::string Reaction::reactantString() const
|
||||
{
|
||||
std::ostringstream result;
|
||||
for (Composition::const_iterator iter = reactants.begin();
|
||||
iter != reactants.end();
|
||||
++iter) {
|
||||
if (iter != reactants.begin()) {
|
||||
result << " + ";
|
||||
}
|
||||
if (iter->second != 1.0) {
|
||||
result << iter->second << " ";
|
||||
}
|
||||
result << iter->first;
|
||||
}
|
||||
return result.str();
|
||||
}
|
||||
|
||||
std::string Reaction::productString() const
|
||||
{
|
||||
std::ostringstream result;
|
||||
for (Composition::const_iterator iter = products.begin();
|
||||
iter != products.end();
|
||||
++iter) {
|
||||
if (iter != products.begin()) {
|
||||
result << " + ";
|
||||
}
|
||||
if (iter->second != 1.0) {
|
||||
result << iter->second << " ";
|
||||
}
|
||||
result << iter->first;
|
||||
}
|
||||
return result.str();
|
||||
}
|
||||
|
||||
std::string Reaction::equation() const
|
||||
{
|
||||
if (reversible) {
|
||||
return reactantString() + " <=> " + productString();
|
||||
} else {
|
||||
return reactantString() + " => " + productString();
|
||||
}
|
||||
}
|
||||
|
||||
ElementaryReaction::ElementaryReaction(const Composition& reactants_,
|
||||
const Composition products_,
|
||||
const Arrhenius& rate_)
|
||||
|
|
@ -63,11 +107,11 @@ ThirdBodyReaction::ThirdBodyReaction(const Composition& reactants_,
|
|||
reaction_type = THREE_BODY_RXN;
|
||||
}
|
||||
|
||||
std::string ThirdBodyReaction::reactantString() {
|
||||
std::string ThirdBodyReaction::reactantString() const {
|
||||
return ElementaryReaction::reactantString() + " + M";
|
||||
}
|
||||
|
||||
std::string ThirdBodyReaction::productString() {
|
||||
std::string ThirdBodyReaction::productString() const {
|
||||
return ElementaryReaction::productString() + " + M";
|
||||
}
|
||||
|
||||
|
|
@ -91,12 +135,24 @@ FalloffReaction::FalloffReaction(
|
|||
{
|
||||
}
|
||||
|
||||
std::string FalloffReaction::reactantString() {
|
||||
return Reaction::reactantString() + " (+M)";
|
||||
std::string FalloffReaction::reactantString() const {
|
||||
if (third_body.default_efficiency == 0 &&
|
||||
third_body.efficiencies.size() == 1) {
|
||||
return Reaction::reactantString() + " (+" +
|
||||
third_body.efficiencies.begin()->first + ")";
|
||||
} else {
|
||||
return Reaction::reactantString() + " (+M)";
|
||||
}
|
||||
}
|
||||
|
||||
std::string FalloffReaction::productString() {
|
||||
return Reaction::productString() + " (+M)";
|
||||
std::string FalloffReaction::productString() const {
|
||||
if (third_body.default_efficiency == 0 &&
|
||||
third_body.efficiencies.size() == 1) {
|
||||
return Reaction::productString() + " (+" +
|
||||
third_body.efficiencies.begin()->first + ")";
|
||||
} else {
|
||||
return Reaction::productString() + " (+M)";
|
||||
}
|
||||
}
|
||||
|
||||
ChemicallyActivatedReaction::ChemicallyActivatedReaction()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue