Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate UEF and related metrics #197

Merged
merged 42 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
1f3f4c0
Create structures.
Jan 1, 2024
2b87503
Add UEF test.
Jan 1, 2024
d62fa56
Organize test code.
Jan 4, 2024
5defbd3
Calc additional values.
Jan 4, 2024
900107a
Calc add'l params.
Jan 4, 2024
bff4b12
Enforce DOE defn's.
Jan 6, 2024
8bd55e3
Format.
Jan 6, 2024
748761e
Fix test results.
Jan 6, 2024
6d38643
Remove variable.
Jan 6, 2024
8a1c251
Eval first-hour rating.
Jan 8, 2024
6f831fb
Modify 1st-hr rating.
Jan 9, 2024
c6e3225
Refine test.
spahrenk Jan 10, 2024
a045e8c
Format.
spahrenk Jan 10, 2024
5178988
Check if qualified.
Jan 10, 2024
bedc69c
Format.
Jan 10, 2024
f3bf0fe
Small changes.
Jan 10, 2024
1fea557
Merge main.
Jan 11, 2024
5125ff4
Improve naming.
Jan 12, 2024
f84912f
Use unordered_map.
Jan 12, 2024
dcc08c1
Improve names.
Jan 12, 2024
e8ab58c
Merge branch 'main' into calc-UEF-fnc
Jan 12, 2024
b191059
Rename fncs Average.
Jan 12, 2024
985261d
Format.
Jan 12, 2024
7dd5db5
Retain draw volume.
Feb 5, 2024
ef495ea
Enable writing output.
Feb 5, 2024
5c0890f
Has calc issue.
Feb 6, 2024
cda3c13
In progress.
Feb 6, 2024
158d1d5
For comparison.
Feb 7, 2024
2c09e4f
Record pre-test minutes.
Feb 7, 2024
e70b057
Improved calc.
Feb 8, 2024
2d054fb
Clean up.
Feb 8, 2024
505bdcb
Change test results.
Feb 8, 2024
105d010
Correct UA.
Feb 10, 2024
2d3dbbe
Fix naming and types.
Feb 10, 2024
c8896b7
Cast DRmode as int.
Feb 10, 2024
795439a
Use size_t.
Feb 10, 2024
c1d5950
Remove special chars.
Feb 12, 2024
2daeb53
Merge main.
Feb 13, 2024
9c0213c
Merge branch 'main' into calc-UEF-fnc
Feb 21, 2024
54a05c1
Merge main.
Feb 26, 2024
d7371d2
Add mesaureMetrics exe.
Feb 26, 2024
e2418c8
Remove unused var.
Feb 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,401 changes: 1,170 additions & 231 deletions src/HPWH.cc

Large diffs are not rendered by default.

193 changes: 168 additions & 25 deletions src/HPWH.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <string>
#include <sstream>
#include <fstream>
#include <cmath>
#include <iostream>
#include <iomanip>
Expand All @@ -12,6 +13,7 @@
#include <cstdio>
#include <cstdlib> //for exit
#include <vector>
#include <unordered_map>

namespace Btwxt
{
Expand Down Expand Up @@ -612,7 +614,6 @@ class HPWH
/**< Sets the tank node temps based on the provided vector of temps, which are mapped onto the
existing nodes, regardless of numNodes. */
int setTankLayerTemperatures(std::vector<double> setTemps, const UNITS units = UNITS_C);
void getTankTemps(std::vector<double>& tankTemps);

bool isSetpointFixed() const; /**< is the setpoint allowed to be changed */
int setSetpoint(double newSetpoint, UNITS units = UNITS_C); /**<default units C*/
Expand Down Expand Up @@ -747,16 +748,6 @@ class HPWH
/**< returns the index of the top node */
int getIndexTopNode() const;

double getTankNodeTemp(int nodeNum, UNITS units = UNITS_C) const;
/**< returns the temperature of the water at the specified node - with specified units
or HPWH_ABORT for incorrect node number or unit failure */

double getNthSimTcouple(int iTCouple, int nTCouple, UNITS units = UNITS_C) const;
/**< returns the temperature from a set number of virtual "thermocouples" specified by nTCouple,
which are constructed from the node temperature array. Specify iTCouple from 1-nTCouple,
1 at the bottom using specified units
returns HPWH_ABORT for iTCouple < 0, > nTCouple, or incorrect units */

int getNumHeatSources() const;
/**< returns the number of heat sources */

Expand Down Expand Up @@ -843,17 +834,6 @@ class HPWH
HEATSOURCE_TYPE getNthHeatSourceType(int N) const;
/**< returns the enum value for what type of heat source the Nth heat source is */

double getOutletTemp(UNITS units = UNITS_C) const;
/**< returns the outlet temperature in the specified units
returns 0 when no draw occurs, or HPWH_ABORT for incorrect unit specifier */
double getCondenserWaterInletTemp(UNITS units = UNITS_C) const;
/**< returns the condenser inlet temperature in the specified units
returns 0 when no HP not running occurs, or HPWH_ABORT for incorrect unit specifier */

double getCondenserWaterOutletTemp(UNITS units = UNITS_C) const;
/**< returns the condenser outlet temperature in the specified units
returns 0 when no HP not running occurs, or HPWH_ABORT for incorrect unit specifier */

double getExternalVolumeHeated(UNITS units = UNITS_L) const;
/**< returns the volume of water heated in an external in the specified units
returns 0 when no external heat source is running */
Expand Down Expand Up @@ -918,6 +898,40 @@ class HPWH
/**< resets variables for timer associated with the DR_TOT call */

double getLocationTemp_C() const;

void getTankTemps(std::vector<double>& tankTemps);

double getOutletTemp(UNITS units = UNITS_C) const;
/**< returns the outlet temperature in the specified units
returns 0 when no draw occurs, or HPWH_ABORT for incorrect unit specifier */

double getCondenserWaterInletTemp(UNITS units = UNITS_C) const;
/**< returns the condenser inlet temperature in the specified units
returns 0 when no HP not running occurs, or HPWH_ABORT for incorrect unit specifier */

double getCondenserWaterOutletTemp(UNITS units = UNITS_C) const;
/**< returns the condenser outlet temperature in the specified units
returns 0 when no HP not running occurs, or HPWH_ABORT for incorrect unit specifier */

double getTankNodeTemp(int nodeNum, UNITS units = UNITS_C) const;
/**< returns the temperature of the water at the specified node - with specified units
or HPWH_ABORT for incorrect node number or unit failure */

double getNthSimTcouple(int iTCouple, int nTCouple, UNITS units = UNITS_C) const;
/**< returns the temperature from a set number of virtual "thermocouples" specified by nTCouple,
which are constructed from the node temperature array. Specify iTCouple from 1-nTCouple,
1 at the bottom using specified units
returns HPWH_ABORT for iTCouple < 0, > nTCouple, or incorrect units */

/// returns the tank temperature averaged uniformly
double getAverageTankTemp_C() const;

/// returns the tank temperature averaged over a distribution
double getAverageTankTemp_C(const std::vector<double>& dist) const;

/// returns the tank temperature averaged using weighted logic nodes
double getAverageTankTemp_C(const std::vector<NodeWeight>& nodeWeights) const;

int setMaxTempDepression(double maxDepression, UNITS units = UNITS_C);

bool hasEnteringWaterHighTempShutOff(int heatSourceIndex);
Expand Down Expand Up @@ -963,6 +977,133 @@ class HPWH
/// Addition of extra heat handled separately from normal heat sources
void addExtraHeatAboveNode(double qAdd_kJ, const int nodeNum);

/// first-hour rating designations to determine draw pattern for 24-hr test
enum class FirstHourRatingDesig
{
VerySmall,
Low,
Medium,
High
};

struct FirstHourRating
{
FirstHourRatingDesig desig;
double drawVolume_L;
};

/// collection of information derived from standard test
struct StandardTestSummary
{
// first recovery values
double recoveryEfficiency = 0.; // eta_r
double recoveryDeliveredEnergy_kJ = 0.;
double recoveryStoredEnergy_kJ = 0.;
double recoveryUsedEnergy_kJ = 0.; // Q_r

//
double standbyPeriodTime_h = 0; // tau_stby,1

double standbyStartTankT_C = 0.; // T_su,0
double standbyEndTankT_C = 0.; // T_su,f

double standbyStartEnergy_kJ = 0.; // Q_su,0
double standbyEndEnergy_kJ = 0.; // Q_su,f
double standbyUsedEnergy_kJ = 0.; // Q_stby

double standbyHourlyLossEnergy_kJperh = 0.; // Q_hr
double standbyLossCoefficient_kJperhC = 0.; // UA

double noDrawTotalTime_h = 0; // tau_stby,2
double noDrawAverageAmbientT_C = 0.; // <T_a,stby,2>

// 24-hr values
double removedVolume_L = 0.;
double waterHeatingEnergy_kJ = 0.; // Q_HW
double avgOutletT_C = 0.; // <Tdel,i>
double avgInletT_C = 0.; // <Tin,i>

double usedFossilFuelEnergy_kJ = 0.; // Q_f
double usedElectricalEnergy_kJ = 0.; // Q_e
double usedEnergy_kJ = 0.; // Q
double consumedHeatingEnergy_kJ = 0.; // Q_d
double standardWaterHeatingEnergy_kJ = 0.; // Q_HW,T
double adjustedConsumedWaterHeatingEnergy_kJ = 0.; // Q_da
double modifiedConsumedWaterHeatingEnergy_kJ = 0.; // Q_dm
double UEF = 0.;

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

bool qualifies = false;
};

struct StandardTestOptions
{
bool saveOutput = false;
bool changeSetpoint = false;
std::ofstream outputFile;
int nTestTCouples = 6;
double setpointT_C = 51.7;
};

/// perform a draw/heat cycle to prepare for test
bool prepForTest(StandardTestOptions& standardTestOptions);

/// determine first-hour rating
bool findFirstHourRating(FirstHourRating& firstHourRating,
StandardTestOptions& standardTestOptions);

/// run 24-hr draw pattern and compute metrics
bool run24hrTest(const FirstHourRating firstHourRating,
StandardTestSummary& standardTestSummary,
StandardTestOptions& standardTestOptions);

/// specific information for a single draw
struct Draw
{
double startTime_min;
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)
{
}
};

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

static std::unordered_map<FirstHourRatingDesig, std::size_t> firstDrawClusterSizes;

/// collection of standard draw patterns
static std::unordered_map<FirstHourRatingDesig, DrawPattern> drawPatterns;

/// fields for test output to csv
struct OutputData
{
int time_min;
double ambientT_C;
double setpointT_C;
double inletT_C;
double drawVolume_L;
DRMODES drMode;
std::vector<double> h_srcIn_kWh;
std::vector<double> h_srcOut_kWh;
std::vector<double> thermocoupleT_C;
double outletT_C;
};

int writeRowAsCSV(std::ofstream& outFILE,
OutputData& outputData,
const CSVOPTIONS& options = CSVOPTIONS::CSVOPT_NONE) const;

private:
class HeatSource;

Expand All @@ -989,9 +1130,6 @@ class HPWH
/// "extra" heat added during a simulation step
double extraEnergyInput_kWh;

double tankAvg_C(const std::vector<NodeWeight> nodeWeights) const;
/**< functions to calculate what the temperature in a portion of the tank is */

/// shift temperatures of tank nodes with indices in the range [mixBottomNode, mixBelowNode)
/// by a factor mixFactor towards their average temperature
void mixTankNodes(int mixBottomNode, int mixBelowNode, double mixFactor);
Expand Down Expand Up @@ -1553,6 +1691,11 @@ inline double FT2_TO_M2(double feet2) { return (feet2 / ft2_per_m2); }
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 HPWH::DRMODES operator|(HPWH::DRMODES a, HPWH::DRMODES b)
{
return static_cast<HPWH::DRMODES>(static_cast<int>(a) | static_cast<int>(b));
Expand Down
21 changes: 3 additions & 18 deletions src/HPWHHeatSources.cc
Original file line number Diff line number Diff line change
Expand Up @@ -464,12 +464,9 @@ double HPWH::HeatSource::fractToMeetComparisonExternal() const
{
hpwh->msg("\tshutsOff logic: %s ", shutOffLogicSet[i]->description.c_str());
}

fracTemp = shutOffLogicSet[i]->getFractToMeetComparisonExternal();

frac = fracTemp < frac ? fracTemp : frac;
}

return frac;
}

Expand Down Expand Up @@ -573,24 +570,12 @@ void HPWH::HeatSource::sortPerformanceMap()

double HPWH::HeatSource::getTankTemp() const
{

std::vector<double> resampledTankTemps(getCondensitySize());
resample(resampledTankTemps, hpwh->tankTemps_C);

double tankTemp_C = 0.;

std::size_t j = 0;
for (auto& resampledNodeTemp : resampledTankTemps)
{
tankTemp_C += condensity[j] * resampledNodeTemp;
// Note that condensity is normalized.
++j;
}
double tankT_C = hpwh->getAverageTankTemp_C(condensity);
if (hpwh->hpwhVerbosity >= VRB_typical)
{
hpwh->msg("tank temp %.2lf \n", tankTemp_C);
hpwh->msg("tank temp %.2lf \n", tankT_C);
}
return tankTemp_C;
return tankT_C;
}

void HPWH::HeatSource::getCapacity(double externalT_C,
Expand Down
5 changes: 4 additions & 1 deletion src/HPWHHeatingLogics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ double HPWH::TempBasedHeatingLogic::getComparisonValue()
}
}

double HPWH::TempBasedHeatingLogic::getTankValue() { return hpwh->tankAvg_C(nodeWeights); }
double HPWH::TempBasedHeatingLogic::getTankValue()
{
return hpwh->getAverageTankTemp_C(nodeWeights);
}

int HPWH::TempBasedHeatingLogic::setDecisionPoint(double value)
{
Expand Down
11 changes: 8 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Build test tool
add_executable(testTool main.cc)

Expand All @@ -8,8 +7,6 @@ target_link_libraries(testTool PRIVATE ${libs})

target_compile_features(testTool PRIVATE cxx_std_17)

add_subdirectory(unit_tests)

# Add output directory for test results
add_custom_target(results_directory ALL COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/output")

Expand Down Expand Up @@ -343,3 +340,11 @@ endforeach (test)

#Add regression test for yearly file
add_test(NAME "RegressionTest.YearRuns" COMMAND ${CMAKE_COMMAND} -E compare_files "${CMAKE_CURRENT_BINARY_DIR}/output/DHW_YRLY.csv" "${CMAKE_CURRENT_SOURCE_DIR}/ref/DHW_YRLY.csv")

# 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)
Loading
Loading