Skip to content

Commit 5cea9c4

Browse files
authored
Merge pull request #11348 from bigladder/Fix-10802-Divide-by-zero-in-controlCoolingSystemToSP
Fix 10802 - Divide by zero error
2 parents 6971c0f + bc6b68b commit 5cea9c4

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

src/EnergyPlus/UnitarySystem.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14130,6 +14130,7 @@ namespace UnitarySystems {
1413014130

1413114131
if (OutletHumRatLS > DesOutHumRat) {
1413214132
CycRatio = 1.0;
14133+
this->m_CoolingSpeedNum = std::max(1, this->m_CoolingSpeedNum);
1413314134

1413414135
for (int speedNum = this->m_CoolingSpeedNum; speedNum <= this->m_NumOfSpeedCooling; ++speedNum) {
1413514136
VariableSpeedCoils::SimVariableSpeedCoils(state,
@@ -14331,7 +14332,8 @@ namespace UnitarySystems {
1433114332
++this->warnIndex.m_SensPLRIter;
1433214333
ShowWarningError(state,
1433314334
format("{} - Iteration limit exceeded calculating part-load ratio for unit = {}", this->UnitType, this->Name));
14334-
ShowContinueError(state, format("Estimated part-load ratio = {:.3R}", (ReqOutput / FullOutput)));
14335+
ShowContinueError(state,
14336+
format("Estimated part-load ratio = {:.3R}", (FullOutput != 0 ? (ReqOutput / FullOutput) : PartLoadFrac)));
1433514337
ShowContinueError(state, format("Calculated part-load ratio = {:.3R}", PartLoadFrac));
1433614338
ShowContinueErrorTimeStamp(state, "The calculated part-load ratio will be used and the simulation continues. Occurrence info:");
1433714339
} else {
@@ -14345,7 +14347,9 @@ namespace UnitarySystems {
1434514347
}
1434614348
}
1434714349
} else if (SolFla == -2) {
14348-
PartLoadFrac = ReqOutput / FullOutput;
14350+
if (FullOutput != 0) {
14351+
PartLoadFrac = ReqOutput / FullOutput;
14352+
}
1434914353
if (!state.dataGlobal->WarmupFlag) {
1435014354
if (this->warnIndex.m_SensPLRFail < 1) {
1435114355
++this->warnIndex.m_SensPLRFail;
@@ -14373,7 +14377,8 @@ namespace UnitarySystems {
1437314377
++this->warnIndex.m_LatPLRIter;
1437414378
ShowWarningError(
1437514379
state, format("{} - Iteration limit exceeded calculating latent part-load ratio for unit = {}", this->UnitType, this->Name));
14376-
ShowContinueError(state, format("Estimated part-load ratio = {:.3R}", (ReqOutput / FullOutput)));
14380+
ShowContinueError(state,
14381+
format("Estimated part-load ratio = {:.3R}", (FullOutput != 0 ? (ReqOutput / FullOutput) : PartLoadFrac)));
1437714382
ShowContinueError(state, format("Calculated part-load ratio = {:.3R}", PartLoadFrac));
1437814383
ShowContinueErrorTimeStamp(state, "The calculated part-load ratio will be used and the simulation continues. Occurrence info:");
1437914384
}

tst/EnergyPlus/unit/HVACDXSystem.unit.cc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,23 @@ TEST_F(EnergyPlusFixture, VariableSpeedCoils_RHControl)
639639
EXPECT_NEAR(state->dataLoopNodes->Node(ControlNode).HumRat, state->dataLoopNodes->Node(ControlNode).HumRatMax, 0.0000001);
640640
// latent load needed to increase compressor speed to speed 4
641641
EXPECT_EQ(4, thisSys->m_CoolingSpeedNum);
642+
643+
// test for divide by zero error in controlCoolingSystemToSP
644+
thisSys->m_DesiredOutletTemp = 23.888888888888900;
645+
thisSys->m_DesiredOutletHumRat = 0.0092857142857142895;
646+
state->dataLoopNodes->Node(InletNode).MassFlowRate = 1.3840962084222401;
647+
state->dataLoopNodes->Node(InletNode).Temp = 16.566173051926114;
648+
state->dataLoopNodes->Node(InletNode).HumRat = 0.0092873376541228961;
649+
state->dataLoopNodes->Node(InletNode).HumRatMax = -999;
650+
651+
has_err_output(true);
652+
EXPECT_NO_THROW(thisSys->controlCoolingSystemToSP(*state, airLoopNum, FirstHVACIteration, HXUnitOn, CompressorOn));
653+
EXPECT_EQ(thisSys->m_CoolingPartLoadFrac, 0);
654+
std::string const expected_error =
655+
" ** Warning ** CoilSystem:Cooling:DX - sensible part-load ratio calculation failed: part-load ratio limits exceeded, for unit = DX "
656+
"COOLING COIL SYSTEM\n ** ~~~ ** Estimated part-load ratio = 0.000\n ** ~~~ ** The estimated part-load ratio will be used and "
657+
"the simulation continues. Occurrence info:\n ** ~~~ ** Environment=, at Simulation time= 00:-15 - 00:00\n";
658+
compare_err_stream(expected_error, true);
642659
}
643660

644661
TEST_F(EnergyPlusFixture, VariableSpeedCoils_LatentDegradation_Test)
@@ -1149,6 +1166,23 @@ TEST_F(EnergyPlusFixture, NewDXCoilModel_RHControl)
11491166
EXPECT_LT(outHumRat3, outHumRat1); // lower outlet humrat with multimode's alternate operating mode
11501167
EXPECT_NEAR(outHumRat1, 0.01166, 0.0001); // sensible control yields higher outlet humrat
11511168
EXPECT_NEAR(outHumRat3, 0.01119, 0.0001); // multimode control yields lower outlet humrat
1169+
1170+
// test for divide by zero error in controlCoolingSystemToSP
1171+
thisSys->m_DesiredOutletTemp = 23.888888888888900;
1172+
thisSys->m_DesiredOutletHumRat = 0.0092857142857142895;
1173+
state->dataLoopNodes->Node(InletNode).MassFlowRate = 1.3840962084222401;
1174+
state->dataLoopNodes->Node(InletNode).Temp = 16.566173051926114;
1175+
state->dataLoopNodes->Node(InletNode).HumRat = 0.0092873376541228961;
1176+
state->dataLoopNodes->Node(InletNode).HumRatMax = -999;
1177+
1178+
has_err_output(true);
1179+
EXPECT_NO_THROW(thisSys->controlCoolingSystemToSP(*state, airLoopNum, FirstHVACIteration, HXUnitOn, CompOn));
1180+
EXPECT_EQ(thisSys->m_CoolingPartLoadFrac, 0);
1181+
std::string const expected_error =
1182+
" ** Warning ** CoilSystem:Cooling:DX - sensible part-load ratio calculation failed: part-load ratio limits exceeded, for unit = DX "
1183+
"COOLING COIL SYSTEM\n ** ~~~ ** Estimated part-load ratio = 0.000\n ** ~~~ ** The estimated part-load ratio will be used and "
1184+
"the simulation continues. Occurrence info:\n ** ~~~ ** Environment=, at Simulation time= 00:-15 - 00:00\n";
1185+
compare_err_stream(expected_error, true);
11521186
}
11531187

11541188
} // namespace EnergyPlus

0 commit comments

Comments
 (0)