Skip to content

Commit

Permalink
integrating #2596 into this PR
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Pierre <nicolas.pierre@artelys.com>
  • Loading branch information
Nicolas Pierre committed Jun 5, 2023
1 parent 595b20b commit 57cd659
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,7 @@ public void writeThreeWindingsTransformerTapChangerTableToFormatter(TableFormatt
for (ThreeWindingsTransformer.Leg leg : twt.getLegs()) {
legNumber++;
RatioTapChanger rtc = leg.getRatioTapChanger();
Terminal t = leg.getTerminal();
double vb = t.getVoltageLevel().getNominalV();
double vb = twt.getRatedU0();
double zb = vb * vb / AmplConstants.SB;
if (rtc != null) {
String id = twt.getId() + "_leg" + legNumber + RATIO_TABLE;
Expand Down Expand Up @@ -587,10 +586,10 @@ private void writePhaseTapChanger(TableFormatter formatter, Identifiable<?> twt,
try {
String ptcId = twt.getId() + leg;
String tcsId = twt.getId() + leg + PHASE_TABLE;
int rtcNum = mapper.getInt(AmplSubset.PHASE_TAP_CHANGER, ptcId);
int ptcNum = mapper.getInt(AmplSubset.PHASE_TAP_CHANGER, ptcId);
int tcsNum = mapper.getInt(AmplSubset.TAP_CHANGER_TABLE, tcsId);
formatter.writeCell(variantIndex)
.writeCell(rtcNum)
.writeCell(ptcNum)
.writeCell(ptc.getTapPosition() - ptc.getLowTapPosition() + 1)
.writeCell(tcsNum)
.writeCell(faultNum)
Expand Down Expand Up @@ -654,12 +653,18 @@ public void writeThreeWindingsTranformersMiddleBusesColumnsToFormatter(TableForm
String middleVlId = AmplUtil.getThreeWindingsTransformerMiddleVoltageLevelId(twt);
int middleBusNum = mapper.getInt(AmplSubset.BUS, middleBusId);
int middleVlNum = mapper.getInt(AmplSubset.VOLTAGE_LEVEL, middleVlId);

double v = twt.getProperty("v") == null ? Double.NaN :
Double.parseDouble(twt.getProperty("v")) / twt.getRatedU0();
double angle = twt.getProperty("angle") == null ? Double.NaN :
Math.toRadians(Double.parseDouble(twt.getProperty("angle")));

formatter.writeCell(variantIndex)
.writeCell(middleBusNum)
.writeCell(middleVlNum)
.writeCell(middleCcNum)
.writeCell(Float.NaN)
.writeCell(Double.NaN)
.writeCell(v)
.writeCell(angle)
.writeCell(0.0)
.writeCell(0.0)
.writeCell(faultNum)
Expand Down Expand Up @@ -1011,70 +1016,44 @@ public void writeThreeWindingsTransformerLegToFormatter(TableFormatter formatter
int legVlNum = mapper.getInt(AmplSubset.VOLTAGE_LEVEL, vl.getId());
int legBusNum = getBusNum(bus);
double vb = vl.getNominalV();
double zb = vb * vb / AmplConstants.SB;
double r = twt.getLeg(legSide).getR() / zb;
double x = twt.getLeg(legSide).getX() / zb;
double g = twt.getLeg(legSide).getG() * zb;
double b = twt.getLeg(legSide).getB() * zb;
double ratedU = twt.getLeg(legSide).getRatedU();
double ratedU0 = twt.getRatedU0();
double ratio = ratedU0 / ratedU;
double ratedU = twt.getLeg(legSide).getRatedU();

double zb0 = ratedU0 * ratedU0 / AmplConstants.SB;
double r = twt.getLeg(legSide).getR() / zb0;
double x = twt.getLeg(legSide).getX() / zb0;
double g = twt.getLeg(legSide).getG() * zb0;
double b = twt.getLeg(legSide).getB() * zb0;
double ratio = vb / ratedU;

RatioTapChanger rtc1 = twt.getLeg(legSide).getRatioTapChanger();
PhaseTapChanger ptc1 = twt.getLeg(legSide).getPhaseTapChanger();
int rtc1Num = rtc1 != null ? mapper.getInt(AmplSubset.RATIO_TAP_CHANGER, id) : -1;
int ptc1Num = ptc1 != null ? mapper.getInt(AmplSubset.PHASE_TAP_CHANGER, id) : -1;

formatter.writeCell(variantIndex)
.writeCell(num);
if (ThreeWindingsTransformer.Side.ONE.equals(legSide)) {
formatter.writeCell(middleBusNum)
.writeCell(legBusNum)
.writeCell(num3wt)
.writeCell(middleVlNum)
.writeCell(legVlNum);
} else {
formatter.writeCell(legBusNum)
.writeCell(middleBusNum)
.writeCell(num3wt)
.writeCell(legVlNum)
.writeCell(middleVlNum);
}
formatter.writeCell(r)
.writeCell(num)
.writeCell(legBusNum)
.writeCell(middleBusNum)
.writeCell(num3wt)
.writeCell(legVlNum)
.writeCell(middleVlNum)
.writeCell(r)
.writeCell(x)
.writeCell(g)
.writeCell(0.0)
.writeCell(b)
.writeCell(0.0)
.writeCell(ratio)
.writeCell(rtc1Num)
.writeCell(ptc1Num);
switch (legSide) {
case ONE:
formatter.writeCell(Double.NaN)
.writeCell(terminal.getP())
.writeCell(Double.NaN)
.writeCell(terminal.getQ())
.writeCell(Double.NaN)
.writeCell(getPermanentLimit(twt.getLeg1().getCurrentLimits().orElse(null)));
break;
case TWO:
formatter.writeCell(terminal.getP())
.writeCell(Double.NaN)
.writeCell(terminal.getQ())
.writeCell(Double.NaN)
.writeCell(getPermanentLimit(twt.getLeg2().getCurrentLimits().orElse(null)))
.writeCell(Double.NaN);
break;
case THREE:
formatter.writeCell(terminal.getP())
.writeCell(Double.NaN)
.writeCell(terminal.getQ())
.writeCell(Double.NaN)
.writeCell(getPermanentLimit(twt.getLeg3().getCurrentLimits().orElse(null)))
.writeCell(Double.NaN);
break;
}
formatter.writeCell(false)
.writeCell(ptc1Num)
.writeCell(terminal.getP())
.writeCell(Double.NaN)
.writeCell(terminal.getQ())
.writeCell(Double.NaN)
.writeCell(getPermanentLimit(twt.getLeg(legSide).getCurrentLimits().orElse(null)))
.writeCell(Double.NaN)
.writeCell(false)
.writeCell(faultNum)
.writeCell(actionNum)
.writeCell(id)
Expand Down Expand Up @@ -1221,7 +1200,7 @@ public void writeGeneratorToFormatter(TableFormatter formatter, Generator gen) t
int conBusNum = AmplUtil.getConnectableBusNum(mapper, t);
double minP = gen.getMinP();
double maxP = gen.getMaxP();
double vb = t.getVoltageLevel().getNominalV();
double vb = gen.getRegulatingTerminal().getVoltageLevel().getNominalV();

formatter.writeCell(variantIndex)
.writeCell(num)
Expand Down Expand Up @@ -1346,18 +1325,22 @@ public void writeThreeWindingsTransformerVoltageLevelToFormatter(TableFormatter
ThreeWindingsTransformer twt) throws IOException {
String vlId = AmplUtil.getThreeWindingsTransformerMiddleVoltageLevelId(twt);
int num = mapper.getInt(AmplSubset.VOLTAGE_LEVEL, vlId);
Terminal t1 = twt.getLeg1().getTerminal();
VoltageLevel vl1 = t1.getVoltageLevel();
formatter.writeCell(variantIndex)
.writeCell(num)
.writeCell("")
.writeCell(0)
.writeCell(vl1.getNominalV())
.writeCell(twt.getRatedU0())
.writeCell(Float.NaN)
.writeCell(Float.NaN)
.writeCell(faultNum)
.writeCell(actionNum)
.writeCell(vl1.getSubstation().flatMap(Substation::getCountry).map(Enum::toString).orElse(""))
.writeCell(twt.getLeg1()
.getTerminal()
.getVoltageLevel()
.getSubstation()
.flatMap(Substation::getCountry)
.map(Enum::toString)
.orElse(""))
.writeCell(vlId)
.writeCell("");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Branches (three-windings-transformer/InitialState)
#"variant" "num" "bus1" "bus2" "3wt num" "sub.1" "sub.2" "r (pu)" "x (pu)" "g1 (pu)" "g2 (pu)" "b1 (pu)" "b2 (pu)" "cst ratio (pu)" "ratio tc" "phase tc" "p1 (MW)" "p2 (MW)" "q1 (MVar)" "q2 (MVar)" "patl1 (A)" "patl2 (A)" "merged" "fault" "curative" "id" "description"
1 1 4 1 1 4 1 0.100000 0.0100000 1.00000 0.00000 0.100000 0.00000 1.00000 -1 1 -99999.0 -99999.0 -99999.0 -99999.0 -99999.0 1000.00 false 0 0 "3WT_leg1" ""
1 2 2 4 1 2 4 0.100000 0.0100000 0.00000 0.00000 0.00000 0.00000 4.00000 1 -1 -99999.0 -99999.0 -99999.0 -99999.0 100.000 -99999.0 false 0 0 "3WT_leg2" ""
1 3 3 4 1 3 4 0.100000 0.0100000 0.00000 0.00000 0.00000 0.00000 12.0000 2 -1 -99999.0 -99999.0 -99999.0 -99999.0 10.0000 -99999.0 false 0 0 "3WT_leg3" ""
1 1 1 4 1 1 4 0.100000 0.0100000 1.00000 0.00000 0.100000 0.00000 1.00000 -1 1 -99999.0 -99999.0 -99999.0 -99999.0 1000.00 -99999.0 false 0 0 "3WT_leg1" ""
1 2 2 4 1 2 4 0.00625000 0.000625000 0.00000 0.00000 0.00000 0.00000 1.00000 1 -1 -99999.0 -99999.0 -99999.0 -99999.0 100.000 -99999.0 false 0 0 "3WT_leg2" ""
1 3 3 4 1 3 4 0.000694444 6.94444e-05 0.00000 0.00000 0.00000 0.00000 1.00000 2 -1 -99999.0 -99999.0 -99999.0 -99999.0 10.0000 -99999.0 false 0 0 "3WT_leg3" ""
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#Tap changer table (three-windings-transformer/InitialState)
#"variant" "num" "tap" "var ratio" "x (pu)" "angle (rad)" "fault" "curative"
1 3 1 1.00000 0.0101000 0.00000 0 0
1 1 1 0.900000 0.0100098 0.00000 0 0
1 1 2 1.00000 0.0100109 0.00000 0 0
1 1 3 1.10000 0.0100120 0.00000 0 0
1 2 1 0.900000 0.0100011 0.00000 0 0
1 2 2 1.00000 0.0100012 0.00000 0 0
1 2 3 1.10000 0.0100013 0.00000 0 0
1 1 1 0.900000 0.000625613 0.00000 0 0
1 1 2 1.00000 0.000625681 0.00000 0 0
1 1 3 1.10000 0.000625749 0.00000 0 0
1 2 1 0.900000 6.94520e-05 0.00000 0 0
1 2 2 1.00000 6.94528e-05 0.00000 0 0
1 2 3 1.10000 6.94537e-05 0.00000 0 0

0 comments on commit 57cd659

Please sign in to comment.