From dcebc7d94b5754b7e4626a950d58e49ab7748f9f Mon Sep 17 00:00:00 2001 From: "Julian.Endres" Date: Mon, 25 Mar 2024 17:32:04 +0100 Subject: [PATCH 1/6] Make invest relations iterable --- src/oemof/solph/components/_generic_storage.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/oemof/solph/components/_generic_storage.py b/src/oemof/solph/components/_generic_storage.py index d1731ee1d..2053ea01f 100644 --- a/src/oemof/solph/components/_generic_storage.py +++ b/src/oemof/solph/components/_generic_storage.py @@ -53,15 +53,15 @@ class GenericStorage(Node): :class:`oemof.solph.options.Investment` object Absolute nominal capacity of the storage, fixed value or object describing parameter of investment optimisations. - invest_relation_input_capacity : numeric or None, :math:`r_{cap,in}` + invest_relation_input_capacity : numeric (iterable or scalar) or None, :math:`r_{cap,in}` Ratio between the investment variable of the input Flow and the investment variable of the storage: :math:`\dot{E}_{in,invest} = E_{invest} \cdot r_{cap,in}` - invest_relation_output_capacity : numeric or None, :math:`r_{cap,out}` + invest_relation_output_capacity : numeric (iterable or scalar) or None, :math:`r_{cap,out}` Ratio between the investment variable of the output Flow and the investment variable of the storage: :math:`\dot{E}_{out,invest} = E_{invest} \cdot r_{cap,out}` - invest_relation_input_output : numeric or None, :math:`r_{in,out}` + invest_relation_input_output : numeric (iterable or scalar) or None, :math:`r_{in,out}` Ratio between the investment variable of the output Flow and the investment variable of the input flow. This ratio used to fix the flow investments to each other. @@ -237,9 +237,9 @@ def __init__( self.min_storage_level = solph_sequence(min_storage_level) self.fixed_costs = solph_sequence(fixed_costs) self.storage_costs = solph_sequence(storage_costs) - self.invest_relation_input_output = invest_relation_input_output - self.invest_relation_input_capacity = invest_relation_input_capacity - self.invest_relation_output_capacity = invest_relation_output_capacity + self.invest_relation_input_output = solph_sequence(invest_relation_input_output) + self.invest_relation_input_capacity = solph_sequence(invest_relation_input_capacity) + self.invest_relation_output_capacity = solph_sequence(invest_relation_output_capacity) self.lifetime_inflow = lifetime_inflow self.lifetime_outflow = lifetime_outflow @@ -567,7 +567,7 @@ def _power_coupled(block): for p in m.PERIODS: expr = ( m.InvestmentFlowBlock.total[n, o[n], p] - ) * n.invest_relation_input_output == ( + ) * n.invest_relation_input_output[p] == ( m.InvestmentFlowBlock.total[i[n], n, p] ) self.power_coupled.add((n, p), expr) @@ -1577,7 +1577,7 @@ def _power_coupled(block): for p in m.PERIODS: expr = ( m.InvestmentFlowBlock.total[n, o[n], p] - ) * n.invest_relation_input_output == ( + ) * n.invest_relation_input_output[p] == ( m.InvestmentFlowBlock.total[i[n], n, p] ) self.power_coupled.add((n, p), expr) @@ -1620,7 +1620,7 @@ def _storage_capacity_outflow_invest_rule(block): for p in m.PERIODS: expr = ( m.InvestmentFlowBlock.total[n, o[n], p] - == self.total[n, p] * n.invest_relation_output_capacity + == self.total[n, p] * n.invest_relation_output_capacity[p] ) self.storage_capacity_outflow.add((n, p), expr) From 9a0669a6e85a2f4689dedaa6a7569774490de78a Mon Sep 17 00:00:00 2001 From: SabineHaas Date: Wed, 3 Apr 2024 16:52:14 +0200 Subject: [PATCH 2/6] Fix tests by adapting error raising to solph_sequence --- src/oemof/solph/components/_generic_storage.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/oemof/solph/components/_generic_storage.py b/src/oemof/solph/components/_generic_storage.py index 2053ea01f..dba3885ff 100644 --- a/src/oemof/solph/components/_generic_storage.py +++ b/src/oemof/solph/components/_generic_storage.py @@ -278,9 +278,9 @@ def _check_invest_attributes(self): ) raise AttributeError(e1) if ( - self.invest_relation_input_output is not None - and self.invest_relation_output_capacity is not None - and self.invest_relation_input_capacity is not None + self.invest_relation_input_output[0] is not None + and self.invest_relation_output_capacity[0] is not None + and self.invest_relation_input_capacity[0] is not None ): e2 = ( "Overdetermined. Three investment object will be coupled" From e6aa466972d917277cbd29e9c470fb0f193732f4 Mon Sep 17 00:00:00 2001 From: SabineHaas Date: Wed, 3 Apr 2024 16:59:55 +0200 Subject: [PATCH 3/6] Apply black --- src/oemof/solph/components/_generic_storage.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/oemof/solph/components/_generic_storage.py b/src/oemof/solph/components/_generic_storage.py index dba3885ff..6b43f2dde 100644 --- a/src/oemof/solph/components/_generic_storage.py +++ b/src/oemof/solph/components/_generic_storage.py @@ -237,9 +237,15 @@ def __init__( self.min_storage_level = solph_sequence(min_storage_level) self.fixed_costs = solph_sequence(fixed_costs) self.storage_costs = solph_sequence(storage_costs) - self.invest_relation_input_output = solph_sequence(invest_relation_input_output) - self.invest_relation_input_capacity = solph_sequence(invest_relation_input_capacity) - self.invest_relation_output_capacity = solph_sequence(invest_relation_output_capacity) + self.invest_relation_input_output = solph_sequence( + invest_relation_input_output + ) + self.invest_relation_input_capacity = solph_sequence( + invest_relation_input_capacity + ) + self.invest_relation_output_capacity = solph_sequence( + invest_relation_output_capacity + ) self.lifetime_inflow = lifetime_inflow self.lifetime_outflow = lifetime_outflow @@ -1620,7 +1626,8 @@ def _storage_capacity_outflow_invest_rule(block): for p in m.PERIODS: expr = ( m.InvestmentFlowBlock.total[n, o[n], p] - == self.total[n, p] * n.invest_relation_output_capacity[p] + == self.total[n, p] + * n.invest_relation_output_capacity[p] ) self.storage_capacity_outflow.add((n, p), expr) From c818a14753d34dbf9418b84cce985ab87a80c3bb Mon Sep 17 00:00:00 2001 From: SabineHaas Date: Wed, 22 May 2024 10:40:44 +0200 Subject: [PATCH 4/6] Fix more tests by adapting to solph_sequence --- src/oemof/solph/components/_generic_storage.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/oemof/solph/components/_generic_storage.py b/src/oemof/solph/components/_generic_storage.py index 6b43f2dde..77941b7e9 100644 --- a/src/oemof/solph/components/_generic_storage.py +++ b/src/oemof/solph/components/_generic_storage.py @@ -263,13 +263,13 @@ def _set_flows(self): """ for flow in self.inputs.values(): if ( - self.invest_relation_input_capacity is not None + self.invest_relation_input_capacity[0] is not None and not isinstance(flow.investment, Investment) ): flow.investment = Investment(lifetime=self.lifetime_inflow) for flow in self.outputs.values(): if ( - self.invest_relation_output_capacity is not None + self.invest_relation_output_capacity[0] is not None and not isinstance(flow.investment, Investment) ): flow.investment = Investment(lifetime=self.lifetime_outflow) @@ -489,7 +489,7 @@ def _create(self, group=None): self.STORAGES_WITH_INVEST_FLOW_REL = Set( initialize=[ - n for n in group if n.invest_relation_input_output is not None + n for n in group if n.invest_relation_input_output[0] is not None ] ) @@ -1167,7 +1167,7 @@ def _create(self, group=None): initialize=[ n for n in group - if n.invest_relation_input_capacity is not None + if n.invest_relation_input_capacity[0] is not None ] ) @@ -1175,13 +1175,13 @@ def _create(self, group=None): initialize=[ n for n in group - if n.invest_relation_output_capacity is not None + if n.invest_relation_output_capacity[0] is not None ] ) self.INVEST_REL_IN_OUT = Set( initialize=[ - n for n in group if n.invest_relation_input_output is not None + n for n in group if n.invest_relation_input_output[0] is not None ] ) @@ -1604,7 +1604,7 @@ def _storage_capacity_inflow_invest_rule(block): for p in m.PERIODS: expr = ( m.InvestmentFlowBlock.total[i[n], n, p] - == self.total[n, p] * n.invest_relation_input_capacity + == self.total[n, p] * n.invest_relation_input_capacity[p] ) self.storage_capacity_inflow.add((n, p), expr) From 1da119643a4f802c62999f7f63835f48474b6771 Mon Sep 17 00:00:00 2001 From: SabineHaas Date: Wed, 22 May 2024 10:57:17 +0200 Subject: [PATCH 5/6] Fix remaining tests by changing order of results --- tests/test_processing.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_processing.py b/tests/test_processing.py index c7d9d5842..d10893dfe 100644 --- a/tests/test_processing.py +++ b/tests/test_processing.py @@ -164,8 +164,6 @@ def test_nodes_with_none_exclusion(self): { "balanced": True, "initial_storage_level": 0, - "invest_relation_input_capacity": 1 / 6, - "invest_relation_output_capacity": 1 / 6, "investment_age": 0, "investment_existing": 0, "investment_interest_rate": 0, @@ -180,6 +178,8 @@ def test_nodes_with_none_exclusion(self): "fixed_losses_absolute": 0, "fixed_losses_relative": 0, "inflow_conversion_factor": 1, + "invest_relation_input_capacity": 1 / 6, + "invest_relation_output_capacity": 1 / 6, "loss_rate": 0, "max_storage_level": 1, "min_storage_level": 0, @@ -204,8 +204,6 @@ def test_nodes_with_none_exclusion_old_name(self): { "balanced": True, "initial_storage_level": 0, - "invest_relation_input_capacity": 1 / 6, - "invest_relation_output_capacity": 1 / 6, "investment_age": 0, "investment_existing": 0, "investment_interest_rate": 0, @@ -220,6 +218,8 @@ def test_nodes_with_none_exclusion_old_name(self): "fixed_losses_absolute": 0, "fixed_losses_relative": 0, "inflow_conversion_factor": 1, + "invest_relation_input_capacity": 1 / 6, + "invest_relation_output_capacity": 1 / 6, "loss_rate": 0, "max_storage_level": 1, "min_storage_level": 0, From e85675423c47021af1eacf46bf4ed0508f7c25a6 Mon Sep 17 00:00:00 2001 From: SabineHaas Date: Wed, 22 May 2024 12:00:04 +0200 Subject: [PATCH 6/6] Apply black --- .../solph/components/_generic_storage.py | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/oemof/solph/components/_generic_storage.py b/src/oemof/solph/components/_generic_storage.py index 77941b7e9..4f3b7165e 100644 --- a/src/oemof/solph/components/_generic_storage.py +++ b/src/oemof/solph/components/_generic_storage.py @@ -262,16 +262,14 @@ def _set_flows(self): coupled with storage capacity via invest relations """ for flow in self.inputs.values(): - if ( - self.invest_relation_input_capacity[0] is not None - and not isinstance(flow.investment, Investment) - ): + if self.invest_relation_input_capacity[ + 0 + ] is not None and not isinstance(flow.investment, Investment): flow.investment = Investment(lifetime=self.lifetime_inflow) for flow in self.outputs.values(): - if ( - self.invest_relation_output_capacity[0] is not None - and not isinstance(flow.investment, Investment) - ): + if self.invest_relation_output_capacity[ + 0 + ] is not None and not isinstance(flow.investment, Investment): flow.investment = Investment(lifetime=self.lifetime_outflow) def _check_invest_attributes(self): @@ -489,7 +487,9 @@ def _create(self, group=None): self.STORAGES_WITH_INVEST_FLOW_REL = Set( initialize=[ - n for n in group if n.invest_relation_input_output[0] is not None + n + for n in group + if n.invest_relation_input_output[0] is not None ] ) @@ -1181,7 +1181,9 @@ def _create(self, group=None): self.INVEST_REL_IN_OUT = Set( initialize=[ - n for n in group if n.invest_relation_input_output[0] is not None + n + for n in group + if n.invest_relation_input_output[0] is not None ] ) @@ -1604,7 +1606,8 @@ def _storage_capacity_inflow_invest_rule(block): for p in m.PERIODS: expr = ( m.InvestmentFlowBlock.total[i[n], n, p] - == self.total[n, p] * n.invest_relation_input_capacity[p] + == self.total[n, p] + * n.invest_relation_input_capacity[p] ) self.storage_capacity_inflow.add((n, p), expr)