Skip to content

Commit

Permalink
Merge branch 'main' into bump_core_6.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
pet-mit committed May 6, 2024
2 parents aad6fc5 + e2b0774 commit 51e0463
Show file tree
Hide file tree
Showing 16 changed files with 981 additions and 128 deletions.
Expand Up @@ -11,6 +11,7 @@
import com.powsybl.openrao.data.cracapi.*;
import com.powsybl.openrao.data.cracapi.cnec.AngleCnec;
import com.powsybl.openrao.data.cracapi.cnec.FlowCnec;
import com.powsybl.openrao.data.cracapi.usagerule.OnFlowConstraintInCountryAdder;
import com.powsybl.openrao.data.cracapi.usagerule.UsageMethod;
import com.powsybl.openrao.data.craccreation.creator.api.ImportStatus;
import com.powsybl.openrao.data.craccreation.creator.cim.craccreator.CimCracCreationContext;
Expand Down Expand Up @@ -98,7 +99,7 @@ public void createAndAddRemedialActionSeries() {
// Read and store Monitored Series
this.flowCnecs = getFlowCnecsFromMonitoredAndContingencySeries(cimSerie);
// Read and create / modify RA creators
boolean shouldReadSharedDomain = cimSerie.getContingencySeries().isEmpty() && cimSerie.getMonitoredSeries().isEmpty();
boolean shouldReadSharedDomain = cimSerie.getMonitoredSeries().isEmpty();
for (RemedialActionSeries remedialActionSeries : cimSerie.getRemedialActionSeries()) {
readRemedialAction(remedialActionSeries, shouldReadSharedDomain);
}
Expand Down Expand Up @@ -406,7 +407,7 @@ private static void addUsageRulesAtInstant(RemedialActionAdder<?> remedialAction
}
UsageMethod usageMethod = instant.isAuto() ? UsageMethod.FORCED : UsageMethod.AVAILABLE;
if (!Objects.isNull(sharedDomain)) {
remedialActionAdder.newOnFlowConstraintInCountryUsageRule().withInstant(instant.getId()).withCountry(sharedDomain).withUsageMethod(usageMethod).add();
addOnFlowConstraintInCountryUsageRule(remedialActionAdder, contingencies, sharedDomain, instant, usageMethod);
return;
}

Expand Down Expand Up @@ -485,6 +486,20 @@ private static void addOnAngleConstraintUsageRule(RemedialActionAdder<?> adder,
.add();
}

private static void addOnFlowConstraintInCountryUsageRule(RemedialActionAdder<?> remedialActionAdder, List<Contingency> contingencies, Country sharedDomain, Instant instant, UsageMethod usageMethod) {
OnFlowConstraintInCountryAdder<?> onFlowConstraintInCountryAdder = remedialActionAdder
.newOnFlowConstraintInCountryUsageRule()
.withInstant(instant.getId())
.withCountry(sharedDomain)
.withUsageMethod(usageMethod);
if (!Objects.isNull(contingencies) && !contingencies.isEmpty()) {
contingencies.forEach(
contingency -> onFlowConstraintInCountryAdder.withContingency(contingency.getId()).add());
} else {
onFlowConstraintInCountryAdder.add();
}
}

/*-------------- SERIES CHECKS ------------------------------*/
private boolean checkRemedialActionSeries(Series cimSerie) {
// --- Check optimizationStatus
Expand Down
Expand Up @@ -703,6 +703,68 @@ void testImportRasAvailableForSpecificCountry() {
.map(InjectionSetpoint.class::cast)
.anyMatch(is -> is.getNetworkElement().getId().equals("_1dc9afba-23b5-41a0-8540-b479ed8baf4b") && is.getSetpoint() == 480)
);

// RA_4
assertNetworkActionImported("RA_4", Set.of("_b94318f6-6d24-4f56-96b9-df2531ad6543", "_1dc9afba-23b5-41a0-8540-b479ed8baf4b"), false);
NetworkAction ra4 = importedCrac.getNetworkAction("RA_4");
assertEquals(2, ra4.getUsageRules().size());
assertTrue(
ra4.getUsageRules().stream()
.filter(OnFlowConstraintInCountry.class::isInstance)
.map(OnFlowConstraintInCountry.class::cast)
.anyMatch(ur -> ur.getInstant().isPreventive() && ur.getContingency().isEmpty() && ur.getCountry().equals(Country.FR))
);
assertTrue(
ra4.getUsageRules().stream()
.filter(OnFlowConstraintInCountry.class::isInstance)
.map(OnFlowConstraintInCountry.class::cast)
.anyMatch(ur -> ur.getInstant().isCurative() && ur.getContingency().orElseThrow().getId().equals("CO_1") && ur.getCountry().equals(Country.FR))
);
assertEquals(2, ra4.getElementaryActions().size());
assertTrue(ra4.getElementaryActions().stream()
.filter(PstSetpoint.class::isInstance)
.map(PstSetpoint.class::cast)
.anyMatch(ps -> ps.getNetworkElement().getId().equals("_b94318f6-6d24-4f56-96b9-df2531ad6543") && ps.getSetpoint() == 0)
);
assertTrue(ra4.getElementaryActions().stream()
.filter(InjectionSetpoint.class::isInstance)
.map(InjectionSetpoint.class::cast)
.anyMatch(is -> is.getNetworkElement().getId().equals("_1dc9afba-23b5-41a0-8540-b479ed8baf4b") && is.getSetpoint() == 480)
);

// RA_5
assertNetworkActionImported("RA_4", Set.of("_b94318f6-6d24-4f56-96b9-df2531ad6543", "_1dc9afba-23b5-41a0-8540-b479ed8baf4b"), false);
NetworkAction ra5 = importedCrac.getNetworkAction("RA_5");
assertEquals(3, ra5.getUsageRules().size());
assertTrue(
ra5.getUsageRules().stream()
.filter(OnFlowConstraintInCountry.class::isInstance)
.map(OnFlowConstraintInCountry.class::cast)
.anyMatch(ur -> ur.getInstant().isPreventive() && ur.getContingency().isEmpty() && ur.getCountry().equals(Country.FR))
);
assertTrue(
ra5.getUsageRules().stream()
.filter(OnFlowConstraintInCountry.class::isInstance)
.map(OnFlowConstraintInCountry.class::cast)
.anyMatch(ur -> ur.getInstant().isCurative() && ur.getContingency().orElseThrow().getId().equals("CO_1") && ur.getCountry().equals(Country.FR))
);
assertTrue(
ra5.getUsageRules().stream()
.filter(OnFlowConstraintInCountry.class::isInstance)
.map(OnFlowConstraintInCountry.class::cast)
.anyMatch(ur -> ur.getInstant().isCurative() && ur.getContingency().orElseThrow().getId().equals("CO_2") && ur.getCountry().equals(Country.FR))
);
assertEquals(2, ra5.getElementaryActions().size());
assertTrue(ra5.getElementaryActions().stream()
.filter(PstSetpoint.class::isInstance)
.map(PstSetpoint.class::cast)
.anyMatch(ps -> ps.getNetworkElement().getId().equals("_b94318f6-6d24-4f56-96b9-df2531ad6543") && ps.getSetpoint() == 0)
);
assertTrue(ra5.getElementaryActions().stream()
.filter(InjectionSetpoint.class::isInstance)
.map(InjectionSetpoint.class::cast)
.anyMatch(is -> is.getNetworkElement().getId().equals("_1dc9afba-23b5-41a0-8540-b479ed8baf4b") && is.getSetpoint() == 480)
);
}

@Test
Expand Down
Expand Up @@ -297,6 +297,105 @@
<resourceCapacity.defaultCapacity>480</resourceCapacity.defaultCapacity>
<resourceCapacity.unitSymbol>MAW</resourceCapacity.unitSymbol>
</RegisteredResource>
</RemedialAction_Series>
</Series>
<Series>
<mRID>RA-Series-4</mRID>
<businessType>B56</businessType>
<name>RA_SERIES-4</name>
<optimization_MarketObjectStatus.status>A52</optimization_MarketObjectStatus.status>
<Contingency_Series>
<mRID>CO_1</mRID>
<name>GHDOV-UENEDI-1 400 kV</name>
<RegisteredResource>
<mRID codingScheme="A02">_ffbabc27-1ccd-4fdc-b037-e341706c8d29</mRID>
<name>VJRKVJ_EIFOC_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>
</RegisteredResource>
</Contingency_Series>
<RemedialAction_Series>
<mRID>RA_4</mRID>
<name>Mixed RA with country</name>
<businessType>B59</businessType>
<applicationMode_MarketObjectStatus.status>A27</applicationMode_MarketObjectStatus.status>
<availability_MarketObjectStatus.status>A39</availability_MarketObjectStatus.status>
<RegisteredResource>
<mRID codingScheme="A02">_b94318f6-6d24-4f56-96b9-df2531ad6543</mRID>
<name>ZFDOVBHLGTZ 1 VJDEOC</name>
<pSRType.psrType>A06</pSRType.psrType>
<in_Domain.mRID codingScheme="A01">10YPT-REN------W</in_Domain.mRID>
<out_Domain.mRID codingScheme="A01">10YPT-REN------W</out_Domain.mRID>
<marketObjectStatus.status>A25</marketObjectStatus.status>
<resourceCapacity.defaultCapacity>-10</resourceCapacity.defaultCapacity>
<resourceCapacity.unitSymbol>C62</resourceCapacity.unitSymbol>
</RegisteredResource>
<RegisteredResource>
<mRID codingScheme="A02">_1dc9afba-23b5-41a0-8540-b479ed8baf4b</mRID>
<name>BHEKG3</name>
<pSRType.psrType>A04</pSRType.psrType>
<in_Domain.mRID codingScheme="A01">10YPT-REN------W</in_Domain.mRID>
<out_Domain.mRID codingScheme="A01">10YPT-REN------W</out_Domain.mRID>
<marketObjectStatus.status>A26</marketObjectStatus.status>
<resourceCapacity.defaultCapacity>480</resourceCapacity.defaultCapacity>
<resourceCapacity.unitSymbol>MAW</resourceCapacity.unitSymbol>
</RegisteredResource>
<Shared_Domain>
<mRID codingScheme="A01">10YFR-RTE------C</mRID>
</Shared_Domain>
</RemedialAction_Series>
</Series>
<Series>
<mRID>RA-Series-5</mRID>
<businessType>B56</businessType>
<name>RA_SERIES-5</name>
<optimization_MarketObjectStatus.status>A52</optimization_MarketObjectStatus.status>
<Contingency_Series>
<mRID>CO_1</mRID>
<name>GHDOV-UENEDI-1 400 kV</name>
<RegisteredResource>
<mRID codingScheme="A02">_ffbabc27-1ccd-4fdc-b037-e341706c8d29</mRID>
<name>VJRKVJ_EIFOC_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>
</RegisteredResource>
</Contingency_Series>
<Contingency_Series>
<mRID>CO_2</mRID>
<name>GHDOV-ZEGU-1 400 kV</name>
<RegisteredResource>
<mRID codingScheme="A02">_b58bf21a-096a-4dae-9a01-3f03b60c24c7</mRID>
<name>VJRKVJ_ZEGU_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>
</RegisteredResource>
</Contingency_Series>
<RemedialAction_Series>
<mRID>RA_5</mRID>
<name>Mixed RA with country with multiple contingencies</name>
<businessType>B59</businessType>
<applicationMode_MarketObjectStatus.status>A27</applicationMode_MarketObjectStatus.status>
<availability_MarketObjectStatus.status>A39</availability_MarketObjectStatus.status>
<RegisteredResource>
<mRID codingScheme="A02">_b94318f6-6d24-4f56-96b9-df2531ad6543</mRID>
<name>ZFDOVBHLGTZ 1 VJDEOC</name>
<pSRType.psrType>A06</pSRType.psrType>
<in_Domain.mRID codingScheme="A01">10YPT-REN------W</in_Domain.mRID>
<out_Domain.mRID codingScheme="A01">10YPT-REN------W</out_Domain.mRID>
<marketObjectStatus.status>A25</marketObjectStatus.status>
<resourceCapacity.defaultCapacity>-10</resourceCapacity.defaultCapacity>
<resourceCapacity.unitSymbol>C62</resourceCapacity.unitSymbol>
</RegisteredResource>
<RegisteredResource>
<mRID codingScheme="A02">_1dc9afba-23b5-41a0-8540-b479ed8baf4b</mRID>
<name>BHEKG3</name>
<pSRType.psrType>A04</pSRType.psrType>
<in_Domain.mRID codingScheme="A01">10YPT-REN------W</in_Domain.mRID>
<out_Domain.mRID codingScheme="A01">10YPT-REN------W</out_Domain.mRID>
<marketObjectStatus.status>A26</marketObjectStatus.status>
<resourceCapacity.defaultCapacity>480</resourceCapacity.defaultCapacity>
<resourceCapacity.unitSymbol>MAW</resourceCapacity.unitSymbol>
</RegisteredResource>
<Shared_Domain>
<mRID codingScheme="A01">10YFR-RTE------C</mRID>
</Shared_Domain>
Expand Down
2 changes: 1 addition & 1 deletion docs/input-data/crac/cim.md
Expand Up @@ -274,7 +274,7 @@ By default, the operator is read from the RemedialAction_Series' mRID, as the st
RemedialAction_Series may also contain Contingency_Series, Monitored_Series and Shared_Domain tags. Remedial actions' [usage rules](json.md#remedial-actions-and-usages-rules) will be defined depending on these tags:
- RemedialAction_Series that don't have any Monitored_Series children tags nor any Shared_Domain tags define **FreeToUse** remedial actions.
- When Monitored_Series tags exist, they define CNECs for which the remedial action series is available. These CNECs could have been defined previously in B57 series, or they are only defined in this B56 series following the [same logic described previously](#cnecs). When the RemedialAction_Series also contains a Contingency_Series, the only CNECs from the Monitored_Series tags that will be considered are those that list CNECs defined with a contingency from the Contingency_Series. For each remaining CNEC, the remedial action is defined with a **OnFlowConstraint** on the remedial action's instant.
- When the RemedialAction_Series has no Contingency_Series, no Monitored_Series, and a Shared_Domain tag, the Shared_Domain tag must be taken into account. It represents a country. Then, the remedial action is defined with a **OnFlowConstraintInCountry** on the remedial action's instant.
- When the RemedialAction_Series has no Monitored_Series, and a Shared_Domain tag, the Shared_Domain tag must be taken into account. It represents a country. Then, the remedial action is defined with a **OnFlowConstraintInCountry** on the remedial action's instant after the given contingencies.

Some remedial actions may have to be aligned in order to keep the same set-point value.
When it's the case, this information is retrieved [from the CracCreationParameters file](creation-parameters.md#range-action-groups-cim)
Expand Down
@@ -0,0 +1,28 @@
/*
* 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/.
*/


package com.powsybl.openrao.monitoring.anglemonitoring;

import com.powsybl.iidm.modification.scalable.Scalable;
import com.powsybl.iidm.network.Network;

import static com.powsybl.openrao.commons.logs.OpenRaoLoggerProvider.BUSINESS_WARNS;

/**
* This abstract implementation uses a Scalable to apply redispatching
*
* @author Peter Mitri {@literal <peter.mitri at rte-france.com>}
*/
public abstract class AbstractRedispatchAction implements RedispatchAction {
protected void apply(Network network, double powerToRedispatch, Scalable scalable) {
double redispatchedPower = scalable.scale(network, powerToRedispatch);
if (Math.abs(redispatchedPower - powerToRedispatch) > 1) {
BUSINESS_WARNS.warn("Redispatching failed: asked={} MW, applied={} MW", powerToRedispatch, redispatchedPower);
}
}
}

0 comments on commit 51e0463

Please sign in to comment.