Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add by formula modification #359

Merged
merged 30 commits into from
Nov 13, 2023
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
changes
Seddik Yengui committed Oct 25, 2023
commit d06b5db98393877f15cbff2b07834790c4d324ed
Original file line number Diff line number Diff line change
@@ -45,7 +45,8 @@ public enum ModificationType {
GENERATION_DISPATCH(PreloadingStrategy.COLLECTION),
VOLTAGE_INIT_MODIFICATION(PreloadingStrategy.COLLECTION),
VSC_CREATION(PreloadingStrategy.NONE),
CONVERTER_STATION_CREATION(PreloadingStrategy.NONE);
CONVERTER_STATION_CREATION(PreloadingStrategy.NONE),
BY_FORMULA_MODIFICATION(PreloadingStrategy.COLLECTION);

private final PreloadingStrategy strategy;

Original file line number Diff line number Diff line change
@@ -102,7 +102,8 @@ public enum Type {
CREATE_VSC_ERROR(HttpStatus.INTERNAL_SERVER_ERROR),
HVDC_LINE_ALREADY_EXISTS(HttpStatus.BAD_REQUEST),
VSC_CONVERTER_STATION_NOT_FOUND(HttpStatus.NOT_FOUND),
CREATE_CONVERTER_STATION_ERROR(HttpStatus.INTERNAL_SERVER_ERROR);
CREATE_CONVERTER_STATION_ERROR(HttpStatus.INTERNAL_SERVER_ERROR),
BY_FORMULA_MODIFICATION_ERROR(HttpStatus.INTERNAL_SERVER_ERROR);

public final HttpStatus status;
private final String message;
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
package org.gridsuite.modification.server.dto;

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.powsybl.iidm.network.IdentifiableType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.gridsuite.modification.server.dto.annotation.ModificationErrorTypeName;
import org.gridsuite.modification.server.dto.formula.FormulaInfos;
import org.gridsuite.modification.server.entities.equipment.modification.ByFormulaModificationEntity;
import org.gridsuite.modification.server.modifications.ByFormulaModification;

import java.util.List;

@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@JsonTypeName("BY_FORMULA_MODIFICATION")
@ModificationErrorTypeName("BY_FORMULA_MODIFICATION_ERROR")
public class ByFormulaModificationInfos extends ModificationInfos {
@Schema(description = "Identifiable type")
private IdentifiableType identifiableType;
@@ -26,4 +32,9 @@ public class ByFormulaModificationInfos extends ModificationInfos {
public ByFormulaModificationEntity toEntity() {
return new ByFormulaModificationEntity(this);
}

@Override
public ByFormulaModification toModification() {
return new ByFormulaModification(this);
}
}
Original file line number Diff line number Diff line change
@@ -3,18 +3,43 @@
import com.powsybl.iidm.network.Battery;
import com.powsybl.iidm.network.Generator;
import com.powsybl.iidm.network.IdentifiableType;
import com.powsybl.iidm.network.MinMaxReactiveLimits;
import com.powsybl.iidm.network.extensions.ActivePowerControl;
import com.powsybl.iidm.network.extensions.ActivePowerControlAdder;
import org.gridsuite.modification.server.NetworkModificationException;

public enum BatteryField implements EquipmentField {
ACTIVE_POWER;
MINIMUM_ACTIVE_POWER,
MAXIMUM_ACTIVE_POWER,
ACTIVE_POWER_SET_POINT,
REACTIVE_POWER_SET_POINT,
DROOP;

@Override
public IdentifiableType getIdentifiableType() {
return IdentifiableType.BATTERY;
}

public static Double getReferenceValue(Battery battery, BatteryField batteryField) {
ActivePowerControl<Battery> activePowerControl = battery.getExtension(ActivePowerControl.class);
return switch (batteryField) {
case ACTIVE_POWER -> battery.getMaxP();
case MINIMUM_ACTIVE_POWER -> battery.getMinP();
case MAXIMUM_ACTIVE_POWER -> battery.getMaxP();
case ACTIVE_POWER_SET_POINT -> battery.getTargetP();
case REACTIVE_POWER_SET_POINT -> battery.getTargetQ();
case DROOP -> activePowerControl != null ? activePowerControl.getDroop() : null;
};
}

public static void setNewValue(Battery battery, BatteryField batteryField, Double newValue) {
switch (batteryField) {
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();
}
}
}
Original file line number Diff line number Diff line change
@@ -20,12 +20,10 @@ public enum GeneratorField implements EquipmentField {
ACTIVE_POWER_SET_POINT,
REACTIVE_POWER_SET_POINT,
VOLTAGE_SET_POINT,
PLANNING_ACTIVE_POWER_SET_POINT,
PLANNED_ACTIVE_POWER_SET_POINT,
MARGINAL_COST,
PLANNING_OUTAGE_RATE,
PLANNED_OUTAGE_RATE,
FORCED_OUTAGE_RATE,
MINIMUM_REACTIVE_POWER,
MAXIMUM_REACTIVE_POWER,
DROOP,
TRANSIENT_REACTANCE,
STEP_UP_TRANSFORMER_REACTANCE,
@@ -37,7 +35,6 @@ public IdentifiableType getIdentifiableType() {
}

public static Double getReferenceValue(Generator generator, GeneratorField generatorField) {
MinMaxReactiveLimits minMaxReactiveLimits = generator.getReactiveLimits(MinMaxReactiveLimits.class);
ActivePowerControl<Generator> activePowerControl = generator.getExtension(ActivePowerControl.class);
GeneratorStartup generatorStartup = generator.getExtension(GeneratorStartup.class);
GeneratorShortCircuit generatorShortCircuit = generator.getExtension(GeneratorShortCircuit.class);
@@ -49,12 +46,10 @@ public static Double getReferenceValue(Generator generator, GeneratorField gener
case RATED_NOMINAL_POWER -> generator.getRatedS();
case REACTIVE_POWER_SET_POINT -> generator.getTargetQ();
case VOLTAGE_SET_POINT -> generator.getTargetV();
case PLANNING_ACTIVE_POWER_SET_POINT -> generatorStartup != null ? generatorStartup.getPlannedActivePowerSetpoint() : null;
case PLANNED_ACTIVE_POWER_SET_POINT -> generatorStartup != null ? generatorStartup.getPlannedActivePowerSetpoint() : null;
case MARGINAL_COST -> generatorStartup != null ? generatorStartup.getMarginalCost() : null;
case PLANNING_OUTAGE_RATE -> generatorStartup != null ? generatorStartup.getPlannedOutageRate() : null;
case PLANNED_OUTAGE_RATE -> generatorStartup != null ? generatorStartup.getPlannedOutageRate() : null;
case FORCED_OUTAGE_RATE -> generatorStartup != null ? generatorStartup.getForcedOutageRate() : null;
case MINIMUM_REACTIVE_POWER -> minMaxReactiveLimits != null ? minMaxReactiveLimits.getMinQ() : null;
case MAXIMUM_REACTIVE_POWER -> minMaxReactiveLimits != null ? minMaxReactiveLimits.getMaxQ() : null;
case DROOP -> activePowerControl != null ? activePowerControl.getDroop() : null;
case TRANSIENT_REACTANCE -> generatorShortCircuit != null ? generatorShortCircuit.getDirectTransX() : null;
case STEP_UP_TRANSFORMER_REACTANCE -> generatorShortCircuit != null ? generatorShortCircuit.getStepUpTransformerX() : null;
@@ -66,22 +61,25 @@ public static void setNewValue(Generator generator, GeneratorField generatorFiel
GeneratorStartup generatorStartup = generator.getExtension(GeneratorStartup.class);
GeneratorShortCircuit generatorShortCircuit = generator.getExtension(GeneratorShortCircuit.class);
MinMaxReactiveLimits minMaxReactiveLimits = generator.getReactiveLimits(MinMaxReactiveLimits.class);
ActivePowerControl<Generator> activePowerControl = generator.getExtension(ActivePowerControl.class);
CoordinatedReactiveControl coordinatedReactiveControl = generator.getExtension(CoordinatedReactiveControl.class);
switch (generatorField) {
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 PLANNING_ACTIVE_POWER_SET_POINT -> {
case PLANNED_ACTIVE_POWER_SET_POINT -> {
if (generatorStartup == null) {
generator.newExtension(GeneratorStartupAdder.class)
.withPlannedActivePowerSetpoint(newValue)
.add();
} else {
generatorStartup.setPlannedActivePowerSetpoint(newValue);
generator.newExtension(GeneratorStartupAdder.class)
.withMarginalCost(generatorStartup.getMarginalCost())
.withPlannedActivePowerSetpoint(newValue)
.withPlannedOutageRate(generatorStartup.getPlannedOutageRate())
.withForcedOutageRate(generatorStartup.getForcedOutageRate())
.add();
}
}
case MARGINAL_COST -> {
@@ -90,16 +88,26 @@ public static void setNewValue(Generator generator, GeneratorField generatorFiel
.withMarginalCost(newValue)
.add();
} else {
generatorStartup.setMarginalCost(newValue);
generator.newExtension(GeneratorStartupAdder.class)
.withMarginalCost(newValue)
.withPlannedActivePowerSetpoint(generatorStartup.getPlannedActivePowerSetpoint())
.withPlannedOutageRate(generatorStartup.getPlannedOutageRate())
.withForcedOutageRate(generatorStartup.getForcedOutageRate())
.add();
}
}
case PLANNING_OUTAGE_RATE -> {
case PLANNED_OUTAGE_RATE -> {
if (generatorStartup == null) {
generator.newExtension(GeneratorStartupAdder.class)
.withPlannedOutageRate(newValue)
.add();
} else {
generatorStartup.setPlannedOutageRate(newValue);
generator.newExtension(GeneratorStartupAdder.class)
.withMarginalCost(generatorStartup.getMarginalCost())
.withPlannedActivePowerSetpoint(generatorStartup.getPlannedActivePowerSetpoint())
.withPlannedOutageRate(newValue)
.withForcedOutageRate(generatorStartup.getForcedOutageRate())
.add();
}
}
case FORCED_OUTAGE_RATE -> {
@@ -108,36 +116,17 @@ public static void setNewValue(Generator generator, GeneratorField generatorFiel
.withForcedOutageRate(newValue)
.add();
} else {
generatorStartup.setForcedOutageRate(newValue);
}
}
case MINIMUM_REACTIVE_POWER -> {
if (minMaxReactiveLimits ==null) {
throw new NetworkModificationException(NetworkModificationException.Type.MODIFY_GENERATOR_ERROR, "TODO");
}
generator.newMinMaxReactiveLimits()
.setMinQ(newValue)
.setMaxQ(minMaxReactiveLimits.getMaxQ())
.add();
}
case MAXIMUM_REACTIVE_POWER -> {
if (minMaxReactiveLimits ==null) {
throw new NetworkModificationException(NetworkModificationException.Type.MODIFY_GENERATOR_ERROR, "TODO");
}
generator.newMinMaxReactiveLimits()
.setMaxQ(newValue)
.setMinQ(minMaxReactiveLimits.getMinQ())
.add();
}
case DROOP -> {
if (activePowerControl == null) {
generator.newExtension(ActivePowerControlAdder.class)
.withDroop(newValue)
generator.newExtension(GeneratorStartupAdder.class)
.withMarginalCost(generatorStartup.getMarginalCost())
.withPlannedActivePowerSetpoint(generatorStartup.getPlannedActivePowerSetpoint())
.withPlannedOutageRate(generatorStartup.getForcedOutageRate())
.withForcedOutageRate(newValue)
.add();
} else {
activePowerControl.setDroop(newValue);
}
}
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())
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@ public class FormulaEntity {
private Operator operator;

public FormulaEntity(FormulaInfos formulaInfos) {
this.id = UUID.randomUUID();
this.filters = formulaInfos.getFilters().stream().map(FilterInfos::toEntity).collect(Collectors.toList());
this.equipmentField1 = formulaInfos.getFieldOrValue1().getEquipmentField().toString();
this.equipmentField2 = formulaInfos.getFieldOrValue2().getEquipmentField().toString();
Original file line number Diff line number Diff line change
@@ -2,15 +2,18 @@

import com.powsybl.commons.reporter.Reporter;
import com.powsybl.commons.reporter.TypedValue;
import com.powsybl.iidm.network.Battery;
import com.powsybl.iidm.network.Generator;
import com.powsybl.iidm.network.Identifiable;
import com.powsybl.iidm.network.Network;
import com.powsybl.network.store.iidm.impl.NetworkImpl;
import org.gridsuite.modification.server.NetworkModificationException;
import org.gridsuite.modification.server.dto.ByFormulaModificationInfos;
import org.gridsuite.modification.server.dto.FilterEquipments;
import org.gridsuite.modification.server.dto.FilterInfos;
import org.gridsuite.modification.server.dto.formula.FormulaInfos;
import org.gridsuite.modification.server.dto.formula.Operator;
import org.gridsuite.modification.server.dto.formula.equipmentfield.BatteryField;
import org.gridsuite.modification.server.dto.formula.equipmentfield.GeneratorField;
import org.gridsuite.modification.server.service.FilterService;
import org.springframework.util.CollectionUtils;
@@ -88,11 +91,15 @@ private void applyFormula(Network network, String identifiableId, FormulaInfos f
Double value1 = formulaInfos.getFieldOrValue1().getRefOrValue(identifiable);
Double value2 = formulaInfos.getFieldOrValue2().getRefOrValue(identifiable);
switch (identifiable.getType()) {
case GENERATOR -> {
GeneratorField.setNewValue((Generator) identifiable,
(GeneratorField) formulaInfos.getEquipmentField(),
case GENERATOR -> GeneratorField.setNewValue((Generator) identifiable,
(GeneratorField) formulaInfos.getEquipmentField(),
applyOperation(formulaInfos.getOperator(), value1, value2));
case BATTERY -> {
BatteryField.setNewValue((Battery) identifiable,
(BatteryField) formulaInfos.getEquipmentField(),
applyOperation(formulaInfos.getOperator(), value1, value2));
}
default -> throw new NetworkModificationException(NetworkModificationException.Type.WRONG_EQUIPMENT_TYPE, "Unsupported equipment");
}
}

Loading