Skip to content

Commit

Permalink
Add UEF test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Ahrenkiel authored and Phil Ahrenkiel committed Jan 1, 2024
1 parent 1f3f4c0 commit 2b87503
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 39 deletions.
92 changes: 56 additions & 36 deletions src/HPWH.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,41 +76,45 @@ HPWH::DrawPattern HPWH::verySmallUsage = {
{HM_TO_MIN(9, 15), 3.8, 3.8},
};

HPWH::DrawPattern HPWH::lowUsage = {
{HM_TO_MIN(0, 00), 7.6, 3.8},
{HM_TO_MIN(1, 00), 3.8, 3.8},
{HM_TO_MIN(1, 05), 1.9, 3.8},
{HM_TO_MIN(1, 10), 1.9, 3.8},
{HM_TO_MIN(1, 15), 1.9, 3.8},
{HM_TO_MIN(8, 00), 3.8, 3.8},
{HM_TO_MIN(8, 15), 7.6, 3.8},
{HM_TO_MIN(9, 00), 5.7, 3.8},
{HM_TO_MIN(9, 15), 3.8, 3.8},
};

HPWH::DrawPattern HPWH::mediumUsage = {
{HM_TO_MIN(0, 00), 7.6, 3.8},
{HM_TO_MIN(1, 00), 3.8, 3.8},
{HM_TO_MIN(1, 05), 1.9, 3.8},
{HM_TO_MIN(1, 10), 1.9, 3.8},
{HM_TO_MIN(1, 15), 1.9, 3.8},
{HM_TO_MIN(8, 00), 3.8, 3.8},
{HM_TO_MIN(8, 15), 7.6, 3.8},
{HM_TO_MIN(9, 00), 5.7, 3.8},
{HM_TO_MIN(9, 15), 3.8, 3.8},
};

HPWH::DrawPattern HPWH::highUsage = {
{HM_TO_MIN(0, 00), 7.6, 3.8},
{HM_TO_MIN(1, 00), 3.8, 3.8},
{HM_TO_MIN(1, 05), 1.9, 3.8},
{HM_TO_MIN(1, 10), 1.9, 3.8},
{HM_TO_MIN(1, 15), 1.9, 3.8},
{HM_TO_MIN(8, 00), 3.8, 3.8},
{HM_TO_MIN(8, 15), 7.6, 3.8},
{HM_TO_MIN(9, 00), 5.7, 3.8},
{HM_TO_MIN(9, 15), 3.8, 3.8},
};
HPWH::DrawPattern HPWH::lowUsage = {{HM_TO_MIN(0, 00), 56.8, 6.4},
{HM_TO_MIN(0, 30), 7.6, 3.8},
{HM_TO_MIN(1, 00), 3.8, 3.8},
{HM_TO_MIN(10, 30), 22.7, 6.4},
{HM_TO_MIN(11, 30), 15.1, 6.4},
{HM_TO_MIN(12, 00), 3.8, 3.8},
{HM_TO_MIN(12, 45), 3.8, 3.8},
{HM_TO_MIN(12, 50), 3.8, 3.8},
{HM_TO_MIN(16, 15), 7.6, 3.8},
{HM_TO_MIN(16, 45), 7.6, 6.4},
{HM_TO_MIN(17, 00), 11.4, 6.4}};

HPWH::DrawPattern HPWH::mediumUsage = {{HM_TO_MIN(0, 00), 56.8, 6.4},
{HM_TO_MIN(0, 30), 7.6, 3.8},
{HM_TO_MIN(1, 40), 34.1, 6.4},
{HM_TO_MIN(10, 30), 34.1, 6.4},
{HM_TO_MIN(11, 30), 18.9, 6.4},
{HM_TO_MIN(12, 00), 3.8, 3.8},
{HM_TO_MIN(12, 45), 3.8, 3.8},
{HM_TO_MIN(12, 50), 3.8, 3.8},
{HM_TO_MIN(16, 00), 3.8, 3.8},
{HM_TO_MIN(16, 15), 7.6, 3.8},
{HM_TO_MIN(16, 45), 7.6, 6.4},
{HM_TO_MIN(17, 00), 26.5, 6.4}};

HPWH::DrawPattern HPWH::highUsage = {{HM_TO_MIN(0, 00), 102, 11.4},
{HM_TO_MIN(0, 30), 7.6, 3.8},
{HM_TO_MIN(0, 40), 3.8, 3.8},
{HM_TO_MIN(1, 40), 34.1, 6.4},
{HM_TO_MIN(10, 30), 56.8, 11.4},
{HM_TO_MIN(11, 30), 18.9, 6.4},
{HM_TO_MIN(12, 00), 3.8, 3.8},
{HM_TO_MIN(12, 45), 3.8, 3.8},
{HM_TO_MIN(12, 50), 3.8, 3.8},
{HM_TO_MIN(16, 00), 7.6, 3.8},
{HM_TO_MIN(16, 15), 7.6, 3.8},
{HM_TO_MIN(16, 30), 7.6, 6.4},
{HM_TO_MIN(16, 45), 7.6, 6.4},
{HM_TO_MIN(17, 00), 53.0, 11.4}};

//-----------------------------------------------------------------------------
/// @brief Samples a std::vector to extract a single value spanning the fractional
Expand Down Expand Up @@ -5397,7 +5401,22 @@ int HPWH::HPWHinit_file(string configFile)

HPWH::Usage HPWH::findUsageFromFirstHourRating() { return Usage::Medium; }

HPWH::Usage HPWH::findUsageFromMaximumGPM_Rating() { return Usage::Medium; }
HPWH::Usage HPWH::findUsageFromMaximumGPM_Rating()
{
if (tankVolume_L < L_TO_GAL(1.7))
{
return Usage::VerySmall;
}
else if (tankVolume_L < L_TO_GAL(2.8))
{
return Usage::Low;
}
else if (tankVolume_L < L_TO_GAL(4.))
{
return Usage::Medium;
}
return Usage::High;
}

bool HPWH::calcUEF(const Usage usage, double& UEF)
{
Expand Down Expand Up @@ -5478,6 +5497,7 @@ bool HPWH::calcUEF(const Usage usage, double& UEF)
totalEnergyConsumed_kJ += getNthHeatSourceEnergyInput(iHS, HPWH::UNITS_KJ);
}

drawnVolume_L += incrementalDrawVolume_L;
++runTime_min;
}
}
Expand Down
15 changes: 12 additions & 3 deletions src/HPWH.hh
Original file line number Diff line number Diff line change
Expand Up @@ -968,8 +968,14 @@ class HPWH
double volume_L;
double flowRate_Lper_min;

Draw(const double startTime_min_in,const double volume_L_in,const double flowRate_Lper_min_in):
startTime_min(startTime_min_in), volume_L(volume_L_in),flowRate_Lper_min(flowRate_Lper_min_in){}
Draw(const double startTime_min_in,
const double volume_L_in,
const double flowRate_Lper_min_in)
: startTime_min(startTime_min_in)
, volume_L(volume_L_in)
, flowRate_Lper_min(flowRate_Lper_min_in)
{
}
};

typedef std::vector<Draw> DrawPattern;
Expand Down Expand Up @@ -1562,7 +1568,10 @@ inline double FT2_TO_M2(double feet2) { return (feet2 / 10.7640); }
inline double MIN_TO_SEC(double minute) { return minute * sec_per_min; }
inline double MIN_TO_HR(double minute) { return minute / min_per_hr; }

inline double HM_TO_MIN(const double hours, const double minutes){return min_per_hr * hours + minutes;}
inline double HM_TO_MIN(const double hours, const double minutes)
{
return min_per_hr * hours + minutes;
}

inline HPWH::DRMODES operator|(HPWH::DRMODES a, HPWH::DRMODES b)
{
Expand Down
3 changes: 3 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ add_executable(testPerformanceMaps testPerformanceMaps.cc)
add_executable(testStateOfChargeFcts testStateOfChargeFcts.cc)
add_executable(testHeatingLogics testHeatingLogics.cc)
add_executable(testEnergyBalance testEnergyBalance.cc)
add_executable(testCalcUEF testCalcUEF.cc)

set(libs libHPWHsim ${PROJECT_NAME}_common_interface)

Expand All @@ -26,6 +27,7 @@ target_link_libraries(testPerformanceMaps PRIVATE ${libs})
target_link_libraries(testStateOfChargeFcts PRIVATE ${libs})
target_link_libraries(testHeatingLogics PRIVATE ${libs})
target_link_libraries(testEnergyBalance PRIVATE ${libs})
target_link_libraries(testCalcUEF PRIVATE ${libs})

target_compile_features(testTool PRIVATE cxx_std_17)

Expand All @@ -46,6 +48,7 @@ add_test(NAME "testPerformanceMaps" COMMAND $<TARGET_FILE:testPerformanceMaps> $
add_test(NAME "testStateOfChargeFcts" COMMAND $<TARGET_FILE:testStateOfChargeFcts> ${testArgs} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_test(NAME "testHeatingLogics" COMMAND $<TARGET_FILE:testHeatingLogics> ${testArgs} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_test(NAME "testEnergyBalance" COMMAND $<TARGET_FILE:testEnergyBalance> ${testArgs} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_test(NAME "testCalcUEF" COMMAND $<TARGET_FILE:testCalcUEF> ${testArgs} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

#add_test(NAME "testREGoesTo99C.AOSmithCAHP120" COMMAND $<TARGET_FILE:testTool> "Preset" "AOSmithCAHP120" "testREGoesTo99C"
#"${CMAKE_CURRENT_BINARY_DIR}/output" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
Expand Down
33 changes: 33 additions & 0 deletions test/testCalcUEF.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* test UEF calculation
*/
#include "HPWH.hh"
#include "testUtilityFcts.cc"

#include <string>

/* Evaluate UEF based on simulations using standard profiles */
static bool testCalcUEF(const std::string& sModelName, double& UEF)
{
HPWH hpwh;

HPWH::MODELS model = mapStringToPreset(sModelName);
if (hpwh.HPWHinit_presets(model) != 0)
{
return false;
}

return hpwh.calcUEF(hpwh.findUsageFromMaximumGPM_Rating(), UEF);
}

int main(int, char**)
{
double UEF;
ASSERTTRUE(testCalcUEF("AOSmithHPTS50", UEF));
ASSERTTRUE(cmpd(UEF, 4.4091));

ASSERTTRUE(testCalcUEF("AquaThermAire", UEF));
ASSERTTRUE(cmpd(UEF, 3.5848));

return 0;
}

0 comments on commit 2b87503

Please sign in to comment.