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

check null values for droop and P0 #512

Merged
merged 18 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -114,7 +114,8 @@ public enum Type {
MODIFY_CONVERTER_STATION_ERROR(HttpStatus.INTERNAL_SERVER_ERROR),
BY_FORMULA_MODIFICATION_ERROR(HttpStatus.INTERNAL_SERVER_ERROR),
HVDC_LINE_NOT_FOUND(HttpStatus.NOT_FOUND),
COMPOSITE_MODIFICATION_ERROR(HttpStatus.INTERNAL_SERVER_ERROR);
COMPOSITE_MODIFICATION_ERROR(HttpStatus.INTERNAL_SERVER_ERROR),
WRONG_HVDC_ANGLE_DROOP_ACTIVE_POWER_CONTROL(HttpStatus.BAD_REQUEST);


public final HttpStatus status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
*/

public class VscModification extends AbstractModification {
public static final String ACTIVE_POWER_CONTROL_ERROR_MESSAGE = "%s attribute(s): %s can not be missing if angle droop active power control is activated";
private final VscModificationInfos modificationInfos;
private static final String NO_VALUE = "No value";

Expand All @@ -57,15 +58,22 @@ public void check(Network network) throws NetworkModificationException {
VscConverterStation converterStation2 = ModificationUtils.getInstance().getVscConverterStation(network, hvdcLine.getConverterStation2().getId());
checkConverterStation(modificationInfos.getConverterStation1(), converterStation1);
checkConverterStation(modificationInfos.getConverterStation2(), converterStation2);

checkDroopModification();

boolean isEnabled = modificationInfos.getAngleDroopActivePowerControl() != null
&& modificationInfos.getAngleDroopActivePowerControl().getValue();
if (isEnabled) {
checkDroopModification(hvdcLine.getId());
}
}

private void checkDroopModification() {
// if droop is set p0 should be also
if (modificationInfos.getP0() == null && modificationInfos.getDroop() != null) {
throw new NetworkModificationException(MODIFY_VSC_ERROR, "P0 is required to modify the equipment");
private void checkDroopModification(String hvdcId) {
if (modificationInfos.getDroop() == null && modificationInfos.getP0() == null) {
throw modifyHvdcAngleDroopActivePowerControl(hvdcId, "Droop and P0");
}
if (modificationInfos.getDroop() == null) {
throw modifyHvdcAngleDroopActivePowerControl(hvdcId, "Droop");
}
if (modificationInfos.getP0() == null) {
throw modifyHvdcAngleDroopActivePowerControl(hvdcId, "P0");
}
}

Expand Down Expand Up @@ -257,6 +265,11 @@ private List<ReportNode> hvdcAngleDroopActivePowerControlAdder(HvdcLine hvdcLine
return reports;
}

private static NetworkModificationException modifyHvdcAngleDroopActivePowerControl(@lombok.NonNull String equipementName, @lombok.NonNull String attributeName) {
thangqp marked this conversation as resolved.
Show resolved Hide resolved
throw new NetworkModificationException(NetworkModificationException.Type.WRONG_HVDC_ANGLE_DROOP_ACTIVE_POWER_CONTROL,
thangqp marked this conversation as resolved.
Show resolved Hide resolved
String.format(ACTIVE_POWER_CONTROL_ERROR_MESSAGE, equipementName, attributeName));
}

private void modifyConverterStation(VscConverterStation converterStation, ConverterStationModificationInfos converterStationModificationInfos, ReportNode subReportNode) {
if (converterStationModificationInfos == null || !isConverterStationModified(converterStationModificationInfos)) {
return;
Expand Down Expand Up @@ -340,5 +353,4 @@ private void modifyVscReactiveLimitsAttributes(ConverterStationModificationInfos
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
import java.util.*;
import java.util.stream.IntStream;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.gridsuite.modification.server.NetworkModificationException.Type.WRONG_HVDC_ANGLE_DROOP_ACTIVE_POWER_CONTROL;
import static org.gridsuite.modification.server.modifications.VscModification.ACTIVE_POWER_CONTROL_ERROR_MESSAGE;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
Expand Down Expand Up @@ -235,10 +236,62 @@ public void testActivateHvdcAngleDroopActivePowerControl() throws Exception {
assertNotNull(hvdcLine);

HvdcAngleDroopActivePowerControl activePowerControl = hvdcLine.getExtension(HvdcAngleDroopActivePowerControl.class);
assertNotNull(activePowerControl);
Assert.assertEquals(5, activePowerControl.getP0(), 0);
Assert.assertEquals(1, activePowerControl.getDroop(), 0);
Assert.assertTrue(activePowerControl.isEnabled());
}

@Test
public void testActivateHvdcAngleDroopActivePowerControlWithNullValues() throws Exception {
var networkuuid = UUID.randomUUID();
Network networkWitoutExt = NetworkCreation.createWithVSC(networkuuid, false);
ReportNode subReporter = ReportNode.NO_OP;
ComputationManager computationManager = new LocalComputationManager();
VscModificationInfos wrongModificationInfos = (VscModificationInfos) buildModification();
wrongModificationInfos.setDroop(null);
wrongModificationInfos.setP0(null);
wrongModificationInfos.setAngleDroopActivePowerControl(new AttributeModification<>(true, OperationType.SET));
VscModification wrongVscModification = new VscModification(wrongModificationInfos);
String message = Assert.assertThrows(NetworkModificationException.class,
() -> wrongVscModification.check(networkWitoutExt))
.getMessage();
Assert.assertEquals(WRONG_HVDC_ANGLE_DROOP_ACTIVE_POWER_CONTROL.name() + " : " + String.format(ACTIVE_POWER_CONTROL_ERROR_MESSAGE,
"hvdcLine", "Droop and P0"), message);
}

@Test
public void testActivateHvdcAngleDroopActivePowerControlWithDroopNull() throws Exception {
var networkuuid = UUID.randomUUID();
Network networkWitoutExt = NetworkCreation.createWithVSC(networkuuid, false);
ReportNode subReporter = ReportNode.NO_OP;
ComputationManager computationManager = new LocalComputationManager();
VscModificationInfos wrongModificationInfos = (VscModificationInfos) buildModification();
wrongModificationInfos.setDroop(null);
wrongModificationInfos.setP0(new AttributeModification<>(100f, OperationType.SET));
wrongModificationInfos.setAngleDroopActivePowerControl(new AttributeModification<>(true, OperationType.SET));
VscModification wrongVscModification = new VscModification(wrongModificationInfos);
String message = Assert.assertThrows(NetworkModificationException.class,
() -> wrongVscModification.check(networkWitoutExt))
.getMessage();
Assert.assertEquals(WRONG_HVDC_ANGLE_DROOP_ACTIVE_POWER_CONTROL.name() + " : " + String.format(ACTIVE_POWER_CONTROL_ERROR_MESSAGE,
"hvdcLine", "Droop"), message);
}

@Test
public void testActivateHvdcAngleDroopActivePowerControlWithP0Null() {
var networkuuid = UUID.randomUUID();
Network networkWitoutExt = NetworkCreation.createWithVSC(networkuuid, false);
VscModificationInfos wrongModificationInfos = (VscModificationInfos) buildModification();
wrongModificationInfos.setDroop(new AttributeModification<>(20f, OperationType.SET));
wrongModificationInfos.setP0(null);
wrongModificationInfos.setAngleDroopActivePowerControl(new AttributeModification<>(true, OperationType.SET));
VscModification wrongVscModification = new VscModification(wrongModificationInfos);
String message = Assert.assertThrows(NetworkModificationException.class,
() -> wrongVscModification.check(networkWitoutExt))
.getMessage();
Assert.assertEquals(WRONG_HVDC_ANGLE_DROOP_ACTIVE_POWER_CONTROL.name() + " : " + String.format(ACTIVE_POWER_CONTROL_ERROR_MESSAGE,
"hvdcLine", "P0"), message);
}

@Test
Expand Down Expand Up @@ -278,7 +331,7 @@ public void testHvdcAngleDroopActivePowerControlWithoutP0() {
modificationInfos.setDroop(null);
modificationInfos.setP0(new AttributeModification<>(10F, OperationType.SET));
VscModification vscModification = new VscModification(modificationInfos);
assertDoesNotThrow(() -> vscModification.check(networkWitoutExt));
Assert.assertThrows(NetworkModificationException.class, () -> vscModification.check(networkWitoutExt));

}

Expand Down
Loading