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

Rename dangling line ucteXnodeCode to pairingKey #2676

Merged
merged 10 commits into from
Sep 21, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ public static StringToIntMapper<AmplSubset> createMapper(Network network) {
}

static String getXnodeBusId(TieLine tieLine) {
return tieLine.getUcteXnodeCode();
return tieLine.getPairingKey();
}

static String getXnodeVoltageLevelId(TieLine tieLine) {
return tieLine.getUcteXnodeCode();
return tieLine.getPairingKey();
}

public static void fillMapper(StringToIntMapper<AmplSubset> mapper, Network network) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private static Network microBE(String modelId) {
.setX(69.0)
.setG(5.75e-5)
.setB(2.1677e-5)
.setUcteXnodeCode("TN_Border_ST24")
.setPairingKey("TN_Border_ST24")
.add();
be7.newCurrentLimits().setPermanentLimit(1180)
.beginTemporaryLimit()
Expand All @@ -144,7 +144,7 @@ private static Network microBE(String modelId) {
.setX(68.2)
.setG(3.08e-5)
.setB(8.2938E-5)
.setUcteXnodeCode("TN_Border_ST23")
.setPairingKey("TN_Border_ST23")
.add();

Bus busBrussels225 = vlBrussels225.getBusBreakerView().newBus()
Expand Down Expand Up @@ -212,7 +212,7 @@ private static Network microBE(String modelId) {
.setX(12.0)
.setG(6e-5)
.setB(1.49854e-4)
.setUcteXnodeCode("TN_Border_AL11")
.setPairingKey("TN_Border_AL11")
.add();
be3.newCurrentLimits().setPermanentLimit(1371)
.beginTemporaryLimit()
Expand All @@ -238,7 +238,7 @@ private static Network microBE(String modelId) {
.setX(6.3)
.setG(4.2e-5)
.setB(6.59734E-5)
.setUcteXnodeCode("TN_Border_GY11")
.setPairingKey("TN_Border_GY11")
.add();
be5.newCurrentLimits().setPermanentLimit(1804)
.beginTemporaryLimit()
Expand All @@ -264,7 +264,7 @@ private static Network microBE(String modelId) {
.setX(2.0)
.setG(4e-5)
.setB(2.51956e-5)
.setUcteXnodeCode("TN_Border_MA11")
.setPairingKey("TN_Border_MA11")
.add();
be4.newCurrentLimits().setPermanentLimit(1226)
.beginTemporaryLimit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,6 @@ private static DanglingLineAdder getDanglingLineAdder(Context context, String bo
.setX(boundaryLine.getX())
.setG(boundaryLine.getG1() + boundaryLine.getG2())
.setB(boundaryLine.getB1() + boundaryLine.getB2())
.setUcteXnodeCode(findUcteXnodeCode(context, boundaryNode));
.setPairingKey(findPairingKey(context, boundaryNode));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ protected AbstractConductingEquipmentConversion(
steadyStatePowerFlow = PowerFlow.UNDEFINED;
}

public String findUcteXnodeCode(String boundaryNode) {
return findUcteXnodeCode(context, boundaryNode);
public String findPairingKey(String boundaryNode) {
return findPairingKey(context, boundaryNode);
}

public static String findUcteXnodeCode(Context context, String boundaryNode) {
public static String findPairingKey(Context context, String boundaryNode) {
return context.boundary().nameAtBoundary(boundaryNode);
}

Expand Down Expand Up @@ -232,7 +232,7 @@ public void convertToDanglingLine(int boundarySide, double r, double x, double g
.setX(x)
.setG(gch)
.setB(bch)
.setUcteXnodeCode(findUcteXnodeCode(boundaryNode)))
.setPairingKey(findPairingKey(boundaryNode)))
.orElseThrow(() -> new CgmesModelException("Dangling line " + id + " has no container"));
identify(dlAdder);
connect(dlAdder, modelSide);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ private static String writeDanglingLineConnectivity(DanglingLine danglingLine, S
// If no information about original boundary has been preserved in the IIDM model,
// we create a new ConnectivityNode in a fictitious Substation and Voltage Level
LOG.info("Dangling line {}{} is not connected to a connectivity node in boundaries files: a fictitious substation and voltage level are created",
danglingLine.getId(), danglingLine.getUcteXnodeCode() != null ? " linked to X-node " + danglingLine.getUcteXnodeCode() : "");
danglingLine.getId(), danglingLine.getPairingKey() != null ? " linked to X-node " + danglingLine.getPairingKey() : "");
connectivityNodeId = CgmesExportUtil.getUniqueId();
String connectivityNodeContainerId = createFictitiousContainerFor(danglingLine, baseVoltageId, cimNamespace, writer, context);
ConnectivityNodeEq.write(connectivityNodeId, danglingLine.getNameOrId() + "_NODE", connectivityNodeContainerId, cimNamespace, writer, context);
Expand All @@ -875,7 +875,7 @@ private static String writeDanglingLineConnectivity(DanglingLine danglingLine, S
if (danglingLine.getProperty(Conversion.CGMES_PREFIX_ALIAS_PROPERTIES + CgmesNames.TOPOLOGICAL_NODE_BOUNDARY) == null) {
// Also create a container if we will have to create a Topological Node for the boundary
LOG.info("Dangling line {}{} is not connected to a topology node in boundaries files: a fictitious substation and voltage level are created",
danglingLine.getId(), danglingLine.getUcteXnodeCode() != null ? " linked to X-node " + danglingLine.getUcteXnodeCode() : "");
danglingLine.getId(), danglingLine.getPairingKey() != null ? " linked to X-node " + danglingLine.getPairingKey() : "");
createFictitiousContainerFor(danglingLine, baseVoltageId, cimNamespace, writer, context);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ private static void writeDanglingLineTopologicalNodes(Network network, String ci
// As a last resort, we create the TN in the same container of the dangling line
LOG.error("Dangling line {}{} is not connected to a topology node in boundaries files: EQ profile must be exported for consistent results." +
" Dangling line {} is considered entirely inside voltage level {}",
dl.getId(), dl.getUcteXnodeCode() != null ? " linked to X-node " + dl.getUcteXnodeCode() : "", dl.getId(), dl.getTerminal().getVoltageLevel().getId());
dl.getId(), dl.getPairingKey() != null ? " linked to X-node " + dl.getPairingKey() : "", dl.getId(), dl.getTerminal().getVoltageLevel().getId());
containerId = context.getNamingStrategy().getCgmesId(dl.getTerminal().getVoltageLevel());
}
String fictTopologicalNodeId = CgmesExportUtil.getUniqueId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ private void compareDanglingLines(DanglingLine expected, DanglingLine actual) {
compare("b", expected.getB(), actual.getB());
compare("p0", expected.getP0(), actual.getP0());
compare("q0", expected.getQ0(), actual.getQ0());
compare("UcteXnodeCode", expected.getUcteXnodeCode(), actual.getUcteXnodeCode());
compare("pairingKey", expected.getPairingKey(), actual.getPairingKey());
compareLoadingLimits(expected, actual,
expected.getActivePowerLimits().orElse(null),
actual.getActivePowerLimits().orElse(null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<iidm:busBreakerTopology>
<iidm:bus id="NHV1" v="402.1428451538086" angle="0.0"/>
</iidm:busBreakerTopology>
<iidm:danglingLine id="NHV1_XNODE1" p0="0.0" q0="0.0" r="1.5" x="20.0" g="1.0E-6" b="1.93E-4" ucteXnodeCode="XNODE1" bus="NHV1" connectableBus="NHV1" p="302.4440612792969" q="98.74027252197266"/>
<iidm:danglingLine id="NVH1_XNODE2" p0="0.0" q0="0.0" r="1.5" x="20.0" g="1.0E-6" b="1.93E-4" ucteXnodeCode="XNODE2" bus="NHV1" connectableBus="NHV1" p="302.4440612792969" q="98.74027252197266"/>
<iidm:danglingLine id="NHV1_XNODE1" p0="0.0" q0="0.0" r="1.5" x="20.0" g="1.0E-6" b="1.93E-4" pairingKey="XNODE1" bus="NHV1" connectableBus="NHV1" p="302.4440612792969" q="98.74027252197266"/>
<iidm:danglingLine id="NVH1_XNODE2" p0="0.0" q0="0.0" r="1.5" x="20.0" g="1.0E-6" b="1.93E-4" pairingKey="XNODE2" bus="NHV1" connectableBus="NHV1" p="302.4440612792969" q="98.74027252197266"/>
</iidm:voltageLevel>
<iidm:twoWindingsTransformer id="NGEN_NHV1" r="0.26658461538461536" x="11.104492831516762" g="0.0" b="0.0" ratedU1="24.0" ratedU2="400.0" bus1="NGEN" connectableBus1="NGEN" voltageLevelId1="VLGEN" bus2="NHV1" connectableBus2="NHV1" voltageLevelId2="VLHV1" p1="605.558349609375" q1="225.2825164794922" p2="-604.8909301757812" q2="-197.48046875"/>
</iidm:substation>
Expand All @@ -23,8 +23,8 @@
<iidm:busBreakerTopology>
<iidm:bus id="NHV2" v="389.9526763916016" angle="-3.5063576698303223"/>
</iidm:busBreakerTopology>
<iidm:danglingLine id="XNODE1_NHV2" p0="0.0" q0="0.0" r="1.5" x="13.0" g="2.0E-6" b="1.93E-4" ucteXnodeCode="XNODE1" bus="NHV2" connectableBus="NHV2" p="-300.43389892578125" q="-137.18849182128906"/>
<iidm:danglingLine id="XNODE2_NHV2" p0="0.0" q0="0.0" r="1.5" x="13.0" g="2.0E-6" b="1.93E-4" ucteXnodeCode="XNODE2" bus="NHV2" connectableBus="NHV2" p="-300.43389892578125" q="-137.18849182128906"/>
<iidm:danglingLine id="XNODE1_NHV2" p0="0.0" q0="0.0" r="1.5" x="13.0" g="2.0E-6" b="1.93E-4" pairingKey="XNODE1" bus="NHV2" connectableBus="NHV2" p="-300.43389892578125" q="-137.18849182128906"/>
<iidm:danglingLine id="XNODE2_NHV2" p0="0.0" q0="0.0" r="1.5" x="13.0" g="2.0E-6" b="1.93E-4" pairingKey="XNODE2" bus="NHV2" connectableBus="NHV2" p="-300.43389892578125" q="-137.18849182128906"/>
</iidm:voltageLevel>
<iidm:voltageLevel id="VLLOAD" nominalV="150.0" topologyKind="BUS_BREAKER">
<iidm:busBreakerTopology>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@
* <td style="border: 1px solid black">The shunt susceptance</td>
* </tr>
* <tr>
* <td style="border: 1px solid black">UcteXnodeCode</td>
* <td style="border: 1px solid black">PairingKey</td>
* <td style="border: 1px solid black">String</td>
* <td style="border: 1px solid black"> - </td>
* <td style="border: 1px solid black">no</td>
* <td style="border: 1px solid black"> - </td>
* <td style="border: 1px solid black">The dangling line's UCTE Xnode code</td>
* <td style="border: 1px solid black">The dangling line's pairing key</td>
* </tr>
* </tbody>
* </table>
Expand Down Expand Up @@ -274,10 +274,10 @@ default Generation getGeneration() {
}

/**
* Get the UCTE Xnode code corresponding to this dangling line in the case
* Get the pairing key corresponding to this dangling line in the case
* where the line is a boundary, return null otherwise.
*/
String getUcteXnodeCode();
String getPairingKey();

Boundary getBoundary();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ interface GenerationAdder {

DanglingLineAdder setB(double b);

DanglingLineAdder setUcteXnodeCode(String ucteXnodeCode);
DanglingLineAdder setPairingKey(String pairingKey);

default GenerationAdder newGeneration() {
throw new UnsupportedOperationException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
* </table>
*
* <p>
* A tie line is created by matching two {@link DanglingLine} with the same Xnode code. <br>
* A tie line is created by matching two {@link DanglingLine} with the same pairing key. <br>
* We have two Dangling Lines within the Tie Line. <br>
* </p>
*
Expand All @@ -91,10 +91,10 @@
public interface TieLine extends Branch<TieLine>, LineCharacteristics {

/**
* Get the UCTE Xnode code corresponding to this tie line in the case where the
* Get the pairing key corresponding to this tie line in the case where the
* line is a boundary, return null otherwise.
*/
String getUcteXnodeCode();
String getPairingKey();

/**
* Get first dangling line of this tie line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.stream.Collectors;

import static com.powsybl.iidm.network.util.TieLineReports.*;

Expand Down Expand Up @@ -157,41 +158,44 @@ public static void mergeDifferentAliases(DanglingLine dl1, DanglingLine dl2, Map
/**
* If it exists, find the dangling line in the merging network that should be associated to a candidate dangling line in the network to be merged.
* Two dangling lines in different IGM should be associated if:
* - they have the same non-null X-node code and are the only dangling lines to have this X-node code in their respective networks
* - they have the same ID and at least one has a non-null pairing key
So-Fras marked this conversation as resolved.
Show resolved Hide resolved
* OR
* - they have the same non-null X-node code and are the only connected dangling lines to have this X-node code in their respective networks
* - they have the same non-null pairing key and are the only dangling lines to have this pairing key in their respective networks
* OR
* - they have the same non-null pairing key and are the only connected dangling lines to have this pairing key in their respective networks
*
* @param candidateDanglingLine candidate dangling line in the network to be merged
* @param getDanglingLinesByXnodeCode function to retrieve dangling lines with a given X-node code in the merging network.
* @param danglingLine dangling line in the merging network with same ID as the candidate dangling line. Can be null.
* @param getDanglingLinesByPairingKey function to retrieve dangling lines with a given pairing key in the merging network.
* @param associateDanglingLines function associating two dangling lines
*/
public static void findAndAssociateDanglingLines(DanglingLine candidateDanglingLine,
Function<String, List<DanglingLine>> getDanglingLinesByXnodeCode,
public static void findAndAssociateDanglingLines(DanglingLine candidateDanglingLine, Function<String, List<DanglingLine>> getDanglingLinesByPairingKey,
BiConsumer<DanglingLine, DanglingLine> associateDanglingLines) {
Objects.requireNonNull(candidateDanglingLine);
Objects.requireNonNull(getDanglingLinesByXnodeCode);
Objects.requireNonNull(getDanglingLinesByPairingKey);
Objects.requireNonNull(associateDanglingLines);
// mapping by ucte xnode code
if (candidateDanglingLine.getUcteXnodeCode() != null) { // if X-node code null: no associated dangling line
// mapping by pairing key
if (candidateDanglingLine.getPairingKey() != null) { // if pairing key null: no associated dangling line
if (candidateDanglingLine.getNetwork().getDanglingLineStream(DanglingLineFilter.UNPAIRED)
.filter(d -> d != candidateDanglingLine)
.filter(d -> candidateDanglingLine.getUcteXnodeCode().equals(d.getUcteXnodeCode()))
.anyMatch(d -> d.getTerminal().isConnected())) { // check that there is no connected dangling line with same X-node code in the network to be merged
.filter(d -> candidateDanglingLine.getPairingKey().equals(d.getPairingKey()))
.anyMatch(d -> d.getTerminal().isConnected())) { // check that there is no connected dangling line with same pairing key in the network to be merged
return; // in that case, do nothing
}
List<DanglingLine> dls = getDanglingLinesByXnodeCode.apply(candidateDanglingLine.getUcteXnodeCode());
List<DanglingLine> dls = getDanglingLinesByPairingKey.apply(candidateDanglingLine.getPairingKey());
if (dls != null) {
if (dls.size() == 1) { // if there is exactly one dangling line in the merging network, merge it
associateDanglingLines.accept(dls.get(0), candidateDanglingLine);
}
if (dls.size() > 1) { // if more than one dangling line in the merging network, check how many are connected
List<DanglingLine> connectedDls = dls.stream().filter(dl -> dl.getTerminal().isConnected()).toList();
List<DanglingLine> connectedDls = dls.stream().filter(dl -> dl.getTerminal().isConnected()).collect(Collectors.toList());
if (connectedDls.size() == 1) { // if there is exactly one connected dangling line in the merging network, merge it. Otherwise, do nothing
associateDanglingLines.accept(connectedDls.get(0), candidateDanglingLine);
}
}
}
}

}

public static double getR(DanglingLine dl1, DanglingLine dl2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DanglingLineAdderImpl extends AbstractInjectionAdder<DanglingLineAdderImpl

private double b = 0.0;

private String ucteXnodeCode;
private String pairingKey;

private GenerationAdderImpl generationAdder;

Expand Down Expand Up @@ -91,8 +91,8 @@ public DanglingLineAdderImpl setB(double b) {
}

@Override
public DanglingLineAdder setUcteXnodeCode(String ucteXnodeCode) {
this.ucteXnodeCode = ucteXnodeCode;
public DanglingLineAdder setPairingKey(String pairingKey) {
this.pairingKey = pairingKey;
return this;
}

Expand Down Expand Up @@ -128,8 +128,7 @@ public DanglingLineImpl add() {
generation = generationAdder.build();
}

DanglingLineImpl danglingLine = new DanglingLineImpl(getNetworkRef(), id, getName(), isFictitious(),
p0, q0, r, x, g, b, ucteXnodeCode, generation);
DanglingLineImpl danglingLine = new DanglingLineImpl(network.getRef(), id, getName(), isFictitious(), p0, q0, r, x, g, b, pairingKey, generation);
danglingLine.addTerminal(terminal);
voltageLevel.attach(terminal, false);
network.getIndex().checkAndAdd(danglingLine);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ void allocateVariantArrayElement(int[] indexes, int sourceIndex) {

private double b;

private final String ucteXnodeCode;
private final String pairingKey;

private final GenerationImpl generation;

Expand All @@ -253,7 +253,7 @@ void allocateVariantArrayElement(int[] indexes, int sourceIndex) {

private final DanglingLineBoundaryImpl boundary;

DanglingLineImpl(Ref<NetworkImpl> network, String id, String name, boolean fictitious, double p0, double q0, double r, double x, double g, double b, String ucteXnodeCode, GenerationImpl generation) {
DanglingLineImpl(Ref<NetworkImpl> network, String id, String name, boolean fictitious, double p0, double q0, double r, double x, double g, double b, String pairingKey, GenerationImpl generation) {
super(network, id, name, fictitious);
this.network = network;
int variantArraySize = network.get().getVariantManager().getVariantArraySize();
Expand All @@ -267,7 +267,7 @@ void allocateVariantArrayElement(int[] indexes, int sourceIndex) {
this.x = x;
this.g = g;
this.b = b;
this.ucteXnodeCode = ucteXnodeCode;
this.pairingKey = pairingKey;
this.operationalLimitsHolder = new OperationalLimitsHolderImpl(this, "limits");
this.boundary = new DanglingLineBoundaryImpl(this);
this.generation = generation != null ? generation.attach(this) : null;
Expand Down Expand Up @@ -410,8 +410,8 @@ public DanglingLineImpl setB(double b) {
}

@Override
public String getUcteXnodeCode() {
return ucteXnodeCode;
public String getPairingKey() {
return pairingKey;
}

@Override
Expand Down
Loading
Loading