Skip to content

Commit

Permalink
Further protect users from mistakes in HX backward compat methods lea…
Browse files Browse the repository at this point in the history
…ding to a zero divisor
  • Loading branch information
jmarrec committed May 13, 2024
1 parent 04636b4 commit 1b8f688
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
38 changes: 30 additions & 8 deletions src/model/HeatExchangerAirToAirSensibleAndLatent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
// Remove when deprecated methods are removed
#include "../utilities/core/DeprecatedHelpers.hpp"

#include <limits>

namespace openstudio {

namespace model {
Expand Down Expand Up @@ -1026,8 +1028,13 @@ namespace model {
return setCurveAt75(*curve_, sensibleEffectivenessat75HeatingAirFlow);
}

auto tableLookup = makeTable(sensibleEffectivenessat75HeatingAirFlow, sensibleEffectivenessat100HeatingAirFlow(), model(),
fmt::format("{}_SensHeatEff", nameString()));
const auto val100 = sensibleEffectivenessat100HeatingAirFlow();
if (std::abs(val100) < std::numeric_limits<double>::min()) {
LOG_AND_THROW("Unable to set " << briefDescription()
<< "'s Sensible Effectiveness at 75 Heating Air Flow because the value at 100 is zero and would lead to a "
"Normalization divisor equal to zero.");
}
auto tableLookup = makeTable(sensibleEffectivenessat75HeatingAirFlow, val100, model(), fmt::format("{}_SensHeatEff", nameString()));
return setSensibleEffectivenessofHeatingAirFlowCurve(tableLookup);
}

Expand All @@ -1038,8 +1045,13 @@ namespace model {
return setCurveAt75(*curve_, latentEffectivenessat75HeatingAirFlow);
}

auto tableLookup =
makeTable(latentEffectivenessat75HeatingAirFlow, latentEffectivenessat100HeatingAirFlow(), model(), fmt::format("{}_LatHeatEff", nameString()));
const auto val100 = latentEffectivenessat100HeatingAirFlow();
if (std::abs(val100) < std::numeric_limits<double>::min()) {
LOG_AND_THROW("Unable to set " << briefDescription()
<< "'s Latent Effectiveness at 75 Heating Air Flow because the value at 100 is zero and would lead to a "
"Normalization divisor equal to zero.");
}
auto tableLookup = makeTable(latentEffectivenessat75HeatingAirFlow, val100, model(), fmt::format("{}_LatHeatEff", nameString()));
return setLatentEffectivenessofHeatingAirFlowCurve(tableLookup);
}

Expand All @@ -1050,8 +1062,13 @@ namespace model {
return setCurveAt75(*curve_, sensibleEffectivenessat75CoolingAirFlow);
}

auto tableLookup = makeTable(sensibleEffectivenessat75CoolingAirFlow, sensibleEffectivenessat100CoolingAirFlow(), model(),
fmt::format("{}_SensCoolEff", nameString()));
const auto val100 = sensibleEffectivenessat100CoolingAirFlow();
if (std::abs(val100) < std::numeric_limits<double>::min()) {
LOG_AND_THROW("Unable to set " << briefDescription()
<< "'s Sensible Effectiveness at 75 Cooling Air Flow because the value at 100 is zero and would lead to a "
"Normalization divisor equal to zero.");
}
auto tableLookup = makeTable(sensibleEffectivenessat75CoolingAirFlow, val100, model(), fmt::format("{}_SensCoolEff", nameString()));
return setSensibleEffectivenessofCoolingAirFlowCurve(tableLookup);
}

Expand All @@ -1062,8 +1079,13 @@ namespace model {
return setCurveAt75(*curve_, latentEffectivenessat75CoolingAirFlow);
}

auto tableLookup =
makeTable(latentEffectivenessat75CoolingAirFlow, latentEffectivenessat100CoolingAirFlow(), model(), fmt::format("{}_LatCoolEff", nameString()));
const auto val100 = latentEffectivenessat100CoolingAirFlow();
if (std::abs(val100) < std::numeric_limits<double>::min()) {
LOG_AND_THROW("Unable to set " << briefDescription()
<< "'s Latent Effectiveness at 75 Cooling Air Flow because the value at 100 is zero and would lead to a "
"Normalization divisor equal to zero.");
}
auto tableLookup = makeTable(latentEffectivenessat75CoolingAirFlow, val100, model(), fmt::format("{}_LatCoolEff", nameString()));
return setLatentEffectivenessofCoolingAirFlowCurve(tableLookup);
}

Expand Down
20 changes: 20 additions & 0 deletions src/model/test/HeatExchangerAirToAirSensibleAndLatent_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,26 @@ TEST_F(ModelFixture, HeatExchangerAirToAirSensibleAndLatent_Deprecated75Effectiv
EXPECT_TRUE(hx.setLatentEffectivenessat75CoolingAirFlow(val2));
EXPECT_DOUBLE_EQ(val2, hx.latentEffectivenessat75CoolingAirFlow());
}

// Ensure we protect users against dumb issues that lead to a normalization divisor of zero
{
// Ensure no curves assigned for now
hx.resetSensibleEffectivenessofHeatingAirFlowCurve();
hx.resetLatentEffectivenessofHeatingAirFlowCurve();
hx.resetSensibleEffectivenessofCoolingAirFlowCurve();
hx.resetLatentEffectivenessofCoolingAirFlowCurve();

// IMHO this doesn't make sense (IDD should be `\minimum> 0.0`), but the E+ IDD and OS IDD have always allowed it, so leaving it untouched
EXPECT_TRUE(hx.setSensibleEffectivenessat100HeatingAirFlow(0.0));
EXPECT_TRUE(hx.setLatentEffectivenessat100HeatingAirFlow(0.0));
EXPECT_TRUE(hx.setSensibleEffectivenessat100CoolingAirFlow(0.0));
EXPECT_TRUE(hx.setLatentEffectivenessat100CoolingAirFlow(0.0));

EXPECT_ANY_THROW(hx.setSensibleEffectivenessat75HeatingAirFlow(0.5));
EXPECT_ANY_THROW(hx.setLatentEffectivenessat75HeatingAirFlow(0.5));
EXPECT_ANY_THROW(hx.setSensibleEffectivenessat75CoolingAirFlow(0.5));
EXPECT_ANY_THROW(hx.setLatentEffectivenessat75CoolingAirFlow(0.5));
}
}

TEST_F(ModelFixture, HeatExchangerAirToAirSensibleAndLatent_assignHistoricalEffectivenessCurves) {
Expand Down

0 comments on commit 1b8f688

Please sign in to comment.