Skip to content

Commit e4c8d68

Browse files
authored
Merge pull request #227 from bigladder/make-generic-update
Make generic update
2 parents 0fab201 + dd09e5a commit e4c8d68

25 files changed

+1680
-1159
lines changed

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ set_target_properties(${PROJECT_NAME}_version_header PROPERTIES FOLDER Dependenc
1414
set(headers
1515
HPWHversion.in.hh
1616
HPWH.hh
17+
HPWHFitter.hh
1718
)
1819

1920
set(sources
@@ -22,6 +23,7 @@ set(sources
2223
HPWHHeatSources.cc
2324
HPWHHeatingLogics.cc
2425
HPWHpresets.cc
26+
HPWHFitter.cc
2527
)
2628

2729
set(library_sources

src/HPWH.cc

Lines changed: 281 additions & 560 deletions
Large diffs are not rendered by default.

src/HPWH.hh

Lines changed: 87 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -619,11 +619,11 @@ class HPWH : public Courier::Sender
619619
};
620620
void setMinutesPerStep(double newMinutesPerStep);
621621

622-
int WriteCSVHeading(std::ofstream& outFILE,
622+
int writeCSVHeading(std::ofstream& outFILE,
623623
const char* preamble = "",
624624
int nTCouples = 6,
625625
int options = CSVOPT_NONE) const;
626-
int WriteCSVRow(std::ofstream& outFILE,
626+
int writeCSVRow(std::ofstream& outFILE,
627627
const char* preamble = "",
628628
int nTCouples = 6,
629629
int options = CSVOPT_NONE) const;
@@ -999,26 +999,41 @@ class HPWH : public Courier::Sender
999999
/// first-hour rating designations to determine draw pattern for 24-hr test
10001000
struct FirstHourRating
10011001
{
1002-
enum class Desig
1002+
enum class Designation
10031003
{
10041004
VerySmall,
10051005
Low,
10061006
Medium,
10071007
High
1008-
};
1008+
} designation;
10091009

1010-
static inline std::unordered_map<Desig, std::string> sDesigMap = {
1011-
{Desig::VerySmall, "Very Small"},
1012-
{Desig::Low, "Low"},
1013-
{Desig::Medium, "Medium"},
1014-
{Desig::High, "High"}};
1010+
static inline std::unordered_map<Designation, std::string> DesignationMap = {
1011+
{Designation::VerySmall, "Very Small"},
1012+
{Designation::Low, "Low"},
1013+
{Designation::Medium, "Medium"},
1014+
{Designation::High, "High"}};
10151015

1016-
Desig desig;
10171016
double drawVolume_L;
1017+
std::string report();
10181018
};
10191019

1020-
/// collection of information derived from standard test
1021-
struct StandardTestSummary
1020+
/// fields for test output to csv
1021+
struct TestData
1022+
{
1023+
int time_min;
1024+
double ambientT_C;
1025+
double setpointT_C;
1026+
double inletT_C;
1027+
double drawVolume_L;
1028+
DRMODES drMode;
1029+
std::vector<double> h_srcIn_kWh;
1030+
std::vector<double> h_srcOut_kWh;
1031+
std::vector<double> thermocoupleT_C;
1032+
double outletT_C;
1033+
};
1034+
1035+
/// collection of information derived from standard 24-h test
1036+
struct TestSummary
10221037
{
10231038
// first recovery values
10241039
double recoveryEfficiency = 0.; // eta_r
@@ -1045,8 +1060,8 @@ class HPWH : public Courier::Sender
10451060
// 24-hr values
10461061
double removedVolume_L = 0.;
10471062
double waterHeatingEnergy_kJ = 0.; // Q_HW
1048-
double avgOutletT_C = 0.; // <Tdel,i>
1049-
double avgInletT_C = 0.; // <Tin,i>
1063+
double averageOutletT_C = 0.; // <Tdel,i>
1064+
double averageInletT_C = 0.; // <Tin,i>
10501065

10511066
double usedFossilFuelEnergy_kJ = 0.; // Q_f
10521067
double usedElectricalEnergy_kJ = 0.; // Q_e
@@ -1055,97 +1070,104 @@ class HPWH : public Courier::Sender
10551070
double standardWaterHeatingEnergy_kJ = 0.; // Q_HW,T
10561071
double adjustedConsumedWaterHeatingEnergy_kJ = 0.; // Q_da
10571072
double modifiedConsumedWaterHeatingEnergy_kJ = 0.; // Q_dm
1058-
double UEF = 0.;
1073+
double EF = 0.;
10591074

10601075
// (calculated) annual totals
10611076
double annualConsumedElectricalEnergy_kJ = 0.; // E_annual,e
10621077
double annualConsumedEnergy_kJ = 0.; // E_annual
10631078

10641079
bool qualifies = false;
1080+
1081+
std::vector<TestData> testDataSet = {};
1082+
1083+
// return a verbose string summary
1084+
std::string report();
10651085
};
10661086

1067-
struct StandardTestOptions
1087+
struct TestConfiguration
10681088
{
1069-
bool saveOutput = false;
1070-
std::string sOutputDirectory = "";
1071-
std::string sOutputFilename = "";
1072-
std::ostream* outputStream = &std::cout;
1073-
bool changeSetpoint = false;
1074-
std::ofstream outputFile;
1075-
int nTestTCouples = 6;
1076-
double setpointT_C = 51.7;
1089+
double ambientT_C;
1090+
double inletT_C;
1091+
double externalT_C;
10771092
};
10781093

1094+
static TestConfiguration testConfiguration_E50;
1095+
static TestConfiguration testConfiguration_UEF;
1096+
static TestConfiguration testConfiguration_E95;
1097+
static double testSetpointT_C;
1098+
10791099
/// perform a draw/heat cycle to prepare for test
1080-
void prepForTest(StandardTestOptions& standardTestOptions);
1100+
void prepareForTest(const TestConfiguration& test_configuration);
10811101

10821102
/// determine first-hour rating
1083-
void findFirstHourRating(FirstHourRating& firstHourRating,
1084-
StandardTestOptions& standardTestOptions);
1103+
FirstHourRating findFirstHourRating();
10851104

1086-
/// run 24-hr draw pattern and compute metrics
1087-
void run24hrTest(const FirstHourRating firstHourRating,
1088-
StandardTestSummary& standardTestSummary,
1089-
StandardTestOptions& standardTestOptions);
1105+
/// run 24-hr draw pattern
1106+
TestSummary run24hrTest(TestConfiguration testConfiguration,
1107+
FirstHourRating::Designation designation,
1108+
bool saveOutput = false);
1109+
TestSummary run24hrTest(TestConfiguration testConfiguration, bool saveOutput = false)
1110+
{
1111+
return run24hrTest(testConfiguration, findFirstHourRating().designation, saveOutput);
1112+
}
10901113

10911114
/// specific information for a single draw
10921115
struct Draw
10931116
{
10941117
double startTime_min;
10951118
double volume_L;
1096-
double flowRate_Lper_min;
1119+
double flowRate_L_per_min;
10971120

10981121
Draw(const double startTime_min_in,
10991122
const double volume_L_in,
11001123
const double flowRate_Lper_min_in)
11011124
: startTime_min(startTime_min_in)
11021125
, volume_L(volume_L_in)
1103-
, flowRate_Lper_min(flowRate_Lper_min_in)
1126+
, flowRate_L_per_min(flowRate_Lper_min_in)
11041127
{
11051128
}
11061129
};
11071130

11081131
/// sequence of draws in pattern
11091132
typedef std::vector<Draw> DrawPattern;
11101133

1111-
static std::unordered_map<FirstHourRating::Desig, std::size_t> firstDrawClusterSizes;
1134+
static std::unordered_map<FirstHourRating::Designation, std::size_t> firstDrawClusterSizes;
11121135

11131136
/// collection of standard draw patterns
1114-
static std::unordered_map<FirstHourRating::Desig, DrawPattern> drawPatterns;
1137+
static std::unordered_map<FirstHourRating::Designation, DrawPattern> drawPatterns;
11151138

1116-
/// fields for test output to csv
1117-
struct OutputData
1118-
{
1119-
int time_min;
1120-
double ambientT_C;
1121-
double setpointT_C;
1122-
double inletT_C;
1123-
double drawVolume_L;
1124-
DRMODES drMode;
1125-
std::vector<double> h_srcIn_kWh;
1126-
std::vector<double> h_srcOut_kWh;
1127-
std::vector<double> thermocoupleT_C;
1128-
double outletT_C;
1129-
};
1139+
struct Fitter;
11301140

1131-
int writeRowAsCSV(std::ofstream& outFILE,
1132-
OutputData& outputData,
1133-
const CSVOPTIONS& options = CSVOPTIONS::CSVOPT_NONE) const;
1141+
/// fit using a single configuration
1142+
TestSummary makeGenericEF(double targetEF,
1143+
TestConfiguration testConfiguration,
1144+
FirstHourRating::Designation designation);
1145+
TestSummary makeGenericEF(double targetEF, TestConfiguration testConfiguration)
1146+
{
1147+
return makeGenericEF(targetEF, testConfiguration, findFirstHourRating().designation);
1148+
}
11341149

1135-
void measureMetrics(FirstHourRating& firstHourRating,
1136-
StandardTestOptions& standardTestOptions,
1137-
StandardTestSummary& standardTestSummary);
1150+
/// fit using each of three configurations, independently
1151+
void makeGenericE50_UEF_E95(double targetE50,
1152+
double targetUEF,
1153+
double targetE95,
1154+
FirstHourRating::Designation designation);
11381155

1139-
struct CustomTestOptions
1156+
void makeGenericE50_UEF_E95(double targetE50, double targetUEF, double targetE95)
11401157
{
1141-
bool overrideFirstHourRating = false;
1142-
FirstHourRating::Desig desig = FirstHourRating::Desig::VerySmall;
1143-
} customTestOptions;
1158+
return makeGenericE50_UEF_E95(
1159+
targetE50, targetUEF, targetE95, findFirstHourRating().designation);
1160+
}
11441161

1145-
void makeGeneric(const double targetUEF);
1162+
/// fit using UEF config, then adjust E50, E95 coefficients
1163+
TestSummary makeGenericUEF(double targetUEF, FirstHourRating::Designation designation);
1164+
TestSummary makeGenericUEF(double targetUEF)
1165+
{
1166+
return makeGenericUEF(targetUEF, findFirstHourRating().designation);
1167+
}
11461168

11471169
private:
1148-
void setAllDefaults(); /**< sets all the defaults default */
1170+
void setAllDefaults(); /**< sets all the defaults */
11491171

11501172
void updateTankTemps(
11511173
double draw, double inletT_C, double ambientT_C, double inletVol2_L, double inletT2_L);
@@ -1444,16 +1466,18 @@ class HPWH::HeatSource : public Courier::Sender
14441466
void defrostDerate(double& to_derate, double airT_C);
14451467
/**< Derates the COP of a system based on the air temperature */
14461468

1447-
struct perfPoint
1469+
struct PerformancePoint
14481470
{
14491471
double T_F;
14501472
std::vector<double> inputPower_coeffs; // c0 + c1*T + c2*T*T
14511473
std::vector<double> COP_coeffs; // c0 + c1*T + c2*T*T
14521474
};
14531475

1454-
std::vector<perfPoint> perfMap;
1476+
std::vector<PerformancePoint> performanceMap;
14551477
/**< A map with input/COP quadratic curve coefficients at a given external temperature */
14561478

1479+
int getAmbientT_index(double ambientT_C);
1480+
14571481
private:
14581482
// start with a few type definitions
14591483
enum COIL_CONFIG

0 commit comments

Comments
 (0)