Skip to content

Commit

Permalink
Add mesaureMetrics exe.
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Ahrenkiel authored and Phil Ahrenkiel committed Feb 26, 2024
1 parent 54a05c1 commit d7371d2
Show file tree
Hide file tree
Showing 2 changed files with 209 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,8 @@ add_test(NAME "RegressionTest.YearRuns" COMMAND ${CMAKE_COMMAND} -E compare_file

# Add unit tests
add_subdirectory(unit_tests)

# Build measureMetrics
add_executable(measureMetrics measureMetrics.cc)
target_link_libraries(measureMetrics PRIVATE ${libs})
target_compile_features(measureMetrics PRIVATE cxx_std_17)
204 changes: 204 additions & 0 deletions test/measureMetrics.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
/*
* Ultiltiy to measure HPWH performance metrics
*/

#include "HPWH.hh"

int main(int argc, char* argv[])
{
HPWH::StandardTestSummary standardTestSummary;
bool validNumArgs = false;
bool runUnitTests = false;

HPWH::StandardTestOptions standardTestOptions;
standardTestOptions.saveOutput = false;
standardTestOptions.changeSetpoint = true;
standardTestOptions.nTestTCouples = 6;
standardTestOptions.setpointT_C = 51.7;

// process command line arguments
std::string sPresetOrFile = "Preset";
std::string sModelName;
std::string sOutputDirectory;
if (argc == 2)
{
sModelName = argv[1];
validNumArgs = true;
runUnitTests = false;
}
else if (argc == 3)
{
sPresetOrFile = argv[1];
sModelName = argv[2];
validNumArgs = true;
runUnitTests = false;
}
else if (argc == 4)
{
sPresetOrFile = argv[1];
sModelName = argv[2];
sOutputDirectory = argv[3];
validNumArgs = true;
runUnitTests = false;
standardTestOptions.saveOutput = true;
}

if (!validNumArgs)
{
std::cout << "Invalid input:\n\
To determine performance metrics for a particular model spec, provide ONE, TWO, or THREE arguments:\n\
\t[model spec Type, i.e., Preset (default) or File]\n\
\t[model spec Name, i.e., Sanden80]\n\
\t[output Directory, i.e., .\\output]\n";
exit(1);
}

for (auto& c : sPresetOrFile)
{
c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
}

HPWH hpwh;
bool validModel = false;
if (sPresetOrFile == "preset")
{
if (hpwh.initPreset(sModelName) == 0)
{
validModel = true;
}
}
else
{
std::string inputFile = sModelName + ".txt";
if (hpwh.initFromFile(inputFile) == 0)
{
validModel = true;
}
}

if (!validModel)
{
std::cout << "Invalid input: Model name not found.\n";
exit(1);
}

sPresetOrFile[0] =
static_cast<char>(std::toupper(static_cast<unsigned char>(sPresetOrFile[0])));
std::cout << "Spec type: " << sPresetOrFile << "\n";
std::cout << "Model name: " << sModelName << "\n";

if (standardTestOptions.saveOutput)
{
std::string sOutputFilename = "test24hr_" + sPresetOrFile + "_" + sModelName + ".csv";

std::string sFullOutputFilename = sOutputDirectory + "/" + sOutputFilename;
standardTestOptions.outputFile.open(sFullOutputFilename.c_str(), std::ifstream::out);
if (!standardTestOptions.outputFile.is_open())
{
std::cout << "Could not open output file " << sFullOutputFilename << "\n";
exit(1);
}
std::cout << "Output file: " << sFullOutputFilename << "\n";

std::string strPreamble;
std::string sHeader = "minutes,Ta,Tsetpoint,inletT,draw,";

int csvOptions = HPWH::CSVOPT_NONE;
hpwh.WriteCSVHeading(standardTestOptions.outputFile,
sHeader.c_str(),
standardTestOptions.nTestTCouples,
csvOptions);
}

HPWH::FirstHourRating firstHourRating;
if (hpwh.findFirstHourRating(firstHourRating, standardTestOptions))
{
std::string sFirstHourRatingDesig = "";
switch (firstHourRating.desig)
{
case HPWH::FirstHourRatingDesig::VerySmall:
{
sFirstHourRatingDesig = "Very Small";
break;
}
case HPWH::FirstHourRatingDesig::Low:
{
sFirstHourRatingDesig = "Low";
break;
}
case HPWH::FirstHourRatingDesig::Medium:
{
sFirstHourRatingDesig = "Medium";
break;
}
case HPWH::FirstHourRatingDesig::High:
{
sFirstHourRatingDesig = "High";
break;
}
}
std::cout << "\tFirst-Hour Rating:\n";
std::cout << "\t\tVolume Drawn (L): " << firstHourRating.drawVolume_L << "\n";
std::cout << "\t\tDesignation: " << sFirstHourRatingDesig << "\n";

if (hpwh.run24hrTest(firstHourRating, standardTestSummary, standardTestOptions))
{

std::cout << "\t24-Hour Test Results:\n";
if (!standardTestSummary.qualifies)
{
std::cout << "\t\tDoes not qualify as consumer water heater.\n";
}

std::cout << "\t\tRecovery Efficiency: " << standardTestSummary.recoveryEfficiency
<< "\n";

std::cout << "\t\tStandby Loss Coefficient (kJ/h degC): "
<< standardTestSummary.standbyLossCoefficient_kJperhC << "\n";

std::cout << "\t\tUEF: " << standardTestSummary.UEF << "\n";

std::cout << "\t\tAverage Inlet Temperature (degC): " << standardTestSummary.avgInletT_C
<< "\n";

std::cout << "\t\tAverage Outlet Temperature (degC): "
<< standardTestSummary.avgOutletT_C << "\n";

std::cout << "\t\tTotal Volume Drawn (L): " << standardTestSummary.removedVolume_L
<< "\n";

std::cout << "\t\tDaily Water-Heating Energy Consumption (kWh): "
<< KJ_TO_KWH(standardTestSummary.waterHeatingEnergy_kJ) << "\n";

std::cout << "\t\tAdjusted Daily Water-Heating Energy Consumption (kWh): "
<< KJ_TO_KWH(standardTestSummary.adjustedConsumedWaterHeatingEnergy_kJ)
<< "\n";

std::cout << "\t\tModified Daily Water-Heating Energy Consumption (kWh): "
<< KJ_TO_KWH(standardTestSummary.modifiedConsumedWaterHeatingEnergy_kJ)
<< "\n";

std::cout << "\tAnnual Values:\n";
std::cout << "\t\tAnnual Electrical Energy Consumption (kWh): "
<< KJ_TO_KWH(standardTestSummary.annualConsumedElectricalEnergy_kJ) << "\n";

std::cout << "\t\tAnnual Energy Consumption (kWh): "
<< KJ_TO_KWH(standardTestSummary.annualConsumedEnergy_kJ) << "\n";
}
else
{
std::cout << "Unable to complete 24-hr test.\n";
}
}
else
{
std::cout << "Unable to complete first-hour rating test.\n";
}

if (standardTestOptions.saveOutput)
{
standardTestOptions.outputFile.close();
}

return 0;
}

0 comments on commit d7371d2

Please sign in to comment.