Skip to content

Fix overflow in Detailed PV Heat Transfer Method when using array dimensions#1331

Merged
brtietz merged 5 commits into
patchfrom
fix_pv_heat_transfer_method
Jul 21, 2025
Merged

Fix overflow in Detailed PV Heat Transfer Method when using array dimensions#1331
brtietz merged 5 commits into
patchfrom
fix_pv_heat_transfer_method

Conversation

@berg-michael

Copy link
Copy Markdown
Collaborator

Description

This PR fixes an overflow that led to incorrect results when using the detailed PV Heat Transfer Method when using array dimensions.

The root cause of the error was that the Length and Width parameters of the mcsp_celltemp_t class were being scaled by Nrows, Ncols on each iteration. The intended behavior was to scale them a single time.

A secondary issue was that the result of the temperature model was not checked. The temperature model takes in a temperature variable by reference and modifies it upon return. In cases where the temperature model fails (including the overflow condition above), the function fails and returns false. Because this return is not checked, and because the temperature variable is initialized to ambient temp, the error state is not detected. This results in the behavior described in nrel/SAM #2081.

This PR should solve these issues.

  1. It removes all modifications of class variables, and instead modifies local copies. This removes the overflow.
  2. It adds additional error checking in cmod_pvsamv1.cpp.
  3. It adds additional error messages in the mcsp_celltemp_t operator() function.

One additional change I made is const-qualifying the pvcelltemp_t and pvmodule_t operator() methods, and cosnt-qualifying additional methods that are downstream of these operator() methods and therefore must be const as well. This required no changes in code besides those I already made in mcsp_celltemp_t to remove the overflow. Const-qualifying these methods should prevent errors of this class from arising in the future.

To test, follow @cpaulgilman's steps to reproduce the bug from the initial issue:

Steps to reproduce the behavior:

  1. Create a default Detailed PV / No Financial case.
  2. On the Module page, choose Heat transfer method for the temperature correction option.
  3. Choose Array Dimensions for the heat transfer dimensions option.
  4. Run a simulation.
  5. On the Data Tables tab of the Results page, display "Subarray 1 Cell temperature (C)" and "Weather file ambient temperature (C)". Note that starting the last daylight time step of January 16, the cell temperature and ambient temperature are the same.

Observe that now the cell temperature does not revert to the ambient temperature on January 16.

image

Fixes # (issue(s)): nrel/SAM #2081

Corresponding branches and PRs:

This PR is an SSC only PR. There are no specific branches of other repositories that this PR depends upon.

Unit Test Impact:

No tests were changed. If tests exist which assumed the correctness of the detailed PV heat transfer method and used array dimensions, the output of those tests may now change.

Checklist

  • requires help revision and I added that label
  • adds, removes, modifies, or deletes variables in existing compute modules
  • adds a new compute module
  • changes defaults
  • I've tagged this PR to a milestone

@coveralls

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 15399421857

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 213 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.005%) to 54.731%

Files with Coverage Reduction New Missed Lines %
ssc/shared/lib_cec6par.cpp 94 61.01%
ssc/ssc/cmod_pvsamv1.cpp 119 87.05%
Totals Coverage Status
Change from base Build 15320299111: -0.005%
Covered Lines: 64390
Relevant Lines: 117648

💛 - Coveralls

@brtietz brtietz added this to the SAM 2025 release patch 1 milestone Jun 4, 2025
@brtietz brtietz added the pv photovoltaic, pvsam, pvwatts label Jun 4, 2025
@brtietz brtietz requested a review from mjprilliman June 4, 2025 15:45

@brtietz brtietz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good from my perspective, thanks for cleaning up all of the 'const' definitions!

I think @mjprilliman should potentially take a look at this as he's more familiar with these models.

@cpaulgilman cpaulgilman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This looks good to me. The cell temperature values look more reasonable, i.e., not equal to ambient temperature. And, comparing results for "module dimensions" to "array dimensions," the latter temperatures are slightly higher, which is what I expect intuitively.

I agree it would be good for @mjprilliman to take a look.

@brtietz brtietz merged commit dc57f6f into patch Jul 21, 2025
10 checks passed
@brtietz brtietz deleted the fix_pv_heat_transfer_method branch July 21, 2025 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

added to release notes pv photovoltaic, pvsam, pvwatts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants