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

[WIP] Returning real slack buses mismatches in SlackBusResult when using multiple slacks #1161

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -191,13 +191,13 @@ private LoadFlowResult runAc(Network network, LoadFlowParameters parameters, Ope
private static ReferenceBusAndSlackBusesResults buildReferenceBusAndSlackBusesResults(AbstractLoadFlowResult result) {
String referenceBusId = null;
List<LoadFlowResult.SlackBusResult> slackBusResultList = new ArrayList<>();
double slackBusActivePowerMismatch = result.getSlackBusActivePowerMismatch() * PerUnit.SB;
//double slackBusActivePowerMismatch = result.getSlackBusActivePowerMismatch() * PerUnit.SB;
if (result.getNetwork().getValidity() == LfNetwork.Validity.VALID) {
referenceBusId = result.getNetwork().getReferenceBus().getId();
List<LfBus> slackBuses = result.getNetwork().getSlackBuses();
slackBusResultList = slackBuses.stream().map(
b -> (LoadFlowResult.SlackBusResult) new LoadFlowResultImpl.SlackBusResultImpl(b.getId(),
slackBusActivePowerMismatch / slackBuses.size())).toList();
b.getMismatchP() * PerUnit.SB)).toList();
}
return new ReferenceBusAndSlackBusesResults(referenceBusId, slackBusResultList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ void multiSlackTest(boolean ac, NewtonRaphsonStoppingCriteriaType stoppingCriter
assertEquals(expectedIterationCount, componentResult.getIterationCount());

List<LoadFlowResult.SlackBusResult> slackBusResults = componentResult.getSlackBusResults();
double expectedSlackBusMismatch = ac ? -0.7164 : -3.5;
assertSlackBusResults(slackBusResults, expectedSlackBusMismatch, 2);
List<Double> expectedSlackBusMismatches = ac ? List.of(-0.7150, -0.7178) : List.of(-3.5, -3.5); // Mismatch values are not exactly the same between both slack buses
assertSlackBusResults(slackBusResults, expectedSlackBusMismatches, 2);

if (ac) {
assertActivePowerValues(302.807, 302.807, 600.868);
Expand All @@ -111,8 +111,8 @@ void multiSlackTest(boolean ac, NewtonRaphsonStoppingCriteriaType stoppingCriter
slackBusResults = componentResult.getSlackBusResults();
expectedIterationCount = ac ? 4 : 0;
assertEquals(expectedIterationCount, componentResult.getIterationCount());
expectedSlackBusMismatch = ac ? -0.005 : 0;
assertSlackBusResults(slackBusResults, expectedSlackBusMismatch, 2);
expectedSlackBusMismatches = ac ? List.of(-0.00576, -0.00572) : List.of(0d, 0d);
assertSlackBusResults(slackBusResults, expectedSlackBusMismatches, 2);
}

@ParameterizedTest(name = "ac : {0}")
Expand All @@ -128,8 +128,8 @@ void nonImpedantBranchTest(boolean ac) {
int expectedIterationCount = ac ? 3 : 0;
assertEquals(expectedIterationCount, componentResult.getIterationCount());
List<LoadFlowResult.SlackBusResult> slackBusResults = componentResult.getSlackBusResults();
double expectedSlackBusMismatch = ac ? -2.755 : -3.5;
assertSlackBusResults(slackBusResults, expectedSlackBusMismatch, 2);
List<Double> expectedSlackBusMismatches = ac ? List.of(-2.7551, -2.7547) : List.of(-3.5, -3.5);
assertSlackBusResults(slackBusResults, expectedSlackBusMismatches, 2);

if (ac) {
assertActivePowerValues(603.567, 0.0, 600.812);
Expand All @@ -144,8 +144,8 @@ void nonImpedantBranchTest(boolean ac) {
slackBusResults = componentResult.getSlackBusResults();
expectedIterationCount = ac ? 4 : 0;
assertEquals(expectedIterationCount, componentResult.getIterationCount());
expectedSlackBusMismatch = ac ? -0.005 : 0;
assertSlackBusResults(slackBusResults, expectedSlackBusMismatch, 2);
expectedSlackBusMismatches = ac ? List.of(-0.0054, -0.0056) : List.of(0d, 0d);
assertSlackBusResults(slackBusResults, expectedSlackBusMismatches, 2);
}

@ParameterizedTest(name = "ac : {0}")
Expand All @@ -162,8 +162,8 @@ void loadOnSlackBusTest(boolean ac) {

List<LoadFlowResult.SlackBusResult> slackBusResults = componentResult.getSlackBusResults();
assertEquals(List.of("VLHV2_0", "VLLOAD_0"), slackBusResults.stream().map(LoadFlowResult.SlackBusResult::getId).toList());
double expectedSlackBusMismatch = ac ? -0.711 : -3.5;
assertSlackBusResults(slackBusResults, expectedSlackBusMismatch, 2);
List<Double> expectedSlackBusMismatches = ac ? List.of(-0.7118, -0.7108) : List.of(-3.5, -3.5);
assertSlackBusResults(slackBusResults, expectedSlackBusMismatches, 2);

if (ac) {
assertActivePowerValues(303.165, 303.165, 601.58);
Expand All @@ -180,10 +180,11 @@ void assertActivePowerValues(double line1P1, double line2P1, double loadT2wtP1)
assertActivePowerEquals(-607, generator.getTerminal());
}

void assertSlackBusResults(List<LoadFlowResult.SlackBusResult> slackBusResults, double expectedMismatch, int slackBusCount) {
void assertSlackBusResults(List<LoadFlowResult.SlackBusResult> slackBusResults, List<Double> expectedMismatches, int slackBusCount) {
assertEquals(slackBusCount, slackBusResults.size());
int i = 0;
for (LoadFlowResult.SlackBusResult slackBusResult : slackBusResults) {
assertEquals(expectedMismatch, slackBusResult.getActivePowerMismatch(), LoadFlowAssert.DELTA_POWER);
assertEquals(expectedMismatches.get(i++), slackBusResult.getActivePowerMismatch(), LoadFlowAssert.DELTA_POWER);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ void testDcSlackDistributionFailureBehavior() {
assertEquals(1, result.getComponentResults().size());
assertEquals(LoadFlowResult.ComponentResult.Status.FAILED, result.getComponentResults().get(0).getStatus());
assertEquals("Outer loop failed: Failed to distribute slack bus active power mismatch, 321.90 MW remains", result.getComponentResults().get(0).getStatusText());
assertEquals(321.9, result.getComponentResults().get(0).getSlackBusResults().get(0).getActivePowerMismatch(), 0.01);
assertEquals(-73.9, result.getComponentResults().get(0).getSlackBusResults().get(0).getActivePowerMismatch(), 0.01); // The actual slack bus mismatch is the initial mismatch since distribution has failed
assertEquals(0, result.getComponentResults().get(0).getDistributedActivePower(), 0.01);
assertReportContains("Failed to distribute slack bus active power mismatch, [-+]?321\\.\\d* MW remains", reportNode);

Expand Down
Loading