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 WindowManager #10836

Open
wants to merge 24 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions src/EnergyPlus/UnitarySystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2983,12 +2983,14 @@ namespace UnitarySystems {
if (this->m_CoolCoilExists && this->m_MaxCoolAirVolFlow < 0.0) {
if (!state.dataSize->SysSizingRunDone) {
int BranchNum = BranchInputManager::GetAirBranchIndex(state, "AirloopHVAC:UnitarySystem", this->Name);
std::string FanType = "";
std::string m_FanName = ""; // the notation m_ implies member variables, and this is a local
BranchFanFlow = 0.0;
if (BranchNum > 0.0) BranchInputManager::GetBranchFanTypeName(state, BranchNum, FanType, m_FanName, ErrFound);
if (!ErrFound && BranchNum > 0) {
BranchFanFlow = state.dataFans->fans(this->m_FanIndex)->maxAirFlowRate;
if (BranchNum > 0.0) {
std::string FanType = "";
std::string FanName = "";
BranchInputManager::GetBranchFanTypeName(state, BranchNum, FanType, FanName, ErrFound);
if (!ErrFound) {
BranchFanFlow = state.dataFans->fans(this->m_FanIndex)->maxAirFlowRate;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[src/EnergyPlus/UnitarySystem.cc:2986]:(style),[variableScope],The scope of the variable 'FanType' can be reduced.
[src/EnergyPlus/UnitarySystem.cc:2987]:(style),[variableScope],The scope of the variable 'm_FanName' can be reduced.

}
if (BranchFanFlow > 0.0) {
this->m_MaxCoolAirVolFlow = BranchFanFlow;
Expand Down Expand Up @@ -6618,10 +6620,7 @@ namespace UnitarySystems {
this->m_MSHeatingSpeedRatio[i] = 1.0;
}
if (this->m_HeatingCoilType_Num == HVAC::Coil_HeatingWaterToAirHPVSEquationFit) {
std::string MultispeedType = "UnitarySystemPerformance:Multispeed";
if (this->m_DesignSpecMSHPIndex == -1) {
std::string MultispeedType = "Fan:SystemModel";
}
std::string MultispeedType = (this->m_DesignSpecMSHPIndex == -1) ? "Fan:SystemModel" : "UnitarySystemPerformance:Multispeed";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[src/EnergyPlus/UnitarySystem.cc:6621]:(style),[variableScope],The scope of the variable 'MultispeedType' can be reduced.
[src/EnergyPlus/UnitarySystem.cc:6623]:(style),[shadowVariable],Local variable 'MultispeedType' shadows outer variable
[src/EnergyPlus/UnitarySystem.cc:6623]:(style),[unreadVariable],Variable 'MultispeedType' is assigned a value that is never used.

int NumOfSpeed = VariableSpeedCoils::GetVSCoilNumOfSpeeds(state, this->m_HeatingCoilName, errorsFound);
if (errorsFound) {
ShowSevereError(state,
Expand Down Expand Up @@ -6664,10 +6663,7 @@ namespace UnitarySystems {
this->m_MSCoolingSpeedRatio[i] = 1.0;
}
if (this->m_CoolingCoilType_Num == HVAC::Coil_CoolingWaterToAirHPVSEquationFit) {
std::string MultispeedType = "UnitarySystemPerformance:Multispeed";
if (this->m_DesignSpecMSHPIndex == -1) {
std::string MultispeedType = "Fan:SystemModel";
}
std::string MultispeedType = (this->m_DesignSpecMSHPIndex == -1) ? "Fan:SystemModel" : "UnitarySystemPerformance:Multispeed";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[src/EnergyPlus/UnitarySystem.cc:6667]:(style),[variableScope],The scope of the variable 'MultispeedType' can be reduced.
[src/EnergyPlus/UnitarySystem.cc:6669]:(style),[shadowVariable],Local variable 'MultispeedType' shadows outer variable
[src/EnergyPlus/UnitarySystem.cc:6669]:(style),[unreadVariable],Variable 'MultispeedType' is assigned a value that is never used.

int NumOfSpeed = VariableSpeedCoils::GetVSCoilNumOfSpeeds(state, this->m_CoolingCoilName, errorsFound);
if (errorsFound) {
ShowSevereError(state,
Expand Down
2 changes: 1 addition & 1 deletion src/EnergyPlus/UserDefinedComponents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ namespace UserDefinedComponents {

void UserPlantComponentStruct::onInitLoopEquip(EnergyPlusData &state, const PlantLocation &calledFromLocation)
{
bool anyEMSRan;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[src/EnergyPlus/UserDefinedComponents.cc:117]:(style),[variableScope],The scope of the variable 'anyEMSRan' can be reduced.

Real64 myLoad = 0.0;
int thisLoop = 0;

Expand All @@ -128,6 +127,7 @@ namespace UserDefinedComponents {

if (thisLoop > 0) {
if (this->Loop(thisLoop).ErlInitProgramMngr > 0) {
bool anyEMSRan;
EMSManager::ManageEMS(state, EMSManager::EMSCallFrom::UserDefinedComponentModel, anyEMSRan, this->Loop(thisLoop).ErlInitProgramMngr);
} else if (this->Loop(thisLoop).initPluginLocation > -1) {
state.dataPluginManager->pluginManager->runSingleUserDefinedPlugin(state, this->Loop(thisLoop).initPluginLocation);
Expand Down
48 changes: 16 additions & 32 deletions src/EnergyPlus/Vectors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ Real64 AreaPolygon(int const n, Array1D<Vector> &p)
{

// PURPOSE OF THIS SUBROUTINE:
// This subroutine calculates the area of a polygon defined by the
// input vectors.
// This subroutine calculates the area of a polygon defined by the input vectors.

// REFERENCE:
// Graphic Gems.
Expand Down Expand Up @@ -189,8 +188,7 @@ Vector VecNormalize(Vector const &vec)
{

// PURPOSE OF THIS SUBROUTINE:
// This subroutine normalizes the input vector and returns the normalized
// vector
// This subroutine normalizes the input vector and returns the normalized vector

// REFERENCE:
// Graphic Gems.
Expand Down Expand Up @@ -295,8 +293,7 @@ void PlaneEquation(Array1D<Vector> &verts, // Structure of the surface
{

// PURPOSE OF THIS SUBROUTINE:
// This subroutine calculates the plane equation for a given
// surface (which should be planar).
// This subroutine calculates the plane equation for a given surface (which should be planar).

// REFERENCE:
// Graphic Gems
Expand Down Expand Up @@ -336,9 +333,7 @@ Real64 Pt2Plane(Vector const &pt, // Point for determining the distance
{

// PURPOSE OF THIS SUBROUTINE:
// This subroutine calculates the distance from a point
// to the plane (of a surface). Used to determine the reveal
// of a heat transfer subsurface.
// This subroutine calculates the distance from a point to the plane (of a surface). Used to determine the reveal of a heat transfer subsurface.

// REFERENCE:
// Graphic Gems
Expand All @@ -358,8 +353,7 @@ void CreateNewellAreaVector(Array1D<Vector> const &VList, int const NSides, Vect
// DATE WRITTEN May 2004

// PURPOSE OF THIS SUBROUTINE:
// This subroutine creates a "Newell" vector from the vector list for a surface
// face. Also the Newell Area vector.
// This subroutine creates a "Newell" vector from the vector list for a surface face. Also the Newell Area vector.

// REFERENCES:
// Collaboration with Bill Carroll, LBNL.
Expand All @@ -384,8 +378,7 @@ void CreateNewellSurfaceNormalVector(Array1D<Vector> const &VList, int const NSi
// DATE WRITTEN Jan 2011

// PURPOSE OF THIS SUBROUTINE:
// This subroutine creates a "Newell" surface normal vector from the vector list
// for a surface face.
// This subroutine creates a "Newell" surface normal vector from the vector list for a surface face.

// REFERENCES:
// September 2010: from OpenGL.org
Expand All @@ -401,14 +394,10 @@ void CreateNewellSurfaceNormalVector(Array1D<Vector> const &VList, int const NSi
// Returning Normalize(Normal)
// End Function

Real64 xvalue;
Real64 yvalue;
Real64 zvalue;

OutNewellSurfaceNormalVector = 0.0;
xvalue = 0.0;
yvalue = 0.0;
zvalue = 0.0;
Real64 xvalue = 0.0;
Real64 yvalue = 0.0;
Real64 zvalue = 0.0;

// IF (NSides > 3) THEN
for (int Side = 1; Side <= NSides; ++Side) {
Expand Down Expand Up @@ -438,8 +427,7 @@ void CompareTwoVectors(Vector const &vector1, // standard vector
// DATE WRITTEN February 2012

// PURPOSE OF THIS SUBROUTINE:
// This routine will provide the ability to compare two vectors (e.g. surface normals)
// to be the same within a specified tolerance.
// This routine will provide the ability to compare two vectors (e.g. surface normals) to be the same within a specified tolerance.

// METHODOLOGY EMPLOYED:
// compare each element (x,y,z)
Expand All @@ -458,8 +446,7 @@ void CalcCoPlanarNess(Array1D<Vector> &Surf, int const NSides, bool &IsCoPlanar,
// DATE WRITTEN June 2004

// PURPOSE OF THIS SUBROUTINE:
// This subroutine provides the calculation to determine if the
// surface is planar or not.
// This subroutine provides the calculation to determine if the surface is planar or not.

// REFERENCES:
// Eric W. Weisstein. "Coplanar." From MathWorld--A Wolfram Web Resource.
Expand Down Expand Up @@ -489,7 +476,8 @@ void CalcCoPlanarNess(Array1D<Vector> &Surf, int const NSides, bool &IsCoPlanar,
if (std::abs(MaxDist) > Constant::SmallDistance) IsCoPlanar = false;
}

std::vector<int> PointsInPlane(Array1D<Vector> &BaseSurf, int const BaseSides, Array1D<Vector> &QuerySurf, int const QuerySides, bool &ErrorFound)
std::vector<int>
PointsInPlane(Array1D<Vector> &BaseSurf, int const BaseSides, Array1D<Vector> const &QuerySurf, int const QuerySides, bool &ErrorFound)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[src/EnergyPlus/Vectors.cc:492]:(style),[constParameterReference],Parameter 'QuerySurf' can be declared as reference to const

{
std::vector<int> pointIndices;

Expand All @@ -505,31 +493,27 @@ std::vector<int> PointsInPlane(Array1D<Vector> &BaseSurf, int const BaseSides, A
return pointIndices;
}

Real64 CalcPolyhedronVolume(EnergyPlusData &state, Polyhedron const &Poly)
Real64 CalcPolyhedronVolume(EnergyPlusData const &state, Polyhedron const &Poly)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[src/EnergyPlus/Vectors.cc:508]:(style),[constParameterReference],Parameter 'state' can be declared as reference to const

{

// SUBROUTINE INFORMATION:
// AUTHOR Linda Lawrie
// DATE WRITTEN June 2004

// PURPOSE OF THIS SUBROUTINE:
// This subroutine provides the volume calculation for a polyhedron
// (i.e. Zone).
// This subroutine provides the volume calculation for a polyhedron (i.e. Zone).

// REFERENCES:
// Conversations with Bill Carroll, LBNL.

// SUBROUTINE LOCAL VARIABLE DECLARATIONS:
Real64 PyramidVolume;

// Object Data
Vector p3FaceOrigin;

Real64 Volume = 0.0;

for (int NFace = 1; NFace <= Poly.NumSurfaceFaces; ++NFace) {
p3FaceOrigin = Poly.SurfaceFace(NFace).FacePoints(2);
PyramidVolume = dot(Poly.SurfaceFace(NFace).NewellAreaVector, (p3FaceOrigin - state.dataVectors->p0));
Real64 PyramidVolume = dot(Poly.SurfaceFace(NFace).NewellAreaVector, (p3FaceOrigin - state.dataVectors->p0));
Volume += PyramidVolume / 3.0;
}
return Volume;
Expand Down
4 changes: 2 additions & 2 deletions src/EnergyPlus/Vectors.hh
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ namespace Vectors {
void CalcCoPlanarNess(Array1D<Vector> &Surf, int const NSides, bool &IsCoPlanar, Real64 &MaxDist, int &ErrorVertex);

std::vector<int>
PointsInPlane(Array1D<Vector> &BaseSurf, int const BaseSides, Array1D<Vector> &QuerySurf, int const QuerySides, bool &ErrorFound);
PointsInPlane(Array1D<Vector> &BaseSurf, int const BaseSides, Array1D<Vector> const &QuerySurf, int const QuerySides, bool &ErrorFound);

Real64 CalcPolyhedronVolume(EnergyPlusData &state, Polyhedron const &Poly);
Real64 CalcPolyhedronVolume(EnergyPlusData const &state, Polyhedron const &Poly);

} // namespace Vectors

Expand Down
5 changes: 2 additions & 3 deletions src/EnergyPlus/WaterUse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ namespace WaterUse {
int IOStatus; // Used in GetObjectItem
int NumAlphas; // Number of Alphas for each GetObjectItem call
int NumNumbers; // Number of Numbers for each GetObjectItem call
int AlphaNum;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[src/EnergyPlus/WaterUse.cc:281]:(style),[variableScope],The scope of the variable 'AlphaNum' can be reduced.


constexpr std::array<std::string_view, static_cast<int>(HeatRecovHX::Num)> HeatRecoverHXNamesUC{"IDEAL", "COUNTERFLOW", "CROSSFLOW"};

Expand Down Expand Up @@ -525,7 +524,7 @@ namespace WaterUse {

waterConnection.myWaterEquipArr.allocate(NumAlphas - 9);

for (AlphaNum = 10; AlphaNum <= NumAlphas; ++AlphaNum) {
for (int AlphaNum = 10; AlphaNum <= NumAlphas; ++AlphaNum) {
int WaterEquipNum = Util::FindItemInList(state.dataIPShortCut->cAlphaArgs(AlphaNum), state.dataWaterUse->WaterEquipment);

if (WaterEquipNum == 0) {
Expand Down Expand Up @@ -1658,7 +1657,7 @@ namespace WaterUse {
// PURPOSE OF THIS SUBROUTINE:
// Calculates the zone internal gains due to water use sensible and latent loads.

bool MyEnvrnFlagLocal(true);
static bool MyEnvrnFlagLocal = true;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[src/EnergyPlus/WaterUse.cc:1665]:(style),[knownConditionTrueFalse],Condition 'MyEnvrnFlagLocal' is always true


if (state.dataWaterUse->numWaterEquipment == 0) return;

Expand Down
Loading
Loading