From 7284c443bdf6f72714932b83c9171e6667894047 Mon Sep 17 00:00:00 2001 From: Julien Marrec Date: Fri, 13 Dec 2024 12:36:21 +0100 Subject: [PATCH] Dry up code via a lambda --- src/EnergyPlus/FluidCoolers.cc | 91 ++++++++++------------------------ 1 file changed, 25 insertions(+), 66 deletions(-) diff --git a/src/EnergyPlus/FluidCoolers.cc b/src/EnergyPlus/FluidCoolers.cc index 6f5847d6050..a79f5167714 100644 --- a/src/EnergyPlus/FluidCoolers.cc +++ b/src/EnergyPlus/FluidCoolers.cc @@ -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)); @@ -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; @@ -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, @@ -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, @@ -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,