Added a few unit definitions to units.h
Overloaded getFloat to allow call to getFloatArray and return a vector
This commit is contained in:
parent
d9b4031614
commit
0d31b2f7a7
3 changed files with 76 additions and 2 deletions
|
|
@ -633,6 +633,22 @@ namespace ctml {
|
|||
return getFloatCurrent(node, type);
|
||||
}
|
||||
|
||||
doublereal getFloat(vector_fp& v, const Cantera::XML_Node& parent,
|
||||
const std::string &name,
|
||||
const std::string type) {
|
||||
if (!parent.hasChild(name))
|
||||
throw CanteraError("getFloat (called from XML Node \"" +
|
||||
parent.name() + "\"): ",
|
||||
"no child XML element named \"" + name + "\" exists");
|
||||
const XML_Node& node = parent.child(name);
|
||||
if (node.hasChild("floatArray")){
|
||||
getFloatArray(node, v, "true", type);
|
||||
return 0;
|
||||
}
|
||||
else{ return getFloatCurrent(node, type);
|
||||
}
|
||||
}
|
||||
|
||||
doublereal getFloatCurrent(const Cantera::XML_Node& node,
|
||||
const std::string type) {
|
||||
doublereal x, x0, x1, fctr = 1.0;
|
||||
|
|
|
|||
|
|
@ -566,6 +566,44 @@ namespace ctml {
|
|||
doublereal getFloat(const Cantera::XML_Node& parent, const std::string &name,
|
||||
const std::string type="");
|
||||
|
||||
//! Get a floating-point value from a child element.
|
||||
/*!
|
||||
* Returns a doublereal value for the child named 'name' of element 'parent'. If
|
||||
* 'type' is supplied and matches a known unit type, unit
|
||||
* conversion to SI will be done if the child element has an attribute
|
||||
* 'units'.
|
||||
*
|
||||
* Note, it's an error for the child element not to exist.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* Code snipet:
|
||||
* @verbatim
|
||||
const XML_Node &State_XMLNode;
|
||||
doublereal pres = OneAtm;
|
||||
if (state_XMLNode.hasChild("pressure")) {
|
||||
pres = getFloat(State_XMLNode, "pressure", "toSI");
|
||||
}
|
||||
@endverbatim
|
||||
*
|
||||
* reads the corresponding XML file:
|
||||
* @verbatim
|
||||
<state>
|
||||
<pressure units="Pa"> 101325.0 </pressure>
|
||||
<\state>
|
||||
@endverbatim
|
||||
*
|
||||
* @param v vector to assign with getFloatArray is XML data is in an array form
|
||||
* @param parent reference to the XML_Node object of the parent XML element
|
||||
* @param name Name of the XML child element
|
||||
* @param type String type. Currently known types are "toSI" and "actEnergy",
|
||||
* and "" , for no conversion. The default value is "",
|
||||
* which implies that no conversion is allowed.
|
||||
*/
|
||||
|
||||
doublereal getFloat(Cantera::vector_fp& v,const Cantera::XML_Node& parent, const std::string &name,
|
||||
const std::string type="toSI");
|
||||
|
||||
//! Get a floating-point value from the current XML element
|
||||
/*!
|
||||
* Returns a doublereal value from the current element. If
|
||||
|
|
|
|||
|
|
@ -182,6 +182,9 @@ namespace Cantera {
|
|||
m_act_u()
|
||||
{
|
||||
|
||||
// unity
|
||||
m_u["1"] = 1.0;
|
||||
|
||||
// length
|
||||
m_u["m"] = 1.0;
|
||||
m_u["cm"] = 0.01;
|
||||
|
|
@ -200,6 +203,9 @@ namespace Cantera {
|
|||
m_u["kcal"] = 4184.0;
|
||||
m_u["eV"] = Faraday; //1.60217733e-19;
|
||||
|
||||
// resistance
|
||||
m_u["ohm"] = 1.0;
|
||||
|
||||
// quantity
|
||||
m_u["mol"] = 1.0e-3;
|
||||
m_u["gmol"] = 1.0e-3;
|
||||
|
|
@ -213,6 +219,7 @@ namespace Cantera {
|
|||
m_u["C"] = 1.0;
|
||||
|
||||
// mass
|
||||
m_u["gm"] = 1.0e-3;
|
||||
m_u["g"] = 1.0e-3;
|
||||
m_u["kg"] = 1.0;
|
||||
|
||||
|
|
@ -227,17 +234,30 @@ namespace Cantera {
|
|||
m_u["hr"] = 3600.0;
|
||||
m_u["ms"] = 0.001;
|
||||
|
||||
// frequency
|
||||
/*// frequency
|
||||
m_u["hZ"] = 0.01/(lightSpeed);
|
||||
m_u["cm^-1"] = 1.0;
|
||||
m_u["m^-1"] = 0.1;
|
||||
m_u["cm-1"] = m_u["cm^-1"];
|
||||
m_u["m-1"] = m_u["m^-1"];
|
||||
m_u["wavenumbers"] = m_u["cm^-1"];
|
||||
m_u["wavenumbers"] = m_u["cm^-1"];*/
|
||||
|
||||
// viscosity
|
||||
m_u["Pa-s"] = 1;
|
||||
m_u["poise"] = 0.1;
|
||||
m_u["centipoise"] = 0.001;
|
||||
m_u["P"] = 0.1;
|
||||
m_u["cP"] = 0.001;
|
||||
|
||||
// volume
|
||||
m_u["kL"] = 1.0;
|
||||
m_u["liter"] = 0.001;
|
||||
m_u["L"] = 0.001;
|
||||
m_u["l"] = 0.001;
|
||||
m_u["mL"] = 1.0e-6;
|
||||
m_u["ml"] = 1.0e-6;
|
||||
m_u["cc"] = 1.0e-6;
|
||||
|
||||
|
||||
m_act_u["eV"] = m_u["eV"]; // /m_u["molec"];
|
||||
m_act_u["K"] = GasConstant;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue