Skip to content

Commit

Permalink
Export unitary weights.
Browse files Browse the repository at this point in the history
  • Loading branch information
spahrenk committed Jan 15, 2025
1 parent 0304cee commit 53040f9
Show file tree
Hide file tree
Showing 64 changed files with 214 additions and 225 deletions.
47 changes: 23 additions & 24 deletions src/HPWH.hh
Original file line number Diff line number Diff line change
Expand Up @@ -382,48 +382,45 @@ class HPWH : public Courier::Sender
{
double height, weight;
};
struct WeightedDistribution:public std::vector<DistributionPoint>
struct WeightedDistribution : public std::vector<DistributionPoint>
{
public:

WeightedDistribution(std::vector<double> heights, std::vector<double> weights)
{
clear();
reserve(heights.size());
auto weight = weights.begin();
for(auto& height: heights)
if(weight != weights.end())
for (auto& height : heights)
if (weight != weights.end())
{
push_back({height, *weight});
++weight;
}
}
double height_range() const
{
return back().height;
}
double height_range() const { return back().height; }
double total_weight() const
{
double total = 0.;
double prevHeight = 0.;
for(auto distPoint: (*this))
for (auto distPoint : (*this))
{
double& height = distPoint.height;
double& weight = distPoint.weight;
total += weight * (height - prevHeight);
prevHeight = height;
double& height = distPoint.height;
double& weight = distPoint.weight;
total += weight * (height - prevHeight);
prevHeight = height;
}
return total;
}
double norm_height(std::size_t i) const
{
return (*this)[i].height / height_range();
}
double norm_weight(std::size_t i) const
double max_weight() const
{
return (*this)[i].weight / total_weight();
double res = 0.;
for (auto distPoint : (*this))
res = std::max(distPoint.weight, res);
return res;
}

double norm_height(std::size_t i) const { return (*this)[i].height / height_range(); }
double norm_weight(std::size_t i) const { return (*this)[i].weight / total_weight(); }
double unitary_weight(std::size_t i) const { return (*this)[i].weight / max_weight(); }
};
enum class DistributionType
{
Expand All @@ -434,12 +431,14 @@ class HPWH : public Courier::Sender

struct Distribution
{
public:
public:
DistributionType distribType;
WeightedDistribution weightedDist;
Distribution(DistributionType distribType_in = DistributionType::Weighted, WeightedDistribution weightedDist_in = {{}, {}}):
distribType(distribType_in), weightedDist(weightedDist_in )
{}
Distribution(DistributionType distribType_in = DistributionType::Weighted,
WeightedDistribution weightedDist_in = {{}, {}})
: distribType(distribType_in), weightedDist(weightedDist_in)
{
}
};

struct NodeWeight
Expand Down
20 changes: 14 additions & 6 deletions src/HPWHHeatingLogic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,30 @@ HPWH::TempBasedHeatingLogic::TempBasedHeatingLogic(std::string desc,
{
dist = {DistributionType::Weighted, {{}, {}}};
auto prev_height = 0.;
for (auto& node : n)
for (auto node = n.begin(); node != n.end(); ++node)
{
if (node.nodeNum == 0)
if (node->nodeNum == 0)
{
dist = {DistributionType::BottomOfTank, {{}, {}}};
return;
}
if (node.nodeNum == LOGIC_SIZE + 1)
if (node->nodeNum == LOGIC_SIZE + 1)
{
dist = {DistributionType::TopOfTank, {{}, {}}};
return;
}
double height_front = node.nodeNum - 1;
double height_front = node->nodeNum - 1;
if (height_front > prev_height)
dist.weightedDist.push_back({height_front, 0.});
dist.weightedDist.push_back({height_front + 1., node.weight});
while (node + 1 != n.end())
{
if ((node + 1)->weight == node->weight)
++node;
else
break;
}
height_front = node->nodeNum - 1;
dist.weightedDist.push_back({height_front + 1., node->weight});
prev_height = height_front + 1.;
}
if (prev_height < LOGIC_SIZE)
Expand Down Expand Up @@ -518,7 +526,7 @@ void HPWH::TempBasedHeatingLogic::to(
for (std::size_t i = 0; i < dist.weightedDist.size(); ++i)
{
heights.push_back(dist.weightedDist.norm_height(i));
weights.push_back(dist.weightedDist.norm_weight(i));
weights.push_back(dist.weightedDist.unitary_weight(i));
}

hpwh_data_model::heat_source_configuration_ns::WeightedDistribution wd;
Expand Down
10 changes: 5 additions & 5 deletions test/models_json/AOSmithCAHP120.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
],
"weight": [
0.0,
5.999999999999997,
1.0,
0.0
]
}
Expand All @@ -67,7 +67,7 @@
],
"weight": [
0.0,
2.9999999999999996
1.0
]
}
},
Expand Down Expand Up @@ -116,7 +116,7 @@
],
"weight": [
0.0,
6.0,
1.0,
0.0
]
}
Expand All @@ -136,7 +136,7 @@
],
"weight": [
0.0,
2.9999999999999996
1.0
]
}
},
Expand Down Expand Up @@ -701,7 +701,7 @@
],
"weight": [
0.0,
6.0,
1.0,
0.0
]
}
Expand Down
4 changes: 2 additions & 2 deletions test/models_json/AOSmithHPTS40.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
],
"weight": [
0.0,
2.9999999999999996
1.0
]
}
},
Expand Down Expand Up @@ -164,7 +164,7 @@
1.0
],
"weight": [
3.0,
1.0,
0.0
]
}
Expand Down
4 changes: 2 additions & 2 deletions test/models_json/AOSmithHPTS50.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
],
"weight": [
0.0,
2.9999999999999996
1.0
]
}
},
Expand Down Expand Up @@ -164,7 +164,7 @@
1.0
],
"weight": [
3.0,
1.0,
0.0
]
}
Expand Down
4 changes: 2 additions & 2 deletions test/models_json/AOSmithHPTS66.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
],
"weight": [
0.0,
2.9999999999999996
1.0
]
}
},
Expand Down Expand Up @@ -164,7 +164,7 @@
1.0
],
"weight": [
3.0,
1.0,
0.0
]
}
Expand Down
4 changes: 2 additions & 2 deletions test/models_json/AOSmithHPTS80.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
],
"weight": [
0.0,
2.9999999999999996
1.0
]
}
},
Expand Down Expand Up @@ -164,7 +164,7 @@
1.0
],
"weight": [
3.0,
1.0,
0.0
]
}
Expand Down
8 changes: 3 additions & 5 deletions test/models_json/AOSmithHPTU50.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,11 @@
"temperature_weight_distribution": {
"normalized_height": [
0.8333333333333334,
0.9166666666666666,
1.0
],
"weight": [
0.0,
0.5,
0.5
1.0
]
}
},
Expand Down Expand Up @@ -94,7 +92,7 @@
1.0
],
"weight": [
12.0,
1.0,
0.0
]
}
Expand Down Expand Up @@ -185,7 +183,7 @@
1.0
],
"weight": [
3.0,
1.0,
0.0
]
}
Expand Down
8 changes: 3 additions & 5 deletions test/models_json/AOSmithHPTU66.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,11 @@
"temperature_weight_distribution": {
"normalized_height": [
0.8333333333333334,
0.9166666666666666,
1.0
],
"weight": [
0.0,
0.5,
0.5
1.0
]
}
},
Expand Down Expand Up @@ -94,7 +92,7 @@
1.0
],
"weight": [
12.0,
1.0,
0.0
]
}
Expand Down Expand Up @@ -176,7 +174,7 @@
1.0
],
"weight": [
3.0,
1.0,
0.0
]
}
Expand Down
8 changes: 3 additions & 5 deletions test/models_json/AOSmithHPTU80.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,11 @@
"temperature_weight_distribution": {
"normalized_height": [
0.8333333333333334,
0.9166666666666666,
1.0
],
"weight": [
0.0,
0.5,
0.5
1.0
]
}
},
Expand Down Expand Up @@ -94,7 +92,7 @@
1.0
],
"weight": [
12.0,
1.0,
0.0
]
}
Expand Down Expand Up @@ -177,7 +175,7 @@
1.0
],
"weight": [
3.0,
1.0,
0.0
]
}
Expand Down
6 changes: 3 additions & 3 deletions test/models_json/AOSmithHPTU80_DR.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
],
"weight": [
0.0,
2.9999999999999996
1.0
]
}
},
Expand Down Expand Up @@ -91,7 +91,7 @@
1.0
],
"weight": [
12.0,
1.0,
0.0
]
}
Expand Down Expand Up @@ -168,7 +168,7 @@
1.0
],
"weight": [
3.0,
1.0,
0.0
]
}
Expand Down
6 changes: 3 additions & 3 deletions test/models_json/AOSmithPHPT60.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
],
"weight": [
0.0,
2.9999999999999996
1.0
]
}
},
Expand Down Expand Up @@ -185,7 +185,7 @@
1.0
],
"weight": [
3.0,
1.0,
0.0
]
}
Expand Down Expand Up @@ -239,7 +239,7 @@
1.0
],
"weight": [
3.0,
1.0,
0.0
]
}
Expand Down
Loading

0 comments on commit 53040f9

Please sign in to comment.