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

Fix and update HeatPipeine classes / oemof_heatpipe.py #137

Merged
merged 3 commits 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
53 changes: 30 additions & 23 deletions dhnx/optimization/oemof_heatpipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ def __str__(self):

class HeatPipeline(Transformer):
r"""A HeatPipeline represent a Pipeline in a district heating system.

This is done by a Transformer with a constant energy loss independent of
actual power, but dependent on the nominal power and the length parameter.
The HeatPipeline is a single-input-single-output transformer. Additionally,
conversion factors for in- and output flow can be applied.
actual power, but dependent on the nominal power.
The HeatPipeline is a single-input-single-output transformer.

Parameters
----------
Expand Down Expand Up @@ -66,12 +66,23 @@ class HeatPipeline(Transformer):

"""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.heat_loss_factor = sequence(kwargs.get('heat_loss_factor', 0))
self.heat_loss_factor_fix = sequence(kwargs.get(
'heat_loss_factor_fix', 0))
def __init__(
self,
inputs,
outputs,
label=None,
heat_loss_factor=0,
heat_loss_factor_fix=0,
):

self.heat_loss_factor = sequence(heat_loss_factor)
self.heat_loss_factor_fix = sequence(heat_loss_factor_fix)

super().__init__(
inputs=inputs,
outputs=outputs,
label=label,
)

self._invest_group = False
self._nonconvex_group = False
Expand Down Expand Up @@ -178,10 +189,6 @@ class HeatPipelineBlock(ScalarBlock): # pylint: disable=too-many-ancestors
loss of heat pipeline"
":math:`\dot{Q}_{nominal}`", ":py:obj:`flows[n, o].nominal_value`", "
P", "Nominal capacity of heating pipeline"
":math:`\eta_{out}`", ":py:obj:`conversion_factors[o][t]`", "P", "
Conversion factor of output flow (Heat Output)"
":math:`\eta_{in}`", ":py:obj:`conversion_factors[i][t]`", "P", "
Conversion factor of input flow (Heat Input)"
":math:`f_{loss}(t)`", ":py:obj:`heat_loss_factor`", "P", "Specific
heat loss factor for pipeline"
":math:`l`", ":py:obj:`length`", "P", "Length of heating pipeline"
Expand Down Expand Up @@ -262,8 +269,14 @@ def _relation_rule(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

Expand Down Expand Up @@ -300,10 +313,6 @@ class HeatPipelineInvestBlock(ScalarBlock): # pylint: disable=too-many-ancestor
loss of heat pipeline"
":math:`\dot{Q}_{nominal}`", ":py:obj:`flows[n, o].nominal_value`", "
V", "Nominal capacity of heating pipeline"
":math:`\eta_{out}`", ":py:obj:`conversion_factors[o][t]`", "P", "
Conversion factor of output flow (heat output)"
":math:`\eta_{in}`", ":py:obj:`conversion_factors[i][t]`", "P", "
Conversion factor of input flow (heat input)"
":math:`f_{loss}(t)`", ":py:obj:`heat_loss_factor`", "P", "Specific
heat loss factor for pipeline"
":math:`l`", ":py:obj:`length`", "P", "Length of heating pipeline"
Expand Down Expand Up @@ -433,15 +442,13 @@ def _relation_rule_with_demand(block, n, t):
expr = 0
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 += m.flow[i, n, 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 += m.flow[i, n, period, t]
expr += - block.heat_loss[n, t]
expr += - m.flow[n, d, period, t]

Expand Down
Loading