Skip to content

Commit

Permalink
Reapply "Introduce variable for storage losses"
Browse files Browse the repository at this point in the history
This reverts commit 6dae8bc.
  • Loading branch information
p-snft committed Jul 9, 2024
1 parent 98fef1e commit 170173a
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions src/oemof/solph/components/_generic_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,8 @@ def _storage_content_bound_rule(block, n, t):
self.STORAGES, m.TIMEPOINTS, bounds=_storage_content_bound_rule
)

self.storage_losses = Var(self.STORAGES, m.TIMESTEPS)

# set the initial storage content
# ToDo: More elegant code possible?
for n in group:
Expand All @@ -508,30 +510,37 @@ def _storage_content_bound_rule(block, n, t):

# ************* Constraints ***************************

def _storage_balance_rule(block, n, t):
"""
Rule definition for the storage balance of every storage n and
every timestep.
"""
expr = 0
expr += block.storage_content[n, t + 1]
expr += (
-block.storage_content[n, t]
* (1 - n.loss_rate[t]) ** m.timeincrement[t]
def _storage_losses_rule(block, n, t):
expr = block.storage_content[n, t] * (
n.loss_rate[t] ** m.timeincrement[t]
)
expr += (
n.fixed_losses_relative[t]
* n.nominal_storage_capacity
* m.timeincrement[t]
)
expr += n.fixed_losses_absolute[t] * m.timeincrement[t]

return expr == block.storage_losses[n, t]

self.losses = Constraint(
self.STORAGES, m.TIMESTEPS, rule=_storage_losses_rule
)

def _storage_balance_rule(block, n, t):
"""
Rule definition for the storage balance of every storage n and
every timestep.
"""
expr = block.storage_content[n, t]
expr -= block.storage_losses[n, t]
expr += (
-m.flow[i[n], n, t] * n.inflow_conversion_factor[t]
m.flow[i[n], n, t] * n.inflow_conversion_factor[t]
) * m.timeincrement[t]
expr += (
expr -= (
m.flow[n, o[n], t] / n.outflow_conversion_factor[t]
) * m.timeincrement[t]
return expr == 0
return expr == block.storage_content[n, t + 1]

self.balance = Constraint(
self.STORAGES, m.TIMESTEPS, rule=_storage_balance_rule
Expand Down

0 comments on commit 170173a

Please sign in to comment.