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) {
144 string owning_phase = phase[
"id"];
146 bool check_for_duplicates =
false;
149 if (d[
"reactions"] ==
"yes") {
150 check_for_duplicates =
true;
157 vector<string> phase_ids;
162 phase_ids.push_back(owning_phase);
167 for (
size_t n = 0; n < phase_ids.size(); n++) {
168 string phase_id = phase_ids[n];
169 bool phase_ok =
false;
172 for (
size_t m = 0; m < th.size(); m++) {
173 if (th[m]->name() == phase_id) {
181 msg +=
" "+th[m]->name();
185 "phase "+phase_id+
" not found. Supplied phases are:"+msg);
211 std::vector<ThermoPhase*> phases{th};
225 vector<string> phase_ids;
230 phase_ids.push_back(p[
"id"]);
238 for (
const auto& sp : reactants) {
244 for (
const auto& sp : products) {
251 std::vector<double> e_counter(phase_ids.size(), 0.0);
254 for (
const auto& sp : products) {
257 double stoich = sp.second;
258 for (
size_t m = 0; m < phase_ids.size(); m++) {
259 if (phase_ids[m] == ph.
name()) {
260 e_counter[m] += stoich * ph.
charge(k);
267 for (
const auto& sp : reactants) {
270 double stoich = sp.second;
271 for (
size_t m = 0; m < phase_ids.size(); m++) {
272 if (phase_ids[m] == ph.
name()) {
273 e_counter[m] -= stoich * ph.
charge(k);
280 bool echemical =
false;
281 for(
size_t m = 0; m < phase_ids.size(); m++) {
282 if (fabs(e_counter[m]) > 1e-4) {
292 if ((type !=
"butlervolmer_noactivitycoeffs" &&
293 type !=
"butlervolmer" &&
294 type !=
"surfaceaffinity") &&
296 XML_Node& f = r.
child(
"rateCoeff").addChild(
"electrochem",
"");
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
Base class for exceptions thrown by Cantera classes.
Public interface for kinetics managers.
virtual void resizeReactions()
Finalize Kinetics object and associated objects.
ThermoPhase & speciesPhase(const std::string &nm)
This function looks up the name of a species and returns a reference to the ThermoPhase object of the...
size_t phaseIndex(const std::string &ph) const
Return the phase index of a phase in the list of phases defined within the object.
virtual void addPhase(ThermoPhase &thermo)
Add a phase to the kinetics manager object.
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 ...
virtual void init()
Prepare the class for the addition of reactions, after all phases have been added.
void skipUndeclaredThirdBodies(bool skip)
Determine behavior when adding a new reaction that contains third-body efficiencies for species not d...
size_t kineticsSpeciesIndex(size_t k, size_t n) const
The location of species k of phase n in species arrays.
virtual std::pair< size_t, size_t > checkDuplicates(bool throw_err=true) const
Check for unmarked duplicate reactions and unmatched marked duplicates.
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...
size_t speciesIndex(const std::string &name) const
Returns the index of a species named 'name' within the Phase object.
Base class for a phase with thermodynamic properties.
Class XML_Node is a tree-based representation of the contents of an XML file.
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
XML_Node & root() const
Return the root of the current XML_Node tree.
void addAttribute(const std::string &attrib, const std::string &value)
Add or modify an attribute of the current node.
XML_Node * parent() const
Returns a pointer to the parent node of the current node.
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...
std::string value() const
Return the value of an XML node as a string.
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data.
bool importKinetics(const XML_Node &phase, std::vector< ThermoPhase * > th, Kinetics *kin)
Import a reaction mechanism for a phase or an interface.
bool installReactionArrays(const XML_Node &p, Kinetics &kin, std::string default_phase, bool check_for_duplicates=false)
Install information about reactions into the kinetics object, kin.
void importPhase(XML_Node &phase, ThermoPhase *th)
Import a phase information into an empty ThermoPhase object.
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"
void getStringArray(const XML_Node &node, std::vector< std::string > &v)
This function interprets the value portion of an XML element as a string.
std::map< std::string, double > Composition
Map from string names to doubles.
XML_Node * get_XML_Node(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 ...
std::string toLowerCopy(const std::string &input)
Convert to lower case.
unique_ptr< Reaction > newReaction(const std::string &type)
Create a new empty Reaction object.
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 ...
bool checkElectrochemReaction(const XML_Node &p, Kinetics &kin, const XML_Node &r)
Check to ensure that all electrochemical reactions are specified correctly.
compositionMap parseCompString(const std::string &ss, const std::vector< std::string > &names=std::vector< std::string >())
Parse a composition string into a map consisting of individual key:composition pairs.
Contains declarations for string manipulation functions within Cantera.