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

Injection sensitivity from bus or busbar section ID #536

Merged
merged 3 commits into from
Jun 1, 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 @@ -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() {
annetill marked this conversation as resolved.
Show resolved Hide resolved
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);
}
}