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

Enum Refactor: DataZoneEquipment #9163

Merged
merged 22 commits into from
Nov 17, 2021
Merged

Enum Refactor: DataZoneEquipment #9163

merged 22 commits into from
Nov 17, 2021

Conversation

dareumnam
Copy link
Collaborator

Pull request overview

Remove constexpr ints in DataZoneEquipment object

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.

  • 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

@dareumnam dareumnam added the Refactoring Includes code changes that don't change the functionality of the program, just perform refactoring label Nov 2, 2021
@dareumnam dareumnam added this to the EnergyPlus 2022.1 milestone Nov 2, 2021
@dareumnam dareumnam self-assigned this Nov 2, 2021
@@ -338,7 +337,8 @@ namespace BaseboardElectric {

for (CtrlZone = 1; CtrlZone <= state.dataGlobal->NumOfZones; ++CtrlZone) {
for (ZoneEquipTypeNum = 1; ZoneEquipTypeNum <= state.dataZoneEquip->ZoneEquipList(CtrlZone).NumOfEquipTypes; ++ZoneEquipTypeNum) {
if (state.dataZoneEquip->ZoneEquipList(CtrlZone).EquipType_Num(ZoneEquipTypeNum) == BBElectricConvective_Num &&
if (state.dataZoneEquip->ZoneEquipList(CtrlZone).EquipType_Num(ZoneEquipTypeNum) ==
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 pedantic, but we should call things Type rather than TypeNum. Not so critical here, more important for member names.

constexpr int ZoneMixer_Type(3);
constexpr int ZoneReturnPlenum_Type(4);
enum class CompType
{
Copy link
Collaborator

@amirroth amirroth Nov 2, 2021

Choose a reason for hiding this comment

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

Not sure CompType is a good name for this enum. Also, need to add Num to the ends of these.

enum ZoneEquip
{
Unassigned = -1,
FanCoil4Pipe = 1,
Copy link
Collaborator

@amirroth amirroth Nov 2, 2021

Choose a reason for hiding this comment

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

Why is this not 0? Is it because there are Array1D that use these as indices? That should be a sign to switch those to std::array. Can do this in a subsequent PR I guess.

Copy link
Member

Choose a reason for hiding this comment

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

@dareumnam any comment on this?

Copy link
Contributor

Choose a reason for hiding this comment

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

image

Copy link
Collaborator

Choose a reason for hiding this comment

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

Per my comment above, arrays indexed by enum should be turned into std::array. Per same comment, no need to hold up this PR for that single change.

Copy link
Member

Choose a reason for hiding this comment

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

👍

RefrigerationAirChillerSet,
UserDefinedZoneHVACForcedAir,
CoolingPanel,
ZoneUnitarySys
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add Num.

Unassgined = -1,
DCVByCurrentLevel,
ByDesignLevel
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add Num.

@@ -358,7 +374,7 @@ namespace DataZoneEquipment {
int NumAvailHeatEquip; // Number of pieces of equipment available for heating
int NumAvailCoolEquip; // Number of pieces of equipment available for cooling
Array1D_string EquipType;
Array1D_int EquipType_Num;
Array1D<DataZoneEquipment::ZoneEquip> EquipType_Num;
Copy link
Collaborator

Choose a reason for hiding this comment

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

No _Num. I understand that there is already an array called EquipType which is an array of strings, but that array should not be necessary. You should convert things from string to enum as we parse the IDF and only use enum internally. If you want, you can put a pin in these comments and do them in a separate PR.

@@ -407,7 +423,7 @@ namespace DataZoneEquipment {
int NumOfComponents;
int InletNodeNum;
Array1D_string ComponentType;
Array1D_int ComponentType_Num;
Array1D<DataZoneEquipment::CompType> ComponentType_Num;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment as above.

@@ -431,7 +447,7 @@ namespace DataZoneEquipment {
int NumOfComponents;
int OutletNodeNum;
Array1D_string ComponentType;
Array1D_int ComponentType_Num;
Array1D<DataZoneEquipment::CompType> ComponentType_Num;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment.

@@ -712,7 +712,7 @@ namespace FanCoilUnits {
state.dataFanCoilUnits->ATMixerOutNode,
FanCoil(FanCoilNum).AirOutNode);
FanCoil(FanCoilNum).ControlZoneNum =
DataZoneEquipment::GetZoneEquipControlledZoneNum(state, DataZoneEquipment::FanCoil4Pipe_Num, FanCoil(FanCoilNum).Name);
DataZoneEquipment::GetZoneEquipControlledZoneNum(state, DataZoneEquipment::ZoneEquip::FanCoil4Pipe, FanCoil(FanCoilNum).Name);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably not something you want to handle in this PR, but ... why are we doing this lookup by FanCoil name if we already know FanCoil index?

Copy link
Contributor

Choose a reason for hiding this comment

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

ZoneEquipConfig stores the component type and name so to look up the correct component needed the type and name (back then). Now that code is progressing a new method might be used.

@@ -516,107 +516,107 @@ void GetZoneEquipmentData(EnergyPlusData &state)
auto const SELECT_CASE_var(UtilityRoutines::MakeUPPERCase(thisZoneEquipList.EquipType(ZoneEquipTypeNum)));

if (SELECT_CASE_var == "ZONEHVAC:AIRDISTRIBUTIONUNIT") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This code should be converted to a getEnumerationValue.

@@ -191,9 +188,9 @@ namespace ReturnAirPathManager {
ErrorsFound = true;
}
if (UtilityRoutines::SameString(state.dataIPShortCut->cAlphaArgs(Counter), "AirLoopHVAC:ZoneMixer"))
state.dataZoneEquip->ReturnAirPath(PathNum).ComponentType_Num(CompNum) = ZoneMixer_Type;
state.dataZoneEquip->ReturnAirPath(PathNum).ComponentType_Num(CompNum) = DataZoneEquipment::CompType::ZoneMixer;
Copy link
Collaborator

Choose a reason for hiding this comment

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

getEnumerationValue.

@@ -4539,7 +4539,7 @@ void ReportMaxVentilationLoads(EnergyPlusData &state)
.EquipType_Num(thisZoneEquipNum));
// case statement to cover all possible zone forced air units that could have outside air

if (SELECT_CASE_var == WindowAC_Num) { // Window Air Conditioner
if (SELECT_CASE_var == DataZoneEquipment::ZoneEquip::WindowAC) { // Window Air Conditioner
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be a switch/case.

@@ -3065,7 +3065,7 @@ void SimZoneEquipment(EnergyPlusData &state, bool const FirstHVACIteration, bool
{
auto const SELECT_CASE_var(state.dataZoneEquip->SupplyAirPath(SupplyAirPathNum).ComponentType_Num(CompNum));

if (SELECT_CASE_var == ZoneSplitter_Type) { // 'AirLoopHVAC:ZoneSplitter'
if (SELECT_CASE_var == DataZoneEquipment::CompType::ZoneSplitter) { // 'AirLoopHVAC:ZoneSplitter'
Copy link
Collaborator

Choose a reason for hiding this comment

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

switch/case.

@Myoldmopar
Copy link
Member

Looks like comments have been addressed here, but speak up if there is anything still waiting. I pulled develop into this locally and re-ran regressions. Everything passes beautifully. If no one has an issue, I'll merge this this afternoon.

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.

Everything looks OK to me. There appears to be one unanswered question which I noted in my comments, but even that is something for later. I think this is good to go.

@@ -12325,9 +12325,6 @@ namespace AirflowNetworkBalanceManager {
// PURPOSE OF THIS SUBROUTINE:
// This subroutine validate zone exhaust fan and associated surface

// Using/Aliasing
using DataZoneEquipment::ZoneExhaustFan_Num;
Copy link
Member

Choose a reason for hiding this comment

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

A simple but nice change.

case PurchasedAir_Num:
switch (state.dataZoneEquip->ZoneEquipList(state.dataZoneEquip->ZoneEquipConfig(ZoneNum).EquipListIndex).EquipTypeEnum(EquipNum)) {
case DataZoneEquipment::ZoneEquip::AirDistUnit:
case DataZoneEquipment::ZoneEquip::PurchasedAir:
Copy link
Member

Choose a reason for hiding this comment

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

This reads so much nicer.

Intermediate,
Outlet,
NUM
};
Copy link
Member

Choose a reason for hiding this comment

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

Awesome.

enum ZoneEquip
{
Unassigned = -1,
FanCoil4Pipe = 1,
Copy link
Member

Choose a reason for hiding this comment

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

@dareumnam any comment on this?

@dareumnam
Copy link
Collaborator Author

@Myoldmopar Thanks for your review. I keep addressing comments on my local branch, but it is okay if this gets merged in first. I can open a separate PR.

@Myoldmopar
Copy link
Member

Alright, pulled develop in just for fun after the version change and it's still passing fine. @dareumnam just make sure to address the last little pieces here on your next PR. Thanks! Merging!

@Myoldmopar Myoldmopar merged commit 9ddaf77 into develop Nov 17, 2021
@Myoldmopar Myoldmopar deleted the enumDataZoneEquipTest branch November 17, 2021 20:54
yujiex pushed a commit that referenced this pull request Jan 27, 2022
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