Skip to content

Commit

Permalink
Refactoring of security analysis api (#1766)
Browse files Browse the repository at this point in the history
* Remove deprecated code (#1579)
* Use ServiceLoader to create SecurityAnalysis (#1585)
* Add SecurityAnalysisProvider
* Add FIXME to rename later and fix comments issues
* Remove runWithLog method in SecurityAnalysisProvider
* Replace SecurityAnalysis factory uses by loaded SecurityAnalysisProvider (#1618)
* Refactoring security-analysis-api : SecurityAnalysisImpl (issue 1604) (#1648)
* Refactoring security-analysis-api : Remove WithLog suffixed methods (#1667)
* Remove SecurityAnalysisResultWithLog class
* Replace WithLog methods with bollean usage
* Add SecurityAnalysisReport composed by SecurityAnalysisResult & LogBytes

Signed-off-by: Thomas ADAM <[email protected]>

* After rebasing: bump to 4.2.0-SNAPSHOT version + do not use "default" word in automatic module name (forbidden)
* Add default impl of API AS in distribution core
* Bump to 4.3.0-SNAPSHOT

Signed-off-by: RALAMBOTIANA MIORA <[email protected]>

* Monitor security analysis (#1737)
* On demand results for specific equipments

Signed-off-by: Etienne Lesot <[email protected]>

* Corrections following reviewer's comments:
- Rename SecurityAnalysisResult.getPreContingencyLimitViolationsResult
- Use only pre/post contingency in javadoc
- Put methods in StateMonitorJson in StateMonitor
- Clear before addAll in setMonitors
* Corrections following reviewer's comments:
- PreContingencyResult constructor requires Collections, not Maps
- Correct SecurityAnalysisResult deserializer and test files
- Optimize monitor merging in StateMonitorIndex
- Add ID-based getters in PreContingencyResult
- Delete redundant methods in SecurityAnalysisResult
- If a monitored ID does not exist, ignore it
- Add tests
* Rebasing from master and resolving conflicts


Co-authored-by: RALAMBOTIANA MIORA <[email protected]>
Co-authored-by: EtienneLt <[email protected]>
  • Loading branch information
miovd and EtienneLt authored Jun 14, 2021
1 parent 2a757fb commit 9596c01
Show file tree
Hide file tree
Showing 181 changed files with 3,281 additions and 1,758 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.powsybl.action.simulator.loadflow.RunningContext;
import com.powsybl.contingency.Contingency;
import com.powsybl.security.*;
import com.powsybl.security.results.PostContingencyResult;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.powsybl.contingency.Contingency;
import com.powsybl.iidm.network.Branch;
import com.powsybl.security.*;
import com.powsybl.security.results.PostContingencyResult;
import org.junit.Test;

import java.util.Arrays;
Expand Down Expand Up @@ -50,7 +51,7 @@ private void testSARBuilder(final boolean convergent) {
@Override
public void onFinalStateResult(SecurityAnalysisResult result) {

testLimitViolation(result.getPreContingencyResult(), convergent, Collections.singletonList("line1"), Collections.singletonList("pre-action"));
testLimitViolation(result.getPreContingencyLimitViolationsResult(), convergent, Collections.singletonList("line1"), Collections.singletonList("pre-action"));

List<PostContingencyResult> postContingencyResults = result.getPostContingencyResults();
assertEquals(1, postContingencyResults.size());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* 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.contingency;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Objects;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
* @author Etienne Lesot <etienne.lesot at rte-france.com>
* <p>
* provide the context to get information of the network after a security analysis
* it contains a contingency's id and a context type. Context type defines
* if we want the information in a pre-contingency state, a post-contingency state or both.
* contingency's id is defined if informations are needed after
* a specific contingency computation
*/
public class ContingencyContext {

private final String contingencyId;

/**
* Define if informations needed are in N_Situation, N-k Situation or both
* if it is N_situation contingencyid is null
*/
private final ContingencyContextType contextType;

public ContingencyContext(@JsonProperty("contingencyId") String contingencyId,
@JsonProperty("contextType") ContingencyContextType contingencyContextType) {
this.contextType = Objects.requireNonNull(contingencyContextType);
this.contingencyId = contingencyId;
}

public String getContingencyId() {
return contingencyId;
}

public ContingencyContextType getContextType() {
return contextType;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ContingencyContext that = (ContingencyContext) o;
return Objects.equals(contingencyId, that.contingencyId) &&
contextType == that.contextType;
}

@Override
public int hashCode() {
return Objects.hash(contingencyId, contextType);
}

@Override
public String toString() {
return "ContingencyContext(" +
"contingencyId='" + Objects.toString(contingencyId, "") + '\'' +
", contextType=" + contextType +
')';
}

public static ContingencyContext all() {
return new ContingencyContext(null, ContingencyContextType.ALL);
}

public static ContingencyContext none() {
return new ContingencyContext(null, ContingencyContextType.NONE);
}

public static ContingencyContext specificContingency(String contingencyId) {
return new ContingencyContext(contingencyId, ContingencyContextType.SPECIFIC);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* 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.contingency;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
* @author Etienne Lesot <etienne.lesot at rte-france.com>
*
* Define for a contingencyContext the type of information asked.
* It can be a pre-contingency state, a post-contingency state on a specific contingency (SPECIFIC) or both (ALL)
*/

public enum ContingencyContextType {
/**
* Corresponds to all contingencies and pre-contingency situation
*/
ALL,
/**
* Corresponds to pre-contingency situation
*/
NONE,
/**
* Corresponds to one contingency his id is specified in the contingencyContext
*/
SPECIFIC,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* 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.contingency;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public class ContingencyContextTest {

@Test
public void test() {
ContingencyContext context = new ContingencyContext("c1", ContingencyContextType.SPECIFIC);
assertEquals("ContingencyContext(contingencyId='c1', contextType=SPECIFIC)", context.toString());
}
}
7 changes: 7 additions & 0 deletions distribution-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,13 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-security-analysis-default</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-sensitivity-analysis-api</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<module>matpower</module>
<module>psse</module>
<module>scripting</module>
<module>security-analysis-api</module>
<module>security-analysis</module>
<module>sensitivity-analysis-api</module>
<module>time-series</module>
<module>tools</module>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 9596c01

Please sign in to comment.