From 2c3c27443e1f725f854f054b2e2ca3363c84fbf4 Mon Sep 17 00:00:00 2001 From: Janine Keith Date: Wed, 15 Nov 2023 15:49:51 -0700 Subject: [PATCH] updated logic in adjust variable to properly identify timestep in adjust losses --- ssc/common.cpp | 12 ++++++++---- test/input_cases/pvsamv1_battery_common_data.h | 4 ++-- test/ssc_test/cmod_pvsamv1_test.cpp | 5 +---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/ssc/common.cpp b/ssc/common.cpp index 42b78204f..7889be904 100644 --- a/ssc/common.cpp +++ b/ssc/common.cpp @@ -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; @@ -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)); @@ -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)); @@ -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."); } } } diff --git a/test/input_cases/pvsamv1_battery_common_data.h b/test/input_cases/pvsamv1_battery_common_data.h index c81e47f6d..5122988c8 100644 --- a/test/input_cases/pvsamv1_battery_common_data.h +++ b/test/input_cases/pvsamv1_battery_common_data.h @@ -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); @@ -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); diff --git a/test/ssc_test/cmod_pvsamv1_test.cpp b/test/ssc_test/cmod_pvsamv1_test.cpp index 6c92fa33d..2212f3832 100644 --- a/test/ssc_test/cmod_pvsamv1_test.cpp +++ b/test/ssc_test/cmod_pvsamv1_test.cpp @@ -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 }