Skip to content

Commit

Permalink
Merge branch 'main' into add-control-on-active-limits-fields
Browse files Browse the repository at this point in the history
  • Loading branch information
ghazwarhili authored Dec 14, 2023
2 parents 69645cc + 0fb7fd2 commit b5f26fe
Show file tree
Hide file tree
Showing 28 changed files with 2,392 additions and 490 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@
<groupId>com.powsybl</groupId>
<artifactId>powsybl-network-store-client</artifactId>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-network-store-iidm-impl</artifactId>
<version>1.7.0</version>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-ws-commons</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@
*/
package org.gridsuite.modification.server.dto;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.*;
import lombok.experimental.SuperBuilder;

/**
* @author Achour Berrahma <achour.berrahma at rte-france.com>
*/
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@Getter
@ToString
@EqualsAndHashCode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@
*/
package org.gridsuite.modification.server.dto;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.*;
import lombok.experimental.SuperBuilder;

/**
* @author Nicolas Noir <nicolas.noir at rte-france.com>
*/
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@Getter
@ToString
@EqualsAndHashCode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,4 @@ public static Set<SubstationInfos> getSubstationsInfos(@NonNull Identifiable<?>
.name(vl.getSubstation().map(Substation::getNameOrId).orElse(null)).build())
.collect(Collectors.toSet());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.powsybl.iidm.network.IdentifiableType;
import com.powsybl.iidm.network.Load;
import com.powsybl.iidm.network.ShuntCompensator;
import com.powsybl.iidm.network.TwoWindingsTransformer;
import com.powsybl.iidm.network.VoltageLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -24,6 +25,7 @@
import org.gridsuite.modification.server.dto.formula.equipmentfield.GeneratorField;
import org.gridsuite.modification.server.dto.formula.equipmentfield.LoadField;
import org.gridsuite.modification.server.dto.formula.equipmentfield.ShuntCompensatorField;
import org.gridsuite.modification.server.dto.formula.equipmentfield.TwoWindingsTransformerField;
import org.gridsuite.modification.server.dto.formula.equipmentfield.VoltageLevelField;


Expand Down Expand Up @@ -52,21 +54,15 @@ public Double getRefOrValue(Identifiable<?> identifiable) {
}

IdentifiableType identifiableType = identifiable.getType();
Double referenceValue = switch (identifiableType) {
return switch (identifiableType) {
case GENERATOR -> GeneratorField.getReferenceValue((Generator) identifiable, equipmentField);
case BATTERY -> BatteryField.getReferenceValue((Battery) identifiable, equipmentField);
case SHUNT_COMPENSATOR -> ShuntCompensatorField.getReferenceValue((ShuntCompensator) identifiable, equipmentField);
case VOLTAGE_LEVEL -> VoltageLevelField.getReferenceValue((VoltageLevel) identifiable, equipmentField);
case LOAD -> LoadField.getReferenceValue((Load) identifiable, equipmentField);
case TWO_WINDINGS_TRANSFORMER -> TwoWindingsTransformerField.getReferenceValue((TwoWindingsTransformer) 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,70 @@
package org.gridsuite.modification.server.dto.formula.equipmentfield;

import com.powsybl.iidm.network.PhaseTapChanger;
import com.powsybl.iidm.network.RatioTapChanger;
import com.powsybl.iidm.network.TwoWindingsTransformer;

public enum TwoWindingsTransformerField {
SERIES_RESISTANCE,
SERIES_REACTANCE,
MAGNETIZING_CONDUCTANCE,
MAGNETIZING_SUSCEPTANCE,
RATED_VOLTAGE_1,
RATED_VOLTAGE_2,
RATED_S,
TARGET_V,
RATIO_LOW_TAP_POSITION,
RATIO_TAP_POSITION,
RATIO_TARGET_DEADBAND,
REGULATION_VALUE,
PHASE_LOW_TAP_POSITION,
PHASE_TAP_POSITION,
PHASE_TARGET_DEADBAND;

public static Double getReferenceValue(TwoWindingsTransformer transformer, String twoWindingsTransformerField) {
TwoWindingsTransformerField field = TwoWindingsTransformerField.valueOf(twoWindingsTransformerField);
final PhaseTapChanger phaseTapChanger = transformer.getPhaseTapChanger();
final RatioTapChanger ratioTapChanger = transformer.getRatioTapChanger();
return switch (field) {
case SERIES_RESISTANCE -> transformer.getR();
case SERIES_REACTANCE -> transformer.getX();
case MAGNETIZING_CONDUCTANCE -> transformer.getG();
case MAGNETIZING_SUSCEPTANCE -> transformer.getB();
case RATED_VOLTAGE_1 -> transformer.getRatedU1();
case RATED_VOLTAGE_2 -> transformer.getRatedU2();
case RATED_S -> transformer.getRatedS();
case TARGET_V -> ratioTapChanger != null ? ratioTapChanger.getTargetV() : null;
case RATIO_LOW_TAP_POSITION -> ratioTapChanger != null ? (double) ratioTapChanger.getLowTapPosition() : null;
case RATIO_TAP_POSITION -> ratioTapChanger != null ? (double) ratioTapChanger.getTapPosition() : null;
case RATIO_TARGET_DEADBAND -> ratioTapChanger != null ? ratioTapChanger.getTargetDeadband() : null;
case REGULATION_VALUE -> phaseTapChanger != null ? phaseTapChanger.getRegulationValue() : null;
case PHASE_LOW_TAP_POSITION -> phaseTapChanger != null ? (double) phaseTapChanger.getLowTapPosition() : null;
case PHASE_TAP_POSITION -> phaseTapChanger != null ? (double) phaseTapChanger.getTapPosition() : null;
case PHASE_TARGET_DEADBAND -> phaseTapChanger != null ? phaseTapChanger.getTargetDeadband() : null;
};
}

public static void setNewValue(TwoWindingsTransformer transformer, String twoWindingsTransformerField, Double newValue) {
TwoWindingsTransformerField field = TwoWindingsTransformerField.valueOf(twoWindingsTransformerField);
final PhaseTapChanger phaseTapChanger = transformer.getPhaseTapChanger();
final RatioTapChanger ratioTapChanger = transformer.getRatioTapChanger();

switch (field) {
case SERIES_RESISTANCE -> transformer.setR(newValue);
case SERIES_REACTANCE -> transformer.setX(newValue);
case MAGNETIZING_CONDUCTANCE -> transformer.setG(newValue);
case MAGNETIZING_SUSCEPTANCE -> transformer.setB(newValue);
case RATED_VOLTAGE_1 -> transformer.setRatedU1(newValue);
case RATED_VOLTAGE_2 -> transformer.setRatedU2(newValue);
case RATED_S -> transformer.setRatedS(newValue);
case TARGET_V -> ratioTapChanger.setTargetV(newValue);
case RATIO_LOW_TAP_POSITION -> ratioTapChanger.setLowTapPosition(newValue.intValue());
case RATIO_TAP_POSITION -> ratioTapChanger.setTapPosition(newValue.intValue());
case RATIO_TARGET_DEADBAND -> ratioTapChanger.setTargetDeadband(newValue);
case REGULATION_VALUE -> phaseTapChanger.setRegulationValue(newValue);
case PHASE_LOW_TAP_POSITION -> phaseTapChanger.setLowTapPosition(newValue.intValue());
case PHASE_TAP_POSITION -> phaseTapChanger.setTapPosition(newValue.intValue());
case PHASE_TARGET_DEADBAND -> phaseTapChanger.setTargetDeadband(newValue);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.gridsuite.modification.server.dto.*;
import org.gridsuite.modification.server.entities.equipment.modification.GeneratorModificationEntity;
import org.gridsuite.modification.server.entities.equipment.modification.LoadModificationEntity;
import org.gridsuite.modification.server.entities.equipment.modification.VoltageLevelModificationEntity;

/**
* @author Etienne Homer <etienne.homer at rte-france.com>
Expand Down Expand Up @@ -46,6 +47,9 @@ public TabularModificationEntity(TabularModificationInfos tabularModificationInf
case "LOAD_MODIFICATION":
modifications = tabularModificationInfos.getModifications().stream().map(loadModificationInfos -> new LoadModificationEntity((LoadModificationInfos) loadModificationInfos)).collect(Collectors.toList());
break;
case "VOLTAGE_LEVEL_MODIFICATION":
modifications = tabularModificationInfos.getModifications().stream().map(voltageLevelModificationInfos -> new VoltageLevelModificationEntity((VoltageLevelModificationInfos) voltageLevelModificationInfos)).collect(Collectors.toList());
break;
default:
break;
}
Expand Down Expand Up @@ -76,6 +80,9 @@ public void update(@NonNull ModificationInfos modificationInfos) {
case "LOAD_MODIFICATION":
modifications.addAll(tabularModificationInfos.getModifications().stream().map(loadModificationInfos -> new LoadModificationEntity((LoadModificationInfos) loadModificationInfos)).collect(Collectors.toList()));
break;
case "VOLTAGE_LEVEL_MODIFICATION":
modifications.addAll(tabularModificationInfos.getModifications().stream().map(voltageLevelModificationInfos -> new VoltageLevelModificationEntity((VoltageLevelModificationInfos) voltageLevelModificationInfos)).collect(Collectors.toList()));
break;
default:
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@
import com.powsybl.commons.reporter.TypedValue;
import com.powsybl.iidm.modification.scalable.Scalable;
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.*;
import org.gridsuite.modification.server.service.FilterService;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import java.util.stream.Collectors;

import static org.gridsuite.modification.server.modifications.ModificationUtils.createReport;
Expand Down Expand Up @@ -52,66 +49,26 @@ public void apply(Network network, Reporter subReporter) {
.filter(distinctByKey(FilterInfos::getId))
.collect(Collectors.toMap(FilterInfos::getId, FilterInfos::getName));

// export filters from filter server
String workingVariantId = network.getVariantManager().getWorkingVariantId();
UUID uuid = ((NetworkImpl) network).getUuid();
Map<UUID, FilterEquipments> exportFilters = filterService
.exportFilters(new ArrayList<>(filters.keySet()), uuid, workingVariantId)
.stream()
.peek(t -> t.setFilterName(filters.get(t.getFilterId())))
.collect(Collectors.toMap(FilterEquipments::getFilterId, Function.identity()));

// collect all filters with wrong equipments ids
Map<UUID, FilterEquipments> filterWithWrongEquipmentsIds = exportFilters.entrySet().stream()
.filter(e -> !CollectionUtils.isEmpty(e.getValue().getNotFoundEquipments()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

Boolean noValidEquipmentId = exportFilters.values().stream()
.allMatch(filterEquipments -> filterEquipments.getIdentifiableAttributes().isEmpty());

if (noValidEquipmentId) {
String errorMsg = scalingInfos.getErrorType() + ": There is no valid equipment ID among the provided filter(s)";
createReport(subReporter, "invalidFilters", errorMsg, TypedValue.ERROR_SEVERITY);
return;
Map<UUID, FilterEquipments> exportFilters = ModificationUtils.getUuidFilterEquipmentsMap(filterService, network, subReporter, filters, scalingInfos.getErrorType());
if (exportFilters != null) {
Map<UUID, FilterEquipments> filtersWithWrongEquipmentIds = ModificationUtils.getUuidFilterWrongEquipmentsIdsMap(subReporter, exportFilters, filters);

// apply variations
scalingInfos.getVariations().forEach(variation -> {
List<IdentifiableAttributes> identifiableAttributes = ModificationUtils.getIdentifiableAttributes(exportFilters, filtersWithWrongEquipmentIds, variation.getFilters(), subReporter);

if (CollectionUtils.isEmpty(identifiableAttributes)) {
String filterNames = variation.getFilters().stream().map(FilterInfos::getName).collect(Collectors.joining(", "));
createReport(subReporter,
"allFiltersWrong",
String.format("All of the following variation's filters have equipments with wrong id : %s", filterNames),
TypedValue.WARN_SEVERITY);
} else {
applyVariation(network, subReporter, identifiableAttributes, variation);
}
});
createReport(subReporter, "scalingCreated", "new scaling created", TypedValue.INFO_SEVERITY);
}

// create report for each wrong filter
filterWithWrongEquipmentsIds.values().forEach(f -> {
var equipmentIds = String.join(", ", f.getNotFoundEquipments());
createReport(subReporter,
"filterEquipmentsNotFound_" + f.getFilterName(),
String.format("Cannot find the following equipments %s in filter %s", equipmentIds, filters.get(f.getFilterId())),
TypedValue.WARN_SEVERITY);
});

// apply variations
scalingInfos.getVariations().forEach(variation -> {
variation.getFilters().stream()
.filter(f -> !exportFilters.containsKey(f.getId()))
.forEach(f -> createReport(subReporter,
"filterNotFound",
String.format("Cannot find the following filter: %s", f.getName()),
TypedValue.WARN_SEVERITY));

List<IdentifiableAttributes> identifiableAttributes = variation.getFilters()
.stream()
.filter(f -> !filterWithWrongEquipmentsIds.containsKey(f.getId()) && exportFilters.containsKey(f.getId()))
.flatMap(f -> exportFilters.get(f.getId())
.getIdentifiableAttributes()
.stream())
.collect(Collectors.toList());

if (CollectionUtils.isEmpty(identifiableAttributes)) {
String filterNames = variation.getFilters().stream().map(FilterInfos::getName).collect(Collectors.joining(", "));
createReport(subReporter,
"allFiltersWrong",
String.format("All of the following variation's filters have equipments with wrong id : %s", filterNames),
TypedValue.WARN_SEVERITY);
} else {
applyVariation(network, subReporter, identifiableAttributes, variation);
}
});
createReport(subReporter, "scalingCreated", "new scaling created", TypedValue.INFO_SEVERITY);
}

private void applyVariation(Network network,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ public void check(Network network) throws NetworkModificationException {
if (!CollectionUtils.isEmpty(points) && modificationPoints != null) {
ModificationUtils.getInstance().checkMaxQGreaterThanMinQ(batteryPoints, modificationPoints, MODIFY_BATTERY_ERROR, errorMessage);
}
checkActivePowerZeroOrBetweenMinAndMaxActivePowerBattery(modificationInfos, battery, MODIFY_BATTERY_ERROR, errorMessage);
}

private void checkActivePowerZeroOrBetweenMinAndMaxActivePowerBattery(BatteryModificationInfos modificationInfos, Battery battery, NetworkModificationException.Type exceptionType, String errorMessage) {
ModificationUtils.getInstance().checkActivePowerZeroOrBetweenMinAndMaxActivePower(
modificationInfos.getActivePowerSetpoint(),
modificationInfos.getMinActivePower(),
modificationInfos.getMaxActivePower(),
battery.getMinP(),
battery.getMaxP(),
battery.getTargetP(),
exceptionType,
errorMessage
);
}

@Override
Expand Down
Loading

0 comments on commit b5f26fe

Please sign in to comment.