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

Manage dangling lines and tie lines #172

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f2f6927
add exception on Three Windings Transformers and Dangling Lines
rolnico Sep 24, 2024
ac3a84c
remove dangling lines from branches (already managed as loads) + rewr…
rolnico Sep 25, 2024
faa9170
test exception on T3T
rolnico Sep 25, 2024
e10a1da
add test on MetrixNetwork
rolnico Sep 25, 2024
332dbd3
switch next to dangling lines should be managed as those next to loads
rolnico Sep 25, 2024
0a73685
add more test for coverage
rolnico Sep 25, 2024
cd7c64b
Merge branch 'main' into nro/use_different_connectables
rolnico Sep 25, 2024
e219fc1
remove useless comment
rolnico Sep 25, 2024
ccfa085
revert fixes on dangling line to do it in another PR
rolnico Sep 26, 2024
b46a26f
manage dangling lines and tie lines
rolnico Sep 26, 2024
e844ad8
add test for tieline coverage
rolnico Sep 27, 2024
41d7943
Merge branch 'main' into nro/use_different_connectables
jeandemanged Nov 7, 2024
de0a3ed
Merge branch 'nro/use_different_connectables' into nro/dangline_lines…
jeandemanged Nov 7, 2024
c322699
Merge branch 'refs/heads/main' into nro/dangline_lines_tie_lines
jeandemanged Nov 8, 2024
e923602
Handle unpaired dangling line as quad + node + load
jeandemanged Nov 8, 2024
c0d333f
test
jeandemanged Nov 8, 2024
4afc31d
DanglingLine BranchMonitoring
jeandemanged Nov 14, 2024
7de56fd
DanglingLine and TieLine Contingency
jeandemanged Nov 14, 2024
b009460
DanglingLine and TieLine Section Monitoring
jeandemanged Nov 14, 2024
5820fb8
Merge branch 'main' into nro/dangline_lines_tie_lines
jeandemanged Nov 15, 2024
1ab3867
clean
jeandemanged Nov 15, 2024
7ce32a1
clean
jeandemanged Nov 15, 2024
6c4e5aa
test
jeandemanged Nov 15, 2024
863c587
Merge branch 'main' into nro/dangline_lines_tie_lines
rolnico Dec 16, 2024
d72e43a
extract method to reduce complexity
rolnico Dec 16, 2024
7992ef4
Merge branch 'main' into nro/dangline_lines_tie_lines
rolnico Dec 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
package com.powsybl.metrix.integration

import com.powsybl.iidm.network.Branch
import com.powsybl.iidm.network.DanglingLine
import com.powsybl.iidm.network.Identifiable
import com.powsybl.iidm.network.Network
import com.powsybl.metrix.mapping.LogDslLoader
Expand Down Expand Up @@ -126,11 +128,19 @@ class BranchMonitoringData {
}

protected static branchData(Closure closure, String id, Network network, TimeSeriesMappingConfigLoader configLoader, MetrixDslData data, LogDslLoader logDslLoader) {
Identifiable identifiable = network.getBranch(id)
Identifiable identifiable = network.getIdentifiable(id)
if (identifiable == null) {
logDslLoader.logWarn("Branch %s not found in the network", id)
return
}
if (!(identifiable instanceof Branch || identifiable instanceof DanglingLine)) {
logDslLoader.logWarn("Branch %s is not a Branch or Dangling Line", id)
return
}
if (identifiable instanceof DanglingLine && identifiable.isPaired()) {
logDslLoader.logWarn("Branch %s is a paired Dangling Line, the TieLine should be used instead", id)
return
}

def branchSpec = branchMonitoringData(closure)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,18 @@ class SectionMonitoringData {
logDslLoader.logWarn("sectionMonitoring '" + id + "' branch id '"+branch.getKey()+"' not found in the network")
return
}
if (!(identifiable instanceof Line || identifiable instanceof TwoWindingsTransformer || identifiable instanceof HvdcLine)) {
if (!(identifiable instanceof Line ||
identifiable instanceof TwoWindingsTransformer ||
identifiable instanceof TieLine ||
identifiable instanceof DanglingLine ||
identifiable instanceof HvdcLine)) {
logDslLoader.logWarn("sectionMonitoring '" + id + "' type " + identifiable.getClass().name + " not supported")
return
}
if (identifiable instanceof DanglingLine && identifiable.isPaired()) {
logDslLoader.logWarn("Branch %s is a paired Dangling Line, the TieLine should be used instead", id)
return
}
}
section.setCoefFlowList(spec.branchList)
data.addSection(section)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class MetrixNetwork {
private static final Logger LOGGER = LoggerFactory.getLogger(MetrixNetwork.class);
private static final String PAYS_CVG_PROPERTY = "paysCvg";
private static final String PAYS_CVG_UNDEFINED = "Undefined";
private static final String METRIX_DANGLING_LINE_BUS_SUFFIX = "_metrixDanglingLineBus";
private static final String METRIX_DANGLING_LINE_LOAD_SUFFIX = "_metrixDanglingLineLoad";

private final Network network;

Expand All @@ -52,8 +54,9 @@ public class MetrixNetwork {
private final Set<Line> lineList = new LinkedHashSet<>();
private final Set<TwoWindingsTransformer> twoWindingsTransformerList = new LinkedHashSet<>();
private final Set<ThreeWindingsTransformer> threeWindingsTransformerList = new LinkedHashSet<>();
private final Set<DanglingLine> danglingLineList = new LinkedHashSet<>();
private final Set<Switch> switchList = new LinkedHashSet<>();
private final Set<DanglingLine> unpairedDanglingLineList = new LinkedHashSet<>();
private final Set<TieLine> tieLineList = new LinkedHashSet<>();

private final Set<PhaseTapChanger> phaseTapChangerList = new LinkedHashSet<>();

Expand Down Expand Up @@ -104,14 +107,18 @@ public List<ThreeWindingsTransformer> getThreeWindingsTransformerList() {
return List.copyOf(threeWindingsTransformerList);
}

public List<DanglingLine> getDanglingLineList() {
return List.copyOf(danglingLineList);
public List<DanglingLine> getUnpairedDanglingLineList() {
return List.copyOf(unpairedDanglingLineList);
}

public List<Switch> getSwitchList() {
return List.copyOf(switchList);
}

public List<TieLine> getTieLineList() {
return List.copyOf(tieLineList);
}

public List<PhaseTapChanger> getPhaseTapChangerList() {
return List.copyOf(phaseTapChangerList);
}
Expand All @@ -137,6 +144,19 @@ public int getIndex(Identifiable<?> identifiable) {
return mapper.getInt(subset, identifiable.getId());
}

public int getUnpairedDanglingLineBusIndex(DanglingLine danglingLine) {
Objects.requireNonNull(danglingLine);
if (danglingLine.isPaired()) {
throw new IllegalStateException("DanglingLine is paired " + danglingLine.getId());
}
return mapper.getInt(MetrixSubset.NOEUD, danglingLine.getId() + METRIX_DANGLING_LINE_BUS_SUFFIX);
}

public static String getUnpairedDanglingLineLoadId(DanglingLine danglingLine) {
Objects.requireNonNull(danglingLine);
return danglingLine.getId() + METRIX_DANGLING_LINE_LOAD_SUFFIX;
}

private MetrixSubset getMetrixSubset(Identifiable<?> identifiable) {
MetrixSubset subset = MetrixSubset.QUAD;
if (identifiable instanceof Generator) {
Expand Down Expand Up @@ -205,6 +225,12 @@ private void addLine(Line line) {
}
}

private void addTieLine(TieLine tieLine) {
if (tieLineList.add(tieLine)) {
mapper.newInt(MetrixSubset.QUAD, tieLine.getId());
}
}

private void addTwoWindingsTransformer(TwoWindingsTransformer twt) {
if (twoWindingsTransformerList.add(twt)) {
mapper.newInt(MetrixSubset.QUAD, twt.getId());
Expand All @@ -217,9 +243,11 @@ private void addThreeWindingsTransformer(ThreeWindingsTransformer twt) {
}
}

private void addDanglingLine(DanglingLine dl) {
if (danglingLineList.add(dl)) {
private void addUnpairedDanglingLine(DanglingLine dl) {
if (unpairedDanglingLineList.add(dl)) {
mapper.newInt(MetrixSubset.QUAD, dl.getId());
mapper.newInt(MetrixSubset.NOEUD, dl.getId() + METRIX_DANGLING_LINE_BUS_SUFFIX);
mapper.newInt(MetrixSubset.LOAD, dl.getId() + METRIX_DANGLING_LINE_LOAD_SUFFIX);
}
}

Expand Down Expand Up @@ -315,6 +343,28 @@ private void createLineList() {
}
}

private void createTieLineList() {
int nbNok = 0;
for (TieLine tieLine : network.getTieLines()) {
Terminal t1 = tieLine.getTerminal1();
Bus b1 = t1.getBusBreakerView().getBus();
Terminal t2 = tieLine.getTerminal2();
Bus b2 = t2.getBusBreakerView().getBus();
if (b1 != null && b2 != null) {
if (busList.contains(b1) && busList.contains(b2)) {
addTieLine(tieLine);
} else {
nbNok++;
}
} else {
nbNok++;
}
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("TieLines total = <%5d> ok = <%5d> not = <%5d>", tieLineList.size() + nbNok, tieLineList.size(), nbNok));
}
}

private void addTwoWindingsTransformer(TwoWindingsTransformer twt, AtomicInteger nbNok, AtomicInteger nbPtcNok) {
Terminal t1 = twt.getTerminal1();
Terminal t2 = twt.getTerminal2();
Expand Down Expand Up @@ -383,23 +433,25 @@ private void createTransformerList() {
createThreeWindingsTransformersList();
}

private void createDanglingLineList() {
private void createUnpairedDanglingLineList() {
int nbNok = 0;
for (DanglingLine dl : network.getDanglingLines()) {
Terminal t = dl.getTerminal();
Bus b = t.getBusBreakerView().getBus();
if (b != null) {
if (busList.contains(b)) {
addDanglingLine(dl);
if (!dl.isPaired()) {
Terminal t = dl.getTerminal();
Bus b = t.getBusBreakerView().getBus();
if (b != null) {
if (busList.contains(b)) {
addUnpairedDanglingLine(dl);
} else {
nbNok++;
}
} else {
nbNok++;
}
} else {
nbNok++;
}
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("Dangling total = <%5d> ok = <%5d> not = <%5d>", danglingLineList.size() + nbNok, danglingLineList.size(), nbNok));
LOGGER.debug(String.format("Dangling total = <%5d> ok = <%5d> not = <%5d>", unpairedDanglingLineList.size() + nbNok, unpairedDanglingLineList.size(), nbNok));
}
}

Expand All @@ -421,7 +473,7 @@ private void createSwitchList() {
}
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("Switches total = <%5d> ok = <%5d> not = <%5d>", switchList.size() + nbNok, switchList.size(), nbNok));
LOGGER.debug(String.format("Switches total = <%5d> ok = <%5d> not = <%5d>", switchList.size() + nbNok, switchList.size(), nbNok));
}
}

Expand Down Expand Up @@ -521,10 +573,11 @@ private void init() {
createGeneratorList();
createLineList();
createTransformerList();
createDanglingLineList();
createUnpairedDanglingLineList();
createSwitchList();
createLoadList();
createHvdcLineList();
createTieLineList();
}

public static MetrixNetwork create(Network network) {
Expand All @@ -538,8 +591,7 @@ public static MetrixNetwork create(Network network, ContingenciesProvider contin
try {
reader = Files.newBufferedReader(remedialActionFile, StandardCharsets.UTF_8);
} catch (IOException e) {
LOGGER.error("Failed to read remedialActionFile {}", remedialActionFile, e);
throw new UncheckedIOException(e);
throw new UncheckedIOException("Failed to read remedialActionFile " + remedialActionFile, e);
}
}
return create(
Expand Down Expand Up @@ -657,7 +709,18 @@ private void addElementToRetainedBreakersList(Switch sw, Terminal terminal, bool
// Since switches connected to lines and TWT are "replaced" by those connectables, no need to set them retained
case LINE, TWO_WINDINGS_TRANSFORMER -> addElementToRetainedBreakersList(sw, terminal.getConnectable().getId(), false);
case LOAD, GENERATOR -> addElementToRetainedBreakersList(sw, switchId, setRetained);
case DANGLING_LINE, HVDC_CONVERTER_STATION, SHUNT_COMPENSATOR, STATIC_VAR_COMPENSATOR,
case DANGLING_LINE -> {
DanglingLine danglingLine = (DanglingLine) terminal.getConnectable();
if (danglingLine.isPaired()) {
// Paired dangling line is managed as a line via the tie line
TieLine tieLine = danglingLine.getTieLine().orElseThrow(() -> new PowsyblException("No tie line on a paired dangling line - should not happen"));
addElementToRetainedBreakersList(sw, tieLine.getId(), false);
} else {
// Unpaired dangling line is managed as a line (ending to a load)
addElementToRetainedBreakersList(sw, terminal.getConnectable().getId(), false);
}
}
case HVDC_CONVERTER_STATION, SHUNT_COMPENSATOR, STATIC_VAR_COMPENSATOR,
THREE_WINDINGS_TRANSFORMER -> {
if (LOGGER.isWarnEnabled()) {
LOGGER.warn("Unsupported connectable type ({}) for switch '{}'", terminal.getConnectable().getType(), switchId);
Expand Down
Loading
Loading