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

Room Air Cleanup -- Part 1 #10092

Merged
merged 18 commits into from
Jul 6, 2023
Merged

Room Air Cleanup -- Part 1 #10092

merged 18 commits into from
Jul 6, 2023

Conversation

amirroth
Copy link
Collaborator

@amirroth amirroth commented Jul 3, 2023

This started as a small effort to replace the ZoneEquipTypeOf_ integers in DataHVACGlobals.hh with an enumeration. It ended up with eliminating that group of constants in favor of the ZoneEquip enumeration in DataZoneEquipment.hh and then doing some cleanup in the RoomAirModel modules where that enumeration was most heavily used.

Some highlights:

  • The namespaces DataRoomAirModel, RoomAirModelManager, RoomAirModelAirflowNetwork, RoomAirModelUserTempPattern, DisplacementVentManager, CrossVentManager, UFADManager, and MundtSimManager are unified into a single RoomAir namespace.
  • state.dataX objects were heavily pruned. This is something I noticed when working on the daylighting module. At some point, whole tranches of local variables migrated into state.dataX objects. In some cases even loop induction variables! I don't know why or when this happened, whether it happened automatically (e.g., variables were mistakenly labeled as static and all static variables were moved to state.dataX) or manually, but it needs to be undone and it can only be undone manually. The general rule is that state.dataX objects should only contain data that persists across time steps. There are two major exceptions to this rule: i) data that is passed among a large number of functions within a single time step, and ii) large temporary data structures that are only used in one function but that have high set-up and tear-down overheads. Either way, I will be doing this aggressively going forward.
  • The pruned state.dataX were largely unified into a single state.dataRoomAir object. There are a few stragglers left, but they will be taken care of in a separate pass in the near future.
  • Some groups of discrete variables were collected into std::array, this primarily applies to history variables.
  • Some Array1D objects were conveted to std::array.
  • Some highly overlapping structs (looking at you, UFADInt and UFADExt) and their containers were unified.
  • getEnumerationValue, shortcuts, and scope reduction.
  • Continued propagating common error shortcut pattern.

This should be a zero diff PR.

@amirroth amirroth added DoNotPublish Includes changes that shouldn't be reported in the changelog Refactoring Includes code changes that don't change the functionality of the program, just perform refactoring labels Jul 3, 2023
@amirroth amirroth added this to the EnergyPlus 23.2 milestone Jul 3, 2023
Copy link
Collaborator Author

@amirroth amirroth left a comment

Choose a reason for hiding this comment

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

Walkthru annotations.

@@ -225,8 +225,8 @@ namespace AirLoopHVACDOAS {
++AirLoopMixerNum;
AirLoopMixer thisMixer;

thisMixer.name = UtilityRoutines::MakeUPPERCase(thisObjectName);
thisMixer.OutletNodeName = UtilityRoutines::MakeUPPERCase(fields.at("outlet_node_name").get<std::string>());
thisMixer.name = UtilityRoutines::makeUPPER(thisObjectName);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just did a global sed to shorten this name. You're welcome. I have another fun name shortener here also.

// TODO: Refactor this away by passing in enums
DataLoopNode::ConnectionObjectType ParentTypeEnum =
static_cast<DataLoopNode::ConnectionObjectType>(getEnumerationValue(ConnectionObjectTypeNamesUC, ParentTypeUC));
static_cast<DataLoopNode::ConnectionObjectType>(getEnumValue(ConnectionObjectTypeNamesUC, ParentTypeUC));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There it is. Should have named it that from the beginning. Sorry.

@@ -64,7 +64,6 @@
#include <EnergyPlus/DataHeatBalance.hh>
#include <EnergyPlus/DataRoomAirModel.hh>
#include <EnergyPlus/DataSurfaces.hh>
#include <EnergyPlus/DataUCSDSharedData.hh>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This module has been incorporated into DataRoomAirModel.hh

Copy link
Contributor

Choose a reason for hiding this comment

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

This file name is still in a CMake file, somewhere (probably ..\src\EnergyPlus), as shown by the Custom Check results.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, I'll get rid of it.

@@ -98,7 +96,7 @@ namespace CrossVentMgr {
Real64 constexpr CrecFlow1(0.415); // First correlation constant for the recirculation flow rate
Real64 constexpr CrecFlow2(0.466); // Second correlation constant for the recirculation flow rate

void ManageUCSDCVModel(EnergyPlusData &state,
void ManageCrossVent(EnergyPlusData &state,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

With all due respect to UCSD, there is no need to embed UCSD into variable and function names. I don't add Roth to names.

for (int Ctd = state.dataUCSDShared->PosZ_Wall((ZoneNum - 1) * 2 + 1); Ctd <= state.dataUCSDShared->PosZ_Wall((ZoneNum - 1) * 2 + 2);
++Ctd) {
int SurfNum = state.dataUCSDShared->APos_Wall(Ctd);
for (int Ctd = state.dataRoomAir->PosZ_Wall(ZoneNum).beg; Ctd <= state.dataRoomAir->PosZ_Wall(ZoneNum).end; ++Ctd) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I cannot tell you how much I hate the pattern of faking what should be an array of structs or even multiple arrays in a single array by, e.g., putting one of the elements in the odd positions in the array and another element in the even positions. It's not cute. It's brittle and opaque and evil.


// Data
class RAFNData
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Buh-bye.

ShowSevereError(state, format("{}{}=\"{}\", invalid data.", RoutineName, cCurrentModuleObject, state.dataIPShortCut->cAlphaArgs(1)));
ShowContinueError(
state, format("Invalid-not found {}=\"{}\".", state.dataIPShortCut->cAlphaFieldNames(2), state.dataIPShortCut->cAlphaArgs(2)));
ShowSevereItemNotFound(state, eoh, ipsc->cAlphaFieldNames(2), ipsc->cAlphaArgs(2));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Shortcuts for common errors.

Copy link
Contributor

Choose a reason for hiding this comment

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

I like that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There are five shortcuts so far: DuplicateName, EmptyField, InvalidKey, ItemNotFound, and OutOfRange but they cover nearly 50% of all input errors.

}
}
}
} // if
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I like to add these annotations. They help me remember where I am in the current nesting level.

bool GetUCSDDVDataFlag = true; // UCSD
bool GetAirModelData = true; // Used to "get" all air model data
bool MyOneTimeFlag = true;
int CompNum = 0;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

All of these were local variables that migrated into state somehow and now went back where they belong.

int Loop = 0; // counter
int Loop2 = 0; // counter
int Loop3 = 0; // counter
int i = 0; // counter
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Really, i is a state variable?

int SurfNum = state.dataRoomAir->APos_Wall(Ctd);
if (SurfNum == 0) continue;

auto const &surf = state.dataSurface->Surface(SurfNum);
state.dataSurface->SurfTAirRef(SurfNum) = DataSurfaces::RefAirTemp::AdjacentAirTemp;
Copy link
Contributor

Choose a reason for hiding this comment

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

This function is called from the CalcUCSDCV (now CalcCrossVent) function. Do we need to set this (line 177) enum each iteration? This will not change for a specific surface will it?

SurfaceConvectionAlgorithm:Inside:UserCurve,
  A2 , \field Reference Temperature for Convection Heat Transfer
       \note Controls which temperature is differenced from surface temperature when using the Hc value
       \type choice
       \key MeanAirTemperature
       \key AdjacentAirTemperature
       \key SupplyAirTemperature

Copy link
Collaborator 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.

Real64 ZoneVolumeFraction; // portion of zone air volume associated with this node
std::string Name = ""; // name
std::string ZoneName = "";
int ZonePtr = 0; // Pointer to the zone number for this statement
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe for a different pass since this PR is rather intense, I see ZoneName and ZonePtr in these and other structs. If we know the zone index we also know the name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah.

Copy link
Contributor

@rraustad rraustad left a comment

Choose a reason for hiding this comment

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

This started as good clean up and ended up very good clean up. Nice job!

std::string ZoneName = ""; // Name of zone
int ZonePtr = 0; // Pointer to the zone number for this statement
int SchedGainsPtr = -1; // Schedule for internal gain fraction to occupied zone
std::string SchedGainsName = ""; // Gains Schedule name
Copy link
Contributor

Choose a reason for hiding this comment

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

You can delete this now.

std::string ZoneName = ""; // Name of zone
int ZonePtr = 0; // Pointer to the zone number for this statement
int SchedGainsPtr = 0; // Schedule for internal gain fraction to occupied zone
std::string SchedGainsName = ""; // Gains Schedule name
Copy link
Contributor

Choose a reason for hiding this comment

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

You can delete this now.

@@ -64,7 +64,6 @@
#include <EnergyPlus/DataHeatBalance.hh>
#include <EnergyPlus/DataRoomAirModel.hh>
#include <EnergyPlus/DataSurfaces.hh>
#include <EnergyPlus/DataUCSDSharedData.hh>
Copy link
Contributor

Choose a reason for hiding this comment

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

This file name is still in a CMake file, somewhere (probably ..\src\EnergyPlus), as shown by the Custom Check results.

ShowSevereError(state, format("{}{}=\"{}\", invalid data.", RoutineName, cCurrentModuleObject, state.dataIPShortCut->cAlphaArgs(1)));
ShowContinueError(
state, format("Invalid-not found {}=\"{}\".", state.dataIPShortCut->cAlphaFieldNames(2), state.dataIPShortCut->cAlphaArgs(2)));
ShowSevereItemNotFound(state, eoh, ipsc->cAlphaFieldNames(2), ipsc->cAlphaArgs(2));
Copy link
Contributor

Choose a reason for hiding this comment

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

I like that.

ShowContinueError(state, format("Entered in {} = {}", cCurrentModuleObject, state.dataIPShortCut->cAlphaArgs(1)));
zoneUI.DiffuserType = static_cast<Diffuser>(getEnumValue(diffuserNamesUC, UtilityRoutines::makeUPPER(ipsc->cAlphaArgs(2))));
if (zoneUI.DiffuserType == Diffuser::Invalid) {
ShowSevereInvalidKey(state, eoh, ipsc->cAlphaFieldNames(2), ipsc->cAlphaArgs(2));
ErrorsFound = true;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Not possible since this field is within min-fields. Usually when I do this and see an else I'll check the idd.

RoomAirSettings:UnderFloorAirDistributionInterior,
       \min-fields 15
  N7 , \field Temperature Difference Threshold for Reporting
  A2 , \field Floor Diffuser Type
       \type choice
       \key Custom
       \key Swirl
       \key VariableArea
       \key HorizontalSwirl
       \key LinearBarGrille
       \default Swirl

@@ -7114,11 +7114,11 @@ namespace UnitarySystems {
if (sysNum == -1) {
// zone equipment require a 1-n index for access to zone availability managers
switch (getPTUnitType) {
case 1:
case 1: // Excuse me?
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I'll change these to constexpr next time I'm in here.

@@ -1172,7 +1172,7 @@ TEST_F(ConvectionCoefficientsFixture, EvaluateHnModels)
SurfNum = 1;
state->dataSurface->Surface.allocate(SurfNum);
state->dataSurface->Surface(SurfNum).Zone = 1;
state->dataRoomAirMod->AirModel.allocate(1);
state->dataRoomAir->AirModel.allocate(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Stopping at unit tests since changes will only be class names.

@rraustad
Copy link
Contributor

rraustad commented Jul 3, 2023

Good thing there are no diffs! That's the only way to guage these massive changes.

@amirroth
Copy link
Collaborator Author

amirroth commented Jul 4, 2023

Good thing there are no diffs! That's the only way to guage these massive changes.

The changes to makeUPPER and getEnumValue and the consolidation of the dataRoomAir state make the changes seem more extensive than they really are. Yes, there are many substantive changes. But 60-70% of the changes are just those three things.

@Myoldmopar
Copy link
Member

Fixed the format and custom check issues, deleting the now empty source file along the way. It's testing happily here, but I'll let at least some of the CI runs do their work on it before final review/merge.

@Myoldmopar
Copy link
Member

Pulled develop one more quick time this morning and everything is still happy as expected, merging. Thanks @amirroth !

@Myoldmopar Myoldmopar merged commit 8282392 into develop Jul 6, 2023
@Myoldmopar Myoldmopar deleted the HVACGlobals1 branch July 6, 2023 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DoNotPublish Includes changes that shouldn't be reported in the changelog 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.

8 participants