From 6b43cd5cf0181c8fddb39fe711bfffd534754efb Mon Sep 17 00:00:00 2001 From: Richard Raustad Date: Sun, 15 Sep 2024 15:22:15 -0400 Subject: [PATCH 01/15] reduce, shadow and dup conditionals --- src/EnergyPlus/PoweredInductionUnits.cc | 50 ++++++++++++------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/src/EnergyPlus/PoweredInductionUnits.cc b/src/EnergyPlus/PoweredInductionUnits.cc index 07523f92033..c8f3dbfc799 100644 --- a/src/EnergyPlus/PoweredInductionUnits.cc +++ b/src/EnergyPlus/PoweredInductionUnits.cc @@ -263,7 +263,7 @@ void GetPIUs(EnergyPlusData &state) state.dataPowerInductionUnits->PiuUniqueNames.reserve(static_cast(state.dataPowerInductionUnits->NumPIUs)); state.dataPowerInductionUnits->CheckEquipName.dimension(state.dataPowerInductionUnits->NumPIUs, true); - int PIUNum{0}; + int PIUNum = 0; auto &ip = state.dataInputProcessing->inputProcessor; // loop over Series PIUs; get and load the input data for (const std::string cCurrentModuleObject : {"AirTerminal:SingleDuct:SeriesPIU:Reheat", "AirTerminal:SingleDuct:ParallelPIU:Reheat"}) { @@ -556,8 +556,8 @@ void GetPIUs(EnergyPlusData &state) ShowFatalError(state, format("{} Errors found in getting input. Preceding conditions cause termination.", RoutineName)); } - for (int PIUNum = 1; PIUNum <= state.dataPowerInductionUnits->NumPIUs; ++PIUNum) { - auto &thisPIU = state.dataPowerInductionUnits->PIU(PIUNum); + for (int PIURpt = 1; PIURpt <= state.dataPowerInductionUnits->NumPIUs; ++PIURpt) { + auto &thisPIU = state.dataPowerInductionUnits->PIU(PIURpt); // Setup Report variables for the PIUs SetupOutputVariable(state, @@ -608,35 +608,35 @@ void GetPIUs(EnergyPlusData &state) thisPIU.TotMassFlowRate, OutputProcessor::TimeStepType::System, OutputProcessor::StoreType::Average, - state.dataPowerInductionUnits->PIU(PIUNum).Name); + state.dataPowerInductionUnits->PIU(PIURpt).Name); SetupOutputVariable(state, "Zone Air Terminal Primary Air Mass Flow Rate", Constant::Units::kg_s, thisPIU.PriMassFlowRate, OutputProcessor::TimeStepType::System, OutputProcessor::StoreType::Average, - state.dataPowerInductionUnits->PIU(PIUNum).Name); + state.dataPowerInductionUnits->PIU(PIURpt).Name); SetupOutputVariable(state, "Zone Air Terminal Secondary Air Mass Flow Rate", Constant::Units::kg_s, thisPIU.SecMassFlowRate, OutputProcessor::TimeStepType::System, OutputProcessor::StoreType::Average, - state.dataPowerInductionUnits->PIU(PIUNum).Name); + state.dataPowerInductionUnits->PIU(PIURpt).Name); SetupOutputVariable(state, "Zone Air Terminal Outlet Discharge Air Temperature", Constant::Units::C, thisPIU.DischargeAirTemp, OutputProcessor::TimeStepType::System, OutputProcessor::StoreType::Average, - state.dataPowerInductionUnits->PIU(PIUNum).Name); + state.dataPowerInductionUnits->PIU(PIURpt).Name); SetupOutputVariable(state, "Zone Air Terminal Current Operation Control Stage", Constant::Units::unknown, thisPIU.CurOperationControlStage, OutputProcessor::TimeStepType::System, OutputProcessor::StoreType::Average, - state.dataPowerInductionUnits->PIU(PIUNum).Name); + state.dataPowerInductionUnits->PIU(PIURpt).Name); } } @@ -1230,8 +1230,6 @@ void SizePIU(EnergyPlusData &state, int const PIUNum) ShowContinueError(state, format("Occurs in{} Object={}", thisPIU.UnitType, thisPIU.Name)); ErrorsFound = true; } - } - if (IsAutoSize) { thisPIU.MaxVolHotWaterFlow = MaxVolHotWaterFlowDes; BaseSizer::reportSizerOutput( state, thisPIU.UnitType, thisPIU.Name, "Design Size Maximum Reheat Water Flow Rate [m3/s]", MaxVolHotWaterFlowDes); @@ -1327,8 +1325,6 @@ void SizePIU(EnergyPlusData &state, int const PIUNum) ShowContinueError(state, format("Occurs in{} Object={}", thisPIU.UnitType, thisPIU.Name)); ErrorsFound = true; } - } - if (IsAutoSize) { thisPIU.MaxVolHotSteamFlow = MaxVolHotSteamFlowDes; BaseSizer::reportSizerOutput( state, thisPIU.UnitType, thisPIU.Name, "Design Size Maximum Reheat Steam Flow [m3/s]", MaxVolHotSteamFlowDes); @@ -2076,18 +2072,18 @@ void CalcParallelPIU(EnergyPlusData &state, void ReportCurOperatingControlStage(EnergyPlusData &state, int const piuNum, bool const unitOn, HeatOpModeType heaterMode, CoolOpModeType coolingMode) { - int undetermined(-1); - int off(0); - int constantVolumeCooling(1); - int constantVolumeHeating(2); - int deadband(3); - int variableSpeedFirstStageCooling(4); - int variableSpeedSecondStageCooling(5); - int variableSpeedStagedHeatFirstStageHeating(6); - int variableSpeedStagedHeatSecondStageHeating(7); - int variableSpeedModulatedHeatFirstStageHeating(8); - int variableSpeedModulatedHeatSecondStageHeating(9); - int variableSpeedModulatedHeatThirdStageHeating(10); + int constexpr undetermined = -1; + int constexpr off = 0; + int constexpr constantVolumeCooling = 1; + int constexpr constantVolumeHeating = 2; + int constexpr deadband = 3; + int constexpr variableSpeedFirstStageCooling = 4; + int constexpr variableSpeedSecondStageCooling = 5; + int constexpr variableSpeedStagedHeatFirstStageHeating = 6; + int constexpr variableSpeedStagedHeatSecondStageHeating = 7; + int constexpr variableSpeedModulatedHeatFirstStageHeating = 8; + int constexpr variableSpeedModulatedHeatSecondStageHeating = 9; + int constexpr variableSpeedModulatedHeatThirdStageHeating = 10; state.dataPowerInductionUnits->PIU(piuNum).CurOperationControlStage = undetermined; @@ -2166,13 +2162,13 @@ void CalcVariableSpeedPIUCoolingBehavior(EnergyPlusData &state, } else { // check how much cooling provided at max fan and primary air state.dataLoopNodes->Node(thisPIU.PriAirInNode).MassFlowRate = thisPIU.MaxPriAirMassFlow; - Real64 TotAirMassFlow = thisPIU.MaxTotAirMassFlow; + TotAirMassFlow = thisPIU.MaxTotAirMassFlow; state.dataLoopNodes->Node(thisPIU.SecAirInNode).MassFlowRate = max(0.0, TotAirMassFlow - thisPIU.MaxPriAirMassFlow); Real64 qdotDelivMaxFan = CalcVariableSpeedPIUQdotDelivered(state, piuNum, zoneNode, false, TotAirMassFlow, 1.0); if (zoneLoad <= qdotDelivMaxFan) { // not going to make it just run at max thisPIU.PriAirMassFlow = thisPIU.PriAirMassFlow; - Real64 TotAirMassFlow = thisPIU.MaxTotAirMassFlow; + TotAirMassFlow = thisPIU.MaxTotAirMassFlow; thisPIU.SecAirMassFlow = max(0.0, TotAirMassFlow - thisPIU.PriAirMassFlow); thisPIU.heatingOperatingMode = HeatOpModeType::HeaterOff; thisPIU.coolingOperatingMode = CoolOpModeType::CoolSecondStage; @@ -2200,7 +2196,7 @@ void CalcVariableSpeedPIUCoolingBehavior(EnergyPlusData &state, ShowFatalError(state, format("Series PIU control failed for {}:{}", thisPIU.UnitType, thisPIU.Name)); } else { thisPIU.PriAirMassFlow = coolSignal * (thisPIU.MaxPriAirMassFlow - thisPIU.MinPriAirMassFlow) + thisPIU.MinPriAirMassFlow; - Real64 TotAirMassFlow = coolSignal * (thisPIU.MaxTotAirMassFlow - thisPIU.MinTotAirMassFlow) + thisPIU.MinTotAirMassFlow; + TotAirMassFlow = coolSignal * (thisPIU.MaxTotAirMassFlow - thisPIU.MinTotAirMassFlow) + thisPIU.MinTotAirMassFlow; thisPIU.SecAirMassFlow = max(0.0, TotAirMassFlow - thisPIU.PriAirMassFlow); thisPIU.heatingOperatingMode = HeatOpModeType::HeaterOff; thisPIU.coolingOperatingMode = CoolOpModeType::CoolFirstStage; From 30826ac75f37e84ac09880349ff3c8c8b7b55a74 Mon Sep 17 00:00:00 2001 From: Richard Raustad Date: Sun, 15 Sep 2024 15:43:55 -0400 Subject: [PATCH 02/15] reduce and clean --- src/EnergyPlus/Psychrometrics.cc | 43 ++++++-------------------------- src/EnergyPlus/Pumps.cc | 5 ++-- 2 files changed, 9 insertions(+), 39 deletions(-) diff --git a/src/EnergyPlus/Psychrometrics.cc b/src/EnergyPlus/Psychrometrics.cc index b1698cc608d..5507c31a7f4 100644 --- a/src/EnergyPlus/Psychrometrics.cc +++ b/src/EnergyPlus/Psychrometrics.cc @@ -285,8 +285,6 @@ namespace Psychrometrics { // FUNCTION INFORMATION: // AUTHOR Linda Lawrie/Amir Roth // DATE WRITTEN August 2011 - // MODIFIED na - // RE-ENGINEERED na // PURPOSE OF THIS FUNCTION: // Provide a "cache" of results for the given arguments and wetbulb (twb) output result. @@ -295,29 +293,9 @@ namespace Psychrometrics { // Use grid shifting and masking to provide hash into the cache. Use Equivalence to // make Fortran ignore "types". - // REFERENCES: - // na - - // USE STATEMENTS: - // na - - // Return value - Real64 Twb_result; // result=> Temperature Wet-Bulb {C} - - // Locals - // FUNCTION ARGUMENT DEFINITIONS: - // FUNCTION PARAMETER DEFINITIONS: std::uint64_t constexpr Grid_Shift = 64 - 12 - twbprecision_bits; - // INTERFACE BLOCK SPECIFICATIONS: - // na - - // DERIVED TYPE DEFINITIONS: - // na - - // FUNCTION LOCAL VARIABLE DECLARATIONS: - #ifdef EP_psych_stats ++state.dataPsychCache->NumTimesCalled[static_cast(PsychrometricFunction::TwbFnTdbWPb_cache)]; #endif @@ -359,11 +337,7 @@ namespace Psychrometrics { cached_Twb[hash].Twb = PsyTwbFnTdbWPb_raw(state, Tdb_tag_r, W_tag_r, Pb_tag_r, CalledFrom); } - // Twbresult_last = cached_Twb(hash)%Twb - // Twb_result = Twbresult_last - Twb_result = cached_Twb[hash].Twb; - - return Twb_result; + return cached_Twb[hash].Twb; } Real64 PsyTwbFnTdbWPb_raw(EnergyPlusData &state, @@ -420,14 +394,13 @@ namespace Psychrometrics { Real64 PSatstar; // Saturation pressure at wet bulb temperature int iter; // Iteration counter int icvg; // Iteration convergence flag - bool FlagError; // set when errors should be flagged #ifdef EP_psych_stats ++state.dataPsychCache->NumTimesCalled[static_cast(PsychrometricFunction::TwbFnTdbWPb)]; #endif // CHECK TDB IN RANGE. - FlagError = false; + bool FlagError = false; #ifdef EP_psych_errors if (TDB <= -100.0 || TDB >= 200.0) { if (!state.dataGlobal->WarmupFlag) { @@ -963,7 +936,7 @@ namespace Psychrometrics { if (H >= 0.0) { Hloc = max(0.00001, H); - } else if (H < 0.0) { + } else { Hloc = min(-0.00001, H); } @@ -1326,16 +1299,15 @@ namespace Psychrometrics { // na // FUNCTION LOCAL VARIABLE DECLARATIONS: - bool FlagError; // set when errors should be flagged - Real64 tSat; // Water temperature guess - int iter; // Iteration counter + Real64 tSat; // Water temperature guess + int iter; // Iteration counter #ifdef EP_psych_stats ++state.dataPsychCache->NumTimesCalled[static_cast(PsychrometricFunction::TsatFnPb)]; #endif // Check press in range. - FlagError = false; + bool FlagError = false; #ifdef EP_psych_errors if (!state.dataGlobal->WarmupFlag) { if (Press <= 0.0017 || Press >= 1555000.0) { @@ -1364,18 +1336,17 @@ namespace Psychrometrics { return state.dataPsychrometrics->tSat_Save; } state.dataPsychrometrics->Press_Save = Press; + iter = 0; if (state.dataPsychrometrics->useInterpolationPsychTsatFnPb) { int n_sample = 1651; // sample bin size = 64 Pa; continous sample size = 1651 // CSpline interpolation tSat = CSplineint(n_sample, Press); // Cubic spline interpolation - iter = 0; } else { // Uses an iterative process to determine the saturation temperature at a given // pressure by correlating saturated water vapor as a function of temperature. // Initial guess of boiling temperature tSat = 100.0; - iter = 0; // If above 1555000,set value of Temp corresponding to Saturation Pressure of 1555000 Pascal. if (Press >= 1555000.0) { diff --git a/src/EnergyPlus/Pumps.cc b/src/EnergyPlus/Pumps.cc index b22f78716f8..c688f9de87c 100644 --- a/src/EnergyPlus/Pumps.cc +++ b/src/EnergyPlus/Pumps.cc @@ -1369,9 +1369,7 @@ void InitializePumps(EnergyPlusData &state, int const PumpNum) int OutletNode; // pump outlet node number Real64 TotalEffic; Real64 SteamDensity; // Density of working fluid - int DummyWaterIndex(1); Real64 TempWaterDensity; - bool errFlag; Real64 mdotMax; // local fluid mass flow rate maximum Real64 mdotMin; // local fluid mass flow rate minimum int plloopnum; @@ -1387,7 +1385,7 @@ void InitializePumps(EnergyPlusData &state, int const PumpNum) // One time inits if (thisPump.PumpOneTimeFlag) { - errFlag = false; + bool errFlag = false; ScanPlantLoopsForObject(state, thisPump.Name, thisPump.TypeOf_Num, thisPump.plantLoc, errFlag, _, _, _, _, _); plloopnum = thisPump.plantLoc.loopNum; lsnum = thisPump.plantLoc.loopSideNum; @@ -1498,6 +1496,7 @@ void InitializePumps(EnergyPlusData &state, int const PumpNum) // Begin environment inits if (thisPump.PumpInitFlag && state.dataGlobal->BeginEnvrnFlag) { if (thisPump.pumpType == PumpType::Cond) { + int DummyWaterIndex = 1; TempWaterDensity = GetDensityGlycol(state, fluidNameWater, Constant::InitConvTemp, DummyWaterIndex, RoutineName); SteamDensity = GetSatDensityRefrig(state, fluidNameSteam, StartTemp, 1.0, thisPump.FluidIndex, RoutineName); From 610c2cfc8e92ad59964a50026af107d316807f28 Mon Sep 17 00:00:00 2001 From: Richard Raustad Date: Sun, 15 Sep 2024 16:22:31 -0400 Subject: [PATCH 03/15] reduce and const --- src/EnergyPlus/Pumps.cc | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/src/EnergyPlus/Pumps.cc b/src/EnergyPlus/Pumps.cc index c688f9de87c..d041f8492a3 100644 --- a/src/EnergyPlus/Pumps.cc +++ b/src/EnergyPlus/Pumps.cc @@ -240,7 +240,6 @@ void GetPumpInput(EnergyPlusData &state) int IOStat; // IO Status when calling get input subroutine bool ErrorsFound; int TempCurveIndex; - std::string TempCurveType; int NumVarSpeedPumps = 0; int NumConstSpeedPumps = 0; int NumCondensatePumps = 0; @@ -1365,44 +1364,38 @@ void InitializePumps(EnergyPlusData &state, int const PumpNum) static constexpr std::string_view RoutineName("PlantPumps::InitializePumps "); // SUBROUTINE LOCAL VARIABLE DECLARATIONS: - int InletNode; // pump inlet node number - int OutletNode; // pump outlet node number Real64 TotalEffic; Real64 SteamDensity; // Density of working fluid Real64 TempWaterDensity; Real64 mdotMax; // local fluid mass flow rate maximum Real64 mdotMin; // local fluid mass flow rate minimum - int plloopnum; DataPlant::LoopSideLocation lsnum; - int brnum; - int cpnum; // Set some variables for convenience auto &thisPump = state.dataPumps->PumpEquip(PumpNum); - InletNode = thisPump.InletNodeNum; - OutletNode = thisPump.OutletNodeNum; + int InletNode = thisPump.InletNodeNum; + int OutletNode = thisPump.OutletNodeNum; // One time inits if (thisPump.PumpOneTimeFlag) { bool errFlag = false; ScanPlantLoopsForObject(state, thisPump.Name, thisPump.TypeOf_Num, thisPump.plantLoc, errFlag, _, _, _, _, _); - plloopnum = thisPump.plantLoc.loopNum; + int plloopnum = thisPump.plantLoc.loopNum; lsnum = thisPump.plantLoc.loopSideNum; - brnum = thisPump.plantLoc.branchNum; - cpnum = thisPump.plantLoc.compNum; + int brnum = thisPump.plantLoc.branchNum; + int cpnum = thisPump.plantLoc.compNum; if (plloopnum > 0 && lsnum != DataPlant::LoopSideLocation::Invalid && brnum > 0 && cpnum > 0) { auto &thisPumpLoc = state.dataPlnt->PlantLoop(plloopnum).LoopSide(lsnum).Branch(brnum); - auto &thisLoopNodeID = state.dataLoopNodes->NodeID; if (thisPumpLoc.Comp(cpnum).NodeNumIn != InletNode || thisPumpLoc.Comp(cpnum).NodeNumOut != OutletNode) { ShowSevereError( state, format("InitializePumps: {}=\"{}\", non-matching nodes.", pumpTypeIDFNames[static_cast(thisPump.pumpType)], thisPump.Name)); ShowContinueError(state, format("...in Branch={}, Component referenced with:", thisPumpLoc.Name)); - ShowContinueError(state, format("...Inlet Node={}", thisLoopNodeID(thisPumpLoc.Comp(cpnum).NodeNumIn))); - ShowContinueError(state, format("...Outlet Node={}", thisLoopNodeID(thisPumpLoc.Comp(cpnum).NodeNumOut))); - ShowContinueError(state, format("...Pump Inlet Node={}", thisLoopNodeID(InletNode))); - ShowContinueError(state, format("...Pump Outlet Node={}", thisLoopNodeID(OutletNode))); + ShowContinueError(state, format("...Inlet Node={}", state.dataLoopNodes->NodeID(thisPumpLoc.Comp(cpnum).NodeNumIn))); + ShowContinueError(state, format("...Outlet Node={}", state.dataLoopNodes->NodeID(thisPumpLoc.Comp(cpnum).NodeNumOut))); + ShowContinueError(state, format("...Pump Inlet Node={}", state.dataLoopNodes->NodeID(InletNode))); + ShowContinueError(state, format("...Pump Outlet Node={}", state.dataLoopNodes->NodeID(OutletNode))); errFlag = true; } } else { // CR9292 @@ -1538,7 +1531,7 @@ void InitializePumps(EnergyPlusData &state, int const PumpNum) if (!state.dataGlobal->BeginEnvrnFlag) thisPump.PumpInitFlag = true; // zero out module level working variables - auto &daPumps = state.dataPumps; + auto const &daPumps = state.dataPumps; daPumps->PumpMassFlowRate = 0.0; daPumps->PumpHeattoFluid = 0.0; daPumps->Power = 0.0; @@ -1637,7 +1630,7 @@ void SetupPumpMinMaxFlows(EnergyPlusData &state, int const LoopNum, int const Pu // Let the user know that his input file is overconstrained } - auto &thisPumpPlant = state.dataPlnt->PlantLoop(thisPump.plantLoc.loopNum); + auto const &thisPumpPlant = state.dataPlnt->PlantLoop(thisPump.plantLoc.loopNum); switch (thisPump.pumpType) { case PumpType::VarSpeed: { @@ -2064,7 +2057,7 @@ void SizePump(EnergyPlusData &state, int const PumpNum) for (int BranchNum = 1; BranchNum <= thisPumpLoop.TotalBranches; ++BranchNum) { auto &thisPumpBranch = thisPumpLoop.Branch(BranchNum); for (int CompNum = 1; CompNum <= thisPumpBranch.TotalComponents; ++CompNum) { - auto &thisPumpComp = thisPumpBranch.Comp(CompNum); + auto const &thisPumpComp = thisPumpBranch.Comp(CompNum); if (thisPump.InletNodeNum == thisPumpComp.NodeNumIn && thisPump.OutletNodeNum == thisPumpComp.NodeNumOut) { if (thisPumpBranch.PumpSizFac > 0.0) { PumpSizFac = thisPumpBranch.PumpSizFac; @@ -2222,8 +2215,8 @@ void ReportPumps(EnergyPlusData &state, int const PumpNum) PumpType = thisPump.pumpType; OutletNode = thisPump.OutletNodeNum; - auto &thisOutNode = state.dataLoopNodes->Node(OutletNode); - auto &daPumps = state.dataPumps; + auto const &thisOutNode = state.dataLoopNodes->Node(OutletNode); + auto const &daPumps = state.dataPumps; if (daPumps->PumpMassFlowRate <= DataBranchAirLoopPlant::MassFlowTolerance) { new (&(state.dataPumps->PumpEquipReport(PumpNum))) ReportVars(); @@ -2347,7 +2340,7 @@ void GetRequiredMassFlowRate(EnergyPlusData &state, // Calculate maximum and minimum mass flow rate associated with maximun and minimum RPM if (thisPump.plantLoc.loopNum > 0) { - auto &thisPlantLoop = state.dataPlnt->PlantLoop(thisPump.plantLoc.loopNum); + auto const &thisPlantLoop = state.dataPlnt->PlantLoop(thisPump.plantLoc.loopNum); if (thisPlantLoop.UsePressureForPumpCalcs && thisPlantLoop.PressureSimType == DataPlant::PressSimType::FlowCorrection && thisPlantLoop.PressureDrop > 0.0) { thisPump.PumpMassFlowRateMaxRPM = ResolveLoopFlowVsPressure(state, @@ -2376,7 +2369,7 @@ void GetRequiredMassFlowRate(EnergyPlusData &state, // Calculate maximum and minimum mass flow rate associated with operating pressure range if (thisPump.plantLoc.loopNum > 0) { - auto &thisPlantLoop = state.dataPlnt->PlantLoop(LoopNum); + auto const &thisPlantLoop = state.dataPlnt->PlantLoop(LoopNum); if (thisPlantLoop.PressureEffectiveK > 0.0) { PumpMassFlowRateMaxPress = std::sqrt(MaxPress / thisPlantLoop.PressureEffectiveK); PumpMassFlowRateMinPress = std::sqrt(MinPress / thisPlantLoop.PressureEffectiveK); From ee7fbf0abbca2ba89234958b0b5fa9478f6a0b02 Mon Sep 17 00:00:00 2001 From: Richard Raustad Date: Sun, 15 Sep 2024 16:35:02 -0400 Subject: [PATCH 04/15] const and dup var --- src/EnergyPlus/ReportCoilSelection.cc | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/EnergyPlus/ReportCoilSelection.cc b/src/EnergyPlus/ReportCoilSelection.cc index defc4a2b2d2..aa489494c27 100644 --- a/src/EnergyPlus/ReportCoilSelection.cc +++ b/src/EnergyPlus/ReportCoilSelection.cc @@ -575,7 +575,7 @@ void ReportCoilSelection::doAirLoopSetup(EnergyPlusData &state, int const coilVe int zoneIndex = state.dataAirLoop->AirToZoneNodeInfo(c->airloopNum).HeatCtrlZoneNums(loopZone); // see if this zone is new or already in list bool found = false; - for (auto &z : c->zoneNum) { + for (auto const &z : c->zoneNum) { if (z == zoneIndex) { found = true; break; @@ -817,7 +817,6 @@ void ReportCoilSelection::doFinalProcessingOfCoilData(EnergyPlusData &state) c->coilDesWaterTempDiff = -999.0; c->plantDesCapacity = -999.0; c->coilCapPrcntPlantCap = -999.0; - c->coilFlowPrcntPlantFlow = -999.0; } c->cpDryAir = Psychrometrics::PsyCpAirFnW(0.0); @@ -1645,7 +1644,7 @@ void ReportCoilSelection::setCoilHeatingCapacity( } } else if (curZoneEqNum > 0 && allocated(state.dataSize->FinalZoneSizing)) { - auto &finalZoneSizing = state.dataSize->FinalZoneSizing(curZoneEqNum); + auto const &finalZoneSizing = state.dataSize->FinalZoneSizing(curZoneEqNum); c->zoneNum.resize(1); c->zoneName.resize(1); c->zoneNum[0] = curZoneEqNum; @@ -1667,7 +1666,7 @@ void ReportCoilSelection::setCoilHeatingCapacity( c->rmSensibleAtPeak = finalZoneSizing.DesHeatLoad; - auto &zoneEqSizing = state.dataSize->ZoneEqSizing(curZoneEqNum); + auto const &zoneEqSizing = state.dataSize->ZoneEqSizing(curZoneEqNum); if (zoneEqSizing.OAVolFlow > 0.0) { c->oaPeakVolFlow = zoneEqSizing.OAVolFlow; } else if (zoneEqSizing.ATMixerVolFlow > 0.0) { @@ -1809,15 +1808,15 @@ void ReportCoilSelection::setCoilHeatingCapacity( if (state.dataSize->DataFlowUsedForSizing > 0.0) { // flow has been set in global, so use it c->coilDesVolFlow = state.dataSize->DataFlowUsedForSizing; } else if (curZoneEqNum > 0 && allocated(state.dataSize->FinalZoneSizing)) { - auto &finalZoneSizing = state.dataSize->FinalZoneSizing(curZoneEqNum); + auto const &finalZoneSizing = state.dataSize->FinalZoneSizing(curZoneEqNum); if (finalZoneSizing.DesHeatMassFlow >= HVAC::SmallMassFlow) { c->coilDesMassFlow = finalZoneSizing.DesHeatMassFlow; c->coilDesVolFlow = c->coilDesMassFlow / state.dataEnvrn->StdRhoAir; } } else if (curSysNum > 0 && curSysNum <= int(state.dataSize->FinalSysSizing.size())) { - auto &finalSysSizing = state.dataSize->FinalSysSizing(curSysNum); + auto const &finalSysSizing = state.dataSize->FinalSysSizing(curSysNum); if (curOASysNum > 0 && allocated(state.dataSize->OASysEqSizing)) { - auto &oASysEqSizing = state.dataSize->OASysEqSizing(curSysNum); + auto const &oASysEqSizing = state.dataSize->OASysEqSizing(curSysNum); if (oASysEqSizing.AirFlow) { c->coilDesVolFlow = oASysEqSizing.AirVolFlow; } else if (oASysEqSizing.HeatingAirFlow) { @@ -1829,7 +1828,7 @@ void ReportCoilSelection::setCoilHeatingCapacity( if (state.dataSize->DataFlowUsedForSizing > 0.0) { c->coilDesVolFlow = state.dataSize->DataFlowUsedForSizing; } else if (curSysNum > 0 && allocated(state.dataSize->UnitarySysEqSizing)) { - auto &unitarySysEqSizing = state.dataSize->UnitarySysEqSizing(curSysNum); + auto const &unitarySysEqSizing = state.dataSize->UnitarySysEqSizing(curSysNum); if (unitarySysEqSizing.AirFlow) { c->coilDesVolFlow = unitarySysEqSizing.AirVolFlow; } else if (unitarySysEqSizing.HeatingAirFlow) { @@ -2060,7 +2059,7 @@ bool ReportCoilSelection::isCompTypeCoil(std::string const &compType // string c void ReportCoilSelection::setZoneLatentLoadCoolingIdealPeak(int const zoneIndex, Real64 const zoneCoolingLatentLoad) { // loop over all the coils and the zones in the coils and if this zone index is in the coil - for (auto &c : coilSelectionDataObjs) { + for (auto const &c : coilSelectionDataObjs) { if (c->isCooling) { for (std::size_t zoneInd = 0; zoneInd < c->zoneNum.size(); ++zoneInd) { @@ -2076,7 +2075,7 @@ void ReportCoilSelection::setZoneLatentLoadCoolingIdealPeak(int const zoneIndex, void ReportCoilSelection::setZoneLatentLoadHeatingIdealPeak(int const zoneIndex, Real64 const zoneHeatingLatentLoad) { // loop over all the coils and the zones in the coils and if this zone index is in the coil - for (auto &c : coilSelectionDataObjs) { + for (auto const &c : coilSelectionDataObjs) { if (c->isHeating) { for (std::size_t zoneInd = 0; zoneInd < c->zoneNum.size(); ++zoneInd) { From e6aa09e1db9a442dd39e68cfb23402bbb97b5132 Mon Sep 17 00:00:00 2001 From: Richard Raustad Date: Sun, 15 Sep 2024 16:39:59 -0400 Subject: [PATCH 05/15] reduce and unused --- src/EnergyPlus/ResultsFramework.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/EnergyPlus/ResultsFramework.cc b/src/EnergyPlus/ResultsFramework.cc index 0649abad7e9..ffa6854ee30 100644 --- a/src/EnergyPlus/ResultsFramework.cc +++ b/src/EnergyPlus/ResultsFramework.cc @@ -715,8 +715,6 @@ namespace ResultsFramework { if (data.empty()) return; updateReportFreq(reportingFrequency); std::vector indices; - std::unordered_set seen; - std::string search_string; std::string reportFrequency = data.at("ReportFrequency").get(); if (reportFrequency == "Detailed-HVAC" || reportFrequency == "Detailed-Zone") { @@ -724,7 +722,7 @@ namespace ResultsFramework { } auto const &columns = data.at("Cols"); for (auto const &column : columns) { - search_string = + std::string search_string = fmt::format("{0} [{1}]({2})", column.at("Variable").get(), column.at("Units").get(), reportFrequency); auto found = std::find(outputVariables.begin(), outputVariables.end(), search_string); if (found == outputVariables.end()) { From 2709afe94357e11752232e7688f35c3e3a9cb15b Mon Sep 17 00:00:00 2001 From: Richard Raustad Date: Sun, 15 Sep 2024 16:44:52 -0400 Subject: [PATCH 06/15] reduce --- src/EnergyPlus/ReturnAirPathManager.cc | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/EnergyPlus/ReturnAirPathManager.cc b/src/EnergyPlus/ReturnAirPathManager.cc index 701d2edc1f0..be12c864a7b 100644 --- a/src/EnergyPlus/ReturnAirPathManager.cc +++ b/src/EnergyPlus/ReturnAirPathManager.cc @@ -111,17 +111,9 @@ namespace ReturnAirPathManager { using NodeInputManager::GetOnlySingleNode; using namespace DataLoopNode; - // Locals - int PathNum; - int CompNum; - int NumAlphas; - int NumNums; - int IOStat; - int Counter; //////////// hoisted into namespace //////////////////////////////////////////////// // static bool ErrorsFound( false ); //////////////////////////////////////////////////////////////////////////////////// - bool IsNotOK; // Flag to verify name bool ErrorsFound = false; @@ -133,10 +125,13 @@ namespace ReturnAirPathManager { state.dataZoneEquip->NumReturnAirPaths = state.dataInputProcessing->inputProcessor->getNumObjectsFound(state, cCurrentModuleObject); if (state.dataZoneEquip->NumReturnAirPaths > 0) { + int NumAlphas; + int NumNums; + int IOStat; state.dataZoneEquip->ReturnAirPath.allocate(state.dataZoneEquip->NumReturnAirPaths); - for (PathNum = 1; PathNum <= state.dataZoneEquip->NumReturnAirPaths; ++PathNum) { + for (int PathNum = 1; PathNum <= state.dataZoneEquip->NumReturnAirPaths; ++PathNum) { state.dataInputProcessing->inputProcessor->getObjectItem(state, cCurrentModuleObject, @@ -170,13 +165,14 @@ namespace ReturnAirPathManager { state.dataZoneEquip->ReturnAirPath(PathNum).ComponentName = ""; state.dataZoneEquip->ReturnAirPath(PathNum).ComponentIndex.allocate(state.dataZoneEquip->ReturnAirPath(PathNum).NumOfComponents); state.dataZoneEquip->ReturnAirPath(PathNum).ComponentIndex = 0; - Counter = 3; + int Counter = 3; - for (CompNum = 1; CompNum <= state.dataZoneEquip->ReturnAirPath(PathNum).NumOfComponents; ++CompNum) { + for (int CompNum = 1; CompNum <= state.dataZoneEquip->ReturnAirPath(PathNum).NumOfComponents; ++CompNum) { if ((Util::SameString(state.dataIPShortCut->cAlphaArgs(Counter), "AirLoopHVAC:ZoneMixer")) || (Util::SameString(state.dataIPShortCut->cAlphaArgs(Counter), "AirLoopHVAC:ReturnPlenum"))) { + bool IsNotOK; // Flag to verify name state.dataZoneEquip->ReturnAirPath(PathNum).ComponentType(CompNum) = state.dataIPShortCut->cAlphaArgs(Counter); state.dataZoneEquip->ReturnAirPath(PathNum).ComponentName(CompNum) = state.dataIPShortCut->cAlphaArgs(Counter + 1); ValidateComponent(state, From 96b6822531fb2dfeb6dad63636384992883a6975 Mon Sep 17 00:00:00 2001 From: Richard Raustad Date: Sun, 15 Sep 2024 16:57:13 -0400 Subject: [PATCH 07/15] reduce and const --- src/EnergyPlus/RoomAirModelAirflowNetwork.cc | 64 ++++++++++---------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/src/EnergyPlus/RoomAirModelAirflowNetwork.cc b/src/EnergyPlus/RoomAirModelAirflowNetwork.cc index 01fbcadae2a..5a76dd6d188 100644 --- a/src/EnergyPlus/RoomAirModelAirflowNetwork.cc +++ b/src/EnergyPlus/RoomAirModelAirflowNetwork.cc @@ -124,7 +124,7 @@ namespace RoomAir { // METHODOLOGY EMPLOYED: // calls subroutines (LOL) - auto &afnZoneInfo = state.dataRoomAir->AFNZoneInfo(zoneNum); + auto const &afnZoneInfo = state.dataRoomAir->AFNZoneInfo(zoneNum); // model control volume for each roomAir:node in the zone. for (int roomAirNodeNum = 1; roomAirNodeNum <= afnZoneInfo.NumOfAirNodes; ++roomAirNodeNum) { @@ -174,7 +174,6 @@ namespace RoomAir { Array1D_bool NodeFound; // True if a node is found. Array1D_bool EquipFound; - bool ErrorsFound = false; Array1D SupplyFrac; Array1D ReturnFrac; @@ -184,9 +183,9 @@ namespace RoomAir { for (int iZone = 1; iZone <= state.dataGlobal->NumOfZones; ++iZone) { auto &afnZoneInfo = state.dataRoomAir->AFNZoneInfo(iZone); if (!afnZoneInfo.IsUsed) continue; - int NumSurfs = 0; + int NumSurfs = 0; // NumSurfs isn't used anywhere? for (int spaceNum : state.dataHeatBal->Zone(iZone).spaceIndexes) { - auto &thisSpace = state.dataHeatBal->space(spaceNum); + auto const &thisSpace = state.dataHeatBal->space(spaceNum); NumSurfs += thisSpace.HTSurfaceLast - thisSpace.HTSurfaceFirst + 1; } @@ -231,7 +230,7 @@ namespace RoomAir { if (allocated(state.dataZoneEquip->ZoneEquipConfig) && allocated(state.dataZoneEquip->ZoneEquipList)) { int MaxNodeNum = 0; int MaxEquipNum = 0; - ErrorsFound = false; + bool ErrorsFound = false; for (int iZone = 1; iZone <= state.dataGlobal->NumOfZones; ++iZone) { if (!state.dataHeatBal->Zone(iZone).IsControlled) continue; MaxEquipNum = max(MaxEquipNum, state.dataZoneEquip->ZoneEquipList(iZone).NumOfEquipTypes); @@ -614,7 +613,7 @@ namespace RoomAir { // PURPOSE OF THIS SUBROUTINE: // update variables - auto &afnZoneInfo = state.dataRoomAir->AFNZoneInfo(zoneNum); + auto const &afnZoneInfo = state.dataRoomAir->AFNZoneInfo(zoneNum); if (!afnZoneInfo.IsUsed) return; @@ -788,7 +787,7 @@ namespace RoomAir { int surfCount = 0; for (int spaceNum : state.dataHeatBal->Zone(zoneNum).spaceIndexes) { - auto &thisSpace = state.dataHeatBal->space(spaceNum); + auto const &thisSpace = state.dataHeatBal->space(spaceNum); for (int SurfNum = thisSpace.HTSurfaceFirst; SurfNum <= thisSpace.HTSurfaceLast; ++SurfNum) { ++surfCount; if (afnZoneInfo.ControlAirNodeID == roomAirNodeNum) { @@ -936,7 +935,7 @@ namespace RoomAir { int surfCount = 1; for (int spaceNum : state.dataHeatBal->Zone(zoneNum).spaceIndexes) { - auto &thisSpace = state.dataHeatBal->space(spaceNum); + auto const &thisSpace = state.dataHeatBal->space(spaceNum); for (int SurfNum = thisSpace.HTSurfaceFirst; SurfNum <= thisSpace.HTSurfaceLast; ++SurfNum, ++surfCount) { auto const &surf = state.dataSurface->Surface(SurfNum); if (surf.Class == SurfaceClass::Window) continue; @@ -952,13 +951,13 @@ namespace RoomAir { if (!afnZoneInfo.Node(roomAirNodeNum).SurfMask(surfCount)) continue; } - auto &HMassConvInFD = state.dataMstBal->HMassConvInFD; - auto &RhoVaporSurfIn = state.dataMstBal->RhoVaporSurfIn; - auto &RhoVaporAirIn = state.dataMstBal->RhoVaporAirIn; + auto const &HMassConvInFD = state.dataMstBal->HMassConvInFD(SurfNum); + auto &RhoVaporSurfIn = state.dataMstBal->RhoVaporSurfIn(SurfNum); + auto &RhoVaporAirIn = state.dataMstBal->RhoVaporAirIn(SurfNum); if (surf.HeatTransferAlgorithm == DataSurfaces::HeatTransferModel::HAMT) { UpdateHeatBalHAMT(state, SurfNum); - SumHmAW += HMassConvInFD(SurfNum) * surf.Area * (RhoVaporSurfIn(SurfNum) - RhoVaporAirIn(SurfNum)); + SumHmAW += HMassConvInFD * surf.Area * (RhoVaporSurfIn - RhoVaporAirIn); Real64 RhoAirZone = PsyRhoAirFnPbTdbW( state, @@ -966,35 +965,34 @@ namespace RoomAir { state.dataZoneTempPredictorCorrector->zoneHeatBalance(surf.Zone).MAT, PsyRhFnTdbRhov(state, state.dataZoneTempPredictorCorrector->zoneHeatBalance(state.dataSurface->Surface(SurfNum).Zone).MAT, - RhoVaporAirIn(SurfNum), + RhoVaporAirIn, "RhoAirZone")); - Real64 Wsurf = - PsyWFnTdbRhPb(state, - state.dataHeatBalSurf->SurfTempInTmp(SurfNum), - PsyRhFnTdbRhov(state, state.dataHeatBalSurf->SurfTempInTmp(SurfNum), RhoVaporSurfIn(SurfNum), "Wsurf"), - state.dataEnvrn->OutBaroPress); + Real64 Wsurf = PsyWFnTdbRhPb(state, + state.dataHeatBalSurf->SurfTempInTmp(SurfNum), + PsyRhFnTdbRhov(state, state.dataHeatBalSurf->SurfTempInTmp(SurfNum), RhoVaporSurfIn, "Wsurf"), + state.dataEnvrn->OutBaroPress); - SumHmARa += HMassConvInFD(SurfNum) * surf.Area * RhoAirZone; - SumHmARaW += HMassConvInFD(SurfNum) * surf.Area * RhoAirZone * Wsurf; + SumHmARa += HMassConvInFD * surf.Area * RhoAirZone; + SumHmARaW += HMassConvInFD * surf.Area * RhoAirZone * Wsurf; } else if (surf.HeatTransferAlgorithm == DataSurfaces::HeatTransferModel::EMPD) { UpdateMoistureBalanceEMPD(state, SurfNum); - RhoVaporSurfIn(SurfNum) = state.dataMstBalEMPD->RVSurface(SurfNum); - - SumHmAW += HMassConvInFD(SurfNum) * surf.Area * (RhoVaporSurfIn(SurfNum) - RhoVaporAirIn(SurfNum)); - SumHmARa += HMassConvInFD(SurfNum) * surf.Area * - PsyRhoAirFnPbTdbW( - state, - state.dataEnvrn->OutBaroPress, - state.dataHeatBalSurf->SurfTempInTmp(SurfNum), - PsyWFnTdbRhPb(state, - state.dataHeatBalSurf->SurfTempInTmp(SurfNum), - PsyRhFnTdbRhovLBnd0C(state, state.dataHeatBalSurf->SurfTempInTmp(SurfNum), RhoVaporAirIn(SurfNum)), - state.dataEnvrn->OutBaroPress)); - SumHmARaW += HMassConvInFD(SurfNum) * surf.Area * RhoVaporSurfIn(SurfNum); + RhoVaporSurfIn = state.dataMstBalEMPD->RVSurface(SurfNum); + + SumHmAW += HMassConvInFD * surf.Area * (RhoVaporSurfIn - RhoVaporAirIn); + SumHmARa += + HMassConvInFD * surf.Area * + PsyRhoAirFnPbTdbW(state, + state.dataEnvrn->OutBaroPress, + state.dataHeatBalSurf->SurfTempInTmp(SurfNum), + PsyWFnTdbRhPb(state, + state.dataHeatBalSurf->SurfTempInTmp(SurfNum), + PsyRhFnTdbRhovLBnd0C(state, state.dataHeatBalSurf->SurfTempInTmp(SurfNum), RhoVaporAirIn), + state.dataEnvrn->OutBaroPress)); + SumHmARaW += HMassConvInFD * surf.Area * RhoVaporSurfIn; } } // for (SurfNum) } // for (spaceNum) From ad5337a6b531f6abf72d3efe04fb50e49d181c44 Mon Sep 17 00:00:00 2001 From: Richard Raustad Date: Sun, 15 Sep 2024 17:15:22 -0400 Subject: [PATCH 08/15] const and reduce --- src/EnergyPlus/RoomAirModelManager.cc | 48 ++++++++++++--------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/src/EnergyPlus/RoomAirModelManager.cc b/src/EnergyPlus/RoomAirModelManager.cc index 4d4057c42af..7edcb321faf 100644 --- a/src/EnergyPlus/RoomAirModelManager.cc +++ b/src/EnergyPlus/RoomAirModelManager.cc @@ -346,7 +346,7 @@ namespace RoomAir { // figure number of surfaces for this zone airPatternZoneInfo.totNumSurfs = 0; for (int spaceNum : state.dataHeatBal->Zone(ZoneNum).spaceIndexes) { - auto &thisSpace = state.dataHeatBal->space(spaceNum); + auto const &thisSpace = state.dataHeatBal->space(spaceNum); airPatternZoneInfo.totNumSurfs += thisSpace.HTSurfaceLast - thisSpace.HTSurfaceFirst + 1; } // allocate nested derived type for surface info @@ -355,7 +355,7 @@ namespace RoomAir { // Fill in what we know for nested structure for surfaces int thisSurfinZone = 0; for (int spaceNum : state.dataHeatBal->Zone(ZoneNum).spaceIndexes) { - auto &thisSpace = state.dataHeatBal->space(spaceNum); + auto const &thisSpace = state.dataHeatBal->space(spaceNum); for (int thisHBsurfID = thisSpace.HTSurfaceFirst; thisHBsurfID <= thisSpace.HTSurfaceLast; ++thisHBsurfID) { ++thisSurfinZone; if (state.dataSurface->Surface(thisHBsurfID).Class == DataSurfaces::SurfaceClass::IntMass) { @@ -696,7 +696,7 @@ namespace RoomAir { } else { int NumOfSurfs = 0; for (int spaceNum : state.dataHeatBal->Zone(airNode.ZonePtr).spaceIndexes) { - auto &thisSpace = state.dataHeatBal->space(spaceNum); + auto const &thisSpace = state.dataHeatBal->space(spaceNum); NumOfSurfs += thisSpace.HTSurfaceLast - thisSpace.HTSurfaceFirst + 1; } airNode.SurfMask.allocate(NumOfSurfs); @@ -744,7 +744,7 @@ namespace RoomAir { auto const &zone = state.dataHeatBal->Zone(airNode.ZonePtr); int NumOfSurfs = 0; for (int spaceNum : zone.spaceIndexes) { - auto &thisSpace = state.dataHeatBal->space(spaceNum); + auto const &thisSpace = state.dataHeatBal->space(spaceNum); NumOfSurfs += thisSpace.HTSurfaceLast - thisSpace.HTSurfaceFirst + 1; } @@ -763,7 +763,7 @@ namespace RoomAir { for (int ListSurfNum = 4; ListSurfNum <= NumAlphas; ++ListSurfNum) { int thisSurfinZone = 0; for (int spaceNum : zone.spaceIndexes) { - auto &thisSpace = state.dataHeatBal->space(spaceNum); + auto const &thisSpace = state.dataHeatBal->space(spaceNum); for (int SurfNum = thisSpace.HTSurfaceFirst; SurfNum <= thisSpace.HTSurfaceLast; ++SurfNum) { ++thisSurfinZone; if (ipsc->cAlphaArgs(ListSurfNum) == state.dataSurface->Surface(SurfNum).Name) { @@ -1339,7 +1339,7 @@ namespace RoomAir { roomAFNZoneInfo.totNumSurfs = 0; for (int spaceNum : state.dataHeatBal->Zone(ZoneNum).spaceIndexes) { - auto &thisSpace = state.dataHeatBal->space(spaceNum); + auto const &thisSpace = state.dataHeatBal->space(spaceNum); roomAFNZoneInfo.totNumSurfs += thisSpace.HTSurfaceLast - thisSpace.HTSurfaceFirst + 1; } } // for (Loop) @@ -1429,7 +1429,7 @@ namespace RoomAir { int NumSurfsThisNode = NumAlphas - 1; int NumOfSurfs = 0; // What is this used for? for (int spaceNum : state.dataHeatBal->Zone(iZone).spaceIndexes) { - auto &thisSpace = state.dataHeatBal->space(spaceNum); + auto const &thisSpace = state.dataHeatBal->space(spaceNum); NumOfSurfs += thisSpace.HTSurfaceLast - thisSpace.HTSurfaceFirst + 1; } @@ -1451,7 +1451,7 @@ namespace RoomAir { int thisSurfinZone = 0; for (int ListSurfNum = 2; ListSurfNum <= NumAlphas; ++ListSurfNum) { for (int spaceNum : state.dataHeatBal->Zone(iZone).spaceIndexes) { - auto &thisSpace = state.dataHeatBal->space(spaceNum); + auto const &thisSpace = state.dataHeatBal->space(spaceNum); for (int SurfNum = thisSpace.HTSurfaceFirst; SurfNum <= thisSpace.HTSurfaceLast; ++SurfNum) { ++thisSurfinZone; if (ipsc->cAlphaArgs(ListSurfNum) == state.dataSurface->Surface(SurfNum).Name) { @@ -1648,13 +1648,11 @@ namespace RoomAir { roomAFNNodeHVAC.SupplyFraction = ipsc->rNumericArgs(iEquipArg); roomAFNNodeHVAC.ReturnFraction = ipsc->rNumericArgs(iEquipArg); - // get equipment index - int EquipIndex = 0; + // get equipment type for (int thisZoneEquipNum = 1; thisZoneEquipNum <= state.dataZoneEquip->ZoneEquipList(iZone).NumOfEquipTypes; ++thisZoneEquipNum) { if (Util::SameString(state.dataZoneEquip->ZoneEquipList(iZone).EquipName(thisZoneEquipNum), roomAFNNodeHVAC.Name) && roomAFNNodeHVAC.zoneEquipType == state.dataZoneEquip->ZoneEquipList(iZone).EquipType(thisZoneEquipNum)) { - EquipIndex = state.dataZoneEquip->ZoneEquipList(iZone).EquipIndex(thisZoneEquipNum); break; } } @@ -1841,18 +1839,16 @@ namespace RoomAir { state.dataRoomAir->HDoor = 0.0; int contWall = 0, contFloor = 0, contCeiling = 0, contWindow = 0, contInternal = 0, contDoor = 0; - int contWallBeg = 0, contFloorBeg = 0, contCeilingBeg = 0, contWindowBeg = 0, contInternalBeg = 0, contDoorBeg = 0; - int contWallLast = 0, contFloorLast = 0, contCeilingLast = 0, contWindowLast = 0, contInternalLast = 0, contDoorLast = 0; // Put the surface and zone information in Apos and PosZ arrays for (int ZNum = 1; ZNum <= state.dataGlobal->NumOfZones; ++ZNum) { // advance ONE position in the arrays PosZ because this is a new zone - contWallBeg = contWall + 1; - contFloorBeg = contFloor + 1; - contCeilingBeg = contCeiling + 1; - contWindowBeg = contWindow + 1; - contInternalBeg = contInternal + 1; - contDoorBeg = contDoor + 1; + int contWallBeg = contWall + 1; + int contFloorBeg = contFloor + 1; + int contCeilingBeg = contCeiling + 1; + int contWindowBeg = contWindow + 1; + int contInternalBeg = contInternal + 1; + int contDoorBeg = contDoor + 1; SetZoneAux = true; Real64 Z1ofZone = std::numeric_limits::max(); @@ -1860,7 +1856,7 @@ namespace RoomAir { // cycle in this zone for all the surfaces for (int spaceNum : state.dataHeatBal->Zone(ZNum).spaceIndexes) { - auto &thisSpace = state.dataHeatBal->space(spaceNum); + auto const &thisSpace = state.dataHeatBal->space(spaceNum); for (int SurfNum = thisSpace.HTSurfaceFirst; SurfNum <= thisSpace.HTSurfaceLast; ++SurfNum) { auto const &surf = state.dataSurface->Surface(SurfNum); @@ -1900,12 +1896,12 @@ namespace RoomAir { } } // for (SurfNum) - contWallLast = contWall; - contFloorLast = contFloor; - contCeilingLast = contCeiling; - contWindowLast = contWindow; - contDoorLast = contDoor; - contInternalLast = contInternal; + int contWallLast = contWall; + int contFloorLast = contFloor; + int contCeilingLast = contCeiling; + int contWindowLast = contWindow; + int contDoorLast = contDoor; + int contInternalLast = contInternal; // PosZ_Wall (... + 1) has the Begin Wall reference in Apos_Wall for the ZNum // PosZ_Wall (... + 2) has the End Wall reference in Apos_Wall for the ZNum state.dataRoomAir->PosZ_Wall(ZNum).beg = contWallBeg; From 2e0e6a78e7ca63ff6d63981b02fd4177b91df0c3 Mon Sep 17 00:00:00 2001 From: Richard Raustad Date: Sun, 15 Sep 2024 17:22:55 -0400 Subject: [PATCH 09/15] shadow, reduce and unused --- src/EnergyPlus/RoomAirModelManager.cc | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/EnergyPlus/RoomAirModelManager.cc b/src/EnergyPlus/RoomAirModelManager.cc index 7edcb321faf..5eea48174f5 100644 --- a/src/EnergyPlus/RoomAirModelManager.cc +++ b/src/EnergyPlus/RoomAirModelManager.cc @@ -1699,7 +1699,7 @@ namespace RoomAir { for (int iGain = 1; iGain <= roomAFNNode.NumIntGains; ++iGain) { auto &intGain = roomAFNNode.IntGain(iGain); if (intGain.FractionCheck) continue; - Real64 SumFraction = roomAFNNode.IntGainsFractions(iGain); + SumFraction = roomAFNNode.IntGainsFractions(iGain); intGain.FractionCheck = true; for (int iRoomAFNNode2 = 1; iRoomAFNNode2 <= roomAFNZoneInfo.NumOfAirNodes; ++iRoomAFNNode2) { @@ -1781,11 +1781,8 @@ namespace RoomAir { Real64 constexpr BaseDischargeCoef(0.62); // SUBROUTINE LOCAL VARIABLE DECLARATIONS: - bool SetZoneAux; Array1D_int AuxSurf; - int MaxSurf; Array2D_int AuxAirflowNetworkSurf; - int ZoneEquipConfigNum; // counter // Do the one time initializations if (state.dataRoomAir->MyOneTimeFlag) { @@ -1849,7 +1846,6 @@ namespace RoomAir { int contWindowBeg = contWindow + 1; int contInternalBeg = contInternal + 1; int contDoorBeg = contDoor + 1; - SetZoneAux = true; Real64 Z1ofZone = std::numeric_limits::max(); Real64 Z2ofZone = std::numeric_limits::lowest(); @@ -1944,7 +1940,7 @@ namespace RoomAir { } } // calculate maximum number of airflow network surfaces in a single zone - MaxSurf = AuxSurf(1); + int MaxSurf = AuxSurf(1); for (int iZone = 2; iZone <= state.dataGlobal->NumOfZones; ++iZone) { if (AuxSurf(iZone) > MaxSurf) MaxSurf = AuxSurf(iZone); } @@ -2452,7 +2448,7 @@ namespace RoomAir { if (state.dataRoomAir->AirModel(iZone).AirModel != RoomAirModel::CrossVent) continue; // don't set these up if they don't make sense - ZoneEquipConfigNum = ZoneNum; // Where does this ZoneNum come from? + int ZoneEquipConfigNum = ZoneNum; // Where does this ZoneNum come from? auto const &zone = state.dataHeatBal->Zone(iZone); // check whether this zone is a controlled zone or not From 8ef0a65f16910fd3a065a3c1907de754c280a5d7 Mon Sep 17 00:00:00 2001 From: Richard Raustad Date: Sun, 15 Sep 2024 17:26:46 -0400 Subject: [PATCH 10/15] const --- src/EnergyPlus/RoomAirModelUserTempPattern.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/EnergyPlus/RoomAirModelUserTempPattern.cc b/src/EnergyPlus/RoomAirModelUserTempPattern.cc index 6a0738ea74e..e59bb9cab2d 100644 --- a/src/EnergyPlus/RoomAirModelUserTempPattern.cc +++ b/src/EnergyPlus/RoomAirModelUserTempPattern.cc @@ -357,7 +357,7 @@ void FigureTwoGradInterpPattern(EnergyPlusData &state, int const PattrnID, int c Real64 Grad; // vertical temperature gradient C/m auto &patternZoneInfo = state.dataRoomAir->AirPatternZoneInfo(ZoneNum); - auto &pattern = state.dataRoomAir->AirPattern(PattrnID); + auto const &pattern = state.dataRoomAir->AirPattern(PattrnID); if (state.dataRoomAirModelTempPattern->MyOneTimeFlag2) { state.dataRoomAirModelTempPattern->SetupOutputFlag.dimension(state.dataGlobal->NumOfZones, true); // init @@ -491,7 +491,7 @@ void FigureConstGradPattern(EnergyPlusData &state, int const PattrnID, int const // DATE WRITTEN August 2005 auto &patternZoneInfo = state.dataRoomAir->AirPatternZoneInfo(ZoneNum); - auto &pattern = state.dataRoomAir->AirPattern(PattrnID); + auto const &pattern = state.dataRoomAir->AirPattern(PattrnID); Real64 Tmean = patternZoneInfo.TairMean; // MAT Real64 Grad = pattern.GradPatrn.Gradient; // Vertical temperature gradient @@ -539,7 +539,7 @@ Real64 FigureNDheightInZone(EnergyPlusData &state, int const thisHBsurf) // inde Real64 ZMin = 0.0; int Count = 0; for (int spaceNum : zone.spaceIndexes) { - auto &thisSpace = state.dataHeatBal->space(spaceNum); + auto const &thisSpace = state.dataHeatBal->space(spaceNum); for (int SurfNum = thisSpace.HTSurfaceFirst; SurfNum <= thisSpace.HTSurfaceLast; ++SurfNum) { auto const &surf = state.dataSurface->Surface(SurfNum); if (surf.Class == DataSurfaces::SurfaceClass::Floor) { @@ -644,7 +644,7 @@ void SetSurfHBDataForTempDistModel(EnergyPlusData &state, int const ZoneNum) // // What if ZoneNodeID is 0? auto &zoneNode = state.dataLoopNodes->Node(patternZoneInfo.ZoneNodeID); - auto &zone = state.dataHeatBal->Zone(ZoneNum); + auto const &zone = state.dataHeatBal->Zone(ZoneNum); auto &zoneHeatBal = state.dataZoneTempPredictorCorrector->zoneHeatBalance(ZoneNum); int ZoneMult = zone.Multiplier * zone.ListMultiplier; @@ -673,7 +673,7 @@ void SetSurfHBDataForTempDistModel(EnergyPlusData &state, int const ZoneNum) // if (zone.HasAirFlowWindowReturn) { for (int spaceNum : zone.spaceIndexes) { - auto &thisSpace = state.dataHeatBal->space(spaceNum); + auto const &thisSpace = state.dataHeatBal->space(spaceNum); for (int SurfNum = thisSpace.HTSurfaceFirst; SurfNum <= thisSpace.HTSurfaceLast; ++SurfNum) { if (state.dataSurface->SurfWinAirflowThisTS(SurfNum) > 0.0 && state.dataSurface->SurfWinAirflowDestination(SurfNum) == DataSurfaces::WindowAirFlowDestination::Return) { @@ -772,7 +772,7 @@ void SetSurfHBDataForTempDistModel(EnergyPlusData &state, int const ZoneNum) // // set results for all surface for (int spaceNum : zone.spaceIndexes) { - auto &thisSpace = state.dataHeatBal->space(spaceNum); + auto const &thisSpace = state.dataHeatBal->space(spaceNum); for (int i = thisSpace.HTSurfaceFirst, j = 0; i <= thisSpace.HTSurfaceLast; ++i) { state.dataHeatBal->SurfTempEffBulkAir(i) = patternZoneInfo.Surf(++j).TadjacentAir; } @@ -780,7 +780,7 @@ void SetSurfHBDataForTempDistModel(EnergyPlusData &state, int const ZoneNum) // // set flag for reference air temperature mode for (int spaceNum : zone.spaceIndexes) { - auto &thisSpace = state.dataHeatBal->space(spaceNum); + auto const &thisSpace = state.dataHeatBal->space(spaceNum); for (int i = thisSpace.HTSurfaceFirst; i <= thisSpace.HTSurfaceLast; ++i) { state.dataSurface->SurfTAirRef(i) = DataSurfaces::RefAirTemp::AdjacentAirTemp; state.dataSurface->SurfTAirRefRpt(i) = DataSurfaces::SurfTAirRefReportVals[state.dataSurface->SurfTAirRef(i)]; From 15be37a991ac2b8bdb2e033cdddc439e1d2b53dc Mon Sep 17 00:00:00 2001 From: Richard Raustad Date: Sun, 15 Sep 2024 17:46:51 -0400 Subject: [PATCH 11/15] reduce and conditionals always true --- src/EnergyPlus/RuntimeLanguageProcessor.cc | 40 +++++++--------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/src/EnergyPlus/RuntimeLanguageProcessor.cc b/src/EnergyPlus/RuntimeLanguageProcessor.cc index 55dc9cd6380..2f5bbbeda96 100644 --- a/src/EnergyPlus/RuntimeLanguageProcessor.cc +++ b/src/EnergyPlus/RuntimeLanguageProcessor.cc @@ -118,10 +118,10 @@ void InitializeRuntimeLanguage(EnergyPlusData &state) // value(7) Seconds (0-59) // value(8) Milliseconds (0-999) - std::string datestring; // supposedly returns blank when no date available. - if (state.dataRuntimeLangProcessor->InitializeOnce) { + std::string datestring; // supposedly returns blank when no date available. + state.dataRuntimeLang->emsVarBuiltInStart = state.dataRuntimeLang->NumErlVariables + 1; state.dataRuntimeLang->False = SetErlValueNumber(0.0); @@ -278,11 +278,9 @@ void BeginEnvrnInitializeRuntimeLanguage(EnergyPlusData &state) // SUBROUTINE LOCAL VARIABLE DECLARATIONS: int ActuatorUsedLoop; - int EMSActuatorVariableNum; int ErlVariableNum; int TrendVarNum; int SensorNum; - int TrendDepth; int loop; bool CycleThisVariable; @@ -319,7 +317,7 @@ void BeginEnvrnInitializeRuntimeLanguage(EnergyPlusData &state) // reinitialize state of actuators for (ActuatorUsedLoop = 1; ActuatorUsedLoop <= state.dataRuntimeLang->numActuatorsUsed + state.dataRuntimeLang->NumExternalInterfaceActuatorsUsed; ++ActuatorUsedLoop) { - EMSActuatorVariableNum = state.dataRuntimeLang->EMSActuatorUsed(ActuatorUsedLoop).ActuatorVariableNum; + int EMSActuatorVariableNum = state.dataRuntimeLang->EMSActuatorUsed(ActuatorUsedLoop).ActuatorVariableNum; ErlVariableNum = state.dataRuntimeLang->EMSActuatorUsed(ActuatorUsedLoop).ErlVariableNum; state.dataRuntimeLang->ErlVariable(ErlVariableNum).Value.Type = Value::Null; *state.dataRuntimeLang->EMSActuatorAvailable(EMSActuatorVariableNum).Actuated = false; @@ -340,7 +338,7 @@ void BeginEnvrnInitializeRuntimeLanguage(EnergyPlusData &state) // reinitialize trend variables so old data are purged for (TrendVarNum = 1; TrendVarNum <= state.dataRuntimeLang->NumErlTrendVariables; ++TrendVarNum) { - TrendDepth = state.dataRuntimeLang->TrendVariable(TrendVarNum).LogDepth; + int TrendDepth = state.dataRuntimeLang->TrendVariable(TrendVarNum).LogDepth; state.dataRuntimeLang->TrendVariable(TrendVarNum).TrendValARR({1, TrendDepth}) = 0.0; } @@ -1035,32 +1033,19 @@ void ParseExpression(EnergyPlusData &state, // AUTHOR Peter Graham Ellis // DATE WRITTEN June 2006 // MODIFIED Brent Griffith, May 2009 - // RE-ENGINEERED na // PURPOSE OF THIS SUBROUTINE: // Parsing string into a series of tokens - // METHODOLOGY EMPLOYED: - - // Using/Aliasing - - // Locals // SUBROUTINE PARAMETER DEFINITIONS: int constexpr MaxDoLoopCounts(500); - // SUBROUTINE ARGUMENT DEFINITIONS: - // SUBROUTINE LOCAL VARIABLE DECLARATIONS: // CHARACTER(len=120), DIMENSION(MaxErrors) :: Error ! Errors should be stored with the stack int NumErrors; std::string::size_type Pos; std::string StringToken; - char NextChar; bool PeriodFound; - bool MinusFound; - bool PlusFound; - bool MultFound; - bool DivFound; bool ErrorFlag; bool OperatorProcessing; int CountDoLooping; @@ -1088,9 +1073,9 @@ void ParseExpression(EnergyPlusData &state, std::string::size_type LastPos(String.length()); Pos = 0; OperatorProcessing = false; // true when an operator is found until terminated by non-operator - MinusFound = false; - MultFound = false; - DivFound = false; + bool MinusFound = false; + bool MultFound = false; + bool DivFound = false; while (Pos < LastPos) { ++CountDoLooping; if (CountDoLooping > MaxDoLoopCounts) { @@ -1099,7 +1084,7 @@ void ParseExpression(EnergyPlusData &state, ShowContinueError(state, format("...Failed to process String=\"{}\".", String)); ShowFatalError(state, "...program terminates due to preceding condition."); } - NextChar = String[Pos]; + char NextChar = String[Pos]; if (NextChar == ' ') { ++Pos; continue; @@ -1111,7 +1096,7 @@ void ParseExpression(EnergyPlusData &state, // Get the next token StringToken = ""; PeriodFound = false; - PlusFound = false; + bool PlusFound = false; ErrorFlag = false; LastED = false; if (is_any_of(NextChar, "0123456789.")) { @@ -1243,7 +1228,7 @@ void ParseExpression(EnergyPlusData &state, ShowContinueError(state, "...Use parenthesis to wrap appropriate variables. For example, X / ( -Y )."); ++NumErrors; DivFound = false; - } else if (OperatorProcessing && (NextChar == '-')) { + } else if (OperatorProcessing) { // if operator was deterined last pass and this character is a -, then insert a 0 before the minus and treat as subtraction // example: change "Var == -1" to "Var == 0-1" OperatorProcessing = false; @@ -1591,7 +1576,7 @@ int ProcessTokens( state.dataRuntimeLang->ErlExpression(ExpressionNum).Operand(5).Number = Token(Pos + 5).Number; state.dataRuntimeLang->ErlExpression(ExpressionNum).Operand(5).Expression = Token(Pos + 5).Expression; state.dataRuntimeLang->ErlExpression(ExpressionNum).Operand(5).Variable = Token(Pos + 5).Variable; - if ((NumOperands == 5) && (NumTokens - 6 > 0)) { // too many tokens for this non-binary operator + if ((NumTokens - 6) > 0) { // too many tokens for this non-binary operator ShowFatalError(state, "EMS error parsing tokens, too many for built-in function"); } } @@ -2865,8 +2850,7 @@ void GetRuntimeLanguageUserInput(EnergyPlusData &state) lAlphaFieldBlanks, cAlphaFieldNames, cNumericFieldNames); - } else if (GlobalNum > state.dataRuntimeLang->NumUserGlobalVariables && - GlobalNum <= state.dataRuntimeLang->NumUserGlobalVariables + state.dataRuntimeLang->NumExternalInterfaceGlobalVariables) { + } else if (GlobalNum <= state.dataRuntimeLang->NumUserGlobalVariables + state.dataRuntimeLang->NumExternalInterfaceGlobalVariables) { cCurrentModuleObject = "ExternalInterface:Variable"; state.dataInputProcessing->inputProcessor->getObjectItem(state, cCurrentModuleObject, From 0a73ab6ebff0066a02b6b1a3c319eed295581bf5 Mon Sep 17 00:00:00 2001 From: Richard Raustad Date: Sun, 15 Sep 2024 18:10:51 -0400 Subject: [PATCH 12/15] reduce and conditional always true --- src/EnergyPlus/RuntimeLanguageProcessor.cc | 50 +++++++++------------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/src/EnergyPlus/RuntimeLanguageProcessor.cc b/src/EnergyPlus/RuntimeLanguageProcessor.cc index 2f5bbbeda96..834e0d961b9 100644 --- a/src/EnergyPlus/RuntimeLanguageProcessor.cc +++ b/src/EnergyPlus/RuntimeLanguageProcessor.cc @@ -1427,7 +1427,6 @@ int ProcessTokens( int LastPos; int TokenNum; int NumTokens; - int Depth; int NumSubTokens; int NewNumTokens; int OperatorNum; @@ -1454,7 +1453,7 @@ int ProcessTokens( while ((Pos > 0) && (ParenthWhileCounter < 50)) { ++ParenthWhileCounter; - Depth = 0; + int Depth = 0; for (TokenNum = 1; TokenNum <= NumTokens; ++TokenNum) { if (Token(TokenNum).Type == Token::Parenthesis) { if (Token(TokenNum).Parenthesis == Token::ParenthesisLeft) { @@ -1718,15 +1717,10 @@ ErlValueType EvaluateExpression(EnergyPlusData &state, int const ExpressionNum, // FUNCTION ARGUMENT DEFINITIONS: // FUNCTION LOCAL VARIABLE DECLARATIONS: - int thisTrend; // local temporary - int thisIndex; // local temporary - Real64 thisAverage; // local temporary - int loop; // local temporary - Real64 thisSlope; // local temporary - Real64 thisMax; // local temporary - Real64 thisMin; // local temporary - int OperandNum; - int SeedN; // number of digits in the number used to seed the generator + Real64 thisAverage; // local temporary + Real64 thisSlope; // local temporary + Real64 thisMax; // local temporary + Real64 thisMin; // local temporary Array1D_int SeedIntARR; // local temporary for random seed Real64 tmpRANDU1; // local temporary for uniform random number Real64 tmpRANDU2; // local temporary for uniform random number @@ -1747,7 +1741,7 @@ ErlValueType EvaluateExpression(EnergyPlusData &state, int const ExpressionNum, // is there a way to keep these and not allocate and deallocate all the time? Operand.allocate(thisErlExpression.NumOperands); // Reduce operands down to literals - for (OperandNum = 1; OperandNum <= thisErlExpression.NumOperands; ++OperandNum) { + for (int OperandNum = 1; OperandNum <= thisErlExpression.NumOperands; ++OperandNum) { auto &thisOperand = Operand(OperandNum); thisOperand = thisErlExpression.Operand(OperandNum); if (thisOperand.Type == Value::Expression) { @@ -1778,6 +1772,8 @@ ErlValueType EvaluateExpression(EnergyPlusData &state, int const ExpressionNum, } if (ReturnValue.Type != Value::Error) { + int thisTrend; // local temporary + int thisIndex; // local temporary // Perform the operation @@ -2025,10 +2021,11 @@ ErlValueType EvaluateExpression(EnergyPlusData &state, int const ExpressionNum, break; case ErlFunc::RandSeed: + int SeedN; // number of digits in the number used to seed the generator // convert arg to an integer array for the seed. RANDOM_SEED(SeedN); // obtains processor's use size as output SeedIntARR.allocate(SeedN); - for (loop = 1; loop <= SeedN; ++loop) { + for (int loop = 1; loop <= SeedN; ++loop) { if (loop == 1) { SeedIntARR(loop) = std::floor(Operand(1).Number); } else { @@ -2319,7 +2316,7 @@ ErlValueType EvaluateExpression(EnergyPlusData &state, int const ExpressionNum, if (thisIndex == 1) { thisMax = state.dataRuntimeLang->TrendVariable(thisTrend).TrendValARR(1); } else { - for (loop = 2; loop <= thisIndex; ++loop) { + for (int loop = 2; loop <= thisIndex; ++loop) { if (loop == 2) { thisMax = max(state.dataRuntimeLang->TrendVariable(thisTrend).TrendValARR(1), state.dataRuntimeLang->TrendVariable(thisTrend).TrendValARR(2)); @@ -2353,7 +2350,7 @@ ErlValueType EvaluateExpression(EnergyPlusData &state, int const ExpressionNum, if (thisIndex == 1) { thisMin = state.dataRuntimeLang->TrendVariable(thisTrend).TrendValARR(1); } else { - for (loop = 2; loop <= thisIndex; ++loop) { + for (int loop = 2; loop <= thisIndex; ++loop) { if (loop == 2) { thisMin = min(state.dataRuntimeLang->TrendVariable(thisTrend).TrendValARR(1), state.dataRuntimeLang->TrendVariable(thisTrend).TrendValARR(2)); @@ -2707,13 +2704,6 @@ void GetRuntimeLanguageUserInput(EnergyPlusData &state) constexpr std::string_view RoutineName = "GetRuntimeLanguageUserInput: "; // SUBROUTINE LOCAL VARIABLE DECLARATIONS: - int GlobalNum; - int StackNum; - int ErrorNum; - int NumAlphas; // Number of elements in the alpha array - int NumNums; // Number of elements in the numeric array - int IOStat; // IO Status when calling get input subroutine - bool ErrorsFound(false); int VariableNum(0); // temporary int RuntimeReportVarNum; bool Found; @@ -2746,6 +2736,11 @@ void GetRuntimeLanguageUserInput(EnergyPlusData &state) if (state.dataRuntimeLangProcessor->GetInput) { // GetInput check is redundant with the InitializeRuntimeLanguage routine state.dataRuntimeLangProcessor->GetInput = false; + int StackNum; + int NumAlphas; // Number of elements in the alpha array + int NumNums; // Number of elements in the numeric array + int IOStat; // IO Status when calling get input subroutine + bool ErrorsFound = false; cCurrentModuleObject = "EnergyManagementSystem:Sensor"; state.dataInputProcessing->inputProcessor->getObjectDefMaxArgs(state, cCurrentModuleObject, TotalArgs, NumAlphas, NumNums); @@ -2829,7 +2824,7 @@ void GetRuntimeLanguageUserInput(EnergyPlusData &state) state.dataRuntimeLang->NumExternalInterfaceFunctionalMockupUnitImportGlobalVariables + state.dataRuntimeLang->NumExternalInterfaceFunctionalMockupUnitExportGlobalVariables > 0) { - for (GlobalNum = 1; + for (int GlobalNum = 1; GlobalNum <= state.dataRuntimeLang->NumUserGlobalVariables + state.dataRuntimeLang->NumExternalInterfaceGlobalVariables + state.dataRuntimeLang->NumExternalInterfaceFunctionalMockupUnitImportGlobalVariables + state.dataRuntimeLang->NumExternalInterfaceFunctionalMockupUnitExportGlobalVariables; @@ -2864,8 +2859,7 @@ void GetRuntimeLanguageUserInput(EnergyPlusData &state) lAlphaFieldBlanks, cAlphaFieldNames, cNumericFieldNames); - } else if (GlobalNum > state.dataRuntimeLang->NumUserGlobalVariables + state.dataRuntimeLang->NumExternalInterfaceGlobalVariables && - GlobalNum <= state.dataRuntimeLang->NumUserGlobalVariables + state.dataRuntimeLang->NumExternalInterfaceGlobalVariables + + } else if (GlobalNum <= state.dataRuntimeLang->NumUserGlobalVariables + state.dataRuntimeLang->NumExternalInterfaceGlobalVariables + state.dataRuntimeLang->NumExternalInterfaceFunctionalMockupUnitImportGlobalVariables) { cCurrentModuleObject = "ExternalInterface:FunctionalMockupUnitImport:To:Variable"; state.dataInputProcessing->inputProcessor->getObjectItem(state, @@ -2882,9 +2876,7 @@ void GetRuntimeLanguageUserInput(EnergyPlusData &state) cAlphaFieldNames, cNumericFieldNames); - } else if (GlobalNum > state.dataRuntimeLang->NumUserGlobalVariables + state.dataRuntimeLang->NumExternalInterfaceGlobalVariables + - state.dataRuntimeLang->NumExternalInterfaceFunctionalMockupUnitImportGlobalVariables && - GlobalNum <= state.dataRuntimeLang->NumUserGlobalVariables + state.dataRuntimeLang->NumExternalInterfaceGlobalVariables + + } else if (GlobalNum <= state.dataRuntimeLang->NumUserGlobalVariables + state.dataRuntimeLang->NumExternalInterfaceGlobalVariables + state.dataRuntimeLang->NumExternalInterfaceFunctionalMockupUnitImportGlobalVariables + state.dataRuntimeLang->NumExternalInterfaceFunctionalMockupUnitExportGlobalVariables) { cCurrentModuleObject = "ExternalInterface:FunctionalMockupUnitExport:To:Variable"; @@ -3224,7 +3216,7 @@ void GetRuntimeLanguageUserInput(EnergyPlusData &state) ShowSevereError( state, format("Errors found parsing EMS Runtime Language program or subroutine = {}", state.dataRuntimeLang->ErlStack(StackNum).Name)); - for (ErrorNum = 1; ErrorNum <= state.dataRuntimeLang->ErlStack(StackNum).NumErrors; ++ErrorNum) { + for (int ErrorNum = 1; ErrorNum <= state.dataRuntimeLang->ErlStack(StackNum).NumErrors; ++ErrorNum) { ShowContinueError(state, state.dataRuntimeLang->ErlStack(StackNum).Error(ErrorNum)); } ErrorsFound = true; From f70c84f72b612135ce34446e0a6e2da1a3706713 Mon Sep 17 00:00:00 2001 From: Richard Raustad Date: Sun, 15 Sep 2024 18:56:39 -0400 Subject: [PATCH 13/15] reduce --- src/EnergyPlus/RuntimeLanguageProcessor.cc | 27 +++++++++------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/EnergyPlus/RuntimeLanguageProcessor.cc b/src/EnergyPlus/RuntimeLanguageProcessor.cc index 834e0d961b9..6f73e1a7d43 100644 --- a/src/EnergyPlus/RuntimeLanguageProcessor.cc +++ b/src/EnergyPlus/RuntimeLanguageProcessor.cc @@ -2704,16 +2704,9 @@ void GetRuntimeLanguageUserInput(EnergyPlusData &state) constexpr std::string_view RoutineName = "GetRuntimeLanguageUserInput: "; // SUBROUTINE LOCAL VARIABLE DECLARATIONS: - int VariableNum(0); // temporary - int RuntimeReportVarNum; - bool Found; OutputProcessor::TimeStepType sovTimeStepType; // temporary OutputProcessor::StoreType sovStoreType; // temporary - std::string EndUseSubCatString; - int TrendNum; - int NumTrendSteps; - int loop; int ErlVarLoop; int CurveIndexNum; int MaxNumAlphas(0); // argument for call to GetObjectDefMaxArgs @@ -2741,6 +2734,8 @@ void GetRuntimeLanguageUserInput(EnergyPlusData &state) int NumNums; // Number of elements in the numeric array int IOStat; // IO Status when calling get input subroutine bool ErrorsFound = false; + int VariableNum = 0; // temporary + int RuntimeReportVarNum; cCurrentModuleObject = "EnergyManagementSystem:Sensor"; state.dataInputProcessing->inputProcessor->getObjectDefMaxArgs(state, cCurrentModuleObject, TotalArgs, NumAlphas, NumNums); @@ -2939,7 +2934,7 @@ void GetRuntimeLanguageUserInput(EnergyPlusData &state) state.dataRuntimeLang->NumEMSCurveIndices = state.dataInputProcessing->inputProcessor->getNumObjectsFound(state, cCurrentModuleObject); if (state.dataRuntimeLang->NumEMSCurveIndices > 0) { state.dataRuntimeLangProcessor->CurveIndexVariableNums.dimension(state.dataRuntimeLang->NumEMSCurveIndices, 0); - for (loop = 1; loop <= state.dataRuntimeLang->NumEMSCurveIndices; ++loop) { + for (int loop = 1; loop <= state.dataRuntimeLang->NumEMSCurveIndices; ++loop) { state.dataInputProcessing->inputProcessor->getObjectItem(state, cCurrentModuleObject, loop, @@ -2999,7 +2994,7 @@ void GetRuntimeLanguageUserInput(EnergyPlusData &state) state.dataRuntimeLang->NumEMSConstructionIndices = state.dataInputProcessing->inputProcessor->getNumObjectsFound(state, cCurrentModuleObject); if (state.dataRuntimeLang->NumEMSConstructionIndices > 0) { state.dataRuntimeLangProcessor->ConstructionIndexVariableNums.dimension(state.dataRuntimeLang->NumEMSConstructionIndices, 0); - for (loop = 1; loop <= state.dataRuntimeLang->NumEMSConstructionIndices; ++loop) { + for (int loop = 1; loop <= state.dataRuntimeLang->NumEMSConstructionIndices; ++loop) { state.dataInputProcessing->inputProcessor->getObjectItem(state, cCurrentModuleObject, loop, @@ -3137,7 +3132,7 @@ void GetRuntimeLanguageUserInput(EnergyPlusData &state) state.dataRuntimeLang->NumErlTrendVariables = state.dataInputProcessing->inputProcessor->getNumObjectsFound(state, cCurrentModuleObject); if (state.dataRuntimeLang->NumErlTrendVariables > 0) { state.dataRuntimeLang->TrendVariable.allocate(state.dataRuntimeLang->NumErlTrendVariables); - for (TrendNum = 1; TrendNum <= state.dataRuntimeLang->NumErlTrendVariables; ++TrendNum) { + for (int TrendNum = 1; TrendNum <= state.dataRuntimeLang->NumErlTrendVariables; ++TrendNum) { state.dataInputProcessing->inputProcessor->getObjectItem(state, cCurrentModuleObject, TrendNum, @@ -3172,7 +3167,7 @@ void GetRuntimeLanguageUserInput(EnergyPlusData &state) state.dataRuntimeLang->ErlVariable(VariableNum).Value.initialized = true; // Cannot figure out how to get around needing this, } - NumTrendSteps = std::floor(rNumericArgs(1)); + int NumTrendSteps = std::floor(rNumericArgs(1)); if (NumTrendSteps > 0) { state.dataRuntimeLang->TrendVariable(TrendNum).LogDepth = NumTrendSteps; // setup data arrays using NumTrendSteps @@ -3185,7 +3180,7 @@ void GetRuntimeLanguageUserInput(EnergyPlusData &state) // current time is zero, each value in trend log array is one zone timestep further back in time // units are hours. all terms negative, getting increasingly negative the further back in time // further back in time is higher index in array - for (loop = 1; loop <= NumTrendSteps; ++loop) { + for (int loop = 1; loop <= NumTrendSteps; ++loop) { if (loop == 1) { state.dataRuntimeLang->TrendVariable(TrendNum).TimeARR(loop) = -state.dataGlobal->TimeStepZone; continue; @@ -3309,7 +3304,7 @@ void GetRuntimeLanguageUserInput(EnergyPlusData &state) if (!lAlphaFieldBlanks(5)) { // Lookup the Runtime Language Context, i.e., PROGRAM, FUNCTION, or global - Found = false; + bool Found = false; for (StackNum = 1; StackNum <= state.dataRuntimeLang->NumErlStacks; ++StackNum) { if (state.dataRuntimeLang->ErlStack(StackNum).Name == cAlphaArgs(5)) { Found = true; @@ -3405,7 +3400,7 @@ void GetRuntimeLanguageUserInput(EnergyPlusData &state) if (state.dataRuntimeLang->NumEMSMeteredOutputVariables > 0) { cCurrentModuleObject = "EnergyManagementSystem:MeteredOutputVariable"; - for (loop = 1; loop <= state.dataRuntimeLang->NumEMSMeteredOutputVariables; ++loop) { + for (int loop = 1; loop <= state.dataRuntimeLang->NumEMSMeteredOutputVariables; ++loop) { RuntimeReportVarNum = state.dataRuntimeLang->NumEMSOutputVariables + loop; state.dataInputProcessing->inputProcessor->getObjectItem(state, cCurrentModuleObject, @@ -3482,7 +3477,7 @@ void GetRuntimeLanguageUserInput(EnergyPlusData &state) if (!lAlphaFieldBlanks(4)) { // Lookup the Runtime Language Context, i.e., PROGRAM, FUNCTION, or global - Found = false; + bool Found = false; for (StackNum = 1; StackNum <= state.dataRuntimeLang->NumErlStacks; ++StackNum) { if (state.dataRuntimeLang->ErlStack(StackNum).Name == cAlphaArgs(4)) { Found = true; @@ -3626,7 +3621,7 @@ void GetRuntimeLanguageUserInput(EnergyPlusData &state) } if (!lAlphaFieldBlanks(8)) { - EndUseSubCatString = cAlphaArgs(8); + std::string EndUseSubCatString = cAlphaArgs(8); SetupOutputVariable(state, cAlphaArgs(1), From 4f8867b07b66f3858999a3d25b1bde21abe5a1e0 Mon Sep 17 00:00:00 2001 From: Richard Raustad Date: Sun, 15 Sep 2024 19:16:47 -0400 Subject: [PATCH 14/15] reduce --- src/EnergyPlus/RuntimeLanguageProcessor.cc | 55 +++++----------------- 1 file changed, 12 insertions(+), 43 deletions(-) diff --git a/src/EnergyPlus/RuntimeLanguageProcessor.cc b/src/EnergyPlus/RuntimeLanguageProcessor.cc index 6f73e1a7d43..47894f1dd31 100644 --- a/src/EnergyPlus/RuntimeLanguageProcessor.cc +++ b/src/EnergyPlus/RuntimeLanguageProcessor.cc @@ -2707,23 +2707,13 @@ void GetRuntimeLanguageUserInput(EnergyPlusData &state) OutputProcessor::TimeStepType sovTimeStepType; // temporary OutputProcessor::StoreType sovStoreType; // temporary - int ErlVarLoop; - int CurveIndexNum; - int MaxNumAlphas(0); // argument for call to GetObjectDefMaxArgs - int MaxNumNumbers(0); // argument for call to GetObjectDefMaxArgs - int TotalArgs(0); // argument for call to GetObjectDefMaxArgs Array1D_string cAlphaFieldNames; Array1D_string cNumericFieldNames; Array1D_bool lNumericFieldBlanks; Array1D_bool lAlphaFieldBlanks; Array1D_string cAlphaArgs; Array1D rNumericArgs; - std::string cCurrentModuleObject; - int ConstructNum; - bool errFlag; std::string::size_type lbracket; - std::string UnitsA; - std::string UnitsB; Constant::Units curUnit(Constant::Units::None); std::string::size_type ptr; @@ -2734,13 +2724,17 @@ void GetRuntimeLanguageUserInput(EnergyPlusData &state) int NumNums; // Number of elements in the numeric array int IOStat; // IO Status when calling get input subroutine bool ErrorsFound = false; + int TotalArgs = 0; // argument for call to GetObjectDefMaxArgs int VariableNum = 0; // temporary int RuntimeReportVarNum; + bool errFlag; + std::string UnitsA; + std::string UnitsB; - cCurrentModuleObject = "EnergyManagementSystem:Sensor"; + std::string cCurrentModuleObject = "EnergyManagementSystem:Sensor"; state.dataInputProcessing->inputProcessor->getObjectDefMaxArgs(state, cCurrentModuleObject, TotalArgs, NumAlphas, NumNums); - MaxNumNumbers = NumNums; - MaxNumAlphas = NumAlphas; + int MaxNumNumbers = NumNums; + int MaxNumAlphas = NumAlphas; cCurrentModuleObject = "EnergyManagementSystem:Actuator"; state.dataInputProcessing->inputProcessor->getObjectDefMaxArgs(state, cCurrentModuleObject, TotalArgs, NumAlphas, NumNums); MaxNumNumbers = max(MaxNumNumbers, NumNums); @@ -2892,7 +2886,7 @@ void GetRuntimeLanguageUserInput(EnergyPlusData &state) } // loop over each alpha and register variable named as global Erl variable - for (ErlVarLoop = 1; ErlVarLoop <= NumAlphas; ++ErlVarLoop) { + for (int ErlVarLoop = 1; ErlVarLoop <= NumAlphas; ++ErlVarLoop) { if ((cCurrentModuleObject.compare("ExternalInterface:FunctionalMockupUnitImport:To:Variable") == 0)) { if (ErlVarLoop == 1) { // Only validate first field of object ExternalInterface:FunctionalMockupUnitImport:To:Variable. @@ -2970,7 +2964,7 @@ void GetRuntimeLanguageUserInput(EnergyPlusData &state) } } - CurveIndexNum = GetCurveIndex(state, cAlphaArgs(2)); // curve name + int CurveIndexNum = GetCurveIndex(state, cAlphaArgs(2)); // curve name if (CurveIndexNum == 0) { if (lAlphaFieldBlanks(2)) { ShowSevereError(state, format("{}{}=\"{} blank field.", RoutineName, cCurrentModuleObject, cAlphaArgs(1))); @@ -3032,7 +3026,7 @@ void GetRuntimeLanguageUserInput(EnergyPlusData &state) continue; } - ConstructNum = Util::FindItemInList(cAlphaArgs(2), state.dataConstruction->Construct); + int ConstructNum = Util::FindItemInList(cAlphaArgs(2), state.dataConstruction->Construct); if (ConstructNum == 0) { if (lAlphaFieldBlanks(2)) { @@ -3251,12 +3245,6 @@ void GetRuntimeLanguageUserInput(EnergyPlusData &state) lbracket = index(cAlphaArgs(1), '['); if (lbracket == std::string::npos) { - UnitsA = ""; - // if (lAlphaFieldBlanks(6)) then - // CALL ShowWarningError(state, RoutineName//TRIM(cCurrentModuleObject)//'="'//TRIM(cAlphaArgs(1))//' no units - // indicated.') CALL ShowContinueError(state, '...no units indicated for this variable. [] is assumed.') - // cAlphaArgs(1)=TRIM(cAlphaArgs(1))//' []' - // endif UnitsB = cAlphaArgs(6); lbracket = index(UnitsB, '['); ptr = index(UnitsB, ']'); @@ -3424,12 +3412,6 @@ void GetRuntimeLanguageUserInput(EnergyPlusData &state) lbracket = index(cAlphaArgs(1), '['); if (lbracket == std::string::npos) { - UnitsA = ""; - // if (lAlphaFieldBlanks(9)) then - // CALL ShowWarningError(state, RoutineName//TRIM(cCurrentModuleObject)//'="'//TRIM(cAlphaArgs(1))//' no units - // indicated.') CALL ShowContinueError(state, '...no units indicated for this variable. [] is assumed.') - // cAlphaArgs(1)=TRIM(cAlphaArgs(1))//' []' - // endif UnitsB = cAlphaArgs(9); lbracket = index(UnitsB, '['); ptr = index(UnitsB, ']'); @@ -3669,24 +3651,11 @@ void ReportRuntimeLanguage(EnergyPlusData &state) // SUBROUTINE INFORMATION: // AUTHOR Peter Graham Ellis // DATE WRITTEN June 2006 - // MODIFIED na - // RE-ENGINEERED na - - // PURPOSE OF THIS SUBROUTINE: - - // METHODOLOGY EMPLOYED: - - // USE STATEMENTS: - - // Locals - // SUBROUTINE LOCAL VARIABLE DECLARATIONS: - int RuntimeReportVarNum; - int VariableNum; - for (RuntimeReportVarNum = 1; + for (int RuntimeReportVarNum = 1; RuntimeReportVarNum <= state.dataRuntimeLang->NumEMSOutputVariables + state.dataRuntimeLang->NumEMSMeteredOutputVariables; ++RuntimeReportVarNum) { - VariableNum = state.dataRuntimeLangProcessor->RuntimeReportVar(RuntimeReportVarNum).VariableNum; + int VariableNum = state.dataRuntimeLangProcessor->RuntimeReportVar(RuntimeReportVarNum).VariableNum; if (state.dataRuntimeLang->ErlVariable(VariableNum).Value.Type == Value::Number) { state.dataRuntimeLangProcessor->RuntimeReportVar(RuntimeReportVarNum).Value = state.dataRuntimeLang->ErlVariable(VariableNum).Value.Number; From 3a2bcdcce99ebaa583acd7e59b3e0b953176ab07 Mon Sep 17 00:00:00 2001 From: Richard Raustad Date: Sun, 15 Sep 2024 19:24:30 -0400 Subject: [PATCH 15/15] reduce, const and unused --- src/EnergyPlus/SQLiteProcedures.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/EnergyPlus/SQLiteProcedures.cc b/src/EnergyPlus/SQLiteProcedures.cc index 731e3ece0d8..b6a1944ffa3 100644 --- a/src/EnergyPlus/SQLiteProcedures.cc +++ b/src/EnergyPlus/SQLiteProcedures.cc @@ -104,8 +104,6 @@ bool ParseSQLiteInput(EnergyPlusData &state, bool &writeOutputToSQLite, bool &wr return input; }; - auto &sql_ort = state.dataOutRptTab; - // There can only be 1 "Output:SQLite" auto const instance = instances.value().begin(); auto const &fields = instance.value(); @@ -123,6 +121,8 @@ bool ParseSQLiteInput(EnergyPlusData &state, bool &writeOutputToSQLite, bool &wr } { // "unit_conversion_for_tabular_data" std::string tabularDataUnitConversion = find_input(fields, "unit_conversion_for_tabular_data"); + auto const &sql_ort = state.dataOutRptTab; + if ("UseOutputControlTableStyles" == tabularDataUnitConversion) { // Jan 2021 Note: Since here we do not know weather sql_ort->unitsStyle has been processed or not, // the value "NotFound" is used for the option "UseOutputControlTableStyles" at this point; @@ -1577,7 +1577,6 @@ void SQLite::createSQLiteTimeIndexRecord(OutputProcessor::ReportFreq const repor bool const warmupFlag) { if (m_writeOutputToSQLite) { - int intStartMinute = 0; int intervalInMinutes = 60; static std::vector lastDayOfMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; @@ -1595,7 +1594,7 @@ void SQLite::createSQLiteTimeIndexRecord(OutputProcessor::ReportFreq const repor ++m_sqlDBTimeIndex; int intEndMinute = static_cast(endMinute + 0.5); - intStartMinute = static_cast(startMinute + 0.5); + int intStartMinute = static_cast(startMinute + 0.5); int t_hour = hour; intervalInMinutes = intEndMinute - intStartMinute; adjustReportingHourAndMinutes(t_hour, intEndMinute); @@ -2611,7 +2610,7 @@ SQLiteProcedures::SQLiteProcedures(std::shared_ptr const &errorStr { sqlite3 *m_connection = nullptr; if (m_writeOutputToSQLite) { - int rc = -1; + int rc; bool ok = true; std::string const dbName_utf8 = FileSystem::toGenericString(dbName);