powsybl / powsybl-core

A framework to build power system oriented software
https://www.powsybl.org
Mozilla Public License 2.0
124 stars 40 forks source link

terminal adder missing node/connectablebus: take voltagelevel topology into account to give the correct error message #3106

Open jonenst opened 2 months ago

jonenst commented 2 months ago

Describe the current behavior

VoltageLevel s1vl1 = s1.newVoltageLevel()
            .setTopologyKind(TopologyKind.NODE_BREAKER)
s1vl1.newLoad().setId("load1").setP0(10.).setQ0(1.).add();

errors with

Exception in thread "main" com.powsybl.iidm.network.ValidationException: Load 'load1': connectable bus is not set
    at com.powsybl.iidm.network.impl.TerminalBuilder.build(TerminalBuilder.java:65)
    at com.powsybl.iidm.network.impl.AbstractInjectionAdder.checkAndGetTerminal(AbstractInjectionAdder.java:55)
    at com.powsybl.iidm.network.impl.LoadAdderImpl.add(LoadAdderImpl.java:71)
    at com.powsybl.iidm.network.impl.LoadAdderImpl.add(LoadAdderImpl.java:16)

should be Load 'load1': node is not set

In this line we use node == null to differentiate between busterminal and nodeterminal but we should use the voltage level topology instead https://github.com/powsybl/powsybl-core/blob/49bcb7643f01f9c979f0dfc662a0476fd1193ea7/iidm/iidm-impl/src/main/java/com/powsybl/iidm/network/impl/TerminalBuilder.java#L65

NOTE: if you use the wrong node/connectablebus, you do get an exception just after:

 com.powsybl.iidm.network.ValidationException: Load 'load1': voltage level S1VL1 has a node/breaker topology, a node connection should be specified instead of a bus connection
    at com.powsybl.iidm.network.impl.NodeBreakerVoltageLevel.checkTerminal(NodeBreakerVoltageLevel.java:1109)
    at com.powsybl.iidm.network.impl.NodeBreakerVoltageLevel.attach(NodeBreakerVoltageLevel.java:1125)
    at com.powsybl.iidm.network.impl.LoadAdderImpl.add(LoadAdderImpl.java:80)
    at com.powsybl.iidm.network.impl.LoadAdderImpl.add(LoadAdderImpl.java:16)

Describe the expected behavior

get the correct exception the first time

Describe the motivation

simplicity

Extra Information

No response