diff --git a/shared/lib_utility_rate_equations.cpp b/shared/lib_utility_rate_equations.cpp index 1f08b23f5..d27c26c50 100644 --- a/shared/lib_utility_rate_equations.cpp +++ b/shared/lib_utility_rate_equations.cpp @@ -1352,6 +1352,7 @@ void forecast_setup::setup(rate_data* rate, std::vector& P_pv_ac, std::v } for (size_t idx = 0; idx < num_recs && idx < array_size; idx++) { + size_t year_one_index = util::yearOneIndex(1.0 / _steps_per_hour, idx); double grid_power = P_pv_ac[idx] - P_load_ac[idx]; gross_load_during_month += P_load_ac[idx] * _dt_hour; @@ -1367,7 +1368,7 @@ void forecast_setup::setup(rate_data* rate, std::vector& P_pv_ac, std::v } if (rate->dc_enabled) { - int dc_tou_period = rate->get_dc_tou_row(idx, curr_month - 1); + int dc_tou_period = rate->get_dc_tou_row(year_one_index, curr_month - 1); size_t month_idx = year * 12 + (curr_month - 1); double peak = monthly_peaks.at(month_idx, dc_tou_period) - peak_offset; // Peak for dispatch calcs in battery: peak minus battery capacity if (-1.0 * grid_power > peak) { diff --git a/test/shared_test/lib_battery_dispatch_automatic_btm_test.cpp b/test/shared_test/lib_battery_dispatch_automatic_btm_test.cpp index 8cca9533a..fd290c3b0 100644 --- a/test/shared_test/lib_battery_dispatch_automatic_btm_test.cpp +++ b/test/shared_test/lib_battery_dispatch_automatic_btm_test.cpp @@ -1619,3 +1619,54 @@ TEST_F(AutoBTMTest_lib_battery_dispatch, DispatchAutoBTMGridOutageFuelCellCharge EXPECT_NEAR(batteryPower->powerCritLoadUnmet, expectedCritLoadUnmet[h], 0.1) << " error in crit load at hour " << h; } } + +TEST_F(AutoBTMTest_lib_battery_dispatch, DispatchAutoBTMSetupRateForecastMultiYear) { + double dtHour = 1; + CreateBattery(dtHour); + + util_rate = new rate_data(); + util_rate->dc_enabled = true; + set_up_default_commercial_rate_data(*util_rate); + + double defaultEff = 0.96; + size_t nyears = 25; + + dispatchAutoBTM = new dispatch_automatic_behind_the_meter_t(batteryModel, dtHour, SOC_min, SOC_max, currentChoice, + max_current, + max_current, max_power * defaultEff, max_power / defaultEff, max_power, max_power, + 0, dispatch_t::BTM_MODES::RETAIL_RATE, dispatch_t::WEATHER_FORECAST_CHOICE::WF_LOOK_AHEAD, 0, nyears, 24, 1, true, + true, false, false, util_rate, replacementCost, cyclingChoice, cyclingCost, omCost, interconnection_limit, chargeOnlySystemExceedLoad, + dischargeOnlyLoadExceedSystem, dischargeToGrid, min_outage_soc, dispatch_t::LOAD_FORECAST_CHOICE::LOAD_LOOK_AHEAD); + + // Setup pv and load signal for peak shaving algorithm + for (size_t h = 0; h < 8760 * nyears; h++) { + if (h % 24 > 6 && h % 24 < 16) { + pv_prediction.push_back(700); + } + else if (h % 24 == 18) { + pv_prediction.push_back(750); + } + else { + pv_prediction.push_back(0); + } + + if (h % 24 == 6) { + load_prediction.push_back(600); + } + else if (h % 24 > 16) { + load_prediction.push_back(700); + } + else { + load_prediction.push_back(50); + } + } + + dispatchAutoBTM->update_load_data(load_prediction); + dispatchAutoBTM->update_pv_data(pv_prediction); + dispatchAutoBTM->setup_rate_forecast(); + + // Testing to make sure there are no errors thrown + + delete util_rate; + +}