Skip to content

Commit

Permalink
add checks on active power control creation (#545)
Browse files Browse the repository at this point in the history
Signed-off-by: Etienne LESOT <[email protected]>
  • Loading branch information
EtienneLt authored Oct 23, 2024
1 parent 15816de commit 6f7a9da
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
import org.gridsuite.modification.server.modifications.ModificationUtils;

import static org.gridsuite.modification.server.NetworkModificationException.Type.MODIFY_BATTERY_ERROR;
import static org.gridsuite.modification.server.modifications.BatteryModification.modifyBatteryActiveLimitsAttributes;
import static org.gridsuite.modification.server.modifications.BatteryModification.modifyBatterySetpointsAttributes;
import static org.gridsuite.modification.server.modifications.BatteryModification.*;

/**
* @author Seddik Yengui <Seddik.yengui at rte-france.com>
Expand All @@ -44,6 +43,7 @@ public static String getReferenceValue(Battery battery, String batteryField) {

public static void setNewValue(Battery battery, String batteryField, @NotNull String newValue) {
BatteryField field = BatteryField.valueOf(batteryField);
String errorMessage = String.format(ERROR_MESSAGE, battery.getId());
final AttributeModification<Double> attributeModification = new AttributeModification<>(Double.parseDouble(newValue), OperationType.SET);
switch (field) {
case MINIMUM_ACTIVE_POWER ->
Expand All @@ -53,7 +53,7 @@ public static void setNewValue(Battery battery, String batteryField, @NotNull St
case ACTIVE_POWER_SET_POINT -> {
ModificationUtils.getInstance().checkActivePowerZeroOrBetweenMinAndMaxActivePower(
attributeModification, null, null, battery.getMinP(),
battery.getMaxP(), battery.getTargetP(), MODIFY_BATTERY_ERROR, "Battery '" + battery.getId() + "' : "
battery.getMaxP(), battery.getTargetP(), MODIFY_BATTERY_ERROR, errorMessage
);
modifyBatterySetpointsAttributes(attributeModification, null, null, null, battery, null);
}
Expand All @@ -64,7 +64,8 @@ public static void setNewValue(Battery battery, String batteryField, @NotNull St
ActivePowerControlAdder<Battery> activePowerControlAdder = battery.newExtension(ActivePowerControlAdder.class);
ModificationUtils.getInstance().modifyActivePowerControlAttributes(
activePowerControl, activePowerControlAdder, null,
new AttributeModification<>(Float.parseFloat(newValue), OperationType.SET), null, null);
new AttributeModification<>(Float.parseFloat(newValue), OperationType.SET), null,
null, MODIFY_BATTERY_ERROR, errorMessage);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public static String getReferenceValue(Generator generator, String generatorFiel

public static void setNewValue(Generator generator, String generatorField, @NotNull String newValue) {
GeneratorField field = GeneratorField.valueOf(generatorField);
String errorMessage = String.format(ERROR_MESSAGE, generator.getId());
switch (field) {
case MAXIMUM_ACTIVE_POWER -> modifyGeneratorActiveLimitsAttributes(
new AttributeModification<>(Double.parseDouble(newValue), OperationType.SET),
Expand All @@ -75,7 +76,7 @@ public static void setNewValue(Generator generator, String generatorField, @NotN
ModificationUtils.getInstance().checkActivePowerZeroOrBetweenMinAndMaxActivePower(
new AttributeModification<>(Double.parseDouble(newValue), OperationType.SET),
null, null, generator.getMinP(), generator.getMaxP(), generator.getTargetP(),
MODIFY_GENERATOR_ERROR, "Generator '" + generator.getId() + "' : "
MODIFY_GENERATOR_ERROR, errorMessage
);
generator.setTargetP(Double.parseDouble(newValue));
}
Expand All @@ -98,7 +99,8 @@ public static void setNewValue(Generator generator, String generatorField, @NotN
ActivePowerControl<Generator> activePowerControl = generator.getExtension(ActivePowerControl.class);
ActivePowerControlAdder<Generator> activePowerControlAdder = generator.newExtension(ActivePowerControlAdder.class);
ModificationUtils.getInstance().modifyActivePowerControlAttributes(activePowerControl, activePowerControlAdder, null,
new AttributeModification<>(Float.parseFloat(newValue), OperationType.SET), null, null);
new AttributeModification<>(Float.parseFloat(newValue), OperationType.SET), null, null,
MODIFY_GENERATOR_ERROR, errorMessage);
}
case TRANSIENT_REACTANCE -> modifyGeneratorShortCircuitAttributes(
new AttributeModification<>(Double.parseDouble(newValue), OperationType.SET),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.util.List;

import static org.gridsuite.modification.server.NetworkModificationException.Type.BATTERY_ALREADY_EXISTS;
import static org.gridsuite.modification.server.NetworkModificationException.Type.CREATE_BATTERY_ERROR;
import static org.gridsuite.modification.server.modifications.BatteryModification.ERROR_MESSAGE;
import static org.gridsuite.modification.server.modifications.ModificationUtils.*;

/**
Expand Down Expand Up @@ -49,6 +51,9 @@ public void check(Network network) throws NetworkModificationException {
modificationInfos.getErrorType(),
modificationInfos.getEquipmentId(),
"Battery");

ModificationUtils.getInstance().checkActivePowerControl(modificationInfos.getParticipate(),
modificationInfos.getDroop(), CREATE_BATTERY_ERROR, String.format(ERROR_MESSAGE, modificationInfos.getEquipmentId()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class BatteryModification extends AbstractModification {
private static final String LIMITS = "Limits";
private static final String ACTIVE_LIMITS = "Active limits";
private static final String SETPOINTS = "Setpoints";
public static final String ERROR_MESSAGE = "Battery '%s' : ";

public BatteryModification(BatteryModificationInfos modificationInfos) {
this.modificationInfos = modificationInfos;
Expand Down Expand Up @@ -171,7 +172,8 @@ public static ReportNode modifyBatteryActivePowerControlAttributes(AttributeModi
ReportNode subReportNodeSetpoints) {
ActivePowerControl<Battery> activePowerControl = battery.getExtension(ActivePowerControl.class);
ActivePowerControlAdder<Battery> activePowerControlAdder = battery.newExtension(ActivePowerControlAdder.class);
return ModificationUtils.getInstance().modifyActivePowerControlAttributes(activePowerControl, activePowerControlAdder, participate, droop, subReportNode, subReportNodeSetpoints);
return ModificationUtils.getInstance().modifyActivePowerControlAttributes(activePowerControl, activePowerControlAdder,
participate, droop, subReportNode, subReportNodeSetpoints, MODIFY_BATTERY_ERROR, String.format(ERROR_MESSAGE, battery.getId()));
}

private ReportNode modifyBatteryConnectivityAttributes(BatteryModificationInfos modificationInfos,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import java.util.ArrayList;
import java.util.List;

import static org.gridsuite.modification.server.NetworkModificationException.Type.GENERATOR_ALREADY_EXISTS;
import static org.gridsuite.modification.server.NetworkModificationException.Type.*;
import static org.gridsuite.modification.server.modifications.GeneratorModification.ERROR_MESSAGE;
import static org.gridsuite.modification.server.modifications.ModificationUtils.*;

/**
Expand Down Expand Up @@ -58,6 +59,9 @@ public void check(Network network) throws NetworkModificationException {
modificationInfos.getRegulatingTerminalId(),
modificationInfos.getRegulatingTerminalType(),
modificationInfos.getRegulatingTerminalVlId());

ModificationUtils.getInstance().checkActivePowerControl(modificationInfos.getParticipate(),
modificationInfos.getDroop(), CREATE_GENERATOR_ERROR, String.format(ERROR_MESSAGE, modificationInfos.getEquipmentId()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class GeneratorModification extends AbstractModification {
private static final String LIMITS = "Limits";
private static final String ACTIVE_LIMITS = "Active limits";
private static final String SETPOINTS = "Setpoints";
public static final String ERROR_MESSAGE = "Generator '%s' : ";

private final GeneratorModificationInfos modificationInfos;

Expand Down Expand Up @@ -210,7 +211,10 @@ private ReportNode modifyGeneratorActivePowerControlAttributes(GeneratorModifica
Generator generator, ReportNode subReportNode, ReportNode subReportNodeSetpoints) {
ActivePowerControl<Generator> activePowerControl = generator.getExtension(ActivePowerControl.class);
ActivePowerControlAdder<Generator> activePowerControlAdder = generator.newExtension(ActivePowerControlAdder.class);
return ModificationUtils.getInstance().modifyActivePowerControlAttributes(activePowerControl, activePowerControlAdder, modificationInfos.getParticipate(), modificationInfos.getDroop(), subReportNode, subReportNodeSetpoints);

return ModificationUtils.getInstance().modifyActivePowerControlAttributes(activePowerControl, activePowerControlAdder,
modificationInfos.getParticipate(), modificationInfos.getDroop(), subReportNode, subReportNodeSetpoints,
MODIFY_GENERATOR_ERROR, String.format(ERROR_MESSAGE, modificationInfos.getEquipmentId()));
}

private void modifyGeneratorStartUpAttributes(GeneratorModificationInfos modificationInfos, Generator generator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1184,38 +1184,49 @@ private void modifyExistingActivePowerControl(ActivePowerControl<?> activePowerC
private void createNewActivePowerControl(ActivePowerControlAdder<?> adder,
AttributeModification<Boolean> participateInfo,
AttributeModification<Float> droopInfo,
List<ReportNode> reports) {
boolean participate = participateInfo != null ? participateInfo.getValue() : false;
adder.withParticipate(participate);
if (participateInfo != null && reports != null) {
reports.add(buildModificationReport(null, participate, "Participate"));
List<ReportNode> reports,
NetworkModificationException.Type exceptionType,
String errorMessage) {
Boolean participate = Optional.ofNullable(participateInfo).map(AttributeModification::getValue).orElse(null);
Float droop = Optional.ofNullable(droopInfo).map(AttributeModification::getValue).orElse(null);
checkActivePowerControl(participate, droop, exceptionType, errorMessage);
if (participate != null && droop != null) {
adder.withParticipate(participate)
.withDroop(droop)
.add();
if (reports != null) {
reports.add(buildModificationReport(null, participate, "Participate"));
reports.add(buildModificationReport(Double.NaN, droop, "Droop"));
}
}
double droop = droopInfo != null ? droopInfo.getValue() : Double.NaN;
adder.withDroop(droop);
if (droopInfo != null && reports != null) {
reports.add(buildModificationReport(Double.NaN, droop, "Droop"));
}

public void checkActivePowerControl(Boolean participate, Float droop, NetworkModificationException.Type exceptionType, String errorMessage) {
if (Boolean.TRUE.equals(participate) && droop == null) {
throw new NetworkModificationException(exceptionType, String.format("%s Active power regulation on : missing required droop value", errorMessage));
}
adder.add();
}

public ReportNode modifyActivePowerControlAttributes(ActivePowerControl<?> activePowerControl,
ActivePowerControlAdder<?> activePowerControlAdder,
AttributeModification<Boolean> participateInfo,
AttributeModification<Float> droopInfo,
ReportNode subReportNode,
ReportNode subReporterSetpoints) {
ReportNode subReporterSetpoints,
NetworkModificationException.Type exceptionType,
String errorMessage) {
List<ReportNode> reports = new ArrayList<>();
if (activePowerControl != null) {
modifyExistingActivePowerControl(activePowerControl, participateInfo, droopInfo, reports);
} else {
createNewActivePowerControl(activePowerControlAdder, participateInfo, droopInfo, reports);
createNewActivePowerControl(activePowerControlAdder, participateInfo, droopInfo, reports, exceptionType, errorMessage);
}
if (subReportNode != null) {
ReportNode subReportNodeSetpoints2 = subReporterSetpoints;
if (subReporterSetpoints == null && !reports.isEmpty()) {
subReportNodeSetpoints2 = subReportNode.newReportNode().withMessageTemplate(SETPOINTS, SETPOINTS).add();
}
reportModifications(subReportNodeSetpoints2, reports, "activePowerRegulationModified", "Active power regulation");
reportModifications(subReportNodeSetpoints2, reports, "activePowerControlModified", "Active power control");
return subReportNodeSetpoints2;
}
return null;
Expand Down

0 comments on commit 6f7a9da

Please sign in to comment.