16#include <boost/algorithm/string.hpp>
21KineticsFactory* KineticsFactory::s_factory = 0;
22std::mutex KineticsFactory::kinetics_mutex;
24KineticsFactory::KineticsFactory() {
25 reg(
"none", []() {
return new Kinetics(); });
28 reg(
"bulk", []() {
return new BulkKinetics(); });
32 reg(
"surface", []() {
return new InterfaceKinetics(); });
36 reg(
"edge", []() {
return new EdgeKinetics(); });
40KineticsFactory* KineticsFactory::factory() {
41 std::unique_lock<std::mutex> lock(kinetics_mutex);
43 s_factory =
new KineticsFactory;
49 std::unique_lock<std::mutex> lock(kinetics_mutex);
61 shared_ptr<Kinetics> kin(KineticsFactory::factory()->
newKinetics(model));
65shared_ptr<Kinetics>
newKinetics(
const vector<shared_ptr<ThermoPhase>>& phases,
68 shared_ptr<Solution> soln)
70 string kinType = phaseNode.
getString(
"kinetics",
"none");
71 kinType = KineticsFactory::factory()->canonicalize(kinType);
72 if (kinType ==
"none") {
75 for (
auto& phase : phases) {
76 nDim = std::min(phase->nDim(), nDim);
81 }
else if (nDim == 1) {
86 shared_ptr<Kinetics> kin(KineticsFactory::factory()->
newKinetics(kinType));
88 soln->setKinetics(kin);
90 for (
auto& phase : phases) {
91 kin->addThermo(phase);
98shared_ptr<Kinetics>
newKinetics(
const vector<shared_ptr<ThermoPhase>>& phases,
99 const string& filename)
101 string reaction_phase = phases.at(0)->name();
103 AnyMap& phaseNode = root[
"phases"].getMapWhere(
"name", reaction_phase);
110 phaseNode.
getBool(
"skip-undeclared-third-bodies",
false));
115 vector<string> sections, rules;
117 if (phaseNode.
hasKey(
"reactions")) {
118 const auto& reactionsNode = phaseNode.
at(
"reactions");
119 if (reactionsNode.is<
string>()) {
120 if (rootNode.
hasKey(
"reactions")) {
123 sections.push_back(
"reactions");
124 rules.push_back(reactionsNode.asString());
125 }
else if (reactionsNode.asString() !=
"none") {
127 "Phase entry implies existence of 'reactions' section "
128 "which does not exist in the current input file.");
130 }
else if (reactionsNode.is<vector<string>>()) {
132 for (
const auto& item : reactionsNode.as<vector<string>>()) {
133 sections.push_back(item);
134 rules.push_back(
"all");
136 }
else if (reactionsNode.is<vector<AnyMap>>()) {
139 for (
const auto& item : reactionsNode.as<vector<AnyMap>>()) {
140 sections.push_back(item.begin()->first);
141 rules.push_back(item.begin()->second.asString());
145 if (!phaseNode.
hasKey(
"kinetics")) {
148 }
else if (rootNode.
hasKey(
"reactions")) {
151 sections.push_back(
"reactions");
152 rules.push_back(
"all");
155 "Phase entry implies existence of 'reactions' section which "
156 "does not exist in the current input file. Add the field "
157 "'reactions: none' to the phase entry to specify a kinetics "
158 "model with no reactions.");
163 fmt::memory_buffer add_rxn_err;
164 for (
size_t i = 0; i < sections.size(); i++) {
165 if (rules[i] ==
"all") {
167 }
else if (rules[i] ==
"declared-species") {
169 }
else if (rules[i] ==
"none") {
173 "Unknown rule '{}' for adding species from the '{}' section.",
174 rules[i], sections[i]);
176 const auto& slash = boost::ifind_last(sections[i],
"/");
179 string fileName (sections[i].begin(), slash.begin());
180 string node(slash.end(), sections[i].end());
184 for (
const auto& R : reactions[node].asVector<
AnyMap>()) {
211 if (add_rxn_err.size()) {
212 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.
bool hasKey(const string &key) const
Returns true if the map contains an item named key.
bool getBool(const string &key, bool default_) const
If key exists, return it as a bool, otherwise return default_.
const string & getString(const string &key, const string &default_) const
If key exists, return it as a string, otherwise return default_.
static AnyMap fromYamlFile(const string &name, const string &parent_name="")
Create an AnyMap from a YAML file.
const AnyValue & at(const string &key) const
Get the value of the item stored in key.
const 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 override
Get a description of the error.
Kinetics * create(const string &name, Args... args)
Create an object using the object construction function corresponding to "name" and the provided cons...
void reg(const string &name, function< Kinetics *(Args...)> f)
Register a new object construction function.
void addAlias(const string &original, const string &alias)
Add an alias for an existing registered type.
void addDeprecatedAlias(const string &original, const string &alias)
Add a deprecated alias for an existing registered type.
void deleteFactory() override
Virtual abstract function that deletes the factory.
Kinetics * newKinetics(const string &model)
Return a new, empty kinetics manager.
Public interface for kinetics managers.
virtual void resizeReactions()
Finalize Kinetics object and associated objects.
virtual string kineticsType() const
Identifies the Kinetics manager type.
virtual pair< size_t, size_t > checkDuplicates(bool throw_err=true) const
Check for unmarked duplicate reactions and unmatched marked duplicates.
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...
void fmt_append(fmt::memory_buffer &b, Args... args)
Versions 6.2.0 and 6.2.1 of fmtlib do not include this define before they include windows....
string toLowerCopy(const string &input)
Convert to lower case.
shared_ptr< Kinetics > newKinetics(const string &model)
Create a new Kinetics instance.
void addReactions(Kinetics &kin, const AnyMap &phaseNode, const AnyMap &rootNode)
Add reactions to a Kinetics object.
Namespace for the Cantera kernel.
void loadExtensions(const AnyMap &node)
Load extensions providing user-defined models from the extensions section of the given node.
unique_ptr< Reaction > newReaction(const string &type)
Create a new empty Reaction object.
Contains declarations for string manipulation functions within Cantera.