Skip to content

Commit

Permalink
Add the shunt compensators modifications in the voltage init modifica…
Browse files Browse the repository at this point in the history
…tion (#324)

* Add the shunt compensators modifications in the voltage init modification

Signed-off-by: Franck LECUYER <[email protected]>
  • Loading branch information
FranckLecuyer authored Sep 19, 2023
1 parent 68f6a21 commit 1e81bc8
Show file tree
Hide file tree
Showing 11 changed files with 408 additions and 6 deletions.
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
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,22 @@ public void testCreateVoltageInitModification() throws Exception {
.vscConverterStationId("VSC2")
.voltageSetpoint(224.)
.build()))
.shuntCompensators(List.of(
VoltageInitShuntCompensatorModificationInfos.builder()
.shuntCompensatorId("v2shunt")
.sectionCount(1)
.connect(true)
.build(),
VoltageInitShuntCompensatorModificationInfos.builder()
.shuntCompensatorId("v5shunt")
.sectionCount(0)
.connect(false)
.build(),
VoltageInitShuntCompensatorModificationInfos.builder()
.shuntCompensatorId("v6shunt")
.sectionCount(1)
.connect(false)
.build()))
.build();

MvcResult mvcResult = mockMvc.perform(post("/v1/groups/modification")
Expand Down
Loading

0 comments on commit 1e81bc8

Please sign in to comment.