10 #define CTML_VERSION_1_4_1
17 using namespace Cantera;
21 std::string FP_Format =
"%23.15E";
22 std::string INT_Format =
"%8d";
25 const std::string& units,
const std::string& type)
27 #ifdef CTML_VERSION_1_4
28 XML_Node& f = node.addChild(
"integer", val);
31 XML_Node& f = node.addChild(title, val);
43 const doublereal val,
const std::string& units,
44 const std::string& type,
const doublereal minval,
45 const doublereal maxval)
47 #ifdef CTML_VERSION_1_4
48 XML_Node& f = node.addChild(
"float", val, ctml::FP_Format);
51 XML_Node& f = node.addChild(title, val, ctml::FP_Format);
60 if (minval !=
Undef) {
63 if (maxval !=
Undef) {
69 const doublereal*
const vals,
const std::string& units,
70 const std::string& type,
71 const doublereal minval,
const doublereal maxval)
75 for (i = 0; i < n; i++) {
76 v +=
fp2str(vals[i],FP_Format);
79 }
else if (i > 0 && (i+1) % 3 == 0) {
85 XML_Node& f = node.addChild(
"floatArray",v);
94 if (minval !=
Undef) {
97 if (maxval !=
Undef) {
103 const doublereal*
const vals,
const std::string units,
104 const std::string type,
const doublereal minval,
105 const doublereal maxval)
109 for (i = 0; i < n; i++) {
110 v +=
fp2str(vals[i],FP_Format);
113 }
else if (i > 0 && (i+1) % 3 == 0) {
119 XML_Node& f = node.addChild(name, v);
133 if (minval !=
Undef) {
136 if (maxval !=
Undef) {
142 const std::string& valueString,
143 const std::string& typeString)
145 XML_Node& f = node.addChild(
"string", valueString);
147 if (typeString !=
"") {
158 if (s->
parent() == &node) {
169 return parent(nameString);
173 std::string& typeString)
179 if (s->
name() ==
"string") {
180 valueString = (*s).value();
181 typeString = (*s)[
"type"];
187 std::string& typeString)
193 valueString = xc.
value();
194 typeString = xc[
"type"];
198 if (s->
name() ==
"string") {
199 valueString = (*s).value();
200 typeString = (*s)[
"type"];
208 std::map<std::string, int>& v)
210 std::vector<XML_Node*> f;
212 int n =
static_cast<int>(f.size());
214 std::string typ, title, vmin, vmax;
215 for (
int i = 0; i < n; i++) {
217 x = atoi(fi().c_str());
222 if (fi[
"max"] !=
"") {
232 "To be removed in Cantera 2.2.");
233 std::vector<XML_Node*> f;
235 int n =
static_cast<int>(f.size());
236 doublereal x, x0, x1, fctr;
237 std::string typ, title, units, vmin, vmax;
238 for (
int i = 0; i < n; i++) {
251 writelog(
"\nWarning: value "+fi()+
" is below lower limit of "
255 if (fi[
"max"] !=
"") {
258 writelog(
"\nWarning: value "+fi()+
" is above upper limit of "
262 fctr = (convert ?
toSI(units) : 1.0);
268 const std::string& name,
269 const std::string& type)
272 throw CanteraError(
"getFloat (called from XML Node \"" +
273 parent.
name() +
"\"): ",
274 "no child XML element named \"" + name +
"\" exists");
280 const std::string& type)
282 doublereal x, x0, x1, fctr = 1.0;
283 string units, vmin, vmax;
287 units = node[
"units"];
293 writelog(
"\nWarning: value "+node()+
" is below lower limit of "
297 if (node[
"max"] !=
"") {
300 writelog(
"\nWarning: value "+node()+
" is above upper limit of "
306 if (type ==
"actEnergy" && units !=
"") {
308 }
else if (type ==
"toSI" && units !=
"") {
310 }
else if (type ==
"temperature" && units !=
"") {
312 }
else if (type ==
"density" && units !=
"") {
314 }
else if (type ==
"pressure" && units !=
"") {
316 }
else if (type !=
"" && units !=
"") {
319 writelog(
"\nWarning: conversion toSI() was done on node value " + node.
name() +
320 "but wasn't explicitly requested. Type was \"" + type +
"\"\n");
325 #ifdef DEBUG_MODE_MORE
326 else if (type ==
"" && units !=
"") {
328 "has a units attribute, \"" + units +
"\","
329 "but no conversion was done because the getFloat() command didn't have a type\n");
336 const std::string& name,
338 const std::string& type)
341 fltRtn=
getFloat(parent, name, type);
348 const std::string& name,
349 const std::string& defaultUnits,
350 const std::string& type)
352 doublereal fctr = 1.0;
353 if (defaultUnits ==
"") {
355 "need to supply an actual value of defaultUnits");
357 if (type ==
"actEnergy") {
359 }
else if (type ==
"toSI") {
360 fctr =
toSI(defaultUnits);
361 }
else if (defaultUnits ==
"temperature") {
362 fctr =
toSI(defaultUnits);
363 }
else if (type ==
"density") {
364 fctr =
toSI(defaultUnits);
365 }
else if (type ==
"pressure") {
366 fctr =
toSI(defaultUnits);
369 "type of units must be supplied and understood");
371 doublereal val =
getFloat(parent, name, type);
377 std::string& modelName)
381 modelName = node[
"model"];
390 throw CanteraError(
"getInteger (called from XML Node \"" +
391 parent.
name() +
"\"): ",
392 "no child XML element named " + name);
396 string units, vmin, vmax;
397 x = atoi(node().c_str());
403 x0 = atoi(vmin.c_str());
405 writelog(
"\nWarning: value "+node()+
" is below lower limit of "
409 if (node[
"max"] !=
"") {
410 x1 = atoi(vmax.c_str());
412 writelog(
"\nWarning: value "+node()+
" is above upper limit of "
420 const bool convert,
const std::string& unitsString,
421 const std::string& nodeName)
423 std::string::size_type icom;
426 string nn = node.
name();
428 if (nn != nodeName) {
429 vector<Cantera::XML_Node*> ll;
431 if (ll.size() == 0) {
433 "wrong xml element type/name: was expecting "
434 + nodeName +
"but accessed " + node.
name());
448 doublereal funit = 1.0;
452 std::string units = (*readNode)[
"units"];
453 if (units !=
"" && convert) {
454 if (unitsString ==
"actEnergy" && units !=
"") {
456 }
else if (unitsString !=
"" && units !=
"") {
461 if ((*readNode)[
"min"] !=
"") {
464 if ((*readNode)[
"max"] !=
"") {
469 std::string val = readNode->
value();
471 icom = val.find(
',');
473 numstr = val.substr(0,icom);
474 val = val.substr(icom+1,val.size());
495 " is below lower limit of " +
fp2str(vmin)+
".\n");
499 " is above upper limit of " +
fp2str(vmin)+
".\n");
502 for (
size_t n = 0; n < v.size(); n++) {
510 std::vector<std::string> v;
512 std::string key, val;
513 int n =
static_cast<int>(v.size());
514 string::size_type icolon;
515 for (
int i = 0; i < n; i++) {
516 icolon = v[i].find(
":");
518 throw CanteraError(
"getMap",
"missing colon in map entry ("
521 key = v[i].substr(0,icolon);
522 val = v[i].substr(icolon+1, v[i].size());
528 std::vector<std::string>& val)
532 int n =
static_cast<int>(v.size());
533 string::size_type icolon;
534 for (
int i = 0; i < n; i++) {
535 icolon = v[i].find(
":");
537 throw CanteraError(
"getPairs",
"Missing a colon in the Pair entry ("
540 key.push_back(v[i].substr(0,icolon));
541 val.push_back(v[i].substr(icolon+1, v[i].size()));
548 const std::vector<std::string>& keyStringRow,
549 const std::vector<std::string>& keyStringCol,
551 const bool matrixSymmetric)
553 size_t szKey1 = keyStringRow.size();
554 size_t szKey2 = keyStringCol.size();
555 size_t nrow = retnValues.
nRows();
556 size_t ncol = retnValues.
nColumns();
559 "size of key1 greater than numrows");
563 "size of key2 greater than num cols");
565 if (matrixSymmetric) {
568 "nrow != ncol for a symmetric matrix");
576 doublereal funit = 1.0;
577 string units = node[
"units"];
578 if (units !=
"" && convert) {
588 string::size_type icolon;
589 for (
size_t i = 0; i < v.size(); i++) {
590 icolon = v[i].find(
":");
592 throw CanteraError(
"getMatrixValues",
"Missing two colons ("
595 key1 = v[i].substr(0,icolon);
596 rmm = v[i].substr(icolon+1, v[i].size());
597 icolon = rmm.find(
":");
599 throw CanteraError(
"getMatrixValues",
"Missing one colon ("
602 key2 = rmm.substr(0,icolon);
603 val = rmm.substr(icolon+1, rmm.size());
607 for (
size_t j = 0; j < szKey1; j++) {
608 if (key1 == keyStringRow[j]) {
614 throw CanteraError(
"getMatrixValues",
"Row not matched by string: "
617 for (
size_t j = 0; j < szKey2; j++) {
618 if (key2 == keyStringCol[j]) {
624 throw CanteraError(
"getMatrixValues",
"Col not matched by string: "
632 retnValues(irow, icol) = dval;
633 if (matrixSymmetric) {
634 retnValues(icol, irow) = dval;
641 std::string val = node.
value();
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...
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
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 addNamedFloatArray(Cantera::XML_Node &node, const std::string &name, const int 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...
bool getOptionalModel(const Cantera::XML_Node &parent, const std::string &nodeName, std::string &modelName)
Get an optional model name from a named child node.
Class XML_Node is a tree-based representation of the contents of an XML file.
bool getOptionalFloat(const Cantera::XML_Node &parent, const std::string &name, doublereal &fltRtn, const std::string &type)
Get an optional floating-point value from a child element.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
doublereal getFloat(const Cantera::XML_Node &parent, const std::string &name, const std::string &type)
Get a floating-point value from a child element.
This file contains definitions for utility functions and text for modules, inputfiles, logs, textlogs, HTML_logs (see Input File Handling, Diagnostic Output, Writing messages to the screen and Writing HTML Logfiles).
void addString(Cantera::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...
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.
XML_Node * getByTitle(const Cantera::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::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...
void addFloatArray(Cantera::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 getFloatCurrent(const Cantera::XML_Node &node, const std::string &type)
Get a floating-point value from the current XML element.
void addFloat(Cantera::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 ...
Base class for exceptions thrown by Cantera classes.
int getPairs(const Cantera::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...
void getString(const Cantera::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 getIntegers(const Cantera::XML_Node &node, std::map< std::string, int > &v)
Get a vector of integer values from a child element.
void getNamedStringValue(const Cantera::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...
void addAttribute(const std::string &attrib, const std::string &value)
Add or modify an attribute of the current node.
std::string value() const
Return the value of an XML node as a string.
doublereal getFloatDefaultUnits(const Cantera::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 getFloats(const Cantera::XML_Node &node, std::map< std::string, double > &v, const bool convert)
Get a vector of floating-point values from a child element.
void getStringArray(const Cantera::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.
void addInteger(Cantera::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...
void getMatrixValues(const Cantera::XML_Node &node, const std::vector< std::string > &keyStringRow, const std::vector< std::string > &keyStringCol, Cantera::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" ...
Contains declarations for string manipulation functions within Cantera.
void writelog(const std::string &msg)
Write a message to the screen.
void getMap(const Cantera::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...
std::string getChildValue(const Cantera::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...
int getInteger(const Cantera::XML_Node &parent, const std::string &name)
Get an integer value from a child element.
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.
size_t getFloatArray(const Cantera::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...
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...