From 5eff596cb0e7ce3dbbedc945b2869e53af7af3b2 Mon Sep 17 00:00:00 2001 From: YenguiSeddik <101111441+YenguiSeddik@users.noreply.github.com> Date: Thu, 21 Sep 2023 09:46:58 +0200 Subject: [PATCH] Refactor reactive limits and Injection connectivity infos (#323) Signed-off-by: Seddik Yengui --- .../server/dto/BatteryCreationInfos.java | 12 +- .../server/dto/GeneratorCreationInfos.java | 16 +-- .../server/dto/InjectionCreationInfos.java | 10 ++ .../server/dto/LoadCreationInfos.java | 10 -- .../server/dto/ReactiveLimitsHolderInfos.java | 24 ++++ .../dto/ShuntCompensatorCreationInfos.java | 10 -- .../creation/BatteryCreationEntity.java | 16 +-- .../creation/GeneratorCreationEntity.java | 16 +-- .../creation/InjectionCreationEntity.java | 13 ++ .../creation/LoadCreationEntity.java | 13 -- .../ShuntCompensatorCreationEntity.java | 16 --- .../server/modifications/BatteryCreation.java | 127 ++--------------- .../modifications/GeneratorCreation.java | 131 ++--------------- .../modifications/ModificationUtils.java | 132 ++++++++++++++++++ 14 files changed, 208 insertions(+), 338 deletions(-) create mode 100644 src/main/java/org/gridsuite/modification/server/dto/ReactiveLimitsHolderInfos.java diff --git a/src/main/java/org/gridsuite/modification/server/dto/BatteryCreationInfos.java b/src/main/java/org/gridsuite/modification/server/dto/BatteryCreationInfos.java index a53185df0..331218d5b 100644 --- a/src/main/java/org/gridsuite/modification/server/dto/BatteryCreationInfos.java +++ b/src/main/java/org/gridsuite/modification/server/dto/BatteryCreationInfos.java @@ -9,7 +9,6 @@ import com.fasterxml.jackson.annotation.JsonTypeName; import com.powsybl.commons.reporter.Reporter; import com.powsybl.commons.reporter.ReporterModel; -import com.powsybl.iidm.network.extensions.ConnectablePosition; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Getter; import lombok.NoArgsConstructor; @@ -36,7 +35,7 @@ @Schema(description = "Battery creation") @JsonTypeName("BATTERY_CREATION") @ModificationErrorTypeName("CREATE_BATTERY_ERROR") -public class BatteryCreationInfos extends InjectionCreationInfos { +public class BatteryCreationInfos extends InjectionCreationInfos implements ReactiveLimitsHolderInfos { @Schema(description = "Minimum active power") private double minActivePower; @@ -68,15 +67,6 @@ public class BatteryCreationInfos extends InjectionCreationInfos { @Schema(description = "Reactive capability curve") private Boolean reactiveCapabilityCurve; - @Schema(description = "Connection Name") - private String connectionName; - - @Schema(description = "Connection Direction") - private ConnectablePosition.Direction connectionDirection; - - @Schema(description = "Connection Position") - private Integer connectionPosition; - @Override public BatteryCreationEntity toEntity() { return new BatteryCreationEntity(this); diff --git a/src/main/java/org/gridsuite/modification/server/dto/GeneratorCreationInfos.java b/src/main/java/org/gridsuite/modification/server/dto/GeneratorCreationInfos.java index 713022e92..dc7d3c365 100644 --- a/src/main/java/org/gridsuite/modification/server/dto/GeneratorCreationInfos.java +++ b/src/main/java/org/gridsuite/modification/server/dto/GeneratorCreationInfos.java @@ -11,7 +11,6 @@ import com.powsybl.commons.reporter.Reporter; import com.powsybl.commons.reporter.ReporterModel; import com.powsybl.iidm.network.EnergySource; -import com.powsybl.iidm.network.extensions.ConnectablePosition; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Getter; import lombok.NoArgsConstructor; @@ -19,13 +18,13 @@ import lombok.ToString; import lombok.experimental.SuperBuilder; -import java.util.List; - import org.gridsuite.modification.server.dto.annotation.ModificationErrorTypeName; import org.gridsuite.modification.server.entities.equipment.creation.GeneratorCreationEntity; import org.gridsuite.modification.server.modifications.AbstractModification; import org.gridsuite.modification.server.modifications.GeneratorCreation; +import java.util.List; + /** * @author Franck Lecuyer */ @@ -38,7 +37,7 @@ @Schema(description = "Generator creation") @JsonTypeName("GENERATOR_CREATION") @ModificationErrorTypeName("CREATE_GENERATOR_ERROR") -public class GeneratorCreationInfos extends InjectionCreationInfos { +public class GeneratorCreationInfos extends InjectionCreationInfos implements ReactiveLimitsHolderInfos { @Schema(description = "Energy source") private EnergySource energySource; @@ -114,15 +113,6 @@ public class GeneratorCreationInfos extends InjectionCreationInfos { @Schema(description = "Reactive capability curve") private Boolean reactiveCapabilityCurve; - @Schema(description = "Connection Name") - private String connectionName; - - @Schema(description = "Connection Direction") - private ConnectablePosition.Direction connectionDirection; - - @Schema(description = "Connection Position") - private Integer connectionPosition; - @Override public GeneratorCreationEntity toEntity() { return new GeneratorCreationEntity(this); diff --git a/src/main/java/org/gridsuite/modification/server/dto/InjectionCreationInfos.java b/src/main/java/org/gridsuite/modification/server/dto/InjectionCreationInfos.java index 731673b54..6a8214bd1 100644 --- a/src/main/java/org/gridsuite/modification/server/dto/InjectionCreationInfos.java +++ b/src/main/java/org/gridsuite/modification/server/dto/InjectionCreationInfos.java @@ -6,6 +6,7 @@ */ 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; @@ -28,4 +29,13 @@ public class InjectionCreationInfos extends EquipmentCreationInfos { @Schema(description = "Bus id") private String busOrBusbarSectionId; + + @Schema(description = "Connection Name") + private String connectionName; + + @Schema(description = "Connection Direction") + private ConnectablePosition.Direction connectionDirection; + + @Schema(description = "Connection Position") + private Integer connectionPosition; } diff --git a/src/main/java/org/gridsuite/modification/server/dto/LoadCreationInfos.java b/src/main/java/org/gridsuite/modification/server/dto/LoadCreationInfos.java index 23091450a..3bfd67c95 100644 --- a/src/main/java/org/gridsuite/modification/server/dto/LoadCreationInfos.java +++ b/src/main/java/org/gridsuite/modification/server/dto/LoadCreationInfos.java @@ -10,7 +10,6 @@ import com.powsybl.commons.reporter.Reporter; import com.powsybl.commons.reporter.ReporterModel; import com.powsybl.iidm.network.LoadType; -import com.powsybl.iidm.network.extensions.ConnectablePosition; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Getter; import lombok.NoArgsConstructor; @@ -44,15 +43,6 @@ public class LoadCreationInfos extends InjectionCreationInfos { @Schema(description = "Reactive power") private double reactivePower; - @Schema(description = "Connection Name") - private String connectionName; - - @Schema(description = "Connection Direction") - private ConnectablePosition.Direction connectionDirection; - - @Schema(description = "Connection Position") - private Integer connectionPosition; - @Override public LoadCreationEntity toEntity() { return new LoadCreationEntity(this); diff --git a/src/main/java/org/gridsuite/modification/server/dto/ReactiveLimitsHolderInfos.java b/src/main/java/org/gridsuite/modification/server/dto/ReactiveLimitsHolderInfos.java new file mode 100644 index 000000000..ad19bace1 --- /dev/null +++ b/src/main/java/org/gridsuite/modification/server/dto/ReactiveLimitsHolderInfos.java @@ -0,0 +1,24 @@ +/** + * Copyright (c) 2022, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +package org.gridsuite.modification.server.dto; + +import java.util.List; + +/** + * @author Seddik Yengui + */ + +public interface ReactiveLimitsHolderInfos { + Boolean getReactiveCapabilityCurve(); + + Double getMinimumReactivePower(); + + Double getMaximumReactivePower(); + + List getReactiveCapabilityCurvePoints(); +} diff --git a/src/main/java/org/gridsuite/modification/server/dto/ShuntCompensatorCreationInfos.java b/src/main/java/org/gridsuite/modification/server/dto/ShuntCompensatorCreationInfos.java index 6f852d995..2ac35c57d 100644 --- a/src/main/java/org/gridsuite/modification/server/dto/ShuntCompensatorCreationInfos.java +++ b/src/main/java/org/gridsuite/modification/server/dto/ShuntCompensatorCreationInfos.java @@ -10,7 +10,6 @@ import com.fasterxml.jackson.annotation.JsonTypeName; import com.powsybl.commons.reporter.Reporter; import com.powsybl.commons.reporter.ReporterModel; -import com.powsybl.iidm.network.extensions.ConnectablePosition; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Getter; import lombok.NoArgsConstructor; @@ -48,15 +47,6 @@ public class ShuntCompensatorCreationInfos extends InjectionCreationInfos { @Schema(description = "Shunt Compensator Type") private ShuntCompensatorType shuntCompensatorType; - @Schema(description = "Connection Name") - private String connectionName; - - @Schema(description = "Connection Direction") - private ConnectablePosition.Direction connectionDirection; - - @Schema(description = "Connection Position") - private Integer connectionPosition; - @Override public ShuntCompensatorCreationEntity toEntity() { return new ShuntCompensatorCreationEntity(this); diff --git a/src/main/java/org/gridsuite/modification/server/entities/equipment/creation/BatteryCreationEntity.java b/src/main/java/org/gridsuite/modification/server/entities/equipment/creation/BatteryCreationEntity.java index 31a62ec97..4c404a321 100644 --- a/src/main/java/org/gridsuite/modification/server/entities/equipment/creation/BatteryCreationEntity.java +++ b/src/main/java/org/gridsuite/modification/server/entities/equipment/creation/BatteryCreationEntity.java @@ -6,7 +6,6 @@ */ package org.gridsuite.modification.server.entities.equipment.creation; -import com.powsybl.iidm.network.extensions.ConnectablePosition; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.NonNull; @@ -28,15 +27,6 @@ @PrimaryKeyJoinColumn(foreignKey = @ForeignKey(name = "batteryCreation_id_fk_constraint")) public class BatteryCreationEntity extends InjectionCreationEntity { - @Column(name = "connectionName") - private String connectionName; - - @Column(name = "connectionDirection") - private ConnectablePosition.Direction connectionDirection; - - @Column(name = "connectionPosition") - private Integer connectionPosition; - @Column(name = "minActivePower") private double minActivePower; @@ -80,9 +70,6 @@ public void update(@NonNull ModificationInfos modificationInfos) { } private void assignAttributes(BatteryCreationInfos batteryCreationInfos) { - this.connectionName = batteryCreationInfos.getConnectionName(); - this.connectionDirection = batteryCreationInfos.getConnectionDirection(); - this.connectionPosition = batteryCreationInfos.getConnectionPosition(); this.minActivePower = batteryCreationInfos.getMinActivePower(); this.maxActivePower = batteryCreationInfos.getMaxActivePower(); this.reactiveCapabilityCurve = batteryCreationInfos.getReactiveCapabilityCurve(); @@ -110,8 +97,7 @@ public BatteryCreationInfos toModificationInfos() { } private BatteryCreationInfos.BatteryCreationInfosBuilder toBatteryCreationInfosBuilder() { - List pointsEmbeddable = getReactiveCapabilityCurvePoints(); - List points = pointsEmbeddable != null ? getReactiveCapabilityCurvePoints() + List points = getReactiveCapabilityCurvePoints() != null ? getReactiveCapabilityCurvePoints() .stream() .map(value -> new ReactiveCapabilityCurveCreationInfos(value.getQminP(), value.getQmaxP(), diff --git a/src/main/java/org/gridsuite/modification/server/entities/equipment/creation/GeneratorCreationEntity.java b/src/main/java/org/gridsuite/modification/server/entities/equipment/creation/GeneratorCreationEntity.java index 569a03c3d..709ef8514 100644 --- a/src/main/java/org/gridsuite/modification/server/entities/equipment/creation/GeneratorCreationEntity.java +++ b/src/main/java/org/gridsuite/modification/server/entities/equipment/creation/GeneratorCreationEntity.java @@ -7,7 +7,6 @@ package org.gridsuite.modification.server.entities.equipment.creation; import com.powsybl.iidm.network.EnergySource; -import com.powsybl.iidm.network.extensions.ConnectablePosition; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.NonNull; @@ -97,15 +96,6 @@ public class GeneratorCreationEntity extends InjectionCreationEntity { @Column(name = "reactiveCapabilityCurve") private Boolean reactiveCapabilityCurve; - @Column(name = "connectionName") - private String connectionName; - - @Column(name = "connectionDirection") - private ConnectablePosition.Direction connectionDirection; - - @Column(name = "connectionPosition") - private Integer connectionPosition; - @ElementCollection @CollectionTable private List reactiveCapabilityCurvePoints; @@ -146,9 +136,6 @@ private void assignAttributes(GeneratorCreationInfos generatorCreationInfos) { this.regulatingTerminalVlId = generatorCreationInfos.getRegulatingTerminalVlId(); this.qPercent = generatorCreationInfos.getQPercent(); this.reactiveCapabilityCurve = generatorCreationInfos.getReactiveCapabilityCurve(); - this.connectionDirection = generatorCreationInfos.getConnectionDirection(); - this.connectionName = generatorCreationInfos.getConnectionName(); - this.connectionPosition = generatorCreationInfos.getConnectionPosition(); } public static List toEmbeddablePoints( @@ -166,8 +153,7 @@ public GeneratorCreationInfos toModificationInfos() { } private GeneratorCreationInfos.GeneratorCreationInfosBuilder toGeneratorCreationInfosBuilder() { - List pointsEmbeddable = getReactiveCapabilityCurvePoints(); - List points = pointsEmbeddable != null ? getReactiveCapabilityCurvePoints() + List points = getReactiveCapabilityCurvePoints() != null ? getReactiveCapabilityCurvePoints() .stream() .map(value -> new ReactiveCapabilityCurveCreationInfos(value.getQminP(), value.getQmaxP(), diff --git a/src/main/java/org/gridsuite/modification/server/entities/equipment/creation/InjectionCreationEntity.java b/src/main/java/org/gridsuite/modification/server/entities/equipment/creation/InjectionCreationEntity.java index b4befe4ab..81c4db1ea 100644 --- a/src/main/java/org/gridsuite/modification/server/entities/equipment/creation/InjectionCreationEntity.java +++ b/src/main/java/org/gridsuite/modification/server/entities/equipment/creation/InjectionCreationEntity.java @@ -6,6 +6,7 @@ */ package org.gridsuite.modification.server.entities.equipment.creation; +import com.powsybl.iidm.network.extensions.ConnectablePosition; import lombok.Getter; import lombok.NoArgsConstructor; import org.gridsuite.modification.server.dto.InjectionCreationInfos; @@ -27,6 +28,15 @@ public class InjectionCreationEntity extends EquipmentCreationEntity { @Column(name = "busOrBusbarSectionId") private String busOrBusbarSectionId; + @Column(name = "connectionName") + private String connectionName; + + @Column(name = "connectionDirection") + private ConnectablePosition.Direction connectionDirection; + + @Column(name = "connectionPosition") + private Integer connectionPosition; + protected InjectionCreationEntity(InjectionCreationInfos injectionCreationInfos) { super(injectionCreationInfos); assignAttributes(injectionCreationInfos); @@ -41,5 +51,8 @@ public void update(ModificationInfos modificationInfos) { private void assignAttributes(InjectionCreationInfos injectionCreationInfos) { this.voltageLevelId = injectionCreationInfos.getVoltageLevelId(); this.busOrBusbarSectionId = injectionCreationInfos.getBusOrBusbarSectionId(); + this.connectionName = injectionCreationInfos.getConnectionName(); + this.connectionPosition = injectionCreationInfos.getConnectionPosition(); + this.connectionDirection = injectionCreationInfos.getConnectionDirection(); } } diff --git a/src/main/java/org/gridsuite/modification/server/entities/equipment/creation/LoadCreationEntity.java b/src/main/java/org/gridsuite/modification/server/entities/equipment/creation/LoadCreationEntity.java index a161e32fc..6203db386 100644 --- a/src/main/java/org/gridsuite/modification/server/entities/equipment/creation/LoadCreationEntity.java +++ b/src/main/java/org/gridsuite/modification/server/entities/equipment/creation/LoadCreationEntity.java @@ -7,7 +7,6 @@ package org.gridsuite.modification.server.entities.equipment.creation; import com.powsybl.iidm.network.LoadType; -import com.powsybl.iidm.network.extensions.ConnectablePosition; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.NonNull; @@ -34,15 +33,6 @@ public class LoadCreationEntity extends InjectionCreationEntity { @Column(name = "reactivePower") private double reactivePower; - @Column(name = "connectionName") - private String connectionName; - - @Column(name = "connectionDirection") - private ConnectablePosition.Direction connectionDirection; - - @Column(name = "connectionPosition") - private Integer connectionPosition; - public LoadCreationEntity(@NonNull LoadCreationInfos loadCreationInfos) { super(loadCreationInfos); assignAttributes(loadCreationInfos); @@ -58,9 +48,6 @@ private void assignAttributes(LoadCreationInfos loadCreationInfos) { loadType = loadCreationInfos.getLoadType(); activePower = loadCreationInfos.getActivePower(); reactivePower = loadCreationInfos.getReactivePower(); - connectionName = loadCreationInfos.getConnectionName(); - connectionDirection = loadCreationInfos.getConnectionDirection(); - connectionPosition = loadCreationInfos.getConnectionPosition(); } @Override diff --git a/src/main/java/org/gridsuite/modification/server/entities/equipment/creation/ShuntCompensatorCreationEntity.java b/src/main/java/org/gridsuite/modification/server/entities/equipment/creation/ShuntCompensatorCreationEntity.java index 1ec46ab34..912a54fe3 100644 --- a/src/main/java/org/gridsuite/modification/server/entities/equipment/creation/ShuntCompensatorCreationEntity.java +++ b/src/main/java/org/gridsuite/modification/server/entities/equipment/creation/ShuntCompensatorCreationEntity.java @@ -7,7 +7,6 @@ package org.gridsuite.modification.server.entities.equipment.creation; -import com.powsybl.iidm.network.extensions.ConnectablePosition; import lombok.Getter; import lombok.NoArgsConstructor; import org.gridsuite.modification.server.dto.ModificationInfos; @@ -37,24 +36,12 @@ public class ShuntCompensatorCreationEntity extends InjectionCreationEntity { @Column private ShuntCompensatorType shuntCompensatorType; - @Column - private String connectionName; - - @Column - private ConnectablePosition.Direction connectionDirection; - - @Column(name = "connectionPosition") - private Integer connectionPosition; - public ShuntCompensatorCreationEntity(ShuntCompensatorCreationInfos creationInfos) { super(creationInfos); maximumNumberOfSections = creationInfos.getMaximumNumberOfSections() != null ? creationInfos.getMaximumNumberOfSections() : 1; susceptancePerSection = creationInfos.getSusceptancePerSection(); qAtNominalV = creationInfos.getQAtNominalV(); shuntCompensatorType = creationInfos.getShuntCompensatorType(); - connectionName = creationInfos.getConnectionName(); - connectionDirection = creationInfos.getConnectionDirection(); - connectionPosition = creationInfos.getConnectionPosition(); } @Override @@ -65,9 +52,6 @@ public void update(ModificationInfos modificationInfos) { susceptancePerSection = shuntCompensatorCreationInfos.getSusceptancePerSection(); qAtNominalV = shuntCompensatorCreationInfos.getQAtNominalV(); shuntCompensatorType = shuntCompensatorCreationInfos.getShuntCompensatorType(); - connectionName = shuntCompensatorCreationInfos.getConnectionName(); - connectionDirection = shuntCompensatorCreationInfos.getConnectionDirection(); - connectionPosition = shuntCompensatorCreationInfos.getConnectionPosition(); } @Override diff --git a/src/main/java/org/gridsuite/modification/server/modifications/BatteryCreation.java b/src/main/java/org/gridsuite/modification/server/modifications/BatteryCreation.java index 3af888a13..403c24329 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/BatteryCreation.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/BatteryCreation.java @@ -12,18 +12,19 @@ import com.powsybl.commons.reporter.TypedValue; import com.powsybl.iidm.modification.topology.CreateFeederBay; import com.powsybl.iidm.modification.topology.CreateFeederBayBuilder; -import com.powsybl.iidm.network.*; +import com.powsybl.iidm.network.Battery; +import com.powsybl.iidm.network.BatteryAdder; +import com.powsybl.iidm.network.Bus; +import com.powsybl.iidm.network.Network; +import com.powsybl.iidm.network.TopologyKind; +import com.powsybl.iidm.network.VoltageLevel; import com.powsybl.iidm.network.extensions.ActivePowerControlAdder; -import org.apache.commons.collections4.CollectionUtils; import org.gridsuite.modification.server.NetworkModificationException; import org.gridsuite.modification.server.dto.BatteryCreationInfos; -import org.gridsuite.modification.server.dto.ReactiveCapabilityCurveCreationInfos; import java.util.ArrayList; import java.util.List; -import java.util.stream.IntStream; -import static org.gridsuite.modification.server.NetworkModificationException.Type.CREATE_BATTERY_ERROR; import static org.gridsuite.modification.server.NetworkModificationException.Type.BATTERY_ALREADY_EXISTS; import static org.gridsuite.modification.server.modifications.ModificationUtils.nanIfNull; @@ -35,17 +36,12 @@ public class BatteryCreation extends AbstractModification { private final BatteryCreationInfos modificationInfos; private static final String LIMITS = "Limits"; private static final String ACTIVE_LIMITS = "Active limits"; - private static final String REACTIVE_LIMITS = "Reactive limits"; private static final String CONNECTIVITY = "Connectivity"; public BatteryCreation(BatteryCreationInfos modificationInfos) { this.modificationInfos = modificationInfos; } - private static NetworkModificationException makeBatteryException(String batteryId, String msgSuffix) { - return new NetworkModificationException(CREATE_BATTERY_ERROR, "Battery '" + batteryId + "' : " + msgSuffix); - } - @Override public void check(Network network) throws NetworkModificationException { if (network.getBattery(modificationInfos.getEquipmentId()) != null) { @@ -57,35 +53,11 @@ public void check(Network network) throws NetworkModificationException { .controlConnectivity(network, modificationInfos.getVoltageLevelId(), modificationInfos.getBusOrBusbarSectionId(), modificationInfos.getConnectionPosition()); - // check min max reactive limits - if (modificationInfos.getMinimumReactivePower() != null && modificationInfos.getMaximumReactivePower() != null) { - if (Double.isNaN(modificationInfos.getMinimumReactivePower())) { - throw makeBatteryException(modificationInfos.getEquipmentId(), "minimum reactive power is not set"); - } else if (Double.isNaN(modificationInfos.getMaximumReactivePower())) { - throw makeBatteryException(modificationInfos.getEquipmentId(), "maximum reactive power is not set"); - } else if (modificationInfos.getMaximumReactivePower() < modificationInfos.getMinimumReactivePower()) { - throw makeBatteryException(modificationInfos.getEquipmentId(), "maximum reactive power is expected to be greater than or equal to minimum reactive power"); - } - } - - // check reactive capability curve limits - List points = modificationInfos.getReactiveCapabilityCurvePoints(); - if (!CollectionUtils.isEmpty(points)) { - if (points.size() < 2) { - throw makeBatteryException(modificationInfos.getEquipmentId(), "a reactive capability curve should have at least two points"); - } - IntStream.range(0, points.size()) - .forEach(i -> { - ReactiveCapabilityCurveCreationInfos newPoint = points.get(i); - if (Double.isNaN(newPoint.getP())) { - throw makeBatteryException(modificationInfos.getEquipmentId(), "P is not set in a reactive capability curve limits point"); - } else if (Double.isNaN(newPoint.getQminP())) { - throw makeBatteryException(modificationInfos.getEquipmentId(), "min Q is not set in a reactive capability curve limits point"); - } else if (Double.isNaN(newPoint.getQmaxP())) { - throw makeBatteryException(modificationInfos.getEquipmentId(), "max Q is not set in a reactive capability curve limits point"); - } - }); - } + // check reactive limits + ModificationUtils.getInstance().checkReactiveLimitsCreation(modificationInfos, + modificationInfos.getErrorType(), + modificationInfos.getEquipmentId(), + "Battery"); } @Override @@ -163,86 +135,11 @@ private void addExtensionsToBattery(BatteryCreationInfos batteryCreationInfos, B } reportBatteryConnectivity(batteryCreationInfos, subReporter); Reporter subReporterLimits = reportBatteryActiveLimits(batteryCreationInfos, subReporter); - createBatteryReactiveLimits(batteryCreationInfos, battery, subReporterLimits); + ModificationUtils.getInstance().createReactiveLimits(batteryCreationInfos, battery, subReporterLimits); Reporter subReporterSetpoints = reportBatterySetPoints(batteryCreationInfos, subReporter); createBatteryActivePowerControl(batteryCreationInfos, battery, subReporterSetpoints); } - private void addToReports(List reports, Double newValue, String fieldName) { - if (newValue != null) { - reports.add(ModificationUtils.getInstance().buildCreationReport(newValue, fieldName)); - } - } - - private void createBatteryReactiveLimits(BatteryCreationInfos batteryCreationInfos, Battery battery, Reporter subReporter) { - if (Boolean.TRUE.equals(batteryCreationInfos.getReactiveCapabilityCurve())) { - createReactiveCapabilityCurve(batteryCreationInfos, battery, subReporter); - } else if (Boolean.FALSE.equals(batteryCreationInfos.getReactiveCapabilityCurve())) { - createMinMaxReactiveLimits(batteryCreationInfos, battery, subReporter); - } - } - - private void createMinMaxReactiveLimits(BatteryCreationInfos batteryCreationInfos, Battery battery, Reporter subReporter) { - List minMaxReactiveLimitsReports = new ArrayList<>(); - if (batteryCreationInfos.getMinimumReactivePower() != null && batteryCreationInfos.getMaximumReactivePower() != null) { - battery.newMinMaxReactiveLimits().setMinQ(batteryCreationInfos.getMinimumReactivePower()) - .setMaxQ(batteryCreationInfos.getMaximumReactivePower()) - .add(); - minMaxReactiveLimitsReports.add(ModificationUtils.getInstance().buildCreationReport( - batteryCreationInfos.getMinimumReactivePower(), - "Minimum reactive power")); - minMaxReactiveLimitsReports.add(ModificationUtils.getInstance().buildCreationReport( - batteryCreationInfos.getMaximumReactivePower(), - "Maximum reactive power")); - Reporter subReporterReactiveLimits = subReporter.createSubReporter(REACTIVE_LIMITS, REACTIVE_LIMITS); - subReporterReactiveLimits.report(Report.builder() - .withKey(REACTIVE_LIMITS) - .withDefaultMessage(REACTIVE_LIMITS) - .withSeverity(TypedValue.INFO_SEVERITY) - .build()); - ModificationUtils.getInstance().reportModifications(subReporterReactiveLimits, minMaxReactiveLimitsReports, "minMaxReactiveLimitsCreated", "By range"); - } - } - - private void createReactiveCapabilityCurve(BatteryCreationInfos batteryCreationInfos, Battery battery, Reporter subReporter) { - List pointsReports = new ArrayList<>(); - ReactiveCapabilityCurveAdder adder = battery.newReactiveCapabilityCurve(); - List points = batteryCreationInfos.getReactiveCapabilityCurvePoints(); - IntStream.range(0, points.size()) - .forEach(i -> { - String fieldSuffix; - ReactiveCapabilityCurveCreationInfos newPoint = points.get(i); - if (i == 0) { - fieldSuffix = "min"; - } else if (i == (points.size() - 1)) { - fieldSuffix = "max"; - } else { - fieldSuffix = Integer.toString(i); - } - createReactiveCapabilityCurvePoint(adder, newPoint, pointsReports, fieldSuffix); - }); - adder.add(); - Reporter subReporterReactiveLimits = subReporter.createSubReporter(REACTIVE_LIMITS, REACTIVE_LIMITS); - subReporterReactiveLimits.report(Report.builder() - .withKey(REACTIVE_LIMITS) - .withDefaultMessage(REACTIVE_LIMITS) - .withSeverity(TypedValue.INFO_SEVERITY) - .build()); - ModificationUtils.getInstance().reportModifications(subReporterReactiveLimits, pointsReports, "curveReactiveLimitsCreated", "By diagram"); - } - - private void createReactiveCapabilityCurvePoint(ReactiveCapabilityCurveAdder adder, ReactiveCapabilityCurveCreationInfos point, - List reports, String fieldSuffix) { - adder.beginPoint() - .setMaxQ(point.getQmaxP()) - .setMinQ(point.getQminP()) - .setP(point.getP()) - .endPoint(); - addToReports(reports, point.getP(), "P" + fieldSuffix); - addToReports(reports, point.getQminP(), "QminP" + fieldSuffix); - addToReports(reports, point.getQmaxP(), "QmaxP" + fieldSuffix); - } - private Reporter reportBatterySetPoints(BatteryCreationInfos batteryCreationInfos, Reporter subReporter) { List setPointReports = new ArrayList<>(); setPointReports.add(ModificationUtils.getInstance() diff --git a/src/main/java/org/gridsuite/modification/server/modifications/GeneratorCreation.java b/src/main/java/org/gridsuite/modification/server/modifications/GeneratorCreation.java index d8d7a07e5..00ad6b261 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/GeneratorCreation.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/GeneratorCreation.java @@ -7,13 +7,6 @@ package org.gridsuite.modification.server.modifications; import com.powsybl.commons.PowsyblException; -import org.apache.commons.collections4.CollectionUtils; -import org.gridsuite.modification.server.NetworkModificationException; -import static org.gridsuite.modification.server.NetworkModificationException.Type.*; -import static org.gridsuite.modification.server.modifications.ModificationUtils.nanIfNull; - -import org.gridsuite.modification.server.dto.GeneratorCreationInfos; - import com.powsybl.commons.reporter.Report; import com.powsybl.commons.reporter.Reporter; import com.powsybl.commons.reporter.TypedValue; @@ -23,7 +16,6 @@ import com.powsybl.iidm.network.Generator; import com.powsybl.iidm.network.GeneratorAdder; import com.powsybl.iidm.network.Network; -import com.powsybl.iidm.network.ReactiveCapabilityCurveAdder; import com.powsybl.iidm.network.Terminal; import com.powsybl.iidm.network.TopologyKind; import com.powsybl.iidm.network.VoltageLevel; @@ -31,11 +23,14 @@ import com.powsybl.iidm.network.extensions.GeneratorShortCircuitAdder; import com.powsybl.network.store.iidm.impl.extensions.CoordinatedReactiveControlAdderImpl; import com.powsybl.network.store.iidm.impl.extensions.GeneratorStartupAdderImpl; -import org.gridsuite.modification.server.dto.ReactiveCapabilityCurveCreationInfos; +import org.gridsuite.modification.server.NetworkModificationException; +import org.gridsuite.modification.server.dto.GeneratorCreationInfos; import java.util.ArrayList; import java.util.List; -import java.util.stream.IntStream; + +import static org.gridsuite.modification.server.NetworkModificationException.Type.GENERATOR_ALREADY_EXISTS; +import static org.gridsuite.modification.server.modifications.ModificationUtils.nanIfNull; /** * @author Ayoub Labidi @@ -45,17 +40,12 @@ public class GeneratorCreation extends AbstractModification { private final GeneratorCreationInfos modificationInfos; private static final String LIMITS = "Limits"; private static final String ACTIVE_LIMITS = "Active limits"; - private static final String REACTIVE_LIMITS = "Reactive limits"; private static final String CONNECTIVITY = "Connectivity"; public GeneratorCreation(GeneratorCreationInfos modificationInfos) { this.modificationInfos = modificationInfos; } - private static NetworkModificationException makeGeneratorException(String generatorId, String msgSuffix) { - return new NetworkModificationException(CREATE_GENERATOR_ERROR, "Generator '" + generatorId + "' : " + msgSuffix); - } - @Override public void check(Network network) throws NetworkModificationException { if (network.getGenerator(modificationInfos.getEquipmentId()) != null) { @@ -66,35 +56,11 @@ public void check(Network network) throws NetworkModificationException { ModificationUtils.getInstance().controlConnectivity(network, modificationInfos.getVoltageLevelId(), modificationInfos.getBusOrBusbarSectionId(), modificationInfos.getConnectionPosition()); - // check min max reactive limits - if (modificationInfos.getMinimumReactivePower() != null && modificationInfos.getMaximumReactivePower() != null) { - if (Double.isNaN(modificationInfos.getMinimumReactivePower())) { - throw makeGeneratorException(modificationInfos.getEquipmentId(), "minimum reactive power is not set"); - } else if (Double.isNaN(modificationInfos.getMaximumReactivePower())) { - throw makeGeneratorException(modificationInfos.getEquipmentId(), "maximum reactive power is not set"); - } else if (modificationInfos.getMaximumReactivePower() < modificationInfos.getMinimumReactivePower()) { - throw makeGeneratorException(modificationInfos.getEquipmentId(), "maximum reactive power is expected to be greater than or equal to minimum reactive power"); - } - } - - // check reactive capability curve limits - List points = modificationInfos.getReactiveCapabilityCurvePoints(); - if (!CollectionUtils.isEmpty(points)) { - if (points.size() < 2) { - throw makeGeneratorException(modificationInfos.getEquipmentId(), "a reactive capability curve should have at least two points"); - } - IntStream.range(0, points.size()) - .forEach(i -> { - ReactiveCapabilityCurveCreationInfos newPoint = points.get(i); - if (Double.isNaN(newPoint.getP())) { - throw makeGeneratorException(modificationInfos.getEquipmentId(), "P is not set in a reactive capability curve limits point"); - } else if (Double.isNaN(newPoint.getQminP())) { - throw makeGeneratorException(modificationInfos.getEquipmentId(), "min Q is not set in a reactive capability curve limits point"); - } else if (Double.isNaN(newPoint.getQmaxP())) { - throw makeGeneratorException(modificationInfos.getEquipmentId(), "max Q is not set in a reactive capability curve limits point"); - } - }); - } + // check reactive limits + ModificationUtils.getInstance().checkReactiveLimitsCreation(modificationInfos, + modificationInfos.getErrorType(), + modificationInfos.getEquipmentId(), + "Generator"); // check regulated terminal VoltageLevel voltageLevel = ModificationUtils.getInstance().getVoltageLevel(network, modificationInfos.getVoltageLevelId()); @@ -174,7 +140,7 @@ private void addExtensionsToGenerator(GeneratorCreationInfos generatorCreationIn } reportGeneratorConnectivity(generatorCreationInfos, subReporter); Reporter subReporterLimits = reportGeneratorActiveLimits(generatorCreationInfos, subReporter); - createGeneratorReactiveLimits(generatorCreationInfos, generator, subReporterLimits); + ModificationUtils.getInstance().createReactiveLimits(generatorCreationInfos, generator, subReporterLimits); Reporter subReporterSetpoints = reportGeneratorSetPoints(generatorCreationInfos, subReporter); createGeneratorVoltageRegulation(generatorCreationInfos, generator, voltageLevel, subReporterSetpoints); createGeneratorActivePowerControl(generatorCreationInfos, generator, subReporterSetpoints); @@ -211,81 +177,6 @@ private void createGeneratorInBusBreaker(VoltageLevel voltageLevel, GeneratorCre .build()); } - private void addToReports(List reports, Double newValue, String fieldName) { - if (newValue != null) { - reports.add(ModificationUtils.getInstance().buildCreationReport(newValue, fieldName)); - } - } - - private void createGeneratorReactiveLimits(GeneratorCreationInfos generatorCreationInfos, Generator generator, Reporter subReporter) { - if (Boolean.TRUE.equals(generatorCreationInfos.getReactiveCapabilityCurve())) { - createReactiveCapabilityCurve(generatorCreationInfos, generator, subReporter); - } else if (Boolean.FALSE.equals(generatorCreationInfos.getReactiveCapabilityCurve())) { - createMinMaxReactiveLimits(generatorCreationInfos, generator, subReporter); - } - } - - private void createMinMaxReactiveLimits(GeneratorCreationInfos generatorCreationInfos, Generator generator, Reporter subReporter) { - List minMaxReactiveLimitsReports = new ArrayList<>(); - if (generatorCreationInfos.getMinimumReactivePower() != null && generatorCreationInfos.getMaximumReactivePower() != null) { - generator.newMinMaxReactiveLimits().setMinQ(generatorCreationInfos.getMinimumReactivePower()) - .setMaxQ(generatorCreationInfos.getMaximumReactivePower()) - .add(); - minMaxReactiveLimitsReports.add(ModificationUtils.getInstance().buildCreationReport( - generatorCreationInfos.getMinimumReactivePower(), - "Minimum reactive power")); - minMaxReactiveLimitsReports.add(ModificationUtils.getInstance().buildCreationReport( - generatorCreationInfos.getMaximumReactivePower(), - "Maximum reactive power")); - Reporter subReporterReactiveLimits = subReporter.createSubReporter(REACTIVE_LIMITS, REACTIVE_LIMITS); - subReporterReactiveLimits.report(Report.builder() - .withKey(REACTIVE_LIMITS) - .withDefaultMessage(REACTIVE_LIMITS) - .withSeverity(TypedValue.INFO_SEVERITY) - .build()); - ModificationUtils.getInstance().reportModifications(subReporterReactiveLimits, minMaxReactiveLimitsReports, "minMaxReactiveLimitsCreated", "By range"); - } - } - - private void createReactiveCapabilityCurvePoint(ReactiveCapabilityCurveAdder adder, ReactiveCapabilityCurveCreationInfos point, - List reports, String fieldSuffix) { - adder.beginPoint() - .setMaxQ(point.getQmaxP()) - .setMinQ(point.getQminP()) - .setP(point.getP()) - .endPoint(); - addToReports(reports, point.getP(), "P" + fieldSuffix); - addToReports(reports, point.getQminP(), "QminP" + fieldSuffix); - addToReports(reports, point.getQmaxP(), "QmaxP" + fieldSuffix); - } - - private void createReactiveCapabilityCurve(GeneratorCreationInfos generatorCreationInfos, Generator generator, Reporter subReporter) { - List pointsReports = new ArrayList<>(); - ReactiveCapabilityCurveAdder adder = generator.newReactiveCapabilityCurve(); - List points = generatorCreationInfos.getReactiveCapabilityCurvePoints(); - IntStream.range(0, points.size()) - .forEach(i -> { - String fieldSuffix; - ReactiveCapabilityCurveCreationInfos newPoint = points.get(i); - if (i == 0) { - fieldSuffix = "min"; - } else if (i == (points.size() - 1)) { - fieldSuffix = "max"; - } else { - fieldSuffix = Integer.toString(i); - } - createReactiveCapabilityCurvePoint(adder, newPoint, pointsReports, fieldSuffix); - }); - adder.add(); - Reporter subReporterReactiveLimits = subReporter.createSubReporter(REACTIVE_LIMITS, REACTIVE_LIMITS); - subReporterReactiveLimits.report(Report.builder() - .withKey(REACTIVE_LIMITS) - .withDefaultMessage(REACTIVE_LIMITS) - .withSeverity(TypedValue.INFO_SEVERITY) - .build()); - ModificationUtils.getInstance().reportModifications(subReporterReactiveLimits, pointsReports, "curveReactiveLimitsCreated", "By diagram"); - } - private Reporter reportGeneratorSetPoints(GeneratorCreationInfos generatorCreationInfos, Reporter subReporter) { List setPointReports = new ArrayList<>(); setPointReports.add(ModificationUtils.getInstance() diff --git a/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java b/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java index 0a2c7352d..4cb5e7959 100644 --- a/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java +++ b/src/main/java/org/gridsuite/modification/server/modifications/ModificationUtils.java @@ -814,5 +814,137 @@ public void checkMaxReactivePowerGreaterThanMinReactivePower(MinMaxReactiveLimit throw new NetworkModificationException(exceptionType, errorMessage + "maximum reactive power " + maxReactivePower + " is expected to be greater than or equal to minimum reactive power " + minReactivePower); } } + + private NetworkModificationException makeEquipmentException(NetworkModificationException.Type errorType, + String equipmentId, + String equipmentName, + String msgSuffix) { + return new NetworkModificationException(errorType, + equipmentName + " '" + equipmentId + "' : " + msgSuffix); + } + + public void checkReactiveLimitsCreation(ReactiveLimitsHolderInfos modificationInfos, + NetworkModificationException.Type errorType, + String equipmentId, + String equipmentName) { + // check min max reactive limits + if (modificationInfos.getMinimumReactivePower() != null && modificationInfos.getMaximumReactivePower() != null) { + if (Double.isNaN(modificationInfos.getMinimumReactivePower())) { + throw makeEquipmentException(errorType, equipmentId, equipmentName, "minimum reactive power is not set"); + } else if (Double.isNaN(modificationInfos.getMaximumReactivePower())) { + throw makeEquipmentException(errorType, equipmentId, equipmentName, "maximum reactive power is not set"); + } else if (modificationInfos.getMaximumReactivePower() < modificationInfos.getMinimumReactivePower()) { + throw makeEquipmentException(errorType, equipmentId, equipmentName, "maximum reactive power is expected to be greater than or equal to minimum reactive power"); + } + } + + // check reactive capability curve limits + List points = modificationInfos.getReactiveCapabilityCurvePoints(); + if (!org.apache.commons.collections4.CollectionUtils.isEmpty(points)) { + if (points.size() < 2) { + throw makeEquipmentException(errorType, equipmentId, equipmentName, "a reactive capability curve should have at least two points"); + } + IntStream.range(0, points.size()) + .forEach(i -> { + ReactiveCapabilityCurveCreationInfos newPoint = points.get(i); + if (Double.isNaN(newPoint.getP())) { + throw makeEquipmentException(errorType, equipmentId, equipmentName, "P is not set in a reactive capability curve limits point"); + } else if (Double.isNaN(newPoint.getQminP())) { + throw makeEquipmentException(errorType, equipmentId, equipmentName, "min Q is not set in a reactive capability curve limits point"); + } else if (Double.isNaN(newPoint.getQmaxP())) { + throw makeEquipmentException(errorType, equipmentId, equipmentName, "max Q is not set in a reactive capability curve limits point"); + } + }); + } + } + + public static void addToReports(List reports, Double newValue, String fieldName) { + if (newValue != null) { + reports.add(ModificationUtils.getInstance().buildCreationReport(newValue, fieldName)); + } + } + + public void createReactiveLimits(ReactiveLimitsHolderInfos creationInfos, + ReactiveLimitsHolder reactiveLimitsHolder, + Reporter subReporter) { + if (Boolean.TRUE.equals(creationInfos.getReactiveCapabilityCurve())) { + createReactiveCapabilityCurve(creationInfos, reactiveLimitsHolder, subReporter); + } else if (Boolean.FALSE.equals(creationInfos.getReactiveCapabilityCurve())) { + createMinMaxReactiveLimits(creationInfos, reactiveLimitsHolder, subReporter); + } + } + + public void createMinMaxReactiveLimits(ReactiveLimitsHolderInfos batteryCreationInfos, + ReactiveLimitsHolder reactiveLimitsHolder, + Reporter subReporter) { + List minMaxReactiveLimitsReports = new ArrayList<>(); + if (batteryCreationInfos.getMinimumReactivePower() != null && batteryCreationInfos.getMaximumReactivePower() != null) { + reactiveLimitsHolder.newMinMaxReactiveLimits() + .setMinQ(batteryCreationInfos.getMinimumReactivePower()) + .setMaxQ(batteryCreationInfos.getMaximumReactivePower()) + .add(); + + minMaxReactiveLimitsReports.add(ModificationUtils.getInstance().buildCreationReport( + batteryCreationInfos.getMinimumReactivePower(), + MIN_REACTIVE_POWER_FIELDNAME)); + + minMaxReactiveLimitsReports.add(ModificationUtils.getInstance().buildCreationReport( + batteryCreationInfos.getMaximumReactivePower(), + MAX_REACTIVE_POWER_FIELDNAME)); + + Reporter subReporterReactiveLimits = subReporter.createSubReporter(REACTIVE_LIMITS, REACTIVE_LIMITS); + + subReporterReactiveLimits.report(Report.builder() + .withKey(REACTIVE_LIMITS) + .withDefaultMessage(REACTIVE_LIMITS) + .withSeverity(TypedValue.INFO_SEVERITY) + .build()); + + ModificationUtils.getInstance().reportModifications(subReporterReactiveLimits, minMaxReactiveLimitsReports, "minMaxReactiveLimitsCreated", "By range"); + } + } + + public void createReactiveCapabilityCurve(ReactiveLimitsHolderInfos creationInfos, + ReactiveLimitsHolder reactiveLimitsHolder, + Reporter subReporter) { + List pointsReports = new ArrayList<>(); + ReactiveCapabilityCurveAdder adder = reactiveLimitsHolder.newReactiveCapabilityCurve(); + List points = creationInfos.getReactiveCapabilityCurvePoints(); + IntStream.range(0, points.size()) + .forEach(i -> { + String fieldSuffix; + ReactiveCapabilityCurveCreationInfos newPoint = points.get(i); + if (i == 0) { + fieldSuffix = "min"; + } else if (i == (points.size() - 1)) { + fieldSuffix = "max"; + } else { + fieldSuffix = Integer.toString(i); + } + createReactiveCapabilityCurvePoint(adder, newPoint, pointsReports, fieldSuffix); + }); + adder.add(); + Reporter subReporterReactiveLimits = subReporter.createSubReporter(REACTIVE_LIMITS, REACTIVE_LIMITS); + subReporterReactiveLimits.report(Report.builder() + .withKey(REACTIVE_LIMITS) + .withDefaultMessage(REACTIVE_LIMITS) + .withSeverity(TypedValue.INFO_SEVERITY) + .build()); + ModificationUtils.getInstance().reportModifications(subReporterReactiveLimits, pointsReports, "curveReactiveLimitsCreated", "By diagram"); + } + + private void createReactiveCapabilityCurvePoint(ReactiveCapabilityCurveAdder adder, + ReactiveCapabilityCurveCreationInfos point, + List reports, + String fieldSuffix) { + adder.beginPoint() + .setMaxQ(point.getQmaxP()) + .setMinQ(point.getQminP()) + .setP(point.getP()) + .endPoint(); + addToReports(reports, point.getP(), "P" + fieldSuffix); + addToReports(reports, point.getQminP(), "QminP" + fieldSuffix); + addToReports(reports, point.getQmaxP(), "QmaxP" + fieldSuffix); + } }