Skip to content
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

Merged
merged 22 commits into from
Mar 15, 2021

Conversation

mitchute
Copy link
Collaborator

@mitchute mitchute commented Mar 12, 2021

Pull request overview

  • Moves the following to state:
    • Fans
    • DataReportingFlags
    • DataMoistureBalanceEMPD
    • DemandManager
    • HeatBalanceAirManager
    • HVACInterfaceManager
    • DataSurfaceLists
    • RootFinder
    • DataRootFinder
    • HVACControllers

Pull Request Author

Add to this list or remove from it as applicable. This is a simple templated set of guidelines.

  • Title of PR should be user-synopsis style (clearly understandable in a standalone changelog context)
  • Label the PR with at least one of: Defect, Refactoring, NewFeature, Performance, and/or DoNoPublish
  • Pull requests that impact EnergyPlus code must also include unit tests to cover enhancement or defect repair
  • Author should provide a "walkthrough" of relevant code changes using a GitHub code review comment process
  • If any diffs are expected, author must demonstrate they are justified using plots and descriptions
  • If changes fix a defect, the fix should be demonstrated in plots and descriptions
  • If any defect files are updated to a more recent version, upload new versions here or on DevSupport
  • If IDD requires transition, transition source, rules, ExpandObjects, and IDFs must be updated, and add IDDChange label
  • If structural output changes, add to output rules file and add OutputChange label
  • If adding/removing any LaTeX docs or figures, update that document's CMakeLists file dependencies

Reviewer

This will not be exhaustively relevant to every PR.

  • Perform a Code Review on GitHub
  • If branch is behind develop, merge develop and build locally to check for side effects of the merge
  • If defect, verify by running develop branch and reproducing defect, then running PR and reproducing fix
  • If feature, test running new feature, try creative ways to break it
  • CI status: all green or justified
  • Check that performance is not impacted (CI Linux results include performance check)
  • Run Unit Test(s) locally
  • Check any new function arguments for performance impacts
  • Verify IDF naming conventions and styles, memos and notes and defaults
  • If new idf included, locally check the err file and other outputs

@mitchute mitchute added the Refactoring Includes code changes that don't change the functionality of the program, just perform refactoring label Mar 12, 2021
@mitchute mitchute added this to the EnergyPlus 9.5.0 milestone Mar 12, 2021
@mitchute mitchute self-assigned this Mar 12, 2021
Comment on lines 8077 to 8078
state->dataWaterCoils->WaterCoil(CoilNum).WaterCoilModel = state->dataWaterCoils->CoilModel_Cooling;
state->dataWaterCoils->WaterCoil(CoilNum).WaterCoilType = HVACControllers::iCoilType::Heating;
Copy link
Collaborator Author

@mitchute mitchute Mar 12, 2021

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?

Copy link
Contributor

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.

Copy link
Collaborator

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.

Copy link
Collaborator Author

@mitchute mitchute Mar 12, 2021

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:

  1. Change HVACController::CoilType* const ints to enum class.
  2. Those are checked against iNodeType in HVACControllers::GetControllerInput which is set by WaterCoils::CheckActuatorNode.
  3. Internally, CheckActuatorNode sets iNodeType from WaterCoils::WaterCoil(coilNum).WaterCoilType.
  4. Changing WaterCoilType from int to HVACControllers::iCoilType then resulted in noticing this problem.

No idea why we have two different type variables.

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Collaborator

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?

Copy link
Contributor

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)

Copy link
Member

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!

Copy link
Collaborator

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.

Comment on lines +59 to +61
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
Copy link
Collaborator Author

@mitchute mitchute Mar 12, 2021

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:

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx.

Comment on lines +68 to +70
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
Copy link
Collaborator Author

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.

@Myoldmopar
Copy link
Member

I'll watch for this to get some CI results and if it's clean then this can go in next.

@Myoldmopar
Copy link
Member

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.

@amirroth
Copy link
Collaborator

None from me, thanks.

Comment on lines 71 to 74
Unassigned,
Simple,
Cooling,
Detailed,
Copy link
Contributor

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.

@Myoldmopar
Copy link
Member

OK, my commit went from:

    enum class iCoilModel
    {
        Unassigned,
        Simple,
        Cooling,
        Detailed,
    };

to

    enum class iCoilModel
    {
        Unassigned,
        HeatingSimple,
        CoolingSimple,
        CoolingDetailed,
    };

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.

@Myoldmopar Myoldmopar merged commit d26e157 into NREL:develop Mar 15, 2021
@Myoldmopar Myoldmopar deleted the GlobalCleanup branch March 15, 2021 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Refactoring Includes code changes that don't change the functionality of the program, just perform refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants