Skip to content

Commit

Permalink
Modify index to year 1 index to correctly utilize tou demand function…
Browse files Browse the repository at this point in the history
…. Add unit test that captures the issue
  • Loading branch information
brtietz committed Mar 20, 2024
1 parent 3947748 commit ae0272e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
3 changes: 2 additions & 1 deletion shared/lib_utility_rate_equations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,7 @@ void forecast_setup::setup(rate_data* rate, std::vector<double>& 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;
Expand All @@ -1367,7 +1368,7 @@ void forecast_setup::setup(rate_data* rate, std::vector<double>& 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) {
Expand Down
51 changes: 51 additions & 0 deletions test/shared_test/lib_battery_dispatch_automatic_btm_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}

0 comments on commit ae0272e

Please sign in to comment.