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 FluidProperties through HVACUnitaryBypassVAV #10668

Merged
merged 3 commits into from
Aug 20, 2024

Conversation

rraustad
Copy link
Contributor

Pull request overview

  • Fixes programming issues
  • Uses CppCheck as a guide

NOTE: ENHANCEMENTS MUST FOLLOW A SUBMISSION PROCESS INCLUDING A FEATURE PROPOSAL AND DESIGN DOCUMENT PRIOR TO SUBMITTING CODE

Pull Request Author

Add to this list or remove from it as applicable. This is a simple templated set of guidelines.

  • Title of PR should be user-synopsis style (clearly understandable in a standalone changelog context)
  • Label the PR with at least one of: Defect, Refactoring, NewFeature, Performance, and/or DoNoPublish
  • Pull requests that impact EnergyPlus code must also include unit tests to cover enhancement or defect repair
  • Author should provide a "walkthrough" of relevant code changes using a GitHub code review comment process
  • If any diffs are expected, author must demonstrate they are justified using plots and descriptions
  • If changes fix a defect, the fix should be demonstrated in plots and descriptions
  • If any defect files are updated to a more recent version, upload new versions here or on DevSupport
  • If IDD requires transition, transition source, rules, ExpandObjects, and IDFs must be updated, and add IDDChange label
  • If structural output changes, add to output rules file and add OutputChange label
  • If adding/removing any LaTeX docs or figures, update that document's CMakeLists file dependencies

Reviewer

This will not be exhaustively relevant to every PR.

  • Perform a Code Review on GitHub
  • If branch is behind develop, merge develop and build locally to check for side effects of the merge
  • If defect, verify by running develop branch and reproducing defect, then running PR and reproducing fix
  • If feature, test running new feature, try creative ways to break it
  • CI status: all green or justified
  • Check that performance is not impacted (CI Linux results include performance check)
  • Run Unit Test(s) locally
  • Check any new function arguments for performance impacts
  • Verify IDF naming conventions and styles, memos and notes and defaults
  • If new idf included, locally check the err file and other outputs

@rraustad rraustad added the DoNotPublish Includes changes that shouldn't be reported in the changelog label Aug 19, 2024
@rraustad rraustad added this to the EnergyPlus 24.2 milestone Aug 19, 2024
@@ -2039,9 +2037,8 @@ namespace FluidProperties {
// for the refrigerant properties.
// Most properties requested (e.g., Specific Heat) must be > 0 but the tables may
// be set up for symmetry and not be limited to just valid values.
auto &df = state.dataFluidProps;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought we were not supposed to reference a class? Maybe this is different. I can easily put these back.

Copy link
Collaborator

@amirroth amirroth Aug 20, 2024

Choose a reason for hiding this comment

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

A class/struct is about the only thing you should reference, what you shouldn't reference is scalars and arrays.

@@ -2759,8 +2752,6 @@ namespace FluidProperties {

int LoTempIndex = FindArrayIndex(Temperature, this->PsTemps, this->PsLowTempIndex, this->PsHighTempIndex);

auto &df = state.dataFluidProps;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why undo this?

Copy link
Member

Choose a reason for hiding this comment

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

If I'm seeing it right, it looks like this variable just got moved into a smaller scope, not undoing the reference usage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The references are staying in place (I put them all back in) and only moving if there was a CppCheck reduce scope suggestion. I do want to see CI results though because the Mac results are troubling.

Copy link
Member

Choose a reason for hiding this comment

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

Just to be clear, Mac results are not reliable right now. There is something very odd going on that I'm trying to investigate. Gort and Tik-Tok are doing fine though.

Copy link
Contributor Author

@rraustad rraustad left a comment

Choose a reason for hiding this comment

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

What I see in CppCheck

@@ -1035,7 +1035,7 @@ namespace FluidProperties {
continue;
}

auto &supTempArray = FluidTemps(supTempArrayNum);
auto const &supTempArray = FluidTemps(supTempArrayNum);
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/FluidProperties.cc:1038]:(style),[constVariable],Variable 'supTempArray' can be declared as reference to const

@@ -1441,7 +1441,7 @@ namespace FluidProperties {

if (!glycolRaw->CpTempArrayName.empty()) {
int cpTempArrayNum = Util::FindItemInList(glycolRaw->CpTempArrayName, FluidTemps);
auto &cpTempArray = FluidTemps(cpTempArrayNum);
auto const &cpTempArray = FluidTemps(cpTempArrayNum);
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/FluidProperties.cc:1444]:(style),[constVariable],Variable 'cpTempArray' can be declared as reference to const

@@ -1452,7 +1452,7 @@ namespace FluidProperties {

if (!glycolRaw->RhoTempArrayName.empty()) {
int rhoTempArrayNum = Util::FindItemInList(glycolRaw->RhoTempArrayName, FluidTemps);
auto &rhoTempArray = FluidTemps(rhoTempArrayNum);
auto const &rhoTempArray = FluidTemps(rhoTempArrayNum);
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/FluidProperties.cc:1455]:(style),[constVariable],Variable 'rhoTempArray' can be declared as reference to const

@@ -1463,7 +1463,7 @@ namespace FluidProperties {

if (!glycolRaw->CondTempArrayName.empty()) {
int condTempArrayNum = Util::FindItemInList(glycolRaw->CondTempArrayName, FluidTemps);
auto &condTempArray = FluidTemps(condTempArrayNum);
auto const &condTempArray = FluidTemps(condTempArrayNum);
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/FluidProperties.cc:1466]:(style),[constVariable],Variable 'condTempArray' can be declared as reference to const

@@ -1474,7 +1474,7 @@ namespace FluidProperties {

if (!glycolRaw->ViscTempArrayName.empty()) {
int viscTempArrayNum = Util::FindItemInList(glycolRaw->ViscTempArrayName, FluidTemps);
auto &viscTempArray = FluidTemps(viscTempArrayNum);
auto const &viscTempArray = FluidTemps(viscTempArrayNum);
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/FluidProperties.cc:1477]:(style),[constVariable],Variable 'viscTempArray' can be declared as reference to const

@@ -297,7 +296,6 @@ void GetStandAloneERV(EnergyPlusData &state)
standAloneERV.ExhaustAirFanName = Alphas(5);
GlobalNames::IntraObjUniquenessCheck(
state, Alphas(5), CurrentModuleObject, cAlphaFields(5), state.dataHVACStandAloneERV->ExhaustAirFanUniqueNames, ErrorsFound);
errFlag = false;
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/HVACStandAloneERV.cc:300]:(style),[redundantAssignment],Variable 'errFlag' is reassigned a value before the old one has been used.

@@ -1695,7 +1693,6 @@ int getEqIndex(EnergyPlusData &state, std::string_view CompName)
for (int StandAloneERVNum = 1; StandAloneERVNum <= state.dataHVACStandAloneERV->NumStandAloneERVs; StandAloneERVNum++) {
if (Util::SameString(CompName, state.dataHVACStandAloneERV->StandAloneERV(StandAloneERVNum).Name)) {
return StandAloneERVNum;
break;
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/HVACStandAloneERV.cc:1698]:(style),[duplicateBreak],Consecutive return, break, continue, goto or throw statements are unnecessary.

@@ -330,7 +330,6 @@ namespace HVACUnitaryBypassVAV {
bool ErrorsFound(false); // Set to true if errors in input, fatal at end of routine
bool DXErrorsFound(false); // Set to true if errors in get coil input
Array1D_int OANodeNums(4); // Node numbers of OA mixer (OA, EA, RA, MA)
std::string HXDXCoolCoilName; // Name of DX cooling coil used with Heat Exchanger Assisted Cooling Coil
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/HVACUnitaryBypassVAV.cc:333]:(style),[unusedVariable],Unused variable: HXDXCoolCoilName

@@ -754,7 +753,7 @@ namespace HVACUnitaryBypassVAV {
ShowContinueError(state, format("...occurs in {} \"{}\"", thisCBVAV.UnitType, thisCBVAV.Name));
ErrorsFound = true;
} else {
auto &newCoil = state.dataCoilCooingDX->coilCoolingDXs[thisCBVAV.DXCoolCoilIndexNum];
auto const &newCoil = state.dataCoilCooingDX->coilCoolingDXs[thisCBVAV.DXCoolCoilIndexNum];
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/HVACUnitaryBypassVAV.cc:757]:(style),[constVariable],Variable 'newCoil' can be declared as reference to const

@@ -2444,7 +2443,7 @@ namespace HVACUnitaryBypassVAV {
}
// now find the speed ratio for the found speednum
auto f = [&state, CBVAVNum, SpeedNum, DesOutTemp](Real64 const SpeedRatio) {
auto &thisCBVAV = state.dataHVACUnitaryBypassVAV->CBVAV(CBVAVNum);
auto const &thisCBVAV = state.dataHVACUnitaryBypassVAV->CBVAV(CBVAVNum);
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/HVACUnitaryBypassVAV.cc:2447]:(style),[constVariable],Variable 'thisCBVAV' can be declared as reference to const

Copy link
Member

@Myoldmopar Myoldmopar left a comment

Choose a reason for hiding this comment

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

These look like nice changes. Lots of additional const attributes and lots of reduced scope. 👍 Are you planning to go further on this PR? If not, it should be able to slide in without any major issues.

@@ -2759,8 +2752,6 @@ namespace FluidProperties {

int LoTempIndex = FindArrayIndex(Temperature, this->PsTemps, this->PsLowTempIndex, this->PsHighTempIndex);

auto &df = state.dataFluidProps;
Copy link
Member

Choose a reason for hiding this comment

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

If I'm seeing it right, it looks like this variable just got moved into a smaller scope, not undoing the reference usage.

@rraustad
Copy link
Contributor Author

@Myoldmopar I am not making any other changes on this branch.

@Myoldmopar
Copy link
Member

Looks like all the reasonable CI machines are reporting happily, and this removes 26 or so messages from the cppcheck results, cleaning up the code nicely without affecting functionality. Good stuff here, and I'm not waiting to merge. Thanks @rraustad

@Myoldmopar Myoldmopar merged commit f274ccb into develop Aug 20, 2024
14 of 15 checks passed
@Myoldmopar Myoldmopar deleted the CppCheck-FluidProperties branch August 20, 2024 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DoNotPublish Includes changes that shouldn't be reported in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants