Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
importKinetics.h
Go to the documentation of this file.
1 /**
2  * @file importKinetics.h
3  * Definitions of global routines for the importing
4  * of data from XML files (see \ref inputfiles).
5  *
6  * This file contains routines which are global routines, i.e.,
7  * not part of any object. These routine take as input, ctml
8  * pointers to data, and pointers to %Cantera objects. The purpose
9  * of these routines is to initialize the %Cantera objects with data
10  * from the ctml tree structures.
11  */
12 // Copyright 2002 California Institute of Technology
13 
14 #ifndef CT_IMPORTKINETICS_H
15 #define CT_IMPORTKINETICS_H
16 
17 #include "Kinetics.h"
18 
19 namespace Cantera
20 {
21 
22 //! Rules for parsing and installing reactions
23 //! @deprecated Unused. To be removed after Cantera 2.2.
24 struct ReactionRules {
25  ReactionRules();
26  bool skipUndeclaredSpecies;
27  bool skipUndeclaredThirdBodies;
28  bool allowNegativeA;
29 };
30 
31 //!This function returns a ratio if two reactions are duplicates of
32 //!one another, and 0.0 otherwise.
33 /*!
34  * The input arguments are two maps from species number to stoichiometric
35  * coefficient, one for each reaction. The reactions are considered duplicates
36  * if their stoichiometric coefficients have the same ratio for all species.
37  *
38  * @param r1 map 1
39  * @param r2 map 2
40  *
41  * @return
42  * Returns 0.0 if the reactions are not the same.
43  * If the reactions are the same, it returns the ratio of the
44  * stoichiometric coefficients.
45  *
46  * @ingroup kineticsmgr
47  * @deprecated Now handled by Kinetics::checkDuplicateStoich. To be removed
48  * after Cantera 2.2.
49  */
50 doublereal isDuplicateReaction(std::map<int, doublereal>& r1,
51  std::map<int, doublereal>& r2);
52 
53 //! This function will check a specific reaction to see if the elements balance.
54 /*!
55  * @param kin Kinetics object
56  * @param rdata Object containing the information about one reaction
57  * @param errorTolerance double containing the error tolerance.
58  *
59  * @ingroup kineticsmgr
60  * @deprecated Now handled by Kinetics::checkReactionBalance. To be removed
61  * after Cantera 2.2.
62  */
64  const ReactionData& rdata,
65  doublereal errorTolerance = 1.0e-3);
66 
67 /**
68  * Get the reactants or products of a reaction. The information is returned in
69  * the spnum, stoich, and order vectors. The length of the vectors is the
70  * number of different types of reactants or products found for the reaction.
71  *
72  * @param[in] rxn XML node pointing to the reaction element in the XML tree.
73  * @param[in] kin Reference to the kinetics object to install the information
74  * into.
75  * @param[in] rp 1 -> Go get the reactants for a reaction; -1 -> Go get the
76  * products for a reaction
77  * @param[in] default_phase Name for the default phase to loop up species in.
78  * @param[out] spnum vector of species numbers found. Length is number of
79  * reactants or products.
80  * @param[out] stoich stoichiometric coefficient of the reactant or product.
81  * Length is number of reactants or products.
82  * @param[out] order Order of the reactant and product in the reaction rate
83  * expression.
84  * @param[in] rules If rules.skipUndeclaredSpecies is set and we fail to find
85  * a species we simply return false, allowing the calling
86  * routine to skip this reaction and continue. Otherwise, we
87  * will throw an error.
88  * @deprecated Now handled through newReaction() and its support functions. To
89  * be removed after Cantera 2.2.
90  */
91 bool getReagents(const XML_Node& rxn, Kinetics& kin, int rp, std::string default_phase,
92  std::vector<size_t>& spnum, vector_fp& stoich,
93  vector_fp& order, const ReactionRules& rules);
94 
95 //! Read the rate coefficient data from the XML file.
96 /*!
97  * Extract the rate coefficient for a reaction from the XML node, kf.
98  * kf should point to a XML element named "rateCoeff".
99  * rdata is the partially filled ReactionData object for the reaction.
100  * This function will fill in more fields in the ReactionData object.
101  *
102  * @param kf XML_Node containing information about the rate coefficients.
103  * @param kin kinetics manager
104  * @param rdata ReactionData reference
105  * @param rules Rules for parsing and installing reactions
106  *
107  * Trigger an exception for negative A unless specifically authorized.
108  *
109  * @deprecated Now handled through newReaction() and its support functions. To
110  * be removed after Cantera 2.2.
111  *
112  * @ingroup kineticsmgr
113  */
114 void getRateCoefficient(const XML_Node& kf, Kinetics& kin, ReactionData& rdata,
115  const ReactionRules& rules);
116 
117 //! Install information about reactions into the kinetics object, kin.
118 /*!
119  * At this point, parent usually refers to the phase XML element.
120  * One of the children of this element is reactionArray,
121  * the element which determines where in the XML file to
122  * look up the reaction rate data.
123  *
124  * @param p parent XML phase element
125  * @param kin Kinetics object to install reactions into
126  * @param default_phase The default_phase is the default phase to assume when
127  * looking up species.
128  * @param check_for_duplicates Check for reactions with exactly the same
129  * reactants and products.
130  *
131  * @return
132  * On return, if reaction instantiation goes correctly, return true.
133  * If there is a problem, return false.
134  *
135  * @ingroup kineticsmgr
136  */
137 bool installReactionArrays(const XML_Node& p, Kinetics& kin,
138  std::string default_phase,
139  bool check_for_duplicates = false);
140 
141 //! Import a reaction mechanism for a phase or an interface.
142 /*!
143  * This routine will import a reaction mechanism into a kinetics object. The
144  * reaction mechanism may either be homogeneous or heterogeneous, involving
145  * multiple ThermoPhase objects. The hosting phase should be included as the
146  * first argument. For example, if phase I is an interface phase between bulk
147  * phases A and B. Then, the XML_Node for phase I should be the first
148  * argument. The vector of ThermoPhase objects should consist of pointers to
149  * phases I, A, and B.
150  *
151  * @param phase This is an XML node containing a description of the owning
152  * phase for the kinetics object. Within the phase is a XML
153  * element called reactionArray containing the location of the
154  * description of the reactions that make up the kinetics object.
155  * Also within the phase is an XML element called phaseArray
156  * containing a listing of other phases that participate in the
157  * kinetics mechanism.
158  *
159  * @param th This is a list of ThermoPhase pointers which must include all
160  * of the phases that participate in the kinetics operator. All
161  * of the phases must have already been initialized and formed
162  * within Cantera. However, their pointers should not have been
163  * added to the Kinetics object; this addition is carried out
164  * here. Additional phases may be include in the list; these have
165  * no effect.
166  *
167  * @param kin This is a pointer to a kinetics manager class that will be
168  * initialized with the kinetics mechanism. Inherited Kinetics
169  * classes should be used here.
170  *
171  * @ingroup kineticsmgr
172  */
173 bool importKinetics(const XML_Node& phase, std::vector<ThermoPhase*> th,
174  Kinetics* kin);
175 
176 //! Build a single-phase ThermoPhase object with associated kinetics mechanism.
177 /*!
178  * In a single call, this routine initializes a ThermoPhase object and a
179  * homogeneous kinetics object for a phase. It returns the fully initialized
180  * ThermoPhase object ptr and kinetics ptr.
181  *
182  * @param root pointer to the XML tree which will be searched to find the
183  * XML phase element.
184  *
185  * @param id Name of the phase to be searched for.
186  * @param nm Name of the XML element. Should be "phase"
187  * @param th Pointer to a bare ThermoPhase object, which will be initialized
188  * by this operation.
189  * @param kin Pointer to a bare Kinetics object, which will be initialized
190  * by this operation to a homogeneous kinetics manager
191  *
192  * @return
193  * Returns true if all went well. If there are errors, it will return false.
194  *
195  * For Example
196  *
197  * @code
198  * ThermoPhase *th = new ThermoPhase();
199  * Kinetics *kin = new Kinetics();
200  * XML_Node *root = get_XML_File("gri30.xml");
201  * ok = buildSolutionFromXML(root, "gri30_mix", "phase", th, kin)
202  * @endcode
203  *
204  * @ingroup inputfiles
205  * @see importKinetics()
206  */
207 bool buildSolutionFromXML(XML_Node& root, const std::string& id,
208  const std::string& nm, ThermoPhase* th, Kinetics* kin);
209 }
210 
211 #endif
void checkRxnElementBalance(Kinetics &kin, const ReactionData &rdata, doublereal errorTolerance)
This function will check a specific reaction to see if the elements balance.
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:100
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.
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:97
bool getReagents(const XML_Node &rxn, Kinetics &kin, int rp, std::string default_phase, std::vector< size_t > &spnum, vector_fp &stoich, vector_fp &order, const ReactionRules &rules)
Get the reactants or products of a reaction.
bool importKinetics(const XML_Node &phase, std::vector< ThermoPhase * > th, Kinetics *k)
Import a reaction mechanism for a phase or an interface.
doublereal isDuplicateReaction(std::map< int, doublereal > &r1, std::map< int, doublereal > &r2)
This function returns a ratio if two reactions are duplicates of one another, and 0...
Public interface for kinetics managers.
Definition: Kinetics.h:128
Rules for parsing and installing reactions.
Intermediate class which stores data about a reaction and its rate parameterization before adding the...
Definition: ReactionData.h:22
Base class for kinetics managers and also contains the kineticsmgr module documentation (see Kinetics...
bool buildSolutionFromXML(XML_Node &root, const std::string &id, const std::string &nm, ThermoPhase *th, Kinetics *kin)
Build a single-phase ThermoPhase object with associated kinetics mechanism.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Definition: ct_defs.h:157
void getRateCoefficient(const XML_Node &kf, Kinetics &kin, ReactionData &rdata, const ReactionRules &rules)
Read the rate coefficient data from the XML file.