Skip to content

Commit 71db750

Browse files
authored
Fix PQ/PV switches report (#1208)
Signed-off-by: Didier Vidal <didier.vidal_externe@rte-france.com>
1 parent 285515f commit 71db750

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

src/main/java/com/powsybl/openloadflow/ac/outerloop/ReactiveLimitsOuterLoop.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ private static boolean switchPqPv(List<PqToPvBus> pqToPvBuses, ContextData conte
209209
}
210210
}
211211

212+
}
213+
214+
if (!pqPvNodes.isEmpty()) {
212215
ReportNode summary = Reports.reportPqToPvBuses(reportNode, pqPvSwitchCount, pqToPvBuses.size() - pqPvSwitchCount);
213216
pqPvNodes.forEach(summary::include);
214217
}
@@ -351,9 +354,11 @@ private boolean switchReactiveControllerBusPq(List<ControllerBusToPqBus> reactiv
351354
break;
352355
}
353356

357+
}
358+
359+
if (!switchedNodes.isEmpty()) {
354360
ReportNode node = Reports.reportReactiveControllerBusesToPqBuses(reportNode, switchCount);
355361
switchedNodes.forEach(node::include);
356-
357362
}
358363

359364
LOGGER.info("{} remote reactive power controller buses switched PQ", switchCount);

src/test/java/com/powsybl/openloadflow/ac/SwitchPqPvTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*/
88
package com.powsybl.openloadflow.ac;
99

10+
import com.powsybl.commons.report.ReportNode;
11+
import com.powsybl.computation.local.LocalComputationManager;
1012
import com.powsybl.iidm.network.*;
1113
import com.powsybl.iidm.network.extensions.VoltagePerReactivePowerControlAdder;
1214
import com.powsybl.loadflow.LoadFlow;
@@ -17,9 +19,12 @@
1719
import com.powsybl.openloadflow.OpenLoadFlowProvider;
1820
import com.powsybl.openloadflow.network.AbstractLoadFlowNetworkFactory;
1921
import com.powsybl.openloadflow.network.SlackBusSelectionMode;
22+
import com.powsybl.openloadflow.util.LoadFlowAssert;
2023
import org.junit.jupiter.api.BeforeEach;
2124
import org.junit.jupiter.api.Test;
2225

26+
import java.io.IOException;
27+
2328
import static com.powsybl.openloadflow.util.LoadFlowAssert.assertVoltageEquals;
2429
import static org.junit.jupiter.api.Assertions.assertEquals;
2530
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -193,6 +198,42 @@ void test() {
193198
assertVoltageEquals(20, b3); // PV
194199
}
195200

201+
@Test
202+
void testMultipleSwitch() throws IOException {
203+
g2.newMinMaxReactiveLimits()
204+
.setMinQ(-179)
205+
.setMaxQ(700)
206+
.add();
207+
g2.setTargetV(22);
208+
ReportNode reportNode = ReportNode.newRootReportNode().withMessageTemplate("test", "test").build();
209+
LoadFlowResult result = loadFlowRunner.run(network, network.getVariantManager().getWorkingVariantId(), LocalComputationManager.getDefault(), parameters, reportNode);
210+
assertTrue(result.isFullyConverged());
211+
// bus 1 and 3 switch PQ at first outer loop, then at next outer loop bus 3 go back PV
212+
assertVoltageEquals(17.441, b1); // PQ => v != 17
213+
assertVoltageEquals(21.99, b2); // PQ => v != 22
214+
assertVoltageEquals(20, b3); // PV
215+
String expected = """
216+
+ test
217+
+ Load flow on network 'switch-pq-pv-test'
218+
+ Network CC0 SC0
219+
+ Network info
220+
Network has 4 buses and 3 branches
221+
Network balance: active generation=300 MW, active load=300 MW, reactive generation=0 MVar, reactive load=200 MVar
222+
Angle reference bus: vl4_0
223+
Slack bus: vl4_0
224+
Outer loop VoltageMonitoring
225+
+ Outer loop ReactiveLimits
226+
+ Outer loop iteration 1
227+
+ 2 buses switched PV -> PQ (1 buses remain PV)
228+
Switch bus 'vl1_0' PV -> PQ, q=-200.872086 < minQ=-179
229+
Switch bus 'vl2_0' PV -> PQ, q=712.632433 > maxQ=700
230+
Outer loop VoltageMonitoring
231+
Outer loop ReactiveLimits
232+
AC load flow completed successfully (solverStatus=CONVERGED, outerloopStatus=STABLE)
233+
""";
234+
LoadFlowAssert.assertReportEqualsString(expected, reportNode);
235+
}
236+
196237
@Test
197238
void testWithSlope() {
198239
g3.remove();

0 commit comments

Comments
 (0)