Skip to content

Commit

Permalink
corections post review
Browse files Browse the repository at this point in the history
Signed-off-by: Mathieu DEHARBE <[email protected]>
  • Loading branch information
Mathieu-Deharbe committed Sep 17, 2024
1 parent 90b6b5c commit e758123
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
import com.powsybl.iidm.network.Battery;
import com.powsybl.iidm.network.extensions.ActivePowerControl;
import com.powsybl.iidm.network.extensions.ActivePowerControlAdder;
import jakarta.validation.constraints.NotNull;
import org.gridsuite.modification.server.dto.AttributeModification;
import org.gridsuite.modification.server.dto.OperationType;
import org.gridsuite.modification.server.modifications.ModificationUtils;

import static org.gridsuite.modification.server.NetworkModificationException.Type.MODIFY_GENERATOR_ERROR;
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;

Expand All @@ -41,23 +42,23 @@ public static Double getReferenceValue(Battery battery, String batteryField) {
};
}

public static void setNewValue(Battery battery, String batteryField, Double newValue) {
public static void setNewValue(Battery battery, String batteryField, @NotNull Double newValue) {
BatteryField field = BatteryField.valueOf(batteryField);
final AttributeModification<Double> modif = new AttributeModification<>(newValue, OperationType.SET);
final AttributeModification<Double> attributeModification = new AttributeModification<>(newValue, OperationType.SET);
switch (field) {
case MINIMUM_ACTIVE_POWER ->
modifyBatteryActiveLimitsAttributes(null, modif, battery, null);
modifyBatteryActiveLimitsAttributes(null, attributeModification, battery, null);
case MAXIMUM_ACTIVE_POWER ->
modifyBatteryActiveLimitsAttributes(modif, null, battery, null);
modifyBatteryActiveLimitsAttributes(attributeModification, null, battery, null);
case ACTIVE_POWER_SET_POINT -> {
ModificationUtils.getInstance().checkActivePowerZeroOrBetweenMinAndMaxActivePower(
modif, null, null, battery.getMinP(),
battery.getMaxP(), battery.getTargetP(), MODIFY_GENERATOR_ERROR, "Battery '" + battery.getId() + "' : "
attributeModification, null, null, battery.getMinP(),
battery.getMaxP(), battery.getTargetP(), MODIFY_BATTERY_ERROR, "Battery '" + battery.getId() + "' : "
);
modifyBatterySetpointsAttributes(modif, null, null, null, battery, null);
modifyBatterySetpointsAttributes(attributeModification, null, null, null, battery, null);
}
case REACTIVE_POWER_SET_POINT -> modifyBatterySetpointsAttributes(
null, modif, null, null, battery, null);
null, attributeModification, null, null, battery, null);
case DROOP -> {
ActivePowerControl<Battery> activePowerControl = battery.getExtension(ActivePowerControl.class);
ActivePowerControlAdder<Battery> activePowerControlAdder = battery.newExtension(ActivePowerControlAdder.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.powsybl.iidm.network.extensions.GeneratorShortCircuit;
import com.powsybl.iidm.network.extensions.GeneratorStartup;
import com.powsybl.network.store.iidm.impl.extensions.CoordinatedReactiveControlAdderImpl;
import jakarta.validation.constraints.NotNull;
import org.gridsuite.modification.server.dto.AttributeModification;
import org.gridsuite.modification.server.dto.OperationType;
import org.gridsuite.modification.server.modifications.ModificationUtils;
Expand Down Expand Up @@ -65,41 +66,41 @@ public static Double getReferenceValue(Generator generator, String generatorFiel
};
}

public static void setNewValue(Generator generator, String generatorField, Double newValue) {
public static void setNewValue(Generator generator, String generatorField, @NotNull Double newValue) {
if (!Double.isNaN(newValue)) {
GeneratorField field = GeneratorField.valueOf(generatorField);
final AttributeModification<Double> attrModif = new AttributeModification<>(newValue, OperationType.SET);
final AttributeModification<Double> attributeModification = new AttributeModification<>(newValue, OperationType.SET);
switch (field) {
case MAXIMUM_ACTIVE_POWER -> modifyGeneratorActiveLimitsAttributes(
attrModif, null, null, generator, null);
case MINIMUM_ACTIVE_POWER -> modifyGeneratorActiveLimitsAttributes(null, attrModif, null, generator, null);
attributeModification, null, null, generator, null);
case MINIMUM_ACTIVE_POWER -> modifyGeneratorActiveLimitsAttributes(null, attributeModification, null, generator, null);
case ACTIVE_POWER_SET_POINT -> {
ModificationUtils.getInstance().checkActivePowerZeroOrBetweenMinAndMaxActivePower(
attrModif, null, null,
attributeModification, null, null,
generator.getMinP(), generator.getMaxP(), generator.getTargetP(),
MODIFY_GENERATOR_ERROR, "Generator '" + generator.getId() + "' : "
);
generator.setTargetP(newValue);
}
case RATED_NOMINAL_POWER -> modifyGeneratorActiveLimitsAttributes(null, null, attrModif, generator, null);
case REACTIVE_POWER_SET_POINT -> modifyTargetQ(generator, attrModif);
case VOLTAGE_SET_POINT -> modifyTargetV(generator, attrModif);
case RATED_NOMINAL_POWER -> modifyGeneratorActiveLimitsAttributes(null, null, attributeModification, generator, null);
case REACTIVE_POWER_SET_POINT -> modifyTargetQ(generator, attributeModification);
case VOLTAGE_SET_POINT -> modifyTargetV(generator, attributeModification);
case PLANNED_ACTIVE_POWER_SET_POINT ->
modifyGeneratorStartUpAttributes(attrModif, null, null, null, generator, null, null);
modifyGeneratorStartUpAttributes(attributeModification, null, null, null, generator, null, null);
case MARGINAL_COST ->
modifyGeneratorStartUpAttributes(null, attrModif, null, null, generator, null, null);
modifyGeneratorStartUpAttributes(null, attributeModification, null, null, generator, null, null);
case PLANNED_OUTAGE_RATE ->
modifyGeneratorStartUpAttributes(null, null, attrModif, null, generator, null, null);
modifyGeneratorStartUpAttributes(null, null, attributeModification, null, generator, null, null);
case FORCED_OUTAGE_RATE ->
modifyGeneratorStartUpAttributes(null, null, null, attrModif, generator, null, null);
modifyGeneratorStartUpAttributes(null, null, null, attributeModification, generator, null, null);
case DROOP -> {
ActivePowerControl<Generator> activePowerControl = generator.getExtension(ActivePowerControl.class);
ActivePowerControlAdder<Generator> activePowerControlAdder = generator.newExtension(ActivePowerControlAdder.class);
ModificationUtils.getInstance().modifyActivePowerControlAttributes(activePowerControl, activePowerControlAdder, null,
new AttributeModification<>(newValue.floatValue(), OperationType.SET), null, null);
}
case TRANSIENT_REACTANCE -> modifyGeneratorShortCircuitAttributes(attrModif, null, generator, null);
case STEP_UP_TRANSFORMER_REACTANCE -> modifyGeneratorShortCircuitAttributes(null, attrModif, generator, null);
case TRANSIENT_REACTANCE -> modifyGeneratorShortCircuitAttributes(attributeModification, null, generator, null);
case STEP_UP_TRANSFORMER_REACTANCE -> modifyGeneratorShortCircuitAttributes(null, attributeModification, generator, null);
case Q_PERCENT -> generator.newExtension(CoordinatedReactiveControlAdderImpl.class)
.withQPercent(newValue)
.add();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ public static void setNewValue(ShuntCompensator shuntCompensator, String shuntCo
ShuntCompensatorLinearModel model = shuntCompensator.getModel(ShuntCompensatorLinearModel.class);
ShuntCompensatorField field = ShuntCompensatorField.valueOf(shuntCompensatorField);
VoltageLevel voltageLevel = shuntCompensator.getTerminal().getVoltageLevel();
var shuntCompensatorType = model.getBPerSection() > 0 ? ShuntCompensatorType.CAPACITOR : ShuntCompensatorType.REACTOR;
var shuntCompensatorType = ShuntCompensatorType.REACTOR;
if (model != null && model.getBPerSection() > 0) {
shuntCompensatorType = ShuntCompensatorType.CAPACITOR;
}
switch (field) {
case MAXIMUM_SECTION_COUNT -> modifyMaximumSectionCount(new AttributeModification<>(newValue.intValue(), OperationType.SET),
null, null, null, shuntCompensator, model);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,31 @@ public static void setNewValue(TwoWindingsTransformer transformer, String twoWin
TwoWindingsTransformerField field = TwoWindingsTransformerField.valueOf(twoWindingsTransformerField);
final PhaseTapChanger phaseTapChanger = transformer.getPhaseTapChanger();
final RatioTapChanger ratioTapChanger = transformer.getRatioTapChanger();
final AttributeModification<Double> attrModif = new AttributeModification<>(newValue, OperationType.SET);
final AttributeModification<Double> attributeModification = new AttributeModification<>(newValue, OperationType.SET);

switch (field) {
case R -> modifyBranchFields(transformer, attrModif, null, null);
case X -> modifyBranchFields(transformer, null, attrModif, null);
case G -> modifyG(transformer, attrModif, null);
case B -> modifyB(transformer, attrModif, null);
case RATED_U1 -> modifyRatedU1(transformer, attrModif, null);
case RATED_U2 -> modifyRatedU2(transformer, attrModif, null);
case RATED_S -> modifyRatedS(transformer, attrModif, null);
case TARGET_V -> modifyTargets(ratioTapChanger, null, true, attrModif, null, null);
case R -> modifyR(transformer, attributeModification, null);
case X -> modifyX(transformer, attributeModification, null);
case G -> modifyG(transformer, attributeModification, null);
case B -> modifyB(transformer, attributeModification, null);
case RATED_U1 -> modifyRatedU1(transformer, attributeModification, null);
case RATED_U2 -> modifyRatedU2(transformer, attributeModification, null);
case RATED_S -> modifyRatedS(transformer, attributeModification, null);
case TARGET_V -> modifyTargets(ratioTapChanger, null, true, attributeModification, null, null);
case RATIO_LOW_TAP_POSITION -> processTapChangerPositionsAndSteps(ratioTapChanger, null, true,
new AttributeModification<>(newValue.intValue(), OperationType.SET), null, null, null);
case RATIO_TAP_POSITION -> processTapChangerPositionsAndSteps(ratioTapChanger, null, true,
null, new AttributeModification<>(newValue.intValue(), OperationType.SET), null, null);
case RATIO_TARGET_DEADBAND -> modifyTargets(ratioTapChanger, null, true, null, attrModif, null);
case RATIO_TARGET_DEADBAND -> modifyTargets(ratioTapChanger, null, true, null, attributeModification, null);
case REGULATION_VALUE -> processPhaseTapRegulation(
phaseTapChanger, null, null, true, attrModif, null, null
phaseTapChanger, null, null, true, attributeModification, null, null
);
case PHASE_LOW_TAP_POSITION -> processTapChangerPositionsAndSteps(phaseTapChanger, null, true,
new AttributeModification<>(newValue.intValue(), OperationType.SET), null, null, null);
case PHASE_TAP_POSITION -> processTapChangerPositionsAndSteps(phaseTapChanger, null, true,
null, new AttributeModification<>(newValue.intValue(), OperationType.SET), null, null);
case PHASE_TARGET_DEADBAND -> processPhaseTapRegulation(
phaseTapChanger, null, null, true, null, attrModif, null
phaseTapChanger, null, null, true, null, attributeModification, null
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1039,20 +1039,19 @@ public ReportNode modifyActivePowerControlAttributes(ActivePowerControl<?> activ
} else {
createNewActivePowerControl(activePowerControlAdder, participateInfo, droopInfo, reports);
}
if (subReportNode == null) {
return null;
}

ReportNode subReportNodeSetpoints2 = subReporterSetpoints;
if (subReporterSetpoints == null && !reports.isEmpty()) {
subReportNodeSetpoints2 = subReportNode.newReportNode().withMessageTemplate(SETPOINTS, SETPOINTS).add();
subReportNodeSetpoints2.newReportNode()
.withMessageTemplate(SETPOINTS, SETPOINTS)
.withSeverity(TypedValue.INFO_SEVERITY)
.add();
if (subReportNode != null) {
ReportNode subReportNodeSetpoints2 = subReporterSetpoints;
if (subReporterSetpoints == null && !reports.isEmpty()) {
subReportNodeSetpoints2 = subReportNode.newReportNode().withMessageTemplate(SETPOINTS, SETPOINTS).add();
subReportNodeSetpoints2.newReportNode()
.withMessageTemplate(SETPOINTS, SETPOINTS)
.withSeverity(TypedValue.INFO_SEVERITY)
.add();
}
reportModifications(subReportNodeSetpoints2, reports, "activePowerRegulationModified", "Active power regulation", Map.of());
return subReportNodeSetpoints2;
}
reportModifications(subReportNodeSetpoints2, reports, "activePowerRegulationModified", "Active power regulation", Map.of());
return subReportNodeSetpoints2;
return null;
}

public void checkMaxQGreaterThanMinQ(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class TwoWindingsTransformerModification extends AbstractBranchModificati

private static final String RATIO_TAP_CHANGER_SUBREPORTER_DEFAULT_MESSAGE = "Ratio tap changer";
private static final String PHASE_TAP_CHANGER_SUBREPORTER_DEFAULT_MESSAGE = "Phase tap changer";
public static final String MAGNETIZING_CONDUCTANCE_FIELD_NAME = "Magnetizing conductance";

public TwoWindingsTransformerModification(TwoWindingsTransformerModificationInfos modificationInfos) {
super(modificationInfos);
Expand Down Expand Up @@ -62,7 +63,9 @@ protected void modifyCharacteristics(Branch<?> branch, BranchModificationInfos b
.withSeverity(TypedValue.INFO_SEVERITY)
.add();

modifyBranchFields(twoWindingsTransformer, branchModificationInfos.getR(), branchModificationInfos.getX(), characteristicsReporter);
// Branch specific fields
modifyR(twoWindingsTransformer, branchModificationInfos.getR(), characteristicsReporter);
modifyX(twoWindingsTransformer, branchModificationInfos.getX(), characteristicsReporter);

// Transformer specific fields
TwoWindingsTransformerModificationInfos twoWindingsTransformerModificationInfos = (TwoWindingsTransformerModificationInfos) branchModificationInfos;
Expand Down Expand Up @@ -138,21 +141,18 @@ public static void modifyG(TwoWindingsTransformer transformer, AttributeModifica
if (reportNode != null) {
double oldMagnetizingConductanceToReport = transformer.getG() * Math.pow(10, 6);
double newMagnetizingConductanceToReport = modifG.getValue() * Math.pow(10, 6);
insertReportNode(reportNode, ModificationUtils.getInstance().buildModificationReportWithIndentation(oldMagnetizingConductanceToReport,
newMagnetizingConductanceToReport, "Magnetizing conductance", 1));
ReportNode gReportNode = ModificationUtils.getInstance().buildModificationReportWithIndentation(
oldMagnetizingConductanceToReport,
newMagnetizingConductanceToReport,
MAGNETIZING_CONDUCTANCE_FIELD_NAME,
1);
insertReportNode(reportNode, gReportNode);
}
transformer.setG(modifG.getValue());
}
}

public static void modifyBranchFields(TwoWindingsTransformer twt, AttributeModification<Double> modifR, AttributeModification<Double> modifX, ReportNode reportNode) {
if (modifR != null && modifR.getValue() != null) {
if (reportNode != null) {
insertReportNode(reportNode, ModificationUtils.getInstance().buildModificationReportWithIndentation(twt.getR(),
modifR.getValue(), "Series resistance", 1));
}
twt.setR(modifR.getValue());
}
public static void modifyX(TwoWindingsTransformer twt, AttributeModification<Double> modifX, ReportNode reportNode) {
if (modifX != null && modifX.getValue() != null) {
if (reportNode != null) {
insertReportNode(reportNode, ModificationUtils.getInstance().buildModificationReportWithIndentation(twt.getX(),
Expand All @@ -162,6 +162,16 @@ public static void modifyBranchFields(TwoWindingsTransformer twt, AttributeModif
}
}

public static void modifyR(TwoWindingsTransformer twt, AttributeModification<Double> modifR, ReportNode reportNode) {
if (modifR != null && modifR.getValue() != null) {
if (reportNode != null) {
insertReportNode(reportNode, ModificationUtils.getInstance().buildModificationReportWithIndentation(twt.getR(),
modifR.getValue(), "Series resistance", 1));
}
twt.setR(modifR.getValue());
}
}

private void addTapChangersToTwoWindingsTransformer(Network network, TwoWindingsTransformerModificationInfos twoWindingsTransformerModificationInfos, TwoWindingsTransformer twt, ReportNode subReportNode) {
if (twt.hasRatioTapChanger() && twoWindingsTransformerModificationInfos.getRatioTapChanger().getEnabled() != null && Boolean.FALSE.equals(twoWindingsTransformerModificationInfos.getRatioTapChanger().getEnabled().getValue())) {
twt.getRatioTapChanger().remove();
Expand Down
Loading

0 comments on commit e758123

Please sign in to comment.