-
Notifications
You must be signed in to change notification settings - Fork 378
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
Quick Fan Cleanup #10462
Quick Fan Cleanup #10462
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.
Walk through.
thisOutsideAirSys.InletNodeNum(CompNum) = Fans::GetFanInletNode(state, typeNameUC, CompName, InletNodeErrFlag); | ||
thisOutsideAirSys.OutletNodeNum(CompNum) = Fans::GetFanOutletNode(state, typeNameUC, CompName, OutletNodeErrFlag); | ||
thisOutsideAirSys.InletNodeNum(CompNum) = Fans::GetFanInletNode(state, thisDOAS.m_FanIndex); | ||
thisOutsideAirSys.OutletNodeNum(CompNum) = Fans::GetFanOutletNode(state, thisDOAS.m_FanIndex); |
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.
All of these functions now take a FanIndex
as an argument rather than FanType
and FanName
strings. This is probably temporary. These functions can be deleted entirely in favor of direct access and this may happen soon. But at least the access idiom is proper now.
@@ -1085,7 +1086,7 @@ namespace AirflowNetwork { | |||
// Members | |||
Real64 FlowRate; // Air volume flow rate | |||
Real64 Ctrl; // Control ratio | |||
int FanTypeNum; // Fan type: Constant volume or ONOFF | |||
DataHVACGlobals::FanType fanType; // Fan type: Constant volume or ONOFF |
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.
Elevate all of these to enum class FanType
.
@@ -717,7 +714,7 @@ namespace AirflowNetwork { | |||
|
|||
int AirLoopNum = state.afn->AirflowNetworkLinkageData(i).AirLoopNum; | |||
|
|||
if (FanTypeNum == FanType_SimpleOnOff) { | |||
if (fanType == DataHVACGlobals::FanType::OnOff) { |
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 are all enum class FanType
now.
int inletNode; | ||
int outletNode; | ||
|
||
if (Util::SameString(Util::makeUPPER(fan_type), "FAN:SYSTEMMODEL")) { | ||
DataHVACGlobals::FanType fanType = |
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.
Use getEnumValue
since this is an enumeration now.
@@ -834,7 +834,7 @@ void CoilCoolingDX::simulate(EnergyPlusData &state, | |||
state.dataRptCoilSelection->coilSelectionReportObj->setCoilSupplyFanInfo(state, | |||
this->name, | |||
state.dataCoilCooingDX->coilCoolingDXObjectName, | |||
state.dataFans->Fan(this->supplyFanIndex).FanName, | |||
state.dataFans->Fan(this->supplyFanIndex).Name, |
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 name field of basically every other object is called Name
.
@@ -378,6 +382,13 @@ namespace DesiccantDehumidifiers { | |||
|
|||
desicDehum.RegenCoilType = Alphas(8); | |||
desicDehum.RegenCoilName = Alphas(9); | |||
|
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.
getEnumValue
and error shortcut patterns.
state.dataHVACFan->fanObjs.emplace_back(new HVACFan::FanSystem(state, thisZoneEvapUnit.FanName)); // call constructor | ||
thisZoneEvapUnit.FanIndex = HVACFan::getFanObjectVectorIndex(state, thisZoneEvapUnit.FanName); | ||
thisZoneEvapUnit.FanIndex = state.dataHVACFan->fanObjs.size() - 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.
No need to search for this object, since you know it's going to be at the end (you just put it there).
@@ -73,14 +74,6 @@ namespace EvaporativeCoolers { | |||
Num | |||
}; | |||
|
|||
enum class FanPlacement |
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.
Four.
|
||
void GetFanVolFlow(EnergyPlusData &state, int FanIndex, Real64 &FanVolFlow); | ||
Real64 GetFanVolFlow(EnergyPlusData &state, int FanIndex); |
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.
Return values via the return value.
src/EnergyPlus/Fans.hh
Outdated
std::string_view ThisObjectType = {}, // parent object type (for error message) | ||
std::string_view ThisObjectName = {} // parent object name (for error message) | ||
); | ||
DataHVACGlobals::FanType GetFanType(EnergyPlusData &state, int FanIndex); |
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.
Return values via the return value.
src/EnergyPlus/FanCoilUnits.cc
Outdated
if (errFlag) { | ||
ShowContinueError(state, format("specified in {} = \"{}\".", CurrentModuleObject, fanCoil.Name)); | ||
fanCoil.fanType = static_cast<DataHVACGlobals::FanType>(getEnumValue(DataHVACGlobals::fanTypeNamesUC, Alphas(9))); | ||
if (fanCoil.fanType == DataHVACGlobals::FanType::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.
Fan type is a choice field and cannot be invalid at this point.
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.
Ok, can change this to an assert
. I guess I should change all of them.
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? The assert will never fail.
assert(fanCoil.fantype != DataHVACGlobals::FanType::Invalid);
src/EnergyPlus/FanCoilUnits.cc
Outdated
ShowSevereItemNotFound(state, eoh, cAlphaFields(10), fanCoil.FanName); | ||
ErrorsFound = true; | ||
} else { | ||
assert(fanCoil.fanType == Fans::GetFanType(state, fanCoil.FanIndex)); |
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.
If a user selects the wrong fan object type in a fan coil unit there would be node connection warnings in release but no specific warning from the fan coil.
FanCoilAutoSize.idf:
ZoneHVAC:FourPipeFanCoil,
Fan:OnOff, !- Supply Air Fan Object Type
Zone1FanCoilFan, !- Supply Air Fan Name
Fan:ConstantVolume,
Zone1FanCoilFan, !- Name
** Warning ** Node Connection Error for object FAN:CONSTANTVOLUME=ZONE1FANCOILFAN
** ~~~ ** Air Nodes not on any Branch or Parent Object
** ~~~ ** Inlet Node : ZONE1FANCOILOAMIXEROUTLETNODE
** ~~~ ** Outlet Node: ZONE1FANCOILFANOUTLETNODE
** Warning ** Node Connection Error for object FAN:ONOFF=ZONE1FANCOILFAN
** ~~~ ** UNDEFINED not on any Branch or Parent Object
** ~~~ ** Inlet Node : ZONE1FANCOILOAMIXEROUTLETNODE
** ~~~ ** Outlet Node: UNDEFINED
In debug this assert will fail. I would suggest changing this to a severe warning. Using either this or a more detailed warning (probably the latter).
if (fanCoil.fanType != Fans::GetFanType(state, fanCoil.FanIndex)) {
ShowSevereItemNotFound(state, eoh, cAlphaFields(9), fanCoil.FanName);
ShowSevereItemNotFound(state, eoh, cAlphaFields(9), Alphas(9));
ErrorsFound = true;
}
** Severe ** GetFanCoilUnits: ZoneHVAC:FourPipeFanCoil = ZONE1FANCOIL
** ~~~ ** Supply Air Fan Name = ZONE1FANCOILFAN, item not found.
** Severe ** GetFanCoilUnits: ZoneHVAC:FourPipeFanCoil = ZONE1FANCOIL
** ~~~ ** Supply Air Fan Object Type = FAN:ONOFF, item not found.
** Fatal ** GetFanCoilUnits: Errors found in input. Preceding condition(s) cause termination.
src/EnergyPlus/IntegratedHeatPump.hh
Outdated
@@ -228,7 +228,7 @@ namespace IntegratedHeatPump { | |||
WHtankType(DataPlant::PlantEquipmentType::Invalid), WHtankID(0), LoopNum(0), LoopSideNum(0), IsWHCallAvail(false), CheckWHCall(false), | |||
CurMode(IHPOperationMode::Idle), ControlledZoneTemp(0), WaterFlowAccumVol(0), SHDWHRunTime(0), CoolVolFlowScale(0), HeatVolFlowScale(0), | |||
MaxHeatAirMassFlow(0), MaxHeatAirVolFlow(0), MaxCoolAirMassFlow(0), MaxCoolAirVolFlow(0), IHPCoilsSized(false), IDFanID(0), | |||
IDFanPlace(0), ODAirInletNodeNum(0), // oudoor coil inlet Nod | |||
fanPlace(DataHVACGlobals::FanPlace::Invalid), ODAirInletNodeNum(0), // oudoor coil inlet Nod |
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.
Unused variable, only change is in the header.
src/EnergyPlus/WindowAC.cc
Outdated
state.dataWindowAC->WindAC(WindACNum).fanType = | ||
static_cast<DataHVACGlobals::FanType>(getEnumValue(DataHVACGlobals::fanTypeNamesUC, Alphas(7))); | ||
if (state.dataWindowAC->WindAC(WindACNum).fanType == DataHVACGlobals::FanType::Invalid) { | ||
ShowSevereInvalidKey(state, eoh, cAlphaFields(7), Alphas(7)); |
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 way this new function (#10066) is used, after converting a choice field to an enum, I don't see how it can ever be called because the choice field should always return a valid enum and therefore not be Invalid. The IP would flag any invalid inputs.
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'm changing all of these to asserts. Thx.
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 assert would never execute. It would be dead code.
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're right. Why can't I remember this? FWIW they don't even compile in release code. So they are really a form of documentation more than anything else, but I will delete them.
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.
Actually I'm going to leave them in. They make me feel better and they don't affect performance.
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.
constexpr int getEnumValue(const gsl::span<const std::string_view> sList, const std::string_view s, const bool b)
{
for (unsigned int i = 0; i < sList.size(); ++i) {
if (sList[i] == s) return i;
}
if (b) assert(false);
return -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.
Don't even need the b
parameter.
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 agree, if getEnumValue is only used for choice fields.
@Myoldmopar, this is ready to merge. |
I'll get clang format settled. It also looks like CppCheck is complaining intensely about some uninitialized variables. And there's an enum related custom check. I'll get them fixed up and get this merged! |
Gotta give credit, it's not used now:
|
I plan to use it in the next PR or the one after (I decided to get this part merged before I tried something more aggressive). I would let this go for now (just like the asserts). |
I actually just commented it out locally and am doing final testing. If I leave it, then when I merge it in a minute, Custom Check will start failing for everyone's branches. It's still in there, just commented to hush the check. Is that OK? |
And as expected CppCheck is happy now. No need to wait on the other CI, merging this one. Thanks @amirroth |
I'm not going to press my luck here, so I will get this merged before I try something more drastic. The changes are:
enum class FanType
rather thatconstexpr int FanType_*
everywhere.enums
plus theconstexpr int
versions into a singleenum class FanPlace
and use everywhere. If you think I am joking, look at the diffs.FanName
only forGetFanIndex
and then takeFanIndex
everywhere else with the exception ofSimulate
(TODO).getEnumValue
and error shortcut patterns to places that were changed to useFanType
andFanPlace
.Everything is green.