-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loader post processor selection (#589)
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
- Loading branch information
Showing
6 changed files
with
163 additions
and
6 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/main/java/com/powsybl/openloadflow/network/AbstractLfNetworkLoaderPostProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Copyright (c) 2022, 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 com.powsybl.openloadflow.network; | ||
|
||
/** | ||
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com> | ||
*/ | ||
public abstract class AbstractLfNetworkLoaderPostProcessor implements LfNetworkLoaderPostProcessor { | ||
|
||
@Override | ||
public LoadingPolicy getLoadingPolicy() { | ||
return LoadingPolicy.ALWAYS; | ||
} | ||
|
||
@Override | ||
public void onBusAdded(Object element, LfBus lfBus) { | ||
// to implement | ||
} | ||
|
||
@Override | ||
public void onBranchAdded(Object element, LfBranch lfBranch) { | ||
// to implement | ||
} | ||
|
||
@Override | ||
public void onInjectionAdded(Object element, LfBus lfBus) { | ||
// to implement | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/test/java/com/powsybl/openloadflow/network/LfNetworkLoaderPostProcessorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/** | ||
* Copyright (c) 2022, 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 com.powsybl.openloadflow.network; | ||
|
||
import com.powsybl.iidm.network.Network; | ||
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; | ||
import com.powsybl.openloadflow.network.impl.LfNetworkLoaderImpl; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
/** | ||
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com> | ||
*/ | ||
class LfNetworkLoaderPostProcessorTest { | ||
|
||
private static final String PP_1 = "PP1"; | ||
private static final String PP_2 = "PP2"; | ||
|
||
private Network network; | ||
private LfNetworkParameters parameters; | ||
|
||
private LfNetworkLoaderPostProcessor pp1; | ||
private LfNetworkLoaderPostProcessor pp2; | ||
|
||
private boolean pp1Activated; | ||
private boolean pp2Activated; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
network = EurostagTutorialExample1Factory.create(); | ||
parameters = new LfNetworkParameters(); | ||
|
||
pp1 = new AbstractLfNetworkLoaderPostProcessor() { | ||
@Override | ||
public String getName() { | ||
return PP_1; | ||
} | ||
|
||
@Override | ||
public void onBusAdded(Object element, LfBus lfBus) { | ||
pp1Activated = true; | ||
} | ||
}; | ||
|
||
pp2 = new AbstractLfNetworkLoaderPostProcessor() { | ||
@Override | ||
public String getName() { | ||
return PP_2; | ||
} | ||
|
||
@Override | ||
public LoadingPolicy getLoadingPolicy() { | ||
return LoadingPolicy.SELECTION; | ||
} | ||
|
||
@Override | ||
public void onBusAdded(Object element, LfBus lfBus) { | ||
pp2Activated = true; | ||
} | ||
}; | ||
|
||
pp1Activated = false; | ||
pp2Activated = false; | ||
} | ||
|
||
@Test | ||
void test1() { | ||
LfNetwork.load(network, new LfNetworkLoaderImpl(() -> List.of(pp1, pp2)), parameters); | ||
assertTrue(pp1Activated); | ||
assertFalse(pp2Activated); | ||
} | ||
|
||
@Test | ||
void test2() { | ||
parameters.setLoaderPostProcessorSelection(Set.of(PP_2)); | ||
LfNetwork.load(network, new LfNetworkLoaderImpl(() -> List.of(pp1, pp2)), parameters); | ||
assertTrue(pp1Activated); | ||
assertTrue(pp2Activated); | ||
} | ||
} |