Skip to content

Commit

Permalink
Merge pull request #417 from openego/featur/#382-add-check-in-topolog…
Browse files Browse the repository at this point in the history
…y-whether-grid-contains-mesh

Featur/#382 add check in topology whether grid contains mesh
  • Loading branch information
birgits authored Aug 21, 2024
2 parents 16cdeb7 + fc52d08 commit 751004e
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 10 deletions.
31 changes: 31 additions & 0 deletions edisgo/network/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -3135,6 +3135,9 @@ def check_integrity(self):
f"optimisation."
)

# check for meshed grid
self.find_meshes()

def assign_feeders(self, mode: str = "grid_feeder"):
"""
Assigns MV or LV feeder to each bus and line, depending on the `mode`.
Expand Down Expand Up @@ -3203,3 +3206,31 @@ def aggregate_lv_grid_at_station(self, lv_grid_id: int | str) -> None:

def __repr__(self):
return f"Network topology {self.id}"

def find_meshes(edisgo_obj) -> list[list[int]] | None:
"""
Find all meshes in the grid.
Parameters
----------
edisgo_obj : EDisGo
EDisGo object.
Returns
-------
Optional[List[List[int]]]
List of all meshes in the grid.
Each mesh is represented as a list of node indices.
If no meshes are found, None is returned.
"""
meshes = nx.cycle_basis(edisgo_obj.to_graph())
if meshes:
logger.warning(
"Grid contains mesh(es). Be aware, that the grid expansion methodology "
"is currently not able to handle meshes. Further, the optimisation of "
"flexibility dispatch is not exact in case of meshed grids, but can "
"still be used."
)
return meshes
else:
return None
24 changes: 14 additions & 10 deletions edisgo/opf/powermodels_opf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,29 @@
import subprocess
import sys

from typing import Optional

import numpy as np

from edisgo.flex_opt import exceptions
from edisgo.io.powermodels_io import from_powermodels
from edisgo.network.topology import Topology

logger = logging.getLogger(__name__)


def pm_optimize(
edisgo_obj,
s_base=1,
flexible_cps=None,
flexible_hps=None,
flexible_loads=None,
flexible_storage_units=None,
opf_version=1,
method="soc",
warm_start=False,
silence_moi=False,
):
s_base: int = 1,
flexible_cps: Optional[np.ndarray] = None,
flexible_hps: Optional[np.ndarray] = None,
flexible_loads: Optional[np.ndarray] = None,
flexible_storage_units: Optional[np.ndarray] = None,
opf_version: int = 1,
method: str = "soc",
warm_start: bool = False,
silence_moi: bool = False,
) -> None:
"""
Run OPF for edisgo object in julia subprocess and write results of OPF to edisgo
object. Results of OPF are time series of operation schedules of flexibilities.
Expand Down Expand Up @@ -105,6 +108,7 @@ def pm_optimize(
Default: True.
"""
Topology.find_meshes(edisgo_obj)
opf_dir = os.path.dirname(os.path.abspath(__file__))
solution_dir = os.path.join(opf_dir, "opf_solutions")
pm, hv_flex_dict = edisgo_obj.to_powermodels(
Expand Down
22 changes: 22 additions & 0 deletions tests/network/test_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -1928,3 +1928,25 @@ def test_check_integrity(self, caplog):
assert "There are lines with very short line lengths" in caplog.text
assert "Very small values for impedance of lines" and line in caplog.text
caplog.clear()

def test_find_meshes(self, caplog: pytest.LogCaptureFixture):
meshes = Topology.find_meshes(self.edisgo)
assert not meshes
self.edisgo.topology.add_line(
"Bus_GeneratorFluctuating_2",
"Bus_GeneratorFluctuating_6",
0.1,
x=0.1,
r=0.1,
)
meshes = Topology.find_meshes(self.edisgo)
assert len(meshes) == 1
assert "Bus_GeneratorFluctuating_2" in meshes[0]
assert "Bus_GeneratorFluctuating_6" in meshes[0]
self.edisgo.topology.add_line(
"Bus_BranchTee_LVGrid_2_3", "Bus_BranchTee_LVGrid_3_3", 0.1, x=0.1, r=0.1
)
meshes = Topology.find_meshes(self.edisgo)
assert len(meshes) == 2
assert "Bus_BranchTee_LVGrid_2_3" in meshes[1]
assert "Grid contains mesh(es)." in caplog.text

0 comments on commit 751004e

Please sign in to comment.