Skip to content

Commit 54f875d

Browse files
authored
Merge pull request #10695 from NREL/CppCheck-PlantPipingSystemsManager
CppCheck PlantPipingSystemsManager
2 parents 6c81d6b + 4fd7d70 commit 54f875d

File tree

5 files changed

+79
-112
lines changed

5 files changed

+79
-112
lines changed

src/EnergyPlus/PlantPipingSystemsManager.cc

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ namespace PlantPipingSystemsManager {
285285
Real64 ZoneTemp = 0.0;
286286

287287
// Set ZoneTemp equal to the average air temperature of the zones the coupled surfaces are part of.
288-
for (auto &z : thisDomain.ZoneCoupledSurfaces) {
288+
for (auto const &z : thisDomain.ZoneCoupledSurfaces) {
289289
int ZoneNum = z.Zone;
290290
ZoneTemp += state.dataZoneTempPredictorCorrector->zoneHeatBalance(ZoneNum).ZTAV;
291291
}
@@ -428,7 +428,7 @@ namespace PlantPipingSystemsManager {
428428
for (int DomainNum = 0; DomainNum < TotalNumDomains; ++DomainNum) {
429429

430430
// Convenience
431-
auto &thisDomain = state.dataPlantPipingSysMgr->domains[DomainNum];
431+
auto const &thisDomain = state.dataPlantPipingSysMgr->domains[DomainNum];
432432

433433
// validate pipe domain-circuit name-to-index references
434434
for (auto &thisCircuit : thisDomain.circuits) {
@@ -437,25 +437,25 @@ namespace PlantPipingSystemsManager {
437437

438438
// correct segment locations for: INTERNAL DATA STRUCTURE Y VALUE MEASURED FROM BOTTOM OF DOMAIN,
439439
// INPUT WAS MEASURED FROM GROUND SURFACE
440-
for (auto &thisCircuit : thisDomain.circuits) {
440+
for (auto const &thisCircuit : thisDomain.circuits) {
441441
for (auto &thisSegment : thisCircuit->pipeSegments) {
442442
thisSegment->PipeLocation.Y = thisDomain.Extents.yMax - thisSegment->PipeLocation.Y;
443443
}
444444
}
445445

446446
// correct segment locations for: BASEMENT X SHIFT
447447
if (thisDomain.HasBasement && thisDomain.BasementZone.ShiftPipesByWidth) {
448-
for (auto &thisCircuit : thisDomain.circuits) {
448+
for (auto const &thisCircuit : thisDomain.circuits) {
449449
for (auto &thisSegment : thisCircuit->pipeSegments) {
450450
thisSegment->PipeLocation.X += thisDomain.BasementZone.Width;
451451
}
452452
}
453453
}
454454

455455
// now we will have good values of pipe segment locations, we can validate them
456-
for (auto &thisCircuit : thisDomain.circuits) {
456+
for (auto const &thisCircuit : thisDomain.circuits) {
457457
// check to make sure it isn't outside the domain
458-
for (auto &thisSegment : thisCircuit->pipeSegments) {
458+
for (auto const &thisSegment : thisCircuit->pipeSegments) {
459459
if ((thisSegment->PipeLocation.X > thisDomain.Extents.xMax) || (thisSegment->PipeLocation.X < 0.0) ||
460460
(thisSegment->PipeLocation.Y > thisDomain.Extents.yMax) || (thisSegment->PipeLocation.Y < 0.0)) {
461461
ShowSevereError(state,
@@ -1106,7 +1106,6 @@ namespace PlantPipingSystemsManager {
11061106
int NumAlphas; // Number of Alphas for each GetObjectItem call
11071107
int NumNumbers; // Number of Numbers for each GetObjectItem call
11081108
int IOStatus; // Used in GetObjectItem
1109-
int CurIndex;
11101109

11111110
// initialize these counters properly so they can be incremented within the DO loop
11121111
int DomainNum = StartingDomainNumForBasement - 1;
@@ -1173,7 +1172,7 @@ namespace PlantPipingSystemsManager {
11731172
}
11741173

11751174
// Basement zone depth
1176-
CurIndex = 11;
1175+
int CurIndex = 11;
11771176
thisDomain.BasementZone.Depth = state.dataIPShortCut->rNumericArgs(CurIndex);
11781177
if (thisDomain.BasementZone.Depth >= thisDomain.Extents.yMax || thisDomain.BasementZone.Depth <= 0.0) {
11791178
ShowSevereError(state, format("Invalid {}", state.dataIPShortCut->cNumericFieldNames(CurIndex)));
@@ -1378,7 +1377,7 @@ namespace PlantPipingSystemsManager {
13781377

13791378
// Total surface area
13801379
Real64 ThisArea = 0.0;
1381-
for (auto &z : thisDomain.ZoneCoupledSurfaces) {
1380+
for (auto const &z : thisDomain.ZoneCoupledSurfaces) {
13821381
ThisArea += z.SurfaceArea;
13831382
}
13841383

@@ -1655,9 +1654,6 @@ namespace PlantPipingSystemsManager {
16551654
DataLoopNode::ConnectionType::Inlet,
16561655
NodeInputManager::CompFluidStream::Primary,
16571656
DataLoopNode::ObjectIsNotParent);
1658-
if (thisCircuit.InletNodeNum == 0) {
1659-
CurIndex = 2;
1660-
}
16611657
thisCircuit.OutletNodeName = state.dataIPShortCut->cAlphaArgs(3);
16621658
thisCircuit.OutletNodeNum = NodeInputManager::GetOnlySingleNode(state,
16631659
thisCircuit.OutletNodeName,
@@ -1668,9 +1664,6 @@ namespace PlantPipingSystemsManager {
16681664
DataLoopNode::ConnectionType::Outlet,
16691665
NodeInputManager::CompFluidStream::Primary,
16701666
DataLoopNode::ObjectIsNotParent);
1671-
if (thisCircuit.OutletNodeNum == 0) {
1672-
CurIndex = 3;
1673-
}
16741667
BranchNodeConnections::TestCompSet(
16751668
state, ObjName_HorizTrench, thisTrenchName, thisCircuit.InletNodeName, thisCircuit.OutletNodeName, "Piping System Circuit Nodes");
16761669

@@ -2123,8 +2116,8 @@ namespace PlantPipingSystemsManager {
21232116
this->developMesh(state);
21242117

21252118
// would be OK to do some post-mesh error handling here I think
2126-
for (auto &thisDomainCircuit : this->circuits) {
2127-
for (auto &segment : thisDomainCircuit->pipeSegments) {
2119+
for (auto const &thisDomainCircuit : this->circuits) {
2120+
for (auto const &segment : thisDomainCircuit->pipeSegments) {
21282121
if (!segment->PipeCellCoordinatesSet) {
21292122
ShowSevereError(state, format("PipingSystems:{}:Pipe segment index not set.", RoutineName));
21302123
ShowContinueError(state, "...Possibly because pipe segment was placed outside of the domain.");
@@ -2356,7 +2349,7 @@ namespace PlantPipingSystemsManager {
23562349
Real64 ThisCellMax;
23572350

23582351
Real64 MaxDivAmount = 0.0;
2359-
for (auto &radCell : CellToCheck.PipeCellData.Soil) {
2352+
for (auto const &radCell : CellToCheck.PipeCellData.Soil) {
23602353
ThisCellMax = std::abs(radCell.Temperature - radCell.Temperature_PrevIteration);
23612354
if (ThisCellMax > MaxDivAmount) {
23622355
MaxDivAmount = ThisCellMax;
@@ -2751,7 +2744,7 @@ namespace PlantPipingSystemsManager {
27512744

27522745
//'NOTE: pipe location y values have already been corrected to be measured from the bottom surface
27532746
//'in input they are measured by depth, but internally they are referred to by distance from y = 0, or the bottom boundary
2754-
for (auto &thisCircuit : this->circuits) {
2747+
for (auto const &thisCircuit : this->circuits) {
27552748

27562749
// set up a convenience variable here
27572750
//'account for the pipe and insulation if necessary
@@ -3029,7 +3022,7 @@ namespace PlantPipingSystemsManager {
30293022

30303023
//'loop across all partitions
30313024
for (int Index = 0; Index < (int)ThesePartitionCenters.size(); ++Index) {
3032-
auto &thisPartitionCenter = ThesePartitionCenters[Index];
3025+
auto const &thisPartitionCenter = ThesePartitionCenters[Index];
30333026

30343027
Real64 const ThisCellWidthBy2 = thisPartitionCenter.TotalWidth / 2.0;
30353028
PartitionType ThisPartitionType = thisPartitionCenter.partitionType;
@@ -3142,10 +3135,10 @@ namespace PlantPipingSystemsManager {
31423135
// MODIFIED na
31433136
// RE-ENGINEERED na
31443137

3145-
int cellCountUpToNow = 0;
31463138
std::vector<Real64> tempCellWidths;
31473139

31483140
if (PartitionsExist) {
3141+
int cellCountUpToNow = 0;
31493142

31503143
for (int i = 0; i < (int)ThesePartitionRegions.size(); ++i) {
31513144
auto &thisPartition = ThesePartitionRegions[i];
@@ -3266,7 +3259,7 @@ namespace PlantPipingSystemsManager {
32663259
default:
32673260
if (thisRegion.thisRegionType == DirDirection) {
32683261
Real64 StartingPointCounter = thisRegion.Min;
3269-
for (auto &cellWidth : thisRegion.CellWidths) {
3262+
for (auto const &cellWidth : thisRegion.CellWidths) {
32703263
RetVal.push_back(StartingPointCounter);
32713264
StartingPointCounter += cellWidth;
32723265
}
@@ -3459,22 +3452,20 @@ namespace PlantPipingSystemsManager {
34593452
// Check if vertical insulation present
34603453
if (this->VertInsPresentFlag) {
34613454
if (InsulationYIndex != 0) { // Partial vertical insulation
3462-
if (CellYIndex <= this->y_max_index && CellYIndex > InsulationYIndex) {
3455+
if (CellYIndex > InsulationYIndex) {
34633456
cellType = CellType::VertInsulation;
34643457
++NumInsulationCells;
34653458
}
34663459
} else { // Vertical insulation extends to depth of basement floor
3467-
if (CellYIndex <= this->y_max_index && CellYIndex > YFloorIndex) {
3468-
cellType = CellType::VertInsulation;
3469-
++NumInsulationCells;
3470-
}
3460+
cellType = CellType::VertInsulation;
3461+
++NumInsulationCells;
34713462
}
34723463
}
34733464
}
34743465
} else if (CellYIndex == this->y_max_index) { // Surface cells
34753466
cellType = CellType::GroundSurface;
34763467
++NumGroundSurfaceCells;
3477-
} else if (CellYIndex == 0 || CellXIndex == 0 || CellZIndex == 0) { // Farfield boundary
3468+
} else if (CellXIndex == 0 || CellZIndex == 0) { // Farfield boundary
34783469
cellType = CellType::FarfieldBoundary;
34793470
}
34803471
} else if (CellXIndex == MaxBasementXNodeIndex && CellYIndex == MinBasementYNodeIndex) {
@@ -3507,7 +3498,7 @@ namespace PlantPipingSystemsManager {
35073498
bool HasInsulation(false);
35083499
RadialSizing PipeSizing;
35093500
Circuit *circuitReference = nullptr;
3510-
for (auto &thisCircuit : this->circuits) {
3501+
for (auto const &thisCircuit : this->circuits) {
35113502
for (auto &segment : thisCircuit->pipeSegments) {
35123503
if (XYRectangle.contains(segment->PipeLocation)) {
35133504
//'inform the cell that it is a pipe node
@@ -3842,7 +3833,7 @@ namespace PlantPipingSystemsManager {
38423833

38433834
bool CircuitInletCellSet = false;
38443835

3845-
for (auto &segment : thisCircuit->pipeSegments) {
3836+
for (auto const &segment : thisCircuit->pipeSegments) {
38463837
switch (segment->FlowDirection) {
38473838
case SegmentFlow::IncreasingZ:
38483839
SegmentInletCellX = segment->PipeCellCoordinates.X;
@@ -5178,7 +5169,7 @@ namespace PlantPipingSystemsManager {
51785169
NextOuterRadialCellTemperature = cell.PipeCellData.Pipe.Temperature;
51795170
}
51805171
} else {
5181-
auto &nextOuterMostSoilCell = cell.PipeCellData.Soil[numSoilCells - 2];
5172+
auto const &nextOuterMostSoilCell = cell.PipeCellData.Soil[numSoilCells - 2];
51825173
NextOuterRadialCellOuterRadius = nextOuterMostSoilCell.OuterRadius;
51835174
NextOuterRadialCellRadialCentroid = nextOuterMostSoilCell.RadialCentroid;
51845175
NextOuterRadialCellConductivity = nextOuterMostSoilCell.Properties.Conductivity;
@@ -5858,12 +5849,12 @@ namespace PlantPipingSystemsManager {
58585849
//'calculate this cell's new Cp value based on the cell temperature
58595850
if (CellTemp <= frzAllIce) { // totally frozen
58605851
rhoCp = this->Moisture.rhoCP_soil_ice;
5861-
} else if ((CellTemp > frzAllIce) && (CellTemp < frzIceTrans)) { // in between totally frozen and ice transition
5852+
} else if (CellTemp < frzIceTrans) { // in between totally frozen and ice transition
58625853
rhoCp = this->Moisture.rhoCP_soil_ice +
58635854
(this->Moisture.rhoCP_soil_transient - this->Moisture.rhoCP_soil_ice) / (frzIceTrans - frzAllIce) * (CellTemp - frzAllIce);
5864-
} else if ((CellTemp >= frzIceTrans) && (CellTemp <= frzLiqTrans)) { // in between ice transition and liquid transition
5855+
} else if (CellTemp <= frzLiqTrans) { // in between ice transition and liquid transition
58655856
rhoCp = this->Moisture.rhoCP_soil_transient;
5866-
} else if ((CellTemp > frzLiqTrans) && (CellTemp < frzAllLiq)) { // in between liquid transition and all liquid
5857+
} else if (CellTemp < frzAllLiq) { // in between liquid transition and all liquid
58675858
rhoCp = this->Moisture.rhoCp_soil_liq_1 +
58685859
(this->Moisture.rhoCP_soil_transient - this->Moisture.rhoCP_soil_liq) / (frzAllLiq - frzLiqTrans) * (frzAllLiq - CellTemp);
58695860
} else { // ( CellTemp >= frzAllLiq ) --- greater than or equal to all liquid

0 commit comments

Comments
 (0)