Skip to content

Commit

Permalink
Merge branch 'master' into eurostag_forbidden_chars
Browse files Browse the repository at this point in the history
  • Loading branch information
mathbagu committed Mar 27, 2017
2 parents c4f9b02 + 84dd3cd commit ce3975a
Show file tree
Hide file tree
Showing 55 changed files with 4,470 additions and 634 deletions.
@@ -1,6 +1,6 @@
/**
* Copyright (c) 2016, All partners of the iTesla project (http://www.itesla-project.eu/consortium)
* Copyright (c) 2016, RTE (http://www.rte-france.com)
* Copyright (c) 2016-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/.
Expand Down Expand Up @@ -1207,13 +1207,17 @@ private void writeStaticVarCompensators(AmplExportContext context) throws IOExce
!append,
LOCALE,
new Column("num"),
new Column("fault"),
new Column(config.getActionType().getLabel()),
new Column("id"))) {
List<String> skipped = new ArrayList<>();
for (StaticVarCompensator svc : network.getStaticVarCompensators()) {
// FIXME
String id = svc.getId();
int num = mapper.getInt(AmplSubset.STATIC_VAR_COMPENSATOR, id);
formatter.writeCell(num)
.writeCell(faultNum)
.writeCell(actionNum)
.writeCell(id);
}
if (skipped.size() > 0) {
Expand Down Expand Up @@ -1398,13 +1402,17 @@ private void writeHVDCLines(AmplExportContext context) throws IOException {
!append,
LOCALE,
new Column("num"),
new Column("fault"),
new Column(config.getActionType().getLabel()),
new Column("id"))) {
List<String> skipped = new ArrayList<>();
for (HvdcLine hvdcLine : network.getHvdcLines()) {
// FIXME
String id = hvdcLine.getId();
int num = mapper.getInt(AmplSubset.HVDC_LINE, id);
formatter.writeCell(num)
.writeCell(faultNum)
.writeCell(actionNum)
.writeCell(id);
}
if (skipped.size() > 0) {
Expand Down
4 changes: 2 additions & 2 deletions ampl-export/src/test/resources/lcc-test-case.txt
@@ -1,3 +1,3 @@
#HVDC lines (hvdctest/InitialState)
#"num" "id"
1 "L"
#"num" "fault" "curative" "id"
1 0 0 "L"
4 changes: 2 additions & 2 deletions ampl-export/src/test/resources/svc-test-case.txt
@@ -1,3 +1,3 @@
#Static VAR compensators (svcTestCase/InitialState)
#"num" "id"
1 "SVC2"
#"num" "fault" "curative" "id"
1 0 0 "SVC2"
4 changes: 2 additions & 2 deletions ampl-export/src/test/resources/vsc-test-case.txt
@@ -1,3 +1,3 @@
#HVDC lines (hvdctest/InitialState)
#"num" "id"
1 "L"
#"num" "fault" "curative" "id"
1 0 0 "L"
@@ -1,6 +1,6 @@
/**
* Copyright (c) 2016, All partners of the iTesla project (http://www.itesla-project.eu/consortium)
* Copyright (c) 2016, RTE (http://www.rte-france.com)
* Copyright (c) 2016-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/.
Expand All @@ -18,7 +18,6 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand All @@ -33,7 +32,6 @@
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;

import eu.itesla_project.iidm.actions_contingencies.xml.mapping.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;
Expand All @@ -42,8 +40,32 @@
import eu.itesla_project.contingency.ContingencyImpl;
import eu.itesla_project.contingency.GeneratorContingency;
import eu.itesla_project.contingency.LineContingency;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Action;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.ActionCtgAssociations;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.ActionPlan;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.ActionsContingencies;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.And;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Association;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Constraint;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Contingency;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.ElementaryAction;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Equipment;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.GenerationOperation;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.LineOperation;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.LogicalExpression;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Operand;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Or;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Parameter;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.PstOperation;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Redispatching;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.SwitchOperation;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Then;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.VoltageLevel;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Zone;
import eu.itesla_project.iidm.actions_contingencies.xml.mapping.Zones;
import eu.itesla_project.iidm.network.Line;
import eu.itesla_project.iidm.network.Network;
import eu.itesla_project.iidm.network.Switch;
import eu.itesla_project.iidm.network.TieLine;
import eu.itesla_project.modules.contingencies.ActionElement;
import eu.itesla_project.modules.contingencies.ActionPlanOption;
Expand Down Expand Up @@ -859,51 +881,16 @@ else if (go.getAction().equals("start")
LOGGER.warn("GenerationOperation : generator id not found: " + genId);
}

for (SwitchOperation sw : ele.getSwitchOperation()) {

String switchId = sw.getId();
String vlId = null;
Zones eleZones = ele.getZones();
if ( eleZones != null ) {
for(BigInteger zoneNum : eleZones.getNum()) {
String zoneId = zonesMapping.get(zoneNum);
eu.itesla_project.modules.contingencies.Zone z = getZone(zoneId);
Collection<eu.itesla_project.modules.contingencies.VoltageLevel> levels = z.getVoltageLevels();
for (eu.itesla_project.modules.contingencies.VoltageLevel l : levels) {
String lid = l.getId();
eu.itesla_project.iidm.network.VoltageLevel vl = network
.getVoltageLevel(lid);
if (vl != null
&& vl.getBusBreakerView().getSwitch(switchId) != null) {
vlId = vl.getId();
break;
}
}
}
}

if (vlId == null) // search all network
{
LOGGER.info("No match found for "+switchId +" among the switches of the switch zones voltage levels. Search continues on all network switches... " );
Iterator<eu.itesla_project.iidm.network.VoltageLevel> it = network
.getVoltageLevels().iterator();
while (it.hasNext()) {
eu.itesla_project.iidm.network.VoltageLevel vl = it.next();
if (vl.getBusBreakerView().getSwitch(switchId) != null) {
vlId = vl.getId();
break;
}

}
}

if (vlId != null) {
if (sw.getAction().equals("opening"))
elements.add(new SwitchOpeningAction(vlId, switchId, sw.getImplementationTime(), sw.getAchievmentIndex()));
else if (sw.getAction().equals("closing"))
elements.add(new SwitchClosingAction(vlId, switchId, sw.getImplementationTime(), sw.getAchievmentIndex()));
for (SwitchOperation swOp : ele.getSwitchOperation()) {
String switchId = swOp.getId();
Switch sw = network.getSwitch(switchId);
if (sw != null) {
if (swOp.getAction().equals("opening"))
elements.add(new SwitchOpeningAction(sw.getVoltageLevel().getId(), switchId, swOp.getImplementationTime(), swOp.getAchievmentIndex()));
else if (swOp.getAction().equals("closing"))
elements.add(new SwitchClosingAction(sw.getVoltageLevel().getId(), switchId, swOp.getImplementationTime(), swOp.getAchievmentIndex()));
} else
LOGGER.warn("No match found for " + switchId + " among all network switches. The switch is eliminated from the action element list");
LOGGER.warn("SwitchOperation : switch id not found: " + switchId);

}

Expand Down
@@ -1,42 +1,164 @@
/**
* Copyright (c) 2016, RTE (http://www.rte-france.com)
* Copyright (c) 2016-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.iidm.actions_contingencies.xml.test;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.math.BigInteger;
import java.net.URL;
import java.util.Collection;
import java.util.List;

import javax.xml.bind.JAXBException;

import org.junit.Test;
import org.xml.sax.SAXException;

import eu.itesla_project.contingency.Contingency;
import eu.itesla_project.contingency.ContingencyElement;
import eu.itesla_project.contingency.ContingencyElementType;
import eu.itesla_project.iidm.actions_contingencies.xml.XmlFileContingenciesAndActionsDatabaseClient;
import eu.itesla_project.iidm.network.Network;
import eu.itesla_project.modules.contingencies.Action;
import eu.itesla_project.modules.contingencies.ActionElement;
import eu.itesla_project.modules.contingencies.ActionElementType;
import eu.itesla_project.modules.contingencies.ActionPlan;
import eu.itesla_project.modules.contingencies.ActionPlanOption;
import eu.itesla_project.modules.contingencies.ActionsContingenciesAssociation;
import eu.itesla_project.modules.contingencies.ConstraintType;
import eu.itesla_project.modules.contingencies.ContingenciesAndActionsDatabaseClient;
import org.xml.sax.SAXException;

import javax.xml.bind.JAXBException;
import eu.itesla_project.modules.contingencies.Zone;

/**
*
* @author Quinary <itesla@quinary.com>
*/
public class ACXmlClientTest {

@Test
public void test() {
try {
URL config = getClass().getResource("/test-ac.xml");
ContingenciesAndActionsDatabaseClient client = new XmlFileContingenciesAndActionsDatabaseClient(config);
client.getActionPlans();
client.getZones();

} catch (JAXBException | SAXException | IOException e) {
e.printStackTrace();
fail("Error " + e.getMessage());
}
public void test() throws JAXBException, SAXException, IOException {

URL testActionsUrl = getClass().getResource("/test-ac.xml");
ContingenciesAndActionsDatabaseClient cadbClient = new XmlFileContingenciesAndActionsDatabaseClient(testActionsUrl);
Network network = ACXmlClientTestUtils.getNetwork();

// Collection<Zone> getZones();
Collection<Zone> zones = cadbClient.getZones();
assertEquals(1, zones.size());
checkZone(zones.iterator().next(), BigInteger.ONE, "ZONE1", "zone one", 2);
// Collection<Zone> getZones(Network network);
zones = cadbClient.getZones(network);
assertEquals(1, zones.size());
checkZone(zones.iterator().next(), BigInteger.ONE, "ZONE1", "zone one", 2);
// Zone getZone(String id);
Zone zone = cadbClient.getZone("ZONE1");
checkZone(zone, BigInteger.ONE, "ZONE1", "zone one", 2);

// List<Contingency> getContingencies(Network network);
List<Contingency> contingencies = cadbClient.getContingencies(network);
assertEquals(1, contingencies.size());
checkContingency(contingencies.iterator().next(), "N-1_Contingency", 1, "LINE1_ACLS", ContingencyElementType.LINE);
// Contingency getContingency(String id, Network network);
Contingency contingency = cadbClient.getContingency("N-1_Contingency", network);
checkContingency(contingency, "N-1_Contingency", 1, "LINE1_ACLS", ContingencyElementType.LINE);

// Collection<Action> getActions(Network network);
Collection<Action> actions = cadbClient.getActions(network);
assertEquals(2, actions.size());
checkAction(actions.iterator().next(), "Action1", 120, 1, "LINE1_ACLS", ActionElementType.LINE_TRIPPING);
// Action getAction(String id, Network network);
Action action = cadbClient.getAction("Action1", network);
checkAction(action, "Action1", 120, 1, "LINE1_ACLS", ActionElementType.LINE_TRIPPING);

// Collection<ActionPlan> getActionPlans();
Collection<ActionPlan> actionPlans = cadbClient.getActionPlans();
assertEquals(1, actionPlans.size());
checkActionPlan(actionPlans.iterator().next(), "Plan1", 1, 2, "Action1");
// Collection<ActionPlaactionPlans = client.getActionPlans();
actionPlans = cadbClient.getActionPlans(network);
assertEquals(1, actionPlans.size());
checkActionPlan(actionPlans.iterator().next(), "Plan1", 1, 2, "Action1");
// ActionPlan getActionPlan(String id);
ActionPlan actionPlan = cadbClient.getActionPlan("Plan1");
checkActionPlan(actionPlan, "Plan1", 1, 2, "Action1");

// Collection<ActionsContingenciesAssociation> getActionsCtgAssociations();
Collection<ActionsContingenciesAssociation> actionCtgAssociations = cadbClient.getActionsCtgAssociations();
assertEquals(2, actionCtgAssociations.size());
checkAssociation(actionCtgAssociations.iterator().next(), 1, "N-1_Contingency", "Action2", "LINE1_ACLS", ConstraintType.BRANCH_OVERLOAD);
// List<ActionsContingenciesAssociation> getActionsCtgAssociations(Network network);
actionCtgAssociations = cadbClient.getActionsCtgAssociations(network);
assertEquals(2, actionCtgAssociations.size());
checkAssociation(actionCtgAssociations.iterator().next(), 1, "N-1_Contingency", "Action2", "LINE1_ACLS", ConstraintType.BRANCH_OVERLOAD);
// Collection<ActionsContingenciesAssociation> getActionsCtgAssociationsByContingency(String contingencyId);
actionCtgAssociations = cadbClient.getActionsCtgAssociationsByContingency("N-1_Contingency");
assertEquals(1, actionCtgAssociations.size());
checkAssociation(actionCtgAssociations.iterator().next(), 1, "N-1_Contingency", "Action2", "LINE1_ACLS", ConstraintType.BRANCH_OVERLOAD);
// Collection<ActionsContingenciesAssociation> getActionsCtgAssociationsByConstraint(String equipmentId, ConstraintType constraintType);
actionCtgAssociations = cadbClient.getActionsCtgAssociationsByConstraint("LINE1_ACLS", ConstraintType.BRANCH_OVERLOAD);
assertEquals(1, actionCtgAssociations.size());
checkAssociation(actionCtgAssociations.iterator().next(), 1, "N-1_Contingency", "Action2", "LINE1_ACLS", ConstraintType.BRANCH_OVERLOAD);
actionCtgAssociations = cadbClient.getActionsCtgAssociationsByConstraint("LINE2_ACLS", ConstraintType.BRANCH_OVERLOAD);
assertEquals(1, actionCtgAssociations.size());
checkAssociation(actionCtgAssociations.iterator().next(), 0, null, "Action1", "LINE2_ACLS", ConstraintType.BRANCH_OVERLOAD);
}

private void checkZone(Zone zone, BigInteger number, String name, String description, int numVoltageLevels) {
assertNotNull(zone);
assertEquals(number, zone.getNumber());
assertEquals(name, zone.getName());
assertEquals(description, zone.getDescription());
assertEquals(numVoltageLevels, zone.getVoltageLevels().size());
}

private void checkContingency(Contingency contingency, String contingencyId, int numEquipments, String equipmentId, ContingencyElementType equipmentType) {
assertNotNull(contingency);
assertEquals(contingencyId, contingency.getId());
assertEquals(numEquipments, contingency.getElements().size());
ContingencyElement contingencyElement = contingency.getElements().iterator().next();
assertEquals(equipmentId, contingencyElement.getId());
assertEquals(equipmentType, contingencyElement.getType());
}

private void checkAction(Action action, String actionId, int startTime, int numEquipments, String equipmentId, ActionElementType equipmentType) {
assertNotNull(action);
assertEquals(actionId, action.getId());
assertTrue(action.isCurative());
assertTrue(action.isPreventive());
assertEquals(BigInteger.valueOf(startTime), action.getStartTime());
assertEquals(numEquipments, action.getElements().size());
ActionElement actionElement = action.getElements().iterator().next();
assertEquals(equipmentId, actionElement.getEquipmentId());
assertEquals(equipmentType, actionElement.getType());
}

private void checkActionPlan(ActionPlan actionPlan, String name, int numOptions, int numActions, String actionId) {
assertNotNull(actionPlan);
assertEquals(name, actionPlan.getName());
assertEquals(numOptions, actionPlan.getPriorityOption().size());
ActionPlanOption option = actionPlan.getPriorityOption().values().iterator().next();
assertEquals(numActions, option.getActions().size());
assertEquals(actionId, option.getActions().values().iterator().next());
}

private void checkAssociation(ActionsContingenciesAssociation actionCtgAssociation, int numContingencies, String contingencyId, String actionId,
String equipmentId, ConstraintType constraintType) {
assertNotNull(actionCtgAssociation);
assertEquals(numContingencies, actionCtgAssociation.getContingenciesId().size());
if ( numContingencies > 0 )
assertEquals(contingencyId, actionCtgAssociation.getContingenciesId().iterator().next());
assertEquals(1, actionCtgAssociation.getActionsId().size());
assertEquals(actionId, actionCtgAssociation.getActionsId().iterator().next());
assertEquals(1, actionCtgAssociation.getConstraints().size());
assertEquals(equipmentId, actionCtgAssociation.getConstraints().iterator().next().getEquipment());
assertEquals(constraintType, actionCtgAssociation.getConstraints().iterator().next().getType());
}

}

0 comments on commit ce3975a

Please sign in to comment.