Skip to content

Commit

Permalink
implemented function for discount rate setting to prevent code duplic…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
lensum committed Jun 26, 2023
1 parent 017f847 commit 9d47b87
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/oemof/solph/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,31 +364,27 @@ def __init__(self, energysystem, discount_rate=None, **kwargs):
not isinstance(energysystem, list)
and energysystem.periods is not None
):
self.discount_rate = 0.02
msg = (
f"By default, a discount_rate of {self.discount_rate} "
f"is used for a multi-period model. "
f"If you want to use another value, "
f"you have to specify the `discount_rate` attribute."
)
warnings.warn(msg, debugging.SuspiciousUsageWarning)
self._set_discount_rate_with_warning()
elif (
isinstance(energysystem, list)
and energysystem[0].periods is not None
):
self.discount_rate = 0.02
msg = (
f"By default, a discount_rate of {self.discount_rate} "
f"is used for a multi-period model. "
f"If you want to use another value, "
f"you have to specify the `discount_rate` attribute."
)
warnings.warn(msg, debugging.SuspiciousUsageWarning)

self._set_discount_rate_with_warning()
else:
pass
super().__init__(energysystem, **kwargs)

def _set_discount_rate_with_warning(self):
"""sets the discount rate to the standard value and raises a warning."""
self.discount_rate = 0.02
msg = (
f"By default, a discount_rate of {self.discount_rate} "
f"is used for a multi-period model. "
f"If you want to use another value, "
f"you have to specify the `discount_rate` attribute."
)
warnings.warn(msg, debugging.SuspiciousUsageWarning)

def _add_parent_block_sets(self):
"""Add all basic sets to the model, i.e. NODES, TIMESTEPS and FLOWS.
Also create sets PERIODS and TIMEINDEX used for multi-period models.
Expand Down

0 comments on commit 9d47b87

Please sign in to comment.