Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stores and apply several limit sets in the branch creation #9

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a6634b6
stores and apply several limit sets in the branch creation
Mathieu-Deharbe Dec 10, 2024
28ad43f
back to CurrentLimitsEntity + update application
Mathieu-Deharbe Dec 12, 2024
1f00dc0
renaming
Mathieu-Deharbe Dec 12, 2024
58a77ef
TUs
Mathieu-Deharbe Dec 16, 2024
0c57651
cleans
Mathieu-Deharbe Dec 16, 2024
eccbc5e
simplify
Mathieu-Deharbe Dec 16, 2024
d05d9be
correction
Mathieu-Deharbe Dec 16, 2024
e0942a2
Merge branch 'main' into complete-limits-in-branch-creation
Mathieu-Deharbe Dec 16, 2024
4ede9ef
Merge branch 'main' into complete-limits-in-branch-creation
Mathieu-Deharbe Dec 18, 2024
5eae6c8
adds OperationalLimitsGroupInfos
Mathieu-Deharbe Dec 18, 2024
ad86424
!CollectionUtils.isEmpty(
Mathieu-Deharbe Dec 18, 2024
13d096f
OperationalLimitsGroupEntity and everything that uses it
Mathieu-Deharbe Dec 19, 2024
c20b3a8
Merge branch 'main' into complete-limits-in-branch-creation
Mathieu-Deharbe Jan 6, 2025
a52072a
post review 1
Mathieu-Deharbe Jan 6, 2025
1c71d77
TU
Mathieu-Deharbe Jan 6, 2025
e5e03d9
reduce cognitive complexity
Mathieu-Deharbe Jan 7, 2025
2e16fd5
comply with build requirements
Mathieu-Deharbe Jan 7, 2025
6e93a4a
post review 2
Mathieu-Deharbe Jan 7, 2025
ba0de6a
Merge branch 'main' into complete-limits-in-branch-creation
Mathieu-Deharbe Jan 10, 2025
d080a43
Merge branch 'main' into complete-limits-in-branch-creation
Mathieu-Deharbe Jan 14, 2025
a07090d
Merge branch 'main' into complete-limits-in-branch-creation
Mathieu-Deharbe Jan 16, 2025
cbc5f73
Merge branch 'main' into complete-limits-in-branch-creation
Mathieu-Deharbe Jan 17, 2025
31cfb43
log selected limit set
Mathieu-Deharbe Jan 17, 2025
dc771ee
Merge remote-tracking branch 'origin/complete-limits-in-branch-creati…
Mathieu-Deharbe Jan 17, 2025
44c9e25
log created limit set
Mathieu-Deharbe Jan 17, 2025
2e595de
cleaning
Mathieu-Deharbe Jan 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import lombok.ToString;
import lombok.experimental.SuperBuilder;

import java.util.List;

/**
* @author Sylvain Bouzols <sylvain.bouzols at rte-france.com>
*/
Expand Down Expand Up @@ -43,11 +45,17 @@ public class BranchCreationInfos extends EquipmentCreationInfos {
@Schema(description = "Bus or Busbar section id Side 2")
private String busOrBusbarSectionId2;

@Schema(description = "Current limits Side 1")
private CurrentLimitsInfos currentLimits1;
@Schema(description = "Operational limit groups on side 1")
private List<OperationalLimitsGroupInfos> operationalLimitsGroups1;

@Schema(description = "Operational limit groups on side 2")
private List<OperationalLimitsGroupInfos> operationalLimitsGroups2;

@Schema(description = "Selected operational limits group id on Side 1")
private String selectedOperationalLimitsGroupId1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private String selectedOperationalLimitsGroup1;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK done.


@Schema(description = "Current limits Side 2")
private CurrentLimitsInfos currentLimits2;
@Schema(description = "Selected operational limits group id on Side 2")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Selected operational limits group on Side 2

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK why not.

private String selectedOperationalLimitsGroupId2;

@Schema(description = "Connection Name 1")
private String connectionName1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
package org.gridsuite.modification.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.*;
basseche marked this conversation as resolved.
Show resolved Hide resolved
import lombok.experimental.SuperBuilder;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Copyright (c) 2024, 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.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.SuperBuilder;

@SuperBuilder
@NoArgsConstructor
@Getter
@Setter
@ToString
@Schema(description = "Operational limits group")
public class OperationalLimitsGroupInfos {
@Schema(description = "Operational limit group id")
private String id;

@Schema(description = "Current limits")
private CurrentLimitsInfos currentLimits;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@
import com.powsybl.iidm.modification.topology.CreateBranchFeederBays;
import com.powsybl.iidm.modification.topology.CreateBranchFeederBaysBuilder;
import com.powsybl.iidm.network.*;
import org.apache.commons.collections4.CollectionUtils;
import org.gridsuite.modification.NetworkModificationException;
import org.gridsuite.modification.dto.CurrentLimitsInfos;
import org.gridsuite.modification.dto.LineCreationInfos;
import org.gridsuite.modification.dto.OperationalLimitsGroupInfos;
import org.gridsuite.modification.utils.ModificationUtils;
import org.gridsuite.modification.utils.PropertiesUtils;

import java.util.List;

import static com.powsybl.iidm.network.TwoSides.ONE;
import static com.powsybl.iidm.network.TwoSides.TWO;
basseche marked this conversation as resolved.
Show resolved Hide resolved
import static org.gridsuite.modification.NetworkModificationException.Type.*;

/**
Expand Down Expand Up @@ -67,16 +72,25 @@ public void apply(Network network, ReportNode subReportNode) {
}

// Set permanent and temporary current limits
CurrentLimitsInfos currentLimitsInfos1 = modificationInfos.getCurrentLimits1();
CurrentLimitsInfos currentLimitsInfos2 = modificationInfos.getCurrentLimits2();
if (currentLimitsInfos1 != null || currentLimitsInfos2 != null) {
List<OperationalLimitsGroupInfos> opLimitsGroupSide1 = modificationInfos.getOperationalLimitsGroups1();
List<OperationalLimitsGroupInfos> opLimitsGroupSide2 = modificationInfos.getOperationalLimitsGroups2();
if (!CollectionUtils.isEmpty(opLimitsGroupSide1)) {
var line = ModificationUtils.getInstance().getLine(network, modificationInfos.getEquipmentId());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var line = ModificationUtils.getInstance().getLine(network, modificationInfos.getEquipmentId());
Line line = ModificationUtils.getInstance().getLine(network, modificationInfos.getEquipmentId());

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK done.

ModificationUtils.getInstance().setCurrentLimitsOnASide(opLimitsGroupSide1, line, ONE);
}
if (!CollectionUtils.isEmpty(opLimitsGroupSide2)) {
var line = ModificationUtils.getInstance().getLine(network, modificationInfos.getEquipmentId());
ModificationUtils.getInstance().setCurrentLimits(currentLimitsInfos1, line.newCurrentLimits1());
ModificationUtils.getInstance().setCurrentLimits(currentLimitsInfos2, line.newCurrentLimits2());
ModificationUtils.getInstance().setCurrentLimitsOnASide(opLimitsGroupSide2, line, TWO);
}
ModificationUtils.getInstance().disconnectBranch(modificationInfos, network.getLine(modificationInfos.getEquipmentId()), subReportNode);
// properties
Line line = network.getLine(modificationInfos.getEquipmentId());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can place this line before (for example, line 74) to avoid calling getLine three times and
extract the code of // Set permanent and temporary current limits... shared between line and twt into a common funct (the second remarq is a suggestion not mandatory)

Copy link
Author

@Mathieu-Deharbe Mathieu-Deharbe Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I thought about this but didn't dare because it looks like whoever wrote this like this did it on purpose. And I didn't want to take the risk.

But ok you look motivated I did it !

if (modificationInfos.getSelectedOperationalLimitsGroupId1() != null) {
line.setSelectedOperationalLimitsGroup1(modificationInfos.getSelectedOperationalLimitsGroupId1());
}
if (modificationInfos.getSelectedOperationalLimitsGroupId2() != null) {
line.setSelectedOperationalLimitsGroup2(modificationInfos.getSelectedOperationalLimitsGroupId2());
}
PropertiesUtils.applyProperties(line, subReportNode, modificationInfos.getProperties(), "LineProperties");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
import com.powsybl.iidm.modification.topology.CreateBranchFeederBays;
import com.powsybl.iidm.modification.topology.CreateBranchFeederBaysBuilder;
import com.powsybl.iidm.network.*;
import org.apache.commons.collections4.CollectionUtils;
import org.gridsuite.modification.NetworkModificationException;
import org.gridsuite.modification.dto.*;
import org.gridsuite.modification.utils.ModificationUtils;
import org.gridsuite.modification.utils.PropertiesUtils;

import java.util.List;
import java.util.Optional;

import static org.gridsuite.modification.NetworkModificationException.Type.*;
Expand Down Expand Up @@ -53,11 +55,19 @@ public void apply(Network network, ReportNode subReportNode) {
}

// Set permanent and temporary current limits
CurrentLimitsInfos currentLimitsInfos1 = modificationInfos.getCurrentLimits1();
CurrentLimitsInfos currentLimitsInfos2 = modificationInfos.getCurrentLimits2();
if (currentLimitsInfos1 != null || currentLimitsInfos2 != null) {
ModificationUtils.getInstance().setCurrentLimits(currentLimitsInfos1, twoWindingsTransformer.newCurrentLimits1());
ModificationUtils.getInstance().setCurrentLimits(currentLimitsInfos2, twoWindingsTransformer.newCurrentLimits2());
List<OperationalLimitsGroupInfos> opLimitsGroupSide1 = modificationInfos.getOperationalLimitsGroups1();
List<OperationalLimitsGroupInfos> opLimitsGroupSide2 = modificationInfos.getOperationalLimitsGroups2();
if (!CollectionUtils.isEmpty(opLimitsGroupSide1)) {
ModificationUtils.getInstance().setCurrentLimitsOnASide(opLimitsGroupSide1, twoWindingsTransformer, TwoSides.ONE);
}
if (!CollectionUtils.isEmpty(opLimitsGroupSide2)) {
ModificationUtils.getInstance().setCurrentLimitsOnASide(opLimitsGroupSide2, twoWindingsTransformer, TwoSides.TWO);
}
if (modificationInfos.getSelectedOperationalLimitsGroupId1() != null) {
twoWindingsTransformer.setSelectedOperationalLimitsGroup1(modificationInfos.getSelectedOperationalLimitsGroupId1());
}
if (modificationInfos.getSelectedOperationalLimitsGroupId2() != null) {
twoWindingsTransformer.setSelectedOperationalLimitsGroup2(modificationInfos.getSelectedOperationalLimitsGroupId2());
}

ModificationUtils.getInstance().disconnectBranch(modificationInfos, network.getTwoWindingsTransformer(modificationInfos.getEquipmentId()), subReportNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import javax.annotation.Nullable;

import static com.powsybl.iidm.network.TwoSides.ONE;
import static org.gridsuite.modification.NetworkModificationException.Type.*;

/**
Expand Down Expand Up @@ -440,15 +441,15 @@ public LineAdder createLineAdder(Network network, VoltageLevel voltageLevel1, Vo
.setB2(lineCreationInfos.getB2() != null ? lineCreationInfos.getB2() : 0.0);

// lineAdder completion by topology
setBranchAdderNodeOrBus(lineAdder, voltageLevel1, lineCreationInfos, TwoSides.ONE, withSwitch1);
setBranchAdderNodeOrBus(lineAdder, voltageLevel1, lineCreationInfos, ONE, withSwitch1);
setBranchAdderNodeOrBus(lineAdder, voltageLevel2, lineCreationInfos, TwoSides.TWO, withSwitch2);

return lineAdder;
}

public void setBranchAdderNodeOrBus(BranchAdder<?, ?> branchAdder, VoltageLevel voltageLevel, BranchCreationInfos branchCreationInfos,
TwoSides side, boolean withSwitch) {
String busOrBusbarSectionId = (side == TwoSides.ONE) ? branchCreationInfos.getBusOrBusbarSectionId1() : branchCreationInfos.getBusOrBusbarSectionId2();
String busOrBusbarSectionId = (side == ONE) ? branchCreationInfos.getBusOrBusbarSectionId1() : branchCreationInfos.getBusOrBusbarSectionId2();
if (voltageLevel.getTopologyKind() == TopologyKind.BUS_BREAKER) {
setBranchAdderBusBreaker(branchAdder, voltageLevel, side, busOrBusbarSectionId);
} else {
Expand All @@ -462,7 +463,7 @@ private void setBranchAdderBusBreaker(BranchAdder<?, ?> branchAdder, VoltageLeve
Bus bus = getBusBreakerBus(voltageLevel, busId);

// complete the lineAdder
if (side == TwoSides.ONE) {
if (side == ONE) {
branchAdder.setBus1(bus.getId()).setConnectableBus1(bus.getId());
} else {
branchAdder.setBus2(bus.getId()).setConnectableBus2(bus.getId());
Expand All @@ -481,7 +482,7 @@ private void setBranchAdderNodeBreaker(BranchAdder<?, ?> branchAdder, VoltageLev
sideSuffix);

// complete the lineAdder
if (side == TwoSides.ONE) {
if (side == ONE) {
branchAdder.setNode1(nodeNum);
} else {
branchAdder.setNode2(nodeNum);
Expand Down Expand Up @@ -1010,24 +1011,34 @@ public Identifiable<?> getEquipmentByIdentifiableType(Network network, Identifia
};
}

public void setCurrentLimits(CurrentLimitsInfos currentLimitsInfos, CurrentLimitsAdder limitsAdder) {
if (currentLimitsInfos != null) {
boolean hasPermanent = currentLimitsInfos.getPermanentLimit() != null;
boolean hasTemporary = currentLimitsInfos.getTemporaryLimits() != null && !currentLimitsInfos.getTemporaryLimits().isEmpty();
if (hasPermanent) {
limitsAdder.setPermanentLimit(currentLimitsInfos.getPermanentLimit());
}
if (hasTemporary) {
for (CurrentTemporaryLimitCreationInfos limit : currentLimitsInfos.getTemporaryLimits()) {
limitsAdder
.beginTemporaryLimit()
.setName(limit.getName())
.setValue(limit.getValue() == null ? Double.MAX_VALUE : limit.getValue())
.setAcceptableDuration(limit.getAcceptableDuration() == null ? Integer.MAX_VALUE : limit.getAcceptableDuration())
.endTemporaryLimit();
/**
* @param opLimitGroups added current limits
* @param branch branch to which limits are going to be added
* @param side which side of the branch receives the limits
*/
public void setCurrentLimitsOnASide(List<OperationalLimitsGroupInfos> opLimitGroups, Branch<?> branch, TwoSides side) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setCurrentLimitsOnSide (don't like the LimitsOnASide)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why ? I think this is more precise with "A" given that "side" also means "secondary" or "in the same time" in english.
At least here we know this is a noun.

for (OperationalLimitsGroupInfos opLimitsGroup : opLimitGroups) {
boolean hasPermanent = opLimitsGroup.getCurrentLimits().getPermanentLimit() != null;
boolean hasTemporary = !CollectionUtils.isEmpty(opLimitsGroup.getCurrentLimits().getTemporaryLimits());
boolean hasLimits = hasPermanent || hasTemporary;
if (hasLimits) {
basseche marked this conversation as resolved.
Show resolved Hide resolved
OperationalLimitsGroup opGroup = side == ONE
? branch.newOperationalLimitsGroup1(opLimitsGroup.getId())
: branch.newOperationalLimitsGroup2(opLimitsGroup.getId());
CurrentLimitsAdder limitsAdder = opGroup.newCurrentLimits();
if (hasPermanent) {
limitsAdder.setPermanentLimit(opLimitsGroup.getCurrentLimits().getPermanentLimit());
}
if (hasTemporary) {
for (CurrentTemporaryLimitCreationInfos limit : opLimitsGroup.getCurrentLimits().getTemporaryLimits()) {
limitsAdder
.beginTemporaryLimit()
.setName(limit.getName())
.setValue(limit.getValue() == null ? Double.MAX_VALUE : limit.getValue())
.setAcceptableDuration(limit.getAcceptableDuration() == null ? Integer.MAX_VALUE : limit.getAcceptableDuration())
.endTemporaryLimit();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can suggest here to use the functional approach (with forEach)

       .forEach(limit -> {
           double value = limit.getValue() != null ? limit.getValue() : Double.MAX_VALUE;
           int duration = limit.getAcceptableDuration() != null ? limit.getAcceptableDuration() : Integer.MAX_VALUE;

           limitsAdder.beginTemporaryLimit()
                      .setName(limit.getName())
                      .setValue(value)
                      .setAcceptableDuration(duration)
                      .endTemporaryLimit();
       });
                   }

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK done. And it reduces cognitive complexity. Nice.

}
}
if (hasPermanent || hasTemporary) {
limitsAdder.add();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
import com.powsybl.iidm.network.ValidationException;

import org.gridsuite.modification.NetworkModificationException;
import org.gridsuite.modification.dto.CurrentLimitsInfos;
import org.gridsuite.modification.dto.FreePropertyInfos;
import org.gridsuite.modification.dto.LineCreationInfos;
import org.gridsuite.modification.dto.ModificationInfos;
import org.gridsuite.modification.dto.*;
import org.gridsuite.modification.utils.NetworkCreation;
import org.junit.jupiter.api.Test;
import java.util.Collections;
Expand Down Expand Up @@ -54,7 +51,16 @@ void testCreateLineOptionalParameters5() throws Exception {
.busOrBusbarSectionId1("bus1")
.voltageLevelId2("v2")
.busOrBusbarSectionId2("bus2")
.currentLimits1(CurrentLimitsInfos.builder().permanentLimit(-1.0).build())
.operationalLimitsGroups1(
List.of(
OperationalLimitsGroupInfos.builder()
.id("limiSet1")
.currentLimits(
CurrentLimitsInfos.builder().permanentLimit(-1.0).build()
).build()
)
)
.selectedOperationalLimitsGroupId1("limiSet1")
.build();
ValidationException exception = assertThrows(ValidationException.class, () -> lineCreationInfosPermanentLimitNOK.toModification().apply(getNetwork()));
assertEquals("AC Line 'idLine2': permanent limit must be >= 0", exception.getMessage());
Expand Down Expand Up @@ -82,8 +88,26 @@ protected ModificationInfos buildModification() {
.b2(20.0)
.voltageLevelId1("v1")
.busOrBusbarSectionId1("bus1")
.currentLimits1(CurrentLimitsInfos.builder().permanentLimit(5.).temporaryLimits(Collections.emptyList()).build())
.currentLimits2(CurrentLimitsInfos.builder().permanentLimit(5.).temporaryLimits(Collections.emptyList()).build())
.operationalLimitsGroups1(
List.of(
OperationalLimitsGroupInfos.builder()
.id("limitSet1")
.currentLimits(
CurrentLimitsInfos.builder().permanentLimit(5.).temporaryLimits(Collections.emptyList()).build()
).build()
)
)
.operationalLimitsGroups2(
List.of(
OperationalLimitsGroupInfos.builder()
.id("limitSet2")
.currentLimits(
CurrentLimitsInfos.builder().permanentLimit(5.).temporaryLimits(Collections.emptyList()).build()
).build()
)
)
.selectedOperationalLimitsGroupId1("limitSet1")
.selectedOperationalLimitsGroupId2("limitSet2")
.voltageLevelId2("v2")
.busOrBusbarSectionId2("bus2")
.properties(List.of(FreePropertyInfos.builder().name(PROPERTY_NAME).value(PROPERTY_VALUE).build()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,34 @@ protected ModificationInfos buildModification() {
.voltageLevelId2("v12")
.busOrBusbarSectionId2("bus12")
.connected2(true)
.currentLimits1(CurrentLimitsInfos.builder().permanentLimit(3.).temporaryLimits(List.of(CurrentTemporaryLimitCreationInfos.builder().name("IT5").acceptableDuration(98647).value(45.).build())).build())
.currentLimits2(CurrentLimitsInfos.builder().permanentLimit(2.).temporaryLimits(List.of(CurrentTemporaryLimitCreationInfos.builder().name("IT10").acceptableDuration(683647).value(791.).build())).build())
.operationalLimitsGroups1(
List.of(
OperationalLimitsGroupInfos.builder()
.id("limitSet1")
.currentLimits(
CurrentLimitsInfos.builder()
.permanentLimit(3.)
.temporaryLimits(
List.of(CurrentTemporaryLimitCreationInfos.builder().name("IT5").acceptableDuration(98647).value(45.).build())
).build()
).build()
)
)
.operationalLimitsGroups2(
List.of(
OperationalLimitsGroupInfos.builder()
.id("limitSet2")
.currentLimits(
CurrentLimitsInfos.builder()
.permanentLimit(2.)
.temporaryLimits(
List.of(CurrentTemporaryLimitCreationInfos.builder().name("IT10").acceptableDuration(683647).value(791.).build())
).build())
.build()
)
)
.selectedOperationalLimitsGroupId1("limitSet1")
.selectedOperationalLimitsGroupId2("limitSet2")
.connectionName1("cn201")
.connectionDirection1(ConnectablePosition.Direction.TOP)
.connectionName2("cn202")
Expand Down
Loading
Loading