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

Implement workaround for oemof.solph 0.5.1 compatibility #134

Merged
merged 1 commit into from
Oct 9, 2024
Merged
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
67 changes: 51 additions & 16 deletions dhnx/optimization/oemof_heatpipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,15 @@ def _heat_loss_rule_convex(block, n, t):
"""
expr = 0
expr += - block.heat_loss[n, t]
expr += n.heat_loss_factor[t] * m.InvestmentFlowBlock.invest[
n, list(n.outputs.keys())[0]
]
try: # oemof.solph<=0.5.0
expr += n.heat_loss_factor[t] * m.InvestmentFlowBlock.invest[
n, list(n.outputs.keys())[0],
]
except KeyError: # oemof.solph>=0.5.1
period = 0 # Periods are not (yet) supported in DHNx
expr += n.heat_loss_factor[t] * m.InvestmentFlowBlock.invest[
n, list(n.outputs.keys())[0], period
]
expr += n.heat_loss_factor_fix[t]
return expr == 0
self.heat_loss_equation_convex = Constraint(
Expand All @@ -375,11 +381,19 @@ def _heat_loss_rule_nonconvex(block, n, t):
"""
expr = 0
expr += - block.heat_loss[n, t]
expr += n.heat_loss_factor[t] * m.InvestmentFlowBlock.invest[
n, list(n.outputs.keys())[0]]
expr += n.heat_loss_factor_fix[t] * \
m.InvestmentFlowBlock.invest_status[
try: # oemof.solph<=0.5.0
expr += n.heat_loss_factor[t] * m.InvestmentFlowBlock.invest[
n, list(n.outputs.keys())[0]]
expr += n.heat_loss_factor_fix[t] * \
m.InvestmentFlowBlock.invest_status[
n, list(n.outputs.keys())[0]]
except KeyError: # oemof.solph>=0.5.1
period = 0 # Periods are not (yet) supported in DHNx
expr += n.heat_loss_factor[t] * m.InvestmentFlowBlock.invest[
n, list(n.outputs.keys())[0], period]
expr += n.heat_loss_factor_fix[t] * \
m.InvestmentFlowBlock.invest_status[
n, list(n.outputs.keys())[0], period]
return expr == 0

self.heat_loss_equation_nonconvex = Constraint(
Expand All @@ -393,9 +407,16 @@ def _relation_rule_no_demand(block, n, t):
o = list(n.outputs.keys())[0]

expr = 0
expr += - m.flow[n, o, t]
expr += m.flow[i, n, t]
try: # oemof.solph<=0.5.0
expr += - m.flow[n, o, t]
expr += m.flow[i, n, t]
except KeyError: # oemof.solph>=0.5.1
period = 0 # Periods are not (yet) supported in DHNx
expr += - m.flow[n, o, period, t]
expr += m.flow[i, n, period, t]

expr += - block.heat_loss[n, t]

return expr == 0

self.relation_no_demand = Constraint(
Expand All @@ -410,11 +431,20 @@ def _relation_rule_with_demand(block, n, t):
d = list(n.outputs.keys())[1]

expr = 0
expr += - m.flow[n, o, t]
expr += m.flow[i, n, t] * n.conversion_factors[
o][t] / n.conversion_factors[i][t]
expr += - block.heat_loss[n, t]
expr += - m.flow[n, d, t]
try: # oemof.solph<=0.5.0
expr += - m.flow[n, o, t]
expr += m.flow[i, n, t] * n.conversion_factors[
o][t] / n.conversion_factors[i][t]
expr += - block.heat_loss[n, t]
expr += - m.flow[n, d, t]
except KeyError: # oemof.solph>=0.5.1
period = 0 # Periods are not (yet) supported in DHNx
expr += - m.flow[n, o, period, t]
expr += m.flow[i, n, period, t] * n.conversion_factors[
o][t] / n.conversion_factors[i][t]
expr += - block.heat_loss[n, t]
expr += - m.flow[n, d, period, t]

return expr == 0
self.relation_with_demand = Constraint(
self.INVESTHEATPIPES_WITH_DEMAND, m.TIMESTEPS,
Expand All @@ -429,8 +459,13 @@ def _inflow_outflow_invest_coupling_rule(block, n): # pylint: disable=unused-ar
i = list(n.inputs.keys())[0]
o = list(n.outputs.keys())[0]

expr = (m.InvestmentFlowBlock.invest[i, n]
== m.InvestmentFlowBlock.invest[n, o])
try: # oemof.solph<=0.5.0
expr = (m.InvestmentFlowBlock.invest[i, n]
== m.InvestmentFlowBlock.invest[n, o])
except KeyError: # oemof.solph>=0.5.1
period = 0 # Periods are not (yet) supported in DHNx
expr = (m.InvestmentFlowBlock.invest[i, n, period]
== m.InvestmentFlowBlock.invest[n, o, period])
return expr
self.inflow_outflow_invest_coupling = Constraint(
self.INVESTHEATPIPES, rule=_inflow_outflow_invest_coupling_rule
Expand Down
Loading