Skip to content

Commit

Permalink
Improve unit conversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Ahrenkiel authored and Phil Ahrenkiel committed Dec 12, 2023
1 parent 9348872 commit 5043494
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
21 changes: 8 additions & 13 deletions src/HPWH.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ const double HPWH::MAXOUTLET_R410A = F_TO_C(140.);
const double HPWH::MAXOUTLET_R744 = F_TO_C(190.);
const double HPWH::MINSINGLEPASSLIFT = dF_TO_dC(15.);

double makeC(const double T_F_or_C,const HPWH::UNITS units,const bool absolute){
return (units == HPWH::UNITS_C) ? T_F_or_C : (absolute ? F_TO_C(T_F_or_C) : dF_TO_dC(T_F_or_C));
}

//-----------------------------------------------------------------------------
/// @brief Samples a std::vector to extract a single value spanning the fractional
/// coordinate range from frac_begin to frac_end.
Expand Down Expand Up @@ -1732,14 +1736,10 @@ std::vector<HPWH::NodeWeight> HPWH::getNodeWeightRange(double bottomFraction, do
return nodeWeights;
}

std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::wholeTank(double decisionPoint) {
std::vector<NodeWeight> nodeWeights = getNodeWeightRange(0., 1.);
return std::make_shared<HPWH::TempBasedHeatingLogic>("whole tank",nodeWeights,decisionPoint,this);
}

std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::wholeTank_absolute(double decisionPoint) {
std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::wholeTank(double decisionPoint,const UNITS units /* = UNITS_C */, const bool absolute /* = false */) {
std::vector<NodeWeight> nodeWeights = getNodeWeightRange(0., 1.);
return std::make_shared<HPWH::TempBasedHeatingLogic>("whole tank",nodeWeights,decisionPoint,this,true);
double decisionPoint_C = makeC(decisionPoint,units,absolute);
return std::make_shared<HPWH::TempBasedHeatingLogic>("whole tank",nodeWeights,decisionPoint_C,this,absolute);
}

std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::topThird(double decisionPoint) {
Expand Down Expand Up @@ -3742,12 +3742,7 @@ int HPWH::HPWHinit_file(string configFile) {
return HPWH_ABORT;
}
if(tempString == "wholeTank") {
if (absolute) {
heatSources[heatsource].addTurnOnLogic(HPWH::wholeTank_absolute(tempDouble));
}
else {
heatSources[heatsource].addTurnOnLogic(HPWH::wholeTank(tempDouble));
}
heatSources[heatsource].addTurnOnLogic(HPWH::wholeTank(tempDouble,UNITS_C,absolute));
} else if(tempString == "topThird") {
heatSources[heatsource].addTurnOnLogic(HPWH::topThird(tempDouble));
} else if(tempString == "bottomThird") {
Expand Down
6 changes: 4 additions & 2 deletions src/HPWH.hh
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,7 @@ public:
std::shared_ptr<HPWH::SoCBasedHeatingLogic> turnOnSoC(std::string desc,double targetSoC,double hystFract,double tempMinUseful_C,
bool constMains,double mains_C);

std::shared_ptr<TempBasedHeatingLogic> wholeTank(double decisionPoint);
std::shared_ptr<TempBasedHeatingLogic> wholeTank_absolute(double decisionPoint);
std::shared_ptr<TempBasedHeatingLogic> wholeTank(double decisionPoint,const UNITS units = UNITS_C, const bool absolute = false);
std::shared_ptr<TempBasedHeatingLogic> topThird(double decisionPoint);
std::shared_ptr<TempBasedHeatingLogic> topThird_absolute(double decisionPoint);
std::shared_ptr<TempBasedHeatingLogic> bottomThird(double decisionPoint);
Expand Down Expand Up @@ -1359,6 +1358,9 @@ inline HPWH::DRMODES operator|(HPWH::DRMODES a,HPWH::DRMODES b)

template< typename T> inline bool aboutEqual(T a,T b) { return fabs(a - b) < HPWH::TOL_MINVALUE; }

/// Generate an absolute or relative temperature in degC.
double makeC(const double T_F_or_C,const HPWH::UNITS units,const bool absolute);

// resampling utility functions
double getResampledValue(const std::vector<double> &values,double beginFraction,double endFraction);
bool resample(std::vector<double> &values,const std::vector<double> &sampleValues);
Expand Down
2 changes: 1 addition & 1 deletion src/HPWHpresets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3868,7 +3868,7 @@ int HPWH::HPWHinit_presets(MODELS presetNum) {
compressor.configuration = HeatSource::CONFIG_WRAPPED;

//logic conditions
compressor.addTurnOnLogic(HPWH::wholeTank_absolute(F_TO_C(111)));
compressor.addTurnOnLogic(HPWH::wholeTank(111,UNITS_F,true));
compressor.addTurnOnLogic(HPWH::standby(dF_TO_dC(14)));

//set everything in its places
Expand Down

0 comments on commit 5043494

Please sign in to comment.