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

TDD surface reordering and bug fixing #8540

Merged
merged 26 commits into from
Mar 4, 2021
Merged

Conversation

xuanluo113
Copy link
Contributor

@xuanluo113 xuanluo113 commented Feb 16, 2021

Pull request overview

This branch includes the following refactoring and bug fixing features.

In particular, for the model DaylightingDeviceTubular.idf in the current testfile list, the outside and inside surface temperature of the TDD surfaces are:
Before -
image
After -
image

We also developed a new test file for tdd surface attached to test the bug fixing. If needed, the new file can be included in the current test suite.
5ZoneWithAttic_DaylightingDeviceDiffuser.idf.txt

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

@xuanluo113 xuanluo113 changed the title Tdd surf TDD surface reordering and bug fixing Feb 16, 2021
@xuanluo113 xuanluo113 self-assigned this Feb 25, 2021
@xuanluo113 xuanluo113 added Defect Includes code to repair a defect in EnergyPlus Performance Includes code changes that are directed at improving the runtime performance of EnergyPlus labels Feb 25, 2021
@xuanluo113 xuanluo113 added this to the EnergyPlus 9.5.0 milestone Feb 25, 2021
@xuanluo113
Copy link
Contributor Author

@mjwitte Would you mind reviewing one more branch? 😀

@xuanluo113 xuanluo113 marked this pull request as ready for review February 25, 2021 22:16
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.

Ran unit tests locally - all OK.

Reviewed results for the defect file and for testfile DaylightingDeviceTubular before and after this fix. Changes look reasonable and dome and diffuser surface temps match each other now (not perfect, but as designed).

Some code comments below.

Comment on lines 1144 to 1145
for (SurfNum = Zone(ZoneNum).HTSurfaceFirst; SurfNum <= Zone(ZoneNum).SurfaceLast; ++SurfNum) {
if (!Surface(SurfNum).HeatTransSurf) continue; // Skip non-heat transfer surfaces
Copy link
Contributor

Choose a reason for hiding this comment

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

This if can be deleted.

Comment on lines 1794 to 1795
for (SurfNum = Zone(ZoneNum).HTSurfaceFirst; SurfNum <= Zone(ZoneNum).SurfaceLast; ++SurfNum) {
if (!Surface(SurfNum).HeatTransSurf) continue; // Skip non-heat transfer surfaces
Copy link
Contributor

Choose a reason for hiding this comment

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

Another if to delete.

@@ -545,7 +545,7 @@ namespace HeatBalanceIntRadExchange {
}
int numEnclosureSurfaces = 0;
for (int zoneNum : thisEnclosure.ZoneNums) {
for (int surfNum = Zone(zoneNum).SurfaceFirst, surfNum_end = Zone(zoneNum).SurfaceLast; surfNum <= surfNum_end; ++surfNum) {
for (int surfNum = Zone(zoneNum).HTSurfaceFirst, surfNum_end = Zone(zoneNum).SurfaceLast; surfNum <= surfNum_end; ++surfNum) {
if (Surface(surfNum).HeatTransSurf) ++numEnclosureSurfaces;
Copy link
Contributor

Choose a reason for hiding this comment

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

The if portion here can be deleted, keep ++numEnclosureSurfaces;

@@ -568,13 +568,13 @@ namespace HeatBalanceIntRadExchange {
int enclosureSurfNum = 0;
for (int const zoneNum : thisEnclosure.ZoneNums) {
int priorZoneTotEnclSurfs = enclosureSurfNum;
for (int surfNum = Zone(zoneNum).SurfaceFirst, surfNum_end = Zone(zoneNum).SurfaceLast; surfNum <= surfNum_end; ++surfNum) {
for (int surfNum = Zone(zoneNum).HTSurfaceFirst, surfNum_end = Zone(zoneNum).SurfaceLast; surfNum <= surfNum_end; ++surfNum) {
if (!Surface(surfNum).HeatTransSurf) continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

Delete.

if (!Surface(surfNum).HeatTransSurf) continue;
++enclosureSurfNum;
thisEnclosure.SurfacePtr(enclosureSurfNum) = surfNum;
}
// Store SurfaceReportNums to maintain original reporting order
for (int allSurfNum = Zone(zoneNum).SurfaceFirst, surfNum_end = Zone(zoneNum).SurfaceLast; allSurfNum <= surfNum_end; ++allSurfNum) {
for (int allSurfNum = Zone(zoneNum).HTSurfaceFirst, surfNum_end = Zone(zoneNum).SurfaceLast; allSurfNum <= surfNum_end; ++allSurfNum) {
if (!Surface(DataSurfaces::AllSurfaceListReportOrder[allSurfNum - 1]).HeatTransSurf) continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

Delete?

if (Zone(Loop).SurfaceFirst > 0) {
for (SurfNum = Zone(Loop).SurfaceFirst; SurfNum <= Zone(Loop).SurfaceLast; ++SurfNum) {
if (Zone(Loop).HTSurfaceFirst > 0) {
for (SurfNum = Zone(Loop).HTSurfaceFirst; SurfNum <= Zone(Loop).SurfaceLast; ++SurfNum) {
if (!Surface(SurfNum).HeatTransSurf) continue; // Skip non-heat transfer surfaces
Copy link
Contributor

Choose a reason for hiding this comment

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

Delete?

@@ -6246,7 +6246,7 @@ namespace ZoneTempPredictorCorrector {
SumSysMCpT /= ZoneMult;
}
// Sum all surface convection: SumHA, SumHATsurf, SumHATref (and additional contributions to SumIntGain)
for (SurfNum = Zone(ZoneNum).SurfaceFirst; SurfNum <= Zone(ZoneNum).SurfaceLast; ++SurfNum) {
for (SurfNum = Zone(ZoneNum).HTSurfaceFirst; SurfNum <= Zone(ZoneNum).SurfaceLast; ++SurfNum) {

if (!Surface(SurfNum).HeatTransSurf) continue; // Skip non-heat transfer surfaces
Copy link
Contributor

Choose a reason for hiding this comment

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

Delete?

@@ -6542,7 +6542,7 @@ namespace ZoneTempPredictorCorrector {
SumNonAirSystem = NonAirSystemResponse(ZoneNum) + SumConvHTRadSys(ZoneNum) + SumConvPool(ZoneNum);

// Sum all surface convection: SumHA, SumHATsurf, SumHATref (and additional contributions to SumIntGain)
for (SurfNum = Zone(ZoneNum).SurfaceFirst; SurfNum <= Zone(ZoneNum).SurfaceLast; ++SurfNum) {
for (SurfNum = Zone(ZoneNum).HTSurfaceFirst; SurfNum <= Zone(ZoneNum).SurfaceLast; ++SurfNum) {

if (!Surface(SurfNum).HeatTransSurf) continue; // Skip non-heat transfer surfaces
Copy link
Contributor

Choose a reason for hiding this comment

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

Deete?

@@ -1443,10 +1443,30 @@ namespace SurfaceGeometry {

if (SurfaceTmpClassMoved(SubSurfNum)) continue;
if (state.dataSurfaceGeometry->SurfaceTmp(SubSurfNum).Zone != ZoneNum) continue;
if (state.dataSurfaceGeometry->SurfaceTmp(SubSurfNum).ExtBoundCond > 0) continue; // Exterior
Copy link
Contributor

Choose a reason for hiding this comment

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

The comments above starting at line 1318 should describe these new groupings/order.

int SurfaceLast; // Last Heat Transfer Surface in Zone
int NonWindowSurfaceFirst; // First Non-Window Heat Transfer Surface in Zone
int NonWindowSurfaceLast; // Last Non-Window Heat Transfer Surface in Zone
int WindowSurfaceFirst; // First Window Heat Transfer Surface in Zone
int WindowSurfaceLast; // Last Window Heat Transfer Surface in Zone
int NonDomeLast; // Last non TDD Dome Surface in Zone
Copy link
Contributor

Choose a reason for hiding this comment

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

The comments here need to be very clear about what's included in each group since some of these overlap.

Copy link
Collaborator

Choose a reason for hiding this comment

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

For clarity and self-documentation purposes, I suggest that these things be done in pairs, XFirst/XLast. Even if some combination of XFirst and YFirst or XLast and YLast are redundant, that is better than having to remember which combination of XFirst and YLast corresponds to which subset. The name X can be the descriptive name of the subset.

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.

@xuanluo113 This is a great improvement - loop intent is soooo much clearer now.

I've noted a few things below that can be cleaned up later.

Mac CI looks good, but I'll let Linux finish before merging this today.

Comment on lines 7063 to 7064
int const firstSurf = Zone(zoneNum).HTSurfaceFirst;
int const lastSurf = Zone(zoneNum).NonDomeLast;
int const lastSurf = Zone(zoneNum).OpaqOrWinSurfaceLast;
Copy link
Contributor

Choose a reason for hiding this comment

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

HTSurfaceFirst --> OpaqOrWinSurfaceFirst

Comment on lines 7485 to 7486
int const firstSurf = Zone(zoneNum).HTSurfaceFirst;
int const lastSurf = Zone(zoneNum).NonDomeLast;
int const lastSurf = Zone(zoneNum).OpaqOrWinSurfaceLast;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.

Comment on lines 7582 to 7583
int const firstSurf = Zone(zoneNum).HTSurfaceFirst;
int const lastSurf = Zone(zoneNum).NonDomeLast;
int const lastSurf = Zone(zoneNum).OpaqOrWinSurfaceLast;
Copy link
Contributor

Choose a reason for hiding this comment

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

And here.

@@ -13797,7 +13797,7 @@ namespace EnergyPlus::OutputReportTabular {
Real64 adjFeneSurfNetRadSeq = 0.0;

// code from ComputeDelayedComponents starts
for (int jSurf = Zone(zoneIndex).HTSurfaceFirst; jSurf <= Zone(zoneIndex).SurfaceLast; ++jSurf) {
for (int jSurf = Zone(zoneIndex).HTSurfaceFirst; jSurf <= Zone(zoneIndex).HTSurfaceLast; ++jSurf) {
if (!Surface(jSurf).HeatTransSurf) continue; // Skip non-heat transfer surfaces
Copy link
Contributor

Choose a reason for hiding this comment

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

Delete.

@@ -14011,7 +14011,7 @@ namespace EnergyPlus::OutputReportTabular {

// opaque surfaces - must combine individual surfaces by class and other side conditions
delayOpaque = 0.0;
for (int kSurf = Zone(zoneIndex).HTSurfaceFirst; kSurf <= Zone(zoneIndex).SurfaceLast; ++kSurf) {
for (int kSurf = Zone(zoneIndex).HTSurfaceFirst; kSurf <= Zone(zoneIndex).HTSurfaceLast; ++kSurf) {
if (!Surface(kSurf).HeatTransSurf) continue; // Skip non-heat transfer surfaces
Copy link
Contributor

Choose a reason for hiding this comment

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

Delete.

@@ -1901,7 +1901,7 @@ namespace ThermalComfort {
// Note that area*emissivity needs to be recalculated because of the possibility of changes to the emissivity via the EMS
SumAET = 0.0;
ZoneAESum(ZoneNum) = 0.0;
for (SurfNum2 = Zone(ZoneNum).SurfaceFirst; SurfNum2 <= Zone(ZoneNum).SurfaceLast; ++SurfNum2) {
for (SurfNum2 = Zone(ZoneNum).HTSurfaceFirst; SurfNum2 <= Zone(ZoneNum).SurfaceLast; ++SurfNum2) {
if ((Surface(SurfNum2).HeatTransSurf) && (SurfNum2 != SurfNum)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Delete first part of if

}

// The window subsurfaces (includes SurfaceClass::TDD_Diffuser)
// The exterior window subsurfaces (includes SurfaceClass::Window and SurfaceClass::GlassDoor) goes next
Copy link
Contributor

Choose a reason for hiding this comment

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

Remember to edit the comment block at the top of this function to be current and it should mention the various first/last variables.

Comment on lines 702 to 703
int OpaqOrIntMassSurfaceFirst; // First Opaque or Interior Mass Heat Transfer Surface in Zone
int OpaqOrIntMassSurfaceLast; // Last Opaque or Interior Mass Heat Transfer Surface in Zone
Copy link
Contributor

Choose a reason for hiding this comment

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

Just be clear, I would add (including doors)

@Myoldmopar
Copy link
Member

Alright, lots of conflicts, but they were all tiny and easy to resolve as expected. I've got them nearly done and I'll push it up and let CI have another pass tonight.

@xuanluo113
Copy link
Contributor Author

@Myoldmopar Thanks.

@Myoldmopar
Copy link
Member

Ran all unit and integration tests, they pass. Spot checked regressions, they look similar to what was happening on here. If CI agrees, then I believe this will be ready to go in later.

@xuanluo113
Copy link
Contributor Author

@Myoldmopar Thanks. Added a commit of minor updates of some code comments.

for (IntWin = Zone(ZoneNum).WindowSurfaceFirst; IntWin <= Zone(ZoneNum).WindowSurfaceLast; ++IntWin) {
if (Surface(IntWin).ExtBoundCond >= 1) {
for (IntWin = state.dataHeatBal->Zone(ZoneNum).WindowSurfaceFirst; IntWin <= state.dataHeatBal->Zone(ZoneNum).WindowSurfaceLast; ++IntWin) {
if (Surface(IntWin).ExtBoundCond >= 1) { // in develop this was Surface(IntWin).Class == SurfaceClass::Window && Surface(IntWin).ExtBoundCond >= 1
Copy link
Contributor

Choose a reason for hiding this comment

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

@Myoldmopar Right, the if==Window is redundant now, because the loop is over just window surfaces.

@@ -2721,8 +2721,8 @@ namespace ZoneTempPredictorCorrector {

for (Loop = 1; Loop <= state.dataGlobal->NumOfZones; ++Loop) {
FirstSurfFlag = true;
if (Zone(Loop).HTSurfaceFirst > 0) {
for (SurfNum = Zone(Loop).HTSurfaceFirst; SurfNum <= Zone(Loop).HTSurfaceLast; ++SurfNum) {
if (state.dataHeatBal->Zone(Loop).HTSurfaceFirst > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@xuanluo113 Is this line still necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's okay to remove.

@Myoldmopar
Copy link
Member

1 file with diffs, just like before. However, there is one unit test that was failing with an array index problem in the previous commit, unrelated to bringing in develop. @xuanluo113 it looks like it might've been introduced with the "address comments" commit (8b9fde0). That'll need to be addressed before merging this.

@mitchute
Copy link
Collaborator

mitchute commented Mar 3, 2021

@Myoldmopar I built and ran unit tests here locally. They all ran successfully.

[----------] Global test environment tear-down
[==========] 1510 tests from 26 test suites ran. (140266 ms total)
[  PASSED  ] 1510 tests

@mitchute
Copy link
Collaborator

mitchute commented Mar 3, 2021

Debug also passess

[----------] Global test environment tear-down
[==========] 1510 tests from 26 test suites ran. (789286 ms total)
[  PASSED  ] 1510 tests.

@Myoldmopar
Copy link
Member

OK, so Ci is way too bogged down right now. We're going to take evidence from multiple sources here to get this merged.

  • The one diff is what was being seen before, no problem
  • @mitchute confirmed that the unit test passes in a debug build, thanks
  • I ran some sampled performance runs locally, and I didn't have time to run the full suites, but I did run chunks of annual runs. The results were basically a wash, no real major gains across the board, but some files did show a few percent improvement.

I am going to merge this now so we can move on. Thanks @xuanluo113 and @mjwitte

@Myoldmopar Myoldmopar merged commit 699d1f5 into NREL:develop Mar 4, 2021
@Myoldmopar Myoldmopar deleted the tdd-surf branch March 4, 2021 15:49
@mjwitte
Copy link
Contributor

mjwitte commented Mar 4, 2021

Linux results finally came through. Performance improvement is 0.2136%. Not huge, but moving in the right direction.

@amirroth
Copy link
Collaborator

amirroth commented Mar 4, 2021

A couple of things.

First, I thought the point of this particular PR was to fix a bug because TDD_dome was being included in the wrong calculations.

Second, performance-wise getting one data-driven branch out of a loop is good because you are not hitting branch mispredictions and pipeline flushes as often. But it is not enough to optimizations like vectorization going. You need to get all of these types of branches (and crazy function calls like the EvalInsideMovableInsulation) out before that stuff kicks in. Just looking over HeatBalanceSurfaceManager, there are still multiple places where we do if (!Surface(SurfNum).HeatTransSurf) continue; and I am sure we are still doing it in other files as well. I was not expecting a big performance improvement just from this specific PR, but it is a performance design pattern that we need to establish. Along with other code/documentation design patterns like matching First/Last pairs, and positive descriptors for variables.

I am happy with this PR.

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 Performance Includes code changes that are directed at improving the runtime performance of EnergyPlus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TDD diffuser and dome inside and outside surface heat balance calculations not consistent with EngRef
10 participants