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

Add the cubic spline interpolation option for PerformancePrecisionTradeoffs #8946

Merged
merged 28 commits into from
Aug 19, 2021

Conversation

LipingWang
Copy link
Contributor

@LipingWang LipingWang commented Aug 4, 2021

Pull request overview

A new override option was added as Mode06 for the field Override Mode of the PerformancePrecisionTradeoffs object. Mode06 offers an alternative method to calculate saturated temperature given pressure in replacement of the psychrometric function PsyTsatFnPb. The previous options for the Override Mode of the object including Mode06 and Mode07 in version 9.5 were switched to Mode07 and Mode08 in version 9.6, respectively.

Code Changes

  • Added the new override option (Mode06) for the field Override Mode of the PerformancePrecisionTradeoffs object in SimulationManager.cc;
  • Modified and updated the existing override modes of this object in SimulationManager.cc;
  • Added a function of cubic spline interpolation (CSplineint) to Psychrometrics.cc;
  • Modified the existing psychrometric function PsyTsatFnPb with the option to use cubic spline interpolation for calculating saturated temperature;
  • IDD: added the new option as described in Energy+.idd;
  • Version update: added transition rules and descriptions to CreatNewIDFUsingRulesV9_6_0.f90 and Rules9-5-0-to9-6-0.md;
  • Reference: added two additional runs including the new override option and updated the testing results and InputOutputReference;
  • Unit tests: added two unit tests for the verification of interpolation sample data and result comparison between cubic spline interpolation and the original psychrometric function PsychTsatFnPb.

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

@@ -129,7 +129,405 @@ namespace Psychrometrics {
// 14 - HR | 15 - max iter | 16 - HR | 17 - max iter | 18 -
// PsyTwbFnTdbWPb_raw (raw calc) | 19 - PsyPsatFnTemp_raw
// (raw calc)

// sample bin size =64 Pa; sample size =1651 (continous)
constexpr std::array<Real64, 1651> tsat_fn_pb_x = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this array is necessary since the contents are just index * 64, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point, the array is just 64x an integer so we can probably either populate it with a for loop or eliminate it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

There is no point in populating it with a loop. If you are going to do that, you may as well leave it as is. Just replace the lookup with a multiplication.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@amirroth @JasonGlazer Thanks a lot for your comments! I will update the code to eliminate the pressure input array and replace it with a multiplication.

@@ -100,7 +100,7 @@ constexpr Int64 psatcache_mask = psatcache_size - 1;
#endif
#ifdef EP_cache_PsyTsatFnPb
constexpr int tsatcache_size = 1024 * 1024;
constexpr int tsatprecision_bits = 24;
constexpr int tsatprecision_bits = 20;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think if convTol is set to 0.01C, this can go down to 16.

Copy link
Contributor

Choose a reason for hiding this comment

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

I asked @LipingWang to look at this earlier and we found that while it increases speed slightly to go from 20 to 16, it also increases the differences in energy, so we decided to stick with 20. This was on a small set of buildings and we can evaluate that with a larger set of buildings to get a more accurate picture if you want.

@JasonGlazer JasonGlazer marked this pull request as draft August 4, 2021 14:24
@JasonGlazer JasonGlazer added the NewFeature Includes code to add a new feature to EnergyPlus label Aug 4, 2021
@JasonGlazer JasonGlazer added this to the EnergyPlus 9.6 IOFreeze milestone Aug 4, 2021
@Myoldmopar
Copy link
Member

Is this actually planned for 9.6 IO Freeze or is it just a sandbox to evaluate the approach?

@JasonGlazer
Copy link
Contributor

It is for the 9.6.0 IO freeze.

@mjwitte mjwitte added the IDDChange Code changes impact the IDD file (cannot be merged after IO freeze) label Aug 17, 2021
@LipingWang LipingWang changed the title Test the new option for the PerformancePrecisionTradeoffs object Add a new option using cubic spline interpolations for the PerformancePrecisionTradeoffs object Aug 17, 2021
@LipingWang LipingWang changed the title Add a new option using cubic spline interpolations for the PerformancePrecisionTradeoffs object Add a new option using cubic spline interpolations for PerformancePrecisionTradeoffs Aug 17, 2021
@LipingWang LipingWang changed the title Add a new option using cubic spline interpolations for PerformancePrecisionTradeoffs Add the cubic spline interpolation option for PerformancePrecisionTradeoffs Aug 17, 2021
@JasonGlazer JasonGlazer marked this pull request as ready for review August 18, 2021 14:26
@JasonGlazer
Copy link
Contributor

I think this is ready for review and merge so I'm taking it out of draft state. At this point, only the MacOS CI tests have run but I expect that it just that the CI machines are backed up with jobs. I am putting myself down as a reviewer.

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.

This looks generally fine. I will tweak the fortran file to fix the indentation, but otherwise the implementation is fine. The unit test seems ... odd. I'm not going to hold the PR for a different unit test at this point, but I would like a comment about it and most likely a modification to the unit test soon so we don't have a huge array just duplicated out in the unit test that becomes a maintenance problem if something changes.

16 & FALSE & CarrollMRT & MODE05 & 1 & 1 & TRUE & 60 & Normal & 0.30 & 0.002 & 47.31 \tabularnewline
17 & FALSE & CarrollMRT & MODE06 & 1 & 1 & TRUE & 60 & Interpolate & 0.30 & 0.002 & 45.62 \tabularnewline
18 & FALSE & CarrollMRT & MODE07 & 1 & 1 & TRUE & 60 & Interpolate & 1.00 & 0.002 & 45.23 \tabularnewline
19 & FALSE & CarrollMRT & MODE08 & 1 & 1 & TRUE & 60 & Interpolate & 1.00 & 0.1 & 44.09 \tabularnewline
Copy link
Member

Choose a reason for hiding this comment

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

👍

Advanced& Allow direct input of convergence field values\tabularnewline

\bottomrule
\end{longtable}

The increasing mode number roughly corresponds with increased speed. Mode01 to Mode05 are overriding inputs in other parts of the IDF/epJSON file and is equivalent to changing those input directly. Mode06 and Mode07 are changing convergence parameters previously not available to be modified by the user.
The increasing mode number roughly corresponds with increased speed. Mode01 to Mode05 are overriding inputs in other parts of the IDF/epJSON file and is equivalent to changing those input directly. Mode06 offers an alternative method to calculate saturated temperature given pressure in replacement of the psychrometric function PsyTsatFnPb. Mode07 and Mode08 are changing convergence parameters previously not available to be modified by the user.
Copy link
Member

Choose a reason for hiding this comment

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

👍

@@ -483,6 +483,7 @@ PerformancePrecisionTradeoffs,
\key Mode05
\key Mode06
\key Mode07
\key Mode08
Copy link
Member

Choose a reason for hiding this comment

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

OK, so Mode06 was inserted, making a new 08 one. Transition rules to follow I see. 👍

-1.9E-09, -2.8E-09, -2E-10, -0.000000004, -2.5E-09, -1E-10, -4.6E-09, -3E-10, -2.5E-09, -3.8E-09,
-3E-10, -2.6E-09, -2.3E-09, -2.1E-09, -2.2E-09, -2.1E-09, -2.4E-09, -2.1E-09, -2.2E-09, -0.000000002,
-2.4E-09, -9E-10, -3.3E-09, -2.2E-09, -4E-10, -4.1E-09, -1.4E-09, -2.9E-09, 4E-10, -5.5E-09,
2.7E-09}; // namespace Psychrometrics
Copy link
Member

Choose a reason for hiding this comment

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

OK

@@ -426,7 +426,16 @@ SUBROUTINE CreateNewIDFUsingRules(EndOfFile,DiffOnly,InLfn,AskForInput,InputFile
! If your original object starts with R, insert the rules here

! If your original object starts with S, insert the rules here

CASE('PERFORMANCEPRECISIONTRADEOFFS')
Copy link
Member

Choose a reason for hiding this comment

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

Mixed tab/space here causing weird indent, I'll fix it since I need to resolve a tiny conflict anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Myoldmopar thank you!

Summary: A new override option including cubic spline interpolations in replacement of original psychrometric function PsyTsatFnPb was added as Mode06 in this object. The previous options for the override mode of the object including Mode06 and Mode07 in version 9.5 were switched to Mode07 and Mode08 in version 9.6, respectively.

Fields 1-2 remains the same.
Fields 3 has been updated by adding a new override mode option.
Copy link
Member

Choose a reason for hiding this comment

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

Could be described a bit better in this line, but I guess the paragraph above basically says it.

100.6190344, 100.636391, 100.6537386, 100.6710809, 100.6884104, 100.7057304, 100.7230452, 100.7403472, 100.7576436, 100.7749305,
100.7922053, 100.809475, 100.8267359, 100.8439874, 100.8612302, 100.8784641, 100.8956893, 100.9129053, 100.9301125, 100.947311,
100.9645009, 100.9816821, 100.9988569, 101.0160203, 101.0331752, 101.0503248, 101.067462, 101.0845908, 101.101711, 101.1188265,
101.1359293};
Copy link
Member

Choose a reason for hiding this comment

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

Is this just the same array as inside the code? I'm not sure I understand what this unit test is doing then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Myoldmopar I should have added more details for this unit test. Yes, this sample array tsat_fn_pb_tsat is the same sample array for saturated temperature as inside the code tsat_fn_pb_y. The purpose of this unit test is to test the correctness of the sample data array. The sample data were extracted from the original psychrometric function PsyTsatFnPb every 64 Pa in the range of 64 Pa to 105,664 Pa. The sample data for saturated temperature from tsat_fn_pb_tsat was compared to the results from the original psychrometric function PsyTsatFnPb. So we can double-check the correctness of the sample data inside the code.

Copy link
Contributor

Choose a reason for hiding this comment

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

@LipingWang the idea of the unit test is good but instead of repeating the array, we should be testing the array that is created in the header file and used by the interpolation function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@JasonGlazer @Myoldmopar sounds great!

@Myoldmopar
Copy link
Member

Tested out the branch, everything built and tested just fine. Played with the transition rules and it transitions objects as expected, whether they don't have that field at all, have a field value that should stay the same, or have a field value that should be converted. This seems good to go in, but would like to follow-up with at least commentary about the unit test later. Thanks @LipingWang and thanks @JasonGlazer for the review.

@Myoldmopar Myoldmopar merged commit d763b10 into NREL:develop Aug 19, 2021
@@ -1439,6 +1444,26 @@ namespace Psychrometrics {

return Temp;
}
Real64 CSplineint(int const n, // sample data size
const Real64 &x) // given value of x
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is no reason to pass scalars by const &. If this is only an input, it should be passed by value. The only parameters that should be passed by reference are output parameters (passing by reference is the only) and objects (passing by value will trigger the copy constructor which 99% of the time you don't want to do).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@amirroth Many thanks for your comments and the details! I will drop the const &.

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants