From aeac8e08dad480a7d46283a0e2f643c2851db4f8 Mon Sep 17 00:00:00 2001 From: minhki95 Date: Wed, 27 Apr 2022 16:53:36 +0200 Subject: [PATCH 1/3] Add attribute cellular_system to enable cellular nested models --- src/oemof/solph/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/oemof/solph/models.py b/src/oemof/solph/models.py index 04bf0e0f8..73fcf9eb9 100644 --- a/src/oemof/solph/models.py +++ b/src/oemof/solph/models.py @@ -74,6 +74,7 @@ def __init__(self, energysystem, **kwargs): self.timeincrement = sequence( kwargs.get("timeincrement", self.es.timeincrement) ) + self.cellular_system = kwargs.get("cellular_system", False) if self.timeincrement[0] is None: try: self.timeincrement = sequence( From c4a42555a113bb85227eb8c7588e0743a27004a1 Mon Sep 17 00:00:00 2001 From: minhki95 Date: Wed, 27 Apr 2022 16:55:11 +0200 Subject: [PATCH 2/3] Enable weighted objective function with accordance to cellular system --- src/oemof/solph/blocks/flow.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/oemof/solph/blocks/flow.py b/src/oemof/solph/blocks/flow.py index 926c5302e..8e07e837f 100644 --- a/src/oemof/solph/blocks/flow.py +++ b/src/oemof/solph/blocks/flow.py @@ -117,7 +117,7 @@ def _create(self, group=None): (g[0], g[1]) for g in group if g[2].summed_max is not None - and g[2].nominal_value is not None + and g[2].nominal_value is not None ] ) @@ -126,7 +126,7 @@ def _create(self, group=None): (g[0], g[1]) for g in group if g[2].summed_min is not None - and g[2].nominal_value is not None + and g[2].nominal_value is not None ] ) @@ -259,11 +259,23 @@ def _objective_expression(self): for i, o in m.FLOWS: if m.flows[i, o].variable_costs[0] is not None: - for t in m.TIMESTEPS: - variable_costs += ( - m.flow[i, o, t] - * m.objective_weighting[t] - * m.flows[i, o].variable_costs[t] - ) + if m.cellular_system: + if i.cell_list and o.cell_list: + intersection = set(i.cell_list) & set(o.cell_list) + weight = len(intersection) + for t in m.TIMESTEPS: + variable_costs += ( + m.flow[i, o, t] + * m.objective_weighting[t] + * m.flows[i, o].variable_costs[t] + * weight + ) + else: + for t in m.TIMESTEPS: + variable_costs += ( + m.flow[i, o, t] + * m.objective_weighting[t] + * m.flows[i, o].variable_costs[t] + ) return variable_costs From fb4365970cb31d8adc9c682323dcc0138ef6cb9e Mon Sep 17 00:00:00 2001 From: minhki95 Date: Mon, 2 May 2022 13:17:41 +0200 Subject: [PATCH 3/3] Modify objective expression of investment flows for weighted sum approach --- src/oemof/solph/blocks/investment_flow.py | 34 ++++++++++++++++++----- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/oemof/solph/blocks/investment_flow.py b/src/oemof/solph/blocks/investment_flow.py index 9cc9075fe..41dd50af9 100644 --- a/src/oemof/solph/blocks/investment_flow.py +++ b/src/oemof/solph/blocks/investment_flow.py @@ -412,14 +412,34 @@ def _objective_expression(self): investment_costs = 0 for i, o in self.CONVEX_INVESTFLOWS: - investment_costs += ( - self.invest[i, o] * m.flows[i, o].investment.ep_costs - ) + if m.cellular_system: + if i.cell_list and o.cell_list: + intersection = set(i.cell_list) & set(o.cell_list) + weight = len(intersection) + investment_costs += ( + self.invest[i, o] + * m.flows[i, o].investment.ep_costs + * weight + ) + else: + investment_costs += ( + self.invest[i, o] * m.flows[i, o].investment.ep_costs + ) for i, o in self.NON_CONVEX_INVESTFLOWS: - investment_costs += ( - self.invest[i, o] * m.flows[i, o].investment.ep_costs - + self.invest_status[i, o] * m.flows[i, o].investment.offset - ) + if m.cellular_system: + if i.cell_list and o.cell_list: + intersection = set(i.cell_list) & set(o.cell_list) + weight = len(intersection) + investment_costs += ( + self.invest[i, o] * m.flows[i, o].investment.ep_costs * weight + + self.invest_status[i, o] * m.flows[i, o].investment.offset + ) + + else: + investment_costs += ( + self.invest[i, o] * m.flows[i, o].investment.ep_costs + + self.invest_status[i, o] * m.flows[i, o].investment.offset + ) self.investment_costs = Expression(expr=investment_costs) return investment_costs