-
Notifications
You must be signed in to change notification settings - Fork 392
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
Convert compressor operation from int constexpr to enum #9199
Conversation
src/EnergyPlus/DataHVACGlobals.hh
Outdated
// Compressor operation | ||
enum class CompressorOperation | ||
{ | ||
Unassigned = -1, | ||
Off, // signal DXCoil that compressor shouldn't run | ||
On, // normal compressor operation | ||
Num | ||
}; |
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.
CompressorOperation
enum class exists in DataHVACGlobals.hh.
src/EnergyPlus/Furnaces.cc
Outdated
@@ -9794,7 +9869,7 @@ namespace Furnaces { | |||
FirstHVACIteration = false; | |||
} | |||
FanOpMode = int(Par(3)); | |||
CompOp = int(Par(4)); | |||
CompOp = static_cast<CompressorOperation>(Par(4)); |
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.
The par(*)
values that are parameters and results of the residual functions had to be static_cast
.
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 things need to be converted to lambdas anyway. There is already an open issue about that. That conversion will make these casts unnecessary.
@@ -54,6 +54,7 @@ | |||
|
|||
// EnergyPlus Headers | |||
#include <EnergyPlus/Data/BaseData.hh> | |||
#include <EnergyPlus/DataHVACGlobals.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.
Had to include the DataHVACGlobals.hh here.
CompressorOperation constexpr iZero(CompressorOperation::Off); | ||
CompressorOperation constexpr iOne(CompressorOperation::On); |
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.
Will refactor 😅
@@ -233,7 +231,7 @@ namespace UnitarySystems { | |||
Real64 &sysOutputProvided, | |||
Real64 &latOutputProvided) | |||
{ | |||
int CompOn = 0; | |||
DataHVACGlobals::CompressorOperation CompOn = DataHVACGlobals::CompressorOperation::Off; |
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.
A using namespace DataHVACGlobals;
statement will shorten these lines, make them more readable. Is that recommended?
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 think we are trying to avoid using
statements in general. The thing to do here is to shorten the name of the namespace itself. There should only be a dozen or so namespaces (there is no one-to-one relationship between namespace and file) and they should have names like HVAC
and Const
not DataGlobalConstants
and DataHVACGlobals
. You don't need long names when you have only 12 of something.
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.
Got it. Should be a quick refactor when it happens.
src/EnergyPlus/UnitarySystem.cc
Outdated
if (CompOn == DataHVACGlobals::CompressorOperation::On) { | ||
this->m_CoolCompPartLoadRatio = PartLoadRatio; | ||
} else { | ||
this->m_CoolCompPartLoadRatio = 0; | ||
} |
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.
Unrolled these multiplying with double(CompOn)
to if else statements checking if the Compressor is on or of.
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.
A shorthand for this idiom is:
this->m_CoolCompPartLoadRatio = DataHVACGlobals::CompressorOperation::On ? PartLoadRatio : 0.0;
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.
Um ...
this->m_CoolCompPartLoadRatio = CompOn ? PartLoadRatio : 0.0;
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.
You caught me! Actually for clarity and type safety it should be:
this->m_CoolCompPartLoadRatio = (compOp == DataHVACGlobals::CompressorOperation::On) ? PartLoadRatio : 0.0;
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.
By the way, I made that mistake on purpose to see if anyone was paying attention! 😉
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.
Will make the changes, thanks for the suggestion! 😃
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.
#9052 should easily merge with all these changes ...
@@ -54,6 +54,7 @@ | |||
|
|||
// EnergyPlus headers | |||
#include <EnergyPlus/Data/BaseData.hh> | |||
#include <EnergyPlus/DataHVACGlobals.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.
Another #include <EnergyPlus/DataHVACGlobals.hh>
statement addition here.
src/EnergyPlus/UnitarySystem.hh
Outdated
int const AirLoopNum, // index to air loop | ||
bool const FirstHVACIteration, // True when first HVAC iteration | ||
Real64 const PartLoadRatio, // coil operating part-load ratio | ||
DataHVACGlobals::CompressorOperation CompOn, // compressor control (0=off, 1=on) |
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 removed const qualifiers in declarations wherever I saw them in the code I was changing. Suggestion from clang-tidy.
int const CompOp, // compressor operation; 1=on, 0=off | ||
bool const FirstHVACIteration, // True when first HVAC iteration | ||
std::string_view CompName, // name of the fan coil unit | ||
CompressorOperation const CompOp, // compressor operation; 1=on, 0=off |
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 hate to be pedantic (actually, I love it) but I think ComprOp
or CompressOp
or CompressorOp
is better than CompOp
. We are already using Comp
to mean component (see preceding parameter), we shouldn't also use it to mean compressor.
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.
Will change to CompressorOp
👍🏽
@@ -229,19 +229,21 @@ void SimDXCoil(EnergyPlusData &state, | |||
// call the HPWHDXCoil routine to calculate water side performance set up the DX coil info for air-side calcs | |||
CalcHPWHDXCoil(state, DXCoilNum, PartLoadRatio); | |||
// CALL CalcDoe2DXCoil(state, DXCoilNum, CompOp, FirstHVACIteration,PartLoadRatio), perform air-side calculations | |||
CalcDoe2DXCoil(state, DXCoilNum, 1, FirstHVACIteration, PartLoadRatio, FanOpMode); | |||
CalcDoe2DXCoil(state, DXCoilNum, CompressorOperation::On, FirstHVACIteration, PartLoadRatio, FanOpMode); |
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 am not sure how many more of these kinds of things we have in EnergyPlus, but replacing integers with symbols is always a good thing. Make the code much more understandable and maintainable. This is a pattern we should propagate maximally.
S1PLR = PartLoadRatio; | ||
S2PLR = 0.0; | ||
} else { | ||
// If a two-stage coil | ||
// Run stage 1 at full load | ||
PerfMode = DehumidMode * 2 + 1; | ||
CalcDoe2DXCoil(state, DXCoilNum, On, FirstHVACIteration, 1.0, FanOpMode, PerfMode); | ||
CalcDoe2DXCoil(state, DXCoilNum, CompressorOperation::On, FirstHVACIteration, 1.0, FanOpMode, PerfMode); |
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.
Not part of this PR, but I would also like to see some kind of pattern where non-symbolic arguments are documented inline, e.g.,:
CalcDoe2DXCoil(state, DXCoilNum, CompressorOperation::On, FirstHVACIteration, /* PartLoadRatio */1.0, FanOpMode, PerfMode);
Or
CalcDoe2DXCoil(state, DXCoilNum, CompressorOperation::On, FirstHVACIteration,
1.0, // PartLoadRatio
FanOpMode, PerfMode);
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 like the first one, and never even thought of doing that.
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 like the first one also, but I think we are trying to avoid using C-style comments. @Myoldmopar, can you advise?
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.
Correct, we agreed to make C style comments illegal because they make parsing the code during refactors more difficult. We have a CI script that will fail if you add C style arguments, so the C++ style will be the way to go.
src/EnergyPlus/DXCoils.cc
Outdated
@@ -9534,7 +9536,7 @@ void CalcHPWHDXCoil(EnergyPlusData &state, | |||
|
|||
void CalcDoe2DXCoil(EnergyPlusData &state, | |||
int const DXCoilNum, // the number of the DX coil to be simulated | |||
int const CompOp, // compressor operation; 1=on, 0=off | |||
CompressorOperation const CompOp, // compressor operation; 1=on, 0=off |
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.
Same comment about name CompOp
.
src/EnergyPlus/DataHVACGlobals.hh
Outdated
// Compressor operation | ||
enum class CompressorOperation | ||
{ | ||
Unassigned = -1, |
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 think @mitchute is doing a pass that is converting Unassigned
to Invalid
.
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 will change this one in this PR.
} else { | ||
SetOnOffMassFlowRate(state, FurnaceNum, AirLoopNum, OnOffAirFlowRatio, OpMode, QZnReq, MoistureLoad, PartLoadRatio); | ||
CalcFurnaceOutput( | ||
state, FurnaceNum, false, 0, Off, 0.0, 0.0, 0.0, 0.0, SensibleOutput, LatentOutput, OnOffAirFlowRatio, false); | ||
CalcFurnaceOutput(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.
Why is this function called CalcFurnaceOutput
and not CalcFurnace
?
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.
There is another function called CalcFurnaceResidual
that calls CalcFurnaceOutput
. Shall I rename CalcFurnaceOutput
to CalcFurnace
?
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.
Don't bother. I shouldn't have said anything.
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/SZVAVModel.cc
Outdated
@@ -977,7 +977,7 @@ namespace SZVAVModel { | |||
bool const &HXUnitOn, |
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 thought we had gotten rid of these bool const &
and int const &
parameters.
|
||
} else if (SELECT_CASE_var == DataHVACGlobals::CoilDX_Cooling) { // CoilCoolingDX | ||
|
||
bool const singleMode = (this->m_SingleMode == 1); | ||
if (this->m_ControlType == ControlType::Setpoint) { | ||
if (this->m_CoolingSpeedNum > 1) { |
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.
Yeah, this type of stuff (casting enum
to double
) is not good. Should scrub this idiom.
// coil operation | ||
constexpr int CoilOn(1); // normal coil operation | ||
constexpr int CoilOff(0); // signal coil shouldn't run |
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 CoilOn
and CoilOff
variables were replaced with CompressorOperation::On
and CompressorOperation::Off
respectively. Reason: the argument of SimHXAssistedCoolingCoil()
where they are used signals compressor operation.
The comments have been addressed and this is ready for review. |
This one next? Seems like it is still ready for review, I'll pull develop and apply Clang Format here as well. |
Super happy here, merging. |
Thank you! :) |
Convert compressor operation from int constexpr to enum
This PR attempts to convert compressor operation in multiple files specified by int constexpr to enum class.
Pull Request Author
Add to this list or remove from it as applicable. This is a simple templated set of guidelines.
Reviewer
This will not be exhaustively relevant to every PR.