Cantera  2.1.2
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 
15 #ifndef CT_IMPORTCTML_H
16 #define CT_IMPORTCTML_H
17 
19 #include "Kinetics.h"
20 
21 namespace Cantera
22 {
23 
24 class Kinetics;
25 class SpeciesThermoFactory;
26 class XML_Node;
27 
28 //! Rules for parsing and installing reactions
29 struct ReactionRules {
30  ReactionRules();
31  bool skipUndeclaredSpecies;
32  bool skipUndeclaredThirdBodies;
33  bool allowNegativeA;
34 };
35 
36 //!This function returns a ratio if two reactions are duplicates of
37 //!one another, and 0.0 otherwise.
38 /*!
39  * The input arguments are two maps from species number to stoichiometric
40  * coefficient, one for each reaction. The reactions are considered duplicates
41  * if their stoichiometric coefficients have the same ratio for all species.
42  *
43  * @param r1 map 1
44  * @param r2 map 2
45  *
46  * @return
47  * Returns 0.0 if the reactions are not the same.
48  * If the reactions are the same, it returns the ratio of the
49  * stoichiometric coefficients.
50  *
51  * @ingroup kineticsmgr
52  */
53 doublereal isDuplicateReaction(std::map<int, doublereal>& r1,
54  std::map<int, doublereal>& r2);
55 
56 //! This function will check a specific reaction to see if the elements balance.
57 /*!
58  * @param kin Kinetics object
59  * @param rdata Object containing the information about one reaction
60  * @param errorTolerance double containing the error tolerance.
61  *
62  * @ingroup kineticsmgr
63  */
65  const ReactionData& rdata,
66  doublereal errorTolerance = 1.0e-3);
67 
68 /**
69  * Get the reactants or products of a reaction. The information is returned in
70  * the spnum, stoich, and order vectors. The length of the vectors is the
71  * number of different types of reactants or products found for the reaction.
72  *
73  * @param[in] rxn xml node pointing to the reaction element in the xml tree.
74  * @param[in] kin Reference to the kinetics object to install the information
75  * into.
76  * @param[in] rp 1 -> Go get the reactants for a reaction; -1 -> Go get the
77  * products for a reaction
78  * @param[in] default_phase Name for the default phase to loop up species in.
79  * @param[out] spnum vector of species numbers found. Length is number of
80  * reactants or products.
81  * @param[out] stoich stoichiometric coefficient of the reactant or product.
82  * Length is number of reactants or products.
83  * @param[out] order Order of the reactant and product in the reaction rate
84  * expression.
85  * @param[in] rules If rules.skipUndeclaredSpecies is set and we fail to find
86  * a species we simply return false, allowing the calling
87  * routine to skip this reaction and continue. Otherwise, we
88  * will throw an error.
89  */
90 bool getReagents(const XML_Node& rxn, Kinetics& kin, int rp,
91  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  * @ingroup kineticsmgr
110  */
111 void getRateCoefficient(const XML_Node& kf, Kinetics& kin, ReactionData& rdata,
112  const ReactionRules& rules);
113 
114 //! Install information about reactions into the kinetics object, kin.
115 /*!
116  * At this point, parent usually refers to the phase xml element.
117  * One of the children of this element is reactionArray,
118  * the element which determines where in the xml file to
119  * look up the reaction rate data.
120  *
121  * @param p parent XML phase element
122  * @param kin Kinetics object to install reactions into
123  * @param default_phase The default_phase is the default phase to assume when
124  * looking up species.
125  * @param check_for_duplicates Check for reactions with exactly the same
126  * reactants and products.
127  *
128  * @return
129  * On return, if reaction instantiation goes correctly, return true.
130  * If there is a problem, return false.
131  *
132  * @ingroup kineticsmgr
133  */
134 bool installReactionArrays(const XML_Node& p, Kinetics& kin,
135  std::string default_phase,
136  bool check_for_duplicates = false);
137 
138 //! Import a reaction mechanism for a phase or an interface.
139 /*!
140  * This routine will import a reaction mechanism into a kinetics object. The
141  * reaction mechanism may either be homogeneous or heterogeneous, involving
142  * multiple ThermoPhase objects. The hosting phase should be included as the
143  * first argument. For example, if phase I is an interface phase between bulk
144  * phases A and B. Then, the XML_Node for phase I should be the first
145  * argument. The vector of ThermoPhase objects should consist of pointers to
146  * phases I, A, and B.
147  *
148  * @param phase This is an xml node containing a description of the owning
149  * phase for the kinetics object. Within the phase is a XML
150  * element called reactionArray containing the location of the
151  * description of the reactions that make up the kinetics object.
152  * Also within the phase is an XML element called phaseArray
153  * containing a listing of other phases that participate in the
154  * kinetics mechanism.
155  *
156  * @param th This is a list of ThermoPhase pointers which must include all
157  * of the phases that participate in the kinetics operator. All
158  * of the phases must have already been initialized and formed
159  * within Cantera. However, their pointers should not have been
160  * added to the Kinetics object; this addition is carried out
161  * here. Additional phases may be include in the list; these have
162  * no effect.
163  *
164  * @param kin This is a pointer to a kinetics manager class that will be
165  * initialized with the kinetics mechanism. Inherited Kinetics
166  * classes may be used here.
167  *
168  * @ingroup kineticsmgr
169  *
170  */
171 bool importKinetics(const XML_Node& phase, std::vector<ThermoPhase*> th,
172  Kinetics* kin);
173 
174 //!Build a single-phase ThermoPhase object with associated kinetics mechanism.
175 /*!
176  * In a single call, this routine initializes a ThermoPhase object and a
177  * homogeneous kinetics object for a phase.
178  *
179  * @param root pointer to the XML tree which will be searched to find the
180  * XML phase element.
181  *
182  * @param id Name of the phase to be searched for.
183  * @param nm Name of the XML element. Should be "phase"
184  * @param th Pointer to a bare ThermoPhase object, which will be initialized
185  * by this operation.
186  * @param k Pointer to a bare Kinetics object, which will be initialized
187  * by this operation to a homogeneous kinetics manager
188  *
189  * @return
190  * Returns true if all went well. If there are errors, it will return false.
191  *
192  * For Example
193  *
194  * @code
195  * ThermoPhase *th = new ThermoPhase();
196  * Kinetics *k = new Kinetics();
197  * XML_Node *root = get_XML_File("gri30.xml");
198  * ok = buildSolutionFromXML(root, "gri30_mix", "phase", th, k)
199  * @endcode
200  *
201  * @ingroup inputfiles
202  * @see importKinetics()
203  */
204 bool buildSolutionFromXML(XML_Node& root, const std::string& id,
205  const std::string& nm, ThermoPhase* th, Kinetics* k);
206 
207 //! Search an XML tree for species data.
208 /*!
209  * This utility routine will search the XML tree for the species named by
210  * the string, kname. It will return the XML_Node pointer. Failures of any
211  * kind return the null pointer.
212  *
213  * @param kname species Name
214  * @param phaseSpeciesData Pointer to the phase XML node pertaining to the
215  * species database for the phase to be found
216  *
217  * @return
218  * Returns a pointer to the XML node containing the species data.
219  *
220  * @ingroup inputfiles
221  */
222 //const XML_Node *speciesXML_Node(std::string kname,
223 // const XML_Node *phaseSpeciesData);
224 
225 }
226 
227 #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 buildSolutionFromXML(XML_Node &root, const std::string &id, const std::string &nm, ThermoPhase *th, Kinetics *k)
Build a single-phase ThermoPhase object with associated kinetics mechanism.
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:101
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:131
Rules for parsing and installing reactions.
Intermediate class which stores data about a reaction and its rate parameterization before adding the...
Definition: ReactionData.h:16
Base class for kinetics managers and also contains the kineticsmgr module documentation (see Kinetics...
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:165
void getRateCoefficient(const XML_Node &kf, Kinetics &kin, ReactionData &rdata, const ReactionRules &rules)
Read the rate coefficient data from the XML file.
Header file for class ThermoPhase, the base class for phases with thermodynamic properties, and the text for the Module thermoprops (see Thermodynamic Properties and class ThermoPhase).