From 52a7eeb18d10e8ad64f964b114f57f4b95d7b8e9 Mon Sep 17 00:00:00 2001 From: Mathieu DEHARBE Date: Mon, 2 Sep 2024 16:47:55 +0200 Subject: [PATCH] VoltageLevelFields Signed-off-by: Mathieu DEHARBE --- .../equipmentfield/VoltageLevelField.java | 24 +++++++------------ .../VoltageLevelModification.java | 22 ++++++++++------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/VoltageLevelField.java b/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/VoltageLevelField.java index a1fc1d644..3338e144f 100644 --- a/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/VoltageLevelField.java +++ b/src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/VoltageLevelField.java @@ -9,7 +9,10 @@ import com.powsybl.iidm.network.VoltageLevel; import com.powsybl.iidm.network.extensions.IdentifiableShortCircuit; -import com.powsybl.iidm.network.extensions.IdentifiableShortCircuitAdder; +import org.gridsuite.modification.server.dto.AttributeModification; +import org.gridsuite.modification.server.dto.OperationType; + +import static org.gridsuite.modification.server.modifications.VoltageLevelModification.modifyVoltageLevelShortCircuit; /** * @author Seddik Yengui @@ -35,26 +38,15 @@ public static Double getReferenceValue(VoltageLevel voltageLevel, String voltage } public static void setNewValue(VoltageLevel voltageLevel, String voltageLevelField, Double newValue) { - IdentifiableShortCircuit identifiableShortCircuit = voltageLevel.getExtension(IdentifiableShortCircuit.class); VoltageLevelField field = VoltageLevelField.valueOf(voltageLevelField); switch (field) { case NOMINAL_VOLTAGE -> voltageLevel.setNominalV(newValue); case LOW_VOLTAGE_LIMIT -> voltageLevel.setLowVoltageLimit(newValue); case HIGH_VOLTAGE_LIMIT -> voltageLevel.setHighVoltageLimit(newValue); - case LOW_SHORT_CIRCUIT_CURRENT_LIMIT -> { - IdentifiableShortCircuitAdder adder = voltageLevel.newExtension(IdentifiableShortCircuitAdder.class).withIpMin(newValue); - if (identifiableShortCircuit != null) { - adder.withIpMax(identifiableShortCircuit.getIpMax()); - } - adder.add(); - } - case HIGH_SHORT_CIRCUIT_CURRENT_LIMIT -> { - IdentifiableShortCircuitAdder adder = voltageLevel.newExtension(IdentifiableShortCircuitAdder.class).withIpMax(newValue); - if (identifiableShortCircuit != null) { - adder.withIpMin(identifiableShortCircuit.getIpMin()); - } - adder.add(); - } + case LOW_SHORT_CIRCUIT_CURRENT_LIMIT -> modifyVoltageLevelShortCircuit( + new AttributeModification<>(newValue, OperationType.SET), null, null, voltageLevel); + case HIGH_SHORT_CIRCUIT_CURRENT_LIMIT -> modifyVoltageLevelShortCircuit( + null, new AttributeModification<>(newValue, OperationType.SET), null, voltageLevel); } } } diff --git a/src/main/java/org/gridsuite/modification/server/modifications/VoltageLevelModification.java b/src/main/java/org/gridsuite/modification/server/modifications/VoltageLevelModification.java index 7bbd83e8b..68a0cd82a 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/VoltageLevelModification.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/VoltageLevelModification.java @@ -13,6 +13,7 @@ import com.powsybl.iidm.network.extensions.IdentifiableShortCircuit; import com.powsybl.iidm.network.extensions.IdentifiableShortCircuitAdder; import org.gridsuite.modification.server.NetworkModificationException; +import org.gridsuite.modification.server.dto.AttributeModification; import org.gridsuite.modification.server.dto.VoltageLevelModificationInfos; import java.util.ArrayList; import java.util.List; @@ -88,20 +89,23 @@ public void apply(Network network, ReportNode subReportNode) { ModificationUtils.getInstance().applyElementaryModifications(voltageLevel::setLowVoltageLimit, voltageLevel::getLowVoltageLimit, modificationInfos.getLowVoltageLimit(), subReportNode, "Low voltage limit"); ModificationUtils.getInstance().applyElementaryModifications(voltageLevel::setHighVoltageLimit, voltageLevel::getHighVoltageLimit, modificationInfos.getHighVoltageLimit(), subReportNode, "High voltage limit"); - modifyVoltageLevelShortCircuit(subReportNode, voltageLevel); + modifyVoltageLevelShortCircuit(modificationInfos.getIpMin(), modificationInfos.getIpMax(), subReportNode, voltageLevel); PropertiesUtils.applyProperties(voltageLevel, subReportNode, modificationInfos.getProperties(), "VlProperties"); } - private void modifyVoltageLevelShortCircuit(ReportNode subReportNode, VoltageLevel voltageLevel) { - if (modificationInfos.getIpMin() != null || modificationInfos.getIpMax() != null) { + public static void modifyVoltageLevelShortCircuit(AttributeModification ipMin, + AttributeModification ipMax, + ReportNode subReportNode, + VoltageLevel voltageLevel) { + if (ipMin != null || ipMax != null) { List reports = new ArrayList<>(); IdentifiableShortCircuit identifiableShortCircuit = voltageLevel.getExtension(IdentifiableShortCircuit.class); IdentifiableShortCircuitAdder identifiableShortCircuitAdder = voltageLevel.newExtension(IdentifiableShortCircuitAdder.class); var oldIpMin = identifiableShortCircuit == null ? null : identifiableShortCircuit.getIpMin(); var oldIpMax = identifiableShortCircuit == null ? null : identifiableShortCircuit.getIpMax(); - if (modificationInfos.getIpMin() != null) { - var newIpMin = modificationInfos.getIpMin().getValue(); + if (ipMin != null) { + var newIpMin = ipMin.getValue(); identifiableShortCircuitAdder.withIpMin(newIpMin); @@ -115,8 +119,8 @@ private void modifyVoltageLevelShortCircuit(ReportNode subReportNode, VoltageLev identifiableShortCircuitAdder.withIpMin(oldIpMin); } - if (modificationInfos.getIpMax() != null) { - var newIpMax = modificationInfos.getIpMax().getValue(); + if (ipMax != null) { + var newIpMax = ipMax.getValue(); identifiableShortCircuitAdder.withIpMax(newIpMax); //Convert to kA to report it like the user set it. @@ -129,7 +133,9 @@ private void modifyVoltageLevelShortCircuit(ReportNode subReportNode, VoltageLev } identifiableShortCircuitAdder.add(); - reports.forEach(report -> insertReportNode(subReportNode, report)); + if (subReportNode != null) { + reports.forEach(report -> insertReportNode(subReportNode, report)); + } } } }