Skip to content

Commit

Permalink
Add length 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 36b2a68 commit 4c322f9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
25 changes: 13 additions & 12 deletions src/HPWH.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ HPWH::ConversionMap<HPWH::P_UNITS> HPWH::convertP = {
{std::make_pair(HPWH::P_UNITS::BTUperH, HPWH::P_UNITS::W), BTUperH_TO_W},
{std::make_pair(HPWH::P_UNITS::W, HPWH::P_UNITS::BTUperH), W_TO_BTUperH}};

HPWH::ConversionMap<HPWH::L_UNITS> HPWH::convertL = {
{std::make_pair(HPWH::L_UNITS::M, HPWH::L_UNITS::M), &ident},
{std::make_pair(HPWH::L_UNITS::FT, HPWH::L_UNITS::FT), &ident},
{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::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 @@ -1331,7 +1337,7 @@ HPWH::getTankSurfaceArea(double vol, V_UNITS volUnits /*L*/, UNITS surfAUnits /*
// 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, UNITS_FT);
double radius = getTankRadius(vol, volUnits, L_UNITS::FT);

double value = 2. * Pi * pow(radius, 2) * (ASPECTRATIO + 1.);

Expand Down Expand Up @@ -1363,7 +1369,7 @@ double HPWH::getTankSurfaceArea(UNITS units /*=UNITS_FT2*/) const
}

/*static*/ double
HPWH::getTankRadius(double vol, V_UNITS volUnits /*L*/, UNITS radiusUnits /*=UNITS_FT*/)
HPWH::getTankRadius(double vol, const V_UNITS volUnits /*L*/, const L_UNITS radiusUnits /*FT*/)
{ // returns tank radius, ft for use in calculation of heat loss in the bottom and top of
// the tank.
// Based off 88 insulated storage tanks currently available on the market from Sanden,
Expand All @@ -1372,27 +1378,22 @@ HPWH::getTankRadius(double vol, V_UNITS volUnits /*L*/, UNITS radiusUnits /*=UNI

double vol_ft3 = convert(vol, volUnits, V_UNITS::FT3);

double value = -1.;
double radius_ft = -1.;
if (vol_ft3 >= 0.)
{
value = pow(vol_ft3 / Pi / ASPECTRATIO, 1. / 3.);
if (radiusUnits == UNITS_M)
value = FT_TO_M(value);
else if (radiusUnits != UNITS_FT)
value = -1.;
radius_ft = convert(pow(vol_ft3 / Pi / ASPECTRATIO, 1. / 3.), L_UNITS::FT, radiusUnits);
}
return value;
return radius_ft;
}

double HPWH::getTankRadius(UNITS units /*=UNITS_FT*/) const
double HPWH::getTankRadius(const L_UNITS units /*FT*/) const
{
// returns tank radius, ft for use in calculation of heat loss in the bottom and top of
// the tank. Based off 88 insulated storage tanks currently available on the market from
// Sanden, AOSmith, HTP, Rheem, and Niles, assumes the aspect ratio for the outer
// measurements is the same is the actual tank.

double value = getTankRadius(tankVolume_L, V_UNITS::L, units);

if (value < 0.)
{
if (hpwhVerbosity >= VRB_reluctant)
Expand Down Expand Up @@ -3508,7 +3509,7 @@ void HPWH::calcSizeConstants()
// bottom node being the fraction of UA that corresponds to the top and bottom of the
// tank. The assumption is that the aspect ratio is the same for all tanks and is the
// same for the outside measurements of the unit and the inner water tank.
const double tankRad_m = getTankRadius(UNITS_M);
const double tankRad_m = getTankRadius(L_UNITS::M);
const double tankHeight_m = ASPECTRATIO * tankRad_m;

nodeVolume_L = tankVolume_L / getNumNodes();
Expand Down
29 changes: 22 additions & 7 deletions src/HPWH.hh
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,6 @@ class HPWH

enum UNITS
{
UNITS_FT, /**< feet */
UNITS_M, /**< meters */
UNITS_FT2, /**< square feet */
UNITS_M2 /**< square meters */
};
Expand Down Expand Up @@ -346,6 +344,19 @@ class HPWH
return convertP[{fromUnits, toUnits}](p);
}

/* length units and conversion */
enum class L_UNITS
{
M, // meteres
FT // feet
};
static ConversionMap<L_UNITS> convertL;
inline static double
convert(const double length, const HPWH::L_UNITS fromUnits, const HPWH::L_UNITS toUnits)
{
return convertL[{fromUnits, toUnits}](length);
}

/* volume units and conversion */
enum class V_UNITS
{
Expand Down Expand Up @@ -857,11 +868,12 @@ class HPWH
getTankSurfaceArea(double vol, V_UNITS volUnits = V_UNITS::L, UNITS surfAUnits = UNITS_FT2);

/**< Returns the tank surface area based off of real storage tanks*/
double getTankRadius(UNITS units = UNITS_FT) const;
double getTankRadius(const L_UNITS units = L_UNITS::FT) const;

/// returns the tank surface radius based off of real storage tanks
static double
getTankRadius(double vol, V_UNITS volUnits = V_UNITS::L, UNITS radiusUnits = UNITS_FT);
static double getTankRadius(double vol,
const V_UNITS volUnits = V_UNITS::L,
const L_UNITS radiusUnits = L_UNITS::FT);

/// report whether the tank size can be changed
bool isTankSizeFixed() const;
Expand Down Expand Up @@ -1749,6 +1761,10 @@ inline double W_TO_KW(const double W) { return W / 1000.; }
inline double BTUperH_TO_W(const double Btu_per_h) { return KW_TO_W(BTUperH_TO_KW(Btu_per_h)); }
inline double W_TO_BTUperH(const double W) { return KW_TO_BTUperH(W_TO_KW(W)); }

// length conversion
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; }

// 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 @@ -1763,8 +1779,7 @@ 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); }

// length conversion
inline double FT_TO_M(const double ft) { return (ft / ft_per_m); }
// area conversion
inline double FT2_TO_M2(const double ft2) { return (ft2 / ft_per_m / ft_per_m); }

// UA conversion
Expand Down

0 comments on commit 4c322f9

Please sign in to comment.