Skip to content

[WIP] Complete tie lines implementation #167

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,16 @@ public <E extends Extension<Line>> void addExtension(Class<? super E> type, E ex
.code(mergedXnode.getCode())
.rdp(mergedXnode.getRdp())
.xdp(mergedXnode.getXdp())
.xnodeP1(mergedXnode.getXnodeP1())
.xnodeP2(mergedXnode.getXnodeP2())
.xnodeQ1(mergedXnode.getXnodeQ1())
.xnodeQ2(mergedXnode.getXnodeQ2())
.line1Id(mergedXnode.getLine1Name())
.line1Name(mergedXnode.getLine1Name())
.line1Fictitious(mergedXnode.isLine1Fictitious())
.b1dp(mergedXnode.getB1dp())
.g1dp(mergedXnode.getG1dp())
.line2Id(mergedXnode.getLine2Name())
.line2Name(mergedXnode.getLine2Name())
.line2Fictitious(mergedXnode.isLine2Fictitious())
.b2dp(mergedXnode.getB2dp())
.g2dp(mergedXnode.getG2dp())
.build());
updateResource();
}
Expand Down Expand Up @@ -179,12 +183,18 @@ private MergedXnode createMergedXnode() {
return new MergedXnodeImpl(this,
resource.getAttributes().getMergedXnode().getRdp(),
resource.getAttributes().getMergedXnode().getXdp(),
resource.getAttributes().getMergedXnode().getXnodeP1(),
resource.getAttributes().getMergedXnode().getXnodeQ1(),
resource.getAttributes().getMergedXnode().getXnodeP2(),
resource.getAttributes().getMergedXnode().getXnodeQ2(),
resource.getAttributes().getMergedXnode().getLine1Name(),
resource.getAttributes().getMergedXnode().isLine1Fictitious(),
0,
0,
resource.getAttributes().getMergedXnode().getB1dp(),
resource.getAttributes().getMergedXnode().getG1dp(),
resource.getAttributes().getMergedXnode().getLine2Name(),
resource.getAttributes().getMergedXnode().isLine2Fictitious(),
0,
0,
resource.getAttributes().getMergedXnode().getB2dp(),
resource.getAttributes().getMergedXnode().getG2dp(),
resource.getAttributes().getMergedXnode().getCode());
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

/**
* @author Abdelsalem Hedhili <abdelsalem.hedhili at rte-france.com>
* @author Slimane Amar <slimane.amar at rte-france.com>
*/

public class TieLineAdderImpl extends AbstractBranchAdder<TieLineAdderImpl> implements TieLineAdder {
Expand Down Expand Up @@ -56,7 +57,7 @@ public HalfLineAdderImpl setId(String id) {
}

public String getName() {
return name;
return name != null ? name : id;
}

public HalfLineAdderImpl setName(String name) {
Expand Down Expand Up @@ -200,11 +201,15 @@ public TieLine add() {
double r = halfLine1Adder.getR() + halfLine2Adder.getR();
double x = halfLine1Adder.getX() + halfLine2Adder.getX();
double b1 = halfLine1Adder.getB1() + halfLine1Adder.getB2();
double b2 = halfLine2Adder.getB1() + halfLine2Adder.getB2();
double g1 = halfLine1Adder.getG1() + halfLine1Adder.getG2();
double b2 = halfLine2Adder.getB1() + halfLine2Adder.getB2();
double g2 = halfLine2Adder.getG1() + halfLine2Adder.getG2();
double rdp = r == 0 ? 0.5 : halfLine1Adder.getR() / r;
double xdp = x == 0 ? 0.5 : halfLine1Adder.getX() / x;
double b1dp = b1 == 0 ? 0.5 : halfLine1Adder.getB1() / b1;
double g1dp = g1 == 0 ? 0.5 : halfLine1Adder.getG1() / g1;
double b2dp = b2 == 0 ? 0.5 : halfLine2Adder.getB1() / b2;
double g2dp = g2 == 0 ? 0.5 : halfLine2Adder.getG1() / g2;
Resource<LineAttributes> resource = Resource.lineBuilder()
.id(id)
.attributes(LineAttributes.builder()
Expand All @@ -228,13 +233,16 @@ public TieLine add() {
MergedXnodeAttributes.builder()
.rdp((float) rdp)
.xdp((float) xdp)
//FIXME need to implement boundary to set the xnodeP and xnodeQ (https://github.com/powsybl/powsybl-core/wiki/IIDM-&-XIIDM-1.5-evolutions#changes-and-fixes)
.xnodeP1(Double.NaN)
.xnodeQ1(Double.NaN)
.xnodeP2(Double.NaN)
.xnodeQ2(Double.NaN)
.line1Name(halfLine1Adder.getId())
.line2Name(halfLine2Adder.getId())
.line1Id(halfLine1Adder.getId())
.line1Name(halfLine1Adder.getName())
.line1Fictitious(halfLine1Adder.isFictitious())
.b1dp((float) b1dp)
.g1dp((float) g1dp)
.line2Id(halfLine2Adder.getId())
.line2Name(halfLine2Adder.getName())
.line2Fictitious(halfLine2Adder.isFictitious())
.b2dp((float) b2dp)
.g2dp((float) g2dp)
.code(ucteXnodeCode)
.build())
.build()).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

/**
* @author Abdelsalem Hedhili <abdelsalem.hedhili at rte-france.com>
* @author Slimane Amar <slimane.amar at rte-france.com>
*/

public class TieLineImpl extends LineImpl implements TieLine {
Expand All @@ -29,7 +30,25 @@ public TieLineImpl(NetworkObjectIndex index, Resource<LineAttributes> resource)
}
}

class HalfLineImpl implements HalfLine {
private final class PositionRatio {
private double sum;
private float ratio;

private PositionRatio(double sum, float ratio) {
this.sum = sum;
this.ratio = ratio;
}

private PositionRatio setSideValue(double sideValue, boolean sideOne) {
double newSide1Value = sideOne ? sideValue : sum * ratio;
double newSide2Value = !sideOne ? sideValue : sum * (1 - ratio);
sum = newSide1Value + newSide2Value;
ratio = (float) (sum == 0 ? 0.5 : newSide1Value / sum);
return this;
}
}

class HalfLineImpl implements HalfLine, Validable {

private final boolean one;

Expand Down Expand Up @@ -91,13 +110,21 @@ public HalfLineImpl(boolean one) {

@Override
public String getId() {
return one ? resource.getAttributes().getMergedXnode().getLine1Name()
: resource.getAttributes().getMergedXnode().getLine2Name();
return one ? resource.getAttributes().getMergedXnode().getLine1Id()
: resource.getAttributes().getMergedXnode().getLine2Id();
}

@Override
public String getName() {
return getId();
String name = one ? resource.getAttributes().getMergedXnode().getLine1Name()
: resource.getAttributes().getMergedXnode().getLine2Name();
return name != null ? name : getId();
}

@Override
public boolean isFictitious() {
return one ? resource.getAttributes().getMergedXnode().isLine1Fictitious()
: resource.getAttributes().getMergedXnode().isLine2Fictitious();
}

@Override
Expand All @@ -107,7 +134,13 @@ public double getR() {

@Override
public HalfLineImpl setR(double r) {
throw new UnsupportedOperationException("TODO");
ValidationUtil.checkR(this, r);
double oldValue = getR();
PositionRatio positionRatio = new PositionRatio(resource.getAttributes().getR(), resource.getAttributes().getMergedXnode().getRdp()).setSideValue(r, one);
resource.getAttributes().setR(positionRatio.sum);
resource.getAttributes().getMergedXnode().setRdp(positionRatio.ratio);
index.notifyUpdate(TieLineImpl.this, getHalfLineAttribute() + ".r", oldValue, r);
return this;
}

@Override
Expand All @@ -117,53 +150,150 @@ public double getX() {

@Override
public HalfLineImpl setX(double x) {
throw new UnsupportedOperationException("TODO");
ValidationUtil.checkX(this, x);
double oldValue = getX();
PositionRatio positionRatio = new PositionRatio(resource.getAttributes().getX(), resource.getAttributes().getMergedXnode().getXdp()).setSideValue(x, one);
resource.getAttributes().setX(positionRatio.sum);
resource.getAttributes().getMergedXnode().setXdp(positionRatio.ratio);
index.notifyUpdate(TieLineImpl.this, getHalfLineAttribute() + ".x", oldValue, x);
return this;
}

@Override
public double getG1() {
return one ? TieLineImpl.this.getG1() / 2 : TieLineImpl.this.getG2() / 2;
return one ?
TieLineImpl.this.getG1() * resource.getAttributes().getMergedXnode().getG1dp() :
TieLineImpl.this.getG2() * resource.getAttributes().getMergedXnode().getG2dp();
}

private void setSideG(double g, boolean halfLineSideOne) {
if (one) {
PositionRatio positionRatio = new PositionRatio(resource.getAttributes().getG1(), resource.getAttributes().getMergedXnode().getG1dp()).setSideValue(g, halfLineSideOne);
resource.getAttributes().setG1(positionRatio.sum);
resource.getAttributes().getMergedXnode().setG1dp(positionRatio.ratio);
} else {
PositionRatio positionRatio = new PositionRatio(resource.getAttributes().getG2(), resource.getAttributes().getMergedXnode().getG2dp()).setSideValue(g, halfLineSideOne);
resource.getAttributes().setG2(positionRatio.sum);
resource.getAttributes().getMergedXnode().setG2dp(positionRatio.ratio);
}
}

@Override
public HalfLineImpl setG1(double g1) {
throw new UnsupportedOperationException("TODO");
ValidationUtil.checkG1(this, g1);
double oldValue = getG1();
setSideG(g1, true);
index.notifyUpdate(TieLineImpl.this, getHalfLineAttribute() + ".g1", oldValue, g1);
return this;
}

@Override
public double getG2() {
return one ? TieLineImpl.this.getG1() / 2 : TieLineImpl.this.getG2() / 2;
return one ?
TieLineImpl.this.getG1() * (1 - resource.getAttributes().getMergedXnode().getG1dp()) :
TieLineImpl.this.getG2() * (1 - resource.getAttributes().getMergedXnode().getG2dp());
}

@Override
public HalfLineImpl setG2(double g2) {
throw new UnsupportedOperationException("TODO");
ValidationUtil.checkG2(this, g2);
double oldValue = getG2();
setSideG(g2, false);
index.notifyUpdate(TieLineImpl.this, getHalfLineAttribute() + ".g2", oldValue, g2);
return this;
}

@Override
public double getB1() {
return one ? TieLineImpl.this.getB1() / 2 : TieLineImpl.this.getB2() / 2;
return one ?
TieLineImpl.this.getB1() * resource.getAttributes().getMergedXnode().getB1dp() :
TieLineImpl.this.getB2() * resource.getAttributes().getMergedXnode().getB2dp();
}

private void setSideB(double b, boolean halfLineSideOne) {
if (one) {
PositionRatio positionRatio = new PositionRatio(resource.getAttributes().getB1(), resource.getAttributes().getMergedXnode().getB1dp()).setSideValue(b, halfLineSideOne);
resource.getAttributes().setB1(positionRatio.sum);
resource.getAttributes().getMergedXnode().setB1dp(positionRatio.ratio);
} else {
PositionRatio positionRatio = new PositionRatio(resource.getAttributes().getB2(), resource.getAttributes().getMergedXnode().getB2dp()).setSideValue(b, halfLineSideOne);
resource.getAttributes().setB2(positionRatio.sum);
resource.getAttributes().getMergedXnode().setB2dp(positionRatio.ratio);
}
}

@Override
public HalfLineImpl setB1(double b1) {
throw new UnsupportedOperationException("TODO");
ValidationUtil.checkB1(this, b1);
double oldValue = getB1();
setSideB(b1, true);
index.notifyUpdate(TieLineImpl.this, getHalfLineAttribute() + ".b1", oldValue, b1);
return this;
}

@Override
public double getB2() {
return one ? TieLineImpl.this.getB1() / 2 : TieLineImpl.this.getB2() / 2;
return one ?
TieLineImpl.this.getB1() * (1 - resource.getAttributes().getMergedXnode().getB1dp()) :
TieLineImpl.this.getB2() * (1 - resource.getAttributes().getMergedXnode().getB2dp());
}

@Override
public HalfLineImpl setB2(double b2) {
throw new UnsupportedOperationException("TODO");
ValidationUtil.checkB2(this, b2);
double oldValue = getB2();
setSideB(b2, false);
index.notifyUpdate(TieLineImpl.this, getHalfLineAttribute() + ".b2", oldValue, b2);
return this;
}

@Override
public Boundary getBoundary() {
return boundary;
}

private String getHalfLineAttribute() {
return "half" + (one ? "1" : "2");
}

@Override
public String getMessageHeader() {
return String.format("Tie line side %s '%s':", one ? "1" : "2", TieLineImpl.this.getId());
}
}

private ValidationException notSupportedForTieLinesException() {
return new ValidationException(this, "direct modification of characteristics not supported for tie lines");
}

@Override
public TieLineImpl setR(double r) {
throw notSupportedForTieLinesException();
}

@Override
public TieLineImpl setX(double x) {
throw notSupportedForTieLinesException();
}

@Override
public TieLineImpl setG1(double g1) {
throw notSupportedForTieLinesException();
}

@Override
public TieLineImpl setB1(double b1) {
throw notSupportedForTieLinesException();
}

@Override
public TieLineImpl setG2(double g2) {
throw notSupportedForTieLinesException();
}

@Override
public TieLineImpl setB2(double b2) {
throw notSupportedForTieLinesException();
}

@Override
Expand Down
Loading