Skip to content

Commit

Permalink
Merge branch 'main' into reactive_limits_refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Seddik Yengui committed Sep 20, 2023
2 parents 5320747 + 1f9f70e commit 4a490f3
Show file tree
Hide file tree
Showing 14 changed files with 464 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,13 @@ public ResponseEntity<Optional<NetworkModificationResult>> duplicateModification
@Parameter(description = "origin group UUID, from where modifications are copied") @RequestParam(value = "duplicateFrom") UUID originGroupUuid) {
return ResponseEntity.ok().body(networkModificationService.duplicateModificationsInGroup(targetGroupUuid, networkUuid, variantId, new ReportInfos(reportUuid, reporterId.toString()), originGroupUuid));
}

@DeleteMapping(value = "/groups/{groupUuid}/stashed-modifications")
@Operation(summary = "Delete the stashed modifications in a group")
@ApiResponse(responseCode = "200", description = "Stashed modifications in the group deleted")
public ResponseEntity<Void> deleteStashedModificationInGroup(@Parameter(description = "Group UUID") @PathVariable("groupUuid") UUID groupUuid,
@Parameter(description = "Return 404 if group is not found") @RequestParam(name = "errorOnGroupNotFound", required = false, defaultValue = "true") Boolean errorOnGroupNotFound) {
networkModificationService.deleteStashedModificationInGroup(groupUuid, errorOnGroupNotFound);
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public class VoltageInitModificationInfos extends ModificationInfos {
@Schema(description = "vsc converter station modifications")
private List<VoltageInitVscConverterStationModificationInfos> vscConverterStations;

@Schema(description = "shunt compensator modifications")
private List<VoltageInitShuntCompensatorModificationInfos> shuntCompensators;

@Override
public ModificationEntity toEntity() {
return new VoltageInitModificationEntity(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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 io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

/**
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
*/
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Schema(description = "Voltage init shunt compensator modification infos")
public class VoltageInitShuntCompensatorModificationInfos {
@Schema(description = "Shunt compensator id")
private String shuntCompensatorId;

@Schema(description = "Section count")
private Integer sectionCount;

@Schema(description = "Connexion")
private Boolean connect;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.gridsuite.modification.server.dto.VoltageInitGeneratorModificationInfos;
import org.gridsuite.modification.server.dto.VoltageInitModificationInfos;
import org.gridsuite.modification.server.dto.ModificationInfos;
import org.gridsuite.modification.server.dto.VoltageInitShuntCompensatorModificationInfos;
import org.gridsuite.modification.server.dto.VoltageInitStaticVarCompensatorModificationInfos;
import org.gridsuite.modification.server.dto.VoltageInitTransformerModificationInfos;
import org.gridsuite.modification.server.dto.VoltageInitVscConverterStationModificationInfos;
Expand Down Expand Up @@ -61,6 +62,12 @@ public class VoltageInitModificationEntity extends ModificationEntity {
foreignKey = @ForeignKey(name = "VoltageInitModificationEntity_vsc_converter_stations_fk1"))
private List<VoltageInitVscConverterStationModificationEmbeddable> vscConverterStations;

@ElementCollection
@CollectionTable(name = "voltageInitShuntCompensatorsModification",
indexes = {@Index(name = "VoltageInitModificationEntity_shunt_compensators_idx1", columnList = "voltage_init_modification_entity_id")},
foreignKey = @ForeignKey(name = "VoltageInitModificationEntity_shunt_compensators_fk1"))
private List<VoltageInitShuntCompensatorModificationEmbeddable> shuntCompensators;

public VoltageInitModificationEntity(VoltageInitModificationInfos voltageInitModificationInfos) {
super(voltageInitModificationInfos);
assignAttributes(voltageInitModificationInfos);
Expand All @@ -77,6 +84,7 @@ private void assignAttributes(VoltageInitModificationInfos voltageInitModificati
transformers = toEmbeddableVoltageInitTransformers(voltageInitModificationInfos.getTransformers());
staticVarCompensators = toEmbeddableVoltageInitStaticVarCompensators(voltageInitModificationInfos.getStaticVarCompensators());
vscConverterStations = toEmbeddableVoltageInitVscConverterStations(voltageInitModificationInfos.getVscConverterStations());
shuntCompensators = toEmbeddableVoltageInitShuntCompensators(voltageInitModificationInfos.getShuntCompensators());
}

public static List<VoltageInitGeneratorModificationEmbeddable> toEmbeddableVoltageInitGenerators(List<VoltageInitGeneratorModificationInfos> generators) {
Expand Down Expand Up @@ -131,6 +139,19 @@ private List<VoltageInitVscConverterStationModificationInfos> toVscConverterStat
.collect(Collectors.toList()) : null;
}

public static List<VoltageInitShuntCompensatorModificationEmbeddable> toEmbeddableVoltageInitShuntCompensators(List<VoltageInitShuntCompensatorModificationInfos> shuntCompensators) {
return shuntCompensators == null ? null : shuntCompensators.stream()
.map(shuntCompensator -> new VoltageInitShuntCompensatorModificationEmbeddable(shuntCompensator.getShuntCompensatorId(), shuntCompensator.getSectionCount(), shuntCompensator.getConnect()))
.collect(Collectors.toList());
}

private List<VoltageInitShuntCompensatorModificationInfos> toShuntCompensatorsModification(List<VoltageInitShuntCompensatorModificationEmbeddable> shuntCompensators) {
return shuntCompensators != null ? shuntCompensators
.stream()
.map(shuntCompensator -> new VoltageInitShuntCompensatorModificationInfos(shuntCompensator.getShuntCompensatorId(), shuntCompensator.getSectionCount(), shuntCompensator.getConnect()))
.collect(Collectors.toList()) : null;
}

@Override
public VoltageInitModificationInfos toModificationInfos() {
return VoltageInitModificationInfos.builder()
Expand All @@ -140,6 +161,7 @@ public VoltageInitModificationInfos toModificationInfos() {
.transformers(toTransformersModification(transformers))
.staticVarCompensators(toStaticVarCompensatorsModification(staticVarCompensators))
.vscConverterStations(toVscConverterStationsModification(vscConverterStations))
.shuntCompensators(toShuntCompensatorsModification(shuntCompensators))
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* 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.entities.equipment.modification;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.Embeddable;

/**
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
*/

@NoArgsConstructor
@AllArgsConstructor
@Getter
@Embeddable
public class VoltageInitShuntCompensatorModificationEmbeddable {
@Column
private String shuntCompensatorId;

@Column
private Integer sectionCount;

@Column
private Boolean connect;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
import com.powsybl.commons.reporter.TypedValue;
import com.powsybl.iidm.network.Generator;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.ShuntCompensator;
import com.powsybl.iidm.network.StaticVarCompensator;
import com.powsybl.iidm.network.Terminal;
import com.powsybl.iidm.network.ThreeWindingsTransformer;
import com.powsybl.iidm.network.TwoWindingsTransformer;
import com.powsybl.iidm.network.VscConverterStation;
import org.gridsuite.modification.server.NetworkModificationException;
import org.gridsuite.modification.server.dto.VoltageInitModificationInfos;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static org.gridsuite.modification.server.NetworkModificationException.Type.VOLTAGE_INIT_MODIFICATION_ERROR;
Expand All @@ -38,6 +42,11 @@ public class VoltageInitModification extends AbstractModification {
private static final String VSC_CONVERTER_STATION_MSG = "Vsc converter station ";
private static final String VOLTAGE_SET_POINT = "Voltage set point";
private static final String REACTIVE_POWER_SET_POINT = "Reactive power set point";
private static final String SHUNT_COMPENSATOR_MSG = "Shunt compensator ";
private static final String SECTION_COUNT = "Section count";
private static final String SHUNT_SECTION_COUNT_VALUE_IGNORED_KEY = "shuntCompensatorSectionCountValueIgnored";
private static final String SHUNT_SECTION_COUNT_VALUE_CANNOT_BE_APPLIED = "Section count value ${value} cannot be applied : it should be 0 or 1";
private static final String VALUE = "value";

public VoltageInitModification(VoltageInitModificationInfos voltageInitModificationInfos) {
this.voltageInitModificationInfos = voltageInitModificationInfos;
Expand All @@ -51,14 +60,19 @@ public void check(Network network) throws NetworkModificationException {
}

private void report(Reporter reporter, String key, String defaultMessage, Map<String, Object> values, TypedValue severity) {
Report report = createReport(key, defaultMessage, values, severity, 0);
reporter.report(report);
}

private Report createReport(String key, String defaultMessage, Map<String, Object> values, TypedValue severity, int indentationLevel) {
ReportBuilder builder = Report.builder()
.withKey(key)
.withDefaultMessage(defaultMessage)
.withDefaultMessage(" ".repeat(indentationLevel * 4) + defaultMessage)
.withSeverity(severity);
for (Map.Entry<String, Object> valueEntry : values.entrySet()) {
builder.withValue(valueEntry.getKey(), valueEntry.getValue().toString());
}
reporter.report(builder.build());
return builder.build();
}

private void applyGeneratorModification(Network network, Reporter subReporter) {
Expand Down Expand Up @@ -185,6 +199,65 @@ private void applyVscConverterStationModification(Network network, Reporter subR
});
}

private void applyShuntCompensatorModification(Network network, Reporter subReporter) {
voltageInitModificationInfos.getShuntCompensators().forEach(m -> {
ShuntCompensator shuntCompensator = network.getShuntCompensator(m.getShuntCompensatorId());
if (shuntCompensator == null) {
Reporter reporter = subReporter.createSubReporter(SHUNT_COMPENSATOR_MSG + m.getShuntCompensatorId(), SHUNT_COMPENSATOR_MSG + m.getShuntCompensatorId());
report(reporter, "shuntCompensatorNotFound", "Shunt compensator with id=${id} not found", Map.of("id", m.getShuntCompensatorId()), TypedValue.WARN_SEVERITY);
return;
}
if (m.getSectionCount() != null || m.getConnect() != null) {
List<Report> reports = new ArrayList<>();

int currentSectionCount = shuntCompensator.getSectionCount();

Terminal shuntCompensatorTerminal = shuntCompensator.getTerminal();
if (shuntCompensatorTerminal.isConnected()) { // shunt compensator is connected
if (m.getSectionCount() == null) {
reports.add(createReport("shuntCompensatorSectionCountUndefined", "Section count value is undefined", Map.of(), TypedValue.WARN_SEVERITY, 1));
} else if (m.getSectionCount() > 1) {
reports.add(createReport(SHUNT_SECTION_COUNT_VALUE_IGNORED_KEY, SHUNT_SECTION_COUNT_VALUE_CANNOT_BE_APPLIED, Map.of(VALUE, m.getSectionCount()), TypedValue.WARN_SEVERITY, 1));
} else if (currentSectionCount > 1) {
reports.add(createReport("shuntCompensatorCurrentSectionCountValueIgnored", "Current section count value ${value} should be 0 or 1", Map.of(VALUE, currentSectionCount), TypedValue.WARN_SEVERITY, 1));
} else {
if (m.getSectionCount() == 0) {
shuntCompensatorTerminal.disconnect();
reports.add(createReport("shuntCompensatorDisconnected", "Shunt compensator disconnected", Map.of(), TypedValue.INFO_SEVERITY, 1));
}
if (m.getSectionCount() != currentSectionCount) {
shuntCompensator.setSectionCount(m.getSectionCount());
reports.add(ModificationUtils.getInstance().buildModificationReportWithIndentation(currentSectionCount, m.getSectionCount(), SECTION_COUNT, 1));
}
}
} else { // shunt compensator is disconnected
if (m.getConnect() == null) {
reports.add(createReport("shuntCompensatorConnectUndefined", "Connect value is undefined", Map.of(), TypedValue.WARN_SEVERITY, 1));
} else if (m.getSectionCount() > 1) {
reports.add(createReport(SHUNT_SECTION_COUNT_VALUE_IGNORED_KEY, SHUNT_SECTION_COUNT_VALUE_CANNOT_BE_APPLIED, Map.of(VALUE, m.getSectionCount()), TypedValue.WARN_SEVERITY, 1));
} else if (currentSectionCount > 1) {
reports.add(createReport("shuntCompensatorCurrentSectionCountValueIgnored", "Current section count value ${value} should be 0 or 1", Map.of(VALUE, currentSectionCount), TypedValue.WARN_SEVERITY, 1));
} else {
if (Boolean.TRUE.equals(m.getConnect()) && m.getSectionCount() == 1) {
shuntCompensatorTerminal.connect();
reports.add(createReport("shuntCompensatorReconnected", "Shunt compensator reconnected", Map.of(), TypedValue.INFO_SEVERITY, 1));
}
if (m.getSectionCount() != currentSectionCount) {
shuntCompensator.setSectionCount(m.getSectionCount());
reports.add(ModificationUtils.getInstance().buildModificationReportWithIndentation(currentSectionCount, m.getSectionCount(), SECTION_COUNT, 1));
}
}
}

if (!reports.isEmpty()) {
Reporter reporter = subReporter.createSubReporter(SHUNT_COMPENSATOR_MSG + m.getShuntCompensatorId(), SHUNT_COMPENSATOR_MSG + m.getShuntCompensatorId());
report(reporter, "shuntCompensatorModification", "Shunt compensator with id=${id} modified :", Map.of("id", m.getShuntCompensatorId()), TypedValue.INFO_SEVERITY);
reports.forEach(reporter::report);
}
}
});
}

@Override
public void apply(Network network, Reporter subReporter) {
// apply generators modifications
Expand All @@ -198,5 +271,8 @@ public void apply(Network network, Reporter subReporter) {

// apply vsc converter stations modifications
applyVscConverterStationModification(network, subReporter);

// apply shunt compensators modifications
applyShuntCompensatorModification(network, subReporter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,21 @@ public void updateModification(@NonNull UUID modificationUuid, @NonNull Modifica
.orElseThrow(() -> new NetworkModificationException(MODIFICATION_NOT_FOUND, String.format(MODIFICATION_NOT_FOUND_MESSAGE, modificationUuid)))
.update(modificationInfos);
}

@Transactional
public void deleteStashedModificationInGroup(UUID groupUuid, boolean errorOnGroupNotFound) {
try {
ModificationGroupEntity groupEntity = getModificationGroup(groupUuid);
if (!groupEntity.getModifications().isEmpty()) {
List<UUID> stashedModifications = groupEntity.getModifications().stream()
.filter(ModificationEntity::getStashed).map(ModificationEntity::getId).collect(Collectors.toList());
deleteModifications(groupUuid, stashedModifications);
}
} catch (NetworkModificationException e) {
if (e.getType() == MODIFICATION_GROUP_NOT_FOUND && !errorOnGroupNotFound) {
return;
}
throw e;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,8 @@ public Optional<NetworkModificationResult> duplicateModificationsInGroup(UUID ta
List<ModificationEntity> duplicatedModificationsEntities = networkModificationRepository.copyModificationsEntities(originGroupUuid);
return saveAndApplyModifications(targetGroupUuid, networkUuid, variantId, reportInfos, duplicatedModificationsEntities);
}

public void deleteStashedModificationInGroup(UUID groupUuid, boolean errorOnGroupNotFound) {
networkModificationRepository.deleteStashedModificationInGroup(groupUuid, errorOnGroupNotFound);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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-4.1.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd">
<changeSet author="lecuyerfra (generated)" id="1694089088065-7">
<createTable tableName="voltage_init_shunt_compensators_modification">
<column name="voltage_init_modification_entity_id" type="UUID">
<constraints nullable="false"/>
</column>
<column name="connect" type="BOOLEAN"/>
<column name="section_count" type="INT"/>
<column name="shunt_compensator_id" type="VARCHAR(255)"/>
</createTable>
</changeSet>
<changeSet author="lecuyerfra (generated)" id="1694089088065-9">
<createIndex indexName="VoltageInitModificationEntity_shunt_compensators_idx1" tableName="voltage_init_shunt_compensators_modification">
<column name="voltage_init_modification_entity_id"/>
</createIndex>
</changeSet>
<changeSet author="lecuyerfra (generated)" id="1694089088065-10">
<addForeignKeyConstraint baseColumnNames="voltage_init_modification_entity_id" baseTableName="voltage_init_shunt_compensators_modification" constraintName="VoltageInitModificationEntity_shunt_compensators_fk1" deferrable="false" initiallyDeferred="false" referencedColumnNames="id" referencedTableName="voltage_init_modification" validate="true"/>
</changeSet>
</databaseChangeLog>
3 changes: 3 additions & 0 deletions src/main/resources/db/changelog/db.changelog-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,7 @@ databaseChangeLog:
relativeToChangelogFile: true
- include:
file: changesets/changelog_20230816T150718Z.xml
relativeToChangelogFile: true
- include:
file: changesets/changelog_20230907T121742Z.xml
relativeToChangelogFile: true
Loading

0 comments on commit 4a490f3

Please sign in to comment.