Skip to content

Commit

Permalink
Add warning if meshes are in the grid
Browse files Browse the repository at this point in the history
  • Loading branch information
joda9 committed Jul 22, 2024
1 parent f2c7f84 commit 9f00fa7
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
28 changes: 28 additions & 0 deletions edisgo/opf/powermodels_opf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import subprocess
import sys

import networkx as nx
import numpy as np

from edisgo.flex_opt import exceptions
Expand All @@ -12,6 +13,32 @@
logger = logging.getLogger(__name__)


def find_meshes(edisgo_obj) -> list:
"""
Find all meshes in the grid.
Parameters
----------
edisgo_obj : :class:`~edisgo.EDisGo`
EDisGo object.
Returns
-------
meshes : list
List of all meshes in the grid.
"""
meshes = nx.cycle_basis(edisgo_obj.to_graph())
if meshes:
logger.warning(
"Grid contains mesh(es). This might cause problems in "
"the power flow or optimisation."
)
return meshes
else:
return None


def pm_optimize(
edisgo_obj,
s_base=1,
Expand Down Expand Up @@ -105,6 +132,7 @@ def pm_optimize(
Default: True.
"""
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
27 changes: 26 additions & 1 deletion tests/opf/test_powermodels_opf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest

from edisgo import EDisGo
from edisgo.opf.powermodels_opf import pm_optimize
from edisgo.opf.powermodels_opf import find_meshes, pm_optimize
from edisgo.tools.tools import aggregate_district_heating_components


Expand Down Expand Up @@ -337,3 +337,28 @@ def test_pm_optimize(self):
)
)
)

def test_find_meshes(self, caplog):
meshes = 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 = 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 = find_meshes(self.edisgo)
assert len(meshes) == 2
assert "Bus_BranchTee_LVGrid_2_3" in meshes[1]
assert (
"Grid contains mesh(es). This might cause problems"
" in the power flow or optimisation." in caplog.text
)

0 comments on commit 9f00fa7

Please sign in to comment.