Go to the documentation of this file.
21 #include "cantera/base/yaml.h"
31 std::string default_phase,
bool check_for_duplicates)
40 vector<XML_Node*> rarrays = p.
getChildren(
"reactionArray");
41 if (rarrays.empty()) {
44 for (
size_t n = 0; n < rarrays.size(); n++) {
67 if (sk[
"species"] ==
"undeclared") {
70 if (sk[
"third_bodies"] ==
"undeclared") {
78 vector<XML_Node*> incl = rxns.
getChildren(
"include");
79 vector<XML_Node*> allrxns = rdata->
getChildren(
"reaction");
82 for (
size_t i = 0; i < allrxns.size(); i++) {
88 for (
size_t nii = 0; nii < incl.size(); nii++) {
90 string imin = ii[
"min"];
91 string imax = ii[
"max"];
95 iwild = imin.find(
"*");
97 imin = imin.substr(0,iwild);
102 for (
size_t i = 0; i < allrxns.size(); i++) {
108 rxid = rxid.substr(0,iwild);
114 if ((rxid >= imin) && (rxid <= imax)) {
125 if (check_for_duplicates) {
142 string owning_phase = phase[
"id"];
144 bool check_for_duplicates =
false;
147 if (d[
"reactions"] ==
"yes") {
148 check_for_duplicates =
true;
155 vector<string> phase_ids;
160 phase_ids.push_back(owning_phase);
165 for (
size_t n = 0; n < phase_ids.size(); n++) {
166 string phase_id = phase_ids[n];
167 bool phase_ok =
false;
170 for (
size_t m = 0; m < th.size(); m++) {
171 if (th[m]->name() == phase_id) {
179 msg +=
" "+th[m]->name();
183 "phase "+phase_id+
" not found. Supplied phases are:"+msg);
209 std::vector<ThermoPhase*> phases{th};
223 vector<string> phase_ids;
228 phase_ids.push_back(p[
"id"]);
236 for (
const auto& sp : reactants) {
242 for (
const auto& sp : products) {
249 std::vector<double> e_counter(phase_ids.size(), 0.0);
252 for (
const auto& sp : products) {
255 double stoich = sp.second;
256 for (
size_t m = 0; m < phase_ids.size(); m++) {
257 if (phase_ids[m] == ph.
name()) {
258 e_counter[m] += stoich * ph.
charge(k);
265 for (
const auto& sp : reactants) {
268 double stoich = sp.second;
269 for (
size_t m = 0; m < phase_ids.size(); m++) {
270 if (phase_ids[m] == ph.
name()) {
271 e_counter[m] -= stoich * ph.
charge(k);
278 bool echemical =
false;
279 for(
size_t m = 0; m < phase_ids.size(); m++) {
280 if (fabs(e_counter[m]) > 1e-4) {
290 if ((type !=
"butlervolmer_noactivitycoeffs" &&
291 type !=
"butlervolmer" &&
292 type !=
"surfaceaffinity") &&
294 XML_Node& f = r.
child(
"rateCoeff").addChild(
"electrochem",
"");
bool installReactionArrays(const XML_Node &p, Kinetics &kin, std::string default_phase, bool check_for_duplicates)
Install information about reactions into the kinetics object, kin.
size_t kineticsSpeciesIndex(size_t k, size_t n) const
The location of species k of phase n in species arrays.
virtual void addPhase(thermo_t &thermo)
Add a phase to the kinetics manager object.
thermo_t & speciesPhase(const std::string &nm)
This function looks up the name of a species and returns a reference to the ThermoPhase object of the...
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
Public interface for kinetics managers.
void addAttribute(const std::string &attrib, const std::string &value)
Add or modify an attribute of the current node.
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
void skipUndeclaredThirdBodies(bool skip)
Determine behavior when adding a new reaction that contains third-body efficiencies for species not d...
XML_Node & root() const
Return the root of the current XML_Node tree.
std::string name() const
Return the name of the phase.
doublereal charge(size_t k) const
Dimensionless electrical charge of a single molecule of species k The charge is normalized by the the...
std::string value() const
Return the value of an XML node as a string.
size_t phaseIndex(const std::string &ph) const
Return the phase index of a phase in the list of phases defined within the object.
bool checkElectrochemReaction(const XML_Node &p, Kinetics &kin, const XML_Node &r)
Check to ensure that all electrochemical reactions are specified correctly.
std::vector< XML_Node * > getChildren(const std::string &name) const
Get a vector of pointers to XML_Node containing all of the children of the current node which match t...
size_t speciesIndex(const std::string &name) const
Returns the index of a species named 'name' within the Phase object.
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.
Base class for a phase with thermodynamic properties.
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.
compositionMap parseCompString(const std::string &ss, const std::vector< std::string > &names)
Parse a composition string into a map consisting of individual key:composition pairs.
std::map< std::string, double > Composition
Map from string names to doubles.
void getStringArray(const XML_Node &node, std::vector< std::string > &v)
This function interprets the value portion of an XML element as a string.
bool importKinetics(const XML_Node &phase, std::vector< ThermoPhase * > th, Kinetics *k)
Import a reaction mechanism for a phase or an interface.
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.
void importPhase(XML_Node &phase, ThermoPhase *th)
Import a phase information into an empty ThermoPhase object.
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.
XML_Node * parent() const
Returns a pointer to the parent node of the current node.
virtual void init()
Prepare the class for the addition of reactions, after all phases have been added.