Skip to content

Commit

Permalink
Allow input voltage levels that do not comply with the predicate to b…
Browse files Browse the repository at this point in the history
…e displayed

Signed-off-by: Sophie Frasnedo <sophie.frasnedo@rte-france.com>
  • Loading branch information
So-Fras committed Dec 8, 2023
1 parent 06c6dbf commit c6ee6ff
Show file tree
Hide file tree
Showing 3 changed files with 518 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,9 @@ public static VoltageLevelFilter createVoltageLevelFilterWithPredicate(Network n
throw new PowsyblException(UNKNOWN_VOLTAGE_LEVEL + voltageLevelId + "'");
}
if (!voltageLevelPredicate.test(vl)) {
LOGGER.warn("vl '{}' has his nominal voltage out of the indicated thresholds", voltageLevelId);
} else {
startingSet.add(vl);
LOGGER.warn("vl '{}' does not comply with the predicate", voltageLevelId);
}
startingSet.add(vl);
}
Set<VoltageLevel> voltageLevels = new HashSet<>();
VoltageLevelFilter.traverseVoltageLevels(startingSet, depth, voltageLevels, voltageLevelPredicate);
Expand All @@ -110,9 +109,9 @@ private static void traverseVoltageLevels(Set<VoltageLevel> voltageLevelsDepth,
}
Set<VoltageLevel> nextDepthVoltageLevels = new HashSet<>();
for (VoltageLevel vl : voltageLevelsDepth) {
if (!visitedVoltageLevels.contains(vl) && predicate.test(vl)) {
if (!visitedVoltageLevels.contains(vl)) {
visitedVoltageLevels.add(vl);
vl.visitEquipments(new VlVisitor(nextDepthVoltageLevels, visitedVoltageLevels));
vl.visitEquipments(new VlVisitor(nextDepthVoltageLevels, visitedVoltageLevels, predicate));
}
}
traverseVoltageLevels(nextDepthVoltageLevels, depth - 1, visitedVoltageLevels, predicate);
Expand All @@ -130,10 +129,12 @@ private static void checkVoltageBoundValues(double nominalVoltageLowerBound, dou
private static class VlVisitor extends DefaultTopologyVisitor {
private final Set<VoltageLevel> nextDepthVoltageLevels;
private final Set<VoltageLevel> visitedVoltageLevels;
private final Predicate<VoltageLevel> voltageLevelPredicate;

public VlVisitor(Set<VoltageLevel> nextDepthVoltageLevels, Set<VoltageLevel> visitedVoltageLevels) {
public VlVisitor(Set<VoltageLevel> nextDepthVoltageLevels, Set<VoltageLevel> visitedVoltageLevels, Predicate<VoltageLevel> voltageLevelPredicate) {
this.nextDepthVoltageLevels = nextDepthVoltageLevels;
this.visitedVoltageLevels = visitedVoltageLevels;
this.voltageLevelPredicate = voltageLevelPredicate;
}

@Override
Expand Down Expand Up @@ -171,7 +172,7 @@ private void visitBranch(Branch<?> branch, Branch.Side side) {

private void visitTerminal(Terminal terminal) {
VoltageLevel voltageLevel = terminal.getVoltageLevel();
if (!visitedVoltageLevels.contains(voltageLevel)) {
if (!visitedVoltageLevels.contains(voltageLevel) && voltageLevelPredicate.test(voltageLevel)) {
nextDepthVoltageLevels.add(voltageLevel);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package com.powsybl.nad;

import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
import com.google.common.jimfs.Configuration;
Expand All @@ -25,13 +26,13 @@
import com.powsybl.nad.svg.iidm.NominalVoltageStyleProvider;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import ch.qos.logback.classic.Logger;
import org.slf4j.LoggerFactory;

import java.nio.file.FileSystem;
import java.nio.file.Path;
import java.util.List;

import static com.powsybl.nad.build.iidm.VoltageLevelFilter.NO_FILTER;
import static org.junit.jupiter.api.Assertions.*;

/**
Expand Down Expand Up @@ -68,7 +69,7 @@ void testDrawSvg() {
NadParameters nadParameters = new NadParameters()
.setSvgParameters(getSvgParameters())
.setStyleProviderFactory(this::getStyleProvider);
NetworkAreaDiagram.draw(network, svgFile, nadParameters, VoltageLevelFilter.NO_FILTER);
NetworkAreaDiagram.draw(network, svgFile, nadParameters, NO_FILTER);
assertEquals(toString("/dangling_line_connected.svg"), getContentFile(svgFile));
}

Expand Down Expand Up @@ -112,11 +113,15 @@ void testVoltageFilteredDiagramOutOfBound() {
logWatcher.start();
((Logger) LoggerFactory.getLogger(VoltageLevelFilter.class)).addAppender(logWatcher);
Network network = IeeeCdfNetworkFactory.create14();
Path svgFileVoltageFilter = fileSystem.getPath("nad-test-voltage-filter.svg");
List<String> voltageLevelList = List.of("VL4");
VoltageLevelFilter.createNominalVoltageUpperBoundFilter(network, voltageLevelList, 90, 2);
VoltageLevelFilter voltageLevelFilter = VoltageLevelFilter.createNominalVoltageUpperBoundFilter(network, voltageLevelList, 130, 2);
NetworkAreaDiagram.draw(network, svgFileVoltageFilter, new NadParameters(), voltageLevelFilter);

List<ILoggingEvent> logsList = logWatcher.list;
assertEquals(1, logsList.size());
assertEquals("vl 'VL4' has his nominal voltage out of the indicated thresholds", logsList.get(0).getFormattedMessage());
assertEquals("vl 'VL4' does not comply with the predicate", logsList.get(0).getFormattedMessage());
assertEquals(toString("/IEEE_14_bus_voltage_filter3.svg"), getContentFile(svgFileVoltageFilter));
}

@Test
Expand Down
Loading

0 comments on commit c6ee6ff

Please sign in to comment.