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 ZoneEquipmentManager #10705

Merged
merged 8 commits into from
Sep 11, 2024
Merged

Conversation

rraustad
Copy link
Contributor

Pull request overview

  • Fixes programming syntax
  • Use Cppcheck as 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 31, 2024
@@ -1758,7 +1757,7 @@ void updateZoneSizingEndDay(DataSizing::ZoneSizingData &zsCalcSizing,
// save heat peak conditions when there is no design heating load or design heating volume flow rate, i.e., when
// zone temperature is always greater than the zone heating thermostat temperature
if (zsCalcFinalSizing.DesHeatLoad == 0) {
bool FirstIteration = true;
bool FirstIteration = true; // declare as static to save for next iteration? but needs to be space/zone specific?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Move to struct to get expected result? It seems the intent is to set these sizing data on a first pass but is not working as intended.

[src/EnergyPlus/ZoneEquipmentManager.cc:1791]:(style),[unreadVariable],Variable 'FirstIteration' is assigned a value that is never used.

Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm following correctly, this is being used locally here to initialize the peak data to the first timestep values, then let the < (or >) comparisons take over for the remaining timesteps in the loop. So, this really is very local, and it is used in the IF, so not sure why cppCheck thinks it isn't used. The name is misleading, could be firstTimeStep or just delete it and put || TimeStepIndex = 1 in the if.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking at this again. This is in EndDay calcs so it seems each of these blocks should be executed at least once. That does not appear to be happening for the later blocks where a previous block was executed and the later block doesn't set bool FirstIteration = true;. I think the || TimeStepIndex == 1 is the better approach. I expect diffs so will target this section in a new branch. I have seen hour of peak = 24 (usually a heating design day) in the past so wondering if TimeStepIndex ==1 or numTimeStepInDay (with condition to not overwrite if set on TimeStepIndex < numTimeStepInDay) is better? If there is no load or flow the entire day maybe it doesn't matter so will try with TimeStepIndex ==1 to see what happens.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, and CppCheck thinks FirstIteration = false; at line 1791 is never used.

bool heatDDNumAllSame = true;
bool coolDDNumAllSame = true;
int priorHeatDDNum = 0;
int priorCoolDDNum = 0;
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/ZoneEquipmentManager.cc:1989]:(style),[unreadVariable],Variable 'heatDDNumAllSame' is assigned a value that is never used.
[src/EnergyPlus/ZoneEquipmentManager.cc:1990]:(style),[unreadVariable],Variable 'coolDDNumAllSame' is assigned a value that is never used.
[src/EnergyPlus/ZoneEquipmentManager.cc:1991]:(style),[unreadVariable],Variable 'priorHeatDDNum' is assigned a value that is never used.
[src/EnergyPlus/ZoneEquipmentManager.cc:1992]:(style),[unreadVariable],Variable 'priorCoolDDNum' is assigned a value that is never used.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, oh these were left over from plan A, but changed to plan B. Ok.

@@ -1004,7 +1004,6 @@ void SetUpZoneSizingArrays(EnergyPlusData &state)
// If this is a DesignSpecification:OutdoorAir:SpaceList check to make sure spaces are valid and belong to this zone
if (thisOAReq.numDSOA > 0) {
for (int spaceCounter = 1; spaceCounter <= thisOAReq.numDSOA; ++spaceCounter) {
std::string thisSpaceName = thisOAReq.dsoaSpaceNames(spaceCounter);
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/ZoneEquipmentManager.cc:1007]:(style),[unreadVariable],Variable 'thisSpaceName' is assigned a value that is never used.

@@ -315,8 +315,6 @@ void sizeZoneSpaceEquipmentPart1(EnergyPlusData &state,
: state.dataZoneTempPredictorCorrector->zoneHeatBalance(zoneNum).NonAirSystemResponse;
auto &sysDepZoneLoads = (spaceNum > 0) ? state.dataZoneTempPredictorCorrector->spaceHeatBalance(spaceNum).SysDepZoneLoads
: state.dataZoneTempPredictorCorrector->zoneHeatBalance(zoneNum).SysDepZoneLoads;
auto &zoneLatentGain = (spaceNum > 0) ? state.dataZoneTempPredictorCorrector->spaceHeatBalance(spaceNum).latentGain
: state.dataZoneTempPredictorCorrector->zoneHeatBalance(zoneNum).latentGain;
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/ZoneEquipmentManager.cc:318]:(style),[variableScope],The scope of the variable 'zoneLatentGain' can be reduced.

Copy link
Member

Choose a reason for hiding this comment

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

@mjwitte this is 1 thing causing a conflict in this branch. It looks like you did something different with zoneLatentGain maybe? I'm hesitant to smash in a conflict resolution when there may be side effects.

Copy link
Contributor

Choose a reason for hiding this comment

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

This can go all the way at the bottom of the function inside this:

        if (zsCalcSizing.zoneLatentSizing) {
            int ZoneMult = zoneOrSpace.Multiplier * zoneOrSpace.ListMultiplier;
           auto &zoneLatentGain = (spaceNum > 0) ? state.dataZoneTempPredictorCorrector>spaceHeatBalance(spaceNum).latentGain
                                          : state.dataZoneTempPredictorCorrector->zoneHeatBalance(zoneNum).latentGain;
            zoneLatentGain += (LatOutputProvided * HgAir) / ZoneMult;
        }

@@ -558,13 +556,15 @@ void sizeZoneSpaceEquipmentPart1(EnergyPlusData &state,
} else {
nonAirSystemResponse = SysOutputProvided;
if (state.dataHeatBal->doSpaceHeatBalance) {
for (int spaceNum : state.dataHeatBal->Zone(zoneNum).spaceIndexes) {
for (int spaceNumLoop : state.dataHeatBal->Zone(zoneNum).spaceIndexes) {
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/ZoneEquipmentManager.cc:561]:(style),[shadowArgument],Local variable 'spaceNum' shadows outer argument

Copy link
Member

Choose a reason for hiding this comment

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

This is the other thing causing a conflict. Obviously this is minor, and it looks like you also changed this to be spaceNum2 or something.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, you can keep either one spaceNum2 or spaceNumLoop. I'll look at the other conflict.

for (std::size_t i = 0; i < state.dataSize->FinalSpaceSizing.size(); ++i) {
updateZoneSizingEndZoneSizingCalc5(state.dataSize->FinalSpaceSizing[i], state.dataSize->CalcFinalSpaceSizing[i]);
for (std::size_t j = 0; j < state.dataSize->FinalSpaceSizing.size(); ++j) {
updateZoneSizingEndZoneSizingCalc5(state.dataSize->FinalSpaceSizing[j], state.dataSize->CalcFinalSpaceSizing[j]);
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/ZoneEquipmentManager.cc:3324]:(style),[shadowVariable],Local variable 'i' shadows outer variable
[src/EnergyPlus/ZoneEquipmentManager.cc:3333]:(style),[shadowVariable],Local variable 'i' shadows outer variable

const Real64 heatLoadRatio = thisZEqList.SequentialHeatingFraction(state, equipNum);
const Real64 coolLoadRatio = thisZEqList.SequentialCoolingFraction(state, equipNum);
heatLoadRatio = thisZEqList.SequentialHeatingFraction(state, equipNum);
coolLoadRatio = thisZEqList.SequentialCoolingFraction(state, equipNum);
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/ZoneEquipmentManager.cc:4272]:(style),[shadowVariable],Local variable 'heatLoadRatio' shadows outer variable
[src/EnergyPlus/ZoneEquipmentManager.cc:4273]:(style),[shadowVariable],Local variable 'coolLoadRatio' shadows outer variable

@Myoldmopar
Copy link
Member

The conflicts here are ever so slightly more complex than I want to deal with right now. If I need to do it later, I can, but I'll want to grok things more deeply than I would like this morning.

@rraustad
Copy link
Contributor Author

These are a little tricky. I started last night just accepting the develop version and running CppCheck again to see what style suggestions remain. Obviously that did not go well with WindowManager. So don't waste anymore time on these. I'll either fix them or punt and do them over.

@Myoldmopar
Copy link
Member

Thanks for resolving things @rraustad. This looks good up here. I'll pull and test.

@Myoldmopar
Copy link
Member

Still clean with develop, thanks @rraustad

@Myoldmopar Myoldmopar merged commit 84646a7 into develop Sep 11, 2024
10 checks passed
@Myoldmopar Myoldmopar deleted the CppCheck-ZoneEquipmentManager branch September 11, 2024 16:11
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.

7 participants