-
Notifications
You must be signed in to change notification settings - Fork 396
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
Global HVACController, RootFinder, and others #8615
Conversation
state->dataWaterCoils->WaterCoil(CoilNum).WaterCoilModel = state->dataWaterCoils->CoilModel_Cooling; | ||
state->dataWaterCoils->WaterCoil(CoilNum).WaterCoilType = HVACControllers::iCoilType::Heating; |
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.
@mjwitte I think it's worth drawing your attention to this particular change. I changed WaterCoilType
here to use an enum value instead of const ints. In doing so, I found that in this unit test, WaterCoilModel
was using the "CoilType" int const value instead of the "CoilModel" int const values at this location. In order to replicate the same behavior, CoilType_Heating
which had a value of 2 had to be moved to CoilModel_Cooling
, which also has a value of 2. So now this unit test looks a little funny, with CoilType values being set to "Heating" and the CoilModel value being set to "Cooling".
I suppose the main question I have is whether you think this looks like just a quirk of this unit test, or if this points to a larger issue that needs to be investigated?
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.
@mitchute No, that's bad. Why is there a coil type enum class in HVACControllers
now?
Earlier in this same unit test a different coil type is set which is probably the source of the inconsistency.
thisVRFTU.SuppHeatCoilType_Num = DataHVACGlobals::Coil_HeatingWater; |
And why does dataWaterCoils->WaterCoil
have two different type variables, WaterCoilType_Num
and WaterCoilType
?
But you had to change WaterCoilModel
to cooling? Now I'm really confused.
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.
Here's a high level comment. EnergyPlus and its API should deal with strings as little as possible. Enumerated values should not be strings, they should be enums. That's what the keyword enum
means. The only things that should be strings are (dynamic) names. This is probably not the right time to do this sweep, but a sweep is needed.
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.
Let's see if I can recreate the chain of events that lead to this:
- Change HVACController::CoilType* const ints to enum class.
- Those are checked against
iNodeType
inHVACControllers::GetControllerInput
which is set byWaterCoils::CheckActuatorNode
. - Internally,
CheckActuatorNode
setsiNodeType
fromWaterCoils::WaterCoil(coilNum).WaterCoilType
. - Changing
WaterCoilType
fromint
toHVACControllers::iCoilType
then resulted in noticing this problem.
No idea why we have two different type variables.
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 see, WaterCoilType
is only heating or cooling, WaterCoilType_Num
is
int const WaterCoil_SimpleHeating;
int const WaterCoil_DetFlatFinCooling;
int const WaterCoil_Cooling;
So, WaterCoilType
could be combined with the other with some OR logic added where needed. FFR I guess.
But WaterCoilModel
is essentially the same list of options?
int const CoilModel_Simple; <-- which is used for WaterCoil_SimpleHeating
int const CoilModel_Cooling;
int const CoilModel_Detailed;
So, it looks like WaterCoil(CoilNum).WaterCoilModel
and WaterCoil(CoilNum).WaterCoilType_Num
are redundant and one or the other should be removed. At a minimum, they should bot work off the same enum class.
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 @mitchute We still have these lines in this unit test.
state->dataWaterCoils->WaterCoil(CoilNum).WaterCoilModel = state->dataWaterCoils->CoilModel_Cooling;
state->dataWaterCoils->WaterCoil(CoilNum).WaterCoilType = HVACControllers::iCoilType::Heating;
What's the plan for fixing this?
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.
What is the semantic distinction between these two variables? Why are they both necessary?
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.
They aren't really necessary. One has choices of "heating" or "cooling" and the other has choices of "heating", "cooling-simple" and "cooling-detailed". With a few logic changes the binary one could be removed. See #8615 (comment)
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.
Verified in GetWaterCoilInput where these are assigned: @mjwitte's suggested names make great sense. I'll make that change alone here and this should be ready to go in. Thank you all for the review!
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.
Alternatively replace all names with auto
and let the compiler figure it out.
constexpr int iSlopeNone(0); // Undefined slope specification | ||
constexpr int iSlopeIncreasing(1); // For overall increasing function F(X) between min and max points | ||
constexpr int iSlopeDecreasing(-1); // For overall decreasing function F(X) between min and max points |
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.
@amirroth @Myoldmopar These were not changed to an enum class because the values are used in error reporting messages, which frankly are not super useful. But that's what we've got. For example:
EnergyPlus/src/EnergyPlus/RootFinder.cc
Lines 244 to 245 in 8340215
ShowContinueError(state, format("SetupRootFinder: iSlopeIncreasing={}", iSlopeIncreasing)); | |
ShowContinueError(state, format("SetupRootFinder: iSlopeDecreasing={}", iSlopeDecreasing)); |
I don't expect either of you to propose a solution at this time, but just noting FFR. We'll run into this as we push more on getting these converted over, so we could start thinking about how situations like this might be handled.
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.
Thx.
constexpr int NoRecircFlow(0); | ||
constexpr int PrimaryRecirc(1); // flow from Supply-outlet/Demand-inlet to Supply-inlet/demand-outlet | ||
constexpr int SecondaryRecirc(2); // flow from Supply-inlet/Demand-outlet to Supply-outlet/demand-inlet |
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.
Same issue here, but this time due to the variables these are assigned to being used as reporting variables.
I'll watch for this to get some CI results and if it's clean then this can go in next. |
It feels like the changes above are settled for now, in the context of this PR. We certainly still have room to improve the code to further reduce the lists of constant ints, but the goal of this is to get rid of the data from the global struct, and leaving a few integers around, as long as they are constexpr, is fully reasonable for this stage. This is a ton of work and is looking good. Does anyone have anything further on this? I'm building and doing a few tests locally to add onto what CI is already doing. |
None from me, thanks. |
src/EnergyPlus/WaterCoils.hh
Outdated
Unassigned, | ||
Simple, | ||
Cooling, | ||
Detailed, |
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.
Never mind my earlier comment - my page wasn't refreshed.
But these enum names here should be "HeatingSimple" "CoolingSimple" and "CoolingDetailed", I'm fairly certain - haven't gone looking for their usage.
OK, my commit went from:
to
I built and ran unit tests successfully. I then ran a few hundred regressions with zero diffs of any kind. This is ready to merge in without waiting on any CI cycles. Thanks for the review everyone. I do understand there is lots of additional valuable work to be made in the enumeration realm, and look forward to that work, but this PR successfully cleans out a bunch of global variables, which is awesome. |
Pull request overview
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.