Skip to content

Commit

Permalink
fix adjustment factor use for pvwatts (#1113)
Browse files Browse the repository at this point in the history
* fix adjustment factor use for pvwatts

* add failing NonAnnualSummerStart test

* change so test is passing

* update test values for NonAnnualSummerStart
  • Loading branch information
dguittet committed Mar 28, 2024
1 parent 990f351 commit 848d831
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 25 deletions.
6 changes: 3 additions & 3 deletions ssc/cmod_pvwattsv7.cpp
Expand Up @@ -1261,7 +1261,7 @@ class cm_pvwattsv7 : public compute_module
p_tpoa[idx] = (ssc_number_t)tpoa; // W/m2
p_tmod[idx] = (ssc_number_t)tmod;
p_dc[idx] = (ssc_number_t)dc; // power, Watts
p_ac[idx] = (ssc_number_t)(ac * haf(hour_of_year)); // power, Watts
p_ac[idx] = (ssc_number_t)(ac * haf(wdprov->annualSimulation() ? hour_of_year : idx)); // power, Watts

// accumulate hourly energy (kWh) (was initialized to zero when allocated)
p_gen[idx_life] = (ssc_number_t)(p_ac[idx]* util::watt_to_kilowatt);
Expand All @@ -1270,8 +1270,8 @@ class cm_pvwattsv7 : public compute_module
annual_kwh += p_gen[idx] / step_per_hour;
}

if (y == 0 && wdprov->annualSimulation()) ld("ac_loss_adjustments") += ac * (1.0 - haf(hour_of_year)) * ts_hour; //ts_hour required to correctly convert to Wh for subhourly data
if (y == 0 && wdprov->annualSimulation()) ld("ac_delivered") += ac * haf(hour_of_year) * ts_hour; //ts_hour required to correctly convert to Wh for subhourly data
if (y == 0 && wdprov->annualSimulation()) ld("ac_loss_adjustments") += ac * (1.0 - haf(wdprov->annualSimulation() ? hour_of_year : idx)) * ts_hour; //ts_hour required to correctly convert to Wh for subhourly data
if (y == 0 && wdprov->annualSimulation()) ld("ac_delivered") += ac * haf(wdprov->annualSimulation() ? hour_of_year : idx) * ts_hour; //ts_hour required to correctly convert to Wh for subhourly data

idx_life++;
}
Expand Down
6 changes: 3 additions & 3 deletions ssc/cmod_pvwattsv8.cpp
Expand Up @@ -1359,7 +1359,7 @@ class cm_pvwattsv8 : public compute_module
p_tmod[idx] = (ssc_number_t)tmod;
p_dc[idx] = (ssc_number_t)dc; // power, Watts
p_ac_pre_adjust[idx] = (ssc_number_t)ac; //power, Watts
p_ac[idx] = (ssc_number_t)(ac * haf(hour_of_year)); // power, Watts
p_ac[idx] = (ssc_number_t)(ac * haf(wdprov->annualSimulation() ? hour_of_year : idx)); // power, Watts

// accumulate hourly energy (kWh) (was initialized to zero when allocated)
p_gen[idx_life] = (ssc_number_t)(p_ac[idx] * util::watt_to_kilowatt);
Expand All @@ -1369,8 +1369,8 @@ class cm_pvwattsv8 : public compute_module
annual_kwh += p_gen[idx] / step_per_hour;
}

if (y == 0 && wdprov->annualSimulation()) ld("ac_loss_adjustments") += ac * (1.0 - haf(hour_of_year)) * ts_hour; //ts_hour required to correctly convert to Wh for subhourly data
if (y == 0 && wdprov->annualSimulation()) ld("ac_delivered") += ac * haf(hour_of_year) * ts_hour; //ts_hour required to correctly convert to Wh for subhourly data
if (y == 0 && wdprov->annualSimulation()) ld("ac_loss_adjustments") += ac * (1.0 - haf(wdprov->annualSimulation() ? hour_of_year : idx)) * ts_hour; //ts_hour required to correctly convert to Wh for subhourly data
if (y == 0 && wdprov->annualSimulation()) ld("ac_delivered") += ac * haf(wdprov->annualSimulation() ? hour_of_year : idx) * ts_hour; //ts_hour required to correctly convert to Wh for subhourly data

idx_life++;
}
Expand Down
36 changes: 18 additions & 18 deletions test/input_cases/weather_inputs.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/input_cases/weather_inputs.h
Expand Up @@ -40,7 +40,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* Creates resources as var_data, as opposed to resources from files, for testing use through SDK
*/

var_table* create_weatherdata_array(size_t length);
var_table* create_weatherdata_array(size_t length, size_t start_idx=0);

void free_weatherdata_array(var_table* data);

Expand Down
25 changes: 25 additions & 0 deletions test/ssc_test/cmod_pvwattsv8_test.cpp
Expand Up @@ -503,6 +503,31 @@ TEST_F(CMPvwattsv8Integration_cmod_pvwattsv8, NonAnnual)
free_weatherdata_array(weather_data);
}

TEST_F(CMPvwattsv8Integration_cmod_pvwattsv8, NonAnnualSummerStart)
{
//set up a weather data array and unassign the solar resource file

auto weather_data = create_weatherdata_array(24, 24 * 180);

ssc_data_unassign(data, "solar_resource_file");
ssc_data_set_table(data, "solar_resource_data", weather_data);

//run the tests
EXPECT_FALSE(run_module(data, "pvwattsv8"));

ssc_number_t dc, gen, ac;
dc = ssc_data_get_array(data, "dc", nullptr)[12];
EXPECT_NEAR(dc, 769.13, 1.) << "DC Energy at noon";

ac = ssc_data_get_array(data, "ac", nullptr)[12];
EXPECT_NEAR(ac, 726.023, 1.) << "AC Energy at noon";

gen = ssc_data_get_array(data, "gen", nullptr)[12];
EXPECT_NEAR(gen, 0.726, 0.01) << "Gen at noon";

free_weatherdata_array(weather_data);
}


TEST_F(CMPvwattsv8Integration_cmod_pvwattsv8, IntermediateOutputTesting)
{
Expand Down

0 comments on commit 848d831

Please sign in to comment.