Skip to content

Commit

Permalink
Use second selector level as fallback selector in NameSlackBusSelector (
Browse files Browse the repository at this point in the history
#632)

Signed-off-by: Anne Tilloy <[email protected]>
Co-authored-by: Geoffroy Jamgotchian <[email protected]>
  • Loading branch information
annetill and geofjamg authored Oct 20, 2022
1 parent 34eabfa commit 8ef2495
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
*/
package com.powsybl.openloadflow.network;

import com.powsybl.commons.PowsyblException;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -55,6 +53,7 @@ public SelectedSlackBus select(List<LfBus> buses) {
}
}
}
throw new PowsyblException("None of the buses or voltage levels " + busesOrVoltageLevelsIds + " have been found");
// fallback to automatic selection among all buses
return secondLevelSelector.select(buses);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;
import com.powsybl.commons.PowsyblException;
import com.powsybl.commons.config.InMemoryPlatformConfig;
import com.powsybl.commons.config.MapModuleConfig;
import com.powsybl.commons.config.PlatformConfig;
Expand All @@ -35,6 +34,7 @@
import java.util.Map;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* @author Jérémy Labous <jlabous at silicom.fr>
Expand Down Expand Up @@ -154,8 +154,7 @@ void testNameSlackBusSelector() throws IOException {
assertEquals(SlackBusSelectionMode.NAME, olfParameters.getSlackBusSelectionMode());
List<LfNetwork> lfNetworks = Networks.load(EurostagTutorialExample1Factory.create(), SlackBusSelector.fromMode(olfParameters.getSlackBusSelectionMode(), olfParameters.getSlackBusesIds(), olfParameters.getPlausibleActivePowerLimit()));
LfNetwork lfNetwork = lfNetworks.get(0);
PowsyblException thrown = assertThrows(PowsyblException.class, lfNetwork::getSlackBus);
assertEquals("None of the buses or voltage levels [???] have been found", thrown.getMessage());
assertEquals("VLHV1_0", lfNetwork.getSlackBus().getId()); // fallback to automatic method.
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
package com.powsybl.openloadflow.network;

import com.powsybl.commons.PowsyblException;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import com.powsybl.openloadflow.network.impl.Networks;
Expand All @@ -16,7 +15,6 @@
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
Expand All @@ -42,15 +40,6 @@ void test() {
assertEquals("VLLOAD_0", lfNetwork.getSlackBus().getId());
}

@Test
void errorTest() {
NameSlackBusSelector slackBusSelector = new NameSlackBusSelector("???");
List<LfNetwork> lfNetworks = Networks.load(network, slackBusSelector);
LfNetwork lfNetwork = lfNetworks.get(0);
assertThrows(PowsyblException.class, () -> lfNetwork.getSlackBus(),
"Slack bus '???' not found");
}

@Test
void voltageLevelIdTest() {
List<LfNetwork> lfNetworks = Networks.load(network, new NameSlackBusSelector("VLGEN"));
Expand Down

0 comments on commit 8ef2495

Please sign in to comment.