Skip to content

Commit

Permalink
updated logic in adjust variable to properly identify timestep in adj…
Browse files Browse the repository at this point in the history
…ust losses
  • Loading branch information
janinefreeman committed Nov 15, 2023
1 parent 916dd29 commit 2c3c274
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
12 changes: 8 additions & 4 deletions ssc/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ bool adjustment_factors::setup(int nsteps, int analysis_period) //nsteps is set
m_factors[nsteps * a + i] *= (1.0 - p[a*nsteps + i]/100.0); //convert from percentages to factors
}
}
else if (n % 12 == 0) { //Monthly
else if (n == (size_t)( 12 * analysis_period)) { //Monthly
for (int a = 0; a < analysis_period; a++) {
for (int i = 0; i < nsteps; i++) {
month = util::month_of(int(i / steps_per_hour))-1;
Expand All @@ -1108,7 +1108,7 @@ bool adjustment_factors::setup(int nsteps, int analysis_period) //nsteps is set

}
}
else if (n % 365 == 0) { //Daily
else if (n == (size_t)( 365 * analysis_period)) { //Daily
for (int a = 0; a < analysis_period; a++) {
for (int i = 0; i < nsteps; i++) {
day = util::day_of_year(int(i / steps_per_hour));
Expand All @@ -1117,7 +1117,7 @@ bool adjustment_factors::setup(int nsteps, int analysis_period) //nsteps is set

}
}
else if (n % 52 == 0) { //Weekly
else if (n == (size_t)( 52 * analysis_period)) { //Weekly
for (int a = 0; a < analysis_period; a++) {
for (int i = 0; i < nsteps; i++) {
week = util::week_of(int(i / steps_per_hour));
Expand All @@ -1132,8 +1132,12 @@ bool adjustment_factors::setup(int nsteps, int analysis_period) //nsteps is set
m_factors[nsteps * a + i] *= (1.0 - p[a]/100.0); //input as factors not percentage
}
}
else if (n > (size_t)(nsteps * analysis_period)) // more helpful error for timestep mismatch
{
m_error = util::format("Lifetime availability losses timestep cannot be more granular than weather file timestep.");
}
else {
m_error = util::format("Error with lifetime loss data inputs");
m_error = util::format("Error in length of lifetime availability losses.");
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/input_cases/pvsamv1_battery_common_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ void pvsamv1_battery_defaults(ssc_data_t& data) {
ssc_data_set_number(data, "dc_adjust_constant", 0.0);
ssc_data_set_number(data, "dc_adjust_en_periods", 1);
ssc_data_set_matrix(data, "dc_adjust_periods", p_dc_adjust_periods, 1, 3);
ssc_data_set_number(data, "dc_adjust_en_timeindex", 1);
ssc_data_set_number(data, "dc_adjust_en_timeindex", 0);
ssc_data_set_array(data, "dc_adjust_timeindex", p_dc_adjust_hourly, 8760);

ssc_data_set_number(data, "batt_chem", 1);
Expand Down Expand Up @@ -1167,7 +1167,7 @@ void commercial_multiarray_default(ssc_data_t& data) {
ssc_data_set_number(data, "dc_adjust_constant", 0.0);
ssc_data_set_number(data, "dc_adjust_en_periods", 1);
ssc_data_set_matrix(data, "dc_adjust_periods", p_dc_adjust_periods, 1, 3);
ssc_data_set_number(data, "dc_adjust_en_timeindex", 1);
ssc_data_set_number(data, "dc_adjust_en_timeindex", 0);
ssc_data_set_array(data, "dc_adjust_timeindex", p_dc_adjust_hourly, 8760);


Expand Down
5 changes: 1 addition & 4 deletions test/ssc_test/cmod_pvsamv1_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,7 @@ TEST_F(CMPvsamv1PowerIntegration_cmod_pvsamv1, LossAdjustmentNonLifetime) {
ssc_data_set_array(data, "adjust_timeindex", timeindex_subhourly, 17520);

pvsam_errors = run_module(data, "pvsamv1");
ssc_data_get_number(data, "annual_energy", &annual_energy);
EXPECT_NEAR(annual_energy, 8833.8, m_error_tolerance_hi);
ssc_data_get_number(data, "kwh_per_kw", &kwh_per_kw);
EXPECT_NEAR(kwh_per_kw, 1883, m_error_tolerance_hi) << "Energy yield"; // Same as 1 year because year 2 has 0 production
EXPECT_TRUE(pvsam_errors); //this should throw an error because we are not allowing losses at a more granular timestep than weather
}


Expand Down

0 comments on commit 2c3c274

Please sign in to comment.