From bd610160d4085f7a73436cdeb223d5966239c721 Mon Sep 17 00:00:00 2001 From: Phil Ahrenkiel Date: Tue, 14 Nov 2023 16:03:11 -0700 Subject: [PATCH] Improve temp-logic init. --- src/HPWH.cc | 205 ++++++++++++++++++++----------------------------- src/HPWH.in.hh | 53 +++++++------ 2 files changed, 111 insertions(+), 147 deletions(-) diff --git a/src/HPWH.cc b/src/HPWH.cc index a9ee5112..281f6dee 100644 --- a/src/HPWH.cc +++ b/src/HPWH.cc @@ -1595,179 +1595,140 @@ std::shared_ptr HPWH::shutOffSoC(string desc,double return std::make_shared(desc,targetSoC,this,hystFract,tempMinUseful_C,constantMainsT,mainsT_C,std::greater()); } -std::shared_ptr 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::getNodeWeightRange(double bottomFraction, double topFraction) { std::vector nodeWeights; - for(int i : { 9,10,11,12 }) { - nodeWeights.emplace_back(i); + if (topFraction < bottomFraction) std::swap(bottomFraction, topFraction); + auto bottomIndex = static_cast(bottomFraction * LOGIC_NODE_SIZE); + auto topIndex = static_cast(topFraction * LOGIC_NODE_SIZE); + for (auto index = bottomIndex; index < topIndex; ++index) { + nodeWeights.emplace_back(static_cast(index) + 1); } - return std::make_shared("top third",nodeWeights,d,this); + return nodeWeights; } -std::shared_ptr HPWH::topThird_absolute(double d) { - std::vector nodeWeights; - for(auto i :{9,10,11,12}) { - nodeWeights.emplace_back(i); - } - return std::make_shared("top third absolute",nodeWeights,d,this); +std::shared_ptr HPWH::topThird(double decisionPoint) { + std::vector nodeWeights = getNodeWeightRange(2./3., 1.); + return std::make_shared("top third",nodeWeights,decisionPoint,this); } -std::shared_ptr HPWH::bottomThird(double d) { - std::vector nodeWeights; - for(auto i :{1,2,3,4}) { - nodeWeights.emplace_back(i); - } - return std::make_shared("bottom third",nodeWeights,d,this); +std::shared_ptr HPWH::topThird_absolute(double decisionPoint) { + std::vector nodeWeights = getNodeWeightRange(2./3., 1.); + return std::make_shared("top third absolute",nodeWeights,decisionPoint,this); } -std::shared_ptr HPWH::bottomSixth(double d) { - std::vector nodeWeights; - for(auto i :{1,2}) { - nodeWeights.emplace_back(i); - } - return std::make_shared("bottom sixth",nodeWeights,d,this); +std::shared_ptr HPWH::bottomThird(double decisionPoint) { + std::vector nodeWeights = getNodeWeightRange(0., 1./3.); + return std::make_shared("bottom third",nodeWeights,decisionPoint,this); } -std::shared_ptr HPWH::bottomSixth_absolute(double d) { - std::vector nodeWeights; - for(auto i :{1,2}) { - nodeWeights.emplace_back(i); - } - return std::make_shared("bottom sixth absolute",nodeWeights,d,this,true); +std::shared_ptr HPWH::bottomSixth(double decisionPoint) { + std::vector nodeWeights = getNodeWeightRange(0., 1./6.); + return std::make_shared("bottom sixth",nodeWeights,decisionPoint,this); } -std::shared_ptr HPWH::secondSixth(double d) { - std::vector nodeWeights; - for(auto i :{3,4}) { - nodeWeights.emplace_back(i); - } - return std::make_shared("second sixth",nodeWeights,d,this); +std::shared_ptr HPWH::bottomSixth_absolute(double decisionPoint) { + std::vector nodeWeights = getNodeWeightRange(0., 1./6.); + return std::make_shared("bottom sixth absolute",nodeWeights,decisionPoint,this,true); } -std::shared_ptr HPWH::thirdSixth(double d) { - std::vector nodeWeights; - for(auto i :{5,6}) { - nodeWeights.emplace_back(i); - } - return std::make_shared("third sixth",nodeWeights,d,this); +std::shared_ptr HPWH::secondSixth(double decisionPoint) { + std::vector nodeWeights = getNodeWeightRange(1./6., 2./6.); + return std::make_shared("second sixth",nodeWeights,decisionPoint,this); } -std::shared_ptr HPWH::fourthSixth(double d) { - std::vector nodeWeights; - for(auto i :{7,8}) { - nodeWeights.emplace_back(i); - } - return std::make_shared("fourth sixth",nodeWeights,d,this); +std::shared_ptr HPWH::thirdSixth(double decisionPoint) { + std::vector nodeWeights = getNodeWeightRange(2./6., 3./6.); + return std::make_shared("third sixth",nodeWeights,decisionPoint,this); } -std::shared_ptr HPWH::fifthSixth(double d) { - std::vector nodeWeights; - for(auto i :{9,10}) { - nodeWeights.emplace_back(i); - } - return std::make_shared("fifth sixth",nodeWeights,d,this); +std::shared_ptr HPWH::fourthSixth(double decisionPoint) { + std::vector nodeWeights = getNodeWeightRange(3./6., 4./6.); + return std::make_shared("fourth sixth",nodeWeights,decisionPoint,this); } -std::shared_ptr HPWH::topSixth(double d) { - std::vector nodeWeights; - for(auto i :{11,12}) { - nodeWeights.emplace_back(i); - } - return std::make_shared("top sixth",nodeWeights,d,this); +std::shared_ptr HPWH::fifthSixth(double decisionPoint) { + std::vector nodeWeights = getNodeWeightRange(4./6., 5./6.); + return std::make_shared("fifth sixth",nodeWeights,decisionPoint,this); } +std::shared_ptr HPWH::topSixth(double decisionPoint) { + std::vector nodeWeights = getNodeWeightRange(5./6., 1.); + return std::make_shared("top sixth",nodeWeights,decisionPoint,this); +} -std::shared_ptr HPWH::bottomHalf(double d) { - std::vector nodeWeights; - for(auto i :{1,2,3,4,5,6}) { - nodeWeights.emplace_back(i); - } - return std::make_shared("bottom half",nodeWeights,d,this); +std::shared_ptr HPWH::bottomHalf(double decisionPoint) { + std::vector nodeWeights = getNodeWeightRange(0., 1./2.); + return std::make_shared("bottom half",nodeWeights,decisionPoint,this); } -std::shared_ptr HPWH::bottomTwelfth(double d) { - std::vector nodeWeights; - nodeWeights.emplace_back(1); - return std::make_shared("bottom twelfth",nodeWeights,d,this); +std::shared_ptr HPWH::bottomTwelfth(double decisionPoint) { + std::vector nodeWeights = getNodeWeightRange(0., 1./12.); + return std::make_shared("bottom twelfth",nodeWeights,decisionPoint,this); } -std::shared_ptr HPWH::standby(double d) { +std::shared_ptr HPWH::standby(double decisionPoint) { std::vector nodeWeights; - nodeWeights.emplace_back(13); // uses very top computation node - return std::make_shared("standby",nodeWeights,d,this); + nodeWeights.emplace_back(LOGIC_NODE_SIZE + 1); // uses very top computation node + return std::make_shared("standby",nodeWeights,decisionPoint,this); } -std::shared_ptr HPWH::topNodeMaxTemp(double d) { +std::shared_ptr HPWH::topNodeMaxTemp(double decisionPoint) { std::vector nodeWeights; - nodeWeights.emplace_back(13); // uses very top computation node - return std::make_shared("top node",nodeWeights,d,this,true,std::greater()); + nodeWeights.emplace_back(LOGIC_NODE_SIZE + 1); // uses very top computation node + return std::make_shared("top node",nodeWeights,decisionPoint,this,true,std::greater()); } -std::shared_ptr HPWH::bottomNodeMaxTemp(double d,bool isEnteringWaterHighTempShutoff /*=false*/) { +std::shared_ptr HPWH::bottomNodeMaxTemp(double decisionPoint,bool isEnteringWaterHighTempShutoff /*=false*/) { std::vector nodeWeights; nodeWeights.emplace_back(0); // uses very bottom computation node - return std::make_shared("bottom node",nodeWeights,d,this,true,std::greater(),isEnteringWaterHighTempShutoff); + return std::make_shared("bottom node",nodeWeights,decisionPoint,this,true,std::greater(),isEnteringWaterHighTempShutoff); } -std::shared_ptr HPWH::bottomTwelfthMaxTemp(double d) { - std::vector nodeWeights; - nodeWeights.emplace_back(1); - return std::make_shared("bottom twelfth",nodeWeights,d,this,true,std::greater()); +std::shared_ptr HPWH::bottomTwelfthMaxTemp(double decisionPoint) { + std::vector nodeWeights = getNodeWeightRange(0., 1./12.); + return std::make_shared("bottom twelfth",nodeWeights,decisionPoint,this,true,std::greater()); } -std::shared_ptr HPWH::topThirdMaxTemp(double d) { - std::vector nodeWeights; - for(auto i :{9,10,11,12}) { - nodeWeights.emplace_back(i); - } - return std::make_shared("top third",nodeWeights,d,this,true,std::greater()); +std::shared_ptr HPWH::topThirdMaxTemp(double decisionPoint) { + std::vector nodeWeights = getNodeWeightRange(2./3., 1.); + return std::make_shared("top third",nodeWeights,decisionPoint,this,true,std::greater()); } -std::shared_ptr HPWH::bottomSixthMaxTemp(double d) { - std::vector nodeWeights; - for(auto i :{1,2}) { - nodeWeights.emplace_back(i); - } - return std::make_shared("bottom sixth",nodeWeights,d,this,true,std::greater()); +std::shared_ptr HPWH::bottomSixthMaxTemp(double decisionPoint) { + std::vector nodeWeights = getNodeWeightRange(0., 1./6.); + return std::make_shared("bottom sixth",nodeWeights,decisionPoint,this,true,std::greater()); } -std::shared_ptr HPWH::secondSixthMaxTemp(double d) { - std::vector nodeWeights; - for(auto i :{3,4}) { - nodeWeights.emplace_back(i); - } - return std::make_shared("second sixth",nodeWeights,d,this,true,std::greater()); +std::shared_ptr HPWH::secondSixthMaxTemp(double decisionPoint) { + std::vector nodeWeights = getNodeWeightRange(1./6., 2./6.); + return std::make_shared("second sixth",nodeWeights,decisionPoint,this,true,std::greater()); } -std::shared_ptr HPWH::fifthSixthMaxTemp(double d) { - std::vector nodeWeights; - for(auto i :{9,10}) { - nodeWeights.emplace_back(i); - } - return std::make_shared("top sixth",nodeWeights,d,this,true,std::greater()); +std::shared_ptr HPWH::fifthSixthMaxTemp(double decisionPoint) { + std::vector nodeWeights = getNodeWeightRange(4./6., 5./6.); + return std::make_shared("top sixth",nodeWeights,decisionPoint,this,true,std::greater()); } -std::shared_ptr HPWH::topSixthMaxTemp(double d) { - std::vector nodeWeights; - for(auto i :{11,12}) { - nodeWeights.emplace_back(i); - } - return std::make_shared("top sixth",nodeWeights,d,this,true,std::greater()); +std::shared_ptr HPWH::topSixthMaxTemp(double decisionPoint) { + std::vector nodeWeights = getNodeWeightRange(5./6., 1.); + return std::make_shared("top sixth",nodeWeights,decisionPoint,this,true,std::greater()); } -std::shared_ptr HPWH::largeDraw(double d) { - std::vector nodeWeights; - for(auto i :{1,2,3,4}) { - nodeWeights.emplace_back(i); - } - return std::make_shared("large draw",nodeWeights,d,this,true); +std::shared_ptr HPWH::largeDraw(double decisionPoint) { + std::vector nodeWeights = getNodeWeightRange(0., 1./4.); + return std::make_shared("large draw",nodeWeights,decisionPoint,this,true); } -std::shared_ptr HPWH::largerDraw(double d) { - std::vector nodeWeights; - for(auto i :{1,2,3,4,5,6}) { - nodeWeights.emplace_back(i); - } - return std::make_shared("larger draw",nodeWeights,d,this,true); +std::shared_ptr HPWH::largerDraw(double decisionPoint) { + std::vector nodeWeights = getNodeWeightRange(0., 1./2.); + return std::make_shared("larger draw",nodeWeights,decisionPoint,this,true); } void HPWH::setNumNodes(const std::size_t num_nodes) diff --git a/src/HPWH.in.hh b/src/HPWH.in.hh index 59bc150a..b2005922 100644 --- a/src/HPWH.in.hh +++ b/src/HPWH.in.hh @@ -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 @@ -376,31 +377,31 @@ public: std::shared_ptr turnOnSoC(std::string desc,double targetSoC,double hystFract,double tempMinUseful_C, bool constMains,double mains_C); - std::shared_ptr topThird(double d); - std::shared_ptr topThird_absolute(double d); - std::shared_ptr bottomThird(double d); - std::shared_ptr bottomHalf(double d) ; - std::shared_ptr bottomTwelfth(double d); - std::shared_ptr bottomSixth(double d); - std::shared_ptr bottomSixth_absolute(double d); - std::shared_ptr secondSixth(double d); - std::shared_ptr thirdSixth(double d); - std::shared_ptr fourthSixth(double d); - std::shared_ptr fifthSixth(double d); - std::shared_ptr topSixth(double d); - - std::shared_ptr standby(double d); - std::shared_ptr topNodeMaxTemp(double d); - std::shared_ptr bottomNodeMaxTemp(double d,bool isEnteringWaterHighTempShutoff = false); - std::shared_ptr bottomTwelfthMaxTemp(double d); - std::shared_ptr topThirdMaxTemp(double d); - std::shared_ptr bottomSixthMaxTemp(double d); - std::shared_ptr secondSixthMaxTemp(double d); - std::shared_ptr fifthSixthMaxTemp(double d); - std::shared_ptr topSixthMaxTemp(double d); - - std::shared_ptr largeDraw(double d); - std::shared_ptr largerDraw(double d); + std::shared_ptr topThird(double decisionPoint); + std::shared_ptr topThird_absolute(double decisionPoint); + std::shared_ptr bottomThird(double decisionPoint); + std::shared_ptr bottomHalf(double decisionPoint) ; + std::shared_ptr bottomTwelfth(double decisionPoint); + std::shared_ptr bottomSixth(double decisionPoint); + std::shared_ptr bottomSixth_absolute(double decisionPoint); + std::shared_ptr secondSixth(double decisionPoint); + std::shared_ptr thirdSixth(double decisionPoint); + std::shared_ptr fourthSixth(double decisionPoint); + std::shared_ptr fifthSixth(double decisionPoint); + std::shared_ptr topSixth(double decisionPoint); + + std::shared_ptr standby(double decisionPoint); + std::shared_ptr topNodeMaxTemp(double decisionPoint); + std::shared_ptr bottomNodeMaxTemp(double decisionPoint,bool isEnteringWaterHighTempShutoff = false); + std::shared_ptr bottomTwelfthMaxTemp(double decisionPoint); + std::shared_ptr topThirdMaxTemp(double decisionPoint); + std::shared_ptr bottomSixthMaxTemp(double decisionPoint); + std::shared_ptr secondSixthMaxTemp(double decisionPoint); + std::shared_ptr fifthSixthMaxTemp(double decisionPoint); + std::shared_ptr topSixthMaxTemp(double decisionPoint); + + std::shared_ptr largeDraw(double decisionPoint); + std::shared_ptr largerDraw(double decisionPoint); ///this is the value that the public functions will return in case of a simulation ///destroying error @@ -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 getNodeWeightRange(double bottomFraction,double topFraction); }; //end of HPWH class