17 std::string FP_Format =
"%23.15E";
20 const doublereal val,
const std::string& units,
21 const std::string& type,
const doublereal minval,
22 const doublereal maxval)
24 XML_Node& f = node.addChild(title, val, FP_Format);
32 if (minval !=
Undef) {
35 if (maxval !=
Undef) {
41 const doublereal*
const vals,
const std::string& units,
42 const std::string& type,
43 const doublereal minval,
const doublereal maxval)
46 for (
size_t i = 0; i < n; i++) {
47 v += fmt::sprintf(FP_Format, vals[i]);
50 }
else if (i > 0 && (i+1) % 3 == 0) {
56 XML_Node& f = node.addChild(
"floatArray",v);
65 if (minval !=
Undef) {
68 if (maxval !=
Undef) {
74 const doublereal*
const vals,
const std::string units,
75 const std::string type,
const doublereal minval,
76 const doublereal maxval)
79 for (
size_t i = 0; i < n; i++) {
80 v += fmt::sprintf(FP_Format, vals[i]);
83 }
else if (i > 0 && (i+1) % 3 == 0) {
89 XML_Node& f = node.addChild(name, v);
103 if (minval !=
Undef) {
106 if (maxval !=
Undef) {
112 const std::string& valueString,
113 const std::string& typeString)
115 XML_Node& f = node.addChild(
"string", valueString);
117 if (typeString !=
"") {
125 if (s && s->
parent() == &node) {
136 return parent(nameString);
140 std::string& typeString)
143 if (s && s->
name() ==
"string") {
144 valueString = s->
value();
145 typeString = s->
attrib(
"type");
153 std::map<std::string, int>& v)
155 std::vector<XML_Node*> f = node.
getChildren(
"integer");
156 for (
size_t i = 0; i < f.size(); i++) {
158 if (fi[
"min"] !=
"" && fi[
"max"] !=
"") {
159 v[fi[
"title"]] = fi.int_value();
165 const std::string& name,
166 const std::string& type)
169 throw CanteraError(
"getFloat (called from XML Node \"" +
170 parent.
name() +
"\"): ",
171 "no child XML element named \"" + name +
"\" exists");
179 doublereal fctr = 1.0;
181 const string& units = node[
"units"];
182 const string& vmin = node[
"min"];
183 const string& vmax = node[
"max"];
185 writelog(
"\nWarning: value "+node.
value()+
" is below lower limit of " 188 if (node[
"max"] !=
"" && x >
fpValue(vmax) +
Tiny) {
189 writelog(
"\nWarning: value "+node.
value()+
" is above upper limit of " 194 if (type ==
"actEnergy" && units !=
"") {
196 }
else if (type ==
"toSI" && units !=
"") {
198 }
else if (type ==
"temperature" && units !=
"") {
200 }
else if (type ==
"density" && units !=
"") {
202 }
else if (type ==
"pressure" && units !=
"") {
204 }
else if (type !=
"" && units !=
"") {
206 writelog(
"\nWarning: conversion toSI() was done on node value " + node.
name() +
207 "but wasn't explicitly requested. Type was \"" + type +
"\"\n");
213 const std::string& name,
215 const std::string& type)
218 fltRtn =
getFloat(parent, name, type);
225 std::string& modelName)
228 modelName = parent.
child(nodeName)[
"model"];
237 throw CanteraError(
"getInteger (called from XML Node \"" +
238 parent.
name() +
"\"): ",
239 "no child XML element named " + name);
243 const string& vmin = node[
"min"];
244 const string& vmax = node[
"max"];
245 if (vmin !=
"" && x <
intValue(vmin)) {
246 writelog(
"\nWarning: value "+node.
value()+
" is below lower limit of " 249 if (node[
"max"] !=
"" && x >
intValue(vmax)) {
250 writelog(
"\nWarning: value "+node.
value()+
" is above upper limit of " 257 const bool convert,
const std::string& unitsString,
258 const std::string& nodeName)
261 if (node.
name() != nodeName) {
263 if (ll.size() == 0) {
265 "wrong XML element type/name: was expecting " 266 + nodeName +
"but accessed " + node.
name());
278 doublereal funit = 1.0;
281 std::string units = readNode->
attrib(
"units");
282 if (units !=
"" && convert) {
283 if (unitsString ==
"actEnergy" && units !=
"") {
285 }
else if (unitsString !=
"" && units !=
"") {
290 if (readNode->
attrib(
"min") !=
"") {
293 if (readNode->
attrib(
"max") !=
"") {
297 std::string val = readNode->
value();
299 size_t icom = val.find(
',');
301 string numstr = val.substr(0,icom);
302 val = val.substr(icom+1,val.size());
314 doublereal vv = v.back();
316 writelog(
"\nWarning: value {} is below lower limit of {}.\n",
320 writelog(
"\nWarning: value {} is above upper limit of {}.\n",
324 for (
size_t n = 0; n < v.size(); n++) {
332 std::vector<std::string> v;
334 for (
size_t i = 0; i < v.size(); i++) {
335 size_t icolon = v[i].find(
":");
337 throw CanteraError(
"getMap",
"missing colon in map entry (" 340 m[v[i].substr(0,icolon)] = v[i].substr(icolon+1, v[i].size());
345 std::vector<std::string>& val)
349 int n =
static_cast<int>(v.size());
350 for (
int i = 0; i < n; i++) {
351 size_t icolon = v[i].find(
":");
353 throw CanteraError(
"getPairs",
"Missing a colon in the Pair entry (" 356 key.push_back(v[i].substr(0,icolon));
357 val.push_back(v[i].substr(icolon+1, v[i].size()));
363 const std::vector<std::string>& keyStringRow,
364 const std::vector<std::string>& keyStringCol,
365 Array2D& retnValues,
const bool convert,
366 const bool matrixSymmetric)
368 if (keyStringRow.size() > retnValues.
nRows()) {
370 "size of key1 greater than numrows");
371 }
else if (keyStringCol.size() > retnValues.
nColumns()) {
373 "size of key2 greater than num cols");
374 }
else if (matrixSymmetric && retnValues.
nRows() != retnValues.
nColumns()) {
376 "nrow != ncol for a symmetric matrix");
381 doublereal funit = 1.0;
382 if (convert && node[
"units"] !=
"") {
383 funit =
toSI(node[
"units"]);
388 for (
size_t i = 0; i < v.size(); i++) {
389 size_t icolon = v[i].find(
":");
391 throw CanteraError(
"getMatrixValues",
"Missing two colons (" 394 string key1 = v[i].substr(0,icolon);
395 string rmm = v[i].substr(icolon+1, v[i].size());
397 icolon = rmm.find(
":");
399 throw CanteraError(
"getMatrixValues",
"Missing one colon (" 403 size_t irow = find(keyStringRow.begin(), keyStringRow.end(), key1)
404 - keyStringRow.begin();
405 if (irow == keyStringRow.size()) {
406 throw CanteraError(
"getMatrixValues",
"Row not matched by string: " 410 string key2 = rmm.substr(0,icolon);
411 size_t icol = find(keyStringCol.begin(), keyStringCol.end(), key2)
412 - keyStringCol.begin();
413 if (icol == keyStringCol.size()) {
414 throw CanteraError(
"getMatrixValues",
"Col not matched by string: " 417 double dval =
fpValueCheck(rmm.substr(icolon+1, rmm.size())) * funit;
420 retnValues(irow, icol) = dval;
421 if (matrixSymmetric) {
422 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.
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...
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...
doublereal actEnergyToSI(const std::string &unit)
Return the conversion factor to convert activation energy unit std::string 'unit' to Kelvin...
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.
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.
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.