Skip to content

Commit

Permalink
Add twt to by formula modification (#383)
Browse files Browse the repository at this point in the history
Signed-off-by:Seddik Yengui <[email protected]>
  • Loading branch information
YenguiSeddik authored Dec 7, 2023
1 parent 66af5a0 commit 49306d5
Show file tree
Hide file tree
Showing 6 changed files with 849 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.powsybl.iidm.network.IdentifiableType;
import com.powsybl.iidm.network.Load;
import com.powsybl.iidm.network.ShuntCompensator;
import com.powsybl.iidm.network.TwoWindingsTransformer;
import com.powsybl.iidm.network.VoltageLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -24,6 +25,7 @@
import org.gridsuite.modification.server.dto.formula.equipmentfield.GeneratorField;
import org.gridsuite.modification.server.dto.formula.equipmentfield.LoadField;
import org.gridsuite.modification.server.dto.formula.equipmentfield.ShuntCompensatorField;
import org.gridsuite.modification.server.dto.formula.equipmentfield.TwoWindingsTransformerField;
import org.gridsuite.modification.server.dto.formula.equipmentfield.VoltageLevelField;


Expand Down Expand Up @@ -52,21 +54,15 @@ public Double getRefOrValue(Identifiable<?> identifiable) {
}

IdentifiableType identifiableType = identifiable.getType();
Double referenceValue = switch (identifiableType) {
return switch (identifiableType) {
case GENERATOR -> GeneratorField.getReferenceValue((Generator) identifiable, equipmentField);
case BATTERY -> BatteryField.getReferenceValue((Battery) identifiable, equipmentField);
case SHUNT_COMPENSATOR -> ShuntCompensatorField.getReferenceValue((ShuntCompensator) identifiable, equipmentField);
case VOLTAGE_LEVEL -> VoltageLevelField.getReferenceValue((VoltageLevel) identifiable, equipmentField);
case LOAD -> LoadField.getReferenceValue((Load) identifiable, equipmentField);
case TWO_WINDINGS_TRANSFORMER -> TwoWindingsTransformerField.getReferenceValue((TwoWindingsTransformer) identifiable, equipmentField);
default -> throw new NetworkModificationException(NetworkModificationException.Type.BY_FORMULA_MODIFICATION_ERROR,
String.format("Unsupported equipment type : %s", identifiableType.name()));
};

if (referenceValue == null) {
throw new NetworkModificationException(NetworkModificationException.Type.BY_FORMULA_MODIFICATION_ERROR,
String.format("value of %s is null", equipmentField));
}

return referenceValue;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.gridsuite.modification.server.dto.formula.equipmentfield;

import com.powsybl.iidm.network.PhaseTapChanger;
import com.powsybl.iidm.network.RatioTapChanger;
import com.powsybl.iidm.network.TwoWindingsTransformer;

public enum TwoWindingsTransformerField {
SERIES_RESISTANCE,
SERIES_REACTANCE,
MAGNETIZING_CONDUCTANCE,
MAGNETIZING_SUSCEPTANCE,
RATED_VOLTAGE_1,
RATED_VOLTAGE_2,
RATED_S,
TARGET_V,
RATIO_LOW_TAP_POSITION,
RATIO_TAP_POSITION,
RATIO_TARGET_DEADBAND,
REGULATION_VALUE,
PHASE_LOW_TAP_POSITION,
PHASE_TAP_POSITION,
PHASE_TARGET_DEADBAND;

public static Double getReferenceValue(TwoWindingsTransformer transformer, String twoWindingsTransformerField) {
TwoWindingsTransformerField field = TwoWindingsTransformerField.valueOf(twoWindingsTransformerField);
final PhaseTapChanger phaseTapChanger = transformer.getPhaseTapChanger();
final RatioTapChanger ratioTapChanger = transformer.getRatioTapChanger();
return switch (field) {
case SERIES_RESISTANCE -> transformer.getR();
case SERIES_REACTANCE -> transformer.getX();
case MAGNETIZING_CONDUCTANCE -> transformer.getG();
case MAGNETIZING_SUSCEPTANCE -> transformer.getB();
case RATED_VOLTAGE_1 -> transformer.getRatedU1();
case RATED_VOLTAGE_2 -> transformer.getRatedU2();
case RATED_S -> transformer.getRatedS();
case TARGET_V -> ratioTapChanger != null ? ratioTapChanger.getTargetV() : null;
case RATIO_LOW_TAP_POSITION -> ratioTapChanger != null ? (double) ratioTapChanger.getLowTapPosition() : null;
case RATIO_TAP_POSITION -> ratioTapChanger != null ? (double) ratioTapChanger.getTapPosition() : null;
case RATIO_TARGET_DEADBAND -> ratioTapChanger != null ? ratioTapChanger.getTargetDeadband() : null;
case REGULATION_VALUE -> phaseTapChanger != null ? phaseTapChanger.getRegulationValue() : null;
case PHASE_LOW_TAP_POSITION -> phaseTapChanger != null ? (double) phaseTapChanger.getLowTapPosition() : null;
case PHASE_TAP_POSITION -> phaseTapChanger != null ? (double) phaseTapChanger.getTapPosition() : null;
case PHASE_TARGET_DEADBAND -> phaseTapChanger != null ? phaseTapChanger.getTargetDeadband() : null;
};
}

public static void setNewValue(TwoWindingsTransformer transformer, String twoWindingsTransformerField, Double newValue) {
TwoWindingsTransformerField field = TwoWindingsTransformerField.valueOf(twoWindingsTransformerField);
final PhaseTapChanger phaseTapChanger = transformer.getPhaseTapChanger();
final RatioTapChanger ratioTapChanger = transformer.getRatioTapChanger();

switch (field) {
case SERIES_RESISTANCE -> transformer.setR(newValue);
case SERIES_REACTANCE -> transformer.setX(newValue);
case MAGNETIZING_CONDUCTANCE -> transformer.setG(newValue);
case MAGNETIZING_SUSCEPTANCE -> transformer.setB(newValue);
case RATED_VOLTAGE_1 -> transformer.setRatedU1(newValue);
case RATED_VOLTAGE_2 -> transformer.setRatedU2(newValue);
case RATED_S -> transformer.setRatedS(newValue);
case TARGET_V -> ratioTapChanger.setTargetV(newValue);
case RATIO_LOW_TAP_POSITION -> ratioTapChanger.setLowTapPosition(newValue.intValue());
case RATIO_TAP_POSITION -> ratioTapChanger.setTapPosition(newValue.intValue());
case RATIO_TARGET_DEADBAND -> ratioTapChanger.setTargetDeadband(newValue);
case REGULATION_VALUE -> phaseTapChanger.setRegulationValue(newValue);
case PHASE_LOW_TAP_POSITION -> phaseTapChanger.setLowTapPosition(newValue.intValue());
case PHASE_TAP_POSITION -> phaseTapChanger.setTapPosition(newValue.intValue());
case PHASE_TARGET_DEADBAND -> phaseTapChanger.setTargetDeadband(newValue);
}
}
}
Loading

0 comments on commit 49306d5

Please sign in to comment.