15 std::string FP_Format =
"%23.15E";
18 const std::string& units,
const std::string& type)
20 XML_Node& f = node.addChild(title, val);
31 const doublereal val,
const std::string& units,
32 const std::string& type,
const doublereal minval,
33 const doublereal maxval)
35 XML_Node& f = node.addChild(title, val, FP_Format);
43 if (minval !=
Undef) {
46 if (maxval !=
Undef) {
52 const doublereal*
const vals,
const std::string& units,
53 const std::string& type,
54 const doublereal minval,
const doublereal maxval)
57 for (
size_t i = 0; i < n; i++) {
58 v +=
fp2str(vals[i],FP_Format);
61 }
else if (i > 0 && (i+1) % 3 == 0) {
67 XML_Node& f = node.addChild(
"floatArray",v);
76 if (minval !=
Undef) {
79 if (maxval !=
Undef) {
85 const doublereal*
const vals,
const std::string units,
86 const std::string type,
const doublereal minval,
87 const doublereal maxval)
90 for (
size_t i = 0; i < n; i++) {
91 v +=
fp2str(vals[i],FP_Format);
94 }
else if (i > 0 && (i+1) % 3 == 0) {
100 XML_Node& f = node.addChild(name, v);
114 if (minval !=
Undef) {
117 if (maxval !=
Undef) {
123 const std::string& valueString,
124 const std::string& typeString)
126 XML_Node& f = node.addChild(
"string", valueString);
128 if (typeString !=
"") {
136 if (s && s->
parent() == &node) {
147 return parent(nameString);
151 std::string& typeString)
154 if (s && s->
name() ==
"string") {
155 valueString = s->
value();
156 typeString = s->
attrib(
"type");
164 std::string& typeString)
166 warn_deprecated(
"getNamedStringValue",
"To be removed after Cantera 2.2");
171 valueString = xc.
value();
172 typeString = xc[
"type"];
175 if (s && s->
name() ==
"string") {
176 valueString = s->
value();
177 typeString = s->
attrib(
"type");
183 std::map<std::string, int>& v)
185 std::vector<XML_Node*> f = node.
getChildren(
"integer");
186 for (
size_t i = 0; i < f.size(); i++) {
188 if (fi[
"min"] !=
"" && fi[
"max"] !=
"") {
189 v[fi[
"title"]] = fi.int_value();
195 const std::string& name,
196 const std::string& type)
199 throw CanteraError(
"getFloat (called from XML Node \"" +
200 parent.
name() +
"\"): ",
201 "no child XML element named \"" + name +
"\" exists");
208 doublereal fctr = 1.0;
210 const string& units = node[
"units"];
211 const string& vmin = node[
"min"];
212 const string& vmax = node[
"max"];
214 writelog(
"\nWarning: value "+node.
value()+
" is below lower limit of "
217 if (node[
"max"] !=
"" && x >
fpValue(vmax) +
Tiny) {
218 writelog(
"\nWarning: value "+node.
value()+
" is above upper limit of "
223 if (type ==
"actEnergy" && units !=
"") {
225 }
else if (type ==
"toSI" && units !=
"") {
227 }
else if (type ==
"temperature" && units !=
"") {
229 }
else if (type ==
"density" && units !=
"") {
231 }
else if (type ==
"pressure" && units !=
"") {
233 }
else if (type !=
"" && units !=
"") {
236 writelog(
"\nWarning: conversion toSI() was done on node value " + node.
name() +
237 "but wasn't explicitly requested. Type was \"" + type +
"\"\n");
242 #ifdef DEBUG_MODE_MORE
243 else if (type ==
"" && units !=
"") {
245 "has a units attribute, \"" + units +
"\","
246 "but no conversion was done because the getFloat() command didn't have a type\n");
253 const std::string& name,
255 const std::string& type)
258 fltRtn =
getFloat(parent, name, type);
265 const std::string& name,
266 const std::string& defaultUnits,
267 const std::string& type)
269 doublereal fctr = 1.0;
270 if (defaultUnits ==
"") {
272 "need to supply an actual value of defaultUnits");
274 if (type ==
"actEnergy") {
276 }
else if (type ==
"toSI") {
277 fctr =
toSI(defaultUnits);
278 }
else if (defaultUnits ==
"temperature") {
279 fctr =
toSI(defaultUnits);
280 }
else if (type ==
"density") {
281 fctr =
toSI(defaultUnits);
282 }
else if (type ==
"pressure") {
283 fctr =
toSI(defaultUnits);
286 "type of units must be supplied and understood");
288 return getFloat(parent, name, type) / fctr;
292 std::string& modelName)
295 modelName = parent.
child(nodeName)[
"model"];
304 throw CanteraError(
"getInteger (called from XML Node \"" +
305 parent.
name() +
"\"): ",
306 "no child XML element named " + name);
310 const string& vmin = node[
"min"];
311 const string& vmax = node[
"max"];
312 if (vmin !=
"" && x <
intValue(vmin)) {
313 writelog(
"\nWarning: value "+node.
value()+
" is below lower limit of "
316 if (node[
"max"] !=
"" && x >
intValue(vmax)) {
317 writelog(
"\nWarning: value "+node.
value()+
" is above upper limit of "
324 const bool convert,
const std::string& unitsString,
325 const std::string& nodeName)
328 if (node.
name() != nodeName) {
330 if (ll.size() == 0) {
332 "wrong XML element type/name: was expecting "
333 + nodeName +
"but accessed " + node.
name());
346 doublereal funit = 1.0;
350 std::string units = readNode->
attrib(
"units");
351 if (units !=
"" && convert) {
352 if (unitsString ==
"actEnergy" && units !=
"") {
354 }
else if (unitsString !=
"" && units !=
"") {
359 if (readNode->
attrib(
"min") !=
"") {
362 if (readNode->
attrib(
"max") !=
"") {
366 std::string val = readNode->
value();
368 size_t icom = val.find(
',');
370 string numstr = val.substr(0,icom);
371 val = val.substr(icom+1,val.size());
387 doublereal vv = v.back();
390 " is below lower limit of " +
fp2str(vmin)+
".\n");
394 " is above upper limit of " +
fp2str(vmin)+
".\n");
397 for (
size_t n = 0; n < v.size(); n++) {
405 std::vector<std::string> v;
407 for (
size_t i = 0; i < v.size(); i++) {
408 size_t icolon = v[i].find(
":");
410 throw CanteraError(
"getMap",
"missing colon in map entry ("
413 m[v[i].substr(0,icolon)] = v[i].substr(icolon+1, v[i].size());
418 std::vector<std::string>& val)
422 int n =
static_cast<int>(v.size());
423 for (
int i = 0; i < n; i++) {
424 size_t icolon = v[i].find(
":");
426 throw CanteraError(
"getPairs",
"Missing a colon in the Pair entry ("
429 key.push_back(v[i].substr(0,icolon));
430 val.push_back(v[i].substr(icolon+1, v[i].size()));
436 const std::vector<std::string>& keyStringRow,
437 const std::vector<std::string>& keyStringCol,
438 Array2D& retnValues,
const bool convert,
439 const bool matrixSymmetric)
441 if (keyStringRow.size() > retnValues.
nRows()) {
443 "size of key1 greater than numrows");
444 }
else if (keyStringCol.size() > retnValues.
nColumns()) {
446 "size of key2 greater than num cols");
447 }
else if (matrixSymmetric && retnValues.
nRows() != retnValues.
nColumns()) {
449 "nrow != ncol for a symmetric matrix");
456 doublereal funit = 1.0;
457 if (convert && node[
"units"] !=
"") {
458 funit =
toSI(node[
"units"]);
463 for (
size_t i = 0; i < v.size(); i++) {
464 size_t icolon = v[i].find(
":");
466 throw CanteraError(
"getMatrixValues",
"Missing two colons ("
469 string key1 = v[i].substr(0,icolon);
470 string rmm = v[i].substr(icolon+1, v[i].size());
472 icolon = rmm.find(
":");
474 throw CanteraError(
"getMatrixValues",
"Missing one colon ("
478 size_t irow = find(keyStringRow.begin(), keyStringRow.end(), key1)
479 - keyStringRow.begin();
480 if (irow == keyStringRow.size()) {
481 throw CanteraError(
"getMatrixValues",
"Row not matched by string: "
485 string key2 = rmm.substr(0,icolon);
486 size_t icol = find(keyStringCol.begin(), keyStringCol.end(), key2)
487 - keyStringCol.begin();
488 if (icol == keyStringCol.size()) {
489 throw CanteraError(
"getMatrixValues",
"Col not matched by string: "
492 double dval =
fpValueCheck(rmm.substr(icolon+1, rmm.size())) * funit;
496 retnValues(irow, icol) = dval;
497 if (matrixSymmetric) {
498 retnValues(icol, irow) = dval;
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...
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...
doublereal fpValue(const std::string &val)
Translate a string into one doublereal value.
size_t nRows() const
Number of rows.
XML_Node * findByAttr(const std::string &attr, const std::string &val, int depth=100000) const
This routine carries out a recursive search for an XML node based on an attribute of each XML node...
integer int_value() const
Return the value of an XML node as a single int.
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
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...
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
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...
doublereal actEnergyToSI(const std::string &unit)
Return the conversion factor to convert activation energy unit std::string 'unit' to Kelvin...
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...
doublereal toSI(const std::string &unit)
Return the conversion factor to convert unit std::string 'unit' to SI units.
const size_t npos
index returned by functions to indicate "no position"
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...
Class XML_Node is a tree-based representation of the contents of an XML file.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
const doublereal Undef
Fairly random number to be used to initialize variables against to see if they are subsequently defin...
A class for 2D arrays stored in column-major (Fortran-compatible) form.
Header file for class Cantera::Array2D.
void getIntegers(const XML_Node &node, std::map< std::string, int > &v)
Get a vector of integer values from a child element.
doublereal getFloatCurrent(const XML_Node &node, const std::string &type)
Get a floating-point value from the current XML element.
std::string fp2str(const double x, const std::string &fmt)
Convert a double into a c++ string.
size_t nColumns() const
Number of columns.
std::string name() const
Returns the name of the XML node.
void tokenizeString(const std::string &oval, std::vector< std::string > &v)
This function separates a string up into tokens according to the location of white space...
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...
Base class for exceptions thrown by Cantera classes.
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...
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
void addAttribute(const std::string &attrib, const std::string &value)
Add or modify an attribute of the current node.
int intValue(const std::string &val)
Translate a string into one integer value.
std::string value() const
Return the value of an XML node as a string.
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 ...
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" ...
int getInteger(const XML_Node &parent, const std::string &name)
Get an integer value from a child element.
bool getOptionalModel(const XML_Node &parent, const std::string &nodeName, std::string &modelName)
Get an optional model name from a named child node.
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...
void getStringArray(const XML_Node &node, std::vector< std::string > &v)
This function interprets the value portion of an XML element as a string.
const doublereal Tiny
Small number to compare differences of mole fractions against.
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...
Contains declarations for string manipulation functions within Cantera.
doublereal getFloat(const XML_Node &parent, const std::string &name, const std::string &type)
Get a floating-point value from a child element.
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.
void writelog(const std::string &msg)
Write a message to the screen.
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...
doublereal fp_value() const
Return the value of an XML node as a single double.
XML_Node * parent() const
Returns a pointer to the parent node of the current node.
doublereal fpValueCheck(const std::string &val)
Translate a string into one doublereal value, with error checking.
void getChildren(const std::string &name, std::vector< XML_Node * > &children) const
Get a vector of pointers to XML_Node containing all of the children of the current node which matches...
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.