22KineticsFactory* KineticsFactory::s_factory = 0;
23std::mutex KineticsFactory::kinetics_mutex;
26 vector<ThermoPhase*> th)
31 string kintype = phaseData.
child(
"kinetics")[
"model"];
43KineticsFactory::KineticsFactory() {
47 reg(
"gas", []() {
return new GasKinetics(); });
50 reg(
"surface", []() {
return new InterfaceKinetics(); });
54 reg(
"edge", []() {
return new EdgeKinetics(); });
63unique_ptr<Kinetics>
newKinetics(
const vector<ThermoPhase*>& phases,
67 std::string kinType = phaseNode.
getString(
"kinetics",
"none");
68 kinType = KineticsFactory::factory()->canonicalize(kinType);
69 if (kinType ==
"none") {
72 for (
auto& phase : phases) {
73 nDim = std::min(phase->nDim(), nDim);
78 }
else if (nDim == 1) {
83 unique_ptr<Kinetics> kin(KineticsFactory::factory()->
newKinetics(kinType));
84 for (
auto& phase : phases) {
85 kin->addPhase(*phase);
92unique_ptr<Kinetics>
newKinetics(
const std::vector<ThermoPhase*>& phases,
93 const std::string& filename,
94 const std::string& phase_name)
96 size_t dot = filename.find_last_of(
".");
102 if (extension ==
"yml" || extension ==
"yaml") {
104 AnyMap& phaseNode = root[
"phases"].getMapWhere(
"name", phase_name);
111 "Couldn't find phase named '{}' in file '{}'.",
112 phase_name, filename);
121 phaseNode.
getBool(
"skip-undeclared-third-bodies",
false));
124 vector<string> sections, rules;
126 if (phaseNode.
hasKey(
"reactions")) {
127 const auto& reactionsNode = phaseNode.
at(
"reactions");
128 if (reactionsNode.is<
string>()) {
129 if (rootNode.
hasKey(
"reactions")) {
132 sections.push_back(
"reactions");
133 rules.push_back(reactionsNode.asString());
134 }
else if (reactionsNode.asString() !=
"none") {
136 "Phase entry implies existence of 'reactions' section "
137 "which does not exist in the current input file.");
139 }
else if (reactionsNode.is<vector<string>>()) {
141 for (
const auto& item : reactionsNode.as<vector<string>>()) {
142 sections.push_back(item);
143 rules.push_back(
"all");
145 }
else if (reactionsNode.is<vector<AnyMap>>()) {
148 for (
const auto& item : reactionsNode.as<vector<AnyMap>>()) {
149 sections.push_back(item.begin()->first);
150 rules.push_back(item.begin()->second.asString());
154 if (!phaseNode.
hasKey(
"kinetics")) {
157 }
else if (rootNode.
hasKey(
"reactions")) {
160 sections.push_back(
"reactions");
161 rules.push_back(
"all");
164 "Phase entry implies existence of 'reactions' section which "
165 "does not exist in the current input file. Add the field "
166 "'reactions: none' to the phase entry to specify a kinetics "
167 "model with no reactions.");
172 fmt::memory_buffer add_rxn_err;
173 for (
size_t i = 0; i < sections.size(); i++) {
174 if (rules[i] ==
"all") {
176 }
else if (rules[i] ==
"declared-species") {
178 }
else if (rules[i] ==
"none") {
182 "Unknown rule '{}' for adding species from the '{}' section.",
183 rules[i], sections[i]);
185 const auto& slash = boost::ifind_last(sections[i],
"/");
188 string fileName (sections[i].begin(), slash.begin());
189 string node(slash.end(), sections[i].end());
192 for (
const auto& R : reactions[node].asVector<AnyMap>()) {
196 fmt_append(add_rxn_err,
"{}", err.
what());
206 fmt_append(add_rxn_err,
"{}", err.
what());
216 if (add_rxn_err.size()) {
217 throw CanteraError(
"addReactions", to_string(add_rxn_err));
Header file for class ThermoPhase, the base class for phases with thermodynamic properties,...
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_.
static AnyMap fromYamlFile(const std::string &name, const std::string &parent_name="")
Create an AnyMap from a YAML file.
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.
Kinetics * create(const std::string &name, Args... args)
Create an object using the object construction function corresponding to "name" and the provided cons...
void addAlias(const std::string &original, const std::string &alias)
Add an alias for an existing registered type.
void reg(const std::string &name, std::function< Kinetics *(Args...)> f)
Register a new object construction function.
virtual Kinetics * newKinetics(XML_Node &phase, std::vector< ThermoPhase * > th)
Return a new kinetics manager that implements a reaction mechanism specified in a CTML file.
Public interface for kinetics managers.
virtual void resizeReactions()
Finalize Kinetics object and associated objects.
virtual bool addReaction(shared_ptr< Reaction > r, bool resize=true)
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 *kin)
Import a reaction mechanism for a phase or an interface.
Definitions of global routines for the importing of data from XML files (see Input File Handling).
Namespace for the Cantera kernel.
const size_t npos
index returned by functions to indicate "no position"
XML_Node * get_XML_File(const std::string &file, int debug=0)
Return a pointer to the XML tree for a Cantera input file.
void addReactions(Kinetics &kin, const AnyMap &phaseNode, const AnyMap &rootNode=AnyMap())
doublereal dot(InputIter x_begin, InputIter x_end, InputIter2 y_begin)
Function that calculates a templated inner product.
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< Reaction > newReaction(const std::string &type)
Create a new empty Reaction object.
shared_ptr< Kinetics > newKinetics(const std::string &model)
Create a new Kinetics instance.
XML_Node * get_XML_NameID(const std::string &nameTarget, const std::string &file_ID, XML_Node *root)
This routine will locate an XML node in either the input XML tree or in another input file specified ...
Contains declarations for string manipulation functions within Cantera.
Classes providing support for XML data files.