Fix infinite loop risk: Counter never incremented in a do-while loop #11557
Fix infinite loop risk: Counter never incremented in a do-while loop #11557dareumnam wants to merge 4 commits into
Counter never incremented in a do-while loop #11557Conversation
|
|
||
| converged_20 = (std::abs(Ncomp_new - Ncomp) <= (Tolerance * Ncomp)) || (Counter >= 30); | ||
| Counter = Counter + 1; | ||
| converged_20 = (std::abs(Ncomp_new - Ncomp) <= (Tolerance * Ncomp)) || (Counter++ >= 30); |
|
Never let the chance for a simple one-line change to turn into a full refactor 🙈 ... sorry @dareumnam my bad I made a couple changes to these convergence loops to keep the convergence criteria and iteration counter separate. I also added a warning message in case they ever don't converge, though, I suspect that's likely a very low possibility given how old this is. @dareumnam pointing it back to you for a review. |
|
|
Interesting. It appears we do have a case where max iterations is being hit. ** Warning ** Check input. Pump nominal power or motor efficiency is set to 0, for pump=MAINS PRESSURE_UNIT1
+ ** Warning ** AirConditioner:VariableRefrigerantFlow "VRF HEAT PUMP":
+ ** ~~~ ** ...CalcVRFCondenser_FluidTCtrl: Iteration limit exceeded calculating heating mode compressor power, maximum iterations = 30
************* Testing Individual Branch Integrity |
|
|
@mitchute Thanks for the refactor! Really appreciate you made the same pattern in both the cooling and heating modes. |
|
Looking at develop more closely, the heating mode's loop (the one already increments |
|
Thanks @dareumnam. Sure, feel free to confirm. It may be only happening once, or during something like warmup, too. It would be good to check to see whether there's anything special going on that would cause it. |
Fair point |
|
@dareumnam it has been 28 days since this pull request was last updated. |
1 similar comment
|
@dareumnam it has been 28 days since this pull request was last updated. |
Pull request overview
Counternever incremented in ando-whileloop — infinite loop risk (HVACVariableRefrigerantFlow.cc) #11556HVACVariableRefrigerantFlow.cc, thedo-whileloop to calculateNcomphas a max iteration guardCounter >= 30, butCounteris initialized to 1 and never incremented inside the loop here.The adjacent similar block already does this correctly with
Counter = Counter + 1, this block is just missing this kind of code.|| (Counter++ >= 30)in both blocks.knownConditionTrueFalsewarning at HVACVariableRefrigerantFlow.cc:11383, where Counter >= 30 is flagged as always false.Description of the purpose of this PR
Pull Request Author
Reviewer