Skip to content

Commit

Permalink
Add case date handling when merging networks (#2845)
Browse files Browse the repository at this point in the history
Signed-off-by: SCHWITZGUEBEL Marc Ext <schwitzguebelmar@rte-france.com>
  • Loading branch information
schwitzguebel authored Jan 9, 2024
1 parent 5c4384b commit de1e4f8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.ZonedDateTime;
import java.util.*;
import java.util.function.Function;
import java.util.function.Supplier;
Expand Down Expand Up @@ -140,6 +141,7 @@ static Network merge(String id, String name, Network... networks) {

NetworkImpl mergedNetwork = new NetworkImpl(id, name, networks[0].getSourceFormat());
setValidationLevels(mergedNetwork, networks);
setCommonCaseDate(mergedNetwork, networks);
for (Network other : networks) {
mergedNetwork.merge(other);
}
Expand All @@ -161,6 +163,17 @@ private static void setValidationLevels(NetworkImpl mergedNetwork, Network[] net
mergedNetwork.setValidationLevelIfGreaterThan(validationLevel);
}

private static void setCommonCaseDate(NetworkImpl mergedNetwork, Network[] networks) {
//if all subnetworks have same case date then apply it to merged network
ZonedDateTime caseDate = networks[0].getCaseDate();
for (Network n : networks) {
if (!Objects.equals(caseDate, n.getCaseDate())) {
return;
}
}
mergedNetwork.setCaseDate(caseDate);
}

RefChain<NetworkImpl> getRef() {
return ref;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

import java.io.IOException;
import java.io.StringWriter;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -168,6 +170,34 @@ void mergeTwoNetworksWithVoltageAngleLimitsFail() {
assertEquals("The following voltage angle limit(s) exist(s) in both networks: [LimitCollision]", e.getMessage());
}

@Test
void mergeNetworksWithDifferentCaseDates() {
ZonedDateTime zonedDateTime1 = ZonedDateTime.of(1999, 12, 1, 10, 30, 0, 0, ZoneId.of("UTC"));
ZonedDateTime zonedDateTime2 = ZonedDateTime.of(2021, 10, 31, 11, 30, 0, 0, ZoneId.of("UTC"));
Network network1 = createNodeBreakerWithVoltageAngleLimit("1");
network1.setCaseDate(zonedDateTime1);
Network network2 = createNodeBreakerWithVoltageAngleLimit("2");
network2.setCaseDate(zonedDateTime2);
Network network3 = createNodeBreakerWithVoltageAngleLimit("3");
network3.setCaseDate(zonedDateTime1);
Network networkMerged = Network.merge(network1, network2, network3);
assertNotEquals(zonedDateTime1, networkMerged.getCaseDate());
assertNotEquals(zonedDateTime2, networkMerged.getCaseDate());
}

@Test
void mergeNetworksWithSameCaseDates() {
ZonedDateTime zonedDateTime1 = ZonedDateTime.of(1999, 12, 1, 10, 30, 0, 0, ZoneId.of("UTC"));
Network network1 = createNodeBreakerWithVoltageAngleLimit("1");
network1.setCaseDate(zonedDateTime1);
Network network2 = createNodeBreakerWithVoltageAngleLimit("2");
network2.setCaseDate(zonedDateTime1);
Network network3 = createNodeBreakerWithVoltageAngleLimit("3");
network3.setCaseDate(zonedDateTime1);
Network networkMerged = Network.merge(network1, network2, network3);
assertEquals(zonedDateTime1, networkMerged.getCaseDate());
}

private static boolean voltageAngleLimitsAreEqual(List<VoltageAngleLimit> expected, List<VoltageAngleLimit> actual) {
if (expected.size() != actual.size()) {
return false;
Expand Down

0 comments on commit de1e4f8

Please sign in to comment.