Skip to content

Commit

Permalink
Implement method für adjusting PtH2-Model with multiple_link
Browse files Browse the repository at this point in the history
  • Loading branch information
lenzim97 committed Jan 29, 2025
1 parent 6026180 commit 229a2bd
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
3 changes: 3 additions & 0 deletions etrago/appl.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,9 @@ def run_etrago(args, json_path):
# spatial clustering
etrago.spatial_clustering()
etrago.spatial_clustering_gas()

#adjust_PtH2_model
etrago.adjust_PtH2_model

# snapshot clustering
etrago.snapshot_clustering()
Expand Down
3 changes: 3 additions & 0 deletions etrago/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
set_random_noise,
set_trafo_costs,
update_busmap,
adjust_PtH2_model
)

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -371,6 +372,8 @@ def __init__(
post_contingency_analysis = post_contingency_analysis_lopf

sclopf = iterate_sclopf

adjust_PtH2_model = adjust_PtH2_model

def dc_lines(self):
return self.filter_links_by_carrier("DC", like=False)
Expand Down
87 changes: 87 additions & 0 deletions etrago/tools/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3198,3 +3198,90 @@ def export_to_shapefile(pypsa_network, shape_files_path=None, srid=4326):
v.loc[:, save_cols[k]].to_file(shp_filename)

return components_dict


def adjust_PtH2_model(self):
"""
Adjust the modelling of electrolyzer with waste-heat and
O2-utilisation. The method creates a multiple-link-model
out of the single links from the dataset (power_to_H2-,
PtH2_waste_heat-, PtH2_O2-links) for each location where
coupling-product usage is possible. The resulting model
consists of a multiple link, additional buses and stores for
waste_heat and O2-utilisation, and the connection link to the
final Heat- and O2-Bus.
Parameters
----------
etrago : :class:`Etrago
Overall container of Etrago
Returns
-------
None.
"""
PtH2_links = self.network.links[self.network.links.carrier == "power_to_H2"].index
PtH2_AC_buses = self.network.buses.loc[self.network.links.loc[PtH2_links, "bus0"]].index.unique()

from itertools import count
store_ids = self.network.stores.index
numeric_parts = [int(idx.split()[0]) for idx in store_ids]
next_bus_id = max(self.network.buses.index.astype(int)) + 1
next_store_id = max(numeric_parts) + 1
bus_id_counter = count(start=next_bus_id)
store_id_counter = count(start=next_store_id)

for bus in PtH2_AC_buses:
power_to_h2_links = self.network.links[
(self.network.links.carrier == "power_to_H2") & (self.network.links.bus0 == bus)].index
power_to_heat_links = self.network.links[
(self.network.links.carrier == "PtH2_waste_heat") & (self.network.links.bus0 == bus)].index
power_to_o2_links = self.network.links[
(self.network.links.carrier == "PtH2_O2") & (self.network.links.bus0 == bus)].index

link_data = []
if len(power_to_heat_links) > 0:
link_data.append({"links": power_to_heat_links, "efficiency": 0.2, "carrier": "waste_heat"})
if len(power_to_o2_links) > 0:
link_data.append({"links": power_to_o2_links, "efficiency": 0.015, "carrier": "O2"})

for idx, data in enumerate(link_data, start=2):
links = data["links"]
efficiency = data["efficiency"]
carrier = data["carrier"]
new_bus_id = next(bus_id_counter)
new_store_id = next(store_id_counter)
store_name = f"{new_store_id} PtH2_{carrier}"

# Add new heat/o2-bus and -store
self.network.add("Bus", name=new_bus_id, carrier=f"PtH2_extra_bus_{carrier}")
self.network.add(
"Store",
name=store_name,
bus=new_bus_id,
carrier=f"PtH2_{carrier}",
e_nom_extendable=True,
e_nom=100000,
marginal_cost=0,
capital_cost=0,
e_cyclic=False,
standing_loss=1
)

self.network.stores.loc[store_name, "scn_name"] = self.args["scn_name"]
self.network.buses.loc[str(new_bus_id), "scn_name"] = self.args["scn_name"]
self.network.buses.loc[str(new_bus_id), "country"] = 'DE'

#set coordinates for new bus for the clustering method
bus0_index = self.network.links.loc[power_to_h2_links, "bus0"]
self.network.buses.loc[str(new_bus_id), "x"] = self.network.buses.loc[bus0_index, "x"].values[0]
self.network.buses.loc[str(new_bus_id), "y"] = self.network.buses.loc[bus0_index, "y"].values[0]

#Connect multiple link with new heat/o2-bus
self.network.links.loc[power_to_h2_links, f"bus{idx}"] = str(new_bus_id)
self.network.links.loc[power_to_h2_links, f"efficiency{idx}"] = efficiency

# Adjust originals waste_heat- and oxygen-links with new bus0
for link in links:
self.network.links.loc[link, "bus0"] = str(new_bus_id)

0 comments on commit 229a2bd

Please sign in to comment.