Skip to content

Commit

Permalink
Improve temp-logic init.
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Ahrenkiel authored and Phil Ahrenkiel committed Nov 14, 2023
1 parent d33195a commit bd61016
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 147 deletions.
205 changes: 83 additions & 122 deletions src/HPWH.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1595,179 +1595,140 @@ std::shared_ptr<HPWH::SoCBasedHeatingLogic> HPWH::shutOffSoC(string desc,double
return std::make_shared<SoCBasedHeatingLogic>(desc,targetSoC,this,hystFract,tempMinUseful_C,constantMainsT,mainsT_C,std::greater<double>());
}

std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::topThird(double d) {
//-----------------------------------------------------------------------------
/// @brief Builds a vector of logic node weights referred to a fixed number of
/// nodes given by LOGIC_NODE_SIZE.
/// @param[in] bottomFraction Lower bounding fraction (0 to 1)
/// @param[in] topFraction Upper bounding fraction (0 to 1)
/// @return vector of node weights
//-----------------------------------------------------------------------------
std::vector<HPWH::NodeWeight> HPWH::getNodeWeightRange(double bottomFraction, double topFraction) {
std::vector<NodeWeight> nodeWeights;
for(int i : { 9,10,11,12 }) {
nodeWeights.emplace_back(i);
if (topFraction < bottomFraction) std::swap(bottomFraction, topFraction);
auto bottomIndex = static_cast<std::size_t>(bottomFraction * LOGIC_NODE_SIZE);
auto topIndex = static_cast<std::size_t>(topFraction * LOGIC_NODE_SIZE);
for (auto index = bottomIndex; index < topIndex; ++index) {
nodeWeights.emplace_back(static_cast<int>(index) + 1);
}
return std::make_shared<HPWH::TempBasedHeatingLogic>("top third",nodeWeights,d,this);
return nodeWeights;
}

std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::topThird_absolute(double d) {
std::vector<NodeWeight> nodeWeights;
for(auto i :{9,10,11,12}) {
nodeWeights.emplace_back(i);
}
return std::make_shared<HPWH::TempBasedHeatingLogic>("top third absolute",nodeWeights,d,this);
std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::topThird(double decisionPoint) {
std::vector<NodeWeight> nodeWeights = getNodeWeightRange(2./3., 1.);
return std::make_shared<HPWH::TempBasedHeatingLogic>("top third",nodeWeights,decisionPoint,this);
}

std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::bottomThird(double d) {
std::vector<NodeWeight> nodeWeights;
for(auto i :{1,2,3,4}) {
nodeWeights.emplace_back(i);
}
return std::make_shared<HPWH::TempBasedHeatingLogic>("bottom third",nodeWeights,d,this);
std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::topThird_absolute(double decisionPoint) {
std::vector<NodeWeight> nodeWeights = getNodeWeightRange(2./3., 1.);
return std::make_shared<HPWH::TempBasedHeatingLogic>("top third absolute",nodeWeights,decisionPoint,this);
}

std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::bottomSixth(double d) {
std::vector<NodeWeight> nodeWeights;
for(auto i :{1,2}) {
nodeWeights.emplace_back(i);
}
return std::make_shared<HPWH::TempBasedHeatingLogic>("bottom sixth",nodeWeights,d,this);
std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::bottomThird(double decisionPoint) {
std::vector<NodeWeight> nodeWeights = getNodeWeightRange(0., 1./3.);
return std::make_shared<HPWH::TempBasedHeatingLogic>("bottom third",nodeWeights,decisionPoint,this);
}

std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::bottomSixth_absolute(double d) {
std::vector<NodeWeight> nodeWeights;
for(auto i :{1,2}) {
nodeWeights.emplace_back(i);
}
return std::make_shared<HPWH::TempBasedHeatingLogic>("bottom sixth absolute",nodeWeights,d,this,true);
std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::bottomSixth(double decisionPoint) {
std::vector<NodeWeight> nodeWeights = getNodeWeightRange(0., 1./6.);
return std::make_shared<HPWH::TempBasedHeatingLogic>("bottom sixth",nodeWeights,decisionPoint,this);
}

std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::secondSixth(double d) {
std::vector<NodeWeight> nodeWeights;
for(auto i :{3,4}) {
nodeWeights.emplace_back(i);
}
return std::make_shared<HPWH::TempBasedHeatingLogic>("second sixth",nodeWeights,d,this);
std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::bottomSixth_absolute(double decisionPoint) {
std::vector<NodeWeight> nodeWeights = getNodeWeightRange(0., 1./6.);
return std::make_shared<HPWH::TempBasedHeatingLogic>("bottom sixth absolute",nodeWeights,decisionPoint,this,true);
}

std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::thirdSixth(double d) {
std::vector<NodeWeight> nodeWeights;
for(auto i :{5,6}) {
nodeWeights.emplace_back(i);
}
return std::make_shared<HPWH::TempBasedHeatingLogic>("third sixth",nodeWeights,d,this);
std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::secondSixth(double decisionPoint) {
std::vector<NodeWeight> nodeWeights = getNodeWeightRange(1./6., 2./6.);
return std::make_shared<HPWH::TempBasedHeatingLogic>("second sixth",nodeWeights,decisionPoint,this);
}

std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::fourthSixth(double d) {
std::vector<NodeWeight> nodeWeights;
for(auto i :{7,8}) {
nodeWeights.emplace_back(i);
}
return std::make_shared<HPWH::TempBasedHeatingLogic>("fourth sixth",nodeWeights,d,this);
std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::thirdSixth(double decisionPoint) {
std::vector<NodeWeight> nodeWeights = getNodeWeightRange(2./6., 3./6.);
return std::make_shared<HPWH::TempBasedHeatingLogic>("third sixth",nodeWeights,decisionPoint,this);
}

std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::fifthSixth(double d) {
std::vector<NodeWeight> nodeWeights;
for(auto i :{9,10}) {
nodeWeights.emplace_back(i);
}
return std::make_shared<HPWH::TempBasedHeatingLogic>("fifth sixth",nodeWeights,d,this);
std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::fourthSixth(double decisionPoint) {
std::vector<NodeWeight> nodeWeights = getNodeWeightRange(3./6., 4./6.);
return std::make_shared<HPWH::TempBasedHeatingLogic>("fourth sixth",nodeWeights,decisionPoint,this);
}

std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::topSixth(double d) {
std::vector<NodeWeight> nodeWeights;
for(auto i :{11,12}) {
nodeWeights.emplace_back(i);
}
return std::make_shared<HPWH::TempBasedHeatingLogic>("top sixth",nodeWeights,d,this);
std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::fifthSixth(double decisionPoint) {
std::vector<NodeWeight> nodeWeights = getNodeWeightRange(4./6., 5./6.);
return std::make_shared<HPWH::TempBasedHeatingLogic>("fifth sixth",nodeWeights,decisionPoint,this);
}

std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::topSixth(double decisionPoint) {
std::vector<NodeWeight> nodeWeights = getNodeWeightRange(5./6., 1.);
return std::make_shared<HPWH::TempBasedHeatingLogic>("top sixth",nodeWeights,decisionPoint,this);
}

std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::bottomHalf(double d) {
std::vector<NodeWeight> nodeWeights;
for(auto i :{1,2,3,4,5,6}) {
nodeWeights.emplace_back(i);
}
return std::make_shared<HPWH::TempBasedHeatingLogic>("bottom half",nodeWeights,d,this);
std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::bottomHalf(double decisionPoint) {
std::vector<NodeWeight> nodeWeights = getNodeWeightRange(0., 1./2.);
return std::make_shared<HPWH::TempBasedHeatingLogic>("bottom half",nodeWeights,decisionPoint,this);
}

std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::bottomTwelfth(double d) {
std::vector<NodeWeight> nodeWeights;
nodeWeights.emplace_back(1);
return std::make_shared<HPWH::TempBasedHeatingLogic>("bottom twelfth",nodeWeights,d,this);
std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::bottomTwelfth(double decisionPoint) {
std::vector<NodeWeight> nodeWeights = getNodeWeightRange(0., 1./12.);
return std::make_shared<HPWH::TempBasedHeatingLogic>("bottom twelfth",nodeWeights,decisionPoint,this);
}

std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::standby(double d) {
std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::standby(double decisionPoint) {
std::vector<NodeWeight> nodeWeights;
nodeWeights.emplace_back(13); // uses very top computation node
return std::make_shared<HPWH::TempBasedHeatingLogic>("standby",nodeWeights,d,this);
nodeWeights.emplace_back(LOGIC_NODE_SIZE + 1); // uses very top computation node
return std::make_shared<HPWH::TempBasedHeatingLogic>("standby",nodeWeights,decisionPoint,this);
}

std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::topNodeMaxTemp(double d) {
std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::topNodeMaxTemp(double decisionPoint) {
std::vector<NodeWeight> nodeWeights;
nodeWeights.emplace_back(13); // uses very top computation node
return std::make_shared<HPWH::TempBasedHeatingLogic>("top node",nodeWeights,d,this,true,std::greater<double>());
nodeWeights.emplace_back(LOGIC_NODE_SIZE + 1); // uses very top computation node
return std::make_shared<HPWH::TempBasedHeatingLogic>("top node",nodeWeights,decisionPoint,this,true,std::greater<double>());
}

std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::bottomNodeMaxTemp(double d,bool isEnteringWaterHighTempShutoff /*=false*/) {
std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::bottomNodeMaxTemp(double decisionPoint,bool isEnteringWaterHighTempShutoff /*=false*/) {
std::vector<NodeWeight> nodeWeights;
nodeWeights.emplace_back(0); // uses very bottom computation node
return std::make_shared<HPWH::TempBasedHeatingLogic>("bottom node",nodeWeights,d,this,true,std::greater<double>(),isEnteringWaterHighTempShutoff);
return std::make_shared<HPWH::TempBasedHeatingLogic>("bottom node",nodeWeights,decisionPoint,this,true,std::greater<double>(),isEnteringWaterHighTempShutoff);
}

std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::bottomTwelfthMaxTemp(double d) {
std::vector<NodeWeight> nodeWeights;
nodeWeights.emplace_back(1);
return std::make_shared<HPWH::TempBasedHeatingLogic>("bottom twelfth",nodeWeights,d,this,true,std::greater<double>());
std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::bottomTwelfthMaxTemp(double decisionPoint) {
std::vector<NodeWeight> nodeWeights = getNodeWeightRange(0., 1./12.);
return std::make_shared<HPWH::TempBasedHeatingLogic>("bottom twelfth",nodeWeights,decisionPoint,this,true,std::greater<double>());
}

std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::topThirdMaxTemp(double d) {
std::vector<NodeWeight> nodeWeights;
for(auto i :{9,10,11,12}) {
nodeWeights.emplace_back(i);
}
return std::make_shared<HPWH::TempBasedHeatingLogic>("top third",nodeWeights,d,this,true,std::greater<double>());
std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::topThirdMaxTemp(double decisionPoint) {
std::vector<NodeWeight> nodeWeights = getNodeWeightRange(2./3., 1.);
return std::make_shared<HPWH::TempBasedHeatingLogic>("top third",nodeWeights,decisionPoint,this,true,std::greater<double>());
}

std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::bottomSixthMaxTemp(double d) {
std::vector<NodeWeight> nodeWeights;
for(auto i :{1,2}) {
nodeWeights.emplace_back(i);
}
return std::make_shared<HPWH::TempBasedHeatingLogic>("bottom sixth",nodeWeights,d,this,true,std::greater<double>());
std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::bottomSixthMaxTemp(double decisionPoint) {
std::vector<NodeWeight> nodeWeights = getNodeWeightRange(0., 1./6.);
return std::make_shared<HPWH::TempBasedHeatingLogic>("bottom sixth",nodeWeights,decisionPoint,this,true,std::greater<double>());
}

std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::secondSixthMaxTemp(double d) {
std::vector<NodeWeight> nodeWeights;
for(auto i :{3,4}) {
nodeWeights.emplace_back(i);
}
return std::make_shared<HPWH::TempBasedHeatingLogic>("second sixth",nodeWeights,d,this,true,std::greater<double>());
std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::secondSixthMaxTemp(double decisionPoint) {
std::vector<NodeWeight> nodeWeights = getNodeWeightRange(1./6., 2./6.);
return std::make_shared<HPWH::TempBasedHeatingLogic>("second sixth",nodeWeights,decisionPoint,this,true,std::greater<double>());
}

std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::fifthSixthMaxTemp(double d) {
std::vector<NodeWeight> nodeWeights;
for(auto i :{9,10}) {
nodeWeights.emplace_back(i);
}
return std::make_shared<HPWH::TempBasedHeatingLogic>("top sixth",nodeWeights,d,this,true,std::greater<double>());
std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::fifthSixthMaxTemp(double decisionPoint) {
std::vector<NodeWeight> nodeWeights = getNodeWeightRange(4./6., 5./6.);
return std::make_shared<HPWH::TempBasedHeatingLogic>("top sixth",nodeWeights,decisionPoint,this,true,std::greater<double>());
}

std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::topSixthMaxTemp(double d) {
std::vector<NodeWeight> nodeWeights;
for(auto i :{11,12}) {
nodeWeights.emplace_back(i);
}
return std::make_shared<HPWH::TempBasedHeatingLogic>("top sixth",nodeWeights,d,this,true,std::greater<double>());
std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::topSixthMaxTemp(double decisionPoint) {
std::vector<NodeWeight> nodeWeights = getNodeWeightRange(5./6., 1.);
return std::make_shared<HPWH::TempBasedHeatingLogic>("top sixth",nodeWeights,decisionPoint,this,true,std::greater<double>());
}

std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::largeDraw(double d) {
std::vector<NodeWeight> nodeWeights;
for(auto i :{1,2,3,4}) {
nodeWeights.emplace_back(i);
}
return std::make_shared<HPWH::TempBasedHeatingLogic>("large draw",nodeWeights,d,this,true);
std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::largeDraw(double decisionPoint) {
std::vector<NodeWeight> nodeWeights = getNodeWeightRange(0., 1./4.);
return std::make_shared<HPWH::TempBasedHeatingLogic>("large draw",nodeWeights,decisionPoint,this,true);
}

std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::largerDraw(double d) {
std::vector<NodeWeight> nodeWeights;
for(auto i :{1,2,3,4,5,6}) {
nodeWeights.emplace_back(i);
}
return std::make_shared<HPWH::TempBasedHeatingLogic>("larger draw",nodeWeights,d,this,true);
std::shared_ptr<HPWH::TempBasedHeatingLogic> HPWH::largerDraw(double decisionPoint) {
std::vector<NodeWeight> nodeWeights = getNodeWeightRange(0., 1./2.);
return std::make_shared<HPWH::TempBasedHeatingLogic>("larger draw",nodeWeights,decisionPoint,this,true);
}

void HPWH::setNumNodes(const std::size_t num_nodes)
Expand Down
53 changes: 28 additions & 25 deletions src/HPWH.in.hh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public:
static const float KWATER_WpermC;
static const float CPWATER_kJperkgC;
static const int CONDENSITY_SIZE = 12; /**< this must be an integer, and only the value 12 change at your own risk */
static const int LOGIC_NODE_SIZE = 12; /**< number of logic nodes associated with temperature-based heating logic */
static const int MAXOUTSTRING = 200; /**< this is the maximum length for a debuging output string */
static const float TOL_MINVALUE; /**< any amount of heat distribution less than this is reduced to 0 this saves on computations */
static const float UNINITIALIZED_LOCATIONTEMP; /**< this is used to tell the
Expand Down Expand Up @@ -376,31 +377,31 @@ 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> topThird(double d);
std::shared_ptr<TempBasedHeatingLogic> topThird_absolute(double d);
std::shared_ptr<TempBasedHeatingLogic> bottomThird(double d);
std::shared_ptr<TempBasedHeatingLogic> bottomHalf(double d) ;
std::shared_ptr<TempBasedHeatingLogic> bottomTwelfth(double d);
std::shared_ptr<TempBasedHeatingLogic> bottomSixth(double d);
std::shared_ptr<TempBasedHeatingLogic> bottomSixth_absolute(double d);
std::shared_ptr<TempBasedHeatingLogic> secondSixth(double d);
std::shared_ptr<TempBasedHeatingLogic> thirdSixth(double d);
std::shared_ptr<TempBasedHeatingLogic> fourthSixth(double d);
std::shared_ptr<TempBasedHeatingLogic> fifthSixth(double d);
std::shared_ptr<TempBasedHeatingLogic> topSixth(double d);

std::shared_ptr<TempBasedHeatingLogic> standby(double d);
std::shared_ptr<TempBasedHeatingLogic> topNodeMaxTemp(double d);
std::shared_ptr<TempBasedHeatingLogic> bottomNodeMaxTemp(double d,bool isEnteringWaterHighTempShutoff = false);
std::shared_ptr<TempBasedHeatingLogic> bottomTwelfthMaxTemp(double d);
std::shared_ptr<TempBasedHeatingLogic> topThirdMaxTemp(double d);
std::shared_ptr<TempBasedHeatingLogic> bottomSixthMaxTemp(double d);
std::shared_ptr<TempBasedHeatingLogic> secondSixthMaxTemp(double d);
std::shared_ptr<TempBasedHeatingLogic> fifthSixthMaxTemp(double d);
std::shared_ptr<TempBasedHeatingLogic> topSixthMaxTemp(double d);

std::shared_ptr<TempBasedHeatingLogic> largeDraw(double d);
std::shared_ptr<TempBasedHeatingLogic> largerDraw(double d);
std::shared_ptr<TempBasedHeatingLogic> topThird(double decisionPoint);
std::shared_ptr<TempBasedHeatingLogic> topThird_absolute(double decisionPoint);
std::shared_ptr<TempBasedHeatingLogic> bottomThird(double decisionPoint);
std::shared_ptr<TempBasedHeatingLogic> bottomHalf(double decisionPoint) ;
std::shared_ptr<TempBasedHeatingLogic> bottomTwelfth(double decisionPoint);
std::shared_ptr<TempBasedHeatingLogic> bottomSixth(double decisionPoint);
std::shared_ptr<TempBasedHeatingLogic> bottomSixth_absolute(double decisionPoint);
std::shared_ptr<TempBasedHeatingLogic> secondSixth(double decisionPoint);
std::shared_ptr<TempBasedHeatingLogic> thirdSixth(double decisionPoint);
std::shared_ptr<TempBasedHeatingLogic> fourthSixth(double decisionPoint);
std::shared_ptr<TempBasedHeatingLogic> fifthSixth(double decisionPoint);
std::shared_ptr<TempBasedHeatingLogic> topSixth(double decisionPoint);

std::shared_ptr<TempBasedHeatingLogic> standby(double decisionPoint);
std::shared_ptr<TempBasedHeatingLogic> topNodeMaxTemp(double decisionPoint);
std::shared_ptr<TempBasedHeatingLogic> bottomNodeMaxTemp(double decisionPoint,bool isEnteringWaterHighTempShutoff = false);
std::shared_ptr<TempBasedHeatingLogic> bottomTwelfthMaxTemp(double decisionPoint);
std::shared_ptr<TempBasedHeatingLogic> topThirdMaxTemp(double decisionPoint);
std::shared_ptr<TempBasedHeatingLogic> bottomSixthMaxTemp(double decisionPoint);
std::shared_ptr<TempBasedHeatingLogic> secondSixthMaxTemp(double decisionPoint);
std::shared_ptr<TempBasedHeatingLogic> fifthSixthMaxTemp(double decisionPoint);
std::shared_ptr<TempBasedHeatingLogic> topSixthMaxTemp(double decisionPoint);

std::shared_ptr<TempBasedHeatingLogic> largeDraw(double decisionPoint);
std::shared_ptr<TempBasedHeatingLogic> largerDraw(double decisionPoint);

///this is the value that the public functions will return in case of a simulation
///destroying error
Expand Down Expand Up @@ -1002,6 +1003,8 @@ private:
/**< A map from index of an resistance element in heatSources to position in the tank, its
is sorted by height from lowest to highest*/

/// Generates a vector of logical nodes
std::vector<HPWH::NodeWeight> getNodeWeightRange(double bottomFraction,double topFraction);

}; //end of HPWH class

Expand Down

0 comments on commit bd61016

Please sign in to comment.