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));
A map of string keys to values whose type can vary at runtime.
const AnyValue & at(const std::string &key) const
Get the value of the item stored in key.
const std::string & getString(const std::string &key, const std::string &default_) const
If key exists, return it as a string, otherwise return default_.
bool getBool(const std::string &key, bool default_) const
If key exists, return it as a bool, otherwise return default_.
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
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.
Base class for exceptions thrown by Cantera classes.
const char * what() const
Get a description of the error.
Public interface for kinetics managers.
virtual bool addReaction(shared_ptr< Reaction > r)
Add a single reaction to the mechanism.
void skipUndeclaredSpecies(bool skip)
Determine behavior when adding a new reaction that contains species not defined in any of the phases ...
void skipUndeclaredThirdBodies(bool skip)
Determine behavior when adding a new reaction that contains third-body efficiencies for species not d...
virtual std::string kineticsType() const
Identifies the Kinetics manager type.
virtual std::pair< size_t, size_t > checkDuplicates(bool throw_err=true) const
Check for unmarked duplicate reactions and unmatched marked duplicates.
Class XML_Node is a tree-based representation of the contents of an XML file.
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
bool importKinetics(const XML_Node &phase, std::vector< ThermoPhase * > th, Kinetics *k)
Import a reaction mechanism for a phase or an interface.
const size_t npos
index returned by functions to indicate "no position"
Definitions of global routines for the importing of data from XML files (see Input File Handling).
Namespace for the Cantera kernel.
doublereal dot(InputIter x_begin, InputIter x_end, InputIter2 y_begin)
Function that calculates a templated inner product.
shared_ptr< Reaction > newReaction(const XML_Node &rxn_node)
Create a new Reaction object for the reaction defined in rxn_node
std::string toLowerCopy(const std::string &input)
Convert to lower case.
Kinetics * newKineticsMgr(XML_Node &phase, std::vector< ThermoPhase * > th)
Create a new kinetics manager.
unique_ptr< Kinetics > newKinetics(std::vector< ThermoPhase * > &phases, const std::string &filename, const std::string &phase_name)
void addReactions(Kinetics &kin, const AnyMap &phaseNode, const AnyMap &rootNode)
Classes providing support for XML data files.