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 exterior energy #7965
Global exterior energy #7965
Conversation
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.
This is a very exciting PR. It's nice to see another chunk getting refactored and yet not having to make changes in hundreds of files. My main review comment is that I think we want to leave the structs defined in their original location, not brought into the data file. In that original header, you'll likely need to forward declare the EnergyPlusData struct or whatever struct you use in the function declarations.
@@ -109,16 +132,38 @@ struct ExteriorEnergyUseData : BaseGlobalStruct | |||
} | |||
}; | |||
|
|||
struct ExteriorEquipmentUsage |
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.
So this is the big question, I think. What do we do with structs? Ahead of this refactor, it is pretty simple, structs and function declarations go in the matching header with the code. But with this refactor, we have a choice. We can either move the structs out to the data folder or we can leave it in the original header and forward declare the EnergyPlus data struct instance. The main pro/con I see is that if we start pulling headers into this file, the file is going to quickly grow to a very large size. Like very. I don't really see any problems with forward declaring the data struct so that we can leave the headers in the original location. Another perk about this approach is that the files changed on Github will go down too, so it will be easier to review. I'm certainly open for discussion, but that's the way I'm leaning right now. Let me know if you want me to take a quick pass here and apply that.
@@ -85,6 +85,29 @@ struct DataGlobal : BaseGlobalStruct | |||
|
|||
struct ExteriorEnergyUseData : BaseGlobalStruct | |||
{ | |||
// MODULE PARAMETER DEFINITIONS: | |||
int const ElecUse = 1; // Electricity |
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.
Whenever possible, when we have a group of int const
in EnergyPlus code, these should be converted over to an enum
or enum class
. They aren't actually 'data', they are basically just another 'type'. As I mentioned in the previous comment, I am leaning toward leaving structs in their original header locations. And these converted int const
into enums
should be left in there as well. In fact, in a bunch of cases, you'll probably find they don't need to be in the header at all, and can just be put at the top of the cc file as a nice bonus.
(after further review below, I see the fuel type is used in the unit test, so the enum will need to stay in the header, no problem.)
int NumExteriorLights = 0; // Number of Exterior Light Inputs | ||
int NumExteriorEqs = 0; // Number of Exterior Equipment Inputs | ||
|
||
// Object Data | ||
Array1D<ExteriorLightUsage> ExteriorLights; // Structure for Exterior Light reporting | ||
Array1D<ExteriorEquipmentUsage> ExteriorEquipment; // Structure for Exterior Equipment Reporting |
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.
👍
NumExteriorLights = 0; | ||
NumExteriorEqs = 0; | ||
ExteriorLights.deallocate(); | ||
ExteriorEquipment.deallocate(); | ||
UniqueExteriorEquipNames.clear(); | ||
GetExteriorEnergyInputFlag = true; |
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.
👍
src/EnergyPlus/InternalHeatGains.cc
Outdated
@@ -3294,14 +3294,14 @@ namespace InternalHeatGains { | |||
ZoneOtherEq(Loop).OtherEquipFuelType = noOtherFuelTypeZero; | |||
FuelTypeString = AlphaName(2); | |||
} else { | |||
ExteriorEnergyUse::ValidateFuelType(ZoneOtherEq(Loop).OtherEquipFuelType, | |||
ExteriorEnergyUse::ValidateFuelType(state.exteriorEnergyUse, ZoneOtherEq(Loop).OtherEquipFuelType, |
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.
This is really nice. I can see a not-so-distant future where this line changes from:
ExteriorEnergyUse::ValidateFuelType(state.exteriorEnergyUse, ...);
to
state.exteriorEnergyUse.validateFuelType(...);
@@ -313,7 +313,7 @@ void EnergyPlus::clearAllStates() | |||
EMSManager::clear_state(); | |||
EvaporativeCoolers::clear_state(); | |||
EvaporativeFluidCoolers::clear_state(); | |||
ExteriorEnergyUse::clear_state(); | |||
//ExteriorEnergyUse::clear_state(); |
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.
So over time, the StateManagement file will become moot as well. All the clear_states will go through the data manager. This is going to be great.
@@ -130,7 +130,7 @@ TEST_F(EnergyPlusFixture, InternalHeatGains_OtherEquipment_CheckFuelType) | |||
if (equip.Name == "OTHEREQ1") { | |||
ASSERT_EQ(equip.OtherEquipFuelType, 0); | |||
} else if (equip.Name == "OTHEREQ2") { | |||
ASSERT_EQ(equip.OtherEquipFuelType, ExteriorEnergyUse::PropaneUse); | |||
ASSERT_EQ(equip.OtherEquipFuelType, state.exteriorEnergyUse.PropaneUse); |
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.
Ahh, and here is one reason why we won't be able to put that enum into the cc file, because the unit test needs to test against it. That's fine, the enum can go in the header, but in general, it's nice to move things out of the header that don't need to be there.
src/EnergyPlus/ExteriorEnergyUse.hh
Outdated
@@ -90,40 +72,21 @@ namespace ExteriorEnergyUse { | |||
|
|||
// Clears the global data in ExteriorEnergyUse. | |||
// Needed for unit tests, should not be normally called. | |||
void clear_state(); | |||
//void clear_state(); |
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.
Oh, and go ahead and delete these lines, not just 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.
Let me know if you want to chat about my changes or my comments here anytime.
@@ -57,6 +57,8 @@ | |||
|
|||
namespace EnergyPlus { | |||
|
|||
struct EnergyPlusData; |
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.
So the main struct will live inside the EnergyPlus namespace. Anywhere that we are using a forward declaration of this struct we need to put it inside the EnergyPlus namespace, not before it, and not inside another nested namespace. This goes with any other lower level structs you may use as well.
@@ -125,7 +127,7 @@ namespace BaseboardElectric { | |||
|
|||
void clear_state(); | |||
|
|||
void SimElectricBaseboard(EnergyPlusData &state, std::string const &EquipName, int const ActualZoneNum, int const ControlledZoneNum, Real64 &PowerMet, int &CompIndex); | |||
void SimElectricBaseboard(EnergyPlus::EnergyPlusData &state, std::string const &EquipName, int const ActualZoneNum, int const ControlledZoneNum, Real64 &PowerMet, int &CompIndex); |
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.
Accompanying that change, whenever we declare it as an argument type, it needs to be declared properly with EnergyPlus::EnergyPlusData
. This goes with the other lower-level types you may use: EnergyPlus::ExteriorEnergyUseData
.
//****************************************************************************************************** | ||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
//****************************************************************************************************** | ||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
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.
Feel free to clean up stuff like this as you refactor.
} | ||
}; | ||
|
||
struct ExteriorEnergyUseData : BaseGlobalStruct { |
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.
These structs should remain very lean, only variables. No nested structures, no int const values, just the actual variables storing data.
struct FansData : BaseGlobalStruct { | ||
// constants | ||
static constexpr int ExhaustFanCoupledToAvailManagers = 150; | ||
static constexpr int ExhaustFanDecoupledFromAvailManagers = 151; |
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 didn't remove these, but I would suggest you doing it. I made an enum class from the constant integers in the exterior energy use namespace. The enum class should live back in the original header file. You'll need to go in and clean up the usage of those variables but it is generally easy. If you don't feel like tackling that during any of these refactors, it is OK, but don't bring them into this namespace. They are really just constants, not variables.
@@ -54,7 +54,6 @@ | |||
|
|||
// EnergyPlus Headers | |||
#include <EnergyPlus/EnergyPlus.hh> | |||
#include <EnergyPlus/Data/EnergyPlusData.hh> |
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.
This was causing a circular inclusion. And it's not needed. If, for some reason, DataGlobals needs something from the Data.hh file, it can forward declare it.
|
||
// SUBROUTINE SPECIFICATIONS FOR MODULE <module_name> | ||
enum class ExteriorFuelUsage { |
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 is where I converted all those int const
into an enumeration. As I said, this isn't part of the actual scope here, so don't sweat every one of these, but in either case, leave them declared in the original header.
@@ -61,6 +61,8 @@ | |||
|
|||
namespace EnergyPlus { | |||
|
|||
struct DataGlobal; |
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 had to go around a number of places and add this forward declaration. It had previously worked because these files all included DataGlobals.hh
, which then included the main data file. When I took that out, these did not compile anymore. This new pattern works fine though.
@@ -3291,7 +3290,7 @@ namespace InternalHeatGains { | |||
|
|||
std::string FuelTypeString(""); | |||
if (AlphaName(2) == "NONE") { | |||
ZoneOtherEq(Loop).OtherEquipFuelType = noOtherFuelTypeZero; | |||
ZoneOtherEq(Loop).OtherEquipFuelType = ExteriorEnergyUse::ExteriorFuelUsage::Unknown; |
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.
Minor changes related to converted the ints to an enumeration.
@@ -54,7 +54,7 @@ | |||
#include <EnergyPlus/UtilityRoutines.hh> | |||
|
|||
void cClearAllStates() { | |||
EnergyPlusData state; //THIS IS TEMPORARY | |||
EnergyPlus::EnergyPlusData state; //THIS IS TEMPORARY |
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.
This definitely needs to be temporary. I will do some thinking about this. I think the main point is that now when someone wants to run an EnergyPlus simulation as a library, they need to own the state.
CI is as good as it's going to get here. Let's call this one done. Merging. |
convert ExteriorEnergyUse over to /Data/EnergyPlusData