Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.powsybl.iidm.network.Generator;
import com.powsybl.iidm.network.extensions.*;
import com.powsybl.network.store.iidm.impl.extensions.CoordinatedReactiveControlAdderImpl;
import jakarta.validation.constraints.NotNull;
import org.gridsuite.modification.dto.AttributeModification;
import org.gridsuite.modification.dto.OperationType;
import org.gridsuite.modification.utils.ModificationUtils;
Expand Down Expand Up @@ -64,7 +63,7 @@ public static String getReferenceValue(Generator generator, String generatorFiel
};
}

public static void setNewValue(Generator generator, String generatorField, @NotNull String newValue) {
public static void setNewValue(Generator generator, String generatorField, String newValue) {
GeneratorField field = GeneratorField.valueOf(generatorField);
String errorMessage = String.format(ERROR_MESSAGE, generator.getId());
switch (field) {
Expand All @@ -82,7 +81,7 @@ public static void setNewValue(Generator generator, String generatorField, @NotN
generator.setTargetP(Double.parseDouble(newValue));
}
case RATED_NOMINAL_POWER -> {
Double ratedNominalPower = Double.parseDouble(newValue);
Double ratedNominalPower = newValue != null ? Double.parseDouble(newValue) : Double.NaN;
checkIsNotNegativeValue(errorMessage, ratedNominalPower, MODIFY_GENERATOR_ERROR, "Rated apparent power");
modifyGeneratorActiveLimitsAttributes(
null, null, new AttributeModification<>(ratedNominalPower, OperationType.SET), generator, null);
Expand Down Expand Up @@ -114,10 +113,14 @@ public static void setNewValue(Generator generator, String generatorField, @NotN
MODIFY_GENERATOR_ERROR, errorMessage);
}
case TRANSIENT_REACTANCE -> modifyGeneratorShortCircuitAttributes(
new AttributeModification<>(Double.parseDouble(newValue), OperationType.SET),
new AttributeModification<>(newValue != null ? Double.parseDouble(newValue) : Double.NaN, OperationType.SET),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you should use Unset instead ? And change AttributeModification behavior for double to return NaN

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds like a good idea but it quickly gets complicated and dangerous for one week before the MVP si I prefer not to.
image

null, generator, null);
case STEP_UP_TRANSFORMER_REACTANCE -> modifyGeneratorShortCircuitAttributes(
null, new AttributeModification<>(Double.parseDouble(newValue), OperationType.SET), generator, null);
null,
new AttributeModification<>(newValue != null ? Double.parseDouble(newValue) : Double.NaN, OperationType.SET),
generator,
null
);
case Q_PERCENT -> generator.newExtension(CoordinatedReactiveControlAdderImpl.class)
.withQPercent(Double.parseDouble(newValue))
.add();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static void setNewValue(Line line, String lineField, @NotNull String newV
}

private static void setNewDoubleValue(Line line, LineField field, String newValue, String errorMessage) {
Double doubleValue = Double.parseDouble(newValue);
Double doubleValue = newValue != null ? Double.parseDouble(newValue) : Double.NaN;
final AttributeModification<Double> attributeModification = new AttributeModification<>(doubleValue, OperationType.SET);
switch (field) {
case R -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static void setNewValue(TwoWindingsTransformer transformer, String twoWin
private static void setNewDoubleValue(TwoWindingsTransformer transformer, TwoWindingsTransformerField field, String newValue, String errorMessage) {
final PhaseTapChanger phaseTapChanger = transformer.getPhaseTapChanger();
final RatioTapChanger ratioTapChanger = transformer.getRatioTapChanger();
final Double doubleValue = Double.valueOf(newValue);
final Double doubleValue = newValue != null ? Double.parseDouble(newValue) : Double.NaN;
final AttributeModification<Double> attributeModification = new AttributeModification<>(doubleValue, OperationType.SET);
switch (field) {
case R -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import com.powsybl.iidm.network.VoltageLevel;
import com.powsybl.iidm.network.extensions.IdentifiableShortCircuit;
import jakarta.validation.constraints.NotNull;
import org.gridsuite.modification.dto.AttributeModification;
import org.gridsuite.modification.dto.OperationType;

Expand Down Expand Up @@ -40,7 +39,7 @@ public static String getReferenceValue(VoltageLevel voltageLevel, String voltage
};
}

public static void setNewValue(VoltageLevel voltageLevel, String voltageLevelField, @NotNull String newValue) {
public static void setNewValue(VoltageLevel voltageLevel, String voltageLevelField, String newValue) {
VoltageLevelField field = VoltageLevelField.valueOf(voltageLevelField);
final String errorMessage = String.format(ERROR_MESSAGE, voltageLevel.getId());
switch (field) {
Expand All @@ -50,19 +49,21 @@ public static void setNewValue(VoltageLevel voltageLevel, String voltageLevelFie
modifyNominalV(voltageLevel, new AttributeModification<>(nominalVoltage, OperationType.SET), null);
}
case LOW_VOLTAGE_LIMIT -> {
Double lowVoltageLimit = Double.valueOf(newValue);
Double lowVoltageLimit = newValue != null ? Double.parseDouble(newValue) : Double.NaN;
checkIsNotNegativeValue(errorMessage, lowVoltageLimit, MODIFY_VOLTAGE_LEVEL_ERROR, "Low voltage limit");
modifLowVoltageLimit(voltageLevel, new AttributeModification<>(lowVoltageLimit, OperationType.SET), null);
}
case HIGH_VOLTAGE_LIMIT -> {
Double highVoltageLimit = Double.valueOf(newValue);
Double highVoltageLimit = newValue != null ? Double.parseDouble(newValue) : Double.NaN;
checkIsNotNegativeValue(errorMessage, highVoltageLimit, MODIFY_VOLTAGE_LEVEL_ERROR, "High voltage limit");
modifyHighVoltageLimit(voltageLevel, new AttributeModification<>(Double.parseDouble(newValue), OperationType.SET), null);
modifyHighVoltageLimit(voltageLevel, new AttributeModification<>(highVoltageLimit, OperationType.SET), null);
}
case LOW_SHORT_CIRCUIT_CURRENT_LIMIT -> modifyVoltageLevelShortCircuit(
new AttributeModification<>(Double.parseDouble(newValue), OperationType.SET), null, null, voltageLevel);
new AttributeModification<>(newValue != null ? Double.parseDouble(newValue) : Double.NaN, OperationType.SET),
null, null, voltageLevel);
case HIGH_SHORT_CIRCUIT_CURRENT_LIMIT -> modifyVoltageLevelShortCircuit(
null, new AttributeModification<>(Double.parseDouble(newValue), OperationType.SET), null, voltageLevel);
null, new AttributeModification<>(newValue != null ? Double.parseDouble(newValue) : Double.NaN, OperationType.SET),
null, voltageLevel);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,63 +102,78 @@ private void modifyOperationalLimitsGroups(Branch<?> branch, List<OperationalLim

private void applySelectedOLGs(Branch<?> branch, List<ReportNode> side1LimitsReports, List<ReportNode> side2LimitsReports) {
if (modificationInfos.getSelectedOperationalLimitsGroup1() != null) {
applySelectedOLGOnSide1(branch, side1LimitsReports);
modifySelectedOperationalLimitsGroup(
branch,
modificationInfos.getSelectedOperationalLimitsGroup1(),
TwoSides.ONE,
side1LimitsReports
);
}
if (modificationInfos.getSelectedOperationalLimitsGroup2() != null) {
applySelectedOLGOnSide2(branch, side2LimitsReports);
modifySelectedOperationalLimitsGroup(
branch,
modificationInfos.getSelectedOperationalLimitsGroup2(),
TwoSides.TWO,
side2LimitsReports);
}
}

private void applySelectedOLGOnSide1(Branch<?> branch, List<ReportNode> reportNode) {
if (Objects.requireNonNull(modificationInfos.getSelectedOperationalLimitsGroup1().getOp()) == OperationType.UNSET) {
private static void applySelectedOLGOnSide1(Branch<?> branch, AttributeModification<String> modifOperationalLimitsGroup, List<ReportNode> reportNode, String newSelectedOLG) {
if (!StringUtils.hasText(newSelectedOLG) || modifOperationalLimitsGroup.getOp() == OperationType.UNSET) {
branch.cancelSelectedOperationalLimitsGroup1();
reportNode.add(ReportNode.newRootReportNode()
.withMessageTemplate("network.modification.noLimitSetSelectedOnSide1")
.withSeverity(TypedValue.INFO_SEVERITY)
.build());
} else if (modificationInfos.getSelectedOperationalLimitsGroup1().getOp() == OperationType.SET) {
String newSelectedOpLG1 = modificationInfos.getSelectedOperationalLimitsGroup1().getValue();
if (StringUtils.hasText(newSelectedOpLG1) && branch.getOperationalLimitsGroup1(newSelectedOpLG1).isEmpty()) {
if (reportNode != null) {
reportNode.add(ReportNode.newRootReportNode()
.withMessageTemplate("network.modification.noLimitSetSelectedOnSide1")
.withSeverity(TypedValue.INFO_SEVERITY)
.build());
}
} else {
if (StringUtils.hasText(newSelectedOLG) && branch.getOperationalLimitsGroup1(newSelectedOLG).isEmpty() && reportNode != null) {
reportNode.add(ReportNode.newRootReportNode()
.withMessageTemplate("network.modification.limitSetAbsentOnSide1")
.withUntypedValue("selectedOperationalLimitsGroup", newSelectedOpLG1)
.withUntypedValue("selectedOperationalLimitsGroup", newSelectedOLG)
.withSeverity(TypedValue.WARN_SEVERITY)
.build());

} else {
branch.setSelectedOperationalLimitsGroup1(newSelectedOpLG1);
reportNode.add(ReportNode.newRootReportNode()
.withMessageTemplate("network.modification.limitSetSelectedOnSide1")
.withUntypedValue("selectedOperationalLimitsGroup1", newSelectedOpLG1)
.withSeverity(TypedValue.INFO_SEVERITY)
.build());
branch.setSelectedOperationalLimitsGroup1(newSelectedOLG);
if (reportNode != null) {
reportNode.add(ReportNode.newRootReportNode()
.withMessageTemplate("network.modification.limitSetSelectedOnSide1")
.withUntypedValue("selectedOperationalLimitsGroup1", newSelectedOLG)
.withSeverity(TypedValue.INFO_SEVERITY)
.build());
}
}
}
}

private void applySelectedOLGOnSide2(Branch<?> branch, List<ReportNode> reportNode) {
if (Objects.requireNonNull(modificationInfos.getSelectedOperationalLimitsGroup2().getOp()) == OperationType.UNSET) {
branch.setSelectedOperationalLimitsGroup2("");
reportNode.add(ReportNode.newRootReportNode()
.withMessageTemplate("network.modification.noLimitSetSelectedOnSide2")
.withSeverity(TypedValue.INFO_SEVERITY)
.build());
} else if (modificationInfos.getSelectedOperationalLimitsGroup2().getOp() == OperationType.SET) {
String newSelectedOpLG = modificationInfos.getSelectedOperationalLimitsGroup2().getValue();
if (StringUtils.hasText(newSelectedOpLG) && branch.getOperationalLimitsGroup2(newSelectedOpLG).isEmpty()) {
private static void applySelectedOLGOnSide2(Branch<?> branch, AttributeModification<String> modifOperationalLimitsGroup, List<ReportNode> reportNode, String newSelectedOLG) {
if (!StringUtils.hasText(newSelectedOLG) || modifOperationalLimitsGroup.getOp() == OperationType.UNSET) {
branch.cancelSelectedOperationalLimitsGroup2();
if (reportNode != null) {
reportNode.add(ReportNode.newRootReportNode()
.withMessageTemplate("network.modification.noLimitSetSelectedOnSide2")
.withSeverity(TypedValue.INFO_SEVERITY)
.build());
}
} else {
if (StringUtils.hasText(newSelectedOLG) && branch.getOperationalLimitsGroup2(newSelectedOLG).isEmpty() && reportNode != null) {
reportNode.add(ReportNode.newRootReportNode()
.withMessageTemplate("network.modification.limitSetAbsentOnSide2")
.withUntypedValue("selectedOperationalLimitsGroup2", newSelectedOpLG)
.withUntypedValue("selectedOperationalLimitsGroup", newSelectedOLG)
.withSeverity(TypedValue.WARN_SEVERITY)
.build());

} else {
branch.setSelectedOperationalLimitsGroup2(newSelectedOpLG);
reportNode.add(ReportNode.newRootReportNode()
.withMessageTemplate("network.modification.limitSetSelectedOnSide2")
.withUntypedValue("selectedOperationalLimitsGroup2", newSelectedOpLG)
.withSeverity(TypedValue.INFO_SEVERITY)
.build());
branch.setSelectedOperationalLimitsGroup2(newSelectedOLG);
if (reportNode != null) {
reportNode.add(ReportNode.newRootReportNode()
.withMessageTemplate("network.modification.limitSetSelectedOnSide2")
.withUntypedValue("selectedOperationalLimitsGroup2", newSelectedOLG)
.withSeverity(TypedValue.INFO_SEVERITY)
.build());
}
}
}
}
Expand Down Expand Up @@ -540,30 +555,18 @@ private void modifyBranchVoltageLevelBusOrBusBarSectionAttributesSide2(BranchMod
);
}

public static void modifySelectedOperationalLimitsGroup(Branch<?> branch, AttributeModification<String> modifOperationalLimitsGroup,
TwoSides side, ReportNode reportNode) {
public static void modifySelectedOperationalLimitsGroup(
Branch<?> branch,
AttributeModification<String> modifOperationalLimitsGroup,
TwoSides side,
List<ReportNode> reportNode) {
Objects.requireNonNull(side);
if (modifOperationalLimitsGroup != null) {
String value = modifOperationalLimitsGroup.getValue();
String previousSelectedLimitsGroup = null;
String newSelectedOLG = modifOperationalLimitsGroup.getValue();
if (side == TwoSides.ONE) {
previousSelectedLimitsGroup = branch.getSelectedOperationalLimitsGroupId1().orElse(null);
if (!StringUtils.hasText(value)) {
branch.cancelSelectedOperationalLimitsGroup1();
} else {
branch.setSelectedOperationalLimitsGroup1(value);
}
applySelectedOLGOnSide1(branch, modifOperationalLimitsGroup, reportNode, newSelectedOLG);
} else if (side == TwoSides.TWO) {
previousSelectedLimitsGroup = branch.getSelectedOperationalLimitsGroupId2().orElse(null);
if (!StringUtils.hasText(value)) {
branch.cancelSelectedOperationalLimitsGroup2();
} else {
branch.setSelectedOperationalLimitsGroup2(value);
}
}
if (reportNode != null) {
insertReportNode(reportNode, ModificationUtils.getInstance().buildModificationReport(previousSelectedLimitsGroup,
modifOperationalLimitsGroup.getValue(), "selected operational limits group side " + side.getNum()));
applySelectedOLGOnSide2(branch, modifOperationalLimitsGroup, reportNode, newSelectedOLG);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,22 +125,23 @@ public static void modifyGeneratorShortCircuitAttributes(AttributeModification<D
ReportNode subReportNode) {
List<ReportNode> reports = new ArrayList<>();
GeneratorShortCircuit generatorShortCircuit = generator.getExtension(GeneratorShortCircuit.class);
Double oldTransientReactance = generatorShortCircuit != null ? generatorShortCircuit.getDirectTransX() : Double.NaN;
Double oldStepUpTransformerReactance = generatorShortCircuit != null ? generatorShortCircuit.getStepUpTransformerX() : Double.NaN;
double oldTransientReactance = generatorShortCircuit != null ? generatorShortCircuit.getDirectTransX() : Double.NaN;
double oldStepUpTransformerReactance = generatorShortCircuit != null ? generatorShortCircuit.getStepUpTransformerX() : Double.NaN;
// Either transient reactance or step-up transformer reactance are modified or
// both
String stepUpTransformerXNewValue = stepUpTransformerX != null ? stepUpTransformerX.getValue().toString() : null;
if (directTransX != null && stepUpTransformerX != null) {
generator.newExtension(GeneratorShortCircuitAdder.class)
.withDirectTransX(directTransX.getValue())
.withStepUpTransformerX(stepUpTransformerX.getValue())
.add();
.withDirectTransX(directTransX.getValue())
.withStepUpTransformerX(stepUpTransformerX.getValue())
.add();
reports.add(ModificationUtils.getInstance().buildModificationReport(
oldTransientReactance,
directTransX.getValue(),
"Transient reactance"));
reports.add(ModificationUtils.getInstance().buildModificationReport(
oldStepUpTransformerReactance,
stepUpTransformerX.getValue(),
stepUpTransformerXNewValue,
"Transformer reactance"));

} else if (directTransX != null) {
Expand All @@ -153,13 +154,20 @@ public static void modifyGeneratorShortCircuitAttributes(AttributeModification<D
directTransX.getValue(),
"Transient reactance"));
} else if (stepUpTransformerX != null) {
generator.newExtension(GeneratorShortCircuitAdder.class)
.withStepUpTransformerX(stepUpTransformerX.getValue())
.withDirectTransX(oldTransientReactance)
.add();
if (Double.isNaN(stepUpTransformerX.getValue())) {
generator.newExtension(GeneratorShortCircuitAdder.class)
.withDirectTransX(oldTransientReactance)
.add();
stepUpTransformerXNewValue = NO_VALUE;
} else {
generator.newExtension(GeneratorShortCircuitAdder.class)
.withStepUpTransformerX(stepUpTransformerX.getValue())
.withDirectTransX(oldTransientReactance)
.add();
}
reports.add(ModificationUtils.getInstance().buildModificationReport(
oldStepUpTransformerReactance,
stepUpTransformerX.getValue(),
stepUpTransformerXNewValue,
"Transformer reactance"));
}
if (subReportNode != null) {
Expand Down
Loading