Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CppCheck PoweredInductionUnits #10741

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
50 changes: 23 additions & 27 deletions src/EnergyPlus/PoweredInductionUnits.cc
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ void GetPIUs(EnergyPlusData &state)
state.dataPowerInductionUnits->PiuUniqueNames.reserve(static_cast<unsigned>(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"}) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
43 changes: 7 additions & 36 deletions src/EnergyPlus/Psychrometrics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<int>(PsychrometricFunction::TwbFnTdbWPb_cache)];
#endif
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<int>(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) {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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<int>(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) {
Expand Down Expand Up @@ -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) {
Expand Down
44 changes: 18 additions & 26 deletions src/EnergyPlus/Pumps.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1365,46 +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
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;
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) {

errFlag = false;
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<int>(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
Expand Down Expand Up @@ -1498,6 +1489,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);
Expand Down Expand Up @@ -1539,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;
Expand Down Expand Up @@ -1638,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: {
Expand Down Expand Up @@ -2065,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;
Expand Down Expand Up @@ -2223,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();
Expand Down Expand Up @@ -2348,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,
Expand Down Expand Up @@ -2377,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);
Expand Down
Loading