Skip to content

Conversation

@jmarrec
Copy link
Contributor

@jmarrec jmarrec commented Oct 6, 2025

Pull request overview

Description of the purpose of this PR

Pull Request Author

  • 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

  • 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

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));
```
@jmarrec jmarrec requested a review from mitchute October 6, 2025 07:57
@jmarrec jmarrec self-assigned this Oct 6, 2025
@jmarrec jmarrec added Defect Includes code to repair a defect in EnergyPlus DoNotPublish Includes changes that shouldn't be reported in the changelog NotIDDChange Code does not impact IDD (can be merged after IO freeze) Developer Issue Related to cmake, packaging, installers, or developer tooling (CI, etc) labels Oct 6, 2025
Comment on lines +318 to +402
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);
Copy link
Contributor Author

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*

Comment on lines +305 to +320
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;
Copy link
Contributor Author

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-

@mitchute
Copy link
Collaborator

mitchute commented Oct 6, 2025

Confirmed this fixes the issue.

@mitchute mitchute merged commit d5e5c63 into develop Oct 6, 2025
14 of 15 checks passed
@mitchute mitchute deleted the 11245_LEEDSummary_RenewableEnergySourceSummary branch October 6, 2025 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Defect Includes code to repair a defect in EnergyPlus Developer Issue Related to cmake, packaging, installers, or developer tooling (CI, etc) DoNotPublish Includes changes that shouldn't be reported in the changelog NotIDDChange Code does not impact IDD (can be merged after IO freeze)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LEEDSummary_RenewableEnergySourceSummary Unit Test Fails on Mac Debug

5 participants