Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BusResults after security analysis is not exhaustive #603

Merged
merged 5 commits into from
Sep 6, 2023
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
22 changes: 17 additions & 5 deletions src/main/java/com/powsybl/openloadflow/network/impl/LfBusImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
*/
package com.powsybl.openloadflow.network.impl;

import com.powsybl.iidm.network.Bus;
import com.powsybl.iidm.network.Country;
import com.powsybl.iidm.network.Load;
import com.powsybl.iidm.network.Substation;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.extensions.LoadAsymmetrical;
import com.powsybl.iidm.network.extensions.SlackTerminal;
import com.powsybl.openloadflow.network.LfNetwork;
Expand Down Expand Up @@ -43,6 +40,8 @@ public class LfBusImpl extends AbstractLfBus {

private final Country country;

private List<String> bbsIds = null;

protected LfBusImpl(Bus bus, LfNetwork network, double v, double angle, LfNetworkParameters parameters,
boolean participating) {
super(network, v, angle, parameters.isDistributedOnConformLoad());
Expand All @@ -53,6 +52,13 @@ protected LfBusImpl(Bus bus, LfNetwork network, double v, double angle, LfNetwor
this.participating = participating;
this.breakers = parameters.isBreakers();
country = bus.getVoltageLevel().getSubstation().flatMap(Substation::getCountry).orElse(null);
if (bus.getVoltageLevel().getTopologyKind() == TopologyKind.NODE_BREAKER) {
bbsIds = bus.getConnectedTerminalStream()
.map(Terminal::getConnectable)
.filter(BusbarSection.class::isInstance)
.map(Connectable::getId)
.collect(Collectors.toList());
}
}

private static void createAsym(Bus bus, LfBusImpl lfBus) {
Expand Down Expand Up @@ -142,7 +148,13 @@ public boolean isParticipating() {
public List<BusResult> createBusResults() {
var bus = getBus();
if (breakers) {
return List.of(new BusResult(getVoltageLevelId(), bus.getId(), v, Math.toDegrees(angle)));
if (bbsIds.isEmpty()) {
return List.of(new BusResult(getVoltageLevelId(), bus.getId(), v, Math.toDegrees(angle)));
} else {
return bbsIds.stream()
.map(bbsId -> new BusResult(getVoltageLevelId(), bbsId, v, Math.toDegrees(angle)))
.collect(Collectors.toList());
}
} else {
return bus.getVoltageLevel().getBusBreakerView().getBusesFromBusViewBusId(bus.getId())
.stream().map(b -> new BusResult(getVoltageLevelId(), b.getId(), v, Math.toDegrees(angle))).collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void testCurrentLimitViolations() {
assertSame(PostContingencyComputationStatus.CONVERGED, result.getPostContingencyResults().get(1).getStatus());
assertEquals(2, result.getPostContingencyResults().get(1).getLimitViolationsResult().getLimitViolations().size());
PostContingencyResult postContingencyResult = getPostContingencyResult(result, "LD");
assertEquals(398.0, postContingencyResult.getNetworkResult().getBusResult("VL1_0").getV(), LoadFlowAssert.DELTA_V);
assertEquals(398.0, postContingencyResult.getNetworkResult().getBusResult("BBS2").getV(), LoadFlowAssert.DELTA_V);
}

@Test
Expand Down Expand Up @@ -2169,4 +2169,29 @@ void testBusContingency() {
assertEquals(0.0, getPostContingencyResult(result, "NHV2").getNetworkResult().getBranchResult("NGEN_NHV1").getI1(), LoadFlowAssert.DELTA_I);
// No output for NGEN and NVH1
}

@Test
void testBusBarSectionBusResults() {
var network = NodeBreakerNetworkFactory.create3barsAndJustOneVoltageLevel();
List<Contingency> contingencies = List.of(new Contingency("C1", new SwitchContingency("C1")),
new Contingency("C2", new SwitchContingency("C2")));
List<StateMonitor> monitors = createNetworkMonitors(network);
SecurityAnalysisParameters securityAnalysisParameters = new SecurityAnalysisParameters();
OpenLoadFlowParameters openLoadFlowParameters = new OpenLoadFlowParameters();
openLoadFlowParameters.setSlackBusSelectionMode(SlackBusSelectionMode.NAME).setSlackBusId("VL1_1");
securityAnalysisParameters.getLoadFlowParameters().addExtension(OpenLoadFlowParameters.class, openLoadFlowParameters);
SecurityAnalysisResult result = runSecurityAnalysis(network, contingencies, monitors, securityAnalysisParameters, Reporter.NO_OP);
assertEquals(3, result.getPreContingencyResult().getNetworkResult().getBusResults().size());
PreContingencyResult preContingencyResult = result.getPreContingencyResult();
assertEquals("BBS1", preContingencyResult.getNetworkResult().getBusResults().get(0).getBusId());
assertEquals(400.0, preContingencyResult.getNetworkResult().getBusResult("BBS1").getV(), LoadFlowAssert.DELTA_V);
assertEquals("BBS2", preContingencyResult.getNetworkResult().getBusResults().get(1).getBusId());
assertEquals(400.0, preContingencyResult.getNetworkResult().getBusResult("BBS2").getV(), LoadFlowAssert.DELTA_V);
assertEquals("BBS3", preContingencyResult.getNetworkResult().getBusResults().get(2).getBusId());
assertEquals(400.0, preContingencyResult.getNetworkResult().getBusResult("BBS3").getV(), LoadFlowAssert.DELTA_V);
PostContingencyResult postContingencyResult = getPostContingencyResult(result, "C1");
assertNull(postContingencyResult.getNetworkResult().getBusResult("BBS1"));
assertEquals(400.0, postContingencyResult.getNetworkResult().getBusResult("BBS2").getV(), LoadFlowAssert.DELTA_V);
assertEquals(400.0, postContingencyResult.getNetworkResult().getBusResult("BBS3").getV(), LoadFlowAssert.DELTA_V);
}
}
Loading