Skip to content
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 @@ -376,6 +376,14 @@ private static void setPhaseTapChangerRegulationAttributes(PhaseTapChanger phase
// the order is important if regulation mode is set and regulation value or target dead band is null it will crash
PhaseTapChanger.RegulationMode regulationMode = regulationModeModification == null ? null : regulationModeModification.getValue();
String fieldName = (regulationMode == CURRENT_LIMITER) ? "Value" : "Flow set point";
// TODO implement some entity to modify all element at once in powsybl core/network store
// it is a fix to avoid to set regulation value to negative before setting regulation mode to ACTIVE_POWER_CONTROL
// so if a new mode is set, regulating is first set to false to pass all check and finally set to its true value
boolean previousRegulatingValue = isModification && phaseTapChanger.isRegulating();
if (isModification && phaseTapChanger.isRegulating()) {
phaseTapChanger.setRegulating(false);
}

// Regulation value
ReportNode regulationValueReportNode = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(
isModification ? phaseTapChanger::setRegulationValue : phaseTapChangerAdder::setRegulationValue,
Expand Down Expand Up @@ -405,11 +413,15 @@ private static void setPhaseTapChangerRegulationAttributes(PhaseTapChanger phase
// Regulating
ReportNode regulatingReportNode = ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(
isModification ? phaseTapChanger::setRegulating : phaseTapChangerAdder::setRegulating,
isModification ? phaseTapChanger::isRegulating : () -> null,
isModification ? () -> previousRegulatingValue : () -> null,
regulatingModification, "Phase tap regulating");
if (regulationReports != null && regulatingReportNode != null) {
regulationReports.add(regulatingReportNode);
}
// fix because can not modify several elements at once
if (isModification && regulatingModification == null && previousRegulatingValue) {
phaseTapChanger.setRegulating(true);
}
}

private void processRatioTapChanger(Network network,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1023,5 +1023,42 @@ void testProcessPhaseTapChangerRegulationModification() {
regulationActivePowerControlModeModification, regulationValueModification, null, regulatingModification, regulationReports));
}

@Test
void testProcessPhaseTapChangerRegulationModificationWithRegulating() {
TwoWindingsTransformer twt = createTwoWindingsTransformer(getNetwork().getSubstation("s1"), "trf3", "trf3", 2.0, 14.745, 0.0, 3.2E-5, 400.0, 225.0,
41, 151, getNetwork().getVoltageLevel("v1").getId(), getNetwork().getVoltageLevel("v2").getId(),
"trf3", 1, ConnectablePosition.Direction.TOP,
"trf3", 2, ConnectablePosition.Direction.TOP);
PhaseTapChangerAdder adder = twt.newPhaseTapChanger();
preparePhaseTapChangerAdder(adder);
adder.add();
PhaseTapChanger phaseTapChanger = twt.getPhaseTapChanger();

phaseTapChanger.setRegulationValue(100);
phaseTapChanger.setTargetDeadband(0);
phaseTapChanger.setRegulationMode(PhaseTapChanger.RegulationMode.CURRENT_LIMITER);
phaseTapChanger.setRegulating(true);

List<ReportNode> regulationReports = new ArrayList<>();
AttributeModification<PhaseTapChanger.RegulationMode> regulationActivePowerControlModeModification = new AttributeModification<>(
PhaseTapChanger.RegulationMode.ACTIVE_POWER_CONTROL, OperationType.SET);
AttributeModification<Double> regulationValueModification = new AttributeModification<>(-100.0, OperationType.SET);

processPhaseTapRegulation(phaseTapChanger, null, true,
regulationActivePowerControlModeModification, regulationValueModification, null, null, regulationReports);
assertEquals(-100.0, phaseTapChanger.getRegulationValue());
assertEquals(PhaseTapChanger.RegulationMode.ACTIVE_POWER_CONTROL, phaseTapChanger.getRegulationMode());
assertTrue(phaseTapChanger.isRegulating());

AttributeModification<PhaseTapChanger.RegulationMode> regulationCurrentLimiterModeModification = new AttributeModification<>(
PhaseTapChanger.RegulationMode.CURRENT_LIMITER, OperationType.SET);
AttributeModification<Double> regulationValueModification2 = new AttributeModification<>(100.0, OperationType.SET);
processPhaseTapRegulation(phaseTapChanger, null, true,
regulationCurrentLimiterModeModification, regulationValueModification2, null, null, regulationReports);
assertEquals(100.0, phaseTapChanger.getRegulationValue());
assertEquals(PhaseTapChanger.RegulationMode.CURRENT_LIMITER, phaseTapChanger.getRegulationMode());
assertTrue(phaseTapChanger.isRegulating());
}

}