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

Make invest relations iterable #1063

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
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
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 @@ -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 = 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 @@ -256,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 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):
Expand All @@ -278,9 +282,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"
Expand Down Expand Up @@ -483,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 is not None
n
for n in group
if n.invest_relation_input_output[0] is not None
]
)

Expand Down Expand Up @@ -567,7 +573,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 Down Expand Up @@ -1161,21 +1167,23 @@ 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
]
)

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 @@ -1577,7 +1585,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 @@ -1598,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
== self.total[n, p]
* n.invest_relation_input_capacity[p]
)
self.storage_capacity_inflow.add((n, p), expr)

Expand All @@ -1620,7 +1629,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
Loading