Skip to content

Commit

Permalink
Add constraint to limit redispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaraBuettner committed Feb 9, 2024
1 parent bcc3f84 commit 6a78627
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions etrago/tools/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,57 @@ def _rule(m):

network.model.min_renewable_share = Constraint(rule=_rule)

def _max_redispatch(self, network, snapshots):
"""
Extra-functionality that limits the maximum usage of redispatch.
Add key 'max_redispatc' and maximual amount of redispatch in MWh
to args.extra_functionality.
Parameters
----------
network : :class:`pypsa.Network
Overall container of PyPSA
snapshots : pandas.DatetimeIndex
List of timesteps considered in the optimization
Returns
-------
None.
"""

ramp_up = list(
network.generators.index[
network.generators.index.str.contains("ramp_up")]
)
ramp_up_links = list(
network.links.index[
network.links.index.str.contains("ramp_up")]
)

def _rule(m):
redispatch_gens = sum(
m.generator_p[gen, sn] * network.snapshot_weightings.generators[sn]
for gen in ramp_up
for sn in snapshots
)
redispatch_links = sum(
m.links_p[gen, sn]
* network.links.loc[ramp_up_links, "efficiency"]
* network.snapshot_weightings.generators[sn]
for gen in ramp_up_links
for sn in snapshots
)
return (
sum(redispatch_gens, redispatch_links)
<= self.args["extra_functionality"]["max_redispatch"]
)

if len(ramp_up) > 0 or len(ramp_up_links)>0:
network.model.max_redispatch = Constraint(rule=_rule)
else:
print("""Constraint max_redispatch was not added,
there are no redispatch generators or links.""")

def _cross_border_flow(self, network, snapshots):
"""
Expand Down

0 comments on commit 6a78627

Please sign in to comment.