Skip to content

Commit

Permalink
Add first version of grid simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaraBuettner committed Aug 22, 2023
1 parent 7165782 commit 7f4e94c
Showing 1 changed file with 168 additions and 14 deletions.
182 changes: 168 additions & 14 deletions etrago/execute/grid_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import numpy as np
import pandas as pd


logger = logging.getLogger(__name__)

__copyright__ = (
Expand All @@ -40,31 +39,186 @@
"DLR-Institute for Networked Energy Systems"
)
__license__ = "GNU Affero General Public License Version 3 (AGPL-3.0)"
__author__ = (
"ulfmueller, ClaraBuettner, CarlosEpia"
)
__author__ = "ulfmueller, ClaraBuettner, CarlosEpia"


def grid_optimization(self):

add_redispatch_generators(self)

self.network.lopf(
solver_name=self.args["solver"],
solver_options=self.args["solver_options"],
pyomo=True,
extra_functionality=extra_functionality(),
formulation=self.args["model_formulation"],

)
solver_name=self.args["solver"],
solver_options=self.args["solver_options"],
pyomo=True,
extra_functionality=extra_functionality(),
formulation=self.args["model_formulation"],
)


def add_redispatch_generators(self):
"""Add ramp up and ramp down generators
"""Add components and parameters to model redispatch with costs
Returns
-------
None.
"""
pass

# Select generator and link components that are considered in redispatch
# all others can be redispatched without any extra costs
gens_redispatch = self.network.generators[
self.network.generators.carrier.isin(
[
"coal",
"lignite",
"nuclear",
"oil",
"others",
"reservoir",
"run_of_river",
"solar",
"wind_offshore",
"wind_onshore",
"solar_rooftop",
"central_biomass_CHP",
"industrial_biomass_CHP",
"biomass",
]
)
].index

links_redispatch = self.network.links[
self.network.links.carrier.isin(["OCGT"])
].index

# Fix generator dispatch from market simulation
self.network.generators_t.p_max_pu.loc[
:, gens_redispatch
] = self.network.generators_t.p[gens_redispatch].mul(
1 / self.network.generators.p_nom[gens_redispatch]
)

self.network.generators_t.p_min_pu.loc[
:, gens_redispatch
] = self.network.generators_t.p[gens_redispatch].mul(
1 / self.network.generators.p_nom[gens_redispatch]
)

# Fix link dispatch from market simulation
self.network.links_t.p_max_pu.loc[
:, links_redispatch
] = self.network.links_t.p0[links_redispatch].mul(
1 / self.network.links.p_nom[links_redispatch]
)

self.network.links_t.p_min_pu.loc[
:, gens_redispatch
] = self.network.links_t.p0[links_redispatch].mul(
1 / self.network.links.p_nom[links_redispatch]
)

# Calculate costs for redispatch
market_price_per_bus = self.network.buses_t.marginal_price

self.network.generators.loc[gens_redispatch, "marginal_cost"]

market_price_per_generator = market_price_per_bus.loc[
:, self.network.generators.loc[gens_redispatch, "bus"]
].median()
market_price_per_generator.index = gens_redispatch

ramp_up_costs = self.network.generators.loc[
gens_redispatch, "marginal_cost"
]

ramp_up_costs[
market_price_per_generator
> self.network.generators.loc[gens_redispatch, "marginal_cost"]
] = market_price_per_generator

ramp_down_costs = (
market_price_per_generator
- self.network.generators.loc[gens_redispatch, "marginal_cost"]
)

# Add ramp up generators
self.network.madd(
"Generator",
gens_redispatch + " ramp_up",
bus=self.network.generators.loc[gens_redispatch, "bus"].values,
p_nom=self.network.generators.loc[gens_redispatch, "p_nom"].values,
marginal_cost=ramp_up_costs.values + 4,
carrier=self.network.generators.loc[gens_redispatch, "carrier"].values,
)

self.network.generators_t.p_max_pu.loc[:, gens_redispatch + " ramp_up"] = (
(
self.network.generators_t.p_max_pu.loc[:, gens_redispatch].mul(
self.network.generators.loc[gens_redispatch, "p_nom"]
)
- (self.network.generators_t.p.loc[:, gens_redispatch])
)
.clip(lower=0.0)
.values
)

# Add ramp up links
self.network.madd(
"Link",
links_redispatch + " ramp_up",
bus0=self.network.links.loc[links_redispatch, "bus0"].values,
bus1=self.network.links.loc[links_redispatch, "bus1"].values,
p_nom=self.network.links.loc[links_redispatch, "p_nom"].values,
marginal_cost=self.network.links.loc[
links_redispatch, "marginal_cost"
].values
+ 4,
carrier=self.network.links.loc[links_redispatch, "carrier"].values,
)

self.network.links_t.p_max_pu.loc[:, links_redispatch + " ramp_up"] = (
(
self.network.links.loc[links_redispatch, "p_nom"]
- (self.network.links_t.p0.loc[:, links_redispatch])
)
.clip(lower=0.0)
.values
)

# Add ramp down generators
self.network.madd(
"Generator",
gens_redispatch + " ramp_down",
bus=self.network.generators.loc[gens_redispatch, "bus"].values,
p_nom=self.network.generators.loc[gens_redispatch, "p_nom"].values,
marginal_cost=-(ramp_down_costs.values + 4),
carrier=self.network.generators.loc[gens_redispatch, "carrier"].values,
)

self.network.generators_t.p_max_pu.loc[
:, gens_redispatch + " ramp_down"
] = 0

self.network.generators_t.p_min_pu.loc[
:, gens_redispatch + " ramp_down"
] = (-(self.network.generators_t.p.loc[:, gens_redispatch])).values

# Add ramp down links
self.network.madd(
"Link",
links_redispatch + " ramp_down",
bus0=self.network.links.loc[links_redispatch, "bus0"].values,
bus1=self.network.links.loc[links_redispatch, "bus1"].values,
p_nom=self.network.links.loc[links_redispatch, "p_nom"].values,
marginal_cost=-(4),
carrier=self.network.links.loc[links_redispatch, "carrier"].values,
)

self.network.links_t.p_max_pu.loc[:, links_redispatch + " ramp_down"] = 0

self.network.links_t.p_min_pu.loc[:, links_redispatch + " ramp_down"] = (
-(self.network.links_t.p0.loc[:, links_redispatch])
).values


def extra_functionality():
return None

0 comments on commit 7f4e94c

Please sign in to comment.