Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add assertion error if flows in and out of battery are detected #261

Merged
merged 5 commits into from
Apr 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')