17 std::string FP_Format =
"%23.15E";
20 const std::string& units,
const std::string& type)
22 warn_deprecated(
"addInteger",
"Unused. To be removed after Cantera 2.3.");
23 XML_Node& f = node.addChild(title, val);
34 const doublereal val,
const std::string& units,
35 const std::string& type,
const doublereal minval,
36 const doublereal maxval)
38 XML_Node& f = node.addChild(title, val, FP_Format);
46 if (minval !=
Undef) {
49 if (maxval !=
Undef) {
55 const doublereal*
const vals,
const std::string& units,
56 const std::string& type,
57 const doublereal minval,
const doublereal maxval)
60 for (
size_t i = 0; i < n; i++) {
61 v += fmt::sprintf(FP_Format, vals[i]);
64 }
else if (i > 0 && (i+1) % 3 == 0) {
70 XML_Node& f = node.addChild(
"floatArray",v);
79 if (minval !=
Undef) {
82 if (maxval !=
Undef) {
88 const doublereal*
const vals,
const std::string units,
89 const std::string type,
const doublereal minval,
90 const doublereal maxval)
93 for (
size_t i = 0; i < n; i++) {
94 v += fmt::sprintf(FP_Format, vals[i]);
97 }
else if (i > 0 && (i+1) % 3 == 0) {
103 XML_Node& f = node.addChild(name, v);
117 if (minval !=
Undef) {
120 if (maxval !=
Undef) {
126 const std::string& valueString,
127 const std::string& typeString)
129 XML_Node& f = node.addChild(
"string", valueString);
131 if (typeString !=
"") {
139 if (s && s->
parent() == &node) {
150 return parent(nameString);
154 std::string& typeString)
157 if (s && s->
name() ==
"string") {
158 valueString = s->
value();
159 typeString = s->
attrib(
"type");
167 std::map<std::string, int>& v)
169 std::vector<XML_Node*> f = node.
getChildren(
"integer");
170 for (
size_t i = 0; i < f.size(); i++) {
172 if (fi[
"min"] !=
"" && fi[
"max"] !=
"") {
173 v[fi[
"title"]] = fi.int_value();
179 const std::string& name,
180 const std::string& type)
183 throw CanteraError(
"getFloat (called from XML Node \"" +
184 parent.
name() +
"\"): ",
185 "no child XML element named \"" + name +
"\" exists");
193 doublereal fctr = 1.0;
195 const string& units = node[
"units"];
196 const string& vmin = node[
"min"];
197 const string& vmax = node[
"max"];
199 writelog(
"\nWarning: value "+node.
value()+
" is below lower limit of " 202 if (node[
"max"] !=
"" && x >
fpValue(vmax) +
Tiny) {
203 writelog(
"\nWarning: value "+node.
value()+
" is above upper limit of " 208 if (type ==
"actEnergy" && units !=
"") {
210 }
else if (type ==
"toSI" && units !=
"") {
212 }
else if (type ==
"temperature" && units !=
"") {
214 }
else if (type ==
"density" && units !=
"") {
216 }
else if (type ==
"pressure" && units !=
"") {
218 }
else if (type !=
"" && units !=
"") {
220 writelog(
"\nWarning: conversion toSI() was done on node value " + node.
name() +
221 "but wasn't explicitly requested. Type was \"" + type +
"\"\n");
227 const std::string& name,
229 const std::string& type)
232 fltRtn =
getFloat(parent, name, type);
239 const std::string& name,
240 const std::string& defaultUnits,
241 const std::string& type)
244 "Use getFloat and toSI directly. To be removed after Cantera 2.3.");
245 doublereal fctr = 1.0;
246 if (defaultUnits ==
"") {
248 "need to supply an actual value of defaultUnits");
250 if (type ==
"actEnergy") {
252 }
else if (type ==
"toSI") {
253 fctr =
toSI(defaultUnits);
254 }
else if (defaultUnits ==
"temperature") {
255 fctr =
toSI(defaultUnits);
256 }
else if (type ==
"density") {
257 fctr =
toSI(defaultUnits);
258 }
else if (type ==
"pressure") {
259 fctr =
toSI(defaultUnits);
262 "type of units must be supplied and understood");
264 return getFloat(parent, name, type) / fctr;
268 std::string& modelName)
271 modelName = parent.
child(nodeName)[
"model"];
280 throw CanteraError(
"getInteger (called from XML Node \"" +
281 parent.
name() +
"\"): ",
282 "no child XML element named " + name);
286 const string& vmin = node[
"min"];
287 const string& vmax = node[
"max"];
288 if (vmin !=
"" && x <
intValue(vmin)) {
289 writelog(
"\nWarning: value "+node.
value()+
" is below lower limit of " 292 if (node[
"max"] !=
"" && x >
intValue(vmax)) {
293 writelog(
"\nWarning: value "+node.
value()+
" is above upper limit of " 300 const bool convert,
const std::string& unitsString,
301 const std::string& nodeName)
304 if (node.
name() != nodeName) {
306 if (ll.size() == 0) {
308 "wrong XML element type/name: was expecting " 309 + nodeName +
"but accessed " + node.
name());
321 doublereal funit = 1.0;
324 std::string units = readNode->
attrib(
"units");
325 if (units !=
"" && convert) {
326 if (unitsString ==
"actEnergy" && units !=
"") {
328 }
else if (unitsString !=
"" && units !=
"") {
333 if (readNode->
attrib(
"min") !=
"") {
336 if (readNode->
attrib(
"max") !=
"") {
340 std::string val = readNode->
value();
342 size_t icom = val.find(
',');
344 string numstr = val.substr(0,icom);
345 val = val.substr(icom+1,val.size());
357 doublereal vv = v.back();
359 writelog(
"\nWarning: value {} is below lower limit of {}.\n",
363 writelog(
"\nWarning: value {} is above upper limit of {}.\n",
367 for (
size_t n = 0; n < v.size(); n++) {
375 std::vector<std::string> v;
377 for (
size_t i = 0; i < v.size(); i++) {
378 size_t icolon = v[i].find(
":");
380 throw CanteraError(
"getMap",
"missing colon in map entry (" 383 m[v[i].substr(0,icolon)] = v[i].substr(icolon+1, v[i].size());
388 std::vector<std::string>& val)
392 int n =
static_cast<int>(v.size());
393 for (
int i = 0; i < n; i++) {
394 size_t icolon = v[i].find(
":");
396 throw CanteraError(
"getPairs",
"Missing a colon in the Pair entry (" 399 key.push_back(v[i].substr(0,icolon));
400 val.push_back(v[i].substr(icolon+1, v[i].size()));
406 const std::vector<std::string>& keyStringRow,
407 const std::vector<std::string>& keyStringCol,
408 Array2D& retnValues,
const bool convert,
409 const bool matrixSymmetric)
411 if (keyStringRow.size() > retnValues.
nRows()) {
413 "size of key1 greater than numrows");
414 }
else if (keyStringCol.size() > retnValues.
nColumns()) {
416 "size of key2 greater than num cols");
417 }
else if (matrixSymmetric && retnValues.
nRows() != retnValues.
nColumns()) {
419 "nrow != ncol for a symmetric matrix");
424 doublereal funit = 1.0;
425 if (convert && node[
"units"] !=
"") {
426 funit =
toSI(node[
"units"]);
431 for (
size_t i = 0; i < v.size(); i++) {
432 size_t icolon = v[i].find(
":");
434 throw CanteraError(
"getMatrixValues",
"Missing two colons (" 437 string key1 = v[i].substr(0,icolon);
438 string rmm = v[i].substr(icolon+1, v[i].size());
440 icolon = rmm.find(
":");
442 throw CanteraError(
"getMatrixValues",
"Missing one colon (" 446 size_t irow = find(keyStringRow.begin(), keyStringRow.end(), key1)
447 - keyStringRow.begin();
448 if (irow == keyStringRow.size()) {
449 throw CanteraError(
"getMatrixValues",
"Row not matched by string: " 453 string key2 = rmm.substr(0,icolon);
454 size_t icol = find(keyStringCol.begin(), keyStringCol.end(), key2)
455 - keyStringCol.begin();
456 if (icol == keyStringCol.size()) {
457 throw CanteraError(
"getMatrixValues",
"Col not matched by string: " 460 double dval =
fpValueCheck(rmm.substr(icolon+1, rmm.size())) * funit;
463 retnValues(irow, icol) = dval;
464 if (matrixSymmetric) {
465 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.
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...
size_t nRows() const
Number of rows.
size_t getFloatArray(const XML_Node &node, vector_fp &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...
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
std::string name() const
Returns the name of the XML node.
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...
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...
void writelog(const std::string &fmt, const Args &... args)
Write a formatted message to the screen.
integer int_value() const
Return the value of an XML node as a single int.
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.
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.
void tokenizeString(const std::string &in_val, 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...
XML_Node * parent() const
Returns a pointer to the parent node of the current node.
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...
std::string value() const
Return the value of an XML node as a string.
void addAttribute(const std::string &attrib, const std::string &value)
Add or modify an attribute of the current node.
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
int intValue(const std::string &val)
Translate a string into one integer value.
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.
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
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...
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
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.
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.
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...
Namespace for the Cantera kernel.
doublereal fpValueCheck(const std::string &val)
Translate a string into one doublereal value, with error checking.
doublereal fp_value() const
Return the value of an XML node as a single double.
size_t nColumns() const
Number of columns.
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.