-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: lisrte <[email protected]>
- Loading branch information
Showing
7 changed files
with
141 additions
and
11 deletions.
There are no files selected for viewing
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
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
76 changes: 76 additions & 0 deletions
76
dynawaltz/src/test/java/com/powsybl/dynawaltz/ModelOptimizerTest.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,76 @@ | ||
/** | ||
* Copyright (c) 2023, 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/. | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
package com.powsybl.dynawaltz; | ||
|
||
import com.google.auto.service.AutoService; | ||
import com.google.common.collect.Lists; | ||
import com.powsybl.commons.reporter.Reporter; | ||
import com.powsybl.dynamicsimulation.DynamicSimulationParameters; | ||
import com.powsybl.dynawaltz.models.BlackBoxModel; | ||
import com.powsybl.dynawaltz.models.generators.AbstractGenerator; | ||
import com.powsybl.dynawaltz.models.generators.GeneratorFictitious; | ||
import com.powsybl.dynawaltz.models.loads.BaseLoad; | ||
import com.powsybl.dynawaltz.models.transformers.TransformerFixedRatio; | ||
import com.powsybl.iidm.network.Network; | ||
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.ServiceLoader; | ||
import java.util.stream.Stream; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
/** | ||
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>} | ||
*/ | ||
class ModelOptimizerTest { | ||
|
||
@Test | ||
void loadOptimizer() { | ||
List<ModelOptimizer> optimizers = Lists.newArrayList(ServiceLoader.load(ModelOptimizer.class)); | ||
assertEquals(2, optimizers.size()); | ||
} | ||
|
||
@Test | ||
void optimizeModels() { | ||
Network network = EurostagTutorialExample1Factory.create(); | ||
DynamicSimulationParameters parameters = DynamicSimulationParameters.load(); | ||
DynaWaltzParameters dynawoParameters = DynaWaltzParameters.load().setUseModelOptimizers(true); | ||
List<BlackBoxModel> dynamicModels = List.of( | ||
new GeneratorFictitious("BBM_GEN", network.getGenerator("GEN"), "GPV"), | ||
new BaseLoad("BBM_LOAD", network.getLoad("LOAD"), "LOAD", "LoadAlphaBeta"), | ||
new TransformerFixedRatio("BBM_TRA", network.getTwoWindingsTransformer("NGEN_NHV1"), "TR", "TransformerFixedRatio")); | ||
DynaWaltzContext context = new DynaWaltzContext(network, network.getVariantManager().getWorkingVariantId(), dynamicModels, Collections.emptyList(), Collections.emptyList(), parameters, dynawoParameters); | ||
assertEquals(2, context.getBlackBoxDynamicModels().size()); | ||
assertFalse(context.getBlackBoxDynamicModelStream().anyMatch(bbm -> bbm.getDynamicModelId().equalsIgnoreCase("BBM_LOAD"))); | ||
assertTrue(context.getBlackBoxDynamicModelStream().anyMatch(bbm -> bbm.getDynamicModelId().equalsIgnoreCase("newModel"))); | ||
} | ||
|
||
@AutoService(ModelOptimizer.class) | ||
public static class ModelOptimizerFilter implements ModelOptimizer { | ||
@Override | ||
public Stream<BlackBoxModel> optimizeModels(Stream<BlackBoxModel> models, DynaWaltzParameters dynaWaltzParameters, Reporter reporter) { | ||
return models.filter(m -> !m.getDynamicModelId().equalsIgnoreCase("BBM_LOAD")); | ||
} | ||
} | ||
|
||
@AutoService(ModelOptimizer.class) | ||
public static class ModelOptimizerSubstitution implements ModelOptimizer { | ||
@Override | ||
public Stream<BlackBoxModel> optimizeModels(Stream<BlackBoxModel> models, DynaWaltzParameters dynaWaltzParameters, Reporter reporter) { | ||
return models.map(m -> { | ||
if ("BBM_GEN".equalsIgnoreCase(m.getDynamicModelId()) && m instanceof AbstractGenerator gen) { | ||
return new GeneratorFictitious("newModel", gen.getEquipment(), "G"); | ||
} | ||
return m; | ||
}); | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
dynawaltz/src/test/java/com/powsybl/dynawaltz/models/HvdcTest.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,45 @@ | ||
/** | ||
* Copyright (c) 2023, 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/. | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
package com.powsybl.dynawaltz.models; | ||
|
||
import com.powsybl.dynawaltz.models.hvdc.HvdcP; | ||
import com.powsybl.dynawaltz.models.hvdc.HvdcPDangling; | ||
import com.powsybl.dynawaltz.models.hvdc.HvdcVscDangling; | ||
import com.powsybl.iidm.network.HvdcLine; | ||
import com.powsybl.iidm.network.Network; | ||
import com.powsybl.iidm.network.test.HvdcTestNetwork; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
/** | ||
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>} | ||
*/ | ||
class HvdcTest { | ||
|
||
@Test | ||
void testConnectedStation() { | ||
Network network = HvdcTestNetwork.createVsc(); | ||
HvdcP hvdc = new HvdcP("hvdc", network.getHvdcLine("L"), "HVDC", "HvdcPV"); | ||
assertEquals(2, hvdc.getConnectedStations().size()); | ||
} | ||
|
||
@Test | ||
void testDanglingConnectedStation() { | ||
Network network = HvdcTestNetwork.createVsc(); | ||
HvdcLine line = network.getHvdcLine("L"); | ||
|
||
HvdcPDangling hvdc = new HvdcPDangling("hvdc", line, "HVDC", "HvdcPVDangling", Side.ONE); | ||
assertEquals(1, hvdc.getConnectedStations().size()); | ||
assertEquals(line.getConverterStation2(), hvdc.getConnectedStations().get(0)); | ||
|
||
HvdcVscDangling hvdc2 = new HvdcVscDangling("hvdc", line, "HVDC", "HvdcVSCDanglingP", Side.TWO); | ||
assertEquals(1, hvdc.getConnectedStations().size()); | ||
assertEquals(line.getConverterStation1(), hvdc2.getConnectedStations().get(0)); | ||
} | ||
} |