Skip to content

Commit

Permalink
Added DC loadflow test
Browse files Browse the repository at this point in the history
Signed-off-by: PRABAKARAN Sylvestre <sylvestre.prabakaran@rte-france.com>
  • Loading branch information
SylvestreSakti committed Dec 6, 2024
1 parent 0471452 commit b0ec63f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ public DcLoadFlowResult run() {
Objects.requireNonNull(referenceGenerator, () -> "No reference generator in " + context.getNetwork());
referenceGenerator.setTargetP(referenceGenerator.getTargetP() + remainingMismatch);
LOGGER.warn("Could not distribute slack bus active power, remaining mismatch {} is redistributed to reference generator {}", remainingMismatch, referenceGenerator.getId());
distributedActivePower += remainingMismatch;
}
}
}
Expand Down
30 changes: 28 additions & 2 deletions src/test/java/com/powsybl/openloadflow/dc/DcLoadFlowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package com.powsybl.openloadflow.dc;

import com.powsybl.commons.PowsyblException;
import com.powsybl.commons.report.ReportNode;
import com.powsybl.ieeecdf.converter.IeeeCdfNetworkFactory;
import com.powsybl.iidm.network.*;
Expand All @@ -28,11 +29,11 @@
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.concurrent.CompletionException;

import static com.powsybl.openloadflow.util.LoadFlowAssert.assertActivePowerEquals;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* @author Sylvain Leclerc {@literal <sylvain.leclerc at rte-france.com>}
Expand Down Expand Up @@ -463,4 +464,29 @@ void testDcApproxIgnoreG() {
assertEquals(307.436, line2.getTerminal1().getP(), 0.01);
assertEquals(-307.436, line2.getTerminal2().getP(), 0.01);
}

@Test
void testDcSlackDistributionFailureBehavior() {
Network network = IeeeCdfNetworkFactory.create57();
parameters.setBalanceType(LoadFlowParameters.BalanceType.PROPORTIONAL_TO_GENERATION_P);
Generator referenceGenerator = network.getGenerator("B1-G");

parametersExt.setSlackDistributionFailureBehavior(OpenLoadFlowParameters.SlackDistributionFailureBehavior.FAIL);
var result = loadFlowRunner.run(network, parameters);
assertEquals(321.9,result.getComponentResults().get(0).getSlackBusResults().get(0).getActivePowerMismatch(), 0.01);
assertEquals(0,result.getComponentResults().get(0).getDistributedActivePower(), 0.01);
assertActivePowerEquals(-128.9,referenceGenerator.getTerminal());
// TODO : receive failure

parametersExt.setSlackDistributionFailureBehavior(OpenLoadFlowParameters.SlackDistributionFailureBehavior.THROW);
CompletionException e = assertThrows(CompletionException.class, () -> loadFlowRunner.run(network, parameters));
assertEquals("DC loadflow failed to distribute slack bus active power on network", e.getCause().getMessage());

parametersExt.setSlackDistributionFailureBehavior(OpenLoadFlowParameters.SlackDistributionFailureBehavior.DISTRIBUTE_ON_REFERENCE_GENERATOR);
parametersExt.setReferenceBusSelectionMode(ReferenceBusSelectionMode.GENERATOR_REFERENCE_PRIORITY);
result = loadFlowRunner.run(network, parameters);
assertEquals(0, result.getComponentResults().get(0).getSlackBusResults().get(0).getActivePowerMismatch(), 0.01);
assertEquals(321.9, result.getComponentResults().get(0).getDistributedActivePower(), 0.01);
assertActivePowerEquals(-450.8,referenceGenerator.getTerminal()); // -128.9 - 321.9 = -450.8
}
}

0 comments on commit b0ec63f

Please sign in to comment.