Skip to content
This repository has been archived by the owner on May 16, 2018. It is now read-only.

Commit

Permalink
Improve security-analysis results (#199)
Browse files Browse the repository at this point in the history
Improve security-analysis results
  • Loading branch information
mathbagu authored and geofjamg committed Aug 30, 2017
1 parent 45209b5 commit e256ee2
Show file tree
Hide file tree
Showing 23 changed files with 484 additions and 317 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void start(ActionDb actionDb, List<String> contingencyIds) {
}
}

protected LoadFlowFactory newLoadLoadLowFactory() {
protected LoadFlowFactory newLoadFlowFactory() {
try {
return config.getLoadFlowFactoryClass().newInstance();
} catch (InstantiationException e) {
Expand All @@ -136,7 +136,7 @@ private boolean next(ActionDb actionDb, RunningContext context) {
observers.forEach(o -> o.roundBegin(context.getContingency(), context.getRound()));
}

LoadFlowFactory loadFlowFactory = newLoadLoadLowFactory();
LoadFlowFactory loadFlowFactory = newLoadFlowFactory();
LoadFlow loadFlow = loadFlowFactory.create(context.getNetwork(), computationManager, 0);

LOGGER.info("Running loadflow ({})", loadFlow.getName());
Expand All @@ -147,7 +147,7 @@ private boolean next(ActionDb actionDb, RunningContext context) {
throw new RuntimeException(e);
}
if (result.isOk()) {
List<LimitViolation> violations = LIMIT_VIOLATION_FILTER.apply(Security.checkLimits(context.getNetwork(), Security.CurrentLimitType.TATL, 1));
List<LimitViolation> violations = LIMIT_VIOLATION_FILTER.apply(Security.checkLimits(context.getNetwork(), 1));
if (violations.size() > 0) {
LOGGER.info("Violations: \n{}", Security.printLimitsViolations(violations, NO_FILTER));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void setUp() throws Exception {
actionDb = new ActionDslLoader(src).load(network);
engine = new LoadFlowActionSimulator(network, computationManager, new LoadFlowActionSimulatorConfig(LoadFlowFactory.class, 3, false), observer) {
@Override
protected LoadFlowFactory newLoadLoadLowFactory() {
protected LoadFlowFactory newLoadFlowFactory() {
return loadFlowFactory;
}
};
Expand Down
5 changes: 5 additions & 0 deletions commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
</build>

<dependencies>
<!-- Compilation dependencies -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
Expand Down
59 changes: 59 additions & 0 deletions commons/src/main/java/eu/itesla_project/commons/json/JsonUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Copyright (c) 2017, 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 eu.itesla_project.commons.json;

import com.fasterxml.jackson.core.JsonGenerator;
import com.google.common.base.Strings;

import java.io.IOException;
import java.util.Objects;

/**
* @author Mathieu Bague <[email protected]>
*/
public final class JsonUtil {

private JsonUtil() {
}

public static void writeOptionalStringField(JsonGenerator jsonGenerator, String fieldName, String value) throws IOException {
Objects.requireNonNull(jsonGenerator);
Objects.requireNonNull(fieldName);

if (!Strings.isNullOrEmpty(value)) {
jsonGenerator.writeStringField(fieldName, value);
}
}

public static void writeOptionalEnumField(JsonGenerator jsonGenerator, String fieldName, Enum<?> value) throws IOException {
Objects.requireNonNull(jsonGenerator);
Objects.requireNonNull(fieldName);

if (value != null) {
jsonGenerator.writeStringField(fieldName, value.name());
}
}

public static void writeOptionalFloatField(JsonGenerator jsonGenerator, String fieldName, float value) throws IOException {
Objects.requireNonNull(jsonGenerator);
Objects.requireNonNull(fieldName);

if (!Float.isNaN(value)) {
jsonGenerator.writeNumberField(fieldName, value);
}
}

public static void writeOptionalIntegerField(JsonGenerator jsonGenerator, String fieldName, int value) throws IOException {
Objects.requireNonNull(jsonGenerator);
Objects.requireNonNull(fieldName);

if (value != Integer.MAX_VALUE) {
jsonGenerator.writeNumberField(fieldName, value);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public ContingencyElement deserialize(JsonParser parser, DeserializationContext
if (type != null) {
switch (type) {
case LINE:
return new LineContingency(id, voltageLevelId);

case BRANCH:
return new BranchContingency(id, voltageLevelId);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright (c) 2017, 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 eu.itesla_project.contingency.json;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import eu.itesla_project.commons.json.JsonUtil;
import eu.itesla_project.contingency.BranchContingency;
import eu.itesla_project.contingency.ContingencyElement;

import java.io.IOException;

/**
* @author Mathieu Bague <[email protected]>
*/
public class ContingencyElementSerializer extends StdSerializer<ContingencyElement> {

public ContingencyElementSerializer() {
super(ContingencyElement.class);
}

@Override
public void serialize(ContingencyElement contingencyElement, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField("id", contingencyElement.getId());
jsonGenerator.writeStringField("type", contingencyElement.getType().name());
if (contingencyElement instanceof BranchContingency) {
BranchContingency branchContingencyElement = (BranchContingency) contingencyElement;
JsonUtil.writeOptionalStringField(jsonGenerator, "voltageLevelId", branchContingencyElement.getVoltageLevelId());
}
jsonGenerator.writeEndObject();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ private static Contingency create() {
List<ContingencyElement> elements = new ArrayList<>();
elements.add(new BranchContingency("NHV1_NHV2_2", "VLHV1"));
elements.add(new BranchContingency("NHV1_NHV2_1"));
elements.add(new LineContingency("NHV1_NHV2_2", "VLHV1"));
elements.add(new LineContingency("NHV1_NHV2_2"));
elements.add(new GeneratorContingency("GEN"));
elements.add(new BusbarSectionContingency("BBS1"));

Expand Down Expand Up @@ -51,8 +53,11 @@ private static void write(Contingency object, Path jsonFile) {

try (OutputStream os = Files.newOutputStream(jsonFile)) {
ObjectMapper mapper = new ObjectMapper();
ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
SimpleModule module = new SimpleModule();
module.addSerializer(ContingencyElement.class, new ContingencyElementSerializer());
mapper.registerModule(module);

ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
writer.writeValue(os, object);
} catch (IOException e) {
throw new UncheckedIOException(e);
Expand Down
12 changes: 9 additions & 3 deletions contingency-api/src/test/resources/contingency.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
"id" : "contingency",
"elements" : [ {
"id" : "NHV1_NHV2_2",
"voltageLevelId" : "VLHV1",
"type" : "BRANCH"
"type" : "BRANCH",
"voltageLevelId" : "VLHV1"
}, {
"id" : "NHV1_NHV2_1",
"voltageLevelId" : null,
"type" : "BRANCH"
}, {
"id" : "NHV1_NHV2_2",
"type" : "LINE",
"voltageLevelId" : "VLHV1"
}, {
"id" : "NHV1_NHV2_2",
"type" : "LINE"
}, {
"id" : "GEN",
"type" : "GENERATOR"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ interface Overload {

Terminal getTerminal(String voltageLevelId);

CurrentLimits getCurrentLimits(Side side);

CurrentLimits getCurrentLimits1();

CurrentLimitsAdder newCurrentLimits1();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ public void setCurrentLimits(Branch.Side side, CurrentLimitsImpl limits) {
}
}

public CurrentLimits getCurrentLimits(Side side) {
switch (side) {
case ONE:
return limits1;
case TWO:
return limits2;
default:
throw new InternalError();
}

}

public CurrentLimits getCurrentLimits1() {
return limits1;
}
Expand Down
Loading

0 comments on commit e256ee2

Please sign in to comment.