Skip to content

Commit

Permalink
Injection sensitivity from bus or busbar section ID (#536)
Browse files Browse the repository at this point in the history
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@rte-france.com>
Co-authored-by: Anne Tilloy <48123713+annetill@users.noreply.github.com>
  • Loading branch information
geofjamg and annetill authored Jun 1, 2022
1 parent 8c8064e commit 2a22847
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -745,25 +745,55 @@ private static Injection<?> getInjection(Network network, String injectionId) {
if (injection == null) {
injection = network.getVscConverterStation(injectionId);
}

if (injection == null) {
throw new PowsyblException("Injection '" + injectionId + "' not found");
}

return injection;
}

protected static String getInjectionBusId(Network network, String injectionId) {
// try with an injection
Injection<?> injection = getInjection(network, injectionId);
Bus bus = injection.getTerminal().getBusView().getBus();
if (bus == null) {
if (injection != null) {
Bus bus = injection.getTerminal().getBusView().getBus();
if (bus == null) {
return null;
}
if (injection instanceof DanglingLine) {
return LfDanglingLineBus.getId((DanglingLine) injection);
} else {
return bus.getId();
}
}

// try with a configured bus
Bus configuredBus = network.getBusBreakerView().getBus(injectionId);
if (configuredBus != null) {
// find a bus from bus view corresponding to this configured bus
List<Terminal> terminals = new ArrayList<>();
configuredBus.visitConnectedEquipments(new AbstractTerminalTopologyVisitor() {
@Override
public void visitTerminal(Terminal terminal) {
terminals.add(terminal);
}
});
for (Terminal terminal : terminals) {
Bus bus = terminal.getBusView().getBus();
if (bus != null) {
return bus.getId();
}
}
return null;
}
if (injection instanceof DanglingLine) {
return LfDanglingLineBus.getId((DanglingLine) injection);
} else {

// try with a busbar section
BusbarSection busbarSection = network.getBusbarSection(injectionId);
if (busbarSection != null) {
Bus bus = busbarSection.getTerminal().getBusView().getBus();
if (bus == null) {
return null;
}
return bus.getId();
}

throw new PowsyblException("Injection '" + injectionId + "' not found");
}

private static void checkBranch(Network network, String branchId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
import com.powsybl.sensitivity.*;
import org.junit.jupiter.api.Test;

import java.util.*;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletionException;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -884,4 +887,97 @@ void nonImpedantBranchTest() {
assertEquals(-0.6666666, result.getBranchFlow1SensitivityValue("glsk", "L2"), LoadFlowAssert.DELTA_POWER);
assertEquals(66.6666, result.getBranchFlow1FunctionReferenceValue("L2"), LoadFlowAssert.DELTA_POWER);
}

@Test
void testConfiguredBusFactor() {
Network network = EurostagTutorialExample1Factory.create();
runAcLf(network);

SensitivityAnalysisParameters sensiParameters = createParameters(true, "VLLOAD_0");

List<SensitivityFactor> factors = List.of(createBranchFlowPerInjectionIncrease("NHV1_NHV2_1", "GEN"),
new SensitivityFactor(SensitivityFunctionType.BRANCH_ACTIVE_POWER_1,
"NHV1_NHV2_1",
SensitivityVariableType.INJECTION_ACTIVE_POWER,
"NGEN",
false,
ContingencyContext.all()));

SensitivityAnalysisResult result = sensiRunner.run(network, factors, Collections.emptyList(), Collections.emptyList(), sensiParameters);

assertEquals(2, result.getValues().size());
assertEquals(result.getBranchFlow1SensitivityValue("GEN", "NHV1_NHV2_1"),
result.getBranchFlow1SensitivityValue("NGEN", "NHV1_NHV2_1"),
LoadFlowAssert.DELTA_POWER);
}

@Test
void testConfiguredBusInvalidFactor() {
Network network = EurostagTutorialExample1Factory.create();
network.getVoltageLevel("VLGEN").getBusBreakerView().newBus()
.setId("X")
.add();
runAcLf(network);

SensitivityAnalysisParameters sensiParameters = createParameters(true, "VLLOAD_0");

List<SensitivityFactor> factors = List.of(new SensitivityFactor(SensitivityFunctionType.BRANCH_ACTIVE_POWER_1,
"NHV1_NHV2_1",
SensitivityVariableType.INJECTION_ACTIVE_POWER,
"X",
false,
ContingencyContext.all()));

SensitivityAnalysisResult result = sensiRunner.run(network, factors, Collections.emptyList(), Collections.emptyList(), sensiParameters);

assertEquals(1, result.getValues().size());
assertEquals(0, result.getBranchFlow1SensitivityValue("X", "NHV1_NHV2_1"), LoadFlowAssert.DELTA_POWER);
}

@Test
void testBusbarSectionFactor() {
Network network = NodeBreakerNetworkFactory.create();
runAcLf(network);

SensitivityAnalysisParameters sensiParameters = createParameters(true, "VL2_0");

List<SensitivityFactor> factors = List.of(createBranchFlowPerInjectionIncrease("L1", "G"),
new SensitivityFactor(SensitivityFunctionType.BRANCH_ACTIVE_POWER_1,
"L1",
SensitivityVariableType.INJECTION_ACTIVE_POWER,
"BBS2",
false,
ContingencyContext.all()));

SensitivityAnalysisResult result = sensiRunner.run(network, factors, Collections.emptyList(), Collections.emptyList(), sensiParameters);

assertEquals(2, result.getValues().size());
assertEquals(result.getBranchFlow1SensitivityValue("G", "L1"),
result.getBranchFlow1SensitivityValue("BBS2", "L1"),
LoadFlowAssert.DELTA_POWER);
}

@Test
void testBusbarSectionInvalidFactor() {
Network network = NodeBreakerNetworkFactory.create();
network.getVoltageLevel("VL1").getNodeBreakerView().newBusbarSection()
.setId("X")
.setNode(100)
.add();
runAcLf(network);

SensitivityAnalysisParameters sensiParameters = createParameters(true, "VL2_0");

List<SensitivityFactor> factors = List.of(new SensitivityFactor(SensitivityFunctionType.BRANCH_ACTIVE_POWER_1,
"L1",
SensitivityVariableType.INJECTION_ACTIVE_POWER,
"X",
false,
ContingencyContext.all()));

SensitivityAnalysisResult result = sensiRunner.run(network, factors, Collections.emptyList(), Collections.emptyList(), sensiParameters);

assertEquals(1, result.getValues().size());
assertEquals(0, result.getBranchFlow1SensitivityValue("X", "L1"), LoadFlowAssert.DELTA_POWER);
}
}

0 comments on commit 2a22847

Please sign in to comment.