Skip to content

Commit

Permalink
Full dry run for NetworkModificationList
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Perrin <olivier.perrin@rte-france.com>
  • Loading branch information
olperr1 committed May 7, 2024
1 parent 2f17f08 commit 7d5933e
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 6 deletions.
9 changes: 4 additions & 5 deletions iidm/iidm-modification/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-loadflow-api</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-iidm-serde</artifactId>
</dependency>

<!-- Test dependencies -->
<dependency>
Expand Down Expand Up @@ -95,11 +99,6 @@
<artifactId>powsybl-iidm-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-iidm-serde</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
*/
package com.powsybl.iidm.modification;

import com.powsybl.commons.PowsyblException;
import com.powsybl.commons.report.ReportNode;
import com.powsybl.commons.report.TypedValue;
import com.powsybl.computation.ComputationManager;
import com.powsybl.computation.local.LocalComputationManager;
import com.powsybl.iidm.modification.topology.DefaultNamingStrategy;
import com.powsybl.iidm.modification.topology.NamingStrategy;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.serde.NetworkSerDe;

import java.util.Arrays;
import java.util.List;
Expand All @@ -36,4 +41,45 @@ public void apply(Network network, NamingStrategy namingStrategy, boolean throwE
ComputationManager computationManager, ReportNode reportNode) {
modificationList.forEach(modification -> modification.apply(network, namingStrategy, throwException, computationManager, reportNode));
}

public boolean fullDryRun(Network network) {
return fullDryRun(network, new DefaultNamingStrategy(), LocalComputationManager.getDefault(), ReportNode.NO_OP);
}

public boolean fullDryRun(Network network, NamingStrategy namingStrategy,
ComputationManager computationManager, ReportNode reportNode) {
String templateKey = "networkModificationsDryRun-start";
String messageTemplate = "DRY-RUN: Checking if network modifications can be applied on network ${networkNameOrId}";
ReportNode childReportNode = reportNode.newReportNode()
.withMessageTemplate(templateKey, messageTemplate)
.withUntypedValue("networkNameOrId", network.getNameOrId())
.withSeverity(TypedValue.INFO_SEVERITY)
.add();

ReportNode dryRunReportNode = ReportNode.newRootReportNode()
.withMessageTemplate(templateKey, messageTemplate)
.withUntypedValue("networkNameOrId", network.getNameOrId())
.build();
try {
//TODO The following copy performs an XML export/import. It will be more performant to change it to the BIN format.
Network dryRunNetwork = NetworkSerDe.copy(network);
dryRunNetwork.setName(network.getNameOrId() + "_Dry-run");
apply(dryRunNetwork, namingStrategy, true, computationManager, dryRunReportNode);
} catch (PowsyblException powsyblException) {
childReportNode.include(dryRunReportNode);
childReportNode.newReportNode()
.withMessageTemplate("networkModificationsDryRun-failure",
"DRY-RUN: Network modifications CANNOT successfully be applied on network ${networkNameOrId}")
.withSeverity(TypedValue.INFO_SEVERITY)
.add();
return false;
}
childReportNode.include(dryRunReportNode);
childReportNode.newReportNode()
.withMessageTemplate("networkModificationsDryRun-success",
"DRY-RUN: Network modifications can successfully be applied on network ${networkNameOrId}")
.withSeverity(TypedValue.INFO_SEVERITY)
.add();
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
*/
package com.powsybl.iidm.modification;

import com.powsybl.commons.PowsyblException;
import com.powsybl.iidm.modification.topology.RemoveFeederBay;
import com.powsybl.iidm.modification.topology.RemoveFeederBayBuilder;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import com.powsybl.iidm.modification.tripping.BranchTripping;
import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertFalse;
Expand All @@ -20,18 +26,54 @@
*/
class NetworkModificationListTest {

private Network network;

@BeforeEach
void init() {
network = EurostagTutorialExample1Factory.create();
}

@Test
void test() {
Network network = EurostagTutorialExample1Factory.create();
assertTrue(network.getLine("NHV1_NHV2_1").getTerminal1().isConnected());
assertTrue(network.getLine("NHV1_NHV2_1").getTerminal2().isConnected());

BranchTripping tripping1 = new BranchTripping("NHV1_NHV2_1", "VLHV1");
BranchTripping tripping2 = new BranchTripping("NHV1_NHV2_1", "VLHV2");
NetworkModificationList modificationList = new NetworkModificationList(tripping1, tripping2);

boolean dryRunIsOk = Assertions.assertDoesNotThrow(() -> modificationList.fullDryRun(network));
assertTrue(dryRunIsOk);
modificationList.apply(network);

assertFalse(network.getLine("NHV1_NHV2_1").getTerminal1().isConnected());
assertFalse(network.getLine("NHV1_NHV2_1").getTerminal2().isConnected());
}

@Test
void applicationFailureTest() {
String lineId = "NHV1_NHV2_1";
assertTrue(network.getLine(lineId).getTerminal1().isConnected());
assertTrue(network.getLine(lineId).getTerminal2().isConnected());

// Operation list:
// 1. Remove a line;
// 2. Open it.
// The second operation could not be performed because of the effect of the first
RemoveFeederBay removal = new RemoveFeederBayBuilder().withConnectableId(lineId).build();
BranchTripping tripping = new BranchTripping(lineId, "VLHV1");
NetworkModificationList task = new NetworkModificationList(removal, tripping);

boolean dryRunIsOk = Assertions.assertDoesNotThrow(() -> task.fullDryRun(network));
// The full dry-run returns that a problem was encountered and that the full NetworkModificationList could not be performed.
// No operation was applied on the network.
assertFalse(dryRunIsOk);
assertNotNull(network.getLine("NHV1_NHV2_1"));
assertTrue(network.getLine("NHV1_NHV2_1").getTerminal1().isConnected());

// If we ignore the dry-run result and try to apply the NetworkModificationList, an exception is thrown and
// the network is in an "unstable" state.
Assertions.assertThrows(PowsyblException.class, () -> task.apply(network), "Branch '" + lineId + "' not found");
assertNull(network.getLine("NHV1_NHV2_1"));
}
}

0 comments on commit 7d5933e

Please sign in to comment.