Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/power_grid_model_ds/_core/model/grids/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def delete_branch(self, branch: BranchArray) -> None:
Args:
branch (BranchArray): The branch to remove
"""
_add_branch_array(branch=branch, grid=self)
_delete_branch_array(branch=branch, grid=self)
self.graphs.delete_branch(branch=branch)
logging.debug(
f"""deleted branch {branch.id.item()} from {branch.from_node.item()} to {branch.to_node.item()}"""
Expand All @@ -233,7 +233,7 @@ def delete_branch3(self, branch: Branch3Array) -> None:
Args:
branch (Branch3Array): The branch3 to remove
"""
_add_branch_array(branch=branch, grid=self)
_delete_branch_array(branch=branch, grid=self)
self.graphs.delete_branch3(branch=branch)

def add_node(self, node: NodeArray) -> None:
Expand Down Expand Up @@ -459,8 +459,8 @@ def from_extended(cls, extended: "Grid") -> "Grid":
return new_grid


def _add_branch_array(branch: BranchArray | Branch3Array, grid: Grid):
"""Add a branch array to the grid"""
def _delete_branch_array(branch: BranchArray | Branch3Array, grid: Grid):
"""Delete a branch array from the grid"""
array_field = grid.find_array_field(branch.__class__)
array_attr = getattr(grid, array_field.name)
setattr(grid, array_field.name, array_attr.exclude(id=branch.id))
Expand Down
37 changes: 37 additions & 0 deletions tests/unit/model/grids/test_grid_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
LineArray,
LinkArray,
NodeArray,
ThreeWindingTransformerArray,
TransformerArray,
TransformerTapRegulatorArray,
)
Expand Down Expand Up @@ -227,6 +228,42 @@ def test_grid_delete_tranformer(basic_grid: Grid):
assert not grid.graphs.complete_graph.has_branch(transformer.from_node.item(), transformer.to_node.item())


def test_grid_add_three_winding_transformer():
grid = Grid.empty()
nodes = NodeArray.zeros(3)
nodes.id = [102, 103, 104]
grid.append(nodes)

three_winding_transformer = ThreeWindingTransformerArray.zeros(1)
three_winding_transformer.node_1 = 102
three_winding_transformer.node_2 = 103
three_winding_transformer.node_3 = 104
three_winding_transformer.status_1 = 1
three_winding_transformer.status_2 = 1
three_winding_transformer.status_3 = 1
grid.append(three_winding_transformer)

assert 1 == len(grid.three_winding_transformer)
assert grid.graphs.active_graph.has_branch(102, 103)
assert grid.graphs.active_graph.has_branch(102, 104)
assert grid.graphs.active_graph.has_branch(103, 104)


def test_grid_delete_three_winding_transformer(grid_with_3wt: Grid):
grid = grid_with_3wt
assert grid.graphs.active_graph.has_branch(101, 102)
assert grid.graphs.active_graph.has_branch(101, 103)
assert grid.graphs.active_graph.has_branch(102, 103)

grid.delete_branch3(branch=grid.three_winding_transformer[0])

assert 0 == len(grid.three_winding_transformer)

assert not grid.graphs.active_graph.has_branch(101, 102)
assert not grid.graphs.active_graph.has_branch(101, 103)
assert not grid.graphs.active_graph.has_branch(102, 103)


def test_grid_activate_branch(basic_grid: Grid):
grid = basic_grid

Expand Down
3 changes: 2 additions & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading