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

Use dense matrix factory everywhere in tests #851

Merged
merged 1 commit into from
Sep 23, 2023
Merged
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 @@ -272,7 +272,7 @@ void testDisabledNonImpedantBranch() {

LoadFlowParameters parameters = new LoadFlowParameters()
.setDc(true);
LoadFlow.run(network, parameters);
loadFlowRunner.run(network, parameters);

assertActivePowerEquals(400.0, network.getLine("L1").getTerminal1());
assertActivePowerEquals(100.0, network.getLine("L2").getTerminal1());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,27 @@
import com.powsybl.computation.ComputationManager;
import com.powsybl.contingency.*;
import com.powsybl.iidm.network.*;
import com.powsybl.loadflow.LoadFlow;
import com.powsybl.loadflow.LoadFlowParameters;
import com.powsybl.loadflow.LoadFlowResult;
import com.powsybl.math.matrix.DenseMatrixFactory;
import com.powsybl.math.matrix.MatrixFactory;
import com.powsybl.openloadflow.OpenLoadFlowParameters;
import com.powsybl.openloadflow.OpenLoadFlowProvider;
import com.powsybl.openloadflow.graph.EvenShiloachGraphDecrementalConnectivityFactory;
import com.powsybl.openloadflow.graph.GraphConnectivityFactory;
import com.powsybl.openloadflow.network.*;
import com.powsybl.security.*;
import com.powsybl.security.action.Action;
import com.powsybl.security.detectors.DefaultLimitViolationDetector;
import com.powsybl.security.monitor.StateMonitor;
import com.powsybl.security.results.*;
import com.powsybl.security.strategy.OperatorStrategy;
import org.junit.jupiter.api.BeforeEach;
import org.mockito.Mockito;

import java.util.*;
import java.util.concurrent.ForkJoinPool;
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.*;
Expand All @@ -41,6 +48,19 @@ public abstract class AbstractOpenSecurityAnalysisTest {

protected OpenLoadFlowProvider loadFlowProvider;

protected LoadFlow.Runner loadFlowRunner;

@BeforeEach
void setUp() {
computationManager = Mockito.mock(ComputationManager.class);
Mockito.when(computationManager.getExecutor()).thenReturn(ForkJoinPool.commonPool());
matrixFactory = new DenseMatrixFactory();
GraphConnectivityFactory<LfBus, LfBranch> connectivityFactory = new EvenShiloachGraphDecrementalConnectivityFactory<>();
securityAnalysisProvider = new OpenSecurityAnalysisProvider(matrixFactory, connectivityFactory);
loadFlowProvider = new OpenLoadFlowProvider(matrixFactory, connectivityFactory);
loadFlowRunner = new LoadFlow.Runner(loadFlowProvider);
}

protected static Network createNodeBreakerNetwork() {
Network network = NodeBreakerNetworkFactory.create();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.powsybl.commons.PowsyblException;
import com.powsybl.commons.reporter.Reporter;
import com.powsybl.commons.reporter.ReporterModel;
import com.powsybl.computation.ComputationManager;
import com.powsybl.contingency.*;
import com.powsybl.ieeecdf.converter.IeeeCdfNetworkFactory;
import com.powsybl.iidm.network.*;
Expand All @@ -20,29 +19,21 @@
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import com.powsybl.iidm.network.test.FourSubstationsNodeBreakerFactory;
import com.powsybl.iidm.network.test.SecurityAnalysisTestNetworkFactory;
import com.powsybl.loadflow.LoadFlow;
import com.powsybl.loadflow.LoadFlowParameters;
import com.powsybl.loadflow.LoadFlowResult;
import com.powsybl.math.matrix.DenseMatrixFactory;
import com.powsybl.openloadflow.OpenLoadFlowParameters;
import com.powsybl.openloadflow.OpenLoadFlowProvider;
import com.powsybl.openloadflow.ac.nr.NewtonRaphsonStatus;
import com.powsybl.openloadflow.graph.EvenShiloachGraphDecrementalConnectivityFactory;
import com.powsybl.openloadflow.graph.GraphConnectivityFactory;
import com.powsybl.openloadflow.network.*;
import com.powsybl.openloadflow.network.impl.OlfBranchResult;
import com.powsybl.openloadflow.util.LoadFlowAssert;
import com.powsybl.security.*;
import com.powsybl.security.monitor.StateMonitor;
import com.powsybl.security.results.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.io.IOException;
import java.util.*;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ForkJoinPool;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -56,16 +47,6 @@
*/
class OpenSecurityAnalysisTest extends AbstractOpenSecurityAnalysisTest {

@BeforeEach
void setUp() {
computationManager = Mockito.mock(ComputationManager.class);
Mockito.when(computationManager.getExecutor()).thenReturn(ForkJoinPool.commonPool());
matrixFactory = new DenseMatrixFactory();
GraphConnectivityFactory<LfBus, LfBranch> connectivityFactory = new EvenShiloachGraphDecrementalConnectivityFactory<>();
securityAnalysisProvider = new OpenSecurityAnalysisProvider(matrixFactory, connectivityFactory);
loadFlowProvider = new OpenLoadFlowProvider(matrixFactory, connectivityFactory);
}

@Test
void testCurrentLimitViolations() {
Network network = createNodeBreakerNetwork();
Expand Down Expand Up @@ -1586,7 +1567,7 @@ void testThreeWindingsTransformerContingency() {
network.getThreeWindingsTransformer("T3wT").getLeg2().getTerminal().disconnect();
network.getThreeWindingsTransformer("T3wT").getLeg3().getTerminal().disconnect();
setSlackBusId(parameters, "VL_1");
LoadFlow.run(network, parameters);
loadFlowRunner.run(network, parameters);

PostContingencyResult contingencyResult = getPostContingencyResult(result, "T3wT");
assertEquals(network.getLine("LINE_12").getTerminal2().getP(), contingencyResult.getNetworkResult().getBranchResult("LINE_12").getP2(), LoadFlowAssert.DELTA_POWER);
Expand Down Expand Up @@ -1753,7 +1734,7 @@ void testStaticVarCompensatorContingency() {

// compare with a simple load low
network.getStaticVarCompensator("svc1").getTerminal().disconnect();
LoadFlow.run(network, parameters.getLoadFlowParameters());
loadFlowRunner.run(network, parameters.getLoadFlowParameters());

PostContingencyResult postContingencyResult = getPostContingencyResult(result, "svc1");
assertEquals(network.getLine("l1").getTerminal1().getP(), postContingencyResult.getNetworkResult().getBranchResult("l1").getP1(), LoadFlowAssert.DELTA_POWER);
Expand Down Expand Up @@ -1785,7 +1766,7 @@ void testStaticVarCompensatorContingencyWithStandByAutomaton() {

// compare with a simple load low
network.getStaticVarCompensator("svc1").getTerminal().disconnect();
LoadFlow.run(network);
loadFlowRunner.run(network);

PostContingencyResult postContingencyResult = getPostContingencyResult(result, "svc1");
assertEquals(network.getLine("l1").getTerminal1().getP(), postContingencyResult.getNetworkResult().getBranchResult("l1").getP1(), LoadFlowAssert.DELTA_POWER);
Expand All @@ -1796,7 +1777,7 @@ void testStaticVarCompensatorContingencyWithStandByAutomaton() {
// test restore.
network.getStaticVarCompensator("svc1").getTerminal().connect();
network.getLoad("ld1").getTerminal().disconnect();
LoadFlow.run(network);
loadFlowRunner.run(network);
PostContingencyResult postContingencyResult2 = getPostContingencyResult(result, "ld1");
assertEquals(network.getLine("l1").getTerminal1().getP(), postContingencyResult2.getNetworkResult().getBranchResult("l1").getP1(), LoadFlowAssert.DELTA_POWER);
assertEquals(network.getLine("l1").getTerminal2().getP(), postContingencyResult2.getNetworkResult().getBranchResult("l1").getP2(), LoadFlowAssert.DELTA_POWER);
Expand Down
Loading
Loading