Skip to content

Commit

Permalink
Add improvements from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
jokochems committed Aug 7, 2023
1 parent 0db730b commit 670ccbd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
21 changes: 9 additions & 12 deletions src/oemof/solph/components/_generic_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1032,21 +1032,20 @@ def _create(self, group=None):
# ########################## CHECKS ###################################
if m.es.periods is not None:
for n in group:
error = (
error_fixed_absolute_losses = (
"For a multi-period investment model, fixed absolute"
" losses are not supported. Please remove parameter."
)
if n.fixed_losses_absolute.default != 0:
raise ValueError(error)
warning = (
raise ValueError(error_fixed_absolute_losses)
error_initial_storage_level = (
"For a multi-period model, initial_storage_level is"
" not supported.\nIt is suggested to remove that"
" parameter since it has no effect.\nstorage_content"
" will be zero, until there is some usable storage "
" capacity installed."
" not supported.\nIt needs to be removed since it"
" has no effect.\nstorage_content will be zero,"
" until there is some usable storage capacity installed."
)
if n.initial_storage_level is not None:
warn(warning, debugging.SuspiciousUsageWarning)
raise ValueError(error_initial_storage_level)

# ########################## SETS #####################################

Expand Down Expand Up @@ -1315,10 +1314,8 @@ def _old_storage_capacity_rule(block):
def _initially_empty_rule(block):
"""Ensure storage to be empty initially"""
for n in self.INVESTSTORAGES:
for t in m.TIMESTEPS:
if t == 0:
expr = self.storage_content[n, 0] == 0
self.initially_empty.add((n, t), expr)
expr = self.storage_content[n, 0] == 0
self.initially_empty.add((n, 0), expr)

self.initially_empty = Constraint(
self.INVESTSTORAGES, m.TIMESTEPS, noruleinit=True
Expand Down
13 changes: 5 additions & 8 deletions tests/multi_period_constraint_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,6 @@ def test_storage_invest_2(self):
investment=solph.Investment(
ep_costs=145, lifetime=20, existing=20, age=19
),
initial_storage_level=0.5,
)
self.energysystem.add(bel, storage)
self.compare_lp_files("storage_invest_2_multi_period.lp")
Expand Down Expand Up @@ -612,7 +611,7 @@ def test_storage_invest_1_fixed_losses(self):
self.get_om()

def test_storage_invest_1_initial_storage_level(self):
"""Test warning for initial storage level
"""Test error for initial storage level
with multi-period investments"""
bel = solph.buses.Bus(label="electricityBus")
storage = solph.components.GenericStorage(
Expand Down Expand Up @@ -642,14 +641,12 @@ def test_storage_invest_1_initial_storage_level(self):
self.energysystem.add(bel, storage)
msg = (
"For a multi-period model, initial_storage_level is"
" not supported.\nIt is suggested to remove that"
" parameter since it has no effect.\nstorage_content"
" will be zero, until there is some usable storage "
" capacity installed."
" not supported.\nIt needs to be removed since it"
" has no effect.\nstorage_content will be zero,"
" until there is some usable storage capacity installed."
)
with warnings.catch_warnings(record=True) as w:
with pytest.raises(ValueError, match=msg):
self.get_om()
assert msg in str(w[1].message)

def test_storage_invest_1_missing_lifetime(self):
"""Test error thrown if storage misses necessary lifetime"""
Expand Down

0 comments on commit 670ccbd

Please sign in to comment.