Skip to content

Commit

Permalink
Same logic should apply to max SOC at end of outage. Clean up additio…
Browse files Browse the repository at this point in the history
…nal tests
  • Loading branch information
brtietz committed Feb 17, 2025
1 parent 883afad commit 773827a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
7 changes: 6 additions & 1 deletion shared/lib_battery_capacity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,11 @@ void capacity_t::check_SOC() {

// do not switch to discharging
state->cell_current = fmin(0, state->cell_current);

// Correct state given current change
state->q0 = q_upper;
}
state->q0 = q_upper;

}
else if (state->q0 < q_lower - tolerance) {
// if undercharged then reduce discharhing
Expand All @@ -172,6 +175,8 @@ void capacity_t::check_SOC() {

// do not switch to charging
state->cell_current = fmax(0, state->cell_current);

// Correct state given current change
state->q0 = q_lower;
}
}
Expand Down
10 changes: 5 additions & 5 deletions test/shared_test/lib_battery_dispatch_automatic_btm_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1217,9 +1217,9 @@ TEST_F(AutoBTMTest_lib_battery_dispatch, DispatchAutoBTMGridOutagePeakShavingEmp
dispatchAutoBTM->dispatch(0, h-1, 0);
h++;

EXPECT_NEAR(batteryPower->powerBatteryDC, 2.68, 0.5) << " error in expected at hour " << h;
EXPECT_NEAR(batteryPower->powerBatteryDC, 2.08, 0.5) << " error in expected at hour " << h;

EXPECT_NEAR(batteryModel->SOC(), 95, 0.01);
EXPECT_NEAR(batteryModel->SOC(), 96.31, 0.01);

// Battery cannot charge above max SOC
batteryPower->powerLoad = 700;
Expand Down Expand Up @@ -1454,14 +1454,14 @@ TEST_F(AutoBTMTest_lib_battery_dispatch, DispatchAutoBTMGridOutageCustomEmptyAnd
EXPECT_EQ(h, 17);

// Show that the battery can discharge above max SOC after outage
batteryPower->powerLoad = 5;
batteryPower->powerLoad = 8;
batteryPower->powerSystem = 0;
batteryPower->isOutageStep = false;
batteryPower->powerCritLoad = 5;
batteryPower->powerCritLoad = 8;
dispatchAutoBTM->dispatch(0, h, 0);
h++;

EXPECT_NEAR(batteryPower->powerBatteryDC, 5.25, 0.5) << " error in expected at hour " << h;
EXPECT_NEAR(batteryPower->powerBatteryDC, 9.45, 0.5) << " error in expected at hour " << h;

EXPECT_NEAR(batteryModel->SOC(), 95.01, 0.01);

Expand Down
6 changes: 3 additions & 3 deletions test/shared_test/lib_battery_dispatch_manual_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ TEST_F(ManualTest_lib_battery_dispatch, OutageWithManualDispatch) {
batteryPower->powerLoad = 50;
dispatchManual->dispatch(year, hour_of_year, step_of_hour);
hour_of_year += 1;
EXPECT_NEAR(batteryPower->powerBatteryDC, -50.0, 0.1);
EXPECT_NEAR(batteryPower->powerBatteryDC, -47.7, 0.1);

// Turn outage back on, should charge to 100%
batteryPower->powerSystem = 700; batteryPower->voltageSystem = 600; batteryPower->powerLoad = 50;
Expand All @@ -691,7 +691,7 @@ TEST_F(ManualTest_lib_battery_dispatch, OutageWithManualDispatch) {
soc = dispatchManual->battery_soc();
}
EXPECT_NEAR(100, dispatchManual->battery_soc(), 0.1);
EXPECT_NEAR(17, hour_of_year, 0.1);
EXPECT_NEAR(19, hour_of_year, 0.1);

// With outage off, can discharge above max SOC
batteryPower->powerSystem = 0; batteryPower->voltageSystem = 600; batteryPower->powerLoad = 14;
Expand All @@ -701,7 +701,7 @@ TEST_F(ManualTest_lib_battery_dispatch, OutageWithManualDispatch) {
EXPECT_NEAR(batteryPower->powerBatteryDC, 14.6, 0.1);

// With outage off, cannot charge above max soc
EXPECT_NEAR(95, dispatchManual->battery_soc(), 0.1);
EXPECT_NEAR(97.42, dispatchManual->battery_soc(), 0.1);
batteryPower->powerSystem = 700; batteryPower->voltageSystem = 600; batteryPower->powerLoad = 14;
batteryPower->powerCritLoad = 14; batteryPower->isOutageStep = false;
dispatchManual->dispatch(year, hour_of_year, step_of_hour);
Expand Down

0 comments on commit 773827a

Please sign in to comment.