diff --git a/Cantera/src/base/ctml.cpp b/Cantera/src/base/ctml.cpp index 8de42e90f..09bed275f 100644 --- a/Cantera/src/base/ctml.cpp +++ b/Cantera/src/base/ctml.cpp @@ -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; diff --git a/Cantera/src/base/ctml.h b/Cantera/src/base/ctml.h index 85d6f8a3b..5ed0539f1 100644 --- a/Cantera/src/base/ctml.h +++ b/Cantera/src/base/ctml.h @@ -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 + + 101325.0 + <\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 diff --git a/Cantera/src/base/units.h b/Cantera/src/base/units.h index 9aa3a3355..25009ea12 100644 --- a/Cantera/src/base/units.h +++ b/Cantera/src/base/units.h @@ -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;