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

Implement Carroll method for Interior Radiant Heat Exchange #7534

Merged
merged 30 commits into from
Jan 13, 2020

Conversation

mbadams5
Copy link
Contributor

@mbadams5 mbadams5 commented Sep 30, 2019

Pull request overview

This PR implements the Carroll method for interior radiant heat exchange instead of the current Hottel's ScriptF method. The Carroll method has linear complexity while the ScriptF method has O(n^2) complexity. This greatly improves runtime (up to 95% runtime reduction) when a zone has a large number of surfaces.

New option added to PerformancePrecisionTradeoffs:
A2; \field Zone Radiant Exchange Algorithm
\note Determines which algorithm will be used to solve long wave radiant exchange among surfaces within a zone.
\type choice
\key ScriptF
\key CarrollMRT
\default ScriptF

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

@mbadams5 mbadams5 added the Performance Includes code changes that are directed at improving the runtime performance of EnergyPlus label Sep 30, 2019
@mbadams5 mbadams5 added this to the EnergyPlus Future milestone Sep 30, 2019
\type choice
\key ScriptF
\key CarrollMRT
\default ScriptF
Copy link
Contributor

Choose a reason for hiding this comment

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

We have a proliferation of these single-function objects. I'd prefer to see this as a new field in, say, HeatBalanceAlgorithm.
Or a better fit might be the new PerformancePrecisionTradeoffs object since that's the intent here.

Copy link
Member

Choose a reason for hiding this comment

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

@mjwitte I can do that.

Is the PerformancePrecisionTradeoffs object merged in yet? If not, I think it would be best to have these tradeoffs in existing topical settings objects (like HeatBalanceAlgorithm) with a clear document on the various tradeoff options and where to find them. There are already several alternatives that aren't in the PerformancePrecisionTradeoffs that can be included, too (e.g., CTF vs. finite difference, and the air heat balance algorithm).

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, it's in v9.2. There is no plan to move existing algorithm options into PerformancePrecisionTradeoffs.

@nealkruis nealkruis marked this pull request as ready for review October 21, 2019 20:19
@mjwitte mjwitte added the IDDChange Code changes impact the IDD file (cannot be merged after IO freeze) label Nov 12, 2019
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.

Getting close. See comments below. Checked in a small tweak to the code and some doc cleanups (easier to just fix than to list here).

Array1<Real64> &Fp // VECTOR OF OPPENHEIM RESISTNACE VALUES
);

void CalcMatrixInverse(Array2<Real64> &A, // Matrix: Gets reduced to L\U form
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the indent got lost here.

src/EnergyPlus/HeatBalanceIntRadExchange.cc Outdated Show resolved Hide resolved
Real64 IRfromParentZone_acc(0.0); // Local accumulator
for (size_type SendZoneSurfNum = 0; SendZoneSurfNum < s_zone_Surfaces; ++SendZoneSurfNum, ++lSR) {
Real64 const scriptF(zone_ScriptF[lSR]); // [ lSR ] == ( SendZoneSurfNum+1, RecZoneSurfNum+1 )
if (CarrollMethod) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a little disappointing to see multiple if (CarrollMethod) in these loops. But I see there's some significant shared sections. I guess other streamlining of CalcInteriorRadExchange will have to wait for another pass.

src/EnergyPlus/HeatBalanceIntRadExchange.cc Show resolved Hide resolved
src/EnergyPlus/HeatBalanceIntRadExchange.cc Show resolved Hide resolved
DoCoilDirectSolutions =
UtilityRoutines::MakeUPPERCase(fields.at("use_coil_direct_solutions"))=="YES";
}
if (fields.find("zone_radiant_exchange_algorithm") != fields.end()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

So, I see input changes, but no output changes. We let PerformancePrecisionTradeoffs into the code without it generating a lick of output to identify what options are active? Would be great if you could add an eio line to report these (similar to System Convergence Limits, for example). If not here, then post an issue to add it.

@@ -141,6 +141,7 @@ ADD_SIMULATION_TEST(IDF_FILE AirflowWindowsAndBetweenGlassShades.idf EPW_FILE US
ADD_SIMULATION_TEST(IDF_FILE ASIHPMixedTank.idf EPW_FILE USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw)
ADD_SIMULATION_TEST(IDF_FILE BaseBoardElectric.idf EPW_FILE USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw)
ADD_SIMULATION_TEST(IDF_FILE CVRhMinHum.idf EPW_FILE USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw)
ADD_SIMULATION_TEST(IDF_FILE CarrollMRT-RefBldgLargeOfficeNew2004_Chicago.idf EPW_FILE USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ran this with and without CarrollMRT (unscientifically on my laptop) and saw negligible change in run time. I suppose we don't have a better example file in the test suite. Do you have a test file that you could attach at the top of the PR that illustrates the potential speed-up?


Carroll, J. A., 1980, An `MRT Method' of Computing Radiant Energy Exchange in Rooms, Proceedings of the Second Systems Simulation and Economic Analysis Conference, San Diego, CA.

Carroll, J. A., 1980a, "An MRT method of computing radiant energy exchange in rooms," Proceedings of the 2nd Systems Simulation and Economic Analysis Conference, San Diego, CA.
Copy link
Contributor

Choose a reason for hiding this comment

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

1980 and 1980a look like the same paper, just formatted a little differently.


CalcFMRT(N, A, FMRT);

std::string const error_string = " ** Severe ** Geometry not compatible with Carroll MRT Zone Radiant Exchange method.\n";
Copy link
Contributor

Choose a reason for hiding this comment

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

This test fails locally on windows, because of mismatched line endings. Need to use a delimited string for the comparison error message, like here.

@nealkruis
Copy link
Member

@mjwitte @RKStrand This is ready for another review.

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.

Comments have been addressed.
#7646 posted to add eio output for PerformancePrecisionTradeoffs.
Ran the new example file with and without the CarrollMRT option, annual source energy differs by about 1.5%.
Merged in develop one more time to check performance.

auto const &construct(Construct(ConstrNumRec));
auto &surface_window(SurfaceWindow(RecSurfNum));
auto const &rec_construct(Construct(ConstrNumRec));
auto &rec_surface_window(SurfaceWindow(RecSurfNum));
Copy link
Contributor

Choose a reason for hiding this comment

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

Good to clarify rec_surface

@mjwitte
Copy link
Contributor

mjwitte commented Dec 6, 2019

@RKStrand Do you want to review before this is merged?

@RKStrand
Copy link
Contributor

RKStrand commented Dec 7, 2019

@mjwitte I'm not sure when I will get around to doing this (finals start next week) and having looked around at the code once already I trust your review. I don't want to hold this up.

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.

@nealkruis I know a performance slowdown of 0.49% is small, it seems we can do better than that here. CalcInteriorRadExchange is a known hot spot that gets called many times. There are four if (CarrollMethod) blocks, two of which are inside surface loops. It seems small, but these add up.

Looking for ways to reduce these extra ifs. The brute force way would be two separate CalcInteriorRadExchange functions, one for CMRT and one for ScriptF. I realize that could result is signficant chunks of duplicate code. So, then we could break those out into some smaller functions? Just thinking out loud here.

}
} else {
SendSurfTemp = SurfaceTemp(SendSurfNum);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

These lines appear to be identical to the logic in lines 348:360. Why not save SendSurfTemp in an array and just grab it here instead of going through all these gymnastics all over again? Seems that would improve the CMRT speed.

And then we're doing all the same stuff again for RecSurfs in 394:420? This one gets emissivities too, but seems we could do that up in 348:360, save arrays of temps and emissivities and get rid of all of these ifs.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Here is something else to consider. There is a possibility that we will want to run both ScriptF and CarrollMRT within the same simulation. For the same enclosure. In the same timestep. My guess is that the difference between ScriptF and CarrollMRT is not uniform, but rather geometry dependent. I can see an optimization where we run both for all enclosures for a few time steps and then choose the algorithm on an enclosure basis based on whether the two algorithms produce similar results within threshold (CarrollMRT) or not (ScriptF).

Copy link
Member

Choose a reason for hiding this comment

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

@mjwitte I like your suggestion. Let me see if I can clean it up a bit.

It's always a question of where to stop. This whole file could probably use a refactor/redesign, especially if we are moving towards enclosures as a concept. We could make an Enclosure class that contains many of these methods broken out into a cleaner design to avoid repetition.

@chipbarnaby
Copy link

chipbarnaby commented Dec 8, 2019 via email

@amirroth
Copy link
Collaborator

amirroth commented Dec 9, 2019

Running CarrollMRT, writing the surface temperatures (or net heat fluxes) into a temporary array, comparing with ScriptF and after a few iterations choosing whether to use CarrollMRT full time is "not possible"?

@chipbarnaby
Copy link

chipbarnaby commented Dec 9, 2019 via email

@RKStrand
Copy link
Contributor

RKStrand commented Dec 9, 2019

I think that writing results into different arrays is possible (it would have to be done for both surface temperature and heat flux histories for all surfaces), but it's probably going to be a bit messy (in a section of code that already isn't a shining example of easy to follow). The question is how many time steps would you need to go before you had an accurate assessment on whether or not the results are similar enough. I think Chip's idea that checking the view factors might be a little less painful if he can find what he is looking for in the literature.

One other thing--whatever method would need to perhaps get a sense for how long the simulation is going to be. It might not be worth switching to a faster method after a period of time if the user is only doing a design day or two?

@amirroth
Copy link
Collaborator

amirroth commented Dec 9, 2019

Chip suggested that we look at view factors instead of surface heat-fluxes/temps, and that's probably a cleaner idea.

@nealkruis
Copy link
Member

nealkruis commented Dec 16, 2019

@mjwitte I think the remaining diffs are related to the fact that receiving and sending surface temperatures were not being calculated consistently before when a complex glazing system had between-glass shading/blinds.

In these cases, the sending surface temperature was calculated as surface_window.EffInsSurfTemp and the receiving surfaces was calculated as SurfaceTemp(RecSurfNum).

It's not clear what it should be. In this branch I'm using SurfaceTemp(SurfNum).

@mjwitte mjwitte added the NewFeature Includes code to add a new feature to EnergyPlus label Dec 27, 2019
@mjwitte
Copy link
Contributor

mjwitte commented Dec 30, 2019

@nealkruis I've made a couple of commits that eliminate the complex glazing diffs and give a slight speed improvement now. If you agree with these changes, I'll merge.

@Myoldmopar
Copy link
Member

This does look clean from a CI perspective, though the branch is now kinda out-of-date. Is it worth just pulling develop in to get final results before merge? I'm not saying we need to, just wondering.

@mjwitte
Copy link
Contributor

mjwitte commented Jan 13, 2020

@nealkruis This will merge after CI comes back all green and pretty. If you want to review my changes before this drops in, now's your chance.

@mjwitte
Copy link
Contributor

mjwitte commented Jan 13, 2020

@Myoldmopar Is something amiss on Mac?

@Myoldmopar
Copy link
Member

Yes, something looks to have gone awry. Disregard for the moment and continue merging as needed. I'll take a look.

@Myoldmopar
Copy link
Member

I took the Mac down for a full reboot and got it going again. It was working great recently so hopefully that's all it needed.

@mjwitte mjwitte merged commit 7e0772b into develop Jan 13, 2020
@mjwitte mjwitte deleted the carroll-mrt branch January 13, 2020 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IDDChange Code changes impact the IDD file (cannot be merged after IO freeze) NewFeature Includes code to add a new feature to 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.