diff --git a/src/HPWH.cc b/src/HPWH.cc index 95db6556..9cb5c930 100644 --- a/src/HPWH.cc +++ b/src/HPWH.cc @@ -102,6 +102,12 @@ HPWH::ConversionMap HPWH::convertL = { {std::make_pair(HPWH::L_UNITS::M, HPWH::L_UNITS::FT), &M_TO_FT}, {std::make_pair(HPWH::L_UNITS::FT, HPWH::L_UNITS::M), &FT_TO_M}}; +HPWH::ConversionMap HPWH::convertA = { + {std::make_pair(HPWH::A_UNITS::M2, HPWH::A_UNITS::M2), &ident}, + {std::make_pair(HPWH::A_UNITS::FT2, HPWH::A_UNITS::FT2), &ident}, + {std::make_pair(HPWH::A_UNITS::M2, HPWH::A_UNITS::FT2), &M2_TO_FT2}, + {std::make_pair(HPWH::A_UNITS::FT2, HPWH::A_UNITS::M2), &FT2_TO_M2}}; + HPWH::ConversionMap HPWH::convertV = { {std::make_pair(HPWH::V_UNITS::L, HPWH::V_UNITS::L), ident}, {std::make_pair(HPWH::V_UNITS::GAL, HPWH::V_UNITS::GAL), ident}, @@ -1322,15 +1328,15 @@ int HPWH::setTankSize_adjustUA(double HPWH_size, V_UNITS units /*L*/, bool force // Uses the UA before the function is called and adjusts the A part of the UA to match // the input volume given getTankSurfaceArea(). double HPWH_size_L = convert(HPWH_size, units, V_UNITS::L); - double oldA = getTankSurfaceArea(UNITS_FT2); + double oldA_ft2 = getTankSurfaceArea(A_UNITS::FT2); setTankSize(HPWH_size_L, V_UNITS::L, forceChange); - setUA(tankUA_kJperHrC / oldA * getTankSurfaceArea(UNITS_FT2), UA_UNITS::KJperHC); + setUA(tankUA_kJperHrC * getTankSurfaceArea(A_UNITS::FT2) / oldA_ft2, UA_UNITS::KJperHC); return 0; } /*static*/ double -HPWH::getTankSurfaceArea(double vol, V_UNITS volUnits /*L*/, UNITS surfAUnits /*=UNITS_FT2*/) +HPWH::getTankSurfaceArea(double vol, const V_UNITS volUnits /*L*/, const A_UNITS surfAUnits /*FT2*/) { // returns tank surface area, old defualt was in ft2 // Based off 88 insulated storage tanks currently available on the market from Sanden, @@ -1338,34 +1344,12 @@ HPWH::getTankSurfaceArea(double vol, V_UNITS volUnits /*L*/, UNITS surfAUnits /* // tankVolume_L with the assumption that the aspect ratio is the same as the outer // dimenisions of the whole unit. double radius = getTankRadius(vol, volUnits, L_UNITS::FT); - - double value = 2. * Pi * pow(radius, 2) * (ASPECTRATIO + 1.); - - if (value >= 0.) - { - if (surfAUnits == UNITS_M2) - value = FT2_TO_M2(value); - else if (surfAUnits != UNITS_FT2) - value = -1.; - } - return value; + return convert(2. * Pi * pow(radius, 2) * (ASPECTRATIO + 1.), A_UNITS::FT2, surfAUnits); } -double HPWH::getTankSurfaceArea(UNITS units /*=UNITS_FT2*/) const +double HPWH::getTankSurfaceArea(const A_UNITS units /*FT2*/) const { - // returns tank surface area, old defualt was in ft2 - // Based off 88 insulated storage tanks currently available on the market from Sanden, - // AOSmith, HTP, Rheem, and Niles. Corresponds to the inner tank with volume - // tankVolume_L with the assumption that the aspect ratio is the same as the outer - // dimenisions of the whole unit. - double value = getTankSurfaceArea(tankVolume_L, V_UNITS::L, units); - if (value < 0.) - { - if (hpwhVerbosity >= VRB_reluctant) - msg("Incorrect unit specification for getTankSurfaceArea. \n"); - value = HPWH_ABORT; - } - return value; + return getTankSurfaceArea(tankVolume_L, V_UNITS::L, units); } /*static*/ double diff --git a/src/HPWH.hh b/src/HPWH.hh index 2b3403ff..47407ece 100644 --- a/src/HPWH.hh +++ b/src/HPWH.hh @@ -262,12 +262,6 @@ class HPWH VRB_emetic = 30 /**< print all the things */ }; - enum UNITS - { - UNITS_FT2, /**< square feet */ - UNITS_M2 /**< square meters */ - }; - struct PairHash { template @@ -347,7 +341,7 @@ class HPWH /* length units and conversion */ enum class L_UNITS { - M, // meteres + M, // meters FT // feet }; static ConversionMap convertL; @@ -357,6 +351,19 @@ class HPWH return convertL[{fromUnits, toUnits}](length); } + /* area units and conversion */ + enum class A_UNITS + { + M2, // square meters + FT2 // square feet + }; + static ConversionMap convertA; + inline static double + convert(const double length, const HPWH::A_UNITS fromUnits, const HPWH::A_UNITS toUnits) + { + return convertA[{fromUnits, toUnits}](length); + } + /* volume units and conversion */ enum class V_UNITS { @@ -862,10 +869,11 @@ class HPWH /**< This sets the tank size and adjusts the UA the HPWH currently has to have the same U value but a new A. A is found via getTankSurfaceArea()*/ - double getTankSurfaceArea(UNITS units = UNITS_FT2) const; + double getTankSurfaceArea(const A_UNITS units = A_UNITS::FT2) const; - static double - getTankSurfaceArea(double vol, V_UNITS volUnits = V_UNITS::L, UNITS surfAUnits = UNITS_FT2); + static double getTankSurfaceArea(double vol, + V_UNITS volUnits = V_UNITS::L, + A_UNITS surfAUnits = A_UNITS::FT2); /**< Returns the tank surface area based off of real storage tanks*/ double getTankRadius(const L_UNITS units = L_UNITS::FT) const; @@ -1765,6 +1773,10 @@ inline double W_TO_BTUperH(const double W) { return KW_TO_BTUperH(W_TO_KW(W)); } inline double M_TO_FT(const double m) { return ft_per_m * m; } inline double FT_TO_M(const double ft) { return ft / ft_per_m; } +// area conversion +inline double M2_TO_FT2(const double m2) { return (ft_per_m * ft_per_m * m2); } +inline double FT2_TO_M2(const double ft2) { return (ft2 / ft_per_m / ft_per_m); } + // volume conversion inline double L_TO_GAL(const double L) { return gal_per_L * L; } inline double GAL_TO_L(const double gal) { return gal / gal_per_L; } @@ -1779,9 +1791,6 @@ inline double FT3_TO_GAL(const double ft3) { return L_TO_GAL(FT3_TO_L(ft3)); } inline double GPM_TO_LPS(const double gpm) { return (gpm / gal_per_L / sec_per_min); } inline double LPS_TO_GPM(const double lps) { return (gal_per_L * lps * sec_per_min); } -// area conversion -inline double FT2_TO_M2(const double ft2) { return (ft2 / ft_per_m / ft_per_m); } - // UA conversion inline double KJperHC_TO_BTUperHF(const double UA_kJperhC) { diff --git a/src/HPWHpresets.cc b/src/HPWHpresets.cc index 13295f15..c5253cff 100644 --- a/src/HPWHpresets.cc +++ b/src/HPWHpresets.cc @@ -235,7 +235,7 @@ int HPWH::HPWHinit_resTankGeneric(double tankVol_L, } // Calc UA - double SA_M2 = getTankSurfaceArea(tankVol_L, HPWH::V_UNITS::L, HPWH::UNITS_M2); + double SA_M2 = getTankSurfaceArea(tankVol_L, HPWH::V_UNITS::L, HPWH::A_UNITS::M2); double tankUA_WperK = SA_M2 / rValue_M2KperW; tankUA_kJperHrC = tankUA_WperK * 3.6; // 3.6 = 3600 S/Hr and 1/1000 kJ/J