Skip to content

Add same reactive limits to generators, VSCs and batteries #988

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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 @@ -45,6 +45,10 @@ public final class NetworkDataframes {
private static final Map<ExtensionDataframeKey, NetworkDataframeMapper> EXTENSIONS_MAPPERS = NetworkExtensions.createExtensionsMappers();

private static final String DEFAULT_OPERATIONAL_LIMIT_GROUP_ID = "DEFAULT";
private static final String MIN_Q_AT_TARGET_P = "min_q_at_target_p";
private static final String MAX_Q_AT_TARGET_P = "max_q_at_target_p";
private static final String MIN_Q_AT_P = "min_q_at_p";
private static final String MAX_Q_AT_P = "max_q_at_p";

private NetworkDataframes() {
}
Expand Down Expand Up @@ -156,7 +160,7 @@ static <U extends Injection<U>> Function<U, String> getVoltageLevelId() {

private static MinMaxReactiveLimits getMinMaxReactiveLimits(ReactiveLimitsHolder holder) {
ReactiveLimits reactiveLimits = holder.getReactiveLimits();
return reactiveLimits instanceof MinMaxReactiveLimits ? (MinMaxReactiveLimits) reactiveLimits : null;
return reactiveLimits instanceof MinMaxReactiveLimits minMaxReactiveLimits ? minMaxReactiveLimits : null;
}

static <U extends ReactiveLimitsHolder> ToDoubleBiFunction<U, NetworkDataframeContext> getPerUnitMinQ(ToDoubleFunction<U> pGetter) {
Expand Down Expand Up @@ -280,10 +284,10 @@ static NetworkDataframeMapper generators() {
setPerUnitMinQ())
.doubles("max_q", ifExistsDoublePerUnitPQ(NetworkDataframes::getMinMaxReactiveLimits, MinMaxReactiveLimits::getMaxQ),
setPerUnitMaxQ())
.doubles("min_q_at_target_p", getPerUnitMinQ(Generator::getTargetP), false)
.doubles("max_q_at_target_p", getPerUnitMaxQ(Generator::getTargetP), false)
.doubles("min_q_at_p", getPerUnitMinQ(getOppositeP()), false)
.doubles("max_q_at_p", getPerUnitMaxQ(getOppositeP()), false)
.doubles(MIN_Q_AT_TARGET_P, getPerUnitMinQ(Generator::getTargetP), false)
.doubles(MAX_Q_AT_TARGET_P, getPerUnitMaxQ(Generator::getTargetP), false)
.doubles(MIN_Q_AT_P, getPerUnitMinQ(getOppositeP()), false)
.doubles(MAX_Q_AT_P, getPerUnitMaxQ(getOppositeP()), false)
.doubles("rated_s", (g, context) -> g.getRatedS(), (g, ratedS, context) -> g.setRatedS(ratedS))
.strings("reactive_limits_kind", NetworkDataframes::getReactiveLimitsKind)
.doubles("target_v", (g, context) -> perUnitTargetV(context, g.getTargetV(), g.getRegulatingTerminal(), g.getTerminal()),
Expand Down Expand Up @@ -377,6 +381,10 @@ static NetworkDataframeMapper batteries() {
setPerUnitMinQ())
.doubles("max_q", ifExistsDoublePerUnitPQ(NetworkDataframes::getMinMaxReactiveLimits, MinMaxReactiveLimits::getMaxQ),
setPerUnitMaxQ())
.doubles(MIN_Q_AT_TARGET_P, getPerUnitMinQ(Battery::getTargetP), false)
.doubles(MAX_Q_AT_TARGET_P, getPerUnitMaxQ(Battery::getTargetP), false)
.doubles(MIN_Q_AT_P, getPerUnitMinQ(getOppositeP()), false)
.doubles(MAX_Q_AT_P, getPerUnitMaxQ(getOppositeP()), false)
.strings("reactive_limits_kind", NetworkDataframes::getReactiveLimitsKind)
.doubles("target_p", (b, context) -> perUnitPQ(context, b.getTargetP()), (b, targetP, context) -> b.setTargetP(unPerUnitPQ(context, targetP)))
.doubles("target_q", (b, context) -> perUnitPQ(context, b.getTargetQ()), (b, targetQ, context) -> b.setTargetQ(unPerUnitPQ(context, targetQ)))
Expand Down Expand Up @@ -745,8 +753,10 @@ static NetworkDataframeMapper vscs() {
.doubles("loss_factor", (vsc, context) -> vsc.getLossFactor(), (vscConverterStation, lf, context) -> vscConverterStation.setLossFactor((float) lf))
.doubles("min_q", ifExistsDoublePerUnitPQ(NetworkDataframes::getMinMaxReactiveLimits, MinMaxReactiveLimits::getMinQ), setPerUnitMinQ())
.doubles("max_q", ifExistsDoublePerUnitPQ(NetworkDataframes::getMinMaxReactiveLimits, MinMaxReactiveLimits::getMaxQ), setPerUnitMaxQ())
.doubles("min_q_at_p", getPerUnitMinQ(getOppositeP()), false)
.doubles("max_q_at_p", getPerUnitMaxQ(getOppositeP()), false)
.doubles(MIN_Q_AT_TARGET_P, getPerUnitMinQ(vsc -> vsc.getHvdcLine().getActivePowerSetpoint()), false)
.doubles(MAX_Q_AT_TARGET_P, getPerUnitMaxQ(vsc -> vsc.getHvdcLine().getActivePowerSetpoint()), false)
.doubles(MIN_Q_AT_P, getPerUnitMinQ(getOppositeP()), false)
.doubles(MAX_Q_AT_P, getPerUnitMaxQ(getOppositeP()), false)
.strings("reactive_limits_kind", NetworkDataframes::getReactiveLimitsKind)
.doubles("target_v", (vsc, context) -> perUnitTargetV(context, vsc.getVoltageSetpoint(), vsc.getRegulatingTerminal(), vsc.getTerminal()),
(vsc, targetV, context) -> vsc.setVoltageSetpoint(unPerUnitTargetV(context, targetV, vsc.getRegulatingTerminal(), vsc.getTerminal())))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,9 @@ void batteries() {
List<Series> allAttributeSeries = createDataFrame(BATTERY, network, new DataframeFilter(ALL_ATTRIBUTES, Collections.emptyList()));
assertThat(allAttributeSeries)
.extracting(Series::getName)
.containsExactly("id", "name", "max_p", "min_p", "min_q", "max_q", "reactive_limits_kind", "target_p", "target_q", "p", "q", "i", "voltage_level_id",
"bus_id", "bus_breaker_bus_id", "node", "connected", "fictitious");
.containsExactly("id", "name", "max_p", "min_p", "min_q", "max_q", "min_q_at_target_p",
"max_q_at_target_p", "min_q_at_p", "max_q_at_p", "reactive_limits_kind", "target_p", "target_q",
"p", "q", "i", "voltage_level_id", "bus_id", "bus_breaker_bus_id", "node", "connected", "fictitious");
}

@Test
Expand Down Expand Up @@ -424,7 +425,8 @@ void vscs() {
List<Series> allAttributeSeries = createDataFrame(VSC_CONVERTER_STATION, network, new DataframeFilter(ALL_ATTRIBUTES, Collections.emptyList()));
assertThat(allAttributeSeries)
.extracting(Series::getName)
.containsExactly("id", "name", "loss_factor", "min_q", "max_q", "min_q_at_p", "max_q_at_p", "reactive_limits_kind", "target_v", "target_q", "voltage_regulator_on", "regulated_element_id",
.containsExactly("id", "name", "loss_factor", "min_q", "max_q", "min_q_at_target_p", "max_q_at_target_p",
"min_q_at_p", "max_q_at_p", "reactive_limits_kind", "target_v", "target_q", "voltage_regulator_on", "regulated_element_id",
"p", "q", "i", "voltage_level_id", "bus_id", "bus_breaker_bus_id", "node", "connected", "fictitious");
}

Expand Down
23 changes: 23 additions & 0 deletions tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -2715,5 +2715,28 @@ def test_alpha_rho_transfo3():
pd.testing.assert_frame_equal(expected_transfo3, transfo3, check_dtype=False, atol=1e-6)


def test_q_min_max_at_target_p():
network = pp.network.create_four_substations_node_breaker_network()
pp.loadflow.run_ac(network)
attributes = ['min_q', 'max_q', 'min_q_at_p', 'max_q_at_p', 'min_q_at_target_p', 'max_q_at_target_p']
generators = network.get_generators(attributes=attributes).tail(1)
expected_generators = pd.DataFrame(index=pd.Series(name='id', data=['GTH2']),
columns=attributes,
data=[[nan, nan, -172.607678, 185.036696, -172.594302, 185.097207]])
pd.testing.assert_frame_equal(expected_generators, generators, check_dtype=False)
vscs = network.get_vsc_converter_stations(attributes=attributes).tail(1)
expected_vscs = pd.DataFrame(index=pd.Series(name='id', data=['VSC2']),
columns=attributes,
data=[[-400.0, 500.0, -400.0, 500.0, -400.0, 500.0]])
pd.testing.assert_frame_equal(expected_vscs, vscs, check_dtype=False)

network_with_batteries = pp.network.load(TEST_DIR.joinpath('battery.xiidm'))
batteries = network_with_batteries.get_batteries(attributes=attributes).head(1)
expected_batteries = pd.DataFrame(index=pd.Series(name='id', data=['BAT']),
columns=attributes,
data=[[-9999.99, 9999.99, -9999.99, 9999.99, -9999.99, 9999.99]])
pd.testing.assert_frame_equal(expected_batteries, batteries, check_dtype=False)


if __name__ == '__main__':
unittest.main()
Loading