Skip to content

Commit

Permalink
Add area units.
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Ahrenkiel authored and Phil Ahrenkiel committed Feb 22, 2024
1 parent 4c322f9 commit eae1dd3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 42 deletions.
40 changes: 12 additions & 28 deletions src/HPWH.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ HPWH::ConversionMap<HPWH::L_UNITS> 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::A_UNITS> 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::V_UNITS> 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},
Expand Down Expand Up @@ -1322,50 +1328,28 @@ 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,
// 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 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
Expand Down
35 changes: 22 additions & 13 deletions src/HPWH.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class T>
Expand Down Expand Up @@ -347,7 +341,7 @@ class HPWH
/* length units and conversion */
enum class L_UNITS
{
M, // meteres
M, // meters
FT // feet
};
static ConversionMap<L_UNITS> convertL;
Expand All @@ -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<A_UNITS> 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
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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; }
Expand All @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/HPWHpresets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit eae1dd3

Please sign in to comment.