Skip to content

Commit

Permalink
calc_battery_energy func in model_ref fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
SongminYu committed Mar 5, 2024
1 parent 299ef1d commit 6a750af
Showing 1 changed file with 10 additions and 31 deletions.
41 changes: 10 additions & 31 deletions models/operation/model_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,47 +111,26 @@ def calc_battery_energy(self, grid_demand: np.array, pv_surplus: np.array):

if pv_surplus[i] > 0:
if bat_soc_start < capacity:
if pv_surplus[i] <= max_charge_power:
charge_amount = pv_surplus[i]
bat_gap = capacity - bat_soc_start
if pv_surplus[i] >= bat_gap:
charge_amount = min(bat_gap, max_charge_power)
else:
charge_amount = max_charge_power
charge_amount = min(pv_surplus[i], max_charge_power)
self.BatSoC[i] = (bat_soc_start + charge_amount * charge_efficiency)
self.PV2Bat[i] = charge_amount
pv_surplus_after_battery[i] -= charge_amount
self.BatSoC[i] = (
bat_soc_start + charge_amount * charge_efficiency
)
self.PV2Bat[i] = charge_amount * charge_efficiency
if self.BatSoC[i] > capacity:
right_charge_amount = (
capacity - bat_soc_start
) / charge_efficiency
pv_surplus_after_battery[i] += (
charge_amount - right_charge_amount
)
self.BatSoC[i] = capacity
self.PV2Bat[i] = capacity - bat_soc_start
else:
pass
else:
self.BatSoC[i] = capacity
self.PV2Bat[i] = 0
else:
if bat_soc_start > 0:
if bat_soc_start < max_discharge_power:
discharge_amount = bat_soc_start
if bat_soc_start * discharge_efficiency <= grid_demand[i]:
discharge_amount = min(bat_soc_start, max_discharge_power)
else:
discharge_amount = max_discharge_power
grid_demand_after_battery[i] = (
grid_demand[i] - discharge_amount * discharge_efficiency
)
discharge_amount = min(grid_demand[i], max_discharge_power)
grid_demand_after_battery[i] = grid_demand[i] - discharge_amount * discharge_efficiency
self.BatSoC[i] = bat_soc_start - discharge_amount
self.Bat2Load[i] = discharge_amount * discharge_efficiency
if grid_demand_after_battery[i] < 0:
discharge_amount = grid_demand[i] / discharge_efficiency
grid_demand_after_battery[i] = 0
self.BatSoC[i] = bat_soc_start - discharge_amount
self.Bat2Load[i] = grid_demand[i]
else:
pass
else:
grid_demand_after_battery[i] = grid_demand[i]
self.BatSoC[i] = 0
Expand Down

0 comments on commit 6a750af

Please sign in to comment.