-
Notifications
You must be signed in to change notification settings - Fork 457
Fix #11245 LEEDSummary_RenewableEnergySourceSummary Unit Test Fails on Mac Debug #11253
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
Fix #11245 LEEDSummary_RenewableEnergySourceSummary Unit Test Fails on Mac Debug #11253
Conversation
When DEBUG_ARITHM_GCC_OR_CLANG is on, on arm64 mac: ``` [ RUN ] EnergyPlusFixture.PVWatts_SSC_NaNFailure Illegal instruction: 4 ./Products/energyplus_tests -- --gtest_filter=*PVWatts_SSC_NaNFailure* ``` When DEBUG_ARITHM_GCC_OR_CLANG is not on, on arm64 mac it passes
on arm64 mac: atan works with a quiet_NaN tan throws a FE_INVALID floating point exception in https://developer.arm.com/documentation/dui0801/g/A64-Floating-point-Instructions/FCVTNS--scalar- ``` double nan = std::numeric_limits<double>::quiet_NaN(); double atan_nan = std::atan(nan); EXPECT_TRUE(std::isnan(atan_nan)); double tan_nan = std::tan(nan); EXPECT_TRUE(std::isnan(tan_nan)); ```
| TEST_F(EnergyPlusFixture, PVWatts_SSC_NaNFailure) | ||
| { | ||
| const std::string idfTxt = delimited_string({ | ||
|
|
||
| "Shading:Site:Detailed,", | ||
| " FlatSurfaceShadetoEast, !- Name", | ||
| " , !- Transmittance Schedule Name", | ||
| " 4, !- Number of Vertices", | ||
| " 0.0,25.0,12.0, !- X,Y,Z ==> Vertex 1 {m}", | ||
| " 0.0,20.00,12.0, !- X,Y,Z ==> Vertex 2 {m}", | ||
| " 5.0,20.00,12.0, !- X,Y,Z ==> Vertex 3 {m}", | ||
| " 5.0,25.0,12.0; !- X,Y,Z ==> Vertex 4 {m}", | ||
|
|
||
| "Generator:PVWatts,", | ||
| " PVWatts3, !- Name", | ||
| " 5, !- PVWatts Version", | ||
| " 3000, !- DC System Capacity {W}", | ||
| " Premium, !- Module Type", | ||
| " FixedOpenRack, !- Array Type", | ||
| " 0.14, !- System Losses", | ||
| " Surface, !- Array Geometry Type", | ||
| " , !- Tilt Angle {deg}", | ||
| " , !- Azimuth Angle {deg}", | ||
| " FlatSurfaceShadetoEast; !- Surface Name", | ||
| }); | ||
|
|
||
| const std::string name = "PVArray"; | ||
| constexpr Real64 dcSystemCapacity = 4000.0; | ||
| constexpr auto moduleType = PVWatts::ModuleType::STANDARD; | ||
| constexpr auto arrayType = PVWatts::ArrayType::FIXED_ROOF_MOUNTED; | ||
| constexpr Real64 systemLosses = 0.14; | ||
| constexpr auto geometryType = PVWatts::GeometryType::TILT_AZIMUTH; | ||
| constexpr Real64 tilt = 0.0; | ||
| constexpr Real64 azimuth = 180.0; | ||
| constexpr size_t surfaceNum = 0; | ||
| constexpr Real64 groundCoverageRatio = 0.4; | ||
|
|
||
| // USA_AZ_Phoenix-Sky.Harbor.Intl.AP.722780_TMY3.epw | ||
| // 6/15 at 7am | ||
| state->dataGlobal->TimeStep = 1; | ||
| state->dataGlobal->TimeStepZone = 1.0; | ||
| state->dataHVACGlobal->TimeStepSys = 1.0; | ||
| state->dataHVACGlobal->TimeStepSysSec = state->dataHVACGlobal->TimeStepSys * Constant::rSecsInHour; | ||
| state->dataGlobal->BeginTimeStepFlag = true; | ||
| state->dataGlobal->MinutesInTimeStep = 60; | ||
| state->dataGlobal->TimeStepsInHour = 1; | ||
| Weather::AllocateWeatherData(*state); // gets us the albedo array initialized | ||
| state->dataEnvrn->Year = 1986; | ||
| state->dataEnvrn->Month = 6; | ||
| state->dataEnvrn->DayOfMonth = 15; | ||
| state->dataGlobal->HourOfDay = 8; // 8th hour of day, 7-8am | ||
| state->dataWeather->WeatherFileLatitude = 33.45; | ||
| state->dataWeather->WeatherFileLongitude = -111.98; | ||
| state->dataWeather->WeatherFileTimeZone = -7; | ||
| state->dataEnvrn->BeamSolarRad = 728; | ||
| state->dataEnvrn->DifSolarRad = 70; | ||
| state->dataEnvrn->WindSpeed = 3.1; | ||
| state->dataEnvrn->OutDryBulbTemp = 31.7; | ||
|
|
||
| // The TimeStepZone etc must be setp before calling the PVWattsGenerator constructor because it sets them on the ssc_data_t struct | ||
| PVWatts::PVWattsGenerator pvw( | ||
| *state, name, dcSystemCapacity, moduleType, arrayType, systemLosses, geometryType, tilt, azimuth, surfaceNum, groundCoverageRatio); | ||
| EXPECT_DOUBLE_EQ(dcSystemCapacity, pvw.getDCSystemCapacity()); | ||
| EXPECT_ENUM_EQ(moduleType, pvw.getModuleType()); | ||
| EXPECT_ENUM_EQ(arrayType, pvw.getArrayType()); | ||
| EXPECT_DOUBLE_EQ(systemLosses, pvw.getSystemLosses()); | ||
| EXPECT_ENUM_EQ(geometryType, pvw.getGeometryType()); | ||
| EXPECT_DOUBLE_EQ(tilt, pvw.getTilt()); | ||
| EXPECT_DOUBLE_EQ(azimuth, pvw.getAzimuth()); | ||
| EXPECT_DOUBLE_EQ(groundCoverageRatio, pvw.getGroundCoverageRatio()); | ||
|
|
||
| pvw.setCellTemperature(30.345); | ||
| pvw.setPlaneOfArrayIrradiance(92.257); | ||
| pvw.calc(*state); | ||
|
|
||
| Real64 generatorPower, generatorEnergy, thermalPower, thermalEnergy; | ||
| pvw.getResults(generatorPower, generatorEnergy, thermalPower, thermalEnergy); | ||
| EXPECT_FALSE(std::isnan(generatorPower)); | ||
| EXPECT_FALSE(std::isnan(generatorEnergy)); | ||
| EXPECT_FALSE(std::isnan(thermalPower)); | ||
| EXPECT_FALSE(std::isnan(thermalEnergy)); | ||
| EXPECT_DOUBLE_EQ(thermalPower, 0.0); | ||
| EXPECT_DOUBLE_EQ(thermalEnergy, 0.0); | ||
| EXPECT_NEAR(generatorPower, 1117.75, 0.5); | ||
| EXPECT_NEAR(generatorEnergy, generatorPower * 60 * 60, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#11244 - Add a PVWatts tests with tilt = 0 which triggers the nan thing
When DEBUG_ARITHM_GCC_OR_CLANG is on, on arm64 mac:
[ RUN ] EnergyPlusFixture.PVWatts_SSC_NaNFailure
Illegal instruction: 4 ./Products/energyplus_tests -- --gtest_filter=*PVWatts_SSC_NaNFailure*
| if (surface_tilt != 0) { | ||
| arg[n] = (1 / tand_stilt) - (1 / (gcr * sind_stilt * (1 - n * step))); | ||
| else | ||
| gamma[n] = (-M_PI / 2) + atan(arg[n]); | ||
| tan_tilt_gamma[n] = tan(surface_tilt * DTOR + gamma[n]); | ||
| Asky_shade[n] = M_PI + M_PI / pow((1 + tan_tilt_gamma[n] * tan_tilt_gamma[n]), 0.5); | ||
| if ((surface_tilt * DTOR + gamma[n]) > (M_PI / 2)) | ||
| { | ||
| Asky_shade[n] = 2 * M_PI - Asky_shade[n]; | ||
| } | ||
| skydiff += (Asky_shade[n] / Asky) * step; | ||
| } else { | ||
| arg[n] = std::numeric_limits<double>::quiet_NaN(); | ||
| gamma[n] = (-M_PI / 2) + atan(arg[n]); | ||
| tan_tilt_gamma[n] = tan(surface_tilt * DTOR + gamma[n]); | ||
| Asky_shade[n] = M_PI + M_PI / pow((1 + tan_tilt_gamma[n] * tan_tilt_gamma[n]), 0.5); | ||
| if (isnan(Asky_shade[n])) | ||
| { | ||
| gamma[n] = std::numeric_limits<double>::quiet_NaN(); | ||
| tan_tilt_gamma[n] = std::numeric_limits<double>::quiet_NaN(); | ||
| Asky_shade[n] = Asky; | ||
| skydiff += step; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid doing NaN computations.
The atan passes, but the tan one traps an FE_INVALID in this instruction: https://developer.arm.com/documentation/dui0801/g/A64-Floating-point-Instructions/FCVTNS--scalar-
|
Confirmed this fixes the issue. |
Pull request overview
Description of the purpose of this PR
Pull Request Author
Reviewer