-
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.
Add dynawo dynamic security analysis (#277)
* Refactor Macro connections creation: add MacroConnectionsAdder, MultipleJobsXml, ContingenciesDydXml && ContingenciesParXml * Refactor providers * Add DynaWaltzSecurityAnalysisProvider and Handler * Use DynamicSecurityAnalysisParameters * Fix contingencies Dyd parameter file name * Create dynamic security analysis module * Refactor provider/handler/config * Add integration test * Rename dynawaltz to dynawo for DSA * Update readthedocs Signed-off-by: lisrte <[email protected]>
- Loading branch information
Showing
67 changed files
with
2,036 additions
and
578 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Configuration | ||
|
||
## Dynawo-algorithms properties | ||
The `dynawo-algorithms` module defines the required parameters to run with Dynawo. | ||
|
||
**homeDir** | ||
Use the `homeDir` property to defines the installation directory of the dynawo simulator. | ||
|
||
**debug** | ||
Use the `debug` property to specify if the temporary folder where the inputs are generated should be kept after the simulation. | ||
|
||
### Examples | ||
|
||
**YAML configuration:** | ||
```yaml | ||
dynawo-algorithms: | ||
homeDir: /home/user/dynawo-algorithms | ||
debug: false | ||
``` | ||
**XML configuration:** | ||
```xml | ||
<dynawo-algorithms> | ||
<homeDir>/home/user/dynawo</homeDir> | ||
<debug>false</debug> | ||
</dynawo-algorithms> | ||
``` | ||
|
||
## Default parameters | ||
The dynamic security analysis reuse the `dynawo-default-parameters` [module](../dynamic_simulation/configuration.md#default-parameters). |
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,18 @@ | ||
# Dynamic security analysis | ||
|
||
```{toctree} | ||
:hidden: | ||
configuration.md | ||
``` | ||
|
||
PowSyBl provides an implementation of the [DynamicSecurityAnalysis API from powsybl-core](inv:powsyblcore:*:*#simulation/dynamic_security/index) with [Dynaωo-algorithms](https://dynawo.github.io/about/dynalgo), a wrapper around [Dynaωo](https://dynawo.github.io) providing utility algorithms to calculate complex key values of a power system. | ||
|
||
## Installation | ||
|
||
Read this [documentation page](https://dynawo.github.io/install/dynalgo) to learn how to install and configure Dynaωo-algorithms. | ||
|
||
## Going further | ||
|
||
You may find an extensive documentation of the Dynawo project [here](https://github.com/dynawo/dynawo/releases/latest/download/DynawoDocumentation.pdf). | ||
The dynamic security analysis use the same dynamic models supplier as the dynamic simulation implementation, documentation can be found [here](../dynamic_simulation/dynamic-models-dsl.md). | ||
|
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
# Powsybl-dynawo documentation | ||
Powsybl-dynawo is an interface between PowSyBl and [Dynaωo](https://dynawo.github.io) open source suites, providing: | ||
- an implementation of [LoadFlow API from powsybl-core](inv:powsyblcore:*:*#simulation/loadflow/index), | ||
- an implementation of [SecurityAnalysis API from powsybl-core](inv:powsyblcore:*:*#simulation/security/index), | ||
- an implementation of [DynamicSimulation API from powsybl-core](inv:powsyblcore:*:*#simulation/dynamic/index). | ||
Powsybl-dynawo is an interface between PowSyBl and [Dynaωo](https://dynawo.github.io) open source suites, providing implementations of: | ||
- [LoadFlow API from powsybl-core](inv:powsyblcore:*:*#simulation/loadflow/index), | ||
- [SecurityAnalysis API from powsybl-core](inv:powsyblcore:*:*#simulation/security/index), | ||
- [DynamicSimulation API from powsybl-core](inv:powsyblcore:*:*#simulation/dynamic/index), | ||
- [DynamicSecurityAnalysis API from powsybl-core](inv:powsyblcore:*:*#simulation/dynamic_security/index). | ||
|
||
```{toctree} | ||
:hidden: | ||
load_flow/index.md | ||
dynamic_simulation/index.md | ||
dynamic_security_analysis/index.md | ||
``` |
File renamed without changes.
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
81 changes: 81 additions & 0 deletions
81
dynaflow/src/main/java/com/powsybl/dynaflow/ContingencyResultsUtils.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,81 @@ | ||
/** | ||
* 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.dynaflow; | ||
|
||
import com.powsybl.commons.report.ReportNode; | ||
import com.powsybl.contingency.Contingency; | ||
import com.powsybl.dynaflow.xml.ConstraintsReader; | ||
import com.powsybl.dynawo.commons.CommonReports; | ||
import com.powsybl.dynawo.commons.timeline.TimelineEntry; | ||
import com.powsybl.dynawo.commons.timeline.XmlTimeLineParser; | ||
import com.powsybl.iidm.network.Network; | ||
import com.powsybl.loadflow.LoadFlowResult; | ||
import com.powsybl.security.*; | ||
import com.powsybl.security.results.NetworkResult; | ||
import com.powsybl.security.results.PostContingencyResult; | ||
import com.powsybl.security.results.PreContingencyResult; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* @author Laurent Issertial <laurent.issertial at rte-france.com> | ||
*/ | ||
public final class ContingencyResultsUtils { | ||
|
||
private ContingencyResultsUtils() { | ||
} | ||
|
||
/** | ||
* Build the pre-contingency results from the input network | ||
*/ | ||
public static PreContingencyResult getPreContingencyResult(Network network, LimitViolationFilter violationFilter) { | ||
List<LimitViolation> limitViolations = Security.checkLimits(network); | ||
List<LimitViolation> filteredViolations = violationFilter.apply(limitViolations, network); | ||
NetworkResult networkResult = new NetworkResult(Collections.emptyList(), Collections.emptyList(), Collections.emptyList()); | ||
return new PreContingencyResult(LoadFlowResult.ComponentResult.Status.CONVERGED, new LimitViolationsResult(filteredViolations), networkResult); | ||
} | ||
|
||
/** | ||
* Build the post-contingency results from the constraints files written by dynawo | ||
*/ | ||
public static List<PostContingencyResult> getPostContingencyResults(Network network, LimitViolationFilter violationFilter, | ||
Path constraintsDir, List<Contingency> contingencies) { | ||
return contingencies.stream() | ||
.map(c -> getPostContingencyResult(network, violationFilter, constraintsDir, c)) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private static PostContingencyResult getPostContingencyResult(Network network, LimitViolationFilter violationFilter, | ||
Path constraintsDir, Contingency contingency) { | ||
Path constraintsFile = constraintsDir.resolve("constraints_" + contingency.getId() + ".xml"); | ||
if (Files.exists(constraintsFile)) { | ||
List<LimitViolation> limitViolationsRead = ConstraintsReader.read(network, constraintsFile); | ||
List<LimitViolation> limitViolationsFiltered = violationFilter.apply(limitViolationsRead, network); | ||
return new PostContingencyResult(contingency, PostContingencyComputationStatus.CONVERGED, new LimitViolationsResult(limitViolationsFiltered)); | ||
} else { | ||
return new PostContingencyResult(contingency, PostContingencyComputationStatus.FAILED, Collections.emptyList()); | ||
} | ||
} | ||
|
||
// Report the timeline events from the timeline files written by dynawo | ||
public static void reportContingenciesTimelines(List<Contingency> contingencies, Path timelineDir, ReportNode reportNode) { | ||
contingencies.forEach(c -> { | ||
ReportNode contingencyReporter = DynaflowReports.createContingenciesTimelineReportNode(reportNode, c.getId()); | ||
getTimeline(timelineDir, c).forEach(e -> CommonReports.reportTimelineEntry(contingencyReporter, e)); | ||
}); | ||
} | ||
|
||
private static List<TimelineEntry> getTimeline(Path timelineDir, Contingency c) { | ||
Path timelineFile = timelineDir.resolve("timeline_" + c.getId() + ".xml"); | ||
return new XmlTimeLineParser().parse(timelineFile); | ||
} | ||
} |
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
108 changes: 108 additions & 0 deletions
108
dynaflow/src/main/java/com/powsybl/dynaflow/DynaFlowHandler.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,108 @@ | ||
/** | ||
* 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.dynaflow; | ||
|
||
import com.powsybl.commons.report.ReportNode; | ||
import com.powsybl.computation.AbstractExecutionHandler; | ||
import com.powsybl.computation.Command; | ||
import com.powsybl.computation.CommandExecution; | ||
import com.powsybl.computation.ExecutionReport; | ||
import com.powsybl.dynaflow.json.DynaFlowConfigSerializer; | ||
import com.powsybl.dynawo.commons.CommonReports; | ||
import com.powsybl.dynawo.commons.DynawoUtil; | ||
import com.powsybl.dynawo.commons.NetworkResultsUpdater; | ||
import com.powsybl.dynawo.commons.loadmerge.LoadsMerger; | ||
import com.powsybl.dynawo.commons.timeline.TimelineEntry; | ||
import com.powsybl.dynawo.commons.timeline.XmlTimeLineParser; | ||
import com.powsybl.iidm.network.Network; | ||
import com.powsybl.iidm.serde.NetworkSerDe; | ||
import com.powsybl.loadflow.LoadFlowParameters; | ||
import com.powsybl.loadflow.LoadFlowResult; | ||
import com.powsybl.loadflow.LoadFlowResultImpl; | ||
import com.powsybl.loadflow.json.LoadFlowResultDeserializer; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static com.powsybl.dynaflow.DynaFlowConstants.*; | ||
import static com.powsybl.dynawo.commons.DynawoConstants.DYNAWO_TIMELINE_FOLDER; | ||
import static com.powsybl.dynawo.commons.DynawoUtil.getCommandExecutions; | ||
|
||
/** | ||
* @author Laurent Issertial <laurent.issertial at rte-france.com> | ||
*/ | ||
public class DynaFlowHandler extends AbstractExecutionHandler<LoadFlowResult> { | ||
private final Network network; | ||
private final Network dynawoInput; | ||
private final String workingStateId; | ||
private final DynaFlowParameters dynaFlowParameters; | ||
private final LoadFlowParameters loadFlowParameters; | ||
private final Command command; | ||
private final ReportNode reportNode; | ||
|
||
public DynaFlowHandler(Network network, String workingStateId, DynaFlowParameters dynaFlowParameters, LoadFlowParameters loadFlowParameters, Command command, ReportNode reportNode) { | ||
this.network = network; | ||
this.workingStateId = workingStateId; | ||
this.dynaFlowParameters = dynaFlowParameters; | ||
this.loadFlowParameters = loadFlowParameters; | ||
this.command = command; | ||
this.dynawoInput = this.dynaFlowParameters.isMergeLoads() ? LoadsMerger.mergeLoads(this.network) : this.network; | ||
this.reportNode = reportNode; | ||
} | ||
|
||
@Override | ||
public List<CommandExecution> before(Path workingDir) throws IOException { | ||
network.getVariantManager().setWorkingVariant(workingStateId); | ||
DynawoUtil.writeIidm(dynawoInput, workingDir.resolve(IIDM_FILENAME)); | ||
DynaFlowConfigSerializer.serialize(loadFlowParameters, dynaFlowParameters, Path.of("."), workingDir.resolve(CONFIG_FILENAME)); | ||
return getCommandExecutions(command); | ||
} | ||
|
||
@Override | ||
public LoadFlowResult after(Path workingDir, ExecutionReport report) { | ||
reportTimeLine(workingDir); | ||
|
||
report.log(); | ||
network.getVariantManager().setWorkingVariant(workingStateId); | ||
boolean status = true; | ||
Path outputNetworkFile = workingDir.resolve("outputs").resolve("finalState").resolve(DynaFlowConstants.OUTPUT_IIDM_FILENAME); | ||
if (Files.exists(outputNetworkFile)) { | ||
NetworkResultsUpdater.update(network, NetworkSerDe.read(outputNetworkFile), dynaFlowParameters.isMergeLoads()); | ||
} else { | ||
status = false; | ||
} | ||
Path resultsPath = workingDir.resolve(OUTPUT_RESULTS_FILENAME); | ||
if (!Files.exists(resultsPath)) { | ||
Map<String, String> metrics = new HashMap<>(); | ||
List<LoadFlowResult.ComponentResult> componentResults = new ArrayList<>(1); | ||
componentResults.add(new LoadFlowResultImpl.ComponentResultImpl(0, | ||
0, | ||
status ? LoadFlowResult.ComponentResult.Status.CONVERGED : LoadFlowResult.ComponentResult.Status.FAILED, | ||
0, | ||
"not-found", | ||
0., | ||
Double.NaN)); | ||
return new LoadFlowResultImpl(status, metrics, null, componentResults); | ||
} | ||
return LoadFlowResultDeserializer.read(resultsPath); | ||
} | ||
|
||
private void reportTimeLine(Path workingDir) { | ||
ReportNode dfReporter = DynaflowReports.createDynaFlowReportNode(reportNode, network.getId()); | ||
Path timelineFile = workingDir.resolve(DYNAFLOW_OUTPUTS_FOLDER) | ||
.resolve(DYNAWO_TIMELINE_FOLDER) | ||
.resolve(DYNAFLOW_TIMELINE_FILE); | ||
List<TimelineEntry> tl = new XmlTimeLineParser().parse(timelineFile); | ||
tl.forEach(e -> CommonReports.reportTimelineEntry(dfReporter, e)); | ||
} | ||
} |
Oops, something went wrong.