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

Fix shunt compensator component type #419

Merged
merged 2 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}
}