Skip to content

Commit 7ca9878

Browse files
Disable the modification of a shunt compensator with multiple sections (#280)
Disable the modification of a shunt compensator with multiple sections Modify the section count when modifying a shunt compensator, depending on the susceptance per section value or the Q at nominal V value.
1 parent 56502ad commit 7ca9878

File tree

2 files changed

+76
-14
lines changed

2 files changed

+76
-14
lines changed

src/main/java/org/gridsuite/modification/server/modifications/ShuntCompensatorModification.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import com.powsybl.iidm.network.ShuntCompensatorModelType;
1717
import com.powsybl.iidm.network.VoltageLevel;
1818
import org.gridsuite.modification.server.NetworkModificationException;
19+
import org.gridsuite.modification.server.dto.AttributeModification;
20+
import org.gridsuite.modification.server.dto.OperationType;
1921
import org.gridsuite.modification.server.dto.ShuntCompensatorModificationInfos;
2022
import org.gridsuite.modification.server.dto.ShuntCompensatorType;
2123

@@ -37,18 +39,34 @@ public ShuntCompensatorModification(ShuntCompensatorModificationInfos shuntCompe
3739
}
3840

3941
@Override
40-
public void apply(Network network, Reporter subReporter) {
42+
public void check(Network network) throws NetworkModificationException {
4143
ShuntCompensator shuntCompensator = network.getShuntCompensator(modificationInfos.getEquipmentId());
4244
if (shuntCompensator == null) {
4345
throw new NetworkModificationException(SHUNT_COMPENSATOR_NOT_FOUND,
4446
String.format("Shunt compensator %s does not exist in network", modificationInfos.getEquipmentId()));
4547
}
46-
VoltageLevel voltageLevel = network.getVoltageLevel(modificationInfos.getVoltageLevelId());
4748

49+
VoltageLevel voltageLevel = network.getVoltageLevel(modificationInfos.getVoltageLevelId());
4850
if (voltageLevel == null) {
4951
throw new NetworkModificationException(VOLTAGE_LEVEL_NOT_FOUND,
5052
String.format("Voltage level %s does not exist in network", modificationInfos.getVoltageLevelId()));
5153
}
54+
}
55+
56+
@Override
57+
public void apply(Network network, Reporter subReporter) {
58+
ShuntCompensator shuntCompensator = network.getShuntCompensator(modificationInfos.getEquipmentId());
59+
VoltageLevel voltageLevel = network.getVoltageLevel(modificationInfos.getVoltageLevelId());
60+
61+
if (shuntCompensator.getMaximumSectionCount() > 1) {
62+
subReporter.report(Report.builder()
63+
.withKey("shuntCompensatorModificationMultiSections")
64+
.withDefaultMessage("It is currently not possible to modify the multi sections shunt compensator with id=${id}")
65+
.withValue("id", modificationInfos.getEquipmentId())
66+
.withSeverity(TypedValue.ERROR_SEVERITY)
67+
.build());
68+
return;
69+
}
5270

5371
subReporter.report(Report.builder()
5472
.withKey("shuntCompensatorModification")
@@ -62,7 +80,6 @@ public void apply(Network network, Reporter subReporter) {
6280
if (shuntCompensator.getModelType() == ShuntCompensatorModelType.LINEAR) {
6381
applyModificationOnLinearModel(subReporter, shuntCompensator, voltageLevel);
6482
}
65-
6683
}
6784

6885
private void applyModificationOnLinearModel(Reporter subReporter, ShuntCompensator shuntCompensator, VoltageLevel voltageLevel) {
@@ -87,8 +104,17 @@ private void applyModificationOnLinearModel(Reporter subReporter, ShuntCompensat
87104

88105
model.setBPerSection(shuntCompensatorType == ShuntCompensatorType.CAPACITOR ? susceptancePerSection : -susceptancePerSection);
89106
reports.add(ModificationUtils.getInstance().buildModificationReport(olQAtNominalV, modificationInfos.getQAtNominalV().getValue(), "Q at nominal voltage"));
107+
108+
AttributeModification<Integer> sectionCountModification = AttributeModification.toAttributeModification(modificationInfos.getQAtNominalV().getValue() == 0. ? 0 : 1, OperationType.SET);
109+
reports.add(ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(shuntCompensator::setSectionCount, shuntCompensator::getSectionCount, sectionCountModification, "Section count"));
110+
}
111+
112+
if (modificationInfos.getSusceptancePerSection() != null) {
113+
reports.add(ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(model::setBPerSection, model::getBPerSection, modificationInfos.getSusceptancePerSection(), "Susceptance per section"));
114+
115+
AttributeModification<Integer> sectionCountModification = AttributeModification.toAttributeModification(modificationInfos.getSusceptancePerSection().getValue() == 0. ? 0 : 1, OperationType.SET);
116+
reports.add(ModificationUtils.getInstance().applyElementaryModificationsAndReturnReport(shuntCompensator::setSectionCount, shuntCompensator::getSectionCount, sectionCountModification, "Section count"));
90117
}
91118
reports.forEach(subReporter::report);
92-
ModificationUtils.getInstance().applyElementaryModifications(model::setBPerSection, model::getBPerSection, modificationInfos.getSusceptancePerSection(), subReporter, "Susceptance per section");
93119
}
94120
}

src/test/java/org/gridsuite/modification/server/modifications/ShuntCompensatorModificationTest.java

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
import com.powsybl.iidm.network.Network;
1111
import com.powsybl.iidm.network.ShuntCompensatorLinearModel;
12+
import com.powsybl.iidm.network.VoltageLevel;
13+
import com.powsybl.iidm.network.extensions.ConnectablePosition;
1214
import lombok.SneakyThrows;
1315
import org.gridsuite.modification.server.NetworkModificationException;
1416
import org.gridsuite.modification.server.dto.*;
@@ -20,6 +22,7 @@
2022

2123
import static org.gridsuite.modification.server.NetworkModificationException.Type.SHUNT_COMPENSATOR_NOT_FOUND;
2224
import static org.gridsuite.modification.server.NetworkModificationException.Type.VOLTAGE_LEVEL_NOT_FOUND;
25+
import static org.gridsuite.modification.server.utils.NetworkUtil.createShuntCompensator;
2326
import static org.gridsuite.modification.server.utils.TestUtils.assertLogMessage;
2427
import static org.junit.Assert.assertEquals;
2528
import static org.junit.Assert.assertNotNull;
@@ -67,14 +70,35 @@ public void testWrongVoltageLevelId() {
6770

6871
@SneakyThrows
6972
@Test
70-
public void testCreateModificationWithShuntCompensatorType() {
73+
public void testShuntCompensatorWithMultipleSections() {
7174
var shuntCompensator = getNetwork().getShuntCompensator("v5shunt");
75+
76+
ShuntCompensatorModificationInfos modificationInfos = ShuntCompensatorModificationInfos.builder()
77+
.equipmentId("v5shunt")
78+
.voltageLevelId("v5")
79+
.shuntCompensatorType(new AttributeModification<>(ShuntCompensatorType.REACTOR, OperationType.SET))
80+
.build();
81+
82+
mockMvc.perform(post(getNetworkModificationUri()).content(mapper.writeValueAsString(modificationInfos)).contentType(MediaType.APPLICATION_JSON))
83+
.andExpect(status().isOk());
84+
85+
assertLogMessage("It is currently not possible to modify the multi sections shunt compensator with id=v5shunt",
86+
"shuntCompensatorModificationMultiSections", reportService);
87+
}
88+
89+
@SneakyThrows
90+
@Test
91+
public void testCreateModificationWithShuntCompensatorType() {
92+
VoltageLevel v5 = getNetwork().getVoltageLevel("v5");
93+
createShuntCompensator(v5, "v7shunt", "v7shunt", 6, 225., 10, true, 1, 1, 2, 1, "feeder_v7shunt", 40, ConnectablePosition.Direction.BOTTOM);
94+
95+
var shuntCompensator = getNetwork().getShuntCompensator("v7shunt");
7296
var model = shuntCompensator.getModel(ShuntCompensatorLinearModel.class);
7397
assertNotNull(model);
7498

7599
assertEquals(1.0, model.getBPerSection(), 0);
76100
ShuntCompensatorModificationInfos modificationInfos = ShuntCompensatorModificationInfos.builder()
77-
.equipmentId("v5shunt")
101+
.equipmentId("v7shunt")
78102
.voltageLevelId("v5")
79103
.shuntCompensatorType(new AttributeModification<>(ShuntCompensatorType.REACTOR, OperationType.SET))
80104
.build();
@@ -88,13 +112,16 @@ public void testCreateModificationWithShuntCompensatorType() {
88112
@SneakyThrows
89113
@Test
90114
public void testCreateModificationWithSusceptancePerSection() {
91-
var shuntCompensator = getNetwork().getShuntCompensator("v5shunt");
115+
VoltageLevel v5 = getNetwork().getVoltageLevel("v5");
116+
createShuntCompensator(v5, "v7shunt", "v7shunt", 6, 225., 10, true, 1, 1, 2, 0, "feeder_v7shunt", 40, ConnectablePosition.Direction.BOTTOM);
117+
118+
var shuntCompensator = getNetwork().getShuntCompensator("v7shunt");
92119
var model = shuntCompensator.getModel(ShuntCompensatorLinearModel.class);
93120
assertNotNull(model);
94121

95122
assertEquals(1.0, model.getBPerSection(), 0);
96123
ShuntCompensatorModificationInfos modificationInfos = ShuntCompensatorModificationInfos.builder()
97-
.equipmentId("v5shunt")
124+
.equipmentId("v7shunt")
98125
.voltageLevelId("v5")
99126
.susceptancePerSection(AttributeModification.toAttributeModification(3.0, OperationType.SET))
100127
.build();
@@ -103,20 +130,26 @@ public void testCreateModificationWithSusceptancePerSection() {
103130
.andExpect(status().isOk());
104131

105132
assertEquals(3.0, model.getBPerSection(), 0);
133+
assertEquals(1, shuntCompensator.getSectionCount());
106134
}
107135

108136
@SneakyThrows
109137
@Test
110138
public void testCreateModificationWithQAtNominalV() {
139+
VoltageLevel v5 = getNetwork().getVoltageLevel("v5");
140+
createShuntCompensator(v5, "v7shunt", "v7shunt", 6, 225., 10, true, 1, 1, 2, 1, "feeder_v7shunt", 40, ConnectablePosition.Direction.BOTTOM);
141+
VoltageLevel v6 = getNetwork().getVoltageLevel("v6");
142+
createShuntCompensator(v6, "v8shunt", "v8shunt", 6, 225., 10, true, 1, 1, 2, 1, "feeder_v8shunt", 50, ConnectablePosition.Direction.BOTTOM);
143+
111144
ShuntCompensatorModificationInfos modificationInfos1 = ShuntCompensatorModificationInfos.builder()
112-
.equipmentId("v5shunt")
145+
.equipmentId("v7shunt")
113146
.voltageLevelId("v5")
114147
.qAtNominalV(new AttributeModification<>(30.5, OperationType.SET))
115148
.shuntCompensatorType(new AttributeModification<>(ShuntCompensatorType.REACTOR, OperationType.SET))
116149
.build();
117150

118151
ShuntCompensatorModificationInfos modificationInfos2 = ShuntCompensatorModificationInfos.builder()
119-
.equipmentId("v6shunt")
152+
.equipmentId("v8shunt")
120153
.voltageLevelId("v6")
121154
.qAtNominalV(new AttributeModification<>(30.5, OperationType.SET))
122155
.shuntCompensatorType(new AttributeModification<>(ShuntCompensatorType.CAPACITOR, OperationType.SET))
@@ -128,21 +161,24 @@ public void testCreateModificationWithQAtNominalV() {
128161
mockMvc.perform(post(getNetworkModificationUri()).content(mapper.writeValueAsString(modificationInfos2)).contentType(MediaType.APPLICATION_JSON))
129162
.andExpect(status().isOk());
130163

131-
var shuntCompensator1 = getNetwork().getShuntCompensator("v5shunt");
164+
var shuntCompensator1 = getNetwork().getShuntCompensator("v7shunt");
132165
var model = shuntCompensator1.getModel(ShuntCompensatorLinearModel.class);
133166
assertNotNull(model);
134167
assertEquals(-2.1121E-4, model.getBPerSection(), 0.0001);
135168

136-
var shuntCompensator2 = getNetwork().getShuntCompensator("v6shunt");
169+
var shuntCompensator2 = getNetwork().getShuntCompensator("v8shunt");
137170
var model2 = shuntCompensator2.getModel(ShuntCompensatorLinearModel.class);
138171
assertNotNull(model2);
139172
assertEquals(2.1121E-4, model2.getBPerSection(), 0.0001);
140173
}
141174

142175
@Override
143176
protected ModificationInfos buildModification() {
177+
VoltageLevel v2 = getNetwork().getVoltageLevel("v2");
178+
createShuntCompensator(v2, "v7shunt", "v7shunt", 15, 225., 10, true, 1, 1, 2, 1, "feeder_v7shunt", 40, ConnectablePosition.Direction.BOTTOM);
179+
144180
return ShuntCompensatorModificationInfos.builder()
145-
.equipmentId("v2shunt")
181+
.equipmentId("v7shunt")
146182
.shuntCompensatorType(new AttributeModification<>(ShuntCompensatorType.CAPACITOR, OperationType.SET))
147183
.qAtNominalV(new AttributeModification<>(15.0, OperationType.SET))
148184
.voltageLevelId("v2")
@@ -161,7 +197,7 @@ protected ModificationInfos buildModificationUpdate() {
161197

162198
@Override
163199
protected void assertNetworkAfterCreation() {
164-
var shuntCompensator = getNetwork().getShuntCompensator("v2shunt");
200+
var shuntCompensator = getNetwork().getShuntCompensator("v7shunt");
165201
var model = shuntCompensator.getModel(ShuntCompensatorLinearModel.class);
166202
assertNotNull(model);
167203
assertEquals(2.9629E-4, model.getBPerSection(), 0.0001);

0 commit comments

Comments
 (0)