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

Bump powsybl-core 4.3.0-alpha-1 #307

Merged
merged 12 commits into from
Jun 15, 2021
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<junit-jupiter.version>5.5.2</junit-jupiter.version>
<slf4jtoys.version>1.6.2</slf4jtoys.version>

<powsybl-core.version>4.2.0</powsybl-core.version>
<powsybl-core.version>4.3.0-alpha-1</powsybl-core.version>
</properties>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
import com.powsybl.commons.reporter.Reporter;
import com.powsybl.contingency.ContingenciesProvider;
import com.powsybl.contingency.Contingency;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.Branch;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.Switch;
import com.powsybl.iidm.network.TopologyKind;
import com.powsybl.loadflow.LoadFlowParameters;
import com.powsybl.math.matrix.MatrixFactory;
import com.powsybl.math.matrix.SparseMatrixFactory;
import com.powsybl.openloadflow.OpenLoadFlowParameters;
import com.powsybl.openloadflow.OpenLoadFlowProvider;
import com.powsybl.openloadflow.ac.nr.NewtonRaphsonStatus;
Expand All @@ -23,14 +27,17 @@
import com.powsybl.openloadflow.equations.Equation;
import com.powsybl.openloadflow.equations.EquationTerm;
import com.powsybl.openloadflow.equations.PreviousValueVoltageInitializer;
import com.powsybl.openloadflow.graph.EvenShiloachGraphDecrementalConnectivity;
import com.powsybl.openloadflow.graph.GraphDecrementalConnectivity;
import com.powsybl.openloadflow.network.*;
import com.powsybl.openloadflow.network.util.ActivePowerDistribution;
import com.powsybl.openloadflow.util.BusState;
import com.powsybl.openloadflow.util.LfContingency;
import com.powsybl.openloadflow.util.PropagatedContingency;
import com.powsybl.security.*;
import com.powsybl.security.detectors.DefaultLimitViolationDetector;
import com.powsybl.security.interceptors.SecurityAnalysisInterceptor;
import com.powsybl.security.results.PostContingencyResult;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -44,7 +51,7 @@
/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public class OpenSecurityAnalysis implements SecurityAnalysis {
public class OpenSecurityAnalysis {

private static final Logger LOGGER = LoggerFactory.getLogger(OpenSecurityAnalysis.class);

Expand All @@ -62,6 +69,14 @@ public class OpenSecurityAnalysis implements SecurityAnalysis {

private static final double POST_CONTINGENCY_INCREASING_FACTOR = 1.1;

public OpenSecurityAnalysis(Network network) {
this(network, new DefaultLimitViolationDetector(), new LimitViolationFilter());
}

public OpenSecurityAnalysis(Network network, LimitViolationDetector detector, LimitViolationFilter filter) {
this(network, detector, filter, new SparseMatrixFactory(), EvenShiloachGraphDecrementalConnectivity::new);
}

public OpenSecurityAnalysis(Network network, LimitViolationDetector detector, LimitViolationFilter filter,
MatrixFactory matrixFactory, Supplier<GraphDecrementalConnectivity<LfBus>> connectivityProvider) {
this.network = Objects.requireNonNull(network);
Expand All @@ -71,31 +86,29 @@ public OpenSecurityAnalysis(Network network, LimitViolationDetector detector, Li
this.connectivityProvider = Objects.requireNonNull(connectivityProvider);
}

@Override
public void addInterceptor(SecurityAnalysisInterceptor interceptor) {
interceptors.add(Objects.requireNonNull(interceptor));
}

@Override
public boolean removeInterceptor(SecurityAnalysisInterceptor interceptor) {
return interceptors.remove(Objects.requireNonNull(interceptor));
}

@Override
public CompletableFuture<SecurityAnalysisResult> run(String workingVariantId, SecurityAnalysisParameters securityAnalysisParameters, ContingenciesProvider contingenciesProvider) {
public CompletableFuture<SecurityAnalysisReport> run(String workingVariantId, SecurityAnalysisParameters securityAnalysisParameters,
ContingenciesProvider contingenciesProvider) {
Objects.requireNonNull(workingVariantId);
Objects.requireNonNull(securityAnalysisParameters);
Objects.requireNonNull(contingenciesProvider);
return CompletableFuture.supplyAsync(() -> {
String oldWorkingVariantId = network.getVariantManager().getWorkingVariantId();
network.getVariantManager().setWorkingVariant(workingVariantId);
SecurityAnalysisResult result = runSync(securityAnalysisParameters, contingenciesProvider);
SecurityAnalysisReport result = runSync(securityAnalysisParameters, contingenciesProvider);
network.getVariantManager().setWorkingVariant(oldWorkingVariantId);
return result;
});
}

SecurityAnalysisResult runSync(SecurityAnalysisParameters securityAnalysisParameters, ContingenciesProvider contingenciesProvider) {
SecurityAnalysisReport runSync(SecurityAnalysisParameters securityAnalysisParameters, ContingenciesProvider contingenciesProvider) {
Stopwatch stopwatch = Stopwatch.createStarted();

LoadFlowParameters lfParameters = securityAnalysisParameters.getLoadFlowParameters();
Expand Down Expand Up @@ -129,7 +142,7 @@ SecurityAnalysisResult runSync(SecurityAnalysisParameters securityAnalysisParame
stopwatch.stop();
LOGGER.info("Security analysis done in {} ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));

return result;
return new SecurityAnalysisReport(result);
}

List<LfNetwork> createNetworks(Set<Switch> allSwitchesToOpen, AcLoadFlowParameters acParameters) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* Copyright (c) 2021, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.openloadflow.sa;

import com.google.auto.service.AutoService;
import com.powsybl.computation.ComputationManager;
import com.powsybl.contingency.ContingenciesProvider;
import com.powsybl.iidm.network.Network;
import com.powsybl.math.matrix.DenseMatrixFactory;
import com.powsybl.math.matrix.MatrixFactory;
import com.powsybl.openloadflow.graph.EvenShiloachGraphDecrementalConnectivity;
import com.powsybl.openloadflow.graph.GraphDecrementalConnectivity;
import com.powsybl.openloadflow.network.LfBus;
import com.powsybl.openloadflow.util.PowsyblOpenLoadFlowVersion;
import com.powsybl.security.*;
import com.powsybl.security.interceptors.SecurityAnalysisInterceptor;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;

/**
* @author Florian Dupuy <florian.dupuy at rte-france.com>
*/
@AutoService(SecurityAnalysisProvider.class)
public class OpenSecurityAnalysisProvider implements SecurityAnalysisProvider {

private final MatrixFactory matrixFactory;

private final Supplier<GraphDecrementalConnectivity<LfBus>> connectivityProvider;

public OpenSecurityAnalysisProvider(MatrixFactory matrixFactory, Supplier<GraphDecrementalConnectivity<LfBus>> connectivityProvider) {
this.matrixFactory = matrixFactory;
this.connectivityProvider = connectivityProvider;
}

public OpenSecurityAnalysisProvider() {
this(new DenseMatrixFactory(), EvenShiloachGraphDecrementalConnectivity::new);
}

@Override
public CompletableFuture<SecurityAnalysisReport> run(Network network, String workingVariantId, LimitViolationDetector limitViolationDetector,
LimitViolationFilter limitViolationFilter, ComputationManager computationManager,
SecurityAnalysisParameters securityAnalysisParameters, ContingenciesProvider contingenciesProvider,
List<SecurityAnalysisInterceptor> interceptors) {
OpenSecurityAnalysis osa = new OpenSecurityAnalysis(network, limitViolationDetector, limitViolationFilter, matrixFactory, connectivityProvider);
interceptors.forEach(osa::addInterceptor);
return osa.run(workingVariantId, securityAnalysisParameters, contingenciesProvider);
}

@Override
public String getName() {
return "OpenSecurityAnalysis";
}

@Override
public String getVersion() {
return new PowsyblOpenLoadFlowVersion().toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@
import com.powsybl.contingency.Contingency;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.test.FourSubstationsNodeBreakerFactory;
import com.powsybl.math.matrix.DenseMatrixFactory;
import com.powsybl.openloadflow.graph.EvenShiloachGraphDecrementalConnectivity;
import com.powsybl.openloadflow.network.LfNetwork;
import com.powsybl.openloadflow.network.MostMeshedSlackBusSelector;
import com.powsybl.openloadflow.util.LfContingency;
import com.powsybl.openloadflow.util.PropagatedContingency;
import com.powsybl.security.LimitViolationFilter;
import com.powsybl.security.detectors.DefaultLimitViolationDetector;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -55,7 +59,8 @@ void test() throws IOException {
LfNetwork mainNetwork = lfNetworks.get(0);
assertEquals(2, lfNetworks.size());

OpenSecurityAnalysis sa = new OpenSecurityAnalysisFactory().create(network, null, 0);
OpenSecurityAnalysis sa = new OpenSecurityAnalysis(network, new DefaultLimitViolationDetector(),
new LimitViolationFilter(), new DenseMatrixFactory(), EvenShiloachGraphDecrementalConnectivity::new);

String branchId = "LINE_S3S4";
Contingency contingency = new Contingency(branchId, new BranchContingency(branchId));
Expand Down
Loading