Skip to content

Commit

Permalink
Add by formula modification (#359)
Browse files Browse the repository at this point in the history
Signed-off-by: Seddik Yengui <[email protected]>
  • Loading branch information
YenguiSeddik authored Nov 13, 2023
1 parent 58f5e5c commit c2b5b44
Show file tree
Hide file tree
Showing 20 changed files with 1,830 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public enum ModificationType {
VOLTAGE_INIT_MODIFICATION(PreloadingStrategy.COLLECTION),
VSC_CREATION(PreloadingStrategy.NONE),
CONVERTER_STATION_CREATION(PreloadingStrategy.NONE),
TABULAR_MODIFICATION(PreloadingStrategy.COLLECTION);
TABULAR_MODIFICATION(PreloadingStrategy.COLLECTION),
BY_FORMULA_MODIFICATION(PreloadingStrategy.COLLECTION);

private final PreloadingStrategy strategy;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,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;
Expand Down
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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
@JsonSubTypes.Type(value = VoltageInitModificationInfos.class),
@JsonSubTypes.Type(value = VscCreationInfos.class),
@JsonSubTypes.Type(value = ConverterStationCreationInfos.class),
@JsonSubTypes.Type(value = TabularModificationInfos.class)
@JsonSubTypes.Type(value = TabularModificationInfos.class),
@JsonSubTypes.Type(value = ByFormulaModificationInfos.class)
})
@SuperBuilder
@NoArgsConstructor
Expand Down
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);
}
}
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
}
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;
}
}
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();
}
}
}
Loading

0 comments on commit c2b5b44

Please sign in to comment.