Fix overflow in Detailed PV Heat Transfer Method when using array dimensions#1331
Merged
Conversation
…ass. refactor mcsp_celltemp_t to use local copies of members it wants to change
…ssary derivatives). This should prevent errors of the class that led to this bug
Pull Request Test Coverage Report for Build 15399421857Details
💛 - Coveralls |
brtietz
approved these changes
Jun 4, 2025
brtietz
left a comment
Collaborator
There was a problem hiding this comment.
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
approved these changes
Jun 10, 2025
cpaulgilman
left a comment
Collaborator
There was a problem hiding this comment.
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.
mjprilliman
approved these changes
Jun 10, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
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:
Observe that now the cell temperature does not revert to the ambient temperature on January 16.
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