Skip to content

Commit

Permalink
VoltageLevelFields
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 2, 2024
1 parent bccd1cb commit 52a7eeb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Seddik.yengui at rte-france.com>
Expand All @@ -35,26 +38,15 @@ public static Double getReferenceValue(VoltageLevel voltageLevel, String voltage
}

public static void setNewValue(VoltageLevel voltageLevel, String voltageLevelField, Double newValue) {
IdentifiableShortCircuit<VoltageLevel> 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<VoltageLevel> adder = voltageLevel.newExtension(IdentifiableShortCircuitAdder.class).withIpMin(newValue);
if (identifiableShortCircuit != null) {
adder.withIpMax(identifiableShortCircuit.getIpMax());
}
adder.add();
}
case HIGH_SHORT_CIRCUIT_CURRENT_LIMIT -> {
IdentifiableShortCircuitAdder<VoltageLevel> 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Double> ipMin,
AttributeModification<Double> ipMax,
ReportNode subReportNode,
VoltageLevel voltageLevel) {
if (ipMin != null || ipMax != null) {
List<ReportNode> reports = new ArrayList<>();
IdentifiableShortCircuit<VoltageLevel> identifiableShortCircuit = voltageLevel.getExtension(IdentifiableShortCircuit.class);
IdentifiableShortCircuitAdder<VoltageLevel> 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);

Expand All @@ -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.
Expand All @@ -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));
}
}
}
}

0 comments on commit 52a7eeb

Please sign in to comment.