Skip to content

Commit

Permalink
Merge pull request #261 from rl-institut/feature/battery_cycle_warning
Browse files Browse the repository at this point in the history
Add assertion error if flows in and out of battery are detected
  • Loading branch information
stefansc1 authored Apr 29, 2021
2 parents b585652 + 9eb8394 commit 32f12fe
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions smooth/components/component_battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,18 @@ def add_to_oemof_model(self, busses, model):
model.add(battery)
return battery

def update_flows(self, results, comp_name=None):
"""Update flow values for each flow in the 'flows' dict of results
:param results: The oemof results for the given time step
:type results: object
:param comp_name: The name of the component - while components can generate more
than one oemof model, they sometimes need to give a custom name, defaults to None
:type comp_name: str, optional
"""
Component.update_flows(self, results, self.name)
self.check_flows()

def update_states(self, results):
"""Updates the states of the battery component for each time step
Expand All @@ -271,3 +283,27 @@ def update_states(self, results):
# Check if this result is the state of charge.
self.soc = df_storage[i_result][0] / self.battery_capacity
self.states["soc"][self.sim_params.i_interval] = self.soc

def check_flows(self):
""" Checks if there are flows in and out of the battery and if so triggers an AssertionError
:raises: ValueError if flows in and out of the battery at the same time are detected
"""
# get current time index
time_idx = self.sim_params.i_interval
# get number of current non-zero flows
non_zero_flows = sum([1 if flow[time_idx] else 0 for flow in self.flows.values()])
if non_zero_flows > 1:
# more than one non-zero flow detected
# compute vac_out_threshold: the minimum vac_out required to prevent circular flows
vac_out_threshold = -self.vac_in / (self.efficiency_charge * self.efficiency_discharge)
if self.vac_in < 0 and self.vac_out < vac_out_threshold:
# vac_in/vac_out invalid: charging and discharging at the same time is incentivized
raise ValueError('There are flows in and out of the Battery \'' + self.name +
'\'. If the Battery is incetivised to be charged using negative '
'vac_in, vac_out has to be chosen higher than: '
'-vac_in / (efficiency_charge * efficiency_discharge)')
else:
# something different went wrong. Does this even happen?
raise ValueError('There are flows in and out of the Battery \'' + self.name +
'\'. Please reevaluate your settings')

0 comments on commit 32f12fe

Please sign in to comment.