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

Update GHE Interpolation Routine #9535

Merged
merged 6 commits into from
Jul 28, 2022
Merged

Update GHE Interpolation Routine #9535

merged 6 commits into from
Jul 28, 2022

Conversation

mitchute
Copy link
Collaborator

Pull request overview

  • Updates the GHE interpolation routine

In working on something else, I noticed that the GHE interpolation routine was pretty convoluted and more complicated than it needed to be. This updates it to be more straightforward and to use features from the stdlib. I've also added a few more unit tests.

I'm seeing small diffs, which I never fully got to the root cause of. When I write the interpolation input/output to a file for the DOAToWaterToAirHPSupply example file and then compare it against the scipy interpolation routine, I get a slightly better RMSE for the updated function. I don't think it's worth digging in any further. Both versions were working, but this one is more modern and is slightly more accurate.

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

@mitchute mitchute added the Refactoring Includes code changes that don't change the functionality of the program, just perform refactoring label Jul 14, 2022
@mitchute mitchute added this to the EnergyPlus 22.2 IOFreeze milestone Jul 14, 2022
@mitchute mitchute requested a review from Myoldmopar July 14, 2022 18:28
@mitchute mitchute self-assigned this Jul 14, 2022
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.

Couple incredibly small tweaks, but this is a great improvement. A 1-D interpolation function shouldn't be all that complex, and this makes that a reality for the GHE. Could consider generalizing this out later for other parts of E+ that might use this.

@@ -2957,99 +2956,40 @@ Real64 GLHESlinky::calcHXResistance(EnergyPlusData &state)

//******************************************************************************

Real64 GLHEBase::interpGFunc(Real64 const LnTTsVal // The value of LN(t/TimeSS) that a g-function
) const
Real64 GLHEBase::interpGFunc(Real64 const LnTTsVal) const
Copy link
Member

Choose a reason for hiding this comment

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

Let's see, this function is only about 100x easier to read and understand now. This is great. I might have a few suggested tweaks, but this seems awesome.

// to find the correct g-function value for a
// known value of the natural log of (T/Ts)
auto &x = this->myRespFactors->LNTTS;
auto &y = this->myRespFactors->GFNC;
Copy link
Member

Choose a reason for hiding this comment

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

Normally, using references to lists is not the right approach, but this is a bit different. In this case, you don't actually know which index you are going to use yet. Using x and y here make this logic extremely easy to read and understand. 👍

// Lund, Sweden, June 1987.
auto x_begin = x.begin();
auto x_end = x.end();
double x_val = LnTTsVal;
Copy link
Member

Choose a reason for hiding this comment

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

Is it worth using references for any of these? I'm not sure how heavy an iterator is, but usually we use references for anything heavier than POD. Also the references could be const I think just to make it clear.

double x_high = x[u_idx];
double y_low = y[l_idx];
double y_high = y[u_idx];
return (x_val - x_low) / (x_high - x_low) * (y_high - y_low) + y_low;
Copy link
Member

Choose a reason for hiding this comment

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

These intermediate variables need to be Real64. I was going to say you could also remove them entirely and just use the lookups in the function, but frankly, this makes it just so easy to see the interpolation, that I'd say leave them.

EXPECT_NEAR(thisGHE.interpGFunc(-14.293207), -2.001293, tolerance);
EXPECT_NEAR(thisGHE.interpGFunc(-14.260100), -1.978820, tolerance);
}

Copy link
Member

Choose a reason for hiding this comment

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

Fantastic.

@nealkruis
Copy link
Member

@mitchute, I'm curious if you'd consider using btwxt for the interpolation? It is a generalized n-dimensional interpolation library that is already linked to EnergyPlus and used for tabular interpolation elsewhere in the code. How many dimensions are you interpolating here?

@mitchute
Copy link
Collaborator Author

This is just a simple 1D interpolation. We could use btwxt here - I don't have a strong preference either way. I had to roll my own for a separate project, and I had this to hand already so that's why I threw it in.

@nealkruis
Copy link
Member

That's fair. Btwxt might be overkill if it's always 1-D.

@Myoldmopar
Copy link
Member

I fully agree that btwxt would be fine here, but also that's for sure overkill here in this always-1-D case. For now let's forge ahead with this super minimal updated version.

@mitchute
Copy link
Collaborator Author

@Myoldmopar comments have been addressed and this is ready for review.

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.

All happy here now, thanks @mitchute

@Myoldmopar
Copy link
Member

The tiny diffs are acceptable, but I don't want to muddy other CI results this afternoon, so I'll hold off from merging this until later. But it's ready.

@Myoldmopar
Copy link
Member

This one's next, testing locally now.

@Myoldmopar
Copy link
Member

All happy with latest develop pulled in, merging now, thanks @mitchute

@Myoldmopar Myoldmopar merged commit f8cf094 into develop Jul 28, 2022
@Myoldmopar Myoldmopar deleted the ghe-interp branch July 28, 2022 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Refactoring Includes code changes that don't change the functionality of the program, just perform refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants