DefaultNetworkReducer extends AbstractNetworkReducer { @Override protected void reduce(Substation substation) { substation.remove(); observers.forEach(o -> o.substationRemoved(substation)); } DefaultNetworkReducer(NetworkPredicate predicate, ReductionOptions options);  DefaultNetworkReducer(NetworkPredicate predicate, ReductionOptions options, NetworkReducerObserver... observers);  DefaultNetworkReducer(NetworkPredicate predicate, ReductionOptions options, List<NetworkReducerObserver> observers);   }
@Test public void testLoad() { Network network = EurostagTutorialExample1Factory.createWithLFResults(); NetworkReducerObserverImpl observer = new NetworkReducerObserverImpl(); NetworkReducer reducer = NetworkReducer.builder() .withNetworkPredicate(IdentifierNetworkPredicate.of("P1")) .withObservers(observer) .build(); reducer.reduce(network); assertEquals(1, network.getSubstationCount()); assertEquals(2, network.getVoltageLevelCount()); assertEquals(1, network.getTwoWindingsTransformerCount()); assertEquals(0, network.getLineCount()); assertEquals(1, network.getGeneratorCount()); assertEquals(2, network.getLoadCount()); assertEquals(0, network.getDanglingLineCount()); Load load1 = network.getLoad(NHV1_NHV2_1); assertNotNull(load1); assertEquals(LoadType.FICTITIOUS, load1.getLoadType()); assertEquals(302.4440612792969, load1.getP0(), 0.0); assertEquals(98.74027252197266, load1.getQ0(), 0.0); assertEquals(302.4440612792969, load1.getTerminal().getP(), 0.0); assertEquals(98.74027252197266, load1.getTerminal().getQ(), 0.0); Load load2 = network.getLoad(NHV1_NHV2_2); assertNotNull(load2); assertEquals(LoadType.FICTITIOUS, load2.getLoadType()); assertEquals(302.4440612792969, load2.getP0(), 0.0); assertEquals(98.74027252197266, load2.getQ0(), 0.0); assertEquals(302.4440612792969, load2.getTerminal().getP(), 0.0); assertEquals(98.74027252197266, load2.getTerminal().getQ(), 0.0); assertEquals(1, observer.getSubstationRemovedCount()); assertEquals(2, observer.getVoltageLevelRemovedCount()); assertEquals(2, observer.getLineReplacedCount()); assertEquals(2, observer.getLineRemovedCount()); assertEquals(0, observer.getTwoWindingsTransformerReplacedCount()); assertEquals(1, observer.getTwoWindingsTransformerRemovedCount()); assertEquals(0, observer.getThreeWindingsTransformerReplacedCount()); assertEquals(0, observer.getThreeWindingsTransformerRemovedCount()); assertEquals(0, observer.getHvdcLineReplacedCount()); assertEquals(0, observer.getHvdcLineRemovedCount()); }
@Test public void testLoad2() { Network network = EurostagTutorialExample1Factory.createWithLFResults(); NetworkReducerObserverImpl observer = new NetworkReducerObserverImpl(); NetworkReducer reducer = NetworkReducer.builder() .withNetworkPredicate(new NominalVoltageNetworkPredicate(225.0, 400.0)) .withObservers(observer) .build(); reducer.reduce(network); assertEquals(2, network.getSubstationCount()); assertEquals(2, network.getVoltageLevelCount()); assertEquals(0, network.getTwoWindingsTransformerCount()); assertEquals(2, network.getLineCount()); assertEquals(0, network.getGeneratorCount()); assertEquals(2, network.getLoadCount()); assertEquals(0, network.getDanglingLineCount()); Load load1 = network.getLoad("NGEN_NHV1"); assertNotNull(load1); assertEquals(LoadType.FICTITIOUS, load1.getLoadType()); assertEquals(-604.8909301757812, load1.getP0(), 0.0); assertEquals(-197.48046875, load1.getQ0(), 0.0); assertEquals(-604.8909301757812, load1.getTerminal().getP(), 0.0); assertEquals(-197.48046875, load1.getTerminal().getQ(), 0.0); Load load2 = network.getLoad("NHV2_NLOAD"); assertNotNull(load2); assertEquals(LoadType.FICTITIOUS, load2.getLoadType()); assertEquals(600.8677978515625, load2.getP0(), 0.0); assertEquals(274.3769836425781, load2.getQ0(), 0.0); assertEquals(600.8677978515625, load2.getTerminal().getP(), 0.0); assertEquals(274.3769836425781, load2.getTerminal().getQ(), 0.0); assertEquals(0, observer.getSubstationRemovedCount()); assertEquals(2, observer.getVoltageLevelRemovedCount()); assertEquals(0, observer.getLineReplacedCount()); assertEquals(0, observer.getLineRemovedCount()); assertEquals(2, observer.getTwoWindingsTransformerReplacedCount()); assertEquals(2, observer.getTwoWindingsTransformerRemovedCount()); assertEquals(0, observer.getThreeWindingsTransformerReplacedCount()); assertEquals(0, observer.getThreeWindingsTransformerRemovedCount()); assertEquals(0, observer.getHvdcLineRemovedCount()); assertEquals(0, observer.getHvdcLineRemovedCount()); }
@Test public void testDanglingLine() { Network network = EurostagTutorialExample1Factory.createWithLFResults(); NetworkReducer reducer = NetworkReducer.builder() .withNetworkPredicate(IdentifierNetworkPredicate.of("P2")) .withDanglingLines(true) .build(); reducer.reduce(network); assertEquals(1, network.getSubstationCount()); assertEquals(2, network.getVoltageLevelCount()); assertEquals(1, network.getTwoWindingsTransformerCount()); assertEquals(0, network.getLineCount()); assertEquals(0, network.getGeneratorCount()); assertEquals(1, network.getLoadCount()); assertEquals(2, network.getDanglingLineCount()); DanglingLine dl1 = network.getDanglingLine(NHV1_NHV2_1); assertNotNull(dl1); assertEquals(1.5, dl1.getR(), 0.0); assertEquals(16.5, dl1.getX(), 0.0); assertEquals(0.0, dl1.getG(), 0.0); assertEquals(1.93e-4, dl1.getB(), 0.0); assertEquals(-300.43389892578125, dl1.getP0(), 0.0); assertEquals(-137.18849182128906, dl1.getQ0(), 0.0); assertEquals(-300.43389892578125, dl1.getTerminal().getP(), 0.0); assertEquals(-137.18849182128906, dl1.getTerminal().getQ(), 0.0); DanglingLine dl2 = network.getDanglingLine(NHV1_NHV2_2); assertNotNull(dl2); assertEquals(1.5, dl2.getR(), 0.0); assertEquals(16.5, dl2.getX(), 0.0); assertEquals(0.0, dl2.getG(), 0.0); assertEquals(1.93e-4, dl2.getB(), 0.0); assertEquals(-300.43389892578125, dl2.getP0(), 0.0); assertEquals(-137.18849182128906, dl2.getQ0(), 0.0); assertEquals(-300.43389892578125, dl2.getTerminal().getP(), 0.0); assertEquals(-137.18849182128906, dl2.getTerminal().getQ(), 0.0); }
@Test public void testFailure() { thrown.expect(PowsyblException.class); thrown.expectMessage("The active power of 'NHV1_NHV2_1' (VLHV1) is not set. Do you forget to compute the flows?"); Network network = EurostagTutorialExample1Factory.create(); NetworkReducer reducer = NetworkReducer.builder() .withNetworkPredicate(IdentifierNetworkPredicate.of("P1")) .build(); reducer.reduce(network); }
@Test public void testWithDisconnectedLines() { Network network = EurostagTutorialExample1Factory.create(); Line line1 = network.getLine(NHV1_NHV2_1); line1.getTerminal1().disconnect(); line1.getTerminal2().disconnect(); Line line2 = network.getLine(NHV1_NHV2_2); line2.getTerminal1().disconnect(); line2.getTerminal2().disconnect(); NetworkReducer reducer = NetworkReducer.builder() .withNetworkPredicate(IdentifierNetworkPredicate.of("P1")) .build(); reducer.reduce(network); Load load1 = network.getLoad(NHV1_NHV2_1); assertEquals(0.0, load1.getP0(), 0.0); assertEquals(0.0, load1.getQ0(), 0.0); assertTrue(Double.isNaN(load1.getTerminal().getP())); assertTrue(Double.isNaN(load1.getTerminal().getQ())); Load load2 = network.getLoad(NHV1_NHV2_2); assertEquals(0.0, load2.getP0(), 0.0); assertEquals(0.0, load2.getQ0(), 0.0); assertTrue(Double.isNaN(load2.getTerminal().getP())); assertTrue(Double.isNaN(load2.getTerminal().getQ())); }
@Test public void testHvdc() { Network network = HvdcTestNetwork.createLcc(); assertEquals(1, network.getHvdcLineCount()); NetworkReducerObserverImpl observer = new NetworkReducerObserverImpl(); NetworkReducer reducer = NetworkReducer.builder() .withNetworkPredicate(IdentifierNetworkPredicate.of("VL1", "VL2")) .withObservers(observer) .build(); reducer.reduce(network); assertEquals(1, network.getHvdcLineCount()); assertEquals(0, observer.getHvdcLineReplacedCount()); assertEquals(0, observer.getHvdcLineRemovedCount()); reducer = NetworkReducer.builder() .withNetworkPredicate(new IdentifierNetworkPredicate(Collections.emptyList())) .withObservers(Collections.singleton(observer)) .build(); reducer.reduce(network); assertEquals(0, network.getHvdcLineCount()); assertEquals(0, observer.getHvdcLineReplacedCount()); assertEquals(1, observer.getHvdcLineRemovedCount()); }
@Test public void testHvdcFailure() { thrown.expect(UnsupportedOperationException.class); thrown.expectMessage("Reduction of HVDC lines is not supported"); Network network = HvdcTestNetwork.createLcc(); NetworkReducer reducer = NetworkReducer.builder() .withNetworkPredicate(IdentifierNetworkPredicate.of("VL1")) .withReductionOptions(new ReductionOptions()) .build(); reducer.reduce(network); }
@Test public void test3WT() { Network network = ThreeWindingsTransformerNetworkFactory.create(); assertEquals(1, network.getThreeWindingsTransformerCount()); NetworkReducerObserverImpl observer = new NetworkReducerObserverImpl(); NetworkReducer reducer = NetworkReducer.builder() .withNetworkPredicate(IdentifierNetworkPredicate.of("VL_132", "VL_33", "VL_11")) .withObservers(observer) .build(); reducer.reduce(network); assertEquals(1, network.getThreeWindingsTransformerCount()); assertEquals(0, observer.getThreeWindingsTransformerReplacedCount()); assertEquals(0, observer.getThreeWindingsTransformerRemovedCount()); reducer = NetworkReducer.builder() .withNetworkPredicate(new IdentifierNetworkPredicate(Collections.emptyList())) .withObservers(Collections.singleton(observer)) .build(); reducer.reduce(network); assertEquals(0, network.getThreeWindingsTransformerCount()); assertEquals(0, observer.getThreeWindingsTransformerReplacedCount()); assertEquals(1, observer.getThreeWindingsTransformerRemovedCount()); }
@Test public void test3WTFailure() { thrown.expect(UnsupportedOperationException.class); thrown.expectMessage("Reduction of three-windings transformers is not supported"); Network network = ThreeWindingsTransformerNetworkFactory.create(); NetworkReducer reducer = NetworkReducer.builder() .withNetworkPredicate(IdentifierNetworkPredicate.of("VL_132", "VL_11")) .withReductionOptions(new ReductionOptions()) .build(); reducer.reduce(network); }