Skip to content

Commit

Permalink
Mcs tabular modifications (#409)
Browse files Browse the repository at this point in the history
Signed-off-by: David SARTORI <david.sartori_externe@rte-france.com>
  • Loading branch information
ne0ds authored Jan 9, 2024
1 parent 0c2950a commit ea3c03c
Show file tree
Hide file tree
Showing 9 changed files with 297 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
@ModificationErrorTypeName("MODIFY_SHUNT_COMPENSATOR_ERROR")
public class ShuntCompensatorModificationInfos extends BasicEquipmentModificationInfos {

@Schema(description = "voltage level id")
private String voltageLevelId;

@Schema(description = "Maximum number of sections")
private AttributeModification<Integer> maximumSectionCount;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@
import java.util.stream.Collectors;

import org.gridsuite.modification.server.dto.*;
import org.gridsuite.modification.server.entities.equipment.modification.*;
import org.gridsuite.modification.server.entities.equipment.modification.BatteryModificationEntity;
import org.gridsuite.modification.server.entities.equipment.modification.GeneratorModificationEntity;
import org.gridsuite.modification.server.entities.equipment.modification.LineModificationEntity;
import org.gridsuite.modification.server.entities.equipment.modification.LoadModificationEntity;
import org.gridsuite.modification.server.entities.equipment.modification.SubstationModificationEntity;
import org.gridsuite.modification.server.entities.equipment.modification.TwoWindingsTransformerModificationEntity;
import org.gridsuite.modification.server.entities.equipment.modification.ShuntCompensatorModificationEntity;
import org.gridsuite.modification.server.entities.equipment.modification.VoltageLevelModificationEntity;

/**
* @author Etienne Homer <etienne.homer at rte-france.com>
Expand Down Expand Up @@ -54,6 +61,9 @@ public TabularModificationEntity(TabularModificationInfos tabularModificationInf
case "VOLTAGE_LEVEL_MODIFICATION":
modifications = tabularModificationInfos.getModifications().stream().map(voltageLevelModificationInfos -> new VoltageLevelModificationEntity((VoltageLevelModificationInfos) voltageLevelModificationInfos)).collect(Collectors.toList());
break;
case "SHUNT_COMPENSATOR_MODIFICATION":
modifications = tabularModificationInfos.getModifications().stream().map(shuntCompensatorModificationInfos -> new ShuntCompensatorModificationEntity((ShuntCompensatorModificationInfos) shuntCompensatorModificationInfos)).collect(Collectors.toList());
break;
case "LINE_MODIFICATION":
modifications = tabularModificationInfos.getModifications().stream().map(lineModificationInfos -> new LineModificationEntity((LineModificationInfos) lineModificationInfos)).collect(Collectors.toList());
break;
Expand Down Expand Up @@ -99,6 +109,9 @@ public void update(@NonNull ModificationInfos modificationInfos) {
case "VOLTAGE_LEVEL_MODIFICATION":
modifications.addAll(tabularModificationInfos.getModifications().stream().map(voltageLevelModificationInfos -> new VoltageLevelModificationEntity((VoltageLevelModificationInfos) voltageLevelModificationInfos)).collect(Collectors.toList()));
break;
case "SHUNT_COMPENSATOR_MODIFICATION":
modifications.addAll(tabularModificationInfos.getModifications().stream().map(shuntCompensatorModificationInfos -> new ShuntCompensatorModificationEntity((ShuntCompensatorModificationInfos) shuntCompensatorModificationInfos)).toList());
break;
case "LINE_MODIFICATION":
modifications.addAll(tabularModificationInfos.getModifications().stream().map(lineModificationInfos -> new LineModificationEntity((LineModificationInfos) lineModificationInfos)).collect(Collectors.toList()));
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
@Entity
@Table(name = "shuntCompensatorModification")
public class ShuntCompensatorModificationEntity extends BasicEquipmentModificationEntity {
@Column(name = "voltageLevelId")
private String voltageLevelId;

@Embedded
@AttributeOverrides(value = {
Expand Down Expand Up @@ -85,7 +83,6 @@ public void update(@NonNull ModificationInfos modificationInfos) {
}

private void assignAttributes(ShuntCompensatorModificationInfos shuntCompensatorModificationInfos) {
this.voltageLevelId = shuntCompensatorModificationInfos.getVoltageLevelId();
this.maximumSectionCount = new IntegerModificationEmbedded(shuntCompensatorModificationInfos.getMaximumSectionCount());
this.sectionCount = new IntegerModificationEmbedded(shuntCompensatorModificationInfos.getSectionCount());
this.maxQAtNominalV = new DoubleModificationEmbedded(shuntCompensatorModificationInfos.getMaxQAtNominalV());
Expand All @@ -104,7 +101,6 @@ public ShuntCompensatorModificationInfos toModificationInfos() {
.uuid(getId())
.date(getDate())
.stashed(getStashed())
.voltageLevelId(getVoltageLevelId())
.equipmentId(getEquipmentId())
.equipmentName(toAttributeModification(getEquipmentNameValue(), getEquipmentNameOp()))
.shuntCompensatorType(toAttributeModification(getShuntCompensatorType()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import java.util.ArrayList;
import java.util.List;

import static org.gridsuite.modification.server.NetworkModificationException.Type.*;
import static org.gridsuite.modification.server.NetworkModificationException.Type.SHUNT_COMPENSATOR_NOT_FOUND;
import static org.gridsuite.modification.server.NetworkModificationException.Type.MODIFY_SHUNT_COMPENSATOR_ERROR;

/**
* @author Seddik Yengui <Seddik.yengui at rte-france.com>
Expand Down Expand Up @@ -60,19 +61,12 @@ public void check(Network network) throws NetworkModificationException {
if (sectionCount < 1 || maximumSectionCount < 1 || sectionCount > maximumSectionCount) {
throw new NetworkModificationException(MODIFY_SHUNT_COMPENSATOR_ERROR, String.format("Section count should be between 1 and Maximum section count (%d), actual : %d", maximumSectionCount, sectionCount));
}

VoltageLevel voltageLevel = network.getVoltageLevel(modificationInfos.getVoltageLevelId());
if (voltageLevel == null) {
throw new NetworkModificationException(VOLTAGE_LEVEL_NOT_FOUND,
String.format("Voltage level %s does not exist in network", modificationInfos.getVoltageLevelId()));
}

}

@Override
public void apply(Network network, Reporter subReporter) {
ShuntCompensator shuntCompensator = network.getShuntCompensator(modificationInfos.getEquipmentId());
VoltageLevel voltageLevel = network.getVoltageLevel(modificationInfos.getVoltageLevelId());
VoltageLevel voltageLevel = shuntCompensator.getTerminal().getVoltageLevel();

subReporter.report(Report.builder()
.withKey("shuntCompensatorModification")
Expand Down Expand Up @@ -118,6 +112,10 @@ private void applyModificationOnLinearModel(Reporter subReporter, ShuntCompensat
double oldSwitchedOnSusceptance = oldSusceptancePerSection * shuntCompensator.getSectionCount();
double oldSwitchedOnQAtNominalV = oldQAtNominalV * shuntCompensator.getSectionCount();

if (modificationInfos.getShuntCompensatorType() != null || modificationInfos.getMaxQAtNominalV() != null) {
modificationInfos.setMaxSusceptance(null);
}

// due to cross validation between maximum section count and section count, we need to modify section count first
// when maximum section count old value is greater than the new one
if (modificationInfos.getMaximumSectionCount() != null && modificationInfos.getMaximumSectionCount().getValue() < shuntCompensator.getMaximumSectionCount()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
import com.powsybl.commons.reporter.Reporter;
import com.powsybl.commons.reporter.TypedValue;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.ShuntCompensatorModelType;
import org.gridsuite.modification.server.NetworkModificationException;
import org.gridsuite.modification.server.dto.ShuntCompensatorModificationInfos;
import org.gridsuite.modification.server.dto.TabularModificationInfos;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.atomic.AtomicInteger;

import static org.gridsuite.modification.server.NetworkModificationException.Type.TABULAR_MODIFICATION_ERROR;

/**
Expand All @@ -44,62 +44,50 @@ public void check(Network network) throws NetworkModificationException {

@Override
public void apply(Network network, Reporter subReporter) {
AtomicInteger applicationFailuresCount = new AtomicInteger(0);
modificationInfos.getModifications().forEach(modifInfos -> {
int applicationFailuresCount = 0;
for (var modifInfos : modificationInfos.getModifications()) {
try {
AbstractModification modification = modifInfos.toModification();
modification.check(network);
if (modifInfos instanceof ShuntCompensatorModificationInfos shuntModification) {
checkShuntCompensatorModification(network, shuntModification, subReporter);
}
modification.apply(network);
} catch (PowsyblException e) {
applicationFailuresCount.incrementAndGet();
applicationFailuresCount++;
subReporter.report(Report.builder()
.withKey(modifInfos.getType().name() + applicationFailuresCount.get())
.withKey(modifInfos.getType().name() + applicationFailuresCount)
.withDefaultMessage(e.getMessage())
.withSeverity(TypedValue.WARN_SEVERITY)
.build());
LOGGER.warn(e.getMessage());
}
});
String defaultMessage = " have been modified";
switch (modificationInfos.getModificationType()) {
case "GENERATOR_MODIFICATION":
defaultMessage = "generators" + defaultMessage;
break;
case "LOAD_MODIFICATION":
defaultMessage = "loads" + defaultMessage;
break;
case "TWO_WINDINGS_TRANSFORMER_MODIFICATION":
defaultMessage = "two windings transformers" + defaultMessage;
break;
case "BATTERY_MODIFICATION":
defaultMessage = "batteries" + defaultMessage;
break;
case "VOLTAGE_LEVEL_MODIFICATION":
defaultMessage = "voltage levels" + defaultMessage;
break;
case "LINE_MODIFICATION":
defaultMessage = "lines" + defaultMessage;
break;
case "SUBSTATION_MODIFICATION":
defaultMessage = "substations" + defaultMessage;
break;
default:
defaultMessage = "equipments of unknown type" + defaultMessage;
break;
}
String defaultMessage = " have been modified";
defaultMessage = switch (modificationInfos.getModificationType()) {
case "GENERATOR_MODIFICATION" -> "generators" + defaultMessage;
case "LOAD_MODIFICATION" -> "loads" + defaultMessage;
case "TWO_WINDINGS_TRANSFORMER_MODIFICATION" -> "two windings transformers" + defaultMessage;
case "BATTERY_MODIFICATION" -> "batteries" + defaultMessage;
case "VOLTAGE_LEVEL_MODIFICATION" -> "voltage levels" + defaultMessage;
case "SHUNT_COMPENSATOR_MODIFICATION" -> "shunt compensator" + defaultMessage;
case "LINE_MODIFICATION" -> "lines" + defaultMessage;
case "SUBSTATION_MODIFICATION" -> "substations" + defaultMessage;
default -> "equipments of unknown type" + defaultMessage;
};

if (modificationInfos.getModifications().size() == applicationFailuresCount.get()) {
if (modificationInfos.getModifications().size() == applicationFailuresCount) {
subReporter.report(Report.builder()
.withKey(TABULAR_MODIFICATION_REPORT_KEY + "Error")
.withDefaultMessage("Tabular modification: No " + defaultMessage)
.withSeverity(TypedValue.ERROR_SEVERITY)
.build());
} else if (applicationFailuresCount.get() > 0) {
} else if (applicationFailuresCount > 0) {
subReporter.report(Report.builder()
.withKey(TABULAR_MODIFICATION_REPORT_KEY + "Warning")
.withDefaultMessage("Tabular modification: ${modificationsCount} " + defaultMessage + " and ${failuresCount} have not been modified")
.withValue("modificationsCount", modificationInfos.getModifications().size() - applicationFailuresCount.get())
.withValue("failuresCount", applicationFailuresCount.get())
.withValue("modificationsCount", modificationInfos.getModifications().size() - applicationFailuresCount)
.withValue("failuresCount", applicationFailuresCount)
.withSeverity(TypedValue.WARN_SEVERITY)
.build());
} else {
Expand All @@ -111,4 +99,42 @@ public void apply(Network network, Reporter subReporter) {
.build());
}
}

public void checkShuntCompensatorModification(
Network network,
ShuntCompensatorModificationInfos shuntCompensatorModificationInfos,
Reporter subReporter
) {
var shuntCompensator = network.getShuntCompensator(shuntCompensatorModificationInfos.getEquipmentId());
if (shuntCompensator.getModelType() == ShuntCompensatorModelType.NON_LINEAR) {
subReporter.report(Report.builder()
.withKey(shuntCompensator.getId())
.withDefaultMessage("Tabular modification: It is currently not possible to modify non-linear shunt compensator with id " + shuntCompensator.getId())
.withSeverity(TypedValue.ERROR_SEVERITY)
.build());
} else if (shuntCompensatorModificationInfos.getMaxSusceptance() != null) {
if (shuntCompensatorModificationInfos.getShuntCompensatorType() != null && shuntCompensatorModificationInfos.getMaxQAtNominalV() != null) {
subReporter.report(Report.builder()
.withKey(shuntCompensator.getId())
.withDefaultMessage("Tabular modification: Input for maximum susceptance has been ignored since it is not possible to simultaneously update type, maximum reactive power and maximum susceptance for shunt compensator with id "
+ shuntCompensator.getId())
.withSeverity(TypedValue.WARN_SEVERITY)
.build());
} else if (shuntCompensatorModificationInfos.getShuntCompensatorType() != null) {
subReporter.report(Report.builder()
.withKey(shuntCompensator.getId())
.withDefaultMessage("Tabular modification: Input for maximum susceptance has been ignored since it is not possible to simultaneously update type and maximum susceptance for shunt compensator with id "
+ shuntCompensator.getId())
.withSeverity(TypedValue.WARN_SEVERITY)
.build());
} else if (shuntCompensatorModificationInfos.getMaxQAtNominalV() != null) {
subReporter.report(Report.builder()
.withKey(shuntCompensator.getId())
.withDefaultMessage("Tabular modification: Input for maximum susceptance has been ignored since it is not possible to simultaneously update maximum reactive power and maximum susceptance for shunt compensator with id "
+ shuntCompensator.getId())
.withSeverity(TypedValue.WARN_SEVERITY)
.build());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
<changeSet author="sartoridav (generated)" id="1703773513578-46">
<dropColumn columnName="VOLTAGE_LEVEL_ID" tableName="SHUNT_COMPENSATOR_MODIFICATION"/>
</changeSet>
</databaseChangeLog>
5 changes: 4 additions & 1 deletion src/main/resources/db/changelog/db.changelog-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,7 @@ databaseChangeLog:
relativeToChangelogFile: true
- include:
file: changesets/changelog_20231214T162501Z.xml
relativeToChangelogFile: true
relativeToChangelogFile: true
- include:
file: changesets/changelog_20231228T142443Z.xml
relativeToChangelogFile: true
Loading

0 comments on commit ea3c03c

Please sign in to comment.