Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ctml.h
Go to the documentation of this file.
1 /**
2  * @file ctml.h
3  * CTML ("Cantera Markup Language") is the variant of XML that Cantera uses
4  * to store data. These functions read and write it.
5  * (see \ref inputfiles and importCTML, ck2ctml)
6  */
7 // Copyright 2002 California Institute of Technology
8 
9 #ifndef CT_CTML_H
10 #define CT_CTML_H
11 
12 #include "ct_defs.h"
13 #include "xml.h"
14 
15 namespace Cantera
16 {
17 class Array2D;
18 
19 //! const Specifying the CTML version number
20 /*!
21  * @todo Codify what the CTML_Version number means.
22  */
23 const std::string CTML_Version = "1.4.1";
24 
25 //! This function adds a child node with the name, "integer", with a value
26 //! consisting of a single integer
27 /*!
28  * This function will add a child node to the current XML node, with the
29  * name "integer". It will have a title attribute, and the body
30  * of the XML node will be filled out with a single integer
31  *
32  * Example:
33  *
34  * Code snippet:
35  * @code
36  * const XML_Node &node;
37  * std::string titleString = "maxIterations";
38  * int value = 1000;
39  * std::string typeString = "optional";
40  * std::string units = "";
41  * addInteger(node, titleString, value, typeString, units);
42  * @endcode
43  *
44  * Creates the following the snippet in the XML file:
45  *
46  * <parentNode>
47  * <integer title="maxIterations" type="optional">
48  * 100
49  * <\integer>
50  * <\parentNode>
51  *
52  * @param node reference to the XML_Node object of the parent XML element
53  * @param titleString String name of the title attribute
54  * @param value Value - single integer
55  * @param unitsString String name of the Units attribute. The default is to
56  * have an empty string.
57  * @param typeString String type. This is an optional parameter. The default
58  * is to have an empty string.
59  *
60  * @todo I don't think this is used. Figure out what is used for writing integers,
61  * and codify that. unitsString shouldn't be here, since it's an int.
62  * typeString should be codified as to its usage.
63  */
64 void addInteger(XML_Node& node, const std::string& titleString,
65  const int value, const std::string& unitsString="",
66  const std::string& typeString="");
67 
68 //! This function adds a child node with the name, "float", with a value
69 //! consisting of a single floating point number
70 /*!
71  * This function will add a child node to the current XML node, with the
72  * name "float". It will have a title attribute, and the body
73  * of the XML node will be filled out with a single float
74  *
75  * Example:
76  *
77  * Code snippet:
78  * @code
79  * const XML_Node &node;
80  * std::string titleString = "activationEnergy";
81  * doublereal value = 50.3;
82  * doublereal maxval = 1.0E3;
83  * doublereal minval = 0.0;
84  * std::string typeString = "optional";
85  * std::string unitsString = "kcal/gmol";
86  * addFloat(node, titleString, value, unitsString, typeString, minval, maxval);
87  * @endcode
88  *
89  * Creates the following the snippet in the XML file:
90  *
91  * <parentNode>
92  * <float title="activationEnergy" type="optional" units="kcal/gmol" min="0.0" max="1.0E3">
93  * 50.3
94  * <\float>
95  * <\parentNode>
96  *
97  * @param node reference to the XML_Node object of the parent XML element
98  * @param titleString String name of the title attribute
99  * @param value Value - single integer
100  * @param unitsString String name of the Units attribute. The default is to
101  * have an empty string.
102  * @param typeString String type. This is an optional parameter. The default
103  * is to have an empty string.
104  * @param minval Minimum allowed value of the float. The default is the
105  * special double, Undef, which means to ignore the
106  * entry.
107  * @param maxval Maximum allowed value of the float. The default is the
108  * special double, Undef, which means to ignore the
109  * entry.
110  */
111 void addFloat(XML_Node& node, const std::string& titleString,
112  const doublereal value, const std::string& unitsString="",
113  const std::string& typeString="", const doublereal minval=Undef,
114  const doublereal maxval=Undef);
115 
116 //! This function adds a child node with the name, "floatArray", with a value
117 //! consisting of a comma separated list of floats
118 /*!
119  * This function will add a child node to the current XML node, with the
120  * name "floatArray". It will have a title attribute, and the body of the
121  * XML node will be filled out with a comma separated list of doublereals.
122  *
123  * Example:
124  *
125  * Code snippet:
126  * @code
127  * const XML_Node &node;
128  * std::string titleString = "additionalTemperatures";
129  * int n = 3;
130  * int Tcases[3] = [273.15, 298.15, 373.15];
131  * std::string typeString = "optional";
132  * std::string units = "Kelvin";
133  * addFloatArray(node, titleString, n, &cases[0], typeString, units);
134  * @endcode
135  *
136  * Creates the following the snippet in the XML file:
137  *
138  * <parentNode>
139  * <floatArray title="additionalTemperatures" type="optional" units="Kelvin">
140  * 273.15, 298.15, 373.15
141  * <\floatArray>
142  * <\parentNode>
143  *
144  * @param node reference to the XML_Node object of the parent XML element
145  * @param titleString String name of the title attribute
146  * @param n Length of the doubles vector.
147  * @param values Pointer to a vector of doubles
148  * @param unitsString String name of the Units attribute. This is an optional
149  * parameter. The default is to have an empty string.
150  * @param typeString String type. This is an optional parameter. The default
151  * is to have an empty string.
152  * @param minval Minimum allowed value of the int. This is an optional
153  * parameter. The default is the
154  * special double, Undef, which means to ignore the
155  * entry.
156  * @param maxval Maximum allowed value of the int. This is an optional
157  * parameter. The default is the special double,
158  * Undef, which means to ignore the entry.
159  */
160 void addFloatArray(XML_Node& node, const std::string& titleString,
161  const size_t n, const doublereal* const values,
162  const std::string& unitsString="", const std::string& typeString="",
163  const doublereal minval=Undef,
164  const doublereal maxval=Undef);
165 
166 //! This function adds a child node with the name given by the first parameter
167 //! with a value consisting of a comma separated list of floats
168 /*!
169  * This function will add a child node to the current XML node, with the name
170  * given in the list. It will have a title attribute, and the body of the XML
171  * node will be filled out with a comma separated list of integers
172  *
173  * Example:
174  *
175  * Code snipet:
176  * @code
177  * const XML_Node &node;
178  * std::string titleString = "additionalTemperatures";
179  * int n = 3;
180  * int Tcases[3] = [273.15, 298.15, 373.15];
181  * std::string typeString = "optional";
182  * std::string units = "Kelvin";
183  * addNamedFloatArray(node, titleString, n, &cases[0], typeString, units);
184  * @endcode
185  *
186  * Creates the following the snippet in the XML file:
187  *
188  * <parentNode>
189  * <additionalTemperatures type="optional" vtype="floatArray" size = "3" units="Kelvin">
190  * 273.15, 298.15, 373.15
191  * <\additionalTemperatures>
192  * <\parentNode>
193  *
194  * @param parentNode reference to the XML_Node object of the parent XML element
195  * @param name Name of the XML node
196  * @param n Length of the doubles vector.
197  * @param vals Pointer to a vector of doubles
198  * @param units String name of the Units attribute. This is an optional
199  * parameter. The default is to have an empty string.
200  * @param type String type. This is an optional parameter. The default
201  * is to have an empty string.
202  * @param minval Minimum allowed value of the int. This is an optional
203  * parameter. The default is the special double,
204  * Undef, which means to ignore the entry.
205  * @param maxval Maximum allowed value of the int. This is an optional
206  * parameter. The default is the special double,
207  * Undef, which means to ignore the entry.
208  */
209 void addNamedFloatArray(XML_Node& parentNode, const std::string& name, const size_t n,
210  const doublereal* const vals, const std::string units = "",
211  const std::string type = "",
212  const doublereal minval=Undef,
213  const doublereal maxval=Undef);
214 
215 //! This function adds a child node with the name string with a string value
216 //! to the current node
217 /*!
218  * This function will add a child node to the current XML node, with the name
219  * "string". It will have a title attribute, and the body of the XML node will
220  * be filled out with the valueString argument verbatim.
221  *
222  * Example:
223  *
224  * Code snippet:
225  * @code
226  * const XML_Node &node;
227  * addString(node, "titleString", "valueString", "typeString");
228  * @endcode
229  *
230  * Creates the following the snippet in the XML file:
231  *
232  * <string title="titleString" type="typeString">
233  * valueString
234  * <\string>
235  *
236  * @param node reference to the XML_Node object of the parent XML element
237  * @param valueString Value string to be used in the new XML node.
238  * @param titleString String name of the title attribute
239  * @param typeString String type. This is an optional parameter.
240  */
241 void addString(XML_Node& node, const std::string& titleString,
242  const std::string& valueString, const std::string& typeString="");
243 
244 //! This function reads the current node or a child node of the current node
245 //! with the default name, "floatArray", with a value field
246 //! consisting of a comma separated list of floats
247 /*!
248  * This function will read either the current XML node or a child node to the
249  * current XML node, with the name "floatArray". It will have a title
250  * attribute, and the body of the XML node will be filled out with a comma
251  * separated list of doublereals. Get an array of floats from the XML Node.
252  * The argument field is assumed to consist of an arbitrary number of comma
253  * separated floats, with an arbitrary amount of white space separating each
254  * field. If the node array has an units attribute field, then the units are
255  * used to convert the floats, iff convert is true.
256  *
257  * Example:
258  *
259  * Code snippet:
260  * @code
261  * const XML_Node &State_XMLNode;
262  * vector_fp v;
263  * bool convert = true;
264  * unitsString = "";
265  * nodeName="floatArray";
266  * getFloatArray(State_XMLNode, v, convert, unitsString, nodeName);
267  * @endcode
268  *
269  * reads the corresponding XML file:
270  *
271  * <state>
272  * <floatArray units="m3"> 32.4, 1, 100. <\floatArray>
273  * <\state>
274  *
275  * and will produce the vector:
276  *
277  * v[0] = 32.4
278  * v[1] = 1.0
279  * v[2] = 100.
280  *
281  * @param node XML parent node of the floatArray
282  * @param v Output vector of floats containing the floatArray information.
283  * @param convert Conversion to SI is carried out if this boolean is
284  * True. The default is true.
285  * @param unitsString String name of the type attribute. This is an optional
286  * parameter. The default is to have an empty string.
287  * The only string that is recognized is actEnergy.
288  * Anything else has no effect. This affects what
289  * units converter is used.
290  * @param nodeName XML Name of the XML node to read.
291  * The default value for the node name is floatArray
292  * @return Returns the number of floats read into v.
293  */
294 size_t getFloatArray(const XML_Node& node, std::vector<doublereal> & v,
295  const bool convert=true, const std::string& unitsString="",
296  const std::string& nodeName = "floatArray");
297 
298 //! This function interprets the value portion of an XML element
299 //! as a string. It then separates the string up into tokens
300 //! according to the location of white space.
301 /*!
302  * The separate tokens are returned in the string vector
303  *
304  * @param node Node to get the value from
305  * @param v Output vector containing the string tokens
306  */
307 void getStringArray(const XML_Node& node, std::vector<std::string>& v);
308 
309 //! This routine is used to interpret the value portions of XML
310 //! elements that contain colon separated pairs.
311 /*!
312  * These are used, for example, in describing the element composition of
313  * species.
314  *
315  * <atomArray> H:4 C:1 <atomArray>
316  *
317  * The string is first separated into a string vector according to the
318  * location of white space. Then each string is again separated into two parts
319  * according to the location of a colon in the string. The first part of the
320  * string is used as the key, while the second part of the string is used as
321  * the value, in the return map. It is an error to not find a colon in each
322  * string pair.
323  *
324  * @param node Current node
325  * @param m Output Map containing the pairs of values found
326  * in the XML Node
327  */
328 void getMap(const XML_Node& node, std::map<std::string, std::string>& m);
329 
330 //! This function interprets the value portion of an XML element
331 //! as a series of "Pairs" separated by white space.
332 /*!
333  * Each pair consists of non-whitespace characters. The first ":" found in the
334  * pair string is used to separate the string into two parts. The first part
335  * is called the "key" The second part is called the "val". String vectors of
336  * key[i] and val[i] are returned in the argument list. Warning: No spaces are
337  * allowed in each pair. Quotes get included as part of the string. Example:
338  *
339  * <xmlNode>
340  * red:112 blue:34
341  * green:banana
342  * </xmlNode>
343  *
344  * Returns:
345  *
346  * index | key | val
347  * ----- | ------- | ---------
348  * 0 | "red" | "112"
349  * 1 | "blue" | "34"
350  * 2 | "green" | "banana"
351  *
352  * @param node XML Node
353  * @param key Vector of keys for each entry
354  * @param val Vector of values for each entry
355  *
356  * @return Returns the number of pairs found
357  */
358 int getPairs(const XML_Node& node, std::vector<std::string>& key,
359  std::vector<std::string>& val);
360 
361 //! This function interprets the value portion of an XML element
362 //! as a series of "Matrix ids and entries" separated by white space.
363 /*!
364  * Each pair consists of non-whitespace characters. The first two ":" found in
365  * the pair string is used to separate the string into three parts. The first
366  * part is called the first key. The second part is the second key. Both parts
367  * must match an entry in the keyString1 and keyString2, respectively, in
368  * order to provide a location to place the object in the matrix. The third
369  * part is called the value. It is expected to be a double. It is translated
370  * into a double and placed into the correct location in the matrix.
371  *
372  * Warning: No spaces are allowed in each triplet. Quotes are part of the
373  * string.
374  *
375  * Example:
376  * keyString = red, blue, black, green
377  *
378  * <xmlNode>
379  * red:green:112
380  * blue:black:3.3E-23
381  * </xmlNode>
382  *
383  * Returns:
384  *
385  * retnValues(0, 3) = 112
386  * retnValues(1, 2) = 3.3E-23
387  *
388  * @param node XML Node containing the information for the matrix
389  * @param keyStringRow Key string for the row
390  * @param keyStringCol Key string for the column entries
391  * @param returnValues Return Matrix.
392  * @param convert If this is true, and if the node has a units
393  * attribute, then conversion to SI units is carried
394  * out. Default is true.
395  * @param matrixSymmetric If true entries are made so that the matrix
396  * is always symmetric. Default is false.
397  */
398 void getMatrixValues(const XML_Node& node,
399  const std::vector<std::string>& keyStringRow,
400  const std::vector<std::string>& keyStringCol,
401  Array2D& returnValues, const bool convert = true,
402  const bool matrixSymmetric = false);
403 
404 //! Get a vector of integer values from a child element.
405 /*!
406  * Returns a std::map containing a keyed values for child XML_Nodes of the
407  * current node with the name, "integer". In the keyed mapping there will be a
408  * list of titles vs. values for all of the XML nodes. The integer XML_nodes
409  * are expected to be in a particular form created by the function
410  * addInteger(). One value per XML_node is expected.
411  *
412  * Example:
413  * @code
414  * const XML_Node &State_XMLNode;
415  * std::map<std::string, integer> v;
416  * getInteger(State_XMLNode, v);
417  * @endcode
418  * reads the corresponding XML file:
419  *
420  * <state>
421  * <integer title="i1"> 1 <\integer>
422  * <integer title="i2"> 2 <\integer>
423  * <integer title="i3"> 3 <\integer>
424  * <\state>
425  *
426  * Will produce the mapping:
427  *
428  * v["i1"] = 1
429  * v["i2"] = 2
430  * v["i3"] = 3
431  *
432  * @param node Current XML node to get the values from
433  * @param v Output map of the results.
434  */
435 void getIntegers(const XML_Node& node, std::map<std::string,int>& v);
436 
437 //! Get a floating-point value from a child element.
438 /*!
439  * Returns a doublereal value for the child named 'name' of element 'parent'.
440  * If 'type' is supplied and matches a known unit type, unit conversion to SI
441  * will be done if the child element has an attribute 'units'.
442  *
443  * Note, it's an error for the child element not to exist.
444  *
445  * Example:
446  *
447  * Code snippet:
448  * @code
449  * const XML_Node &State_XMLNode;
450  * doublereal pres = OneAtm;
451  * if (state_XMLNode.hasChild("pressure")) {
452  * pres = getFloat(State_XMLNode, "pressure", "toSI");
453  * }
454  * @endcode
455  *
456  * reads the corresponding XML file:
457  *
458  * <state>
459  * <pressure units="Pa"> 101325.0 </pressure>
460  * <\state>
461  *
462  * @param parent reference to the XML_Node object of the parent XML element
463  * @param name Name of the XML child element
464  * @param type String type. Currently known types are "toSI" and "actEnergy",
465  * and "" , for no conversion. The default value is "",
466  * which implies that no conversion is allowed.
467  */
468 doublereal getFloat(const XML_Node& parent, const std::string& name,
469  const std::string& type="");
470 
471 //! Get a floating-point value from the current XML element
472 /*!
473  * Returns a doublereal value from the current element. If 'type' is supplied
474  * and matches a known unit type, unit conversion to SI will be done if the
475  * child element has an attribute 'units'.
476  *
477  * Note, it's an error for the child element not to exist.
478  *
479  * Example:
480  *
481  * Code snippet:
482  * @code
483  * const XML_Node &State_XMLNode;
484  * doublereal pres = OneAtm;
485  * if (state_XMLNode.hasChild("pressure")) {
486  * XML_Node *pres_XMLNode = State_XMLNode.getChild("pressure");
487  * pres = getFloatCurrent(pres_XMLNode, "toSI");
488  * }
489  * @endcode
490  *
491  * Reads the corresponding XML file:
492  *
493  * <state>
494  * <pressure units="Pa"> 101325.0 </pressure>
495  * <\state>
496  *
497  * @param currXML reference to the current XML_Node object
498  * @param type String type. Currently known types are "toSI" and "actEnergy",
499  * and "" , for no conversion. The default value is "",
500  * which implies that no conversion is allowed.
501  */
502 doublereal getFloatCurrent(const XML_Node& currXML, const std::string& type="");
503 
504 //! Get an optional floating-point value from a child element.
505 /*!
506  * Returns a doublereal value for the child named 'name' of element 'parent'.
507  * If 'type' is supplied and matches a known unit type, unit conversion to SI
508  * will be done if the child element has an attribute 'units'.
509  *
510  * Example:
511  *
512  * Code snippet:
513  * @code
514  * const XML_Node &State_XMLNode;
515  * doublereal pres = OneAtm;
516  * bool exists = getOptionalFloat(State_XMLNode, "pressure", pres, "toSI");
517  * @endcode
518  *
519  * reads the corresponding XML file:
520  *
521  * <state>
522  * <pressure units="Pa"> 101325.0 </pressure>
523  * <\state>
524  *
525  * @param parent reference to the XML_Node object of the parent XML element
526  * @param name Name of the XML child element
527  * @param fltRtn Float Return. It will be overridden if the XML
528  * element exists.
529  * @param type String type. Currently known types are "toSI" and
530  * "actEnergy", and "" , for no conversion. The default value is
531  * "", which implies that no conversion is allowed.
532  *
533  * @return returns true if the child element named "name" exists
534  */
535 bool getOptionalFloat(const XML_Node& parent, const std::string& name,
536  doublereal& fltRtn, const std::string& type="");
537 
538 //! Get an integer value from a child element.
539 /*!
540  * Returns an integer value for the child named 'name' of element 'parent'.
541  * Note, it's an error for the child element not to exist.
542  *
543  * Example:
544  *
545  * Code snippet:
546  * @code
547  * const XML_Node &State_XMLNode;
548  * int number = 1;
549  * if (state_XMLNode.hasChild("NumProcs")) {
550  * number = getInteger(State_XMLNode, "numProcs");
551  * }
552  * @endcode
553  *
554  * reads the corresponding XML file:
555  *
556  * <state>
557  * <numProcs> 10 <numProcs/>
558  * <\state>
559  *
560  * @param parent reference to the XML_Node object of the parent XML element
561  * @param name Name of the XML child element
562  */
563 int getInteger(const XML_Node& parent, const std::string& name);
564 
565 //! Get a floating-point value from a child element with a defined units field
566 /*!
567  * Returns a doublereal value for the child named 'name' of element 'parent'.
568  * 'type' must be supplied and match a known unit type. Note, it's an error
569  * for the child element not to exist.
570  *
571  * Example:
572  *
573  * Code snippet:
574  * @code
575  * const XML_Node &State_XMLNode;
576  * doublereal pres = OneAtm;
577  * if (state_XMLNode.hasChild("pressure")) {
578  * pres = getFloatDefaultUnits(State_XMLNode, "pressure", "Pa", "toSI");
579  * }
580  * @endcode
581  *
582  * reads the corresponding XML file:
583  *
584  * <state>
585  * <pressure units="Pa"> 101325.0 </pressure>
586  * <\state>
587  *
588  * @param parent reference to the XML_Node object of the parent XML element
589  * @param name Name of the XML child element
590  * @param defaultUnits Default units string to be found in the units attribute.
591  * If the units string in the XML field is equal to defaultUnits,
592  * no units conversion will be carried out.
593  * @param type String type. Currently known types are "toSI" and "actEnergy",
594  * and "" , for no conversion. The default value is "",
595  * which implies that no conversion is allowed.
596  */
597 doublereal getFloatDefaultUnits(const XML_Node& parent,
598  const std::string& name,
599  const std::string& defaultUnits,
600  const std::string& type="toSI");
601 
602 //! Get an optional model name from a named child node.
603 /*!
604  * Returns the model name attribute for the child named 'nodeName' of element
605  * 'parent'. Note, it's optional for the child node to exist
606  *
607  * Example:
608  *
609  * Code snippet:
610  * @code
611  * std::string modelName = "";
612  * bool exists = getOptionalModel(transportNode, "compositionDependence",
613  * modelName);
614  * @endcode
615  *
616  * reads the corresponding XML file:
617  *
618  * <transport model="Simple">
619  * <compositionDependence model="Solvent_Only"/>
620  * </transport>
621  *
622  * On return modelName is set to "Solvent_Only".
623  *
624  * @param parent reference to the XML_Node object of the parent XML element
625  * @param nodeName Name of the XML child element
626  * @param modelName On return this contains the contents of the model attribute
627  * @return True if the nodeName XML node exists. False otherwise.
628  */
629 bool getOptionalModel(const XML_Node& parent, const std::string& nodeName,
630  std::string& modelName);
631 
632 //! Search the child nodes of the current node for an XML Node with a Title
633 //! attribute of a given name.
634 /*!
635  * @param node Current node from which to conduct the search
636  * @param title Name of the title attribute
637  * @return Returns a pointer to the matched child node. Returns 0 if no node
638  * is found.
639  */
640 XML_Node* getByTitle(const XML_Node& node, const std::string& title);
641 
642 //! This function reads a child node with the name string with a specific
643 //! title attribute named titleString
644 /*!
645  * This function will read a child node to the current XML node with the name
646  * "string". It must have a title attribute, named titleString, and the body
647  * of the XML node will be read into the valueString output argument.
648  *
649  * If the child node is not found then the empty string is returned.
650  *
651  * Example:
652  *
653  * Code snipet:
654  * @code
655  * const XML_Node &node;
656  * getString(XML_Node& node, std::string titleString, std::string valueString,
657  * std::string typeString);
658  * @endcode
659  *
660  * Reads the following the snippet in the XML file:
661  *
662  * <string title="titleString" type="typeString">
663  * valueString
664  * <\string>
665  *
666  * @param node Reference to the XML_Node object of the parent XML element
667  * @param titleString String name of the title attribute of the child node
668  * @param valueString Value string that is found in the child node. output
669  * variable
670  * @param typeString String type. This is an optional output variable. It
671  * is filled with the attribute "type" of the XML entry.
672  */
673 void getString(const XML_Node& node, const std::string& titleString,
674  std::string& valueString, std::string& typeString);
675 
676 //! This function attempts to read a named child node and returns with the
677 //! contents in the value string. title attribute named "titleString"
678 /*!
679  * This function will read a child node to the current XML node, with the name
680  * "string". It must have a title attribute, named titleString, and the body
681  * of the XML node will be read into the valueString output argument.
682  *
683  * If the child node is not found then the empty string is returned.
684  *
685  * Example:
686  *
687  * Code snippet:
688  * @code
689  * const XML_Node &node;
690  * std::string valueString;
691  * std::string typeString;
692  * std::string nameString = "timeIncrement";
693  * getString(XML_Node& node, nameString, valueString, valueString, typeString);
694  * @endcode
695  *
696  * Reads the following the snippet in the XML file:
697  *
698  * <nameString type="typeString">
699  * valueString
700  * <\nameString>
701  *
702  * or alternatively as a retrofit and special case, it also reads the
703  * following case:
704  *
705  * <string title="nameString" type="typeString">
706  * valueString
707  * <\string>
708  *
709  * @param node Reference to the XML_Node object of the parent XML element
710  * @param[in] nameString Name of the XML Node
711  * @param[out] valueString Value string that is found in the child node.
712  * @param[out] typeString String type. This is an optional output variable.
713  * It is filled with the attribute "type" of the XML entry.
714  * @deprecated To be removed after Cantera 2.2.
715  */
716 void getNamedStringValue(const XML_Node& node, const std::string& nameString, std::string& valueString,
717  std::string& typeString);
718 
719 //! This function reads a child node with the name, nameString, and returns
720 //! its XML value as the return string
721 /*!
722  * If the child XML_node named "name" doesn't exist, the empty string is returned.
723  *
724  * Code snippet:
725  * @code
726  * const XML_Node &parent;
727  * string nameString = "vacancy_species";
728  * string valueString = getChildValue(parent, nameString
729  * std::string typeString);
730  * @endcode
731  *
732  * returns `valueString = "O(V)"` from the following the snippet in the XML file:
733  *
734  * <vacancySpecies>
735  * O(V)
736  * <\vacancySpecies>
737  *
738  * @param parent parent reference to the XML_Node object of the parent XML element
739  * @param nameString Name of the child XML_Node to read the value from.
740  * @return String value of the child XML_Node
741  */
742 std::string getChildValue(const XML_Node& parent,
743  const std::string& nameString);
744 
745 //! Read an ctml file from a file and fill up an XML tree
746 /*!
747  * This is the main routine that reads a ctml file and puts it into
748  * an XML_Node tree
749  *
750  * @param node Root of the tree
751  * @param file Name of the file
752  * @param debug Turn on debugging printing
753  * @deprecated To be removed after Cantera 2.2. Use get_XML_File() instead.
754  */
755 void get_CTML_Tree(XML_Node* node, const std::string& file,
756  const int debug = 0);
757 
758 //! Read an ctml file from a file and fill up an XML tree.
759 //! @param file Name of the file
760 //! @return Root of the tree
761 //! @deprecated To be removed after Cantera 2.2. Use get_XML_File() instead.
762 XML_Node getCtmlTree(const std::string& file);
763 
764 //! Convert a cti file into a ctml file
765 /*!
766  * @param file Pointer to the file
767  * @param debug Turn on debug printing
768  *
769  * @ingroup inputfiles
770  */
771 void ct2ctml(const char* file, const int debug = 0);
772 
773 //! Get a string with the ctml representation of a cti file.
774 /*!
775  * @param file Path to the input file in CTI format
776  * @return String containing the XML representation of the input file
777  *
778  * @ingroup inputfiles
779  */
780 std::string ct2ctml_string(const std::string& file);
781 
782 //! Get a string with the ctml representation of a cti input string.
783 /*!
784  * @param cti String containing the cti representation
785  * @return String containing the XML representation of the input
786  *
787  * @ingroup inputfiles
788  */
789 std::string ct_string2ctml_string(const std::string& cti);
790 
791 //! Convert a Chemkin-format mechanism into a CTI file.
792 /*!
793  * @param in_file input file containing species and reactions
794  * @param thermo_file optional input file containing thermo data
795  * @param transport_file optional input file containing transport parameters
796  * @param id_tag id of the phase
797  */
798 void ck2cti(const std::string& in_file, const std::string& thermo_file="",
799  const std::string& transport_file="",
800  const std::string& id_tag="gas");
801 
802 }
803 
804 // namespace alias for backward compatibility
805 namespace ctml = Cantera;
806 
807 #endif
void getMap(const XML_Node &node, std::map< std::string, std::string > &m)
This routine is used to interpret the value portions of XML elements that contain colon separated pai...
Definition: ctml.cpp:403
void addFloatArray(XML_Node &node, const std::string &title, const size_t n, const doublereal *const vals, const std::string &units, const std::string &type, const doublereal minval, const doublereal maxval)
This function adds a child node with the name, "floatArray", with a value consisting of a comma separ...
Definition: ctml.cpp:51
std::string ct2ctml_string(const std::string &file)
Get a string with the ctml representation of a cti file.
Definition: ct2ctml.cpp:178
std::string getChildValue(const XML_Node &parent, const std::string &nameString)
This function reads a child node with the name, nameString, and returns its XML value as the return s...
Definition: ctml.cpp:142
void addNamedFloatArray(XML_Node &node, const std::string &name, const size_t n, const doublereal *const vals, const std::string units, const std::string type, const doublereal minval, const doublereal maxval)
This function adds a child node with the name given by the first parameter with a value consisting of...
Definition: ctml.cpp:84
void addInteger(XML_Node &node, const std::string &title, const int val, const std::string &units, const std::string &type)
This function adds a child node with the name, "integer", with a value consisting of a single integer...
Definition: ctml.cpp:17
void addString(XML_Node &node, const std::string &titleString, const std::string &valueString, const std::string &typeString)
This function adds a child node with the name string with a string value to the current node...
Definition: ctml.cpp:122
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:100
This file contains definitions of terms that are used in internal routines and are unlikely to need m...
const doublereal Undef
Fairly random number to be used to initialize variables against to see if they are subsequently defin...
Definition: ct_defs.h:134
A class for 2D arrays stored in column-major (Fortran-compatible) form.
Definition: Array.h:29
void ct2ctml(const char *file, const int debug)
Convert a cti file into a ctml file.
Definition: ct2ctml.cpp:55
const std::string CTML_Version
const Specifying the CTML version number
Definition: ctml.h:23
XML_Node getCtmlTree(const std::string &file)
Read an ctml file from a file and fill up an XML tree.
Definition: ct2ctml.cpp:285
void getIntegers(const XML_Node &node, std::map< std::string, int > &v)
Get a vector of integer values from a child element.
Definition: ctml.cpp:182
doublereal getFloatCurrent(const XML_Node &node, const std::string &type)
Get a floating-point value from the current XML element.
Definition: ctml.cpp:206
void ck2cti(const std::string &in_file, const std::string &thermo_file, const std::string &transport_file, const std::string &id_tag)
Convert a Chemkin-format mechanism into a CTI file.
Definition: ct2ctml.cpp:188
Classes providing support for XML data files.
void get_CTML_Tree(XML_Node *rootPtr, const std::string &file, const int debug)
Read an ctml file from a file and fill up an XML tree.
Definition: ct2ctml.cpp:277
int getPairs(const XML_Node &node, std::vector< std::string > &key, std::vector< std::string > &val)
This function interprets the value portion of an XML element as a series of "Pairs" separated by whit...
Definition: ctml.cpp:417
void getString(const XML_Node &node, const std::string &titleString, std::string &valueString, std::string &typeString)
This function reads a child node with the name string with a specific title attribute named titleStri...
Definition: ctml.cpp:150
std::string ct_string2ctml_string(const std::string &cti)
Get a string with the ctml representation of a cti input string.
Definition: ct2ctml.cpp:183
void addFloat(XML_Node &node, const std::string &title, const doublereal val, const std::string &units, const std::string &type, const doublereal minval, const doublereal maxval)
This function adds a child node with the name, "float", with a value consisting of a single floating ...
Definition: ctml.cpp:30
void getMatrixValues(const XML_Node &node, const std::vector< std::string > &keyStringRow, const std::vector< std::string > &keyStringCol, Array2D &retnValues, const bool convert, const bool matrixSymmetric)
This function interprets the value portion of an XML element as a series of "Matrix ids and entries" ...
Definition: ctml.cpp:435
int getInteger(const XML_Node &parent, const std::string &name)
Get an integer value from a child element.
Definition: ctml.cpp:301
bool getOptionalModel(const XML_Node &parent, const std::string &nodeName, std::string &modelName)
Get an optional model name from a named child node.
Definition: ctml.cpp:291
XML_Node * getByTitle(const XML_Node &node, const std::string &title)
Search the child nodes of the current node for an XML Node with a Title attribute of a given name...
Definition: ctml.cpp:133
void getStringArray(const XML_Node &node, std::vector< std::string > &v)
This function interprets the value portion of an XML element as a string.
Definition: ctml.cpp:503
size_t getFloatArray(const XML_Node &node, std::vector< doublereal > &v, const bool convert, const std::string &unitsString, const std::string &nodeName)
This function reads the current node or a child node of the current node with the default name...
Definition: ctml.cpp:323
doublereal getFloat(const XML_Node &parent, const std::string &name, const std::string &type)
Get a floating-point value from a child element.
Definition: ctml.cpp:194
doublereal getFloatDefaultUnits(const XML_Node &parent, const std::string &name, const std::string &defaultUnits, const std::string &type)
Get a floating-point value from a child element with a defined units field.
Definition: ctml.cpp:264
void getNamedStringValue(const XML_Node &node, const std::string &nameString, std::string &valueString, std::string &typeString)
This function attempts to read a named child node and returns with the contents in the value string...
Definition: ctml.cpp:163
bool getOptionalFloat(const XML_Node &parent, const std::string &name, doublereal &fltRtn, const std::string &type)
Get an optional floating-point value from a child element.
Definition: ctml.cpp:252