-
Notifications
You must be signed in to change notification settings - Fork 394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add convergence check for co2 and contaminant #10500
Add convergence check for co2 and contaminant #10500
Conversation
std::array<bool, 3> HVACGenContamNotConverged = {false}; // Flag to show mass flow convergence | ||
std::array<Real64, ConvergLogStackDepth> HVACGenContamDemandToSupplyTolValue = {0.0}; // Queue of convergence "results" | ||
std::array<Real64, ConvergLogStackDepth> HVACGenContamSupplyDeck1ToDemandTolValue = {0.0}; // Queue of convergence "results" | ||
std::array<Real64, ConvergLogStackDepth> HVACGenContamSupplyDeck2ToDemandTolValue = {0.0}; // Queue of convergence "results" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add more variables for CO2 and contaminant convergence check
} | ||
if (state.dataContaminantBalance->Contaminant.GenericContamSimulation) { | ||
airLoopConv.HVACGenContamNotConverged[0] = false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initialize bool variables with false
OutOfToleranceFlag = true; // Something has changed--resimulate the other side of the loop | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Convergence check for AirSystemDemandSide
airLoopConv.HVACGenContamNotConverged[1] = true; | ||
OutOfToleranceFlag = true; // Something has changed--resimulate the other side of the loop | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Convergence check for AirSystemSupplySideDeck1
airLoopConv.HVACGenContamNotConverged[2] = true; | ||
OutOfToleranceFlag = true; // Something has changed--resimulate the other side of the loop | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Convergence check for AirSystemSupplySideDeck2
src/EnergyPlus/HVACManager.cc
Outdated
HistoryTrace)); | ||
} | ||
} // Generic contaminant not converged | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provide error messages if convergence is not met.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could all this repeated stuff be put into a single function and called with an array reference or two passed in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to hold off on marking approve/reject right now. I would love to get a response about the array index comments. Honestly, when there is a check on a contam tolerance value at array index [0], and then assigning not converged[2] to a value, I cannot tell if that's right or a typo. It would be great to know how big of an effort it would be to "at least" give those zeroes, ones, and twos meaningful names through constexpr int variables. Or an enum. Or something else. If it's enormous, I won't hold this fix up for that.
} | ||
if (state.dataContaminantBalance->Contaminant.GenericContamSimulation) { | ||
airLoopConv.HVACGenContamNotConverged[1] = false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oof, I really don't like further propagating these numbers. As far as I can tell, the index in this array is based on where we are calling from? Is that actually how it works? I'm not saying we need to go in and gut things for this fix, but it's just something that I think should be cleaned up. At a minimum, shouldn't we at least have a constexpr variable for "0", "1", and "2"? And more importantly, does it make sense for these to be arrays at all? Feels more like we should have a little struct and just create 3 different variable instances of that struct. Rant over.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Myoldmopar Your understanding is correct. The index in the array represents a call-from type as DataConvergParams::CalledFrom. I also agree to have a constexpr variable for "0", "1", and "2" with clear representation. Since constexpr variable change is beyond the current issue scope, I would like to suggest to create a new issue to handle a new constexpr variable.
if (airLoopConv.HVACGenContamSupplyDeck2ToDemandTolValue[0] > DataConvergParams::HVACGenContamToler) { | ||
airLoopConv.HVACGenContamNotConverged[2] = true; | ||
OutOfToleranceFlag = true; // Something has changed--resimulate the other side of the loop | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, checking the value of variable [0] and then saying converged[2] = true. This is not easy to read and understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Myoldmopar a new constexpr variable suggested by you may address your concern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this DemandTolValue[0] is not related to the same indexing that the converged[2] was referencing? It doesn't have to be changed now, and using CalledFrom is helpful indeed.
src/EnergyPlus/HVACManager.cc
Outdated
HistoryTrace)); | ||
} | ||
} // Generic contaminant not converged | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could all this repeated stuff be put into a single function and called with an array reference or two passed in?
@Myoldmopar The convergence check for CO2 and generic contaminant mimics the convergence check for temperature and others. That is why I adopt index of the array of NotConverged as (0, 1, 2). I agree the index can be replaced by a new constexpr variable or enum. Since the change is beyond the current issue scope, it is better to have a new issue to handle the change. |
@Myoldmopar Since the index of the array represents calledFrom type, here is my suggestion for the index. It should be noted that CalledFrom is defined as enum already. Please let me know what you think. |
@Myoldmopar A function was created to handle not convergence errors in different categories, mass flow rate, humidity ratio, temperature, energy, CO2 and generic contaminant. |
A new test file was uploaded to test no convergence errors. |
@Myoldmopar The Win64-Windows-10-VisualStudio-16 — Build Failed I recompiled E+ on my local computer using Visual Studio. It is OK to generate exe files for both release and debug. Is ti possible to let me know how fix this failure? Thanks. |
@Myoldmopar It is ready for review again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm requesting changes, but I'm going to make them myself. I'll get them pushed up and wait for one more round of CI and then get this merged. Thanks @lgu1234
airLoopConv.HVACHumRatNotConverged[0] = false; | ||
airLoopConv.HVACTempNotConverged[0] = false; | ||
airLoopConv.HVACEnergyNotConverged[0] = false; | ||
airLoopConv.HVACMassFlowNotConverged[(int)CalledFrom] = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't need to be changed here, but you are welcome to do this cast one time and create a new int from it. That way the array lookup is a bit cleaner. It won't affect performance or anything, but could help readability:
int iCall = (int)calledFromEnum;
airLoopConv.HVACMassFlowNotConverged[iCall] = false;
// ...lots more uses of iCall without having (int) everywhere...
if (airLoopConv.HVACGenContamSupplyDeck2ToDemandTolValue[0] > DataConvergParams::HVACGenContamToler) { | ||
airLoopConv.HVACGenContamNotConverged[2] = true; | ||
OutOfToleranceFlag = true; // Something has changed--resimulate the other side of the loop | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this DemandTolValue[0] is not related to the same indexing that the converged[2] was referencing? It doesn't have to be changed now, and using CalledFrom is helpful indeed.
} | ||
} // energy not converged | ||
|
||
// mass flow rate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Future work: create a reference to reuse to avoid these lookups and collapse all these long lines:
auto & thisSys = state.dataConvergeParams->AirLoopConvergence(AirSysNum);
ConvergenceErrors(state,
thisSys.HVACMassFlowNotConverged,
thisSys.HVACFlowDemandToSupplyTolValue,
thisSys.HVACFlowSupplyDeck1ToDemandTolValue,
thisSys.HVACFlowSupplyDeck2ToDemandTolValue,
AirSysNum,
1);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Myoldmopar I tried to use references for all arrays and was unable to pass compile.
src/EnergyPlus/HVACManager.cc
Outdated
if (index == 3) CaseName = "temperature"; | ||
if (index == 4) CaseName = "energy"; | ||
if (index == 5) CaseName = "CO2"; | ||
if (index == 6) CaseName = "generic contaminant"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oooh this should be a constexpr array of strings. I'm going to stop short of requiring it here, but this should just be a lookup.
src/EnergyPlus/HVACManager.cc
Outdated
std::array<bool, 3> HVACNotConverged, | ||
std::array<Real64, 10> DemandToSupply, | ||
std::array<Real64, 10> SupplyDeck1ToDemand, | ||
std::array<Real64, 10> SupplyDeck2ToDemand, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmmm... are these going to be copied? This is something that might actually have to be changed. @lgu1234 I will likely make a pass at cleaning this up and maybe touch some of the other random notes I've made here.
Alright, I addressed my own comments and it should be ready. I'll let CI confirm things, but then this should be ready for merge. |
@Myoldmopar Your changes are better. Thanks. |
I ran a quick local test with develop, still happy, let's merge. Thanks @lgu1234 |
Pull request overview
The convergence check for CO2 and generic contaminant was added based on decision in the issue.
The differences are found in the test file, located in EnergyPlusDevSupport.
NOTE: ENHANCEMENTS MUST FOLLOW A SUBMISSION PROCESS INCLUDING A FEATURE PROPOSAL AND DESIGN DOCUMENT PRIOR TO SUBMITTING CODE
Pull Request Author
Add to this list or remove from it as applicable. This is a simple templated set of guidelines.
Reviewer
This will not be exhaustively relevant to every PR.