-
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.
Handle sided contingencies in DynaFlow and Dynawo SA (#412)
* Handle sided contingencies in DynaFlow and Dynawo SA * Add ContingencyEventModelsTest Signed-off-by: lisrte <laurent.issertial@rte-france.com>
- Loading branch information
Showing
10 changed files
with
228 additions
and
51 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
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
104 changes: 104 additions & 0 deletions
104
...ity-analysis/src/main/java/com/powsybl/dynawo/security/ContingencyEventModelsFactory.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,104 @@ | ||
/** | ||
* Copyright (c) 2024, 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.dynawo.security; | ||
|
||
import com.powsybl.commons.PowsyblException; | ||
import com.powsybl.commons.report.ReportNode; | ||
import com.powsybl.contingency.Contingency; | ||
import com.powsybl.contingency.ContingencyElement; | ||
import com.powsybl.contingency.SidedContingencyElement; | ||
import com.powsybl.dynawo.DynawoSimulationContext; | ||
import com.powsybl.dynawo.models.BlackBoxModel; | ||
import com.powsybl.dynawo.models.events.ContextDependentEvent; | ||
import com.powsybl.dynawo.models.events.EventDisconnectionBuilder; | ||
import com.powsybl.dynawo.models.macroconnections.MacroConnect; | ||
import com.powsybl.dynawo.models.macroconnections.MacroConnectionsAdder; | ||
import com.powsybl.dynawo.models.macroconnections.MacroConnector; | ||
import com.powsybl.dynawo.parameters.ParametersSet; | ||
import com.powsybl.iidm.network.Network; | ||
import com.powsybl.iidm.network.TwoSides; | ||
|
||
import java.util.*; | ||
|
||
/** | ||
* @author Laurent Issertial <laurent.issertial at rte-france.com> | ||
*/ | ||
public final class ContingencyEventModelsFactory { | ||
|
||
public static List<ContingencyEventModels> createFrom(List<Contingency> contingencies, DynawoSimulationContext context, | ||
MacroConnectionsAdder macroConnectionsAdder, | ||
double contingenciesStartTime, | ||
ReportNode reportNode) { | ||
return contingencies.stream() | ||
.map(c -> createFrom(c, context, macroConnectionsAdder, contingenciesStartTime, reportNode)) | ||
.filter(Objects::nonNull) | ||
.toList(); | ||
} | ||
|
||
public static ContingencyEventModels createFrom(Contingency contingency, DynawoSimulationContext context, | ||
MacroConnectionsAdder macroConnectionsAdder, | ||
double contingenciesStartTime, | ||
ReportNode reportNode) { | ||
List<BlackBoxModel> eventModels = createContingencyEventModelList(contingency, context, contingenciesStartTime, reportNode); | ||
if (eventModels.isEmpty()) { | ||
return null; | ||
} | ||
Map<String, MacroConnector> macroConnectorsMap = new HashMap<>(); | ||
List<MacroConnect> macroConnectList = new ArrayList<>(); | ||
List<ParametersSet> eventParameters = new ArrayList<>(eventModels.size()); | ||
// Set Contingencies connections and parameters | ||
macroConnectionsAdder.setMacroConnectorAdder(macroConnectorsMap::computeIfAbsent); | ||
macroConnectionsAdder.setMacroConnectAdder(macroConnectList::add); | ||
eventModels.forEach(em -> { | ||
em.createMacroConnections(macroConnectionsAdder); | ||
em.createDynamicModelParameters(context, eventParameters::add); | ||
}); | ||
return new ContingencyEventModels(contingency, eventModels, macroConnectorsMap, macroConnectList, eventParameters); | ||
} | ||
|
||
private static List<BlackBoxModel> createContingencyEventModelList(Contingency contingency, | ||
DynawoSimulationContext context, | ||
double contingenciesStartTime, | ||
ReportNode reportNode) { | ||
return contingency.getElements().stream() | ||
.map(ce -> createContingencyEventModel(ce, context, contingenciesStartTime, reportNode)) | ||
.filter(Objects::nonNull) | ||
.toList(); | ||
} | ||
|
||
private static BlackBoxModel createContingencyEventModel(ContingencyElement element, | ||
DynawoSimulationContext context, | ||
double contingenciesStartTime, | ||
ReportNode reportNode) { | ||
Network network = context.getNetwork(); | ||
EventDisconnectionBuilder builder = EventDisconnectionBuilder.of(network) | ||
.staticId(element.getId()) | ||
.startTime(contingenciesStartTime); | ||
if (element instanceof SidedContingencyElement sidedElement && sidedElement.getVoltageLevelId() != null) { | ||
TwoSides side = SidedContingencyElement.getContingencySide(network, sidedElement); | ||
if (side != null) { | ||
builder.disconnectOnly(side); | ||
} else { | ||
DynamicSecurityAnalysisReports.createContingencyVoltageIdNotFoundReportNode(reportNode, | ||
sidedElement.getId(), sidedElement.getVoltageLevelId()); | ||
return null; | ||
} | ||
} | ||
BlackBoxModel bbm = builder.build(); | ||
if (bbm == null) { | ||
throw new PowsyblException("Contingency element " + element.getType() + " not supported"); | ||
} | ||
if (bbm instanceof ContextDependentEvent cde) { | ||
cde.setEquipmentHasDynamicModel(context); | ||
} | ||
return bbm; | ||
} | ||
|
||
private ContingencyEventModelsFactory() { | ||
} | ||
} |
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
79 changes: 79 additions & 0 deletions
79
...curity-analysis/src/test/java/com/powsybl/dynawo/security/ContingencyEventModelsTest.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,79 @@ | ||
/** | ||
* Copyright (c) 2024, 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.dynawo.security; | ||
|
||
import com.powsybl.commons.report.ReportNode; | ||
import com.powsybl.contingency.Contingency; | ||
import com.powsybl.dynamicsimulation.DynamicSimulationParameters; | ||
import com.powsybl.dynawo.DynawoSimulationContext; | ||
import com.powsybl.dynawo.DynawoSimulationParameters; | ||
import com.powsybl.dynawo.models.BlackBoxModel; | ||
import com.powsybl.dynawo.models.generators.BaseGeneratorBuilder; | ||
import com.powsybl.dynawo.models.macroconnections.MacroConnectionsAdder; | ||
import com.powsybl.dynawo.models.macroconnections.MacroConnector; | ||
import com.powsybl.dynawo.parameters.ParametersSet; | ||
import com.powsybl.iidm.network.Network; | ||
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.*; | ||
|
||
import static com.powsybl.iidm.network.test.EurostagTutorialExample1Factory.*; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
/** | ||
* @author Laurent Issertial {@literal <laurent.issertial at rte-france.com>} | ||
*/ | ||
class ContingencyEventModelsTest { | ||
|
||
@Test | ||
void test() { | ||
Network network = EurostagTutorialExample1Factory.create(); | ||
List<BlackBoxModel> dynamicModels = List.of( | ||
BaseGeneratorBuilder.of(network) | ||
.staticId("GEN") | ||
.parameterSetId("gen") | ||
.build()); | ||
DynawoSimulationContext context = setupDynawoContext(network, dynamicModels); | ||
MacroConnectionsAdder macroConnectionsAdder = new MacroConnectionsAdder(context::getDynamicModel, | ||
context::getPureDynamicModel, | ||
new ArrayList<>()::add, | ||
new HashMap<String, MacroConnector>()::computeIfAbsent, | ||
ReportNode.NO_OP); | ||
List<Contingency> contingencies = List.of( | ||
Contingency.load("LOAD"), | ||
Contingency.generator("GEN"), | ||
Contingency.line(NHV1_NHV2_1, VLHV1), | ||
Contingency.branch(NHV1_NHV2_2, "WRONG_ID")); | ||
|
||
List<ContingencyEventModels> contingencyEvents = ContingencyEventModelsFactory.createFrom(contingencies, context, | ||
macroConnectionsAdder, 2, ReportNode.NO_OP); | ||
assertThat(contingencyEvents).hasSize(3); | ||
assertThat(contingencyEvents.get(0).eventModels()) | ||
.hasSize(1) | ||
.map(BlackBoxModel::getLib).containsExactly("EventConnectedStatus"); | ||
assertThat(contingencyEvents.get(1).eventModels()) | ||
.hasSize(1) | ||
.map(BlackBoxModel::getLib).containsExactly("EventSetPointBoolean"); | ||
assertThat(contingencyEvents.get(2).eventModels()) | ||
.hasSize(1) | ||
.map(BlackBoxModel::getLib).containsExactly("EventQuadripoleDisconnection"); | ||
ParametersSet parametersSet = contingencyEvents.get(2).eventParameters().get(0); | ||
assertTrue(parametersSet.getBool("event_disconnectOrigin")); | ||
assertFalse(parametersSet.getBool("event_disconnectExtremity")); | ||
} | ||
|
||
private DynawoSimulationContext setupDynawoContext(Network network, List<BlackBoxModel> dynamicModels) { | ||
DynamicSimulationParameters parameters = DynamicSimulationParameters.load(); | ||
DynawoSimulationParameters dynawoParameters = DynawoSimulationParameters.load(); | ||
return new DynawoSimulationContext(network, network.getVariantManager().getWorkingVariantId(), dynamicModels, | ||
Collections.emptyList(), Collections.emptyList(), parameters, dynawoParameters); | ||
} | ||
} |