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

Clean up for PR: conv to enum DataPlant::PlantEquipmentType #9053 #9137

Merged
merged 54 commits into from
Nov 29, 2021

Conversation

jmythms
Copy link
Contributor

@jmythms jmythms commented Oct 15, 2021

Pull request overview

To Do:

  • Link To-Do list, address all comment status.
  • Push constexpr commit + clangFormat + anything else.

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

@jmythms jmythms added the Refactoring Includes code changes that don't change the functionality of the program, just perform refactoring label Oct 15, 2021
@jmythms jmythms added this to the EnergyPlus 2022.1 milestone Oct 15, 2021
@jmythms jmythms self-assigned this Oct 15, 2021
@nrel-bot
Copy link

@jmythms @Myoldmopar it has been 28 days since this pull request was last updated.

@Myoldmopar
Copy link
Member

@jmythms let me know if you would like to tackle the conflicts here or if I should. It looks like a bunch of files, but honestly I bet they are all small resolutions, since it even shows they can be addressed here on Github itself.

@jmythms
Copy link
Contributor Author

jmythms commented Nov 15, 2021

@jmythms let me know if you would like to tackle the conflicts here or if I should. It looks like a bunch of files, but honestly I bet they are all small resolutions, since it even shows they can be addressed here on Github itself.

I'll get them, will try to get it done by the end of the day :)

@jmythms jmythms marked this pull request as draft November 16, 2021 04:20
@jmythms jmythms marked this pull request as ready for review November 16, 2021 15:31
@jmythms
Copy link
Contributor Author

jmythms commented Nov 16, 2021

This is ready for review.

@Myoldmopar
Copy link
Member

Awesome, thanks @jmythms !

constexpr std::array<std::string_view, static_cast<int>(CrankcaseHeaterControlTemp::Num)> CrankcaseHeaterControlTempNamesUC{
"SCHEDULE",
"ZONE",
"OUTDOORS",
Copy link
Contributor

@rraustad rraustad Nov 16, 2021

Choose a reason for hiding this comment

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

Cut-n-Paste error? Should be EXTERIOR ?

Copy link
Member

Choose a reason for hiding this comment

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

@jmythms can you respond to this?

Copy link
Contributor Author

@jmythms jmythms Nov 16, 2021

Choose a reason for hiding this comment

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

Currently, Develop checks against the text "OUTDOORS" to set
HPWH.CrankcaseTempIndicator = CrankTempEnum::Exterior;. I don't know if this is a bug... But the code in this PR has the same behavior as Develop, as of now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checking the IDD file to confirm.

Copy link
Contributor

Choose a reason for hiding this comment

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

One thought I had was that it doesn't matter what the string is so this still looks OK. Another thought is for the future where the string does not closely resemble the enum name. I could go either way here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Change the enum name given what the IDD shows. Also, there are now 2 string arrays with the same strings, this one and one before this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, will do!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know if I should combine them and just re-use one string array. This might save a tiny bit of memory, and both seem to be referring to a somewhat similar physical phenomenon: ambient air temperatures. On the other hand, it might be better to keep them separate for understandability: one refers to the tank ambient temperature and another to compressor ambient temperature.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, just leave that for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you!

Copy link
Member

@Myoldmopar Myoldmopar left a comment

Choose a reason for hiding this comment

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

Overall this is looking great. I'm curious about the high temperature setpoint rename and messaging changes, can you discuss that and also the comment from @rraustad before we proceed further?

@@ -4444,7 +4444,7 @@ void CalcHeatEmissionReport(EnergyPlusData &state)
// Water heater and thermal storage
auto &WaterThermalTank(state.dataWaterThermalTanks->WaterThermalTank);
for (int iTank = 1; iTank <= state.dataWaterThermalTanks->numWaterThermalTank; ++iTank) {
if (WaterThermalTank(iTank).AmbientTempIndicator == WaterThermalTanks::AmbientTempEnum::OutsideAir) {
if (WaterThermalTank(iTank).AmbientTempIndicator == WaterThermalTanks::WTTAmbientTemp::OutsideAir) {
Copy link
Member

Choose a reason for hiding this comment

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

OK, so renamed the enum I assume. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, just wanted to take the word "Enum" out.

THeatRecSetPoint = state.dataLoopNodes->Node(this->HeatRecSetPointNodeNum).TempSetPoint;
} else if (state.dataPlnt->PlantLoop(this->HRLoopNum).LoopDemandCalcScheme ==
DataPlant::LoopDemandCalcScheme::DualSetPointDeadBand) {
THeatRecSetPoint = state.dataLoopNodes->Node(this->HeatRecSetPointNodeNum).TempSetPointHi;
Copy link
Member

Choose a reason for hiding this comment

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

These are fine, though I do wonder if there was discussion about making these into switch blocks? The reason we have all these SELECT_CASE_var blocks is because in Fortran, the selectors could be integer, logical, or character, but in C++, the case labels have to be constant, non-extern, and cannot be strings. In many cases within EnergyPlus, the case labels are either extern variables or strings, so it can't be made directly into a switch block, and you must use an IF structure. But as we move toward more enumeration, the number of switch blocks we can use grows.

I am not proposing that you redo these as switch blocks now, but moving forward, I would personally like to see more switch blocks where they are possible. I'm curious what others think though. I didn't see a specific section title in the wiki that addressed this, but it could be in there if I poked around a little more.

In either case, this is definitely a huge improvement already, and thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The logic I used here was that: if there are only two comparisons, use if-else. If there are more than two, use Switch/case. Referring to this older discussion here. Will start moving to switch/case 👍🏽

.TempSetPoint == SensedNodeFlagValue) {
if (!state.dataGlobal->AnyEnergyManagementSystemInModel) {

switch (state.dataPlnt->PlantLoop(LoopNum).LoopDemandCalcScheme) {
Copy link
Member

Choose a reason for hiding this comment

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

Excellent, this one is a switch block, nice!

CurrentModuleObject = "PlantEquipmentList";
} else if (SELECT_CASE_var == LoopType::Condenser) {
} else if (state.dataPlantCondLoopOp->EquipListsTypeList(Num) == LoopType::Condenser) {
Copy link
Member

Choose a reason for hiding this comment

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

One thing about switch blocks is that the IDEs will force you to justify if you don't handle every possible enum choice. With IF blocks you can easily slip enum cases by without handling them. (Of course with switch blocks it is easy to forget a break)

ErrorsFound = true;
} else {
// need call to EMS to check node
NodeEMSSetPointMissing = false;
CheckIfNodeSetPointManagedByEMS(
state,
state.dataPlnt->PlantLoop(LoopNum).OpScheme(SchemeNum).EquipList(1).Comp(CompNum).SetPointNodeNum,
EMSManager::SPControlType::iTemperatureSetPoint,
EMSManager::SPControlType::iTemperatureMaxSetPoint,
Copy link
Member

Choose a reason for hiding this comment

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

Unexpected renaming, I'll have to figure out why that is needed.

Copy link
Contributor Author

@jmythms jmythms Nov 16, 2021

Choose a reason for hiding this comment

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

I think this is GitHub getting confused about which line to compare against. I think this should be compared against line 1601 in Develop. Instead, it is comparing against Develop line 1550, which is line 1549 in this PR. It seems to be showing up ok in the CLion diff viewer.
image

Copy link
Member

Choose a reason for hiding this comment

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

👍


// Chillers
if (SELECT_CASE_var == DataPlant::HowMet::ByNominalCapLowOutLimit) { // chillers with lower limit on outlet temperature
switch (this_component.HowLoadServed) {
Copy link
Member

Choose a reason for hiding this comment

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

👍

break;
}
default:
break; // Don't do anything
Copy link
Member

Choose a reason for hiding this comment

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

I ❤️ this so much more than the SELECT_CASE_var code.

EXPECT_EQ(Tank.FuelType, "Electricity");
EXPECT_EQ(Tank.OffCycParaFuelType, "Electricity");
EXPECT_EQ(Tank.OnCycParaFuelType, "Electricity");
EXPECT_TRUE(compare_enums(Tank.FuelType, WaterThermalTanks::Fuel::Electricity));
Copy link
Member

Choose a reason for hiding this comment

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

Yay!

constexpr std::array<std::string_view, static_cast<int>(CrankcaseHeaterControlTemp::Num)> CrankcaseHeaterControlTempNamesUC{
"SCHEDULE",
"ZONE",
"OUTDOORS",
Copy link
Member

Choose a reason for hiding this comment

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

@jmythms can you respond to this?

if (SELECT_CASE_var == "UFACTORTIMESAREAANDDESIGNWATERFLOWRATE") {
state.dataWaterCoils->WaterCoil(CoilNum).CoilPerfInpMeth = state.dataWaterCoils->UAandFlow;
if (AlphArray(7) == "NOMINALCAPACITY") { // not "UFACTORTIMESAREAANDDESIGNWATERFLOWRATE"
state.dataWaterCoils->WaterCoil(CoilNum).CoilPerfInpMeth = state.dataWaterCoils->NomCap;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know this is not part of this PR, but it looks like there are still some int const's lurking in state.

Copy link
Member

Choose a reason for hiding this comment

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

There are, and I've a way to sniff them out, along with other const Array1D and things, so they'll be fixed separate. Thanks for noticing!

constexpr std::array<std::string_view, static_cast<int>(WTTAmbientTemp::Num)> HPWHAmbientTempNamesUC{
"SCHEDULE", "ZONEAIRONLY", "OUTDOORAIRONLY", "ZONEANDOUTDOORAIR"};

constexpr int TankAmbientTempNamesNum = static_cast<int>(WTTAmbientTemp::Num) - 1; // Since AmbientTemp::ZoneAndOA is not appilcable to Tank
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would define this as another enumerated value in WTTAmbientTemp:

    Num,
    TankNum = Num - 1
};

Copy link
Contributor Author

@jmythms jmythms Nov 21, 2021

Choose a reason for hiding this comment

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

Will change, thanks! Also learned that two enum constants can have the same value, which is cool, weird, and a little scary.

@Myoldmopar
Copy link
Member

This looks like it has been vetted sufficiently and is now all green. Any loose ends to wrap up before merging? I don't see any.

@jmythms
Copy link
Contributor Author

jmythms commented Nov 29, 2021

This looks like it has been vetted sufficiently and is now all green. Any loose ends to wrap up before merging? I don't see any.

All good to go from my side.

@Myoldmopar
Copy link
Member

This branch is still 0 commits behind develop, so there is no need to wait for more results. Merging this in, thanks everyone!

@Myoldmopar Myoldmopar merged commit 02b81ad into develop Nov 29, 2021
@Myoldmopar Myoldmopar deleted the enumDataPlant3 branch November 29, 2021 17:18
@jmythms
Copy link
Contributor Author

jmythms commented Nov 29, 2021

Thank you!

@amirroth
Copy link
Collaborator

  1. 👍

yujiex pushed a commit that referenced this pull request Jan 27, 2022
Clean up for PR: conv to enum DataPlant::PlantEquipmentType #9053
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.