From ef441e4182c02d5376488382466eb0c7a682699a Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Thu, 14 Apr 2016 19:41:44 -0400 Subject: [PATCH] [CTML] Deprecate getFloatDefaultUnits This function is unnecessarily complicated and rarely needed. --- include/cantera/base/ctml.h | 1 + src/base/ctml.cpp | 2 ++ src/thermo/FixedChemPotSSTP.cpp | 4 ++-- src/thermo/MetalSHEelectrons.cpp | 2 +- src/thermo/MineralEQ3.cpp | 12 ++++++------ src/thermo/SpeciesThermoFactory.cpp | 12 ++++++------ src/thermo/StoichSubstance.cpp | 2 +- 7 files changed, 19 insertions(+), 16 deletions(-) diff --git a/include/cantera/base/ctml.h b/include/cantera/base/ctml.h index 07513d2b1..384d60956 100644 --- a/include/cantera/base/ctml.h +++ b/include/cantera/base/ctml.h @@ -575,6 +575,7 @@ int getInteger(const XML_Node& parent, const std::string& name); * @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. + * @deprecated Use getFloat and toSI directly. To be removed after Cantera 2.3. */ doublereal getFloatDefaultUnits(const XML_Node& parent, const std::string& name, diff --git a/src/base/ctml.cpp b/src/base/ctml.cpp index 23553cf8f..d26f6bcb4 100644 --- a/src/base/ctml.cpp +++ b/src/base/ctml.cpp @@ -237,6 +237,8 @@ doublereal getFloatDefaultUnits(const XML_Node& parent, const std::string& defaultUnits, const std::string& type) { + warn_deprecated("getFloatDefaultUnits", + "Use getFloat and toSI directly. To be removed after Cantera 2.3."); doublereal fctr = 1.0; if (defaultUnits == "") { throw CanteraError("getFloatDefaultUnits", diff --git a/src/thermo/FixedChemPotSSTP.cpp b/src/thermo/FixedChemPotSSTP.cpp index 1ac775925..a10583a9c 100644 --- a/src/thermo/FixedChemPotSSTP.cpp +++ b/src/thermo/FixedChemPotSSTP.cpp @@ -235,7 +235,7 @@ void FixedChemPotSSTP::initThermoXML(XML_Node& phaseNode, const std::string& id_ SingleSpeciesTP::initThermoXML(phaseNode, id_); if (model == "FixedChemPot") { - double val = getFloatDefaultUnits(tnode, "chemicalPotential", "J/kmol"); + double val = getFloat(tnode, "chemicalPotential", "toSI"); chemPot_ = val; } else { _updateThermo(); @@ -262,7 +262,7 @@ void FixedChemPotSSTP::setParametersFromXML(const XML_Node& eosdata) "thermo model attribute must be FixedChemPot or StoichSubstance or StoichSubstanceSSTP"); } if (model == "FixedChemPotSSTP") { - doublereal val = getFloatDefaultUnits(eosdata, "chemicalPotential", "J/kmol"); + doublereal val = getFloat(eosdata, "chemicalPotential", "toSI"); chemPot_ = val; } } diff --git a/src/thermo/MetalSHEelectrons.cpp b/src/thermo/MetalSHEelectrons.cpp index ee76c2315..397b94297 100644 --- a/src/thermo/MetalSHEelectrons.cpp +++ b/src/thermo/MetalSHEelectrons.cpp @@ -157,7 +157,7 @@ void MetalSHEelectrons::initThermoXML(XML_Node& phaseNode, const std::string& id XML_Node& tnode = phaseNode.child("thermo"); doublereal dens = 2.65E3; if (tnode.hasChild("density")) { - dens = getFloatDefaultUnits(tnode, "density", "kg/m3"); + dens = getFloat(tnode, "density", "toSI"); } setDensity(dens); SingleSpeciesTP::initThermoXML(phaseNode, id_); diff --git a/src/thermo/MineralEQ3.cpp b/src/thermo/MineralEQ3.cpp index bd78c6fc7..7f0e063ff 100644 --- a/src/thermo/MineralEQ3.cpp +++ b/src/thermo/MineralEQ3.cpp @@ -210,13 +210,13 @@ void MineralEQ3::initThermoXML(XML_Node& phaseNode, const std::string& id_) const XML_Node& MinEQ3node = xsp->child("thermo").child("MinEQ3"); m_deltaG_formation_pr_tr = - getFloatDefaultUnits(MinEQ3node, "DG0_f_Pr_Tr", "cal/gmol", "actEnergy"); + getFloat(MinEQ3node, "DG0_f_Pr_Tr", "actEnergy") / actEnergyToSI("cal/gmol"); m_deltaH_formation_pr_tr = - getFloatDefaultUnits(MinEQ3node, "DH0_f_Pr_Tr", "cal/gmol", "actEnergy"); - m_Entrop_pr_tr = getFloatDefaultUnits(MinEQ3node, "S0_Pr_Tr", "cal/gmol/K"); - m_a = getFloatDefaultUnits(MinEQ3node, "a", "cal/gmol/K"); - m_b = getFloatDefaultUnits(MinEQ3node, "b", "cal/gmol/K2"); - m_c = getFloatDefaultUnits(MinEQ3node, "c", "cal-K/gmol"); + getFloat(MinEQ3node, "DH0_f_Pr_Tr", "actEnergy") / actEnergyToSI("cal/gmol"); + m_Entrop_pr_tr = getFloat(MinEQ3node, "S0_Pr_Tr", "toSI") / toSI("cal/gmol/K"); + m_a = getFloat(MinEQ3node, "a", "toSI") / toSI("cal/gmol/K"); + m_b = getFloat(MinEQ3node, "b", "toSI") / toSI("cal/gmol/K2"); + m_c = getFloat(MinEQ3node, "c", "toSI") / toSI("cal-K/gmol"); convertDGFormation(); } diff --git a/src/thermo/SpeciesThermoFactory.cpp b/src/thermo/SpeciesThermoFactory.cpp index fc9bf5c50..0295c8106 100644 --- a/src/thermo/SpeciesThermoFactory.cpp +++ b/src/thermo/SpeciesThermoFactory.cpp @@ -158,13 +158,13 @@ SpeciesThermoInterpType* newShomateForMineralEQ3(const XML_Node& MinEQ3node) doublereal p0 = strSItoDbl(MinEQ3node["Pref"]); doublereal deltaG_formation_pr_tr = - getFloatDefaultUnits(MinEQ3node, "DG0_f_Pr_Tr", "cal/gmol", "actEnergy"); + getFloat(MinEQ3node, "DG0_f_Pr_Tr", "actEnergy") / actEnergyToSI("cal/gmol"); doublereal deltaH_formation_pr_tr = - getFloatDefaultUnits(MinEQ3node, "DH0_f_Pr_Tr", "cal/gmol", "actEnergy"); - doublereal Entrop_pr_tr = getFloatDefaultUnits(MinEQ3node, "S0_Pr_Tr", "cal/gmol/K"); - doublereal a = getFloatDefaultUnits(MinEQ3node, "a", "cal/gmol/K"); - doublereal b = getFloatDefaultUnits(MinEQ3node, "b", "cal/gmol/K2"); - doublereal c = getFloatDefaultUnits(MinEQ3node, "c", "cal-K/gmol"); + getFloat(MinEQ3node, "DH0_f_Pr_Tr", "actEnergy") / actEnergyToSI("cal/gmol"); + doublereal Entrop_pr_tr = getFloat(MinEQ3node, "S0_Pr_Tr", "toSI") / toSI("cal/gmol/K"); + doublereal a = getFloat(MinEQ3node, "a", "toSI") / toSI("cal/gmol/K"); + doublereal b = getFloat(MinEQ3node, "b", "toSI") / toSI("cal/gmol/K2"); + doublereal c = getFloat(MinEQ3node, "c", "toSI") / toSI("cal-K/gmol"); doublereal dg = deltaG_formation_pr_tr * 4.184 * 1.0E3; doublereal DHjmol = deltaH_formation_pr_tr * 1.0E3 * 4.184; doublereal fac = DHjmol - dg - 298.15 * Entrop_pr_tr * 1.0E3 * 4.184; diff --git a/src/thermo/StoichSubstance.cpp b/src/thermo/StoichSubstance.cpp index 497887583..a1c9f65b9 100644 --- a/src/thermo/StoichSubstance.cpp +++ b/src/thermo/StoichSubstance.cpp @@ -179,7 +179,7 @@ void StoichSubstance::initThermoXML(XML_Node& phaseNode, const std::string& id_) throw CanteraError("StoichSubstance::initThermoXML", "thermo model attribute must be StoichSubstance"); } - double dens = getFloatDefaultUnits(tnode, "density", "kg/m3"); + double dens = getFloat(tnode, "density", "toSI"); setDensity(dens); SingleSpeciesTP::initThermoXML(phaseNode, id_); }