Skip to content

Commit

Permalink
Fix shunt compensator component type (#419)
Browse files Browse the repository at this point in the history
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
  • Loading branch information
geofjamg authored Oct 14, 2022
1 parent 2c3c02c commit 6e2b25a
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,19 @@ private void addSnakeEdges(SubstationGraph graph, Substation substation) {
.collect(Collectors.toList()));
}

static boolean isCapacitor(ShuntCompensator sc) {
switch (sc.getModelType()) {
case LINEAR:
return ((ShuntCompensatorLinearModel) sc.getModel()).getBPerSection() >= 0;
case NON_LINEAR:
ShuntCompensatorNonLinearModel model = (ShuntCompensatorNonLinearModel) sc.getModel();
double averageB = model.getAllSections().stream().mapToDouble(ShuntCompensatorNonLinearModel.Section::getB).average().orElse(0);
return averageB >= 0;
default:
throw new IllegalStateException("Unknown shunt compensator model type: " + sc.getModelType());
}
}

private abstract static class AbstractGraphBuilder extends DefaultTopologyVisitor {

protected final VoltageLevelGraph graph;
Expand Down Expand Up @@ -219,8 +232,7 @@ private FeederNode createFeederNode(VoltageLevelGraph graph, Injection<?> inject
case STATIC_VAR_COMPENSATOR:
return NodeFactory.createStaticVarCompensator(graph, injection.getId(), injection.getNameOrId());
case SHUNT_COMPENSATOR:
// FIXME(mathbagu): Non linear shunt can be capacitor or inductor depending on the number of section enabled
return ((ShuntCompensator) injection).getB() >= 0 ? NodeFactory.createCapacitor(graph, injection.getId(), injection.getNameOrId())
return isCapacitor((ShuntCompensator) injection) ? NodeFactory.createCapacitor(graph, injection.getId(), injection.getNameOrId())
: NodeFactory.createInductor(graph, injection.getId(), injection.getNameOrId());
case DANGLING_LINE:
return NodeFactory.createDanglingLine(graph, injection.getId(), injection.getNameOrId());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Copyright (c) 2022, 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.sld.builders;

import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import org.junit.Test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

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

@Test
public void isCapacitorTest() {
Network network = EurostagTutorialExample1Factory.create();
VoltageLevel vlload = network.getVoltageLevel("VLLOAD");
ShuntCompensator sc = vlload.newShuntCompensator()
.setId("SC")
.setConnectableBus("NLOAD")
.newLinearModel()
.setBPerSection(0.05)
.setMaximumSectionCount(1)
.add()
.setSectionCount(0)
.add();
assertTrue(NetworkGraphBuilder.isCapacitor(sc));
sc.getModel(ShuntCompensatorLinearModel.class).setBPerSection(-0.03);
assertFalse(NetworkGraphBuilder.isCapacitor(sc));
ShuntCompensator sc2 = vlload.newShuntCompensator()
.setId("SC2")
.setConnectableBus("NLOAD")
.newNonLinearModel()
.beginSection()
.setB(0.05)
.endSection()
.beginSection()
.setB(-0.02)
.endSection()
.add()
.setSectionCount(0)
.add();
assertTrue(NetworkGraphBuilder.isCapacitor(sc2));
sc2.getModel(ShuntCompensatorNonLinearModel.class).getAllSections().get(1).setB(-0.07);
assertFalse(NetworkGraphBuilder.isCapacitor(sc2));
}
}

0 comments on commit 6e2b25a

Please sign in to comment.