Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix LimitViolationsResult in dynamic SA #407

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
*/
package com.powsybl.dynawo.it;

import com.google.common.io.ByteStreams;
import com.powsybl.commons.datasource.ResourceDataSource;
import com.powsybl.commons.datasource.ResourceSet;
import com.powsybl.commons.report.ReportNode;
import com.powsybl.commons.test.ComparisonUtils;
import com.powsybl.commons.test.TestUtil;
import com.powsybl.contingency.Contingency;
import com.powsybl.dynamicsimulation.DynamicSimulationParameters;
import com.powsybl.dynamicsimulation.groovy.DynamicModelGroovyExtension;
Expand All @@ -32,17 +30,17 @@
import com.powsybl.security.dynamic.DynamicSecurityAnalysisRunParameters;
import com.powsybl.security.json.SecurityAnalysisResultSerializer;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.List;
import java.util.Objects;

import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.stream.Stream;

/**
* @author Laurent Issertial <laurent.issertial at rte-france.com>
Expand All @@ -62,31 +60,33 @@ void setUp() throws Exception {
provider = new DynawoSecurityAnalysisProvider(new DynawoAlgorithmsConfig(Path.of("/dynaflow-launcher"), true));
parameters = new DynamicSecurityAnalysisParameters()
.setDynamicSimulationParameters(new DynamicSimulationParameters(0, 100))
.setDynamicContingenciesParameters(new DynamicSecurityAnalysisParameters.ContingenciesParameters(50));
.setDynamicContingenciesParameters(new DynamicSecurityAnalysisParameters.ContingenciesParameters(10));
dynawoSimulationParameters = new DynawoSimulationParameters();
parameters.getDynamicSimulationParameters().addExtension(DynawoSimulationParameters.class, dynawoSimulationParameters);
}

@Test
void testIeee14() throws IOException {
@ParameterizedTest
@MethodSource("provideSimulationParameter")
void testIeee14DSA(String criteriaPath, List<Contingency> contingencies, String resultsPath) throws IOException {
Network network = Network.read(new ResourceDataSource("IEEE14", new ResourceSet("/ieee14", "IEEE14.iidm")));

GroovyDynamicModelsSupplier dynamicModelsSupplier = new GroovyDynamicModelsSupplier(
getResourceAsStream("/ieee14/disconnectline/dynamicModels.groovy"),
getResourceAsStream("/ieee14/dynamic-security-analysis/dynamicModels.groovy"),
GroovyExtension.find(DynamicModelGroovyExtension.class, DynawoSimulationProvider.NAME));

List<ParametersSet> modelsParameters = ParametersXml.load(getResourceAsStream("/ieee14/disconnectline/models.par"));
ParametersSet networkParameters = ParametersXml.load(getResourceAsStream("/ieee14/disconnectline/network.par"), "8");
ParametersSet solverParameters = ParametersXml.load(getResourceAsStream("/ieee14/disconnectline/solvers.par"), "2");
List<ParametersSet> modelsParameters = ParametersXml.load(getResourceAsStream("/ieee14/models.par"));
ParametersSet networkParameters = ParametersXml.load(getResourceAsStream("/ieee14/network.par"), "8");
ParametersSet solverParameters = ParametersXml.load(getResourceAsStream("/ieee14/solvers.par"), "2");
dynawoSimulationParameters.setModelsParameters(modelsParameters)
.setNetworkParameters(networkParameters)
.setSolverParameters(solverParameters)
.setSolverType(DynawoSimulationParameters.SolverType.IDA);
.setSolverType(DynawoSimulationParameters.SolverType.IDA)
.setCriteriaFilePath(Path.of(Objects.requireNonNull(getClass()
.getResource(criteriaPath)).getPath()));

ReportNode reportNode = ReportNode.newRootReportNode()
.withMessageTemplate("root", "Root message")
.build();
List<Contingency> contingencies = List.of(Contingency.load("_LOAD__11_EC"));

DynamicSecurityAnalysisRunParameters runParameters = new DynamicSecurityAnalysisRunParameters()
.setComputationManager(computationManager)
Expand All @@ -98,16 +98,20 @@ void testIeee14() throws IOException {
.join()
.getResult();

StringWriter swReporterAs = new StringWriter();
reportNode.print(swReporterAs);
InputStream refStreamReporterAs = Objects.requireNonNull(getClass().getResourceAsStream("/ieee14/dynamic-security-analysis/timeline_report.txt"));
String refLogExportAs = TestUtil.normalizeLineSeparator(new String(ByteStreams.toByteArray(refStreamReporterAs), StandardCharsets.UTF_8));
String logExportAs = TestUtil.normalizeLineSeparator(swReporterAs.toString());
assertEquals(refLogExportAs, logExportAs);

StringWriter serializedResult = new StringWriter();
SecurityAnalysisResultSerializer.write(result, serializedResult);
InputStream expected = Objects.requireNonNull(getClass().getResourceAsStream("/ieee14/dynamic-security-analysis/results.json"));
InputStream expected = Objects.requireNonNull(getClass().getResourceAsStream(resultsPath));
ComparisonUtils.assertTxtEquals(expected, serializedResult.toString());
}

private static Stream<Arguments> provideSimulationParameter() {
return Stream.of(
Arguments.of("/ieee14/dynamic-security-analysis/convergence/criteria.crt",
List.of(Contingency.line("_BUS____1-BUS____5-1_AC"), Contingency.generator("_GEN____2_SM")),
"/ieee14/dynamic-security-analysis/convergence/results.json"),
Arguments.of("/ieee14/dynamic-security-analysis/failed-criteria/criteria.crt",
List.of(Contingency.line("_BUS____1-BUS____5-1_AC")),
"/ieee14/dynamic-security-analysis/failed-criteria/results.json")
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,9 @@ void testIeee14DynawoSuppliers() {
DynamicModelsSupplier dynamicModelsSupplier = DynawoModelsSupplier.load(getResourceAsStream("/ieee14/disconnectline/dynamicModels.json"));
EventModelsSupplier eventModelsSupplier = DynawoEventModelsSupplier.load(getResourceAsStream("/ieee14/disconnectline/eventModels.json"));

List<ParametersSet> modelsParameters = ParametersXml.load(getResourceAsStream("/ieee14/disconnectline/models.par"));
ParametersSet networkParameters = ParametersXml.load(getResourceAsStream("/ieee14/disconnectline/network.par"), "8");
ParametersSet solverParameters = ParametersXml.load(getResourceAsStream("/ieee14/disconnectline/solvers.par"), "2");
List<ParametersSet> modelsParameters = ParametersXml.load(getResourceAsStream("/ieee14/models.par"));
ParametersSet networkParameters = ParametersXml.load(getResourceAsStream("/ieee14/network.par"), "8");
ParametersSet solverParameters = ParametersXml.load(getResourceAsStream("/ieee14/solvers.par"), "2");
dynawoSimulationParameters.setModelsParameters(modelsParameters)
.setNetworkParameters(networkParameters)
.setSolverParameters(solverParameters)
Expand Down Expand Up @@ -324,9 +324,9 @@ private Supplier<DynamicSimulationResult> setupIEEE14Simulation(ReportNode repor
getResourceAsStream("/ieee14/disconnectline/outputVariables.groovy"),
GroovyExtension.find(OutputVariableGroovyExtension.class, DynawoSimulationProvider.NAME));

List<ParametersSet> modelsParameters = ParametersXml.load(getResourceAsStream("/ieee14/disconnectline/models.par"));
ParametersSet networkParameters = ParametersXml.load(getResourceAsStream("/ieee14/disconnectline/network.par"), "8");
ParametersSet solverParameters = ParametersXml.load(getResourceAsStream("/ieee14/disconnectline/solvers.par"), "2");
List<ParametersSet> modelsParameters = ParametersXml.load(getResourceAsStream("/ieee14/models.par"));
ParametersSet networkParameters = ParametersXml.load(getResourceAsStream("/ieee14/network.par"), "8");
ParametersSet solverParameters = ParametersXml.load(getResourceAsStream("/ieee14/solvers.par"), "2");
dynawoSimulationParameters.setModelsParameters(modelsParameters)
.setNetworkParameters(networkParameters)
.setSolverParameters(solverParameters)
Expand Down
28 changes: 19 additions & 9 deletions dynawo-integration-tests/src/test/resources/ieee14/IEEE14.iidm
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<iidm:network xmlns:iidm="http://www.powsybl.org/schema/iidm/1_4" id="ieee14bus" caseDate="2017-06-09T10:14:24.146+02:00" forecastDistance="0" sourceFormat="CIM1">
<!--
Copyright (c) 2022, RTE (http://www.rte-france.com)
See AUTHORS.txt
All rights reserved.
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

This file is part of Dynawo, an hybrid C++/Modelica open source suite
of simulation tools for power systems.
-->
<iidm:network xmlns:iidm="http://www.itesla_project.eu/schema/iidm/1_0" id="ieee14bus" caseDate="2017-06-09T10:14:24.146+02:00" forecastDistance="0" sourceFormat="CIM1">
<iidm:substation id="_BUS___10_SS" name="BUS 10_SS" country="AF" geographicalTags="_SGR_01">
<iidm:voltageLevel id="_BUS___10_VL" name="BUS 10_VL" nominalV="13.8" topologyKind="BUS_BREAKER">
<iidm:busBreakerTopology>
Expand Down Expand Up @@ -78,9 +90,7 @@
<iidm:bus id="_BUS____9_TN" v="14.5719" angle="-14.9385"/>
</iidm:busBreakerTopology>
<iidm:load id="_LOAD___9_EC" name="LOAD 9" loadType="UNDEFINED" p0="29.5" q0="16.6" bus="_BUS____9_TN" connectableBus="_BUS____9_TN" p="29.5" q="16.6"/>
<iidm:shunt id="_BANK___9_SC" name="BANK 9" sectionCount="1" voltageRegulatorOn="false" bus="_BUS____9_TN" connectableBus="_BUS____9_TN" q="-21.256718">
<iidm:shuntLinearModel bPerSection="0.099769" maximumSectionCount="1"/>
</iidm:shunt>
<iidm:shunt id="_BANK___9_SC" name="BANK 9" bPerSection="0.099769" maximumSectionCount="1" currentSectionCount="1" bus="_BUS____9_TN" connectableBus="_BUS____9_TN" q="-21.256718"/>
</iidm:voltageLevel>
<iidm:voltageLevel id="_BUS____7_VL" name="BUS 7_VL" nominalV="13.8" topologyKind="BUS_BREAKER">
<iidm:busBreakerTopology>
Expand All @@ -94,12 +104,12 @@
<iidm:load id="_LOAD___4_EC" name="LOAD 4" loadType="UNDEFINED" p0="47.8" q0="-3.9" bus="_BUS____4_TN" connectableBus="_BUS____4_TN" p="47.8" q="-3.9"/>
</iidm:voltageLevel>
<iidm:twoWindingsTransformer id="_BUS____4-BUS____9-1_PT" name="BUS 4-BUS 9-1" r="0.0" x="1.0591881" g="0.0" b="0.0" ratedU1="69.0" ratedU2="13.8" bus1="_BUS____4_TN" connectableBus1="_BUS____4_TN" voltageLevelId1="_BUS____4_VL" bus2="_BUS____9_TN" connectableBus2="_BUS____9_TN" voltageLevelId2="_BUS____9_VL" p1="16.299362" q1="1.270369" p2="-16.299362" q2="0.050373">
<iidm:ratioTapChanger lowTapPosition="1" tapPosition="4" loadTapChangingCapabilities="false">
<iidm:ratioTapChanger lowTapPosition="1" tapPosition="4" regulating="false" loadTapChangingCapabilities="false">
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="1.1111112"/>
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="1.0834236"/>
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="1.0570825"/>
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="1.0319917"/>
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="1.015744"/>
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="1.0157440"/>
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="1.0"/>
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="0.9803922"/>
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="0.9615385"/>
Expand All @@ -111,7 +121,7 @@
<iidm:currentLimits2 permanentLimit="4183.7"/>
</iidm:twoWindingsTransformer>
<iidm:twoWindingsTransformer id="_BUS____4-BUS____7-1_PT" name="BUS 4-BUS 7-1" r="0.0" x="0.39824802" g="0.0" b="0.0" ratedU1="69.0" ratedU2="13.8" bus1="_BUS____4_TN" connectableBus1="_BUS____4_TN" voltageLevelId1="_BUS____4_VL" bus2="_BUS____7_TN" connectableBus2="_BUS____7_TN" voltageLevelId2="_BUS____7_VL" p1="28.129929" q1="-10.561864" p2="-28.129929" q2="12.3099">
<iidm:ratioTapChanger lowTapPosition="1" tapPosition="5" loadTapChangingCapabilities="false">
<iidm:ratioTapChanger lowTapPosition="1" tapPosition="5" regulating="false" loadTapChangingCapabilities="false">
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="1.1111112"/>
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="1.0875476"/>
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="1.0649627"/>
Expand Down Expand Up @@ -145,11 +155,11 @@
<iidm:load id="_LOAD___5_EC" name="LOAD 5" loadType="UNDEFINED" p0="7.6" q0="1.6" bus="_BUS____5_TN" connectableBus="_BUS____5_TN" p="7.6" q="1.6"/>
</iidm:voltageLevel>
<iidm:twoWindingsTransformer id="_BUS____5-BUS____6-1_PT" name="BUS 5-BUS 6-1" r="0.0" x="0.47994804" g="0.0" b="0.0" ratedU1="69.0" ratedU2="13.8" bus1="_BUS____5_TN" connectableBus1="_BUS____5_TN" voltageLevelId1="_BUS____5_VL" bus2="_BUS____6_TN" connectableBus2="_BUS____6_TN" voltageLevelId2="_BUS____6_VL" p1="43.804256" q1="9.096129" p2="-43.804256" q2="-4.821185">
<iidm:ratioTapChanger lowTapPosition="1" tapPosition="3" loadTapChangingCapabilities="false">
<iidm:ratioTapChanger lowTapPosition="1" tapPosition="3" regulating="false" loadTapChangingCapabilities="false">
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="1.1111112"/>
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="1.0917031"/>
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="1.0729614"/>
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="1.047486"/>
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="1.0474860"/>
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="1.0231924"/>
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="1.0"/>
<iidm:step r="0.0" x="0.0" g="0.0" b="0.0" rho="0.9803922"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version='1.0' encoding='UTF-8'?>
<!--
Copyright (c) 2015-2021, RTE (http://www.rte-france.com)
See AUTHORS.txt
All rights reserved.
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

This file is part of Dynawo, an hybrid C++/Modelica open source suite
of simulation tools for power systems.
-->
<criteria xmlns="http://www.rte-france.com/dynawo">
<busCriteria>
<parameters id ="Risque modele" scope="DYNAMIC" type="LOCAL_VALUE" uMinPu="0.8" uNomMin="225"/>
<country id="AF"/>
<country id="AFGHANISTAN"/>
</busCriteria>
<loadCriteria>
<parameters id ="Risque protection" scope="DYNAMIC" type="SUM" pMax="100">
<voltageLevel uMaxPu="0.85"/>
</parameters>
<country id="AF"/>
<country id="AFGHANISTAN"/>
</loadCriteria>
<loadCriteria>
<parameters id ="Risque QdE" scope="FINAL" type="SUM" pMax="200">
<voltageLevel uMaxPu="0.92"/>
</parameters>
<country id="AF"/>
<country id="AFGHANISTAN"/>
</loadCriteria>
<loadCriteria>
<parameters id ="Risque Surete" scope="FINAL" type="SUM" pMax="1500">
<voltageLevel uMaxPu="0.92"/>
</parameters>
<country id="AF"/>
<country id="AFGHANISTAN"/>
</loadCriteria>
<loadCriteria>
<parameters id ="Risque IGA" scope="FINAL" type="SUM" pMax="3000">
<voltageLevel uMaxPu="0.92"/>
</parameters>
<country id="AF"/>
<country id="AFGHANISTAN"/>
</loadCriteria>
</criteria>
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"version" : "1.7",
"preContingencyResult" : {
"status" : "CONVERGED",
"limitViolationsResult" : {
"limitViolations" : [ {
"subjectId" : "_BUS____1-BUS____2-1_AC",
"subjectName" : "BUS 1-BUS 2-1",
"limitType" : "CURRENT",
"limitName" : "permanent",
"limit" : 836.74,
"limitReduction" : 1.0,
"value" : 1248.0773003764798,
"side" : "ONE"
} ],
"actionsTaken" : [ ]
},
"networkResult" : {
"branchResults" : [ ],
"busResults" : [ ],
"threeWindingsTransformerResults" : [ ]
}
},
"postContingencyResults" : [ {
"contingency" : {
"id" : "_BUS____1-BUS____5-1_AC",
"elements" : [ {
"id" : "_BUS____1-BUS____5-1_AC",
"type" : "LINE"
} ]
},
"status" : "CONVERGED",
"limitViolationsResult" : {
"limitViolations" : [ {
"subjectId" : "_BUS____1-BUS____2-1_AC",
"subjectName" : "BUS 1-BUS 2-1",
"limitType" : "CURRENT",
"limitName" : "PATL",
"limit" : 836.74,
"limitReduction" : 1.0,
"value" : 1248.100487597837,
"side" : "ONE"
} ],
"actionsTaken" : [ ]
},
"networkResult" : {
"branchResults" : [ ],
"busResults" : [ ],
"threeWindingsTransformerResults" : [ ]
},
"connectivityResult" : {
"createdSynchronousComponentCount" : 0,
"createdConnectedComponentCount" : 0,
"disconnectedLoadActivePower" : 0.0,
"disconnectedGenerationActivePower" : 0.0,
"disconnectedElements" : [ ]
}
}, {
"contingency" : {
"id" : "_GEN____2_SM",
"elements" : [ {
"id" : "_GEN____2_SM",
"type" : "GENERATOR"
} ]
},
"status" : "CONVERGED",
"limitViolationsResult" : {
"limitViolations" : [ {
"subjectId" : "_BUS____1-BUS____2-1_AC",
"subjectName" : "BUS 1-BUS 2-1",
"limitType" : "CURRENT",
"limitName" : "PATL",
"limit" : 836.74,
"limitReduction" : 1.0,
"value" : 1248.100487597837,
"side" : "ONE"
} ],
"actionsTaken" : [ ]
},
"networkResult" : {
"branchResults" : [ ],
"busResults" : [ ],
"threeWindingsTransformerResults" : [ ]
},
"connectivityResult" : {
"createdSynchronousComponentCount" : 0,
"createdConnectedComponentCount" : 0,
"disconnectedLoadActivePower" : 0.0,
"disconnectedGenerationActivePower" : 0.0,
"disconnectedElements" : [ ]
}
} ],
"operatorStrategyResults" : [ ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* 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
*/

import com.powsybl.iidm.network.Load

for (Load load : network.loads) {
if (load.id != "_LOAD___2_EC") {
LoadAlphaBeta {
staticId load.id
parameterSetId "LAB"
}
}
}

for (gen in ["_GEN____1_SM", "_GEN____2_SM", "_GEN____3_SM"]) {
GeneratorSynchronousFourWindingsProportionalRegulations {
staticId gen
parameterSetId "GSFWPR" + gen
}
}

for (gen in ["_GEN____6_SM", "_GEN____8_SM"]) {
GeneratorSynchronousThreeWindingsProportionalRegulations {
staticId gen
parameterSetId "GSTWPR" + gen
}
}
Loading
Loading