-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Seddik Yengui <[email protected]>
- Loading branch information
1 parent
58f5e5c
commit c2b5b44
Showing
20 changed files
with
1,830 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/main/java/org/gridsuite/modification/server/dto/ByFormulaModificationInfos.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* Copyright (c) 2023, 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 com.fasterxml.jackson.annotation.JsonTypeName; | ||
import com.powsybl.commons.reporter.Reporter; | ||
import com.powsybl.commons.reporter.ReporterModel; | ||
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 lombok.ToString; | ||
import lombok.experimental.SuperBuilder; | ||
import org.gridsuite.modification.server.ModificationType; | ||
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; | ||
|
||
/** | ||
* @author Seddik Yengui <Seddik.yengui at rte-france.com> | ||
*/ | ||
|
||
@SuperBuilder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Getter | ||
@Setter | ||
@JsonTypeName("BY_FORMULA_MODIFICATION") | ||
@ModificationErrorTypeName("BY_FORMULA_MODIFICATION_ERROR") | ||
@ToString(callSuper = true) | ||
@Schema(description = "Modification by formula") | ||
public class ByFormulaModificationInfos extends ModificationInfos { | ||
@Schema(description = "Identifiable type") | ||
private IdentifiableType identifiableType; | ||
|
||
@Schema(description = "list of formulas") | ||
private List<FormulaInfos> formulaInfosList; | ||
|
||
@Override | ||
public ByFormulaModificationEntity toEntity() { | ||
return new ByFormulaModificationEntity(this); | ||
} | ||
|
||
@Override | ||
public ByFormulaModification toModification() { | ||
return new ByFormulaModification(this); | ||
} | ||
|
||
@Override | ||
public Reporter createSubReporter(ReporterModel reporter) { | ||
return reporter.createSubReporter(ModificationType.BY_FORMULA_MODIFICATION.name(), "By formula modification"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/org/gridsuite/modification/server/dto/formula/FormulaInfos.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* Copyright (c) 2023, 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.formula; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.experimental.SuperBuilder; | ||
import org.gridsuite.modification.server.dto.FilterInfos; | ||
import org.gridsuite.modification.server.entities.equipment.modification.FormulaEntity; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
/** | ||
* @author Seddik Yengui <Seddik.yengui at rte-france.com> | ||
*/ | ||
|
||
@SuperBuilder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Getter | ||
@Setter | ||
public class FormulaInfos { | ||
@Schema(description = "id") | ||
private UUID id; | ||
|
||
@Schema(description = "List of filters") | ||
private List<FilterInfos> filters; | ||
|
||
@Schema(description = "Edited field") | ||
private String editedField; | ||
|
||
@Schema(description = "First reference field or value") | ||
private ReferenceFieldOrValue fieldOrValue1; | ||
|
||
@Schema(description = "Second reference field or value") | ||
private ReferenceFieldOrValue fieldOrValue2; | ||
|
||
@Schema(description = "Operator") | ||
private Operator operator; | ||
|
||
public FormulaEntity toEntity() { | ||
return new FormulaEntity(this); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/org/gridsuite/modification/server/dto/formula/Operator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Copyright (c) 2023, 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.formula; | ||
|
||
/** | ||
* @author Seddik Yengui <Seddik.yengui at rte-france.com> | ||
*/ | ||
|
||
public enum Operator { | ||
ADDITION, | ||
SUBTRACTION, | ||
MULTIPLICATION, | ||
DIVISION, | ||
PERCENTAGE | ||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/org/gridsuite/modification/server/dto/formula/ReferenceFieldOrValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* Copyright (c) 2023, 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.formula; | ||
|
||
import com.powsybl.iidm.network.Battery; | ||
import com.powsybl.iidm.network.Generator; | ||
import com.powsybl.iidm.network.Identifiable; | ||
import com.powsybl.iidm.network.IdentifiableType; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import org.gridsuite.modification.server.NetworkModificationException; | ||
import org.gridsuite.modification.server.dto.formula.equipmentfield.BatteryField; | ||
import org.gridsuite.modification.server.dto.formula.equipmentfield.GeneratorField; | ||
|
||
/** | ||
* @author Seddik Yengui <Seddik.yengui at rte-france.com> | ||
*/ | ||
|
||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Getter | ||
@Setter | ||
public class ReferenceFieldOrValue { | ||
private String equipmentField; | ||
|
||
private Double value; | ||
|
||
public Double getRefOrValue(Identifiable<?> identifiable) { | ||
if (value == null && equipmentField == null) { | ||
throw new NetworkModificationException(NetworkModificationException.Type.BY_FORMULA_MODIFICATION_ERROR, | ||
"There is no value or reference to any of the equipment fields"); | ||
} | ||
|
||
if (value != null && !Double.isNaN(value)) { | ||
return value; | ||
} | ||
|
||
IdentifiableType identifiableType = identifiable.getType(); | ||
Double referenceValue = switch (identifiableType) { | ||
case GENERATOR -> GeneratorField.getReferenceValue((Generator) identifiable, equipmentField); | ||
case BATTERY -> BatteryField.getReferenceValue((Battery) 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; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/org/gridsuite/modification/server/dto/formula/equipmentfield/BatteryField.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Copyright (c) 2023, 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.formula.equipmentfield; | ||
|
||
import com.powsybl.iidm.network.Battery; | ||
import com.powsybl.iidm.network.extensions.ActivePowerControl; | ||
import com.powsybl.iidm.network.extensions.ActivePowerControlAdder; | ||
|
||
/** | ||
* @author Seddik Yengui <Seddik.yengui at rte-france.com> | ||
*/ | ||
|
||
public enum BatteryField { | ||
MINIMUM_ACTIVE_POWER, | ||
MAXIMUM_ACTIVE_POWER, | ||
ACTIVE_POWER_SET_POINT, | ||
REACTIVE_POWER_SET_POINT, | ||
DROOP; | ||
|
||
public static Double getReferenceValue(Battery battery, String batteryField) { | ||
ActivePowerControl<Battery> activePowerControl = battery.getExtension(ActivePowerControl.class); | ||
BatteryField field = BatteryField.valueOf(batteryField); | ||
return switch (field) { | ||
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, String batteryField, Double newValue) { | ||
BatteryField field = BatteryField.valueOf(batteryField); | ||
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(); | ||
} | ||
} | ||
} |
Oops, something went wrong.