Skip to content

Commit

Permalink
IEEE CDF importer: support lines with different nominal voltage at bo…
Browse files Browse the repository at this point in the history
…th ends (#2480)

Signed-off-by: José Antonio Marqués <marquesja@aia.es>
  • Loading branch information
marqueslanauja authored Mar 20, 2023
1 parent 52770a1 commit 7bfeb03
Show file tree
Hide file tree
Showing 10 changed files with 517 additions and 486 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.powsybl.commons.parameters.Parameter;
import com.powsybl.commons.parameters.ParameterDefaultValueConfig;
import com.powsybl.commons.parameters.ParameterType;

import org.apache.commons.math3.complex.Complex;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.slf4j.Logger;
Expand Down Expand Up @@ -301,8 +303,20 @@ private static void createLine(IeeeCdfBranch ieeeCdfBranch, ContainersMapping co
String bus2Id = getBusId(ieeeCdfBranch.getzBusNumber());
String voltageLevel1Id = containerMapping.getVoltageLevelId(ieeeCdfBranch.getTapBusNumber());
String voltageLevel2Id = containerMapping.getVoltageLevelId(ieeeCdfBranch.getzBusNumber());
VoltageLevel voltageLevel1 = network.getVoltageLevel(voltageLevel1Id);
VoltageLevel voltageLevel2 = network.getVoltageLevel(voltageLevel2Id);
double zb = Math.pow(voltageLevel2.getNominalV(), 2) / perUnitContext.getSb();

double nominalV1 = voltageLevel1.getNominalV();
double nominalV2 = voltageLevel2.getNominalV();
double sBase = perUnitContext.getSb();
double r = impedanceToEngineeringUnitsForLine(ieeeCdfBranch.getResistance(), nominalV1, nominalV2, sBase);
double x = impedanceToEngineeringUnitsForLine(ieeeCdfBranch.getReactance(), nominalV1, nominalV2, sBase);
Complex ytr = impedanceToAdmittance(r, x);
double g1 = admittanceEndToEngineeringUnitsForLine(ytr.getReal(), 0.0, nominalV1, nominalV2, sBase);
double b1 = admittanceEndToEngineeringUnitsForLine(ytr.getImaginary(), ieeeCdfBranch.getChargingSusceptance() * 0.5, nominalV1, nominalV2, sBase);
double g2 = admittanceEndToEngineeringUnitsForLine(ytr.getReal(), 0.0, nominalV2, nominalV1, sBase);
double b2 = admittanceEndToEngineeringUnitsForLine(ytr.getImaginary(), ieeeCdfBranch.getChargingSusceptance() * 0.5, nominalV2, nominalV1, sBase);

network.newLine()
.setId(id)
.setBus1(bus1Id)
Expand All @@ -311,15 +325,32 @@ private static void createLine(IeeeCdfBranch ieeeCdfBranch, ContainersMapping co
.setBus2(bus2Id)
.setConnectableBus2(bus2Id)
.setVoltageLevel2(voltageLevel2Id)
.setR(ieeeCdfBranch.getResistance() * zb)
.setX(ieeeCdfBranch.getReactance() * zb)
.setG1(0)
.setB1(ieeeCdfBranch.getChargingSusceptance() / zb / 2)
.setG2(0)
.setB2(ieeeCdfBranch.getChargingSusceptance() / zb / 2)
.setR(r)
.setX(x)
.setG1(g1)
.setB1(b1)
.setG2(g2)
.setB2(b2)
.add();
}

// avoid NaN when r and x, both are 0.0
private static Complex impedanceToAdmittance(double r, double x) {
return r == 0.0 && x == 0.0 ? new Complex(0.0, 0.0) : new Complex(r, x).reciprocal();
}

private static double impedanceToEngineeringUnitsForLine(double impedance, double nominalVoltageAtEnd, double nominalVoltageAtOtherEnd, double sBase) {
// this method handles also line with different nominal voltage at ends
return impedance * nominalVoltageAtEnd * nominalVoltageAtOtherEnd / sBase;
}

private static double admittanceEndToEngineeringUnitsForLine(double transmissionAdmittance, double shuntAdmittanceAtEnd,
double nominalVoltageAtEnd, double nominalVoltageAtOtherEnd, double sBase) {
// this method handles also line with different nominal voltage at ends
// note that ytr is already in engineering units
return shuntAdmittanceAtEnd * sBase / (nominalVoltageAtEnd * nominalVoltageAtEnd) - (1 - nominalVoltageAtOtherEnd / nominalVoltageAtEnd) * transmissionAdmittance;
}

private static TwoWindingsTransformer createTransformer(IeeeCdfBranch ieeeCdfBranch, ContainersMapping containerMapping, PerUnitContext perUnitContext, Network network) {
String id = getBranchId('T', ieeeCdfBranch.getTapBusNumber(), ieeeCdfBranch.getzBusNumber(), ieeeCdfBranch.getCircuit(), network);
String bus1Id = getBusId(ieeeCdfBranch.getTapBusNumber());
Expand Down
302 changes: 151 additions & 151 deletions ieee-cdf/ieee-cdf-converter/src/test/resources/ieee118cdf.xiidm

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,18 @@
<iidm:line id="L1-2-1" r="1.9380000000000002E-4" x="5.917E-4" g1="0.0" b1="2.64" g2="0.0" b2="2.64" bus1="B1" connectableBus1="B1" voltageLevelId1="VL1" bus2="B2" connectableBus2="B2" voltageLevelId2="VL2" p1="156.80460550423726" q1="-20.385996504218742" p2="-152.51135079358247" q2="27.644686712136078"/>
<iidm:line id="L1-5-1" r="5.403000000000001E-4" x="0.0022304" g1="0.0" b1="2.46" g2="0.0" b2="2.46" bus1="B1" connectableBus1="B1" voltageLevelId1="VL1" bus2="B5" connectableBus2="B5" voltageLevelId2="VL5" p1="75.45984665884176" q1="3.633925403313589" p2="-72.70202647937735" q2="2.4271286338461557"/>
<iidm:line id="L2-3-1" r="4.699E-4" x="0.0019797" g1="0.0" b1="2.19" g2="0.0" b2="2.19" bus1="B2" connectableBus1="B2" voltageLevelId1="VL2" bus2="B3" connectableBus2="B3" voltageLevelId2="VL3" p1="73.21495680663453" q1="3.562425614598175" p2="-70.89310172288711" q2="1.5940519384338359"/>
<iidm:line id="L2-4-1" r="5.811000000000001E-4" x="0.0017632000000000001" g1="0.0" b1="1.7000000000000002" g2="0.0" b2="1.7000000000000002" bus1="B2" connectableBus1="B2" voltageLevelId1="VL2" bus2="B4" connectableBus2="B4" voltageLevelId2="VL4" p1="56.087059815006704" q1="-1.7302430501670583" p2="-54.41309686496292" q2="3.1912641255194156"/>
<iidm:line id="L2-5-1" r="5.695E-4" x="0.0017388000000000002" g1="0.0" b1="1.73" g2="0.0" b2="1.73" bus1="B2" connectableBus1="B2" voltageLevelId1="VL2" bus2="B5" connectableBus2="B5" voltageLevelId2="VL5" p1="41.43497174916875" q1="0.9051868430390382" p2="-40.53554453627294" q2="-1.8481468203730618"/>
<iidm:line id="L2-4-1" r="5.811E-4" x="0.0017632000000000001" g1="0.0" b1="1.7000000000000002" g2="0.0" b2="1.7000000000000002" bus1="B2" connectableBus1="B2" voltageLevelId1="VL2" bus2="B4" connectableBus2="B4" voltageLevelId2="VL4" p1="56.08705981500669" q1="-1.7302430501671768" p2="-54.41309686496289" q2="3.1912641255194103"/>
<iidm:line id="L2-5-1" r="5.695E-4" x="0.0017388" g1="0.0" b1="1.73" g2="0.0" b2="1.73" bus1="B2" connectableBus1="B2" voltageLevelId1="VL2" bus2="B5" connectableBus2="B5" voltageLevelId2="VL5" p1="41.43497174916875" q1="0.9051868430390382" p2="-40.53554453627291" q2="-1.8481468203730662"/>
<iidm:line id="L3-4-1" r="6.701E-4" x="0.0017102999999999999" g1="0.0" b1="0.64" g2="0.0" b2="0.64" bus1="B3" connectableBus1="B3" voltageLevelId1="VL3" bus2="B4" connectableBus2="B4" voltageLevelId2="VL4" p1="-23.339091648553538" q1="4.298866192308682" p2="23.71301863607503" q2="-4.660601598334643"/>
<iidm:line id="L4-5-1" r="1.3350000000000002E-4" x="4.2110000000000004E-4" g1="0.0" b1="0.0" g2="0.0" b2="0.0" bus1="B4" connectableBus1="B4" voltageLevelId1="VL4" bus2="B5" connectableBus2="B5" voltageLevelId2="VL5" p1="-61.35283310325834" q1="15.506179520895373" p2="61.868710055227915" q2="-13.87894518026324"/>
<iidm:line id="L4-5-1" r="1.3350000000000002E-4" x="4.211E-4" g1="0.0" b1="0.0" g2="0.0" b2="0.0" bus1="B4" connectableBus1="B4" voltageLevelId1="VL4" bus2="B5" connectableBus2="B5" voltageLevelId2="VL5" p1="-61.35283310325834" q1="15.506179520895373" p2="61.868710055227915" q2="-13.87894518026324"/>
<iidm:line id="L6-11-1" r="9.498E-4" x="0.001989" g1="0.0" b1="0.0" g2="0.0" b2="0.0" bus1="B6" connectableBus1="B6" voltageLevelId1="VL5" bus2="B11" connectableBus2="B11" voltageLevelId2="VL11" p1="7.336764124036019" q1="3.518103633220369" p2="-7.281840845230593" q2="-3.4030874176549952"/>
<iidm:line id="L6-12-1" r="0.0012291000000000001" x="0.0025581" g1="0.0" b1="0.0" g2="0.0" b2="0.0" bus1="B6" connectableBus1="B6" voltageLevelId1="VL5" bus2="B12" connectableBus2="B12" voltageLevelId2="VL12" p1="7.849685030631457" q1="2.552328640974945" p2="-7.776542430194539" q2="-2.4000984838049164"/>
<iidm:line id="L6-13-1" r="6.615E-4" x="0.0013027" g1="0.0" b1="0.0" g2="0.0" b2="0.0" bus1="B6" connectableBus1="B6" voltageLevelId1="VL5" bus2="B13" connectableBus2="B13" voltageLevelId2="VL13" p1="17.92680495621049" q1="7.4404051072185755" p2="-17.709138023508487" q2="-7.011750967791672"/>
<iidm:line id="L7-8-1" r="0.0" x="0.0017615" g1="0.0" b1="0.0" g2="0.0" b2="0.0" bus1="B7" connectableBus1="B7" voltageLevelId1="VL4" bus2="B8" connectableBus2="B8" voltageLevelId2="VL8" p1="-9.769962616701378E-15" q1="-16.88106727221128" p2="9.325873406851315E-15" q2="17.326142492194254"/>
<iidm:line id="L7-9-1" r="0.0" x="0.0011001" g1="0.0" b1="0.0" g2="0.0" b2="0.0" bus1="B7" connectableBus1="B7" voltageLevelId1="VL4" bus2="B9" connectableBus2="B9" voltageLevelId2="VL4" p1="28.108371214225585" q1="6.1797863346607835" p2="-28.108371214225585" q2="-5.3718907856009945"/>
<iidm:line id="L9-10-1" r="3.181E-4" x="8.45E-4" g1="0.0" b1="0.0" g2="0.0" b2="0.0" bus1="B9" connectableBus1="B9" voltageLevelId1="VL4" bus2="B10" connectableBus2="B10" voltageLevelId2="VL10" p1="5.274515902374918" q1="4.268051989907747" p2="-5.261383601417242" q2="-4.233167380321964"/>
<iidm:line id="L9-14-1" r="0.0012711" x="0.0027038" g1="0.0" b1="0.0" g2="0.0" b2="0.0" bus1="B9" connectableBus1="B9" voltageLevelId1="VL4" bus2="B14" connectableBus2="B14" voltageLevelId2="VL14" p1="9.339568641122321" q1="3.49376405544432" p2="-9.22622778582496" q2="-3.252672870995411"/>
<iidm:line id="L10-11-1" r="8.205E-4" x="0.0019207" g1="0.0" b1="0.0" g2="0.0" b2="0.0" bus1="B10" connectableBus1="B10" voltageLevelId1="VL10" bus2="B11" connectableBus2="B11" voltageLevelId2="VL11" p1="-3.829441562512516" q1="-1.6388207630515992" p2="3.8423294444181595" q2="1.6689898730773987"/>
<iidm:line id="L10-11-1" r="8.204999999999999E-4" x="0.0019207" g1="0.0" b1="0.0" g2="0.0" b2="0.0" bus1="B10" connectableBus1="B10" voltageLevelId1="VL10" bus2="B11" connectableBus2="B11" voltageLevelId2="VL11" p1="-3.829441562512516" q1="-1.6388207630515992" p2="3.8423294444181595" q2="1.6689898730773987"/>
<iidm:line id="L12-13-1" r="0.0022092" x="0.0019988000000000002" g1="0.0" b1="0.0" g2="0.0" b2="0.0" bus1="B12" connectableBus1="B12" voltageLevelId1="VL12" bus2="B13" connectableBus2="B13" voltageLevelId2="VL13" p1="1.6615444669128372" q1="0.8031797935511802" p2="-1.6547843718856987" q2="-0.7970635170980549"/>
<iidm:line id="L13-14-1" r="0.0017093" x="0.0034802" g1="0.0" b1="0.0" g2="0.0" b2="0.0" bus1="B13" connectableBus1="B13" voltageLevelId1="VL13" bus2="B14" connectableBus2="B14" voltageLevelId2="VL14" p1="5.509245481064252" q1="1.5540625689550724" p2="-5.458444160664185" q2="-1.4506291428412763"/>
<iidm:extension id="VL1">
Expand Down
18 changes: 9 additions & 9 deletions ieee-cdf/ieee-cdf-converter/src/test/resources/ieee14cdf.xiidm
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,20 @@
</iidm:substation>
<iidm:line id="L1-2-1" r="3.5320050000000003" x="10.7837325" g1="0.0" b1="1.448559670781893E-4" g2="0.0" b2="1.448559670781893E-4" bus1="B1" connectableBus1="B1" voltageLevelId1="VL1" bus2="B2" connectableBus2="B2" voltageLevelId2="VL2"/>
<iidm:line id="L1-5-1" r="9.8469675" x="40.64904" g1="0.0" b1="1.3497942386831276E-4" g2="0.0" b2="1.3497942386831276E-4" bus1="B1" connectableBus1="B1" voltageLevelId1="VL1" bus2="B5" connectableBus2="B5" voltageLevelId2="VL5"/>
<iidm:line id="L2-3-1" r="8.5639275" x="36.0800325" g1="0.0" b1="1.2016460905349794E-4" g2="0.0" b2="1.2016460905349794E-4" bus1="B2" connectableBus1="B2" voltageLevelId1="VL2" bus2="B3" connectableBus2="B3" voltageLevelId2="VL3"/>
<iidm:line id="L2-3-1" r="8.563927499999998" x="36.0800325" g1="0.0" b1="1.2016460905349794E-4" g2="0.0" b2="1.2016460905349794E-4" bus1="B2" connectableBus1="B2" voltageLevelId1="VL2" bus2="B3" connectableBus2="B3" voltageLevelId2="VL3"/>
<iidm:line id="L2-4-1" r="10.5905475" x="32.13432" g1="0.0" b1="9.327846364883403E-5" g2="0.0" b2="9.327846364883403E-5" bus1="B2" connectableBus1="B2" voltageLevelId1="VL2" bus2="B4" connectableBus2="B4" voltageLevelId2="VL4"/>
<iidm:line id="L2-5-1" r="10.3791375" x="31.68963" g1="0.0" b1="9.492455418381344E-5" g2="0.0" b2="9.492455418381344E-5" bus1="B2" connectableBus1="B2" voltageLevelId1="VL2" bus2="B5" connectableBus2="B5" voltageLevelId2="VL5"/>
<iidm:line id="L3-4-1" r="12.2125725" x="31.170217499999996" g1="0.0" b1="3.511659807956104E-5" g2="0.0" b2="3.511659807956104E-5" bus1="B3" connectableBus1="B3" voltageLevelId1="VL3" bus2="B4" connectableBus2="B4" voltageLevelId2="VL4"/>
<iidm:line id="L2-5-1" r="10.379137499999999" x="31.68963" g1="0.0" b1="9.492455418381344E-5" g2="0.0" b2="9.492455418381344E-5" bus1="B2" connectableBus1="B2" voltageLevelId1="VL2" bus2="B5" connectableBus2="B5" voltageLevelId2="VL5"/>
<iidm:line id="L3-4-1" r="12.2125725" x="31.170217499999993" g1="0.0" b1="3.511659807956104E-5" g2="0.0" b2="3.511659807956104E-5" bus1="B3" connectableBus1="B3" voltageLevelId1="VL3" bus2="B4" connectableBus2="B4" voltageLevelId2="VL4"/>
<iidm:line id="L4-5-1" r="2.4330375" x="7.6745475" g1="0.0" b1="0.0" g2="0.0" b2="0.0" bus1="B4" connectableBus1="B4" voltageLevelId1="VL4" bus2="B5" connectableBus2="B5" voltageLevelId2="VL5"/>
<iidm:line id="L6-11-1" r="0.13677119999999998" x="0.286416" g1="0.0" b1="0.0" g2="0.0" b2="0.0" bus1="B6" connectableBus1="B6" voltageLevelId1="VL6" bus2="B11" connectableBus2="B11" voltageLevelId2="VL11"/>
<iidm:line id="L6-12-1" r="0.1769904" x="0.3683664" g1="0.0" b1="0.0" g2="0.0" b2="0.0" bus1="B6" connectableBus1="B6" voltageLevelId1="VL6" bus2="B12" connectableBus2="B12" voltageLevelId2="VL12"/>
<iidm:line id="L6-13-1" r="0.095256" x="0.1875888" g1="0.0" b1="0.0" g2="0.0" b2="0.0" bus1="B6" connectableBus1="B6" voltageLevelId1="VL6" bus2="B13" connectableBus2="B13" voltageLevelId2="VL13"/>
<iidm:line id="L7-8-1" r="0.0" x="0.7046" g1="0.0" b1="0.0" g2="0.0" b2="0.0" bus1="B7" connectableBus1="B7" voltageLevelId1="VL7" bus2="B8" connectableBus2="B8" voltageLevelId2="VL8"/>
<iidm:line id="L7-9-1" r="0.0" x="0.15841439999999998" g1="0.0" b1="0.0" g2="0.0" b2="0.0" bus1="B7" connectableBus1="B7" voltageLevelId1="VL7" bus2="B9" connectableBus2="B9" voltageLevelId2="VL9"/>
<iidm:line id="L9-10-1" r="0.0458064" x="0.12168000000000001" g1="0.0" b1="0.0" g2="0.0" b2="0.0" bus1="B9" connectableBus1="B9" voltageLevelId1="VL9" bus2="B10" connectableBus2="B10" voltageLevelId2="VL10"/>
<iidm:line id="L9-14-1" r="0.1830384" x="0.3893472" g1="0.0" b1="0.0" g2="0.0" b2="0.0" bus1="B9" connectableBus1="B9" voltageLevelId1="VL9" bus2="B14" connectableBus2="B14" voltageLevelId2="VL14"/>
<iidm:line id="L6-13-1" r="0.09525600000000001" x="0.18758879999999997" g1="0.0" b1="0.0" g2="0.0" b2="0.0" bus1="B6" connectableBus1="B6" voltageLevelId1="VL6" bus2="B13" connectableBus2="B13" voltageLevelId2="VL13"/>
<iidm:line id="L7-8-1" r="0.0" x="0.49322000000000005" g1="0.0" b1="-0.8689254867430936" g2="0.0" b2="0.6082478407201655" bus1="B7" connectableBus1="B7" voltageLevelId1="VL7" bus2="B8" connectableBus2="B8" voltageLevelId2="VL8"/>
<iidm:line id="L7-9-1" r="0.0" x="0.1848168" g1="0.0" b1="0.7729662176660504" g2="0.0" b2="-0.9017939206103922" bus1="B7" connectableBus1="B7" voltageLevelId1="VL7" bus2="B9" connectableBus2="B9" voltageLevelId2="VL9"/>
<iidm:line id="L9-10-1" r="0.04580639999999999" x="0.12168" g1="0.0" b1="0.0" g2="0.0" b2="0.0" bus1="B9" connectableBus1="B9" voltageLevelId1="VL9" bus2="B10" connectableBus2="B10" voltageLevelId2="VL10"/>
<iidm:line id="L9-14-1" r="0.18303840000000002" x="0.3893472" g1="0.0" b1="0.0" g2="0.0" b2="0.0" bus1="B9" connectableBus1="B9" voltageLevelId1="VL9" bus2="B14" connectableBus2="B14" voltageLevelId2="VL14"/>
<iidm:line id="L10-11-1" r="0.118152" x="0.27658079999999996" g1="0.0" b1="0.0" g2="0.0" b2="0.0" bus1="B10" connectableBus1="B10" voltageLevelId1="VL10" bus2="B11" connectableBus2="B11" voltageLevelId2="VL11"/>
<iidm:line id="L12-13-1" r="0.3181248" x="0.2878272" g1="0.0" b1="0.0" g2="0.0" b2="0.0" bus1="B12" connectableBus1="B12" voltageLevelId1="VL12" bus2="B13" connectableBus2="B13" voltageLevelId2="VL13"/>
<iidm:line id="L12-13-1" r="0.3181248" x="0.28782719999999995" g1="0.0" b1="0.0" g2="0.0" b2="0.0" bus1="B12" connectableBus1="B12" voltageLevelId1="VL12" bus2="B13" connectableBus2="B13" voltageLevelId2="VL13"/>
<iidm:line id="L13-14-1" r="0.2461392" x="0.5011488" g1="0.0" b1="0.0" g2="0.0" b2="0.0" bus1="B13" connectableBus1="B13" voltageLevelId1="VL13" bus2="B14" connectableBus2="B14" voltageLevelId2="VL14"/>
<iidm:extension id="VL1">
<slt:slackTerminal id="B1-G"/>
Expand Down
Loading

0 comments on commit 7bfeb03

Please sign in to comment.