Skip to content

Commit

Permalink
Constrain flow count to avoid cycling flows
Browse files Browse the repository at this point in the history
- use new constraint feature from oemof 0.4
- make Battery flows nonconvex to be able to use its status of activity
- add the limited flow count constraint to the oemof model

Resolves simultanious in and out flow of #218
  • Loading branch information
j-ti committed Mar 10, 2021
1 parent 2854ea0 commit 795490f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions smooth/components/component_battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,11 @@ def create_oemof_model(self, busses, _):
battery = solph.components.GenericStorage(
label=self.name,
inputs={busses[self.bus_in_and_out]: solph.Flow(
nominal_value=self.p_in_max, variable_costs=self.current_vac[0])
},
nonconvex=solph.NonConvex(), exclusive_flow=True,
nominal_value=self.p_in_max, variable_costs=self.current_vac[0]),
},
outputs={busses[self.bus_in_and_out]: solph.Flow(
nonconvex=solph.NonConvex(), exclusive_flow=False,
nominal_value=self.p_out_max, variable_costs=self.current_vac[1])
},
loss_rate=self.loss_rate,
Expand Down
18 changes: 18 additions & 0 deletions smooth/framework/run_smooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
"""

import oemof.solph as solph
from oemof.solph.constraints import limit_active_flow_count

from smooth.framework.simulation_parameters import SimulationParameters as sp
from smooth.framework.functions.debug import get_df_debug, show_debug
Expand Down Expand Up @@ -200,6 +201,23 @@ def run_smooth(model):
# Do the simulation for this time step.
model_to_solve = solph.Model(oemof_model)

# Add constraints to the oemof model
# - Only one Battery flow should be active per timestep
# TODO: specify constrained flow within model description file (maybe using keyword),
# so it does not apply for all Generic Storages, but e.g. only batteries
my_constraint_flows = []
for flow in model_to_solve.flows:
for in_or_out in flow:
if isinstance(in_or_out, solph.components.GenericStorage):
my_constraint_flows.append(flow)
model_to_solve = limit_active_flow_count(model_to_solve,
'in_or_out_flow',
my_constraint_flows,
lower_limit=0,
upper_limit=1)



for this_comp in components:
this_comp.update_constraints(busses, model_to_solve)

Expand Down

0 comments on commit 795490f

Please sign in to comment.