Skip to content

Commit

Permalink
Dry up code via a lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarrec committed Dec 13, 2024
1 parent 9e8586b commit 7284c44
Showing 1 changed file with 25 additions and 66 deletions.
91 changes: 25 additions & 66 deletions src/EnergyPlus/FluidCoolers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -954,15 +954,13 @@ void FluidCoolerspecs::size(EnergyPlusData &state)
// Find the appropriate Plant Sizing object
int PltSizCondNum = state.dataPlnt->PlantLoop(this->plantLoc.loopNum).PlantSizNum;

if (this->DesignWaterFlowRateWasAutoSized) {
if (PltSizCondNum > 0) {
// This conditional statement is to trap when the user specified Condenser/Fluid Cooler water design setpoint
// temperature is less than design inlet air dry bulb temperature
if (state.dataSize->PlantSizData(PltSizCondNum).ExitTemp <= this->DesignEnteringAirTemp &&
state.dataPlnt->PlantFirstSizesOkayToFinalize) {
ShowSevereError(state, format("Error when autosizing the UA value for fluid cooler = {}.", this->Name));
ShowContinueError(state,
format("Design Loop Exit Temperature ({:.2R} C) must be greater than design entering air dry-bulb temperature "
// This is to trap when the user specified Condenser/Fluid Cooler water design setpoint temperature is less than design inlet air dry bulb
// temperature
auto ensureSizingPlantExitTempIsNotLessThanDesignEnteringAirTemp = [this, &state, PltSizCondNum]() {
if (state.dataSize->PlantSizData(PltSizCondNum).ExitTemp <= this->DesignEnteringAirTemp && state.dataPlnt->PlantFirstSizesOkayToFinalize) {
ShowSevereError(state, format("Error when autosizing the UA value for fluid cooler = {}.", this->Name));
ShowContinueError(state,
format("Design Loop Exit Temperature ({:.2R} C) must be greater than design entering air dry-bulb temperature "
"({:.2R} C) when autosizing the fluid cooler UA.",
state.dataSize->PlantSizData(PltSizCondNum).ExitTemp,
this->DesignEnteringAirTemp));
Expand All @@ -971,9 +969,15 @@ void FluidCoolerspecs::size(EnergyPlusData &state)
"design approach temperature (e.g., 4 C).");
ShowContinueError(state,
"If using HVACTemplate:Plant:ChilledWaterLoop, then check that input field Condenser Water Design Setpoint must be "
"> design inlet air dry-bulb temp if autosizing the Fluid Cooler.");
ShowFatalError(state, "Review and revise design input values as appropriate.");
}
"> design inlet air dry-bulb temp if autosizing the Fluid Cooler.");
ShowFatalError(state, "Review and revise design input values as appropriate.");
}
};

if (this->DesignWaterFlowRateWasAutoSized) {
if (PltSizCondNum > 0) {

ensureSizingPlantExitTempIsNotLessThanDesignEnteringAirTemp();

if (state.dataSize->PlantSizData(PltSizCondNum).DesVolFlowRate >= HVAC::SmallWaterVolFlow) {
tmpDesignWaterFlowRate = state.dataSize->PlantSizData(PltSizCondNum).DesVolFlowRate;
Expand Down Expand Up @@ -1039,24 +1043,9 @@ void FluidCoolerspecs::size(EnergyPlusData &state)
if (state.dataPlnt->PlantFirstSizesOkayToFinalize) this->HighSpeedFanPower = tmpHighSpeedFanPower;
} else if (PltSizCondNum > 0) {
if (state.dataSize->PlantSizData(PltSizCondNum).DesVolFlowRate >= HVAC::SmallWaterVolFlow) {
// This conditional statement is to trap when the user specified Condenser/Fluid Cooler water design setpoint
// temperature is less than design inlet air dry bulb temperature
if (state.dataSize->PlantSizData(PltSizCondNum).ExitTemp <= this->DesignEnteringAirTemp &&
state.dataPlnt->PlantFirstSizesOkayToFinalize) {
ShowSevereError(state, format("Error when autosizing the UA value for fluid cooler = {}.", this->Name));
ShowContinueError(state,
format("Design Loop Exit Temperature ({:.2R} C) must be greater than design entering air dry-bulb "
"temperature ({:.2R} C) when autosizing the fluid cooler UA.",
state.dataSize->PlantSizData(PltSizCondNum).ExitTemp,
this->DesignEnteringAirTemp));
ShowContinueError(state,
"It is recommended that the Design Loop Exit Temperature = design inlet air dry-bulb temp plus the "
"Fluid Cooler design approach temperature (e.g., 4 C).");
ShowContinueError(state,
"If using HVACTemplate:Plant:ChilledWaterLoop, then check that input field Condenser Water Design "
"Setpoint must be > design inlet air dry-bulb temp if autosizing the Fluid Cooler.");
ShowFatalError(state, "Review and revise design input values as appropriate.");
}

ensureSizingPlantExitTempIsNotLessThanDesignEnteringAirTemp();

rho = FluidProperties::GetDensityGlycol(state,
state.dataPlnt->PlantLoop(this->plantLoc.loopNum).FluidName,
Constant::InitConvTemp,
Expand Down Expand Up @@ -1128,24 +1117,9 @@ void FluidCoolerspecs::size(EnergyPlusData &state)
if (state.dataPlnt->PlantFirstSizesOkayToFinalize) this->HighSpeedAirFlowRate = tmpHighSpeedAirFlowRate;
} else if (PltSizCondNum > 0) {
if (state.dataSize->PlantSizData(PltSizCondNum).DesVolFlowRate >= HVAC::SmallWaterVolFlow) {
// This conditional statement is to trap when the user specified Condenser/Fluid Cooler water design setpoint
// temperature is less than design inlet air dry bulb temperature
if (state.dataSize->PlantSizData(PltSizCondNum).ExitTemp <= this->DesignEnteringAirTemp &&
state.dataPlnt->PlantFirstSizesOkayToFinalize) {
ShowSevereError(state, format("Error when autosizing the UA value for fluid cooler = {}.", this->Name));
ShowContinueError(state,
format("Design Loop Exit Temperature ({:.2R} C) must be greater than design entering air dry-bulb "
"temperature ({:.2R} C) when autosizing the fluid cooler UA.",
state.dataSize->PlantSizData(PltSizCondNum).ExitTemp,
this->DesignEnteringAirTemp));
ShowContinueError(state,
"It is recommended that the Design Loop Exit Temperature = design inlet air dry-bulb temp plus the "
"Fluid Cooler design approach temperature (e.g., 4 C).");
ShowContinueError(state,
"If using HVACTemplate:Plant:ChilledWaterLoop, then check that input field Condenser Water Design "
"Setpoint must be > design inlet air dry-bulb temp if autosizing the Fluid Cooler.");
ShowFatalError(state, "Review and revise design input values as appropriate.");
}

ensureSizingPlantExitTempIsNotLessThanDesignEnteringAirTemp();

rho = FluidProperties::GetDensityGlycol(state,
state.dataPlnt->PlantLoop(this->plantLoc.loopNum).FluidName,
Constant::InitConvTemp,
Expand Down Expand Up @@ -1210,24 +1184,9 @@ void FluidCoolerspecs::size(EnergyPlusData &state)
if (this->HighSpeedFluidCoolerUAWasAutoSized && state.dataPlnt->PlantFirstSizesOkayToFinalize) {
if (PltSizCondNum > 0) {
if (state.dataSize->PlantSizData(PltSizCondNum).DesVolFlowRate >= HVAC::SmallWaterVolFlow) {
// This conditional statement is to trap when the user specified Condenser/Fluid Cooler water design setpoint
// temperature is less than design inlet air dry bulb temperature
if (state.dataSize->PlantSizData(PltSizCondNum).ExitTemp <= this->DesignEnteringAirTemp &&
state.dataPlnt->PlantFirstSizesOkayToFinalize) {
ShowSevereError(state, format("Error when autosizing the UA value for fluid cooler = {}.", this->Name));
ShowContinueError(state,
format("Design Loop Exit Temperature ({:.2R} C) must be greater than design entering air dry-bulb "
"temperature ({:.2R} C) when autosizing the fluid cooler UA.",
state.dataSize->PlantSizData(PltSizCondNum).ExitTemp,
this->DesignEnteringAirTemp));
ShowContinueError(state,
"It is recommended that the Design Loop Exit Temperature = design inlet air dry-bulb temp plus the Fluid "
"Cooler design approach temperature (e.g., 4 C).");
ShowContinueError(state,
"If using HVACTemplate:Plant:ChilledWaterLoop, then check that input field Condenser Water Design Setpoint "
"must be > design inlet air dry-bulb temp if autosizing the Fluid Cooler.");
ShowFatalError(state, "Review and revise design input values as appropriate.");
}

ensureSizingPlantExitTempIsNotLessThanDesignEnteringAirTemp();

rho = FluidProperties::GetDensityGlycol(state,
state.dataPlnt->PlantLoop(this->plantLoc.loopNum).FluidName,
Constant::InitConvTemp,
Expand Down

3 comments on commit 7284c44

@nrel-bot-2c
Copy link

Choose a reason for hiding this comment

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

10817_CrashFluidCooler (jmarrec) - x86_64-Linux-Ubuntu-24.04-gcc-13.2: OK (2920 of 2920 tests passed, 0 test warnings)

Build Badge Test Badge

@nrel-bot-2c
Copy link

Choose a reason for hiding this comment

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

10817_CrashFluidCooler (jmarrec) - x86_64-Linux-Ubuntu-24.04-gcc-13.2-UnitTestsCoverage-RelWithDebInfo: OK (2102 of 2102 tests passed, 0 test warnings)

Build Badge Test Badge Coverage Badge

@nrel-bot-2c
Copy link

Choose a reason for hiding this comment

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

10817_CrashFluidCooler (jmarrec) - x86_64-Linux-Ubuntu-24.04-gcc-13.2-IntegrationCoverage-RelWithDebInfo: Coverage Too Low

Build Badge Test Badge Coverage Badge

Please sign in to comment.