Skip to content

Commit

Permalink
Import TapPositionAction from TapChanger (#1126)
Browse files Browse the repository at this point in the history
* Import TapPositionAction from TapChanger

Signed-off-by: Thomas Bouquet <thomas.bouquet@rte-france.com>

* Author + copyright

Signed-off-by: Thomas Bouquet <thomas.bouquet@rte-france.com>

---------

Signed-off-by: Thomas Bouquet <thomas.bouquet@rte-france.com>
  • Loading branch information
bqth29 authored Sep 23, 2024
1 parent 32e4a3b commit df23b63
Show file tree
Hide file tree
Showing 18 changed files with 59 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ public Set<RemedialActionDependency> getRemedialActionDependencies() {
return new NcPropertyBagsConverter<>(RemedialActionDependency::fromPropertyBag).convert(getPropertyBags(CsaProfileKeyword.REMEDIAL_ACTION, OverridingObjectsFields.SCHEME_REMEDIAL_ACTION_DEPENDENCY, CsaProfileConstants.REQUEST_REMEDIAL_ACTION_DEPENDENCY));
}

public Set<TapChanger> getTapChangers() {
return new NcPropertyBagsConverter<>(TapChanger::fromPropertyBag).convert(getPropertyBags(CsaProfileKeyword.CGMES, CsaProfileConstants.REQUEST_TAP_CHANGER));
}

private void setOverridingData(OffsetDateTime importTimestamp) {
overridingData = new HashMap<>();
for (OverridingObjectsFields overridingObject : OverridingObjectsFields.values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,14 @@ private CsaProfileConstants() {
public static final String REQUEST_REMEDIAL_ACTION_GROUP = "remedialActionGroup";
public static final String REQUEST_REMEDIAL_ACTION_DEPENDENCY = "remedialActionDependency";
public static final String ROTATING_MACHINE = "rotatingMachineId";
public static final String TAP_CHANGER = "tapChangerId";
public static final String TAP_CHANGER_ID = "tapChangerId";
public static final String NORMAL_VALUE = "normalValue";
public static final String OVERRIDE_VALUE = "value";
public static final String STATIC_PROPERTY_RANGE_VALUE_KIND = "valueKind";
public static final String STATIC_PROPERTY_RANGE_DIRECTION = "direction";
public static final String TAP_CHANGER = "tapChanger";
public static final String POWER_TRANSFORMER = "powerTransformer";
public static final String REQUEST_TAP_CHANGER = "tapChanger";

/**
* requests for flow cnec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.powsybl.openrao.data.cracio.commons.OpenRaoImportException;
import com.powsybl.openrao.data.cracio.csaprofiles.nc.RemedialActionDependency;
import com.powsybl.openrao.data.cracio.csaprofiles.nc.SchemeRemedialAction;
import com.powsybl.openrao.data.cracio.csaprofiles.nc.TapChanger;
import com.powsybl.openrao.data.cracio.csaprofiles.nc.TapPositionAction;

import java.util.*;
Expand All @@ -53,7 +54,8 @@ public CsaProfileRemedialActionsCreator(Crac crac, Network network, CsaProfileCr
this.crac = crac;
this.elementaryActionsHelper = new ElementaryActionsHelper(nativeCrac);
this.networkActionCreator = new NetworkActionCreator(this.crac, network);
this.pstRangeActionCreator = new PstRangeActionCreator(this.crac, network);
Map<String, String> pstPerTapChanger = new NcAggregator<>(TapChanger::powerTransformer).aggregate(nativeCrac.getTapChangers()).entrySet().stream().collect(Collectors.toMap(entry -> entry.getValue().iterator().next().mrid(), Map.Entry::getKey));
this.pstRangeActionCreator = new PstRangeActionCreator(this.crac, network, pstPerTapChanger);
Map<String, Set<AssessedElementWithRemedialAction>> linkedAeWithRa = new NcAggregator<>(AssessedElementWithRemedialAction::remedialAction).aggregate(nativeCrac.getAssessedElementWithRemedialActions());
Map<String, Set<ContingencyWithRemedialAction>> linkedCoWithRa = new NcAggregator<>(ContingencyWithRemedialAction::remedialAction).aggregate(nativeCrac.getContingencyWithRemedialActions());
this.nativeRemedialActions = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@
public class PstRangeActionCreator {
private final Crac crac;
private final Network network;
private final Map<String, String> pstPerTapChanger;

public PstRangeActionCreator(Crac crac, Network network) {
public PstRangeActionCreator(Crac crac, Network network, Map<String, String> pstPerTapChanger) {
this.crac = crac;
this.network = network;
this.pstPerTapChanger = pstPerTapChanger;
}

public PstRangeActionAdder getPstRangeActionAdder(boolean isGroup, String elementaryActionsAggregatorId, TapPositionAction nativeTapPositionAction, Map<String, Set<StaticPropertyRange>> linkedStaticPropertyRanges, String remedialActionId) {
Expand All @@ -50,7 +52,11 @@ private void addTapPositionElementaryAction(boolean isGroup, String elementaryAc
throw new OpenRaoImportException(ImportStatus.NOT_FOR_RAO, String.format("Remedial action %s will not be imported because the field normalEnabled in TapPositionAction is set to false", remedialActionId));
}
CsaProfileCracUtils.checkPropertyReference(remedialActionId, "TapPositionAction", PropertyReference.TAP_CHANGER, nativeTapPositionAction.propertyReference());
IidmPstHelper iidmPstHelper = new IidmPstHelper(nativeTapPositionAction.tapChangerId(), network);
if (!pstPerTapChanger.containsKey(nativeTapPositionAction.tapChangerId())) {
throw new OpenRaoImportException(ImportStatus.ELEMENT_NOT_FOUND_IN_NETWORK, String.format("Remedial action %s will not be imported because no PowerTransformer was found in the network for TapChanger %s", remedialActionId, nativeTapPositionAction.tapChangerId()));
}
String pstId = pstPerTapChanger.get(nativeTapPositionAction.tapChangerId());
IidmPstHelper iidmPstHelper = new IidmPstHelper(pstId, network);
if (!iidmPstHelper.isValid()) {
throw new OpenRaoImportException(ImportStatus.ELEMENT_NOT_FOUND_IN_NETWORK, String.format("Remedial action %s will not be imported because %s", remedialActionId, iidmPstHelper.getInvalidReason()));
}
Expand All @@ -59,7 +65,7 @@ private void addTapPositionElementaryAction(boolean isGroup, String elementaryAc
pstRangeActionAdder.withGroupId(elementaryActionsAggregatorId);
}
pstRangeActionAdder
.withNetworkElement(nativeTapPositionAction.tapChangerId())
.withNetworkElement(pstId)
.withInitialTap(iidmPstHelper.getInitialTap())
.withTapToAngleConversionMap(iidmPstHelper.getTapToAngleConversionMap());

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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.data.cracio.csaprofiles.nc;

import com.powsybl.openrao.data.cracio.csaprofiles.craccreator.constants.CsaProfileConstants;
import com.powsybl.triplestore.api.PropertyBag;

/**
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>}
*/
public record TapChanger(String mrid, String powerTransformer) implements NCObject {
public static TapChanger fromPropertyBag(PropertyBag propertyBag) {
return new TapChanger(propertyBag.getId(CsaProfileConstants.TAP_CHANGER), propertyBag.getId(CsaProfileConstants.POWER_TRANSFORMER));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public record TapPositionAction(String mrid, String tapChangerId, String propert
public static TapPositionAction fromPropertyBag(PropertyBag propertyBag) {
return new TapPositionAction(
propertyBag.getId(CsaProfileConstants.TAP_POSITION_ACTION),
propertyBag.getId(CsaProfileConstants.TAP_CHANGER),
propertyBag.getId(CsaProfileConstants.TAP_CHANGER_ID),
propertyBag.get(CsaProfileConstants.GRID_ALTERATION_PROPERTY_REFERENCE),
Boolean.parseBoolean(propertyBag.getOrDefault(CsaProfileConstants.NORMAL_ENABLED, "true")),
propertyBag.getId(CsaProfileConstants.REQUEST_GRID_STATE_ALTERATION_REMEDIAL_ACTION),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -798,3 +798,21 @@ GRAPH <%s> {
nc:RemedialActionDependency.enabled ?enabled .
}
}

# query: tapChanger
PREFIX cim: <http://iec.ch/TC57/2013/CIM-schema-cim16#>
SELECT *
{
VALUES ?type { cim:PhaseTapChangerSymmetrical cim:PhaseTapChangerAsymmetrical cim:PhaseTapChangerLinear cim:PhaseTapChangerTabular cim:RatioTapChanger }
GRAPH <%s> {
?tapChanger rdf:type ?type .

# Conditionally bind the correct TransformerEnd based on the type of the tap changer
BIND(IF(?type = cim:RatioTapChanger, cim:RatioTapChanger.TransformerEnd, cim:PhaseTapChanger.TransformerEnd) AS ?transformerEndProperty)

?tapChanger ?transformerEndProperty ?transformerEnd .

?transformerEnd rdf:type cim:PowerTransformerEnd ;
cim:PowerTransformerEnd.PowerTransformer ?powerTransformer .
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void importPstRangeActions() {

assertEquals(7, cracCreationContext.getRemedialActionCreationContexts().stream().filter(context -> !context.isImported()).toList().size());

assertRaNotImported(cracCreationContext, "remedial-action-5", ImportStatus.ELEMENT_NOT_FOUND_IN_NETWORK, "Remedial action remedial-action-5 will not be imported because transformer with id unknown-pst was not found in network");
assertRaNotImported(cracCreationContext, "remedial-action-5", ImportStatus.ELEMENT_NOT_FOUND_IN_NETWORK, "Remedial action remedial-action-5 will not be imported because no PowerTransformer was found in the network for TapChanger unknown-tap-changer");
assertRaNotImported(cracCreationContext, "remedial-action-6", ImportStatus.INCONSISTENCY_IN_DATA, "Remedial action remedial-action-6 will not be imported because TapPositionAction must have a property reference with http://energy.referencedata.eu/PropertyReference/TapChanger.step value, but it was: http://energy.referencedata.eu/PropertyReference/Switch.open");
assertRaNotImported(cracCreationContext, "remedial-action-7", ImportStatus.INCONSISTENCY_IN_DATA, "Remedial action remedial-action-7 will not be imported because StaticPropertyRange must have a property reference with http://energy.referencedata.eu/PropertyReference/TapChanger.step value, but it was: http://energy.referencedata.eu/PropertyReference/Switch.open");
assertRaNotImported(cracCreationContext, "remedial-action-9", ImportStatus.NOT_FOR_RAO, "Remedial action remedial-action-9 will not be imported because the field normalEnabled in TapPositionAction is set to false");
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit df23b63

Please sign in to comment.