Skip to content

Commit

Permalink
Merge branch 'main' into add_twt_to_by_formula_modification
Browse files Browse the repository at this point in the history
  • Loading branch information
YenguiSeddik authored Dec 7, 2023
2 parents fa8b662 + 66af5a0 commit b74ab50
Show file tree
Hide file tree
Showing 18 changed files with 965 additions and 298 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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,18 @@ public void apply(Network network, Reporter subReporter) {

report(resultReporter, Integer.toString(componentNum), "SupplyDemandBalanceCouldBeMet", "The supply-demand balance could be met",
Map.of(), TypedValue.INFO_SEVERITY);
generatorsByRegion.forEach((region, generators) -> report(resultReporter, Integer.toString(componentNum), "SumGeneratorActivePower" + region, "Sum of generator active power setpoints in ${region} region: ${sum} MW.",
Map.of("region", region, "sum", getSumActivePower(generators)), TypedValue.INFO_SEVERITY));
generatorsByRegion.forEach((region, generators) -> {
Map<EnergySource, Double> activePowerSumByEnergySource = getActivePowerSumByEnergySource(generators);
report(resultReporter, Integer.toString(componentNum), "SumGeneratorActivePower" + region, "Sum of generator active power setpoints in ${region} region: ${sum} MW (NUCLEAR: ${nuclearSum} MW, THERMAL: ${thermalSum} MW, HYDRO: ${hydroSum} MW, WIND AND SOLAR: ${windAndSolarSum} MW, OTHER: ${otherSum} MW).",
Map.of("region", region,
"sum", activePowerSumByEnergySource.values().stream().reduce(0d, Double::sum),
"nuclearSum", activePowerSumByEnergySource.getOrDefault(EnergySource.NUCLEAR, 0d),
"thermalSum", activePowerSumByEnergySource.getOrDefault(EnergySource.THERMAL, 0d),
"hydroSum", activePowerSumByEnergySource.getOrDefault(EnergySource.HYDRO, 0d),
"windAndSolarSum", activePowerSumByEnergySource.getOrDefault(EnergySource.WIND, 0d) + activePowerSumByEnergySource.getOrDefault(EnergySource.SOLAR, 0d),
"otherSum", activePowerSumByEnergySource.getOrDefault(EnergySource.OTHER, 0d)
), TypedValue.INFO_SEVERITY);
});
} else {
double remainingPowerImbalance = totalAmountSupplyToBeDispatched - realized;
report(resultReporter, Integer.toString(componentNum), "SupplyDemandBalanceCouldNotBeMet", "The supply-demand balance could not be met : the remaining power imbalance is ${remainingPower} MW",
Expand Down Expand Up @@ -602,8 +612,8 @@ private boolean hasCvgPropertyName(Set<String> propertyNames) {
return propertyNames.stream().anyMatch(REGION_CVG::equals);
}

private double getSumActivePower(List<Generator> generators) {
return generators.stream().mapToDouble(Generator::getTargetP).sum();
private Map<EnergySource, Double> getActivePowerSumByEnergySource(List<Generator> generators) {
return generators.stream().collect(Collectors.toMap(Generator::getEnergySource, Generator::getTargetP, Double::sum));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,23 @@ public void check(Network network) throws NetworkModificationException {
modificationInfos.getRegulatingTerminalType().getValue(),
modificationInfos.getRegulatingTerminalVlId().getValue());
}
checkActivePowerZeroOrBetweenMinAndMaxActivePowerGenerator(modificationInfos, generator, MODIFY_GENERATOR_ERROR, errorMessage);
}
}

private void checkActivePowerZeroOrBetweenMinAndMaxActivePowerGenerator(GeneratorModificationInfos modificationInfos, Generator generator, NetworkModificationException.Type exceptionType, String errorMessage) {
ModificationUtils.getInstance().checkActivePowerZeroOrBetweenMinAndMaxActivePower(
modificationInfos.getActivePowerSetpoint(),
modificationInfos.getMinActivePower(),
modificationInfos.getMaxActivePower(),
generator.getMinP(),
generator.getMaxP(),
generator.getTargetP(),
exceptionType,
errorMessage
);
}

@Override
public void apply(Network network, Reporter subReporter) {
if (modificationInfos == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,44 +780,53 @@ public void modifyMinMaxReactiveLimits(MinMaxReactiveLimits minMaxReactiveLimits
reportModifications(subReporterReactiveLimits, reports, "minMaxReactiveLimitsModified", "By range");
}

private void modifyExistingActivePowerControl(ActivePowerControl<?> activePowerControl,
AttributeModification<Boolean> participateInfo,
AttributeModification<Float> droopInfo,
List<Report> reports) {
double oldDroop = activePowerControl.getDroop();
boolean oldParticipate = activePowerControl.isParticipate();

Optional.ofNullable(participateInfo).ifPresent(info -> {
activePowerControl.setParticipate(info.getValue());
reports.add(buildModificationReport(oldParticipate, info.getValue(), "Participate"));
});

Optional.ofNullable(droopInfo).ifPresent(info -> {
activePowerControl.setDroop(info.getValue());
reports.add(buildModificationReport(oldDroop, info.getValue(), "Droop"));
});
}

private void createNewActivePowerControl(ActivePowerControlAdder<?> adder,
AttributeModification<Boolean> participateInfo,
AttributeModification<Float> droopInfo,
List<Report> reports) {
boolean participate = participateInfo != null ? participateInfo.getValue() : false;
adder.withParticipate(participate);
if (participateInfo != null) {
reports.add(buildModificationReport(null, participate, "Participate"));
}
double droop = droopInfo != null ? droopInfo.getValue() : Double.NaN;
adder.withDroop(droop);
if (droopInfo != null) {
reports.add(buildModificationReport(Double.NaN, droop, "Droop"));
}
adder.add();
}

public Reporter modifyActivePowerControlAttributes(ActivePowerControl<?> activePowerControl,
ActivePowerControlAdder<?> activePowerControlAdder,
AttributeModification<Boolean> participateInfo,
AttributeModification<Float> droopInfo,
Reporter subReporter,
Reporter subReporterSetpoints) {
List<Report> reports = new ArrayList<>();
double oldDroop = Double.NaN;
boolean oldParticipate = false;
double droop = droopInfo != null ? droopInfo.getValue() : Double.NaN;
if (activePowerControl != null) {
oldDroop = activePowerControl.getDroop();
oldParticipate = activePowerControl.isParticipate();
}

if (participateInfo != null) {
activePowerControlAdder
.withParticipate(participateInfo.getValue());
reports.add(ModificationUtils.getInstance().buildModificationReport(activePowerControl != null ? activePowerControl.isParticipate() : null,
participateInfo.getValue(),
"Participate"));
} else {
activePowerControlAdder
.withParticipate(oldParticipate);
}

if (droopInfo != null) {
activePowerControlAdder
.withDroop(droop);
reports.add(ModificationUtils.getInstance().buildModificationReport(oldDroop,
droop,
"Droop"));
modifyExistingActivePowerControl(activePowerControl, participateInfo, droopInfo, reports);
} else {
activePowerControlAdder
.withDroop(oldDroop);
createNewActivePowerControl(activePowerControlAdder, participateInfo, droopInfo, reports);
}
activePowerControlAdder
.add();

Reporter subReporterSetpoints2 = subReporterSetpoints;
if (subReporterSetpoints == null && !reports.isEmpty()) {
Expand Down Expand Up @@ -862,6 +871,16 @@ public void checkMaxReactivePowerGreaterThanMinReactivePower(MinMaxReactiveLimit
}
}

public void checkActivePowerZeroOrBetweenMinAndMaxActivePower(AttributeModification<Double> activePowerInfos, AttributeModification<Double> minActivePowerInfos, AttributeModification<Double> maxActivePowerInfos, Double previousMinActivePower, Double previousMaxActivePower, Double previousActivePower, NetworkModificationException.Type exceptionType, String errorMessage) {
Double minActivePower = minActivePowerInfos != null ? minActivePowerInfos.getValue() : previousMinActivePower;
Double maxActivePower = maxActivePowerInfos != null ? maxActivePowerInfos.getValue() : previousMaxActivePower;
Double activePower = activePowerInfos != null ? activePowerInfos.getValue() : previousActivePower;

if (activePower != 0 && (activePower < minActivePower || activePower > maxActivePower)) {
throw new NetworkModificationException(exceptionType, errorMessage + "Active power " + activePower + " is expected to be equal to 0 or within the range of minimum active power and maximum active power: [" + minActivePower + ", " + maxActivePower + "]");
}
}

private NetworkModificationException makeEquipmentException(NetworkModificationException.Type errorType,
String equipmentId,
String equipmentName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package org.gridsuite.modification.server.modifications;

import com.google.common.collect.Iterables;
import com.powsybl.iidm.network.*;
import com.powsybl.network.store.client.NetworkStoreService;
import lombok.Setter;
Expand Down Expand Up @@ -40,6 +41,8 @@ public class NetworkStoreListener implements NetworkListener {

private final List<EquipmentInfos> createdEquipments = new ArrayList<>();

private final List<EquipmentInfos> modifiedEquipments = new ArrayList<>();

private final Set<SimpleElementImpact> networkImpacts = new LinkedHashSet<>();

// TODO : Move to the NetworkModificationApplicator class
Expand Down Expand Up @@ -92,18 +95,6 @@ public Network getNetwork() {
return network;
}

@Override
public void onUpdate(Identifiable identifiable, String attribute, Object oldValue, Object newValue) {
networkImpacts.add(
SimpleElementImpact.builder()
.impactType(SimpleElementImpact.SimpleImpactType.MODIFICATION)
.elementType(identifiable.getType())
.elementId(identifiable.getId())
.substationIds(getSubstationIds(identifiable))
.build()
);
}

private void addSimpleModificationImpact(Identifiable<?> identifiable) {
networkImpacts.add(
SimpleElementImpact.builder()
Expand All @@ -130,9 +121,66 @@ public void onElementReplaced(Identifiable identifiable, String attribute, Objec
addSimpleModificationImpact(identifiable);
}

@Override
public void onUpdate(Identifiable identifiable, String attribute, Object oldValue, Object newValue) {
addSimpleModificationImpact(identifiable);
updateEquipmentIndexation(identifiable, attribute, networkUuid, network.getVariantManager().getWorkingVariantId());
}

@Override
public void onUpdate(Identifiable identifiable, String attribute, String variantId, Object oldValue, Object newValue) {
addSimpleModificationImpact(identifiable);
updateEquipmentIndexation(identifiable, attribute, networkUuid, network.getVariantManager().getWorkingVariantId());
}

private void updateEquipmentIndexation(Identifiable<?> identifiable, String attribute, UUID networkUuid, String variantId) {
modifiedEquipments.add(toEquipmentInfos(identifiable, networkUuid, variantId));

// because all each equipment carry its linked voltage levels/substations name within its document
// if attribute is "name" and identifiable type is VOLTAGE_LEVEL or SUBSTATION, we need to update all equipments linked to it
if (attribute.equals("name") && (identifiable.getType().equals(IdentifiableType.VOLTAGE_LEVEL) || identifiable.getType().equals(IdentifiableType.SUBSTATION))) {
updateLinkedEquipments(identifiable);
}
}

private void updateLinkedEquipments(Identifiable<?> identifiable) {
if (identifiable.getType().equals(IdentifiableType.VOLTAGE_LEVEL)) {
VoltageLevel updatedVoltageLevel = network.getVoltageLevel(identifiable.getId());
// update all equipments linked to voltageLevel
updateEquipmentsLinkedToVoltageLevel(updatedVoltageLevel);
// update substation linked to voltageLevel
Optional<Substation> linkedSubstation = updatedVoltageLevel.getSubstation();
if (linkedSubstation.isPresent()) {
modifiedEquipments.add(toEquipmentInfos(linkedSubstation.get(), networkUuid, network.getVariantManager().getWorkingVariantId()));
}
} else if (identifiable.getType().equals(IdentifiableType.SUBSTATION)) {
Substation updatedSubstation = network.getSubstation(identifiable.getId());
updateEquipmentsLinkedToSubstation(updatedSubstation);
}
}

private void updateEquipmentsLinkedToSubstation(Substation substation) {
Iterable<VoltageLevel> linkedVoltageLevels = substation.getVoltageLevels();
// update all voltageLevels linked to substation
linkedVoltageLevels.forEach(vl -> modifiedEquipments.add(toEquipmentInfos(vl, networkUuid, network.getVariantManager().getWorkingVariantId())));
// update all equipments linked to each of the voltageLevels
linkedVoltageLevels.forEach(vl ->
Iterables.concat(
vl.getConnectables(),
vl.getSwitches()
).forEach(c ->
modifiedEquipments.add(toEquipmentInfos(c, networkUuid, network.getVariantManager().getWorkingVariantId()))
)
);
}

private void updateEquipmentsLinkedToVoltageLevel(VoltageLevel voltageLevel) {
Iterables.concat(
voltageLevel.getConnectables(),
voltageLevel.getSwitches()
).forEach(c ->
modifiedEquipments.add(toEquipmentInfos(c, networkUuid, network.getVariantManager().getWorkingVariantId()))
);
}

@Override
Expand Down Expand Up @@ -192,6 +240,18 @@ public NetworkModificationResult flushNetworkModifications() {
.build();
}

private static EquipmentInfos toEquipmentInfos(Identifiable<?> identifiable, UUID networkUuid, String variantId) {
return EquipmentInfos.builder()
.networkUuid(networkUuid)
.variantId(variantId)
.id(identifiable.getId())
.name(identifiable.getNameOrId())
.type(identifiable.getType().name())
.voltageLevels(EquipmentInfos.getVoltageLevelsInfos(identifiable))
.substations(EquipmentInfos.getSubstationsInfos(identifiable))
.build();
}

private void flushEquipmentInfos() {
String variantId = network.getVariantManager().getWorkingVariantId();
Set<String> presentEquipmentDeletionsIds = equipmentInfosService.findEquipmentInfosList(deletedEquipmentsIds, networkUuid, variantId).stream().map(EquipmentInfos::getId).collect(Collectors.toSet());
Expand All @@ -213,5 +273,6 @@ private void flushEquipmentInfos() {
equipmentInfosService.deleteEquipmentInfosList(equipmentDeletionsIds, networkUuid, variantId);
equipmentInfosService.addAllTombstonedEquipmentInfos(tombstonedEquipmentInfos);
equipmentInfosService.addAllEquipmentInfos(createdEquipments);
equipmentInfosService.addAllEquipmentInfos(modifiedEquipments);
}
}
Loading

0 comments on commit b74ab50

Please sign in to comment.