Skip to content

Commit

Permalink
Use voltageLevelId to improve getBus() lookup time (#496)
Browse files Browse the repository at this point in the history
* Optimization by using voltage level id in bus modifications.
* Change preloading strategy for voltage init modifications.
* Deal with existing modifications in database.

Signed-off-by: Franck LECUYER <[email protected]>
  • Loading branch information
antoinebhs authored Jul 10, 2024
1 parent c7895ad commit 6928386
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public enum ModificationType {
DELETE_VOLTAGE_LEVEL_ON_LINE(PreloadingStrategy.NONE),
DELETE_ATTACHING_LINE(PreloadingStrategy.NONE),
GENERATION_DISPATCH(PreloadingStrategy.COLLECTION),
VOLTAGE_INIT_MODIFICATION(PreloadingStrategy.COLLECTION),
VOLTAGE_INIT_MODIFICATION(PreloadingStrategy.ALL_COLLECTIONS_NEEDED_FOR_BUS_VIEW),
VSC_CREATION(PreloadingStrategy.NONE),
VSC_MODIFICATION(PreloadingStrategy.NONE),
CONVERTER_STATION_CREATION(PreloadingStrategy.NONE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
@Setter
@Schema(description = "Voltage init bus modfication infos")
public class VoltageInitBusModificationInfos {
@Schema(description = "Voltage level id")
private String voltageLevelId;

@Schema(description = "Bus id")
private String busId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
@Getter
@Embeddable
public class VoltageInitBusModificationEmbeddable {
@Column
private String voltageLevelId;

@Column
private String busId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,14 @@ private List<VoltageInitShuntCompensatorModificationInfos> toShuntCompensatorsMo

public static List<VoltageInitBusModificationEmbeddable> toEmbeddableVoltageInitBuses(List<VoltageInitBusModificationInfos> buses) {
return buses == null ? null : buses.stream()
.map(bus -> new VoltageInitBusModificationEmbeddable(bus.getBusId(), bus.getV(), bus.getAngle()))
.map(bus -> new VoltageInitBusModificationEmbeddable(bus.getVoltageLevelId(), bus.getBusId(), bus.getV(), bus.getAngle()))
.collect(Collectors.toList());
}

private List<VoltageInitBusModificationInfos> toBusesModification(List<VoltageInitBusModificationEmbeddable> buses) {
return buses != null ? buses
.stream()
.map(bus -> new VoltageInitBusModificationInfos(bus.getBusId(), bus.getV(), bus.getAngle()))
.map(bus -> new VoltageInitBusModificationInfos(bus.getVoltageLevelId(), bus.getBusId(), bus.getV(), bus.getAngle()))
.collect(Collectors.toList()) : null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,14 @@ private void applyBusModification(Network network, ReportNode subReportNode) {
int modificationsCount = 0;
List<ReportNode> reports = new ArrayList<>();
for (VoltageInitBusModificationInfos m : voltageInitModificationInfos.getBuses()) {
final Bus bus = network.getBusView().getBus(m.getBusId());
String voltageLevelId = m.getVoltageLevelId();
Bus bus;
if (voltageLevelId != null) {
final VoltageLevel voltageLevel = network.getVoltageLevel(voltageLevelId);
bus = voltageLevel.getBusView().getBus(m.getBusId());
} else {
bus = network.getBusView().getBus(m.getBusId());
}
if (bus == null) {
reports.add(ReportNode.newRootReportNode()
.withMessageTemplate("busNotFound", "Bus with id=${id} not found")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?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="lecuyerfra (generated)" id="1720515985912-29">
<addColumn tableName="voltage_init_bus_modification">
<column name="voltage_level_id" type="varchar(255)"/>
</addColumn>
</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 @@ -297,3 +297,6 @@ databaseChangeLog:
- include:
file: changesets/changelog_20240617T212921Z.xml
relativeToChangelogFile: true
- include:
file: changesets/changelog_20240709T090545Z.xml
relativeToChangelogFile: true
Original file line number Diff line number Diff line change
Expand Up @@ -1417,11 +1417,13 @@ public void testCreateVoltageInitModification() throws Exception {
.build()))
.buses(List.of(
VoltageInitBusModificationInfos.builder()
.voltageLevelId("v1")
.busId("1.1")
.v(225.)
.angle(0.)
.build(),
VoltageInitBusModificationInfos.builder()
.voltageLevelId("v1")
.busId("1.2")
.v(226.)
.angle(0.6)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,13 @@ protected ModificationInfos buildModification() {
.build()))
.buses(List.of(
VoltageInitBusModificationInfos.builder()
.voltageLevelId("v2")
.busId("busNotFound")
.v(400.)
.angle(0.)
.build(),
VoltageInitBusModificationInfos.builder()
.voltageLevelId("v1")
.busId("v1_0")
.v(230.)
.angle(0.5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1190,11 +1190,13 @@ public void testVoltageInitModification() {
.build()))
.buses(List.of(
VoltageInitBusModificationInfos.builder()
.voltageLevelId("1")
.busId("B1")
.v(225.)
.angle(0.)
.build(),
VoltageInitBusModificationInfos.builder()
.voltageLevelId("2")
.busId("B2")
.v(380.)
.angle(0.3)
Expand Down

0 comments on commit 6928386

Please sign in to comment.