Skip to content

Commit

Permalink
Add method to check if a branch is overloaded
Browse files Browse the repository at this point in the history
  • Loading branch information
geofjamg committed Sep 29, 2016
1 parent c779b7f commit 5e3b2c1
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ enum Side {

CurrentLimitsAdder newCurrentLimits2();

boolean isOverloaded();

int getOverloadDuration();
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,28 @@ public CurrentLimitsAdder newCurrentLimits2() {
return new CurrentLimitsAdderImpl<>(TwoTerminalsConnectable.Side.TWO, this);
}

public boolean isOverloaded() {
return (limits1 != null && getTerminal1().getI() >= limits1.getPermanentLimit())
|| (limits2 != null && getTerminal2().getI() >= limits2.getPermanentLimit());
}

private static int getOverloadDuration(CurrentLimits limits, Terminal t) {
if (limits != null) {
float i1 = t.getI();
float previousLimit = limits.getPermanentLimit();
for (CurrentLimits.TemporaryLimit tl : limits.getTemporaryLimits()) {
if (i1 >= previousLimit && i1 < tl.getLimit()) {
return tl.getAcceptableDuration();
}
previousLimit = tl.getLimit();
}
}
return Integer.MAX_VALUE;
}

public int getOverloadDuration() {
int duration1 = getOverloadDuration(limits1, getTerminal1());
int duration2 = getOverloadDuration(limits2, getTerminal2());
return Math.min(duration1, duration2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@
*/
public class CurrentLimitsAdderImpl<SIDE, OWNER extends CurrentLimitsOwner<SIDE> & Validable> implements CurrentLimitsAdder {

private static final Comparator<Integer> ACCEPTABLE_DURATION_COMPARATOR = new Comparator<Integer>() {
@Override
public int compare(Integer acceptableDuraction1, Integer acceptableDuraction2) {
return acceptableDuraction2 - acceptableDuraction1;
}
};
private static final Comparator<Integer> ACCEPTABLE_DURATION_COMPARATOR = (acceptableDuraction1, acceptableDuraction2) -> acceptableDuraction2 - acceptableDuraction1;

private final SIDE side;

Expand Down Expand Up @@ -67,7 +62,7 @@ public CurrentLimitsAdder endTemporaryLimit() {
throw new ValidationException(owner, "acceptable duration must be >= 0");
}
temporaryLimits.put(acceptableDuration, new TemporaryLimitImpl(limit, acceptableDuration));
return (CurrentLimitsAdder) CurrentLimitsAdderImpl.this;
return CurrentLimitsAdderImpl.this;
}

}
Expand All @@ -88,6 +83,23 @@ public TemporaryLimitAdder beginTemporaryLimit() {
return new TemporaryLimitAdderImpl();
}

private void check() {
// check temporary limits are consistents with permanent
float previousLimit = Float.NaN;
for (TemporaryLimit tl : temporaryLimits.values()) { // iterate in ascending order
if (tl.getLimit() <= permanentLimit) {
throw new ValidationException(owner, "Temporary limit should be greather than permanent limit");
}
if (Float.isNaN(previousLimit)) {
previousLimit = tl.getLimit();
} else {
if (tl.getLimit() <= previousLimit) {
throw new ValidationException(owner, "Temporary limit inconsistency");
}
}
}
}

@Override
public CurrentLimits add() {
if (permanentLimit <= 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* Copyright (c) 2016, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package eu.itesla_project.iidm.network.impl;

import eu.itesla_project.iidm.network.*;
import org.junit.Test;
import static org.junit.Assert.*;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public class CurrentLimitsTest {

private Network createNetwork() {
Network network = NetworkFactory.create("test", "test");
Substation s1 = network.newSubstation()
.setId("S1")
.setCountry(Country.FR)
.add();
VoltageLevel vl1 = s1.newVoltageLevel()
.setId("VL1")
.setNominalV(400f)
.setTopologyKind(TopologyKind.BUS_BREAKER)
.add();
vl1.getBusBreakerView().newBus()
.setId("B1")
.add();
Substation s2 = network.newSubstation()
.setId("S2")
.setCountry(Country.FR)
.add();
VoltageLevel vl2 = s2.newVoltageLevel()
.setId("VL2")
.setNominalV(400f)
.setTopologyKind(TopologyKind.BUS_BREAKER)
.add();
vl2.getBusBreakerView().newBus()
.setId("B2")
.add();
Line l = network.newLine()
.setId("L")
.setVoltageLevel1("VL1")
.setConnectableBus1("B1")
.setBus1("B1")
.setVoltageLevel2("VL2")
.setConnectableBus2("B2")
.setBus2("B2")
.setR(1)
.setX(1)
.setG1(0)
.setG2(0)
.setB1(0)
.setB2(0)
.add();
l.newCurrentLimits1()
.setPermanentLimit(1000)
.beginTemporaryLimit()
.setAcceptableDuration(20 * 60)
.setLimit(1200)
.endTemporaryLimit()
.beginTemporaryLimit()
.setAcceptableDuration(5 * 60)
.setLimit(1400)
.endTemporaryLimit()
.beginTemporaryLimit()
.setAcceptableDuration(60)
.setLimit(1600)
.endTemporaryLimit()
.add();
return network;
}

@Test
public void test() {
Network network = createNetwork();
Line l = network.getLine("L");
assertFalse(l.isOverloaded());
l.getTerminal1().getBusBreakerView().getBus().setV(390);
l.getTerminal1().setP(100).setQ(50);
assertTrue(!Float.isNaN(l.getTerminal1().getI()));
assertFalse(l.isOverloaded());
l.getTerminal1().setP(800).setQ(400);
assertTrue(l.isOverloaded());
assertTrue(l.getOverloadDuration() == 5 * 60);
l.getTerminal1().setP(900).setQ(500);
assertTrue(l.getOverloadDuration() == 60);
}
}

0 comments on commit 5e3b2c1

Please sign in to comment.