Skip to content

Commit

Permalink
Merge branch 'main' into ayolab/remove-hack-and-update-report-management
Browse files Browse the repository at this point in the history
  • Loading branch information
ayolab authored Sep 26, 2024
2 parents c42153e + bc45748 commit 0455b7d
Show file tree
Hide file tree
Showing 24 changed files with 1,192 additions and 567 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.gridsuite.modification.server.dto;
import com.powsybl.iidm.network.extensions.ConnectablePosition;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -35,9 +36,39 @@ public class BranchModificationInfos extends BasicEquipmentModificationInfos {
@Schema(description = "Current limits Side 2")
private CurrentLimitsModificationInfos currentLimits2;

@Schema(description = "Voltage level id modification 1")
private AttributeModification<String> voltageLevelId1;

@Schema(description = "Voltage level id modification 2")
private AttributeModification<String> voltageLevelId2;

@Schema(description = "Bus id modification 1")
private AttributeModification<String> busOrBusbarSectionId1;

@Schema(description = "Bus id modification 2")
private AttributeModification<String> busOrBusbarSectionId2;

@Schema(description = "Connection Name 1")
private AttributeModification<String> connectionName1;

@Schema(description = "Connection Name 2")
private AttributeModification<String> connectionName2;

@Schema(description = "Connection Direction 1")
private AttributeModification<ConnectablePosition.Direction> connectionDirection1;

@Schema(description = "Connection Direction 2")
private AttributeModification<ConnectablePosition.Direction> connectionDirection2;

@Schema(description = "Connection Position 1")
private AttributeModification<Integer> connectionPosition1;

@Schema(description = "Connection Position 2")
private AttributeModification<Integer> connectionPosition2;

@Schema(description = "Connected 1")
private AttributeModification<Boolean> connected1;
private AttributeModification<Boolean> terminal1Connected;

@Schema(description = "Connected 2")
private AttributeModification<Boolean> connected2;
private AttributeModification<Boolean> terminal2Connected;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
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_BATTERY_ERROR;
import static org.gridsuite.modification.server.modifications.BatteryModification.modifyBatteryActiveLimitsAttributes;
import static org.gridsuite.modification.server.modifications.BatteryModification.modifyBatterySetpointsAttributes;

/**
* @author Seddik Yengui <Seddik.yengui at rte-france.com>
Expand All @@ -34,16 +42,30 @@ 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> attributeModification = new AttributeModification<>(newValue, OperationType.SET);
switch (field) {
case MINIMUM_ACTIVE_POWER -> battery.setMinP(newValue);
case MAXIMUM_ACTIVE_POWER -> battery.setMaxP(newValue);
case ACTIVE_POWER_SET_POINT -> battery.setTargetP(newValue);
case REACTIVE_POWER_SET_POINT -> battery.setTargetQ(newValue);
case DROOP -> battery.newExtension(ActivePowerControlAdder.class)
.withDroop(newValue)
.add();
case MINIMUM_ACTIVE_POWER ->
modifyBatteryActiveLimitsAttributes(null, attributeModification, battery, null);
case MAXIMUM_ACTIVE_POWER ->
modifyBatteryActiveLimitsAttributes(attributeModification, null, battery, null);
case ACTIVE_POWER_SET_POINT -> {
ModificationUtils.getInstance().checkActivePowerZeroOrBetweenMinAndMaxActivePower(
attributeModification, null, null, battery.getMinP(),
battery.getMaxP(), battery.getTargetP(), MODIFY_BATTERY_ERROR, "Battery '" + battery.getId() + "' : "
);
modifyBatterySetpointsAttributes(attributeModification, null, null, null, battery, null);
}
case REACTIVE_POWER_SET_POINT -> modifyBatterySetpointsAttributes(
null, attributeModification, null, null, battery, null);
case DROOP -> {
ActivePowerControl<Battery> activePowerControl = battery.getExtension(ActivePowerControl.class);
ActivePowerControlAdder<Battery> activePowerControlAdder = battery.newExtension(ActivePowerControlAdder.class);
ModificationUtils.getInstance().modifyActivePowerControlAttributes(
activePowerControl, activePowerControlAdder, null,
new AttributeModification<>(newValue.floatValue(), OperationType.SET), null, null);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@
import com.powsybl.iidm.network.extensions.ActivePowerControl;
import com.powsybl.iidm.network.extensions.ActivePowerControlAdder;
import com.powsybl.iidm.network.extensions.CoordinatedReactiveControl;
import com.powsybl.iidm.network.extensions.CoordinatedReactiveControlAdder;
import com.powsybl.iidm.network.extensions.GeneratorShortCircuit;
import com.powsybl.iidm.network.extensions.GeneratorShortCircuitAdder;
import com.powsybl.iidm.network.extensions.GeneratorStartup;
import com.powsybl.iidm.network.extensions.GeneratorStartupAdder;
import com.powsybl.network.store.iidm.impl.extensions.CoordinatedReactiveControlAdderImpl;
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.modifications.GeneratorModification.*;

/**
* @author Seddik Yengui <Seddik.yengui at rte-france.com>
Expand Down Expand Up @@ -61,86 +65,42 @@ 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, double newValue) {
if (!Double.isNaN(newValue)) {
GeneratorStartup generatorStartup = generator.getExtension(GeneratorStartup.class);
GeneratorShortCircuit generatorShortCircuit = generator.getExtension(GeneratorShortCircuit.class);
GeneratorField field = GeneratorField.valueOf(generatorField);
final AttributeModification<Double> attributeModification = new AttributeModification<>(newValue, OperationType.SET);
switch (field) {
case MAXIMUM_ACTIVE_POWER -> generator.setMaxP(newValue);
case MINIMUM_ACTIVE_POWER -> generator.setMinP(newValue);
case ACTIVE_POWER_SET_POINT -> generator.setTargetP(newValue);
case RATED_NOMINAL_POWER -> generator.setRatedS(newValue);
case REACTIVE_POWER_SET_POINT -> generator.setTargetQ(newValue);
case VOLTAGE_SET_POINT -> generator.setTargetV(newValue);
case PLANNED_ACTIVE_POWER_SET_POINT -> {
if (generatorStartup == null) {
generator.newExtension(GeneratorStartupAdder.class)
.withPlannedActivePowerSetpoint(newValue)
.add();
} else {
generator.newExtension(GeneratorStartupAdder.class)
.withMarginalCost(generatorStartup.getMarginalCost())
.withPlannedActivePowerSetpoint(newValue)
.withPlannedOutageRate(generatorStartup.getPlannedOutageRate())
.withForcedOutageRate(generatorStartup.getForcedOutageRate())
.add();
}
}
case MARGINAL_COST -> {
if (generatorStartup == null) {
generator.newExtension(GeneratorStartupAdder.class)
.withMarginalCost(newValue)
.add();
} else {
generator.newExtension(GeneratorStartupAdder.class)
.withMarginalCost(newValue)
.withPlannedActivePowerSetpoint(generatorStartup.getPlannedActivePowerSetpoint())
.withPlannedOutageRate(generatorStartup.getPlannedOutageRate())
.withForcedOutageRate(generatorStartup.getForcedOutageRate())
.add();
}
}
case PLANNED_OUTAGE_RATE -> {
if (generatorStartup == null) {
generator.newExtension(GeneratorStartupAdder.class)
.withPlannedOutageRate(newValue)
.add();
} else {
generator.newExtension(GeneratorStartupAdder.class)
.withMarginalCost(generatorStartup.getMarginalCost())
.withPlannedActivePowerSetpoint(generatorStartup.getPlannedActivePowerSetpoint())
.withPlannedOutageRate(newValue)
.withForcedOutageRate(generatorStartup.getForcedOutageRate())
.add();
}
case MAXIMUM_ACTIVE_POWER -> modifyGeneratorActiveLimitsAttributes(
attributeModification, null, null, generator, null);
case MINIMUM_ACTIVE_POWER -> modifyGeneratorActiveLimitsAttributes(null, attributeModification, null, generator, null);
case ACTIVE_POWER_SET_POINT -> {
ModificationUtils.getInstance().checkActivePowerZeroOrBetweenMinAndMaxActivePower(
attributeModification, null, null,
generator.getMinP(), generator.getMaxP(), generator.getTargetP(),
MODIFY_GENERATOR_ERROR, "Generator '" + generator.getId() + "' : "
);
generator.setTargetP(newValue);
}
case FORCED_OUTAGE_RATE -> {
if (generatorStartup == null) {
generator.newExtension(GeneratorStartupAdder.class)
.withForcedOutageRate(newValue)
.add();
} else {
generator.newExtension(GeneratorStartupAdder.class)
.withMarginalCost(generatorStartup.getMarginalCost())
.withPlannedActivePowerSetpoint(generatorStartup.getPlannedActivePowerSetpoint())
.withPlannedOutageRate(generatorStartup.getForcedOutageRate())
.withForcedOutageRate(newValue)
.add();
}
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(attributeModification, null, null, null, generator, null, null);
case MARGINAL_COST ->
modifyGeneratorStartUpAttributes(null, attributeModification, null, null, generator, null, null);
case PLANNED_OUTAGE_RATE ->
modifyGeneratorStartUpAttributes(null, null, attributeModification, null, generator, null, null);
case FORCED_OUTAGE_RATE ->
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<>((float) newValue, OperationType.SET), null, null);
}
case DROOP -> generator.newExtension(ActivePowerControlAdder.class)
.withDroop(newValue)
.add();
case TRANSIENT_REACTANCE -> generator.newExtension(GeneratorShortCircuitAdder.class)
.withDirectTransX(newValue)
.withStepUpTransformerX(generatorShortCircuit == null ? Double.NaN : generatorShortCircuit.getStepUpTransformerX())
.add();
case STEP_UP_TRANSFORMER_REACTANCE -> generator.newExtension(GeneratorShortCircuitAdder.class)
.withDirectTransX(generatorShortCircuit == null ? 0.0D : generatorShortCircuit.getDirectTransX())
.withStepUpTransformerX(newValue)
.add();
case Q_PERCENT -> generator.newExtension(CoordinatedReactiveControlAdder.class)
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 @@ -8,6 +8,11 @@
package org.gridsuite.modification.server.dto.formula.equipmentfield;

import com.powsybl.iidm.network.Load;
import org.gridsuite.modification.server.dto.AttributeModification;
import org.gridsuite.modification.server.dto.OperationType;

import static org.gridsuite.modification.server.modifications.LoadModification.modifyP0;
import static org.gridsuite.modification.server.modifications.LoadModification.modifyQ0;

/**
* @author Seddik Yengui <Seddik.yengui at rte-france.com>
Expand All @@ -28,8 +33,8 @@ public static Double getReferenceValue(Load load, String loadField) {
public static void setNewValue(Load load, String loadField, Double newValue) {
LoadField field = LoadField.valueOf(loadField);
switch (field) {
case ACTIVE_POWER -> load.setP0(newValue);
case REACTIVE_POWER -> load.setQ0(newValue);
case ACTIVE_POWER -> modifyP0(load, new AttributeModification<>(newValue, OperationType.SET), null);
case REACTIVE_POWER -> modifyQ0(load, new AttributeModification<>(newValue, OperationType.SET), null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
import com.powsybl.iidm.network.ShuntCompensatorModelType;
import com.powsybl.iidm.network.VoltageLevel;
import org.gridsuite.modification.server.NetworkModificationException;
import org.gridsuite.modification.server.dto.AttributeModification;
import org.gridsuite.modification.server.dto.OperationType;
import org.gridsuite.modification.server.dto.ShuntCompensatorType;

import static org.gridsuite.modification.server.modifications.ShuntCompensatorModification.*;

/**
* @author Seddik Yengui <Seddik.yengui at rte-france.com>
Expand Down Expand Up @@ -42,19 +47,18 @@ 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 = ShuntCompensatorType.REACTOR;
if (model != null && model.getBPerSection() > 0) {
shuntCompensatorType = ShuntCompensatorType.CAPACITOR;
}
switch (field) {
case MAXIMUM_SECTION_COUNT -> {
int maximumSectionCount = newValue.intValue();
model.setBPerSection(model.getBPerSection() * shuntCompensator.getMaximumSectionCount() / maximumSectionCount);
model.setMaximumSectionCount(maximumSectionCount);
}
case SECTION_COUNT -> shuntCompensator.setSectionCount(newValue.intValue());
case MAXIMUM_SUSCEPTANCE -> model.setBPerSection(newValue / shuntCompensator.getMaximumSectionCount());
case MAXIMUM_Q_AT_NOMINAL_VOLTAGE -> {
double newQatNominalV = newValue / shuntCompensator.getMaximumSectionCount();
double newSusceptancePerSection = newQatNominalV / Math.pow(voltageLevel.getNominalV(), 2);
model.setBPerSection(newSusceptancePerSection);
}
case MAXIMUM_SECTION_COUNT -> modifyMaximumSectionCount(new AttributeModification<>(newValue.intValue(), OperationType.SET),
null, null, null, shuntCompensator, model);
case SECTION_COUNT -> modifySectionCount(new AttributeModification<>(newValue.intValue(), OperationType.SET), null, shuntCompensator);
case MAXIMUM_SUSCEPTANCE -> modifyMaxSusceptance(new AttributeModification<>(newValue, OperationType.SET),
shuntCompensator.getMaximumSectionCount(), null, model);
case MAXIMUM_Q_AT_NOMINAL_VOLTAGE -> modifyMaximumQAtNominalVoltage(new AttributeModification<>(newValue, OperationType.SET),
voltageLevel, shuntCompensator.getMaximumSectionCount(), null, model, shuntCompensatorType);
}
}
}
Loading

0 comments on commit 0455b7d

Please sign in to comment.