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

Fix #10302 - CalcEquipmentFlowRates assert failure due to out of bounds std::array indexing #10528

Merged
merged 3 commits into from
May 31, 2024

Conversation

jmarrec
Copy link
Contributor

@jmarrec jmarrec commented May 27, 2024

Pull request overview

DefectFiles: show fix

cd EnergyPlusDevSupport/DefectFiles/10000s/10302

before:

image

After:

image

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

@jmarrec jmarrec added the Defect Includes code to repair a defect in EnergyPlus label May 27, 2024
@jmarrec jmarrec requested a review from Myoldmopar May 27, 2024 13:40
@jmarrec jmarrec self-assigned this May 27, 2024
Comment on lines +59 to +78
TEST_F(EnergyPlusFixture, CalcConvCoeffBetweenPlates)
{
constexpr Real64 TempSurf1 = 251.0; // temperature of surface 1
constexpr Real64 TempSurf2 = 26.5; // temperature of surface 2

constexpr Real64 Tref = 0.5 * (TempSurf1 + TempSurf2);

constexpr Real64 maxArrayTemp = 126.85; // This is the max temperature in the `Temps` array that stores the correlation temps
EXPECT_TRUE(Tref > maxArrayTemp);

// Irrelevant to this test
constexpr Real64 AirGap = 0.05; // characteristic length [m]
constexpr Real64 CosTilt = 0.87; // cosine of surface tilt angle relative to the horizontal
constexpr Real64 SinTilt = 0.80; // sine of surface tilt angle relative to the horizontal

Real64 hConvCoef = EnergyPlus::SolarCollectors::CollectorData::CalcConvCoeffBetweenPlates(TempSurf1, TempSurf2, AirGap, CosTilt, SinTilt);
EXPECT_FALSE(std::isnan(hConvCoef));
EXPECT_TRUE(std::isfinite(hConvCoef));
EXPECT_NEAR(4.71593, hConvCoef, 0.001);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before fix:

$ Products/energyplus_tests -- --gtest_filter=*CalcConvCoeffBetweenPlates*
Note: Google Test filter = *CalcConvCoeffBetweenPlates*
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from EnergyPlusFixture
[ RUN      ] EnergyPlusFixture.CalcConvCoeffBetweenPlates
/Users/julien/Software/Others/EnergyPlus/tst/EnergyPlus/unit/SolarCollectors.unit.cc:76: Failure
Value of: std::isfinite(hConvCoef)
  Actual: false
Expected: true
/Users/julien/Software/Others/EnergyPlus/tst/EnergyPlus/unit/SolarCollectors.unit.cc:77: Failure
The difference between 4.71593 and hConvCoef is inf, which exceeds 0.001, where
4.71593 evaluates to 4.7159300000000002,
hConvCoef evaluates to -inf, and
0.001 evaluates to 0.001.
[  FAILED  ] EnergyPlusFixture.CalcConvCoeffBetweenPlates (69 ms)
[----------] 1 test from EnergyPlusFixture (69 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (69 ms total)
[  PASSED  ] 0 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] EnergyPlusFixture.CalcConvCoeffBetweenPlates

Comment on lines +57 to +59
#include <EnergyPlus/EPVector.hh>
#include <EnergyPlus/EnergyPlus.hh>
#include <EnergyPlus/Plant/DataPlant.hh>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Missing includes

@@ -1979,7 +1979,7 @@ namespace SolarCollectors {
CondOfAir = Conductivity[Index];
PrOfAir = Pr[Index];
DensOfAir = Density[Index];
} else if (Index > NumOfPropDivisions) {
} else if (Index >= NumOfPropDivisions) { // 0-index, hence MaxIndex = NumOfPropDivisions - 1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actual fix

jmarrec added 2 commits May 30, 2024 00:12
```shell
$ Products/energyplus_tests -- --gtest_filter=*CalcConvCoeffBetweenPlates*
Note: Google Test filter = *CalcConvCoeffBetweenPlates*
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from EnergyPlusFixture
[ RUN      ] EnergyPlusFixture.CalcConvCoeffBetweenPlates
/Users/julien/Software/Others/EnergyPlus/tst/EnergyPlus/unit/SolarCollectors.unit.cc:76: Failure
Value of: std::isfinite(hConvCoef)
  Actual: false
Expected: true
/Users/julien/Software/Others/EnergyPlus/tst/EnergyPlus/unit/SolarCollectors.unit.cc:77: Failure
The difference between 4.71593 and hConvCoef is inf, which exceeds 0.001, where
4.71593 evaluates to 4.7159300000000002,
hConvCoef evaluates to -inf, and
0.001 evaluates to 0.001.
[  FAILED  ] EnergyPlusFixture.CalcConvCoeffBetweenPlates (69 ms)
[----------] 1 test from EnergyPlusFixture (69 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (69 ms total)
[  PASSED  ] 0 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] EnergyPlusFixture.CalcConvCoeffBetweenPlates
```
@jmarrec jmarrec force-pushed the 10302-CalcEquipmentFlowRates branch from 6bc2384 to 3f70b49 Compare May 29, 2024 22:12
Copy link
Contributor

@mjwitte mjwitte left a comment

Choose a reason for hiding this comment

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

Fix looks good. Not sure why there aren't any CI results. Updating with develop and will wait for CI to run.

@mjwitte mjwitte assigned Myoldmopar and unassigned jmarrec May 31, 2024
@Myoldmopar
Copy link
Member

All good here, thanks @jmarrec and @mjwitte, merging.

@Myoldmopar Myoldmopar merged commit 19e1844 into develop May 31, 2024
15 checks passed
@Myoldmopar Myoldmopar deleted the 10302-CalcEquipmentFlowRates branch May 31, 2024 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Defect Includes code to repair a defect in EnergyPlus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CalcEquipmentFlowRates assert failure
7 participants