powsybl-core
powsybl-core copied to clipboard
Fix network element deep removal
Do you want to request a feature or report a bug? Bug
What is the current behavior? PR #1862 (corresponding to issues #1852 & #1857) introduced the feature of topology cleanup after injection removal, but this only works as one may expect with very simple cases of injections connected to one bus only.
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem
- Create a network and a voltage level with following topology:
- Use Connectable::remove(true) to remove connectable B with topology cleanup
- The result contains switches which are expected to be removed (circled in red):
What is the expected behavior? Circled switches removed
What is the motivation / use case for changing the behavior? Helping the user to remove properly an injection
After discussion with @geofjamg, the following algorithm is proposed when removing a connectable:
- Traverse the voltage level from the corresponding node and remove all the switches (or internal connection) encountered until arriving a) either at a node with more than 2 neighbours: apply step 2. b) or at a bus node, then the traverser should stop
- At nodes with more than 2 neighbours, we need to look how the corresponding neighbouring paths end: a) if one (or more) neighbouring path goes to connectables only (no buses), then the traverser should stop b) else: first remove all neighbouring path ending on one or more buses (no connectables), then stop the traverser if there is more than one remaining path, else continue removing switches on the only remaining path until encountering a node with more than 2 neighbours (which this time stops the traversing)