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

CIM CRAC permissive imports #784

Merged
merged 5 commits into from
Aug 30, 2023
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 @@ -26,7 +26,7 @@ private CimCracUtils() { }

public static Contingency getContingencyFromCrac(ContingencySeries cimContingency, CimCracCreationContext cracCreationContext) {
CimContingencyCreationContext ccc = cracCreationContext.getContingencyCreationContextById(cimContingency.getMRID());
if (ccc == null || ccc.getCreatedContingencyId() == null) {
if (ccc == null || !ccc.isImported()) {
return null;
}
return cracCreationContext.getCrac().getContingency(ccc.getCreatedContingencyId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private Set<Series> getCnecSeries() {
}

private boolean describesCnecsToImport(Series series) {
return series.getBusinessType().equals(CNECS_SERIES_BUSINESS_TYPE);
return series.getBusinessType().equals(CNECS_SERIES_BUSINESS_TYPE) || series.getBusinessType().equals(REMEDIAL_ACTIONS_SERIES_BUSINESS_TYPE);
}

private void readAndAddCnec(MonitoredSeries monitoredSeries, List<Contingency> contingencies, String optimizationStatus, List<String> invalidContingencies) {
Expand Down Expand Up @@ -132,7 +132,7 @@ private void readAndAddCnec(MonitoredSeries monitoredSeries, List<Contingency> c
} else {
String contingencyList = StringUtils.join(invalidContingencies, ", ");
monitoredSeriesCreationContext = MonitoredSeriesCreationContext.imported(nativeId, nativeName, resourceId, resourceName,
true, String.format("Contingencies %s not defined in B55s", contingencyList));
true, String.format("Contingencies %s were not imported", contingencyList));
}

// Read measurements
Expand Down Expand Up @@ -180,13 +180,7 @@ private void saveMonitoredSeriesCreationContexts(String nativeId, MonitoredSerie
}

private boolean isMnec(String optimizationStatus) {
if (Objects.nonNull(optimizationStatus) && optimizationStatus.equals(CNECS_MNEC_MARKET_OBJECT_STATUS)) {
return true;
} else if (Objects.isNull(optimizationStatus) || optimizationStatus.equals(CNECS_OPTIMIZED_MARKET_OBJECT_STATUS)) {
return false;
} else {
throw new FaraoException(String.format("Unrecognized optimization_MarketObjectStatus.status: %s", optimizationStatus));
}
return Objects.nonNull(optimizationStatus) && optimizationStatus.equals(CNECS_MNEC_MARKET_OBJECT_STATUS);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on ne veut plus lever une exception ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non parce que les B56 ne contiennent pas cette info

}

private MeasurementCreationContext createCnecFromMeasurement(Analog measurement, String cnecId, boolean isMnec, CgmesBranchHelper branchHelper, List<Contingency> contingencies) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.Set;
import java.util.stream.Collectors;

import static com.farao_community.farao.data.crac_creation.creator.cim.crac_creator.CimConstants.CONTINGENCY_SERIES_BUSINESS_TYPE;
import static com.farao_community.farao.data.crac_creation.creator.cim.crac_creator.CimConstants.*;

/**
* @author Godelaine de Montmorillon {@literal <godelaine.demontmorillon at rte-france.com>}
Expand Down Expand Up @@ -65,6 +65,10 @@ public void createAndAddContingencies() {
}

private void addContingency(ContingencySeries cimContingency) {
if (cimContingencyCreationContexts.stream().anyMatch(ccc -> ccc.getNativeId().equals(cimContingency.getMRID()))) {
return;
}

String createdContingencyId = cimContingency.getMRID();
ContingencyAdder contingencyAdder = crac.newContingency()
.withId(createdContingencyId)
Expand Down Expand Up @@ -125,6 +129,8 @@ private String getNetworkElementIdInNetwork(String networkElementIdInCrac) {
}

private boolean describesContingencyToImport(Series series) {
return series.getBusinessType().equals(CONTINGENCY_SERIES_BUSINESS_TYPE);
return series.getBusinessType().equals(CONTINGENCY_SERIES_BUSINESS_TYPE)
|| series.getBusinessType().equals(CNECS_SERIES_BUSINESS_TYPE)
|| series.getBusinessType().equals(REMEDIAL_ACTIONS_SERIES_BUSINESS_TYPE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public Set<RemedialActionSeriesCreationContext> add() {
return raSeriesIds.stream().map(id -> RemedialActionSeriesCreationContext.importedHvdcRa(id, createdRaIds, false, isDirectionInverted.get(id), "")).collect(Collectors.toSet());
} else {
String contingencyList = StringUtils.join(invalidContingencies, ", ");
return raSeriesIds.stream().map(id -> RemedialActionSeriesCreationContext.importedHvdcRa(id, createdRaIds, true, isDirectionInverted.get(id), String.format("Contingencies %s not defined in B55s", contingencyList))).collect(Collectors.toSet());
return raSeriesIds.stream().map(id -> RemedialActionSeriesCreationContext.importedHvdcRa(id, createdRaIds, true, isDirectionInverted.get(id), String.format("Contingencies %s were not imported", contingencyList))).collect(Collectors.toSet());
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public static RemedialActionSeriesCreationContext importWithContingencies(String
return RemedialActionSeriesCreationContext.imported(createdRemedialActionId, false, "");
} else {
String contingencyList = StringUtils.join(invalidContingencies, ", ");
return RemedialActionSeriesCreationContext.imported(createdRemedialActionId, true, String.format("Contingencies %s not defined in B55s", contingencyList));
return RemedialActionSeriesCreationContext.imported(createdRemedialActionId, true, String.format("Contingencies %s were not imported", contingencyList));
}
}

Expand All @@ -352,7 +352,7 @@ public static RemedialActionSeriesCreationContext importPstRaWithContingencies(S
return PstRangeActionSeriesCreationContext.imported(createdRemedialActionId, networkElementNativeMrid, networkElementNativeName, false, "");
} else {
String contingencyList = StringUtils.join(invalidContingencies, ", ");
return PstRangeActionSeriesCreationContext.imported(createdRemedialActionId, networkElementNativeMrid, networkElementNativeName, true, String.format("Contingencies %s not defined in B55s", contingencyList));
return PstRangeActionSeriesCreationContext.imported(createdRemedialActionId, networkElementNativeMrid, networkElementNativeName, true, String.format("Contingencies %s were not imported", contingencyList));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
import com.farao_community.farao.data.crac_creation.creator.cim.parameters.*;
import com.google.common.base.Suppliers;
import com.powsybl.computation.local.LocalComputationManager;
import com.powsybl.iidm.network.Country;
import com.powsybl.iidm.network.ImportConfig;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.Network;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
Expand All @@ -53,6 +54,8 @@
* @author Godelaine de Montmorillon {@literal <godelaine.demontmorillon at rte-france.com>}
*/
class CimCracCreatorTest {
private static final double DOUBLE_TOLERANCE = 1e-6;

private Crac importedCrac;
private CimCracCreationContext cracCreationContext;
private static Network baseNetwork;
Expand Down Expand Up @@ -279,9 +282,9 @@ private void assertHasOneThreshold(String cnecId, Side side, Unit unit, double m
assertEquals(side, threshold.getSide());
assertEquals(unit, threshold.getUnit());
assertTrue(threshold.limitsByMin());
assertEquals(min, threshold.min().get(), 0.0);
assertEquals(min, threshold.min().get(), DOUBLE_TOLERANCE);
assertTrue(threshold.limitsByMax());
assertEquals(max, threshold.max().get(), 0.0);
assertEquals(max, threshold.max().get(), DOUBLE_TOLERANCE);
}

private void assertHasTwoThresholds(String cnecId, Unit unit, double min, double max) {
Expand All @@ -292,9 +295,9 @@ private void assertHasTwoThresholds(String cnecId, Unit unit, double min, double
cnec.getThresholds().forEach(threshold -> {
assertEquals(unit, threshold.getUnit());
assertTrue(threshold.limitsByMin());
assertEquals(min, threshold.min().get(), 0.0);
assertEquals(min, threshold.min().get(), DOUBLE_TOLERANCE);
assertTrue(threshold.limitsByMax());
assertEquals(max, threshold.max().get(), 0.0);
assertEquals(max, threshold.max().get(), DOUBLE_TOLERANCE);
});
}

Expand Down Expand Up @@ -929,4 +932,54 @@ void importAndDuplicateAutoCnecs() {
assertCnecHasOutageDuplicate("CNEC-4 - Co-1 - auto");
assertCnecHasOutageDuplicate("CNEC-4 - Co-2 - auto");
}

@Test
void testPermissiveImports() {
// Test that we can import contingencies from B56 & B57, and CNECs from B56
setUpWithSpeed("/cracs/CIM_21_5_1_permissive.xml", baseNetwork, OffsetDateTime.parse("2021-04-01T23:00Z"), Set.of(new RangeActionSpeed("AUTO_1", 1)));

// Contingencies
assertEquals(3, importedCrac.getContingencies().size());
assertContingencyImported("Co-one-1", "OIUYTR-QSCV-1 400 kV", Set.of("_ffbabc27-1ccd-4fdc-b037-e341706c8d29"), false);
assertContingencyImported("Co-one-2", "OIUYTR-LKJHGOI-1 400 kV", Set.of("_b58bf21a-096a-4dae-9a01-3f03b60c24c7"), false);
assertContingencyImported("Co-one-3", "AZERTY-LKJHG-1 400 kV", Set.of("_df16b3dd-c905-4a6f-84ee-f067be86f5da"), false);

// FlowCNECs
assertEquals(14, importedCrac.getFlowCnecs().size());

assertCnecImported("TUU_MR_31", Set.of(
"GHIOL_QSDFGH_1_220 - Co-one-1 - auto", "GHIOL_QSDFGH_1_220 - preventive", "GHIOL_QSDFGH_1_220 - Co-one-1 - outage",
"GHIOL_QSDFGH_1_220 - Co-one-3 - outage", "GHIOL_QSDFGH_1_220 - Co-one-3 - curative", "GHIOL_QSDFGH_1_220 - Co-one-2 - curative",
"GHIOL_QSDFGH_1_220 - Co-one-3 - auto", "GHIOL_QSDFGH_1_220 - Co-one-1 - curative", "GHIOL_QSDFGH_1_220 - Co-one-2 - auto",
"GHIOL_QSDFGH_1_220 - Co-one-2 - outage"
));
assertHasOneThreshold("GHIOL_QSDFGH_1_220 - preventive", Side.LEFT, Unit.PERCENT_IMAX, -1, 1);
assertHasOneThreshold("GHIOL_QSDFGH_1_220 - Co-one-1 - outage", Side.LEFT, Unit.PERCENT_IMAX, -1.15, 1.15);
assertHasOneThreshold("GHIOL_QSDFGH_1_220 - Co-one-2 - auto", Side.LEFT, Unit.PERCENT_IMAX, -1.1, 1.1);
assertHasOneThreshold("GHIOL_QSDFGH_1_220 - Co-one-3 - curative", Side.LEFT, Unit.PERCENT_IMAX, -1.05, 1.05);

assertCnecImported("TUU_MR_56", Set.of(
"GHIOL_QSRBJH_1_400 - Co-one-1 - auto", "GHIOL_QSRBJH_1_400 - preventive", "GHIOL_QSRBJH_1_400 - Co-one-1 - outage",
"GHIOL_QSRBJH_1_400 - Co-one-1 - curative"
));
assertHasOneThreshold("GHIOL_QSRBJH_1_400 - preventive", Side.LEFT, Unit.PERCENT_IMAX, -1, 1);
assertHasOneThreshold("GHIOL_QSRBJH_1_400 - Co-one-1 - outage", Side.LEFT, Unit.PERCENT_IMAX, -1.5, 1.5);
assertHasOneThreshold("GHIOL_QSRBJH_1_400 - Co-one-1 - auto", Side.LEFT, Unit.PERCENT_IMAX, -1.3, 1.3);
assertHasOneThreshold("GHIOL_QSRBJH_1_400 - Co-one-1 - curative", Side.LEFT, Unit.PERCENT_IMAX, -1.05, 1.05);

// PRA_1
assertPstRangeActionImported("PRA_1", "_a708c3bc-465d-4fe7-b6ef-6fa6408a62b0", false);
PstRangeAction pra1 = importedCrac.getPstRangeAction("PRA_1");
assertEquals(7, pra1.getUsageRules().size());

// PRA_CRA_1
assertPstRangeActionImported("PRA_CRA_1", "_e8a7eaec-51d6-4571-b3d9-c36d52073c33", true);
PstRangeAction praCra1 = importedCrac.getPstRangeAction("PRA_CRA_1");
assertEquals(6, praCra1.getUsageRules().size());

// AUTO_1
assertPstRangeActionImported("AUTO_1", "_e8a7eaec-51d6-4571-b3d9-c36d52073c33", true);
PstRangeAction auto1 = importedCrac.getPstRangeAction("AUTO_1");
assertEquals(2, auto1.getUsageRules().size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@
<in_Domain.mRID codingScheme="A01">1------0</in_Domain.mRID>
<out_Domain.mRID codingScheme="A01">1------0</out_Domain.mRID>
</RegisteredResource>
<RegisteredResource>
<mRID codingScheme="A02">_df16b3dd-c905-4a6f-84ee-f067be86f5da</mRID>
<name>Co2NetworkElementName</name>
<in_Domain.mRID codingScheme="A01">1------0</in_Domain.mRID>
<out_Domain.mRID codingScheme="A01">1------0</out_Domain.mRID>
</RegisteredResource>
</Contingency_Series>
</Series>
</Point>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
<mRID>Co-1</mRID>
<name>Co-1-name</name>
<RegisteredResource>
<mRID codingScheme="A02">_ffbabc27-1ccd-4fdc-b037-e341706c8d29</mRID>
<mRID codingScheme="A02">_b18cd1aa-7808-49b9-a7cf-605eaf07b006 + _e8acf6b6-99cb-45ad-b8dc-16c7866a4ddc</mRID>
<name>Co1NetworkElementName</name>
<in_Domain.mRID codingScheme="A01">1------0</in_Domain.mRID>
<out_Domain.mRID codingScheme="A01">1------0</out_Domain.mRID>
Expand All @@ -144,7 +144,7 @@
<mRID>Fake-Co</mRID>
<name>Fake-Co-name</name>
<RegisteredResource>
<mRID codingScheme="A02">_df16b3dd-c905-4a6f-84ee-f067be86f5da</mRID>
<mRID codingScheme="A02">_df16b3dd-c905-4a6f-84ee-f067be86f5da_doesnt_exist</mRID>
<name>FakeCoElement</name>
<in_Domain.mRID codingScheme="A01">1------0</in_Domain.mRID>
<out_Domain.mRID codingScheme="A01">1------0</out_Domain.mRID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
<mRID>Co-1</mRID>
<name>Co-1-name</name>
<RegisteredResource>
<mRID codingScheme="A02">_ffbabc27-1ccd-4fdc-b037-e341706c8d29</mRID>
<mRID codingScheme="A02">_b18cd1aa-7808-49b9-a7cf-605eaf07b006 + _e8acf6b6-99cb-45ad-b8dc-16c7866a4ddc</mRID>
<name>Co1NetworkElementName</name>
<in_Domain.mRID codingScheme="A01">1------0</in_Domain.mRID>
<out_Domain.mRID codingScheme="A01">1------0</out_Domain.mRID>
Expand All @@ -144,7 +144,7 @@
<mRID>Fake-Co</mRID>
<name>Fake-Co-name</name>
<RegisteredResource>
<mRID codingScheme="A02">_df16b3dd-c905-4a6f-84ee-f067be86f5da</mRID>
<mRID codingScheme="A02">_df16b3dd-c905-4a6f-84ee-f067be86f5da_doesnt_exist</mRID>
<name>FakeCoElement</name>
<in_Domain.mRID codingScheme="A01">1------0</in_Domain.mRID>
<out_Domain.mRID codingScheme="A01">1------0</out_Domain.mRID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
<mRID>Co-1</mRID>
<name>Co-1-name</name>
<RegisteredResource>
<mRID codingScheme="A02">_ffbabc27-1ccd-4fdc-b037-e341706c8d29</mRID>
<mRID codingScheme="A02">_b18cd1aa-7808-49b9-a7cf-605eaf07b006 + _e8acf6b6-99cb-45ad-b8dc-16c7866a4ddc</mRID>
<name>Co1NetworkElementName</name>
<in_Domain.mRID codingScheme="A01">1------0</in_Domain.mRID>
<out_Domain.mRID codingScheme="A01">1------0</out_Domain.mRID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
<mRID>Co-one-9</mRID>
<name>AZERTY-LKJHG-1 400 kV_TO_IGNORE</name>
<RegisteredResource>
<mRID codingScheme="A02">_df16b3dd-c905-4a6f-84ee-f067be86f5da</mRID>
<mRID codingScheme="A02">_df16b3dd-c905-4a6f-84ee-f067be86f5da_doesnt_exist</mRID>
<name>AZERTY_LKJHG_1_400</name>
<in_Domain.mRID codingScheme="A01">10YES-REE------0</in_Domain.mRID>
<out_Domain.mRID codingScheme="A01">10YES-REE------0</out_Domain.mRID>
Expand Down
Loading