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

Proposed fix regulating phase tap changer #547

Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static void setNewValue(TwoWindingsTransformer transformer, String twoWin
case PHASE_TAP_POSITION -> processTapChangerPositionsAndSteps(phaseTapChanger, null, true,
null, new AttributeModification<>((int) Double.parseDouble(newValue), OperationType.SET), null, null);
case PHASE_TARGET_DEADBAND -> processPhaseTapRegulation(
phaseTapChanger, null, null, true, null, attributeModification, null
phaseTapChanger, null, regulationMode, true, null, attributeModification, null
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.List;

import static org.gridsuite.modification.server.NetworkModificationException.Type.TWO_WINDINGS_TRANSFORMER_NOT_FOUND;
import static org.gridsuite.modification.server.dto.AttributeModification.toAttributeModification;
import static org.gridsuite.modification.server.modifications.ModificationUtils.insertReportNode;

/**
Expand Down Expand Up @@ -215,10 +216,8 @@ private void processPhaseTapChanger(Network network,
regulationMode = phaseTapChangerInfos.getRegulationMode().getValue();
}

if (!PhaseTapChanger.RegulationMode.FIXED_TAP.equals(regulationMode)) {
processPhaseTapRegulation(phaseTapChanger, phaseTapChangerAdder, regulationMode, isModification,
processPhaseTapRegulation(phaseTapChanger, phaseTapChangerAdder, regulationMode, isModification,
phaseTapChangerInfos.getRegulationValue(), phaseTapChangerInfos.getTargetDeadband(), regulationReports);
}

processRegulatingTerminal(phaseTapChangerInfos, phaseTapChanger, phaseTapChangerAdder, regulationReports,
network,
Expand Down Expand Up @@ -250,6 +249,14 @@ private void processPhaseTapChanger(Network network,
}
}

public static String getRegulationValueLabel(PhaseTapChanger.RegulationMode regulationMode) {
return switch (regulationMode) {
case FIXED_TAP -> "Current or Flow set point";
case CURRENT_LIMITER -> "Current";
case ACTIVE_POWER_CONTROL -> "Flow set point";
};
}

public static void processPhaseTapRegulation(PhaseTapChanger phaseTapChanger,
PhaseTapChangerAdder phaseTapChangerAdder,
PhaseTapChanger.RegulationMode regulationMode,
Expand All @@ -258,45 +265,52 @@ public static void processPhaseTapRegulation(PhaseTapChanger phaseTapChanger,
AttributeModification<Double> modifyTargetDeadband,
List<ReportNode> regulationReports) {

if (regulationMode != null) {
String fieldName = (regulationMode == PhaseTapChanger.RegulationMode.CURRENT_LIMITER) ? "Value" : "Flow set point";
if (regulationMode == null) {
return;
}

if (regulationMode != PhaseTapChanger.RegulationMode.FIXED_TAP) {
// Flow set point or current limiter
ReportNode regulationValueReportNode = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(
isModification ? phaseTapChanger::setRegulationValue
: phaseTapChangerAdder::setRegulationValue,
isModification ? phaseTapChanger::getRegulationValue : () -> null,
modifyRegulationValue,
fieldName,
getRegulationValueLabel(regulationMode),
2);
if (regulationReports != null && regulationValueReportNode != null) {
regulationReports.add(regulationValueReportNode);
}

// Deadband
ReportNode targetDeadbandReportNode = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(
isModification ? phaseTapChanger::setTargetDeadband
: phaseTapChangerAdder::setTargetDeadband,
isModification ? phaseTapChanger::getTargetDeadband : () -> null,
modifyTargetDeadband,
"Target deadband",
2);

if (regulationReports != null && targetDeadbandReportNode != null) {
regulationReports.add(targetDeadbandReportNode);
}
}

ReportNode targetDeadbandReportNode = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(
isModification ? phaseTapChanger::setTargetDeadband
: phaseTapChangerAdder::setTargetDeadband,
isModification ? phaseTapChanger::getTargetDeadband : () -> null,
modifyTargetDeadband, "Target deadband", 2);

if (regulationReports != null && targetDeadbandReportNode != null) {
regulationReports.add(targetDeadbandReportNode);
}
if (regulationMode != null) {
processRegulating(isModification, phaseTapChanger, phaseTapChangerAdder,
regulationMode != PhaseTapChanger.RegulationMode.FIXED_TAP, regulationReports);
}
}

private static void processRegulating(boolean isModification, PhaseTapChanger phaseTapChanger, PhaseTapChangerAdder phaseTapChangerAdder,
boolean regulating, List<ReportNode> regulationReports) {
ReportNode regulatingReportNode = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(
isModification ? phaseTapChanger::setRegulating
: phaseTapChangerAdder::setRegulating,
isModification ? phaseTapChanger::isRegulating : () -> null,
AttributeModification.toAttributeModification(regulating, OperationType.SET),
regulating ? "Voltage regulation" : "Phase tap regulating", 1);
if (regulationReports != null && regulatingReportNode != null) {
regulationReports.add(regulatingReportNode);
// regulating
// IF current regulating mode is different to FIXED_TAB, and we switch to FIXED_TAP => SET regulating to false, otherwise true
PhaseTapChanger.RegulationMode oldRegulationMode = isModification ? phaseTapChanger.getRegulationMode() : null;
boolean newRegulating = !(oldRegulationMode != PhaseTapChanger.RegulationMode.FIXED_TAP && regulationMode == PhaseTapChanger.RegulationMode.FIXED_TAP);

if (oldRegulationMode != PhaseTapChanger.RegulationMode.FIXED_TAP && regulationMode == PhaseTapChanger.RegulationMode.FIXED_TAP) {
ReportNode regulatingReportNode = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(
isModification ? phaseTapChanger::setRegulating
: phaseTapChangerAdder::setRegulating,
isModification ? phaseTapChanger::isRegulating : () -> null,
toAttributeModification(newRegulating, OperationType.SET),
"Phase tap regulating", 1);
if (regulationReports != null && regulatingReportNode != null) {
regulationReports.add(regulatingReportNode);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,13 @@ protected void createEquipments() {
"trf1", 38, ConnectablePosition.Direction.TOP,
"trf1", 49, ConnectablePosition.Direction.BOTTOM);
twt6.setRatedS(20);
addPhaseTapChangerSteps(twt6.newPhaseTapChanger().setRegulationValue(47).setLowTapPosition(1).setTapPosition(1).setTargetDeadband(36));
addPhaseTapChangerSteps(twt6.newPhaseTapChanger()
.setRegulationMode(PhaseTapChanger.RegulationMode.FIXED_TAP)
.setRegulationValue(47)
.setTargetDeadband(36)
.setLowTapPosition(1)
.setTapPosition(1)
);
}

@Override
Expand Down Expand Up @@ -387,7 +393,7 @@ protected void assertAfterNetworkModificationCreation() {

TwoWindingsTransformer twt5 = getNetwork().getTwoWindingsTransformer(TWT_ID_5);
PhaseTapChanger phaseTapChanger5 = twt5.getPhaseTapChanger();
assertNotNull(phaseTapChanger4);
assertNotNull(phaseTapChanger5);
assertEquals(2, phaseTapChanger5.getLowTapPosition());
assertEquals(2, phaseTapChanger5.getTapPosition());
assertEquals(2, twt5.getR(), 0);
Expand All @@ -396,9 +402,9 @@ protected void assertAfterNetworkModificationCreation() {

TwoWindingsTransformer twt6 = getNetwork().getTwoWindingsTransformer(TWT_ID_6);
PhaseTapChanger phaseTapChanger6 = twt6.getPhaseTapChanger();
assertNotNull(phaseTapChanger4);
assertEquals(2, phaseTapChanger6.getRegulationValue(), 0);
assertEquals(10, phaseTapChanger6.getTargetDeadband(), 0);
assertNotNull(phaseTapChanger6);
assertEquals(47, phaseTapChanger6.getRegulationValue(), 0);
assertEquals(36, phaseTapChanger6.getTargetDeadband(), 0);
assertEquals(20, twt6.getX(), 0);
assertEquals(25, twt6.getG(), 0);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@
package org.gridsuite.modification.server.modifications.byfilter.formula;

import com.github.tomakehurst.wiremock.client.WireMock;
import com.powsybl.iidm.network.IdentifiableType;
import com.powsybl.iidm.network.PhaseTapChanger;
import com.powsybl.iidm.network.PhaseTapChangerAdder;
import com.powsybl.iidm.network.RatioTapChanger;
import com.powsybl.iidm.network.RatioTapChangerAdder;
import com.powsybl.iidm.network.Substation;
import com.powsybl.iidm.network.TwoWindingsTransformer;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.extensions.ConnectablePosition;
import org.gridsuite.filter.AbstractFilter;
import org.gridsuite.filter.identifierlistfilter.IdentifierListFilter;
import org.gridsuite.filter.identifierlistfilter.IdentifierListFilterEquipmentAttributes;
import org.gridsuite.filter.utils.EquipmentType;
import org.gridsuite.modification.server.dto.ByFormulaModificationInfos;
import org.gridsuite.modification.server.dto.NetworkModificationResult;
import org.gridsuite.modification.server.dto.byfilter.equipmentfield.TwoWindingsTransformerField;
import org.gridsuite.modification.server.dto.byfilter.formula.FormulaInfos;
import org.gridsuite.modification.server.dto.byfilter.formula.Operator;
import org.gridsuite.modification.server.dto.byfilter.formula.ReferenceFieldOrValue;
import org.gridsuite.modification.server.dto.byfilter.equipmentfield.TwoWindingsTransformerField;
import org.junit.Test;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import static org.gridsuite.modification.server.utils.NetworkUtil.createTwoWindingsTransformer;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.*;

public class TwoWindingsTransformerByFormulaModificationTest extends AbstractByFormulaModificationTest {
private static final String TWT_ID_1 = "twt1";
Expand Down Expand Up @@ -173,7 +165,7 @@ protected void createEquipments() {
"trf1", 30, ConnectablePosition.Direction.TOP,
"trf1", 40, ConnectablePosition.Direction.BOTTOM);
twt4.setRatedS(15);
addPhaseTapChangerSteps(twt4.newPhaseTapChanger().setRegulationValue(45).setLowTapPosition(1).setTapPosition(2).setTargetDeadband(34));
addPhaseTapChangerSteps(twt4.newPhaseTapChanger().setRegulationMode(PhaseTapChanger.RegulationMode.CURRENT_LIMITER).setRegulationValue(45).setLowTapPosition(1).setTapPosition(2).setTargetDeadband(34));

TwoWindingsTransformer twt5 = createTwoWindingsTransformer(s3, TWT_ID_5, TWT_ID_5, 50, 60, 70,
80, 30, 40, 101, 101,
Expand All @@ -189,7 +181,7 @@ protected void createEquipments() {
"trf1", 38, ConnectablePosition.Direction.TOP,
"trf1", 49, ConnectablePosition.Direction.BOTTOM);
twt6.setRatedS(20);
addPhaseTapChangerSteps(twt6.newPhaseTapChanger().setRegulationValue(47).setLowTapPosition(1).setTapPosition(1).setTargetDeadband(36));
addPhaseTapChangerSteps(twt6.newPhaseTapChanger().setRegulationMode(PhaseTapChanger.RegulationMode.FIXED_TAP).setRegulationValue(47).setLowTapPosition(1).setTapPosition(1).setTargetDeadband(36));
}

@Override
Expand Down Expand Up @@ -415,7 +407,7 @@ protected void assertAfterNetworkModificationCreation() {

TwoWindingsTransformer twt5 = getNetwork().getTwoWindingsTransformer(TWT_ID_5);
PhaseTapChanger phaseTapChanger5 = twt5.getPhaseTapChanger();
assertNotNull(phaseTapChanger4);
assertNotNull(phaseTapChanger5);
assertEquals(4, phaseTapChanger5.getLowTapPosition());
assertEquals(4, phaseTapChanger5.getTapPosition());
assertEquals(100, twt5.getR(), 0);
Expand All @@ -424,9 +416,9 @@ protected void assertAfterNetworkModificationCreation() {

TwoWindingsTransformer twt6 = getNetwork().getTwoWindingsTransformer(TWT_ID_6);
PhaseTapChanger phaseTapChanger6 = twt6.getPhaseTapChanger();
assertNotNull(phaseTapChanger4);
assertEquals(94, phaseTapChanger6.getRegulationValue(), 0);
assertEquals(26, phaseTapChanger6.getTargetDeadband(), 0);
assertNotNull(phaseTapChanger6);
assertEquals(47, phaseTapChanger6.getRegulationValue(), 0);
assertEquals(36, phaseTapChanger6.getTargetDeadband(), 0);
assertEquals(85, twt6.getX(), 0);
assertEquals(100, twt6.getG(), 0);
}
Expand Down
Loading