Skip to content

Commit

Permalink
Merge pull request #1063 from oemof/features/generic-storage-periodic…
Browse files Browse the repository at this point in the history
…-invest-relation

Make invest relations iterable
  • Loading branch information
p-snft authored Aug 23, 2024
2 parents 5706ca2 + e856754 commit abb1be9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 29 deletions.
60 changes: 35 additions & 25 deletions src/oemof/solph/components/_generic_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -238,9 +238,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 = 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

Expand All @@ -257,24 +263,22 @@ def _set_flows(self):
coupled with storage capacity via invest relations
"""
for flow in self.inputs.values():
if (
self.invest_relation_input_capacity 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 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):
"""Raise errors for infeasible investment attribute combinations"""
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"
Expand Down Expand Up @@ -480,7 +484,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 is not None
n
for n in group
if n.invest_relation_input_output[0] is not None
]
)

Expand Down Expand Up @@ -573,7 +579,7 @@ def _power_coupled(_):
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)
Expand Down Expand Up @@ -1164,21 +1170,23 @@ def _create(self, group):
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
]
)

self.INVEST_REL_CAP_OUT = Set(
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
]
)

Expand Down Expand Up @@ -1551,7 +1559,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)
Expand All @@ -1572,7 +1580,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
== self.total[n, p]
* n.invest_relation_input_capacity[p]
)
self.storage_capacity_inflow.add((n, p), expr)

Expand All @@ -1594,7 +1603,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
== self.total[n, p]
* n.invest_relation_output_capacity[p]
)
self.storage_capacity_outflow.add((n, p), expr)

Expand Down
8 changes: 4 additions & 4 deletions tests/test_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit abb1be9

Please sign in to comment.