Skip to content

Commit

Permalink
Remove code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
jokochems committed Oct 20, 2023
1 parent 555234b commit c75ecec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
22 changes: 11 additions & 11 deletions src/oemof/solph/components/_generic_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1953,20 +1953,20 @@ def _evaluate_remaining_value_difference(
present_value_factor_remaining = 1 / economics.annuity(
capex=1, n=remaining_lifetime, wacc=interest
)
convex_investment_costs = (
self.invest[n, p]
* (remaining_annuity - original_annuity)
* present_value_factor_remaining
) * (1 + m.discount_rate) ** (-end_year_of_optimization)
if nonconvex:
return (
self.invest[n, p]
* (remaining_annuity - original_annuity)
* present_value_factor_remaining
+ self.invest_status[n, p]
* (n.investment.offset[-1] - n.investment.offset[p])
return convex_investment_costs + self.invest_status[
n, p
] * (
n.investment.offset[-1] -
n.investment.offset[p]
) * (1 + m.discount_rate) ** (-end_year_of_optimization)
else:
return (
self.invest[n, p]
* (remaining_annuity - original_annuity)
* present_value_factor_remaining
) * (1 + m.discount_rate) ** (-end_year_of_optimization)
return convex_investment_costs
else:
return 0
else:
Expand Down
25 changes: 11 additions & 14 deletions src/oemof/solph/flows/_investment_flow_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -1110,23 +1110,20 @@ def _evaluate_remaining_value_difference(
present_value_factor_remaining = 1 / economics.annuity(
capex=1, n=remaining_lifetime, wacc=interest
)
convex_investment_costs = (
self.invest[i, o, p]
* (remaining_annuity - original_annuity)
* present_value_factor_remaining
) * (1 + m.discount_rate) ** (-end_year_of_optimization)
if nonconvex:
return (
self.invest[i, o, p]
* (remaining_annuity - original_annuity)
* present_value_factor_remaining
+ self.invest_status[i, o, p]
* (
m.flows[i, o].investment.offset[-1]
- m.flows[i, o].investment.offset[p]
)
return convex_investment_costs + self.invest_status[
i, o, p
] * (
m.flows[i, o].investment.offset[-1]
- m.flows[i, o].investment.offset[p]
) * (1 + m.discount_rate) ** (-end_year_of_optimization)
else:
return (
self.invest[i, o, p]
* (remaining_annuity - original_annuity)
* present_value_factor_remaining
) * (1 + m.discount_rate) ** (-end_year_of_optimization)
return convex_investment_costs
else:
return 0
else:
Expand Down

0 comments on commit c75ecec

Please sign in to comment.