Go to the documentation of this file.
20 KineticsFactory* KineticsFactory::s_factory = 0;
21 std::mutex KineticsFactory::kinetics_mutex;
24 vector<ThermoPhase*> th)
29 string kintype = phaseData.
child(
"kinetics")[
"model"];
41 KineticsFactory::KineticsFactory() {
42 reg(
"none", []() {
return new Kinetics(); });
43 reg(
"gas", []() {
return new GasKinetics(); });
44 addAlias(
"gas",
"gaskinetics");
45 reg(
"surface", []() {
return new InterfaceKinetics(); });
46 addAlias(
"surface",
"interface");
47 reg(
"edge", []() {
return new EdgeKinetics(); });
55 unique_ptr<Kinetics>
newKinetics(vector<ThermoPhase*>& phases,
59 unique_ptr<Kinetics> kin(KineticsFactory::factory()->
newKinetics(
60 phaseNode.
getString(
"kinetics",
"none")));
61 for (
auto& phase : phases) {
62 kin->addPhase(*phase);
69 unique_ptr<Kinetics>
newKinetics(std::vector<ThermoPhase*>& phases,
70 const std::string& filename,
71 const std::string& phase_name)
73 size_t dot = filename.find_last_of(
".");
79 if (extension ==
"yml" || extension ==
"yaml") {
80 AnyMap root = AnyMap::fromYamlFile(filename);
81 AnyMap& phaseNode = root[
"phases"].getMapWhere(
"name", phase_name);
88 "Couldn't find phase named '{}' in file '{}'.",
89 phase_name, filename);
98 phaseNode.
getBool(
"skip-undeclared-third-bodies",
false));
101 vector<string> sections, rules;
103 if (phaseNode.
hasKey(
"reactions")) {
106 "Phase entry includes a 'reactions' field but does not "
107 "specify a kinetics model.");
109 const auto& reactionsNode = phaseNode.
at(
"reactions");
110 if (reactionsNode.is<
string>()) {
111 if (rootNode.
hasKey(
"reactions")) {
114 sections.push_back(
"reactions");
115 rules.push_back(reactionsNode.asString());
116 }
else if (reactionsNode.asString() !=
"none") {
118 "Phase entry implies existence of 'reactions' section "
119 "which does not exist in the current input file.");
121 }
else if (reactionsNode.is<vector<string>>()) {
123 for (
const auto& item : reactionsNode.as<vector<string>>()) {
124 sections.push_back(item);
125 rules.push_back(
"all");
127 }
else if (reactionsNode.is<vector<AnyMap>>()) {
130 for (
const auto& item : reactionsNode.as<vector<AnyMap>>()) {
131 sections.push_back(item.begin()->first);
132 rules.push_back(item.begin()->second.asString());
136 if (rootNode.
hasKey(
"reactions")) {
139 sections.push_back(
"reactions");
140 rules.push_back(
"all");
143 "Phase entry implies existence of 'reactions' section which "
144 "does not exist in the current input file. Add the field "
145 "'reactions: none' to the phase entry to specify a kinetics "
146 "model with no reactions.");
151 fmt::memory_buffer add_rxn_err;
152 for (
size_t i = 0; i < sections.size(); i++) {
153 if (rules[i] ==
"all") {
155 }
else if (rules[i] ==
"declared-species") {
157 }
else if (rules[i] ==
"none") {
161 "Unknown rule '{}' for adding species from the '{}' section.",
162 rules[i], sections[i]);
164 const auto& slash = boost::ifind_last(sections[i],
"/");
167 string fileName (sections[i].begin(), slash.begin());
168 string node(slash.end(), sections[i].end());
169 AnyMap reactions = AnyMap::fromYamlFile(fileName,
171 for (
const auto& R : reactions[node].asVector<AnyMap>()) {
175 format_to(add_rxn_err,
"{}", err.
what());
184 format_to(add_rxn_err,
"{}", err.
what());
191 if (add_rxn_err.size()) {
192 throw CanteraError(
"addReactions", to_string(add_rxn_err));
const char * what() const
Get a description of the error.
Kinetics * newKineticsMgr(XML_Node &phase, std::vector< ThermoPhase * > th)
Create a new kinetics manager.
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
Public interface for kinetics managers.
void skipUndeclaredThirdBodies(bool skip)
Determine behavior when adding a new reaction that contains third-body efficiencies for species not d...
const AnyValue & at(const std::string &key) const
Get the value of the item stored in key.
virtual std::string kineticsType() const
Identifies the Kinetics manager type.
const std::vector< T > & asVector(size_t nMin=npos, size_t nMax=npos) const
Return the held value, if it is a vector of type T.
void addReactions(Kinetics &kin, const AnyMap &phaseNode, const AnyMap &rootNode)
unique_ptr< Kinetics > newKinetics(std::vector< ThermoPhase * > &phases, const std::string &filename, const std::string &phase_name)
Class XML_Node is a tree-based representation of the contents of an XML file.
virtual std::pair< size_t, size_t > checkDuplicates(bool throw_err=true) const
Check for unmarked duplicate reactions and unmatched marked duplicates.
shared_ptr< Reaction > newReaction(const XML_Node &rxn_node)
Create a new Reaction object for the reaction defined in rxn_node
virtual bool addReaction(shared_ptr< Reaction > r)
Add a single reaction to the mechanism.
bool getBool(const std::string &key, bool default_) const
If key exists, return it as a bool, otherwise return default_.
doublereal dot(InputIter x_begin, InputIter x_end, InputIter2 y_begin)
Function that calculates a templated inner product.
bool importKinetics(const XML_Node &phase, std::vector< ThermoPhase * > th, Kinetics *k)
Import a reaction mechanism for a phase or an interface.
A map of string keys to values whose type can vary at runtime.
void skipUndeclaredSpecies(bool skip)
Determine behavior when adding a new reaction that contains species not defined in any of the phases ...
std::string toLowerCopy(const std::string &input)
Convert to lower case.
Base class for exceptions thrown by Cantera classes.
const size_t npos
index returned by functions to indicate "no position"
Namespace for the Cantera kernel.
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
const std::string & getString(const std::string &key, const std::string &default_) const
If key exists, return it as a string, otherwise return default_.