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

CGMES export: fix missing breaker #2840

Merged
merged 5 commits into from
Jan 18, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,6 @@ public boolean isExportedEquipment(Identifiable<?> c) {
boolean ignored = c.isFictitious() &&
(c instanceof Load
|| c instanceof Switch && "true".equals(c.getProperty(Conversion.PROPERTY_IS_CREATED_FOR_DISCONNECTED_TERMINAL)));
if (c instanceof Switch ss) {
VoltageLevel.BusBreakerView view = ss.getVoltageLevel().getBusBreakerView();
if (ss.isRetained() && view.getBus1(ss.getId()).equals(view.getBus2(ss.getId()))) {
ignored = true;
}
}
return !ignored;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
import com.powsybl.cgmes.conformity.CgmesConformity1ModifiedCatalog;
import com.powsybl.cgmes.conversion.CgmesImport;
import com.powsybl.cgmes.model.CgmesNamespace;
import com.powsybl.commons.datasource.FileDataSource;
import com.powsybl.commons.test.AbstractSerDeTest;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.SwitchKind;
import com.powsybl.iidm.network.TopologyKind;
import com.powsybl.iidm.network.VoltageLevel;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -23,6 +26,7 @@
import java.util.Properties;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

/**
* @author Luma Zamarreño {@literal <zamarrenolm at aia.es>}
Expand Down Expand Up @@ -74,6 +78,36 @@ void testSwitchTypePreservedNodeBreaker() {
assertEquals("#_" + switchId, switchIdSsh);
}

@Test
void testExportRetainedSwitchWithSameBusBreakerBusAtBothEnds() {
// We create a network where a retained breaker has the same bus-breaker buses at both ends
// After #2574, a breaker with these characteristics was not exported to CGMES
// It may happen in some double bar configurations where lines (or other equipment) may be connected to both bars
// and there is also a retained coupler
Network n = Network.create("retained-breaker-between-busbar-sections", "manual");
VoltageLevel vl = n.newVoltageLevel().setId("vl").setName("vl").setTopologyKind(TopologyKind.NODE_BREAKER).setNominalV(10).add();
VoltageLevel.NodeBreakerView nb = vl.getNodeBreakerView();
nb.newBusbarSection().setId("bbs1").setNode(1).add();
nb.newBusbarSection().setId("bbs2").setNode(2).add();
nb.newSwitch().setId("coupler").setName("coupler").setNode1(1).setNode2(2).setKind(SwitchKind.BREAKER).setRetained(true).add();
vl.newLoad().setId("load").setName("load").setNode(3)
.setP0(10).setQ0(0).add();
vl.newGenerator().setId("gen").setName("gen").setNode(4)
.setTargetP(10).setTargetV(10).setMinP(0).setMaxP(100).setVoltageRegulatorOn(true).add();
nb.newSwitch().setId("load-bk").setName("load-bk").setNode1(3).setNode2(31).setKind(SwitchKind.BREAKER).add();
nb.newSwitch().setId("load-dis1").setName("load-dis1").setNode1(31).setNode2(1).setKind(SwitchKind.DISCONNECTOR).add();
nb.newSwitch().setId("load-dis2").setName("load-dis2").setNode1(31).setNode2(2).setKind(SwitchKind.DISCONNECTOR).add();
nb.newSwitch().setId("gen-bk").setName("gen-bk").setNode1(4).setNode2(41).setKind(SwitchKind.BREAKER).add();
nb.newSwitch().setId("gen-dis1").setName("gen-dis1").setNode1(41).setNode2(1).setKind(SwitchKind.DISCONNECTOR).add();
nb.newSwitch().setId("gen-dis2").setName("gen-dis2").setNode1(41).setNode2(2).setKind(SwitchKind.DISCONNECTOR).add();

// Check that the coupler is preserved when exported to CGMES
String basename = n.getNameOrId();
n.write("CGMES", null, tmpDir.resolve(basename));
Network n1 = Network.read(new FileDataSource(tmpDir, basename));
assertNotNull(n1.getSwitch("coupler"));
}

private static String readId(String elementName, String rdfIdAttrName, Path ssh) {
String id;
try (InputStream is = Files.newInputStream(ssh)) {
Expand Down