19std::string FP_Format =
"%23.15E";
22 const doublereal val,
const std::string& units,
23 const std::string& type,
const doublereal minval,
24 const doublereal maxval)
26 XML_Node& f = node.addChild(title, val, FP_Format);
34 if (minval !=
Undef) {
37 if (maxval !=
Undef) {
43 const doublereal*
const vals,
const std::string& units,
44 const std::string& type,
45 const doublereal minval,
const doublereal maxval)
48 for (
size_t i = 0; i < n; i++) {
49 v += fmt::sprintf(FP_Format, vals[i]);
52 }
else if (i > 0 && (i+1) % 3 == 0) {
58 XML_Node& f = node.addChild(
"floatArray",v);
67 if (minval !=
Undef) {
70 if (maxval !=
Undef) {
76 const doublereal*
const vals,
const std::string units,
77 const std::string type,
const doublereal minval,
78 const doublereal maxval)
81 for (
size_t i = 0; i < n; i++) {
82 v += fmt::sprintf(FP_Format, vals[i]);
85 }
else if (i > 0 && (i+1) % 3 == 0) {
91 XML_Node& f = node.addChild(name, v);
105 if (minval !=
Undef) {
108 if (maxval !=
Undef) {
114 const std::string& valueString,
115 const std::string& typeString)
117 XML_Node& f = node.addChild(
"string", valueString);
119 if (typeString !=
"") {
127 if (s && s->
parent() == &node) {
138 return parent(nameString);
142 std::string& typeString)
145 if (s && s->
name() ==
"string") {
146 valueString = s->
value();
147 typeString = s->
attrib(
"type");
155 std::map<std::string, int>& v)
157 std::vector<XML_Node*> f = node.
getChildren(
"integer");
158 for (
size_t i = 0; i < f.size(); i++) {
160 if (fi[
"min"] !=
"" && fi[
"max"] !=
"") {
167 const std::string& name,
168 const std::string& type)
171 throw CanteraError(
"getFloat (called from XML Node \"" +
172 parent.
name() +
"\"): ",
173 "no child XML element named \"" + name +
"\" exists");
181 doublereal fctr = 1.0;
183 const string& units = node[
"units"];
184 const string& vmin = node[
"min"];
185 const string& vmax = node[
"max"];
187 writelog(
"\nWarning: value "+node.
value()+
" is below lower limit of "
190 if (node[
"max"] !=
"" && x >
fpValue(vmax) +
Tiny) {
191 writelog(
"\nWarning: value "+node.
value()+
" is above upper limit of "
196 if (type ==
"actEnergy" && units !=
"") {
198 }
else if (type ==
"toSI" && units !=
"") {
200 }
else if (type ==
"temperature" && units !=
"") {
202 }
else if (type ==
"density" && units !=
"") {
204 }
else if (type ==
"pressure" && units !=
"") {
206 }
else if (type !=
"" && units !=
"") {
208 writelog(
"\nWarning: conversion toSI() was done on node value " + node.
name() +
209 "but wasn't explicitly requested. Type was \"" + type +
"\"\n");
215 const std::string& name,
217 const std::string& type)
220 fltRtn =
getFloat(parent, name, type);
227 std::string& modelName)
230 modelName = parent.
child(nodeName)[
"model"];
239 throw CanteraError(
"getInteger (called from XML Node \"" +
240 parent.
name() +
"\"): ",
241 "no child XML element named " + name);
245 const string& vmin = node[
"min"];
246 const string& vmax = node[
"max"];
247 if (vmin !=
"" && x <
intValue(vmin)) {
248 writelog(
"\nWarning: value "+node.
value()+
" is below lower limit of "
251 if (node[
"max"] !=
"" && x >
intValue(vmax)) {
252 writelog(
"\nWarning: value "+node.
value()+
" is above upper limit of "
259 const bool convert,
const std::string& unitsString,
260 const std::string& nodeName)
263 if (node.
name() != nodeName) {
265 if (ll.size() == 0) {
267 "wrong XML element type/name: was expecting "
268 + nodeName +
"but accessed " + node.
name());
280 doublereal funit = 1.0;
283 std::string units = readNode->
attrib(
"units");
284 if (units !=
"" && convert) {
285 if (unitsString ==
"actEnergy" && units !=
"") {
287 }
else if (unitsString !=
"" && units !=
"") {
292 if (readNode->
attrib(
"min") !=
"") {
295 if (readNode->
attrib(
"max") !=
"") {
299 std::string val = readNode->
value();
301 size_t icom = val.find(
',');
303 string numstr = val.substr(0,icom);
304 val = val.substr(icom+1,val.size());
316 doublereal vv = v.back();
318 writelog(
"\nWarning: value {} is below lower limit of {}.\n",
322 writelog(
"\nWarning: value {} is above upper limit of {}.\n",
326 for (
size_t n = 0; n < v.size(); n++) {
334 std::vector<std::string> v;
336 for (
size_t i = 0; i < v.size(); i++) {
337 size_t icolon = v[i].find(
":");
339 throw CanteraError(
"getMap",
"missing colon in map entry ("
342 m[v[i].substr(0,icolon)] = v[i].substr(icolon+1, v[i].size());
347 std::vector<std::string>& val)
351 int n =
static_cast<int>(v.size());
352 for (
int i = 0; i < n; i++) {
353 size_t icolon = v[i].find(
":");
355 throw CanteraError(
"getPairs",
"Missing a colon in the Pair entry ("
358 key.push_back(v[i].substr(0,icolon));
359 val.push_back(v[i].substr(icolon+1, v[i].size()));
365 const std::vector<std::string>& keyStringRow,
366 const std::vector<std::string>& keyStringCol,
367 Array2D& retnValues,
const bool convert,
368 const bool matrixSymmetric)
370 if (keyStringRow.size() > retnValues.
nRows()) {
372 "size of key1 greater than numrows");
373 }
else if (keyStringCol.size() > retnValues.
nColumns()) {
375 "size of key2 greater than num cols");
376 }
else if (matrixSymmetric && retnValues.
nRows() != retnValues.
nColumns()) {
378 "nrow != ncol for a symmetric matrix");
383 doublereal funit = 1.0;
384 if (convert && node[
"units"] !=
"") {
385 funit =
toSI(node[
"units"]);
390 for (
size_t i = 0; i < v.size(); i++) {
391 size_t icolon = v[i].find(
":");
393 throw CanteraError(
"getMatrixValues",
"Missing two colons ("
396 string key1 = v[i].substr(0,icolon);
397 string rmm = v[i].substr(icolon+1, v[i].size());
399 icolon = rmm.find(
":");
401 throw CanteraError(
"getMatrixValues",
"Missing one colon ("
405 size_t irow = find(keyStringRow.begin(), keyStringRow.end(), key1)
406 - keyStringRow.begin();
407 if (irow == keyStringRow.size()) {
408 throw CanteraError(
"getMatrixValues",
"Row not matched by string: "
412 string key2 = rmm.substr(0,icolon);
413 size_t icol = find(keyStringCol.begin(), keyStringCol.end(), key2)
414 - keyStringCol.begin();
415 if (icol == keyStringCol.size()) {
416 throw CanteraError(
"getMatrixValues",
"Col not matched by string: "
419 double dval =
fpValueCheck(rmm.substr(icolon+1, rmm.size())) * funit;
422 retnValues(irow, icol) = dval;
423 if (matrixSymmetric) {
424 retnValues(icol, irow) = dval;
Header file for class Cantera::Array2D.
A class for 2D arrays stored in column-major (Fortran-compatible) form.
size_t nRows() const
Number of rows.
size_t nColumns() const
Number of columns.
Base class for exceptions thrown by Cantera classes.
Class XML_Node is a tree-based representation of the contents of an XML file.
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.
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
std::string name() const
Returns the name of the XML node.
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.
integer int_value() const
Return the value of an XML node as a single int.
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.
void clear()
Clear the current node and everything under it.
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...
std::string value() const
Return the value of an XML node as a string.
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data.
This file contains definitions for utility functions and text for modules, inputfiles,...
void writelog(const std::string &fmt, const Args &... args)
Write a formatted message to the screen.
Namespace for the Cantera kernel.
const size_t npos
index returned by functions to indicate "no position"
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...
const double Tiny
Small number to compare differences of mole fractions against.
int intValue(const std::string &val)
Translate a string into one integer value.
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 double Undef
Fairly random number to be used to initialize variables against to see if they are subsequently defin...
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.
doublereal getFloatCurrent(const XML_Node &currXML, const std::string &type="")
Get a floating-point value from the current XML element.
doublereal getFloat(const XML_Node &parent, const std::string &name, const std::string &type="")
Get a floating-point value from a child element.
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.
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...
doublereal fpValue(const std::string &val)
Translate a string into one doublereal value.
void addFloat(XML_Node &node, const std::string &titleString, const doublereal value, const std::string &unitsString="", const std::string &typeString="", const doublereal minval=Undef, const doublereal maxval=Undef)
This function adds a child node with the name, "float", with a value consisting of a single floating ...
bool getOptionalModel(const XML_Node &parent, const std::string &nodeName, std::string &modelName)
Get an optional model name from a named child node.
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...
doublereal actEnergyToSI(const std::string &unit)
Return the conversion factor to convert activation energy unit std::string 'unit' to Kelvin.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
int getInteger(const XML_Node &parent, const std::string &name)
Get an integer value from a child element.
size_t getFloatArray(const XML_Node &node, vector_fp &v, const bool convert=true, const std::string &unitsString="", const std::string &nodeName="floatArray")
This function reads the current node or a child node of the current node with the default name,...
void getMatrixValues(const XML_Node &node, const std::vector< std::string > &keyStringRow, const std::vector< std::string > &keyStringCol, Array2D &returnValues, const bool convert=true, const bool matrixSymmetric=false)
This function interprets the value portion of an XML element as a series of "Matrix ids and entries" ...
doublereal toSI(const std::string &unit)
Return the conversion factor to convert unit std::string 'unit' to SI units.
doublereal fpValueCheck(const std::string &val)
Translate a string into one doublereal value, with error checking.
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 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(XML_Node &node, const std::string &titleString, const size_t n, const doublereal *const values, const std::string &unitsString="", const std::string &typeString="", const doublereal minval=Undef, const doublereal maxval=Undef)
This function adds a child node with the name, "floatArray", with a value consisting of a comma separ...
void addNamedFloatArray(XML_Node &parentNode, const std::string &name, const size_t n, const doublereal *const vals, const std::string units="", const std::string type="", const doublereal minval=Undef, const doublereal maxval=Undef)
This function adds a child node with the name given by the first parameter with a value consisting of...
void getIntegers(const XML_Node &node, std::map< std::string, int > &v)
Get a vector of integer values from a child element.
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...
Contains declarations for string manipulation functions within Cantera.