Skip to content

PV models speed up#1212

Merged
dguittet merged 26 commits into
developfrom
pvwatts_speed
Oct 14, 2024
Merged

PV models speed up#1212
dguittet merged 26 commits into
developfrom
pvwatts_speed

Conversation

@dguittet

@dguittet dguittet commented Sep 30, 2024

Copy link
Copy Markdown
Collaborator

Speed up pvsamv1, pvwattsv7 and pvwattsv8 by speeding up irradproc and sssky_diffuse_table.

irradproc:

  • for intra-annual solarpos_spa calculation speed up, introduce a hash table that tracks the intermediate outputs of calculate_spa that reduces the number of times that calculate_spa is called per timestep
  • for lifetime calculation, inter-annual speed up is done by storing the results of solarpos_spa in a vector so that the values are not recalculated each year

sssky_diffuse_table:

  • change the keys of the hash table to numeric key instead of string since sprintf takes a long time
  • reduce the number of steps/samples required to compute the self-shading loss in sssky_diffuse_table::compute

pvwattsv8 and pvwattsv7:

  • move irrad proc outside the time loop

pvsamv1:

  • move irrad proc outside the time loop
  • change the constructor used for irradproc

tests:

  • pvsamv1 test values are changed (shows how the actual value changed)
  • pvwattsv8 test tolerances are changed (shows how much the relative error increased in order to use the old expected values). A potential additional change in this PR is to change the expected values to the new values

Speed changes

Before is the original code, "Spa Hash" is what is implemented in this PR

image

image

@mjprilliman mjprilliman 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 great! I want to double check seasonal tilt behavior, so I may need to do a bit more debugging.

Comment thread shared/lib_irradproc.cpp
Comment thread test/ssc_test/cmod_pvsamv1_test.cpp
Comment thread shared/lib_irradproc.cpp

@mjprilliman mjprilliman 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 to me. Just one merge conflict from recent merges to address

@janinefreeman

Copy link
Copy Markdown
Collaborator

This looks good to me! I think it makes sense to update the pvwattsv8 expected test values to the new values as well. I like scaling the error tolerance by annual energy, but I think I'd like to make the error tolerance itself smaller if we're keeping that approach.

Requesting an additional review from @sjanzou , particularly on the hash table, just because this is a big change for pvwatts and pvsam.

Super excited for these results @dguittet !!! Nice job!!!

@janinefreeman janinefreeman requested a review from sjanzou October 2, 2024 16:45
@dguittet

dguittet commented Oct 2, 2024

Copy link
Copy Markdown
Collaborator Author

Need tests for Alaska and South Africa

@sjanzou sjanzou 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 overall, just a few comments and questions on some of the implementation values and sensitivities.

Thanks for tackling this!

Comment thread test/ssc_test/cmod_pvwattsv5_test.cpp
Comment thread shared/lib_irradproc.cpp
ascension_and_declination[0], ascension_and_declination[1]};

if (use_table)
spa_table[spa_key_inputs] = spa_outputs;

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.

Have you run with use_table = false to verify previous results?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes. I'm planning to remove this code once we're done examining sensitivities-- thoughts on deleting this?

Comment thread shared/lib_irradproc.cpp Outdated
Comment thread shared/lib_irradproc.h
spa_table_key(double j, double dt, double p, double t, double a, double d):
jd(j), delta_t(dt), ascension(a), declination(d)
{
int pressure_bucket = 10;

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.

Do you have a sensitivity plot based on pressure and temp bucket size?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Sure, the sensitivity is super low to pressure and temperature:

pressure bucket temp bucket time (ms) result change
10 5 3250 na
2 5 3443 na
2 2 3490 na
10 2 3411 na
1 1 3630 na
20 10 3238 na

Comment thread shared/lib_irradproc.h
Comment thread shared/lib_pvshade.cpp
Comment thread shared/lib_pvshade.cpp
@dguittet

Copy link
Copy Markdown
Collaborator Author

Need tests for Alaska and South Africa

@janinefreeman

Ran Pvwattsv8 tests for Alaska and tip of South America and the changes in this PR (both self shading and solarpos), and checked changes in annual energy and monthly energy.

The max change over those 26 values was < 0.02%.

@sjanzou sjanzou 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.

Thanks for tackling this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants