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

Handle incomplete EPW design conditions header #5134

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

joseph-robertson
Copy link
Collaborator

@joseph-robertson joseph-robertson commented Apr 1, 2024

Pull request overview

  • Fixes EPWDesignCondition getters should return boost::optional #5132.
  • EpwDesignCondition has many API-breaking changes related to its getters. The previous behavior was to misleadingly return a value of 0 for any empty design condition header field. The types for the getters are now either boost::optional<double> or boost::optional<int>.

Notes:

  • Does stringToDouble return 0.0 if an empty string is passed in? Yes.
  • Should the following changes be made to EpwFile.hpp / EpwFile.cpp:
    • check for empty strings in setters; e.g., check heatingDryBulb99 is empty string in setHeatingDryBulb99? Yes.
    • change all getters to return boost::optional<double>; e..g, double EpwDesignCondition::heatingDryBulb99() const { to boost::optional<double> EpwDesignCondition::heatingDryBulb99() const {? Yes.
    • change, e.g., double m_heatingDryBulb99 to boost::optional<double> m_heatingDryBulb99 in EpwDesignCondition class? Yes.

Pull Request Author

  • Model API Changes / Additions
  • Any new or modified fields have been implemented in the EnergyPlus ForwardTranslator (and ReverseTranslator as appropriate)
  • Model API methods are tested (in src/model/test)
  • EnergyPlus ForwardTranslator Tests (in src/energyplus/Test)
  • If a new object or method, added a test in NREL/OpenStudio-resources: Add Link
  • If needed, added VersionTranslation rules for the objects (src/osversion/VersionTranslator.cpp)
  • Verified that C# bindings built fine on Windows, partial classes used as needed, etc.
  • All new and existing tests passes
  • If methods have been deprecated, update rest of code to use the new methods

Labels:

  • If change to an IDD file, add the label IDDChange
  • If breaking existing API, add the label APIChange
  • If deemed ready, add label Pull Request - Ready for CI so that CI builds your PR

Review Checklist

This will not be exhaustively relevant to every PR.

  • Perform a Code Review on GitHub
  • Code Style, strip trailing whitespace, etc.
  • All related changes have been implemented: model changes, model tests, FT changes, FT tests, VersionTranslation, OS App
  • Labeling is ok
  • 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

@joseph-robertson joseph-robertson added component - Utilities Other Pull Request - Ready for CI This pull request if finalized and is ready for continuous integration verification prior to merge. labels Apr 1, 2024
@joseph-robertson joseph-robertson self-assigned this Apr 1, 2024
@joseph-robertson joseph-robertson added severity - Normal Bug APIChange A motivated non-backward compatible change that breaks the existing API and needs to be communicated labels Jul 26, 2024
@joseph-robertson joseph-robertson marked this pull request as ready for review July 26, 2024 22:29
@jmarrec jmarrec force-pushed the epw-incomplete-design branch from be61615 to 82ac99f Compare October 30, 2024 09:30
@jmarrec
Copy link
Collaborator

jmarrec commented Oct 30, 2024

Rebased onto develop and resolved conflicts.

Copy link
Collaborator

@jmarrec jmarrec left a comment

Choose a reason for hiding this comment

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

Made a couple of minor changes

Copy link
Collaborator

Choose a reason for hiding this comment

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

Breaking the "Design Condition" line on the comma and diffing USA_CO_Golden-NREL.724666_TMY3.epw USA_CO_Golden-NREL.724666_TMY3_IncompleteDesign.epw

image

std::vector<EpwDesignCondition> designs = epwFile.designConditions();
EXPECT_EQ(1, designs.size());
EXPECT_EQ("Climate Design Data 2013 ASHRAE Handbook", designs[0].titleOfDesignCondition());
ASSERT_FALSE(designs[0].heatingColdestMonth());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpick: ASSERT_TRUE on an optional before dereferencing it makes sense. Here you could just do EXPECT_FALSE.

@@ -492,6 +494,109 @@ TEST(Filetypes, EpwFile_NoDesign) {
}
}

TEST(Filetypes, EpwFile_IncompleteDesign) {
try {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why use a try...? (I know, the other tests have it... but makes no sense)

Comment on lines 2683 to 2684
boost::optional<int> EpwDesignCondition::heatingColdestMonth() const {
return boost::optional<int>(m_heatingColdestMonth);
Copy link
Collaborator

Choose a reason for hiding this comment

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

why wrapping it? heatingColdestMonth is already a boost::optional, so just return that.

Comment on lines 2957 to 2964
bool ok;
double value = stringToDouble(heatingDryBulb99, &ok);
setHeatingDryBulb99(value);
if (!ok) {
m_heatingDryBulb99 = boost::none;
} else {
setHeatingDryBulb99(value);
}
return ok;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not in the scope of this PR, but I dislike this. stringToDouble should be boost::optional<double> stringToDouble(const std::string& str).

Also a lot of fields in EpwDataPoint internally store a std::string representation of a number, use magic string numbers for unknown values (constants would be better, whether that's a string or an actual number), which I also don't like.

boost::optional<double> EpwDataPoint::dryBulbTemperature() const {
if (m_dryBulbTemperature == "99.9") {
return boost::none;
}
return boost::optional<double>(std::stod(m_dryBulbTemperature));
}
bool EpwDataPoint::setDryBulbTemperature(double value) {
if (-70 >= value || 70 <= value) {
LOG_FREE(Warn, "openstudio.EpwFile", "DryBulbTemperature value '" << value << "' not within the expected limits");
}
m_dryBulbTemperature = std::to_string(value);
return true;
}
bool EpwDataPoint::setDryBulbTemperature(const std::string& dryBulbTemperature) {
bool ok;
double value = stringToDouble(dryBulbTemperature, &ok);
if (!ok) {
m_dryBulbTemperature = "99.9";
return false;
} else if (-70 >= value || 70 <= value) {
LOG_FREE(Warn, "openstudio.EpwFile", "DryBulbTemperature value '" << value << "' not within the expected limits");
}
m_dryBulbTemperature = dryBulbTemperature;
return true;
}

But this isn't something we need to address now.

@jmarrec
Copy link
Collaborator

jmarrec commented Oct 30, 2024

I didn't find occurrences of this being used anywhere in the common openstudio-gems I have on my machine right now.

The only one I can find is ResStock's weather.rb, but I'm sure @joseph-robertson is well aware he'll need to change that so I'm fine with the API Break. @kbenne, grand protector of the API, could you chime in for confirmation?

https://github.com/NREL/resstock/blob/280a58c2686f30a1b09f10ba3640e49c265d06f3/resources/hpxml-measures/HPXMLtoOpenStudio/resources/weather.rb#L261-L276)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
APIChange A motivated non-backward compatible change that breaks the existing API and needs to be communicated component - Utilities Other Pull Request - Ready for CI This pull request if finalized and is ready for continuous integration verification prior to merge. severity - Normal Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EPWDesignCondition getters should return boost::optional
3 participants