Skip to content

Commit

Permalink
Revamp the routine to take more references to shorten the code, scope…
Browse files Browse the repository at this point in the history
… the variables, initialize them, don't check 4 times if CurZoneEqNum is > 0
  • Loading branch information
jmarrec committed Aug 21, 2024
1 parent 52ffb00 commit 5dbc7b1
Showing 1 changed file with 68 additions and 81 deletions.
149 changes: 68 additions & 81 deletions src/EnergyPlus/WindowAC.cc
Original file line number Diff line number Diff line change
Expand Up @@ -900,30 +900,19 @@ namespace WindowAC {
static constexpr std::string_view RoutineName("SizeWindowAC: "); // include trailing blank space

// SUBROUTINE LOCAL VARIABLE DECLARATIONS:
Real64 MaxAirVolFlowDes; // Autosized maximum air flow for reporting
Real64 MaxAirVolFlowUser; // Hardsized maximum air flow for reporting
Real64 OutAirVolFlowDes; // Autosized outdoor air flow for reporting
Real64 OutAirVolFlowUser; // Hardsized outdoor ari flow for reporting
bool IsAutoSize; // Indicator to autosize
std::string CompName; // component name
std::string CompType; // component type
std::string SizingString; // input field sizing description (e.g., Nominal Capacity)
Real64 TempSize; // autosized value of coil input field
int FieldNum = 2; // IDD numeric field number where input field description is found
int SizingMethod; // Integer representation of sizing method name (e.g., CoolingAirflowSizing, HeatingAirflowSizing, CoolingCapacitySizing,
// HeatingCapacitySizing, etc.)
bool PrintFlag; // TRUE when sizing information is reported in the eio file
int zoneHVACIndex; // index of zoneHVAC equipment sizing specification
int SAFMethod(0); // supply air flow rate sizing method (SupplyAirFlowRate, FlowPerFloorArea, FractionOfAutosizedCoolingAirflow,
// FractionOfAutosizedHeatingAirflow ...)
int CapSizingMethod(0); // capacity sizing methods (HeatingDesignCapacity, CapacityPerFloorArea, FractionOfAutosizedCoolingCapacity, and
// FractionOfAutosizedHeatingCapacity )

IsAutoSize = false;
MaxAirVolFlowDes = 0.0;
MaxAirVolFlowUser = 0.0;
OutAirVolFlowDes = 0.0;
OutAirVolFlowUser = 0.0;
auto &windowAC = state.dataWindowAC->WindAC(WindACNum);

Real64 MaxAirVolFlowDes = 0.0; // Autosized maximum air flow for reporting
Real64 MaxAirVolFlowUser = 0.0; // Hardsized maximum air flow for reporting
Real64 OutAirVolFlowDes = 0.0; // Autosized outdoor air flow for reporting
Real64 OutAirVolFlowUser = 0.0; // Hardsized outdoor ari flow for reporting
bool IsAutoSize = false; // Indicator to autosize
std::string const CompType = "ZoneHVAC:WindowAirConditioner"; // component name
std::string const CompName = windowAC.Name; // component type
Real64 TempSize = AutoSize; // autosized value of coil input field
int FieldNum = 2; // IDD numeric field number where input field description is found
bool PrintFlag = false; // TRUE when sizing information is reported in the eio file

state.dataSize->DataFracOfAutosizedCoolingAirflow = 1.0;
state.dataSize->DataFracOfAutosizedHeatingAirflow = 1.0;
state.dataSize->DataFracOfAutosizedCoolingCapacity = 1.0;
Expand All @@ -932,43 +921,47 @@ namespace WindowAC {
state.dataSize->ZoneHeatingOnlyFan = false;
state.dataSize->ZoneCoolingOnlyFan = true;
state.dataSize->DataScalableCapSizingON = false;
CompType = "ZoneHVAC:WindowAirConditioner";
CompName = state.dataWindowAC->WindAC(WindACNum).Name;
state.dataSize->DataZoneNumber = state.dataWindowAC->WindAC(WindACNum).ZonePtr;
state.dataSize->DataFanType = state.dataWindowAC->WindAC(WindACNum).fanType;
state.dataSize->DataFanIndex = state.dataWindowAC->WindAC(WindACNum).FanIndex;
state.dataSize->DataFanPlacement = state.dataWindowAC->WindAC(WindACNum).fanPlace;

auto &zoneEqSizing = state.dataSize->ZoneEqSizing(state.dataSize->CurZoneEqNum);
state.dataSize->DataZoneNumber = windowAC.ZonePtr;
state.dataSize->DataFanType = windowAC.fanType;
state.dataSize->DataFanIndex = windowAC.FanIndex;
state.dataSize->DataFanPlacement = windowAC.fanPlace;

if (state.dataSize->CurZoneEqNum > 0) {
if (state.dataWindowAC->WindAC(WindACNum).HVACSizingIndex > 0) {
zoneHVACIndex = state.dataWindowAC->WindAC(WindACNum).HVACSizingIndex;
auto &zoneEqSizing = state.dataSize->ZoneEqSizing(state.dataSize->CurZoneEqNum);

if (windowAC.HVACSizingIndex > 0) {
// N1 , \field Maximum Supply Air Flow Rate
SizingMethod = HVAC::CoolingAirflowSizing;

auto const &zoneHVACSizing = state.dataSize->ZoneHVACSizing(windowAC.HVACSizingIndex);

// Integer representation of sizing method name (e.g., CoolingAirflowSizing, HeatingAirflowSizing, CoolingCapacitySizing,
// HeatingCapacitySizing, etc.
int SizingMethod = HVAC::CoolingAirflowSizing;
PrintFlag = true;
SAFMethod = state.dataSize->ZoneHVACSizing(zoneHVACIndex).CoolingSAFMethod;
// supply air flow rate sizing method (SupplyAirFlowRate, FlowPerFloorArea, FractionOfAutosizedCoolingAirflow,
// FractionOfAutosizedHeatingAirflow)
int const SAFMethod = zoneHVACSizing.CoolingSAFMethod;
zoneEqSizing.SizingMethod(SizingMethod) = SAFMethod;
if (SAFMethod == None || SAFMethod == SupplyAirFlowRate || SAFMethod == FlowPerFloorArea ||
SAFMethod == FractionOfAutosizedCoolingAirflow) {
if (SAFMethod == SupplyAirFlowRate) {
if (state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxCoolAirVolFlow > 0.0) {
zoneEqSizing.AirVolFlow = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxCoolAirVolFlow;
if (zoneHVACSizing.MaxCoolAirVolFlow > 0.0) {
zoneEqSizing.AirVolFlow = zoneHVACSizing.MaxCoolAirVolFlow;
zoneEqSizing.SystemAirFlow = true;
}
TempSize = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxCoolAirVolFlow;
TempSize = zoneHVACSizing.MaxCoolAirVolFlow;
} else if (SAFMethod == FlowPerFloorArea) {
zoneEqSizing.SystemAirFlow = true;
zoneEqSizing.AirVolFlow = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxCoolAirVolFlow *
state.dataHeatBal->Zone(state.dataSize->DataZoneNumber).FloorArea;
zoneEqSizing.AirVolFlow =
zoneHVACSizing.MaxCoolAirVolFlow * state.dataHeatBal->Zone(state.dataSize->DataZoneNumber).FloorArea;
TempSize = zoneEqSizing.AirVolFlow;
state.dataSize->DataScalableSizingON = true;
} else if (SAFMethod == FractionOfAutosizedCoolingAirflow) {
state.dataSize->DataFracOfAutosizedCoolingAirflow = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxCoolAirVolFlow;
state.dataSize->DataFracOfAutosizedCoolingAirflow = zoneHVACSizing.MaxCoolAirVolFlow;
TempSize = AutoSize;
state.dataSize->DataScalableSizingON = true;
} else {
TempSize = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxCoolAirVolFlow;
TempSize = zoneHVACSizing.MaxCoolAirVolFlow;
}
bool errorsFound = false;
CoolingAirFlowSizer sizingCoolingAirFlow;
Expand All @@ -977,25 +970,25 @@ namespace WindowAC {
stringOverride = "maximum_supply_air_flow_rate [m3/s]";
}
sizingCoolingAirFlow.overrideSizingString(stringOverride);
// sizingCoolingAirFlow.setHVACSizingIndexData(FanCoil(FanCoilNum).HVACSizingIndex);
// sizingCoolingAirFlow.setHVACSizingIndexData(windowAC.HVACSizingIndex);
sizingCoolingAirFlow.initializeWithinEP(state, CompType, CompName, PrintFlag, RoutineName);
state.dataWindowAC->WindAC(WindACNum).MaxAirVolFlow = sizingCoolingAirFlow.size(state, TempSize, errorsFound);
windowAC.MaxAirVolFlow = sizingCoolingAirFlow.size(state, TempSize, errorsFound);

} else if (SAFMethod == FlowPerCoolingCapacity) {
SizingMethod = CoolingCapacitySizing;
SizingMethod = HVAC::CoolingCapacitySizing;
TempSize = AutoSize;
PrintFlag = false;
state.dataSize->DataScalableSizingON = true;
state.dataSize->DataFlowUsedForSizing = state.dataSize->FinalZoneSizing(state.dataSize->CurZoneEqNum).DesCoolVolFlow;
if (state.dataSize->ZoneHVACSizing(zoneHVACIndex).CoolingCapMethod == FractionOfAutosizedCoolingCapacity) {
state.dataSize->DataFracOfAutosizedCoolingCapacity = state.dataSize->ZoneHVACSizing(zoneHVACIndex).ScaledCoolingCapacity;
if (zoneHVACSizing.CoolingCapMethod == FractionOfAutosizedCoolingCapacity) {
state.dataSize->DataFracOfAutosizedCoolingCapacity = zoneHVACSizing.ScaledCoolingCapacity;
}
bool errorsFound = false;
CoolingCapacitySizer sizerCoolingCapacity;
sizerCoolingCapacity.overrideSizingString(SizingString);
sizerCoolingCapacity.overrideSizingString("");
sizerCoolingCapacity.initializeWithinEP(state, CompType, CompName, PrintFlag, RoutineName);
state.dataSize->DataCapacityUsedForSizing = sizerCoolingCapacity.size(state, TempSize, errorsFound);
state.dataSize->DataFlowPerCoolingCapacity = state.dataSize->ZoneHVACSizing(zoneHVACIndex).MaxCoolAirVolFlow;
state.dataSize->DataFlowPerCoolingCapacity = zoneHVACSizing.MaxCoolAirVolFlow;
PrintFlag = true;
TempSize = AutoSize;
errorsFound = false;
Expand All @@ -1005,29 +998,31 @@ namespace WindowAC {
stringOverride = "maximum_supply_air_flow_rate [m3/s]";
}
sizingCoolingAirFlow.overrideSizingString(stringOverride);
// sizingCoolingAirFlow.setHVACSizingIndexData(FanCoil(FanCoilNum).HVACSizingIndex);
// sizingCoolingAirFlow.setHVACSizingIndexData(windowAC.HVACSizingIndex);
sizingCoolingAirFlow.initializeWithinEP(state, CompType, CompName, PrintFlag, RoutineName);
state.dataWindowAC->WindAC(WindACNum).MaxAirVolFlow = sizingCoolingAirFlow.size(state, TempSize, errorsFound);
windowAC.MaxAirVolFlow = sizingCoolingAirFlow.size(state, TempSize, errorsFound);
}
// DataScalableSizingON = false;

// initialize capacity sizing variables: cooling
CapSizingMethod = state.dataSize->ZoneHVACSizing(zoneHVACIndex).CoolingCapMethod;
// capacity sizing methods (HeatingDesignCapacity, CapacityPerFloorArea, FractionOfAutosizedCoolingCapacity, and
// FractionOfAutosizedHeatingCapacity )
int const CapSizingMethod = zoneHVACSizing.CoolingCapMethod;
zoneEqSizing.SizingMethod(SizingMethod) = CapSizingMethod;
if (CapSizingMethod == CoolingDesignCapacity || CapSizingMethod == CapacityPerFloorArea ||
CapSizingMethod == FractionOfAutosizedCoolingCapacity) {
if (CapSizingMethod == HeatingDesignCapacity) {
if (state.dataSize->ZoneHVACSizing(zoneHVACIndex).ScaledCoolingCapacity > 0.0) {
if (zoneHVACSizing.ScaledCoolingCapacity > 0.0) {
zoneEqSizing.CoolingCapacity = true;
zoneEqSizing.DesCoolingLoad = state.dataSize->ZoneHVACSizing(zoneHVACIndex).ScaledCoolingCapacity;
zoneEqSizing.DesCoolingLoad = zoneHVACSizing.ScaledCoolingCapacity;
}
} else if (CapSizingMethod == CapacityPerFloorArea) {
zoneEqSizing.CoolingCapacity = true;
zoneEqSizing.DesCoolingLoad = state.dataSize->ZoneHVACSizing(zoneHVACIndex).ScaledCoolingCapacity *
state.dataHeatBal->Zone(state.dataSize->DataZoneNumber).FloorArea;
zoneEqSizing.DesCoolingLoad =
zoneHVACSizing.ScaledCoolingCapacity * state.dataHeatBal->Zone(state.dataSize->DataZoneNumber).FloorArea;
state.dataSize->DataScalableCapSizingON = true;
} else if (CapSizingMethod == FractionOfAutosizedCoolingCapacity) {
state.dataSize->DataFracOfAutosizedCoolingCapacity = state.dataSize->ZoneHVACSizing(zoneHVACIndex).ScaledCoolingCapacity;
state.dataSize->DataFracOfAutosizedCoolingCapacity = zoneHVACSizing.ScaledCoolingCapacity;
state.dataSize->DataScalableCapSizingON = true;
}
}
Expand All @@ -1037,40 +1032,32 @@ namespace WindowAC {
// N1 , \field Maximum Supply Air Flow Rate
FieldNum = 1;
PrintFlag = true;
SizingString = state.dataWindowAC->WindACNumericFields(WindACNum).FieldNames(FieldNum) + " [m3/s]";
TempSize = state.dataWindowAC->WindAC(WindACNum).MaxAirVolFlow;
std::string stringOverride = state.dataWindowAC->WindACNumericFields(WindACNum).FieldNames(FieldNum) + " [m3/s]";
TempSize = windowAC.MaxAirVolFlow;
bool errorsFound = false;
SystemAirFlowSizer sizerSystemAirFlow;
sizerSystemAirFlow.overrideSizingString(SizingString);
// sizerSystemAirFlow.setHVACSizingIndexData(FanCoil(FanCoilNum).HVACSizingIndex);
sizerSystemAirFlow.overrideSizingString(stringOverride);
// sizerSystemAirFlow.setHVACSizingIndexData(windowAC.HVACSizingIndex);
sizerSystemAirFlow.initializeWithinEP(state, CompType, CompName, PrintFlag, RoutineName);
state.dataWindowAC->WindAC(WindACNum).MaxAirVolFlow = sizerSystemAirFlow.size(state, TempSize, errorsFound);
windowAC.MaxAirVolFlow = sizerSystemAirFlow.size(state, TempSize, errorsFound);
}
}

if (state.dataWindowAC->WindAC(WindACNum).OutAirVolFlow == AutoSize) {

if (state.dataSize->CurZoneEqNum > 0) {
if (windowAC.OutAirVolFlow == AutoSize) {

CheckZoneSizing(state,
state.dataWindowAC->cWindowAC_UnitTypes(state.dataWindowAC->WindAC(WindACNum).UnitType),
state.dataWindowAC->WindAC(WindACNum).Name);
state.dataWindowAC->WindAC(WindACNum).OutAirVolFlow =
min(state.dataSize->FinalZoneSizing(state.dataSize->CurZoneEqNum).MinOA, state.dataWindowAC->WindAC(WindACNum).MaxAirVolFlow);
if (state.dataWindowAC->WindAC(WindACNum).OutAirVolFlow < SmallAirVolFlow) {
state.dataWindowAC->WindAC(WindACNum).OutAirVolFlow = 0.0;
CheckZoneSizing(state, state.dataWindowAC->cWindowAC_UnitTypes(windowAC.UnitType), windowAC.Name);
windowAC.OutAirVolFlow = min(state.dataSize->FinalZoneSizing(state.dataSize->CurZoneEqNum).MinOA, windowAC.MaxAirVolFlow);
if (windowAC.OutAirVolFlow < SmallAirVolFlow) {
windowAC.OutAirVolFlow = 0.0;
}
BaseSizer::reportSizerOutput(state,
state.dataWindowAC->cWindowAC_UnitTypes(state.dataWindowAC->WindAC(WindACNum).UnitType),
state.dataWindowAC->WindAC(WindACNum).Name,
state.dataWindowAC->cWindowAC_UnitTypes(windowAC.UnitType),
windowAC.Name,
"Maximum Outdoor Air Flow Rate [m3/s]",
state.dataWindowAC->WindAC(WindACNum).OutAirVolFlow);
windowAC.OutAirVolFlow);
}
}

if (state.dataSize->CurZoneEqNum > 0) {
zoneEqSizing.OAVolFlow = state.dataWindowAC->WindAC(WindACNum).OutAirVolFlow;
zoneEqSizing.AirVolFlow = state.dataWindowAC->WindAC(WindACNum).MaxAirVolFlow;
zoneEqSizing.OAVolFlow = windowAC.OutAirVolFlow;
zoneEqSizing.AirVolFlow = windowAC.MaxAirVolFlow;
}

state.dataSize->DataScalableCapSizingON = false;
Expand Down

0 comments on commit 5dbc7b1

Please sign in to comment.