Skip to content

Commit 2ad53fb

Browse files
feat: partial load on bus network components (#289)
* feat: partial load on bus network components Signed-off-by: Joris Mancini <[email protected]> * fix tests Signed-off-by: Joris Mancini <[email protected]> * performance: use PreloadingStrategy.NONE with low numbers of substations (#290) Signed-off-by: Joris Mancini <[email protected]> --------- Signed-off-by: Joris Mancini <[email protected]>
1 parent f6ba471 commit 2ad53fb

File tree

6 files changed

+39
-26
lines changed

6 files changed

+39
-26
lines changed

src/main/java/org/gridsuite/network/map/dto/InfoTypeParameters.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class InfoTypeParameters {
1616
public static final String QUERY_PARAM_DC_POWERFACTOR = "dcPowerFactor";
1717
public static final String QUERY_PARAM_LOAD_OPERATIONAL_LIMIT_GROUPS = "loadOperationalLimitGroups";
1818
public static final String QUERY_PARAM_LOAD_REGULATING_TERMINALS = "loadRegulatingTerminals";
19+
public static final String QUERY_PARAM_LOAD_NETWORK_COMPONENTS = "loadNetworkComponents";
1920

2021
public static final InfoTypeParameters TAB = new InfoTypeParameters(ElementInfos.InfoType.TAB, null);
2122

src/main/java/org/gridsuite/network/map/dto/definition/bus/BusTabInfos.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ public class BusTabInfos extends ElementInfosWithProperties {
2525

2626
private Double angle;
2727

28+
@JsonInclude(JsonInclude.Include.NON_NULL)
2829
private Integer synchronousComponentNum;
2930

31+
@JsonInclude(JsonInclude.Include.NON_NULL)
3032
private Integer connectedComponentNum;
3133

3234
private String voltageLevelId;

src/main/java/org/gridsuite/network/map/dto/mapper/BusInfosMapper.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
import org.gridsuite.network.map.dto.definition.bus.BusTabInfos;
1414
import org.gridsuite.network.map.dto.utils.ElementUtils;
1515

16+
import java.util.Optional;
17+
18+
import static org.gridsuite.network.map.dto.InfoTypeParameters.QUERY_PARAM_LOAD_NETWORK_COMPONENTS;
1619
import static org.gridsuite.network.map.dto.utils.ElementUtils.getProperties;
1720
import static org.gridsuite.network.map.dto.utils.ElementUtils.mapCountry;
1821

@@ -25,27 +28,34 @@ private BusInfosMapper() {
2528
}
2629

2730
public static ElementInfos toData(Identifiable<?> identifiable, InfoTypeParameters infoTypeParameters) {
31+
boolean shouldLoadNetworkComponents = Optional.ofNullable(infoTypeParameters.getOptionalParameters().get(QUERY_PARAM_LOAD_NETWORK_COMPONENTS))
32+
.map(Boolean::valueOf)
33+
.orElse(false);
2834
return switch (infoTypeParameters.getInfoType()) {
2935
case LIST -> ElementInfosMapper.toListInfos(identifiable);
30-
case TAB -> toTabInfos(identifiable);
36+
case TAB -> toTabInfos(identifiable, shouldLoadNetworkComponents);
3137
default -> throw new UnsupportedOperationException("TODO");
3238
};
3339
}
3440

35-
private static BusTabInfos toTabInfos(Identifiable<?> identifiable) {
41+
private static BusTabInfos toTabInfos(Identifiable<?> identifiable, boolean shouldLoadNetworkComponents) {
3642
Bus bus = (Bus) identifiable;
3743
BusTabInfos.BusTabInfosBuilder<?, ?> builder = BusTabInfos.builder().id(bus.getId())
3844
.angle(bus.getAngle())
3945
.v(bus.getV())
4046
.voltageLevelId(bus.getVoltageLevel().getId())
4147
.nominalVoltage(bus.getVoltageLevel().getNominalV())
4248
.country(mapCountry(bus.getVoltageLevel().getSubstation().orElse(null)))
43-
.synchronousComponentNum(bus.getSynchronousComponent().getNum())
4449
.properties(getProperties(bus))
45-
.connectedComponentNum(bus.getConnectedComponent().getNum())
4650
.substationProperties(bus.getVoltageLevel().getSubstation().map(ElementUtils::getProperties).orElse(null))
4751
.voltageLevelProperties(getProperties(bus.getVoltageLevel()));
4852

53+
if (shouldLoadNetworkComponents) {
54+
builder
55+
.synchronousComponentNum(bus.getSynchronousComponent().getNum())
56+
.connectedComponentNum(bus.getConnectedComponent().getNum());
57+
}
58+
4959
return builder.build();
5060
}
5161
}

src/main/java/org/gridsuite/network/map/services/NetworkMapService.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
import java.util.*;
2727
import java.util.stream.Collectors;
2828
import java.util.stream.Stream;
29+
import java.util.stream.StreamSupport;
30+
31+
import static org.gridsuite.network.map.dto.InfoTypeParameters.QUERY_PARAM_LOAD_NETWORK_COMPONENTS;
2932

3033
/**
3134
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
@@ -62,7 +65,16 @@ private List<String> getSubstationsIds(UUID networkUuid, String variantId, List<
6265
}
6366

6467
public AllElementsInfos getAllElementsInfos(UUID networkUuid, String variantId, @NonNull List<String> substationsId, Map<String, Map<String, String>> additionalParametersByType) {
65-
Network network = getNetwork(networkUuid, PreloadingStrategy.ALL_COLLECTIONS_NEEDED_FOR_BUS_VIEW, variantId);
68+
// With network components we have to traverse almost all the network to recompute so we can switch to
69+
// ALL_COLLECTIONS_NEEDED_FOR_BUS_VIEW directly
70+
boolean shouldLoadNetworkComponents = Optional.ofNullable(additionalParametersByType.get(ElementType.BUS.toString()))
71+
.map(map -> map.get(QUERY_PARAM_LOAD_NETWORK_COMPONENTS))
72+
.map(Boolean::valueOf)
73+
.orElse(false);
74+
PreloadingStrategy preloadingStrategy = shouldLoadNetworkComponents || substationsId.size() >= 5 ?
75+
PreloadingStrategy.ALL_COLLECTIONS_NEEDED_FOR_BUS_VIEW :
76+
PreloadingStrategy.NONE;
77+
Network network = getNetwork(networkUuid, preloadingStrategy, variantId);
6678
return AllElementsInfos.builder()
6779
.substations(getSubstationsInfos(network, substationsId, getInfoTypeParameters(additionalParametersByType, ElementType.SUBSTATION), null))
6880
.voltageLevels(getVoltageLevelsInfos(network, substationsId, getInfoTypeParameters(additionalParametersByType, ElementType.VOLTAGE_LEVEL), null))
@@ -253,10 +265,11 @@ private List<ElementInfos> getTieLinesInfos(Network network, @NonNull List<Strin
253265

254266
private List<ElementInfos> getBusesInfos(Network network, @NonNull List<String> substationsId, InfoTypeParameters infoTypeParameters) {
255267
Stream<Bus> buses = substationsId.isEmpty() ? network.getBusView().getBusStream() :
256-
network.getBusView().getBusStream()
257-
.filter(Objects::nonNull)
258-
.filter(bus -> bus.getVoltageLevel().getSubstation().stream().anyMatch(substation -> substationsId.contains(substation.getId())))
259-
.distinct();
268+
substationsId
269+
.stream()
270+
.flatMap(id -> network.getSubstation(id).getVoltageLevelStream())
271+
.flatMap(vl -> StreamSupport.stream(vl.getBusView().getBuses().spliterator(), false));
272+
260273
return buses
261274
.map(c -> ElementType.BUS.getInfosGetter().apply(c, infoTypeParameters))
262275
.distinct()

src/test/java/org/gridsuite/network/map/NetworkMapControllerTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class NetworkMapControllerTest {
7676
public static final String QUERY_PARAM_DC_POWER_FACTOR = "dcPowerFactor";
7777
public static final String QUERY_PARAM_LOAD_OPERATIONAL_LIMIT_GROUPS = "loadOperationalLimitGroups";
7878
public static final String QUERY_PARAM_LOAD_REGULATING_TERMINALS = "loadRegulatingTerminals";
79+
public static final String QUERY_PARAM_LOAD_NETWORK_COMPONENTS = "loadNetworkComponents";
7980
public static final String QUERY_PARAM_NOMINAL_VOLTAGES = "nominalVoltages";
8081

8182
@Autowired
@@ -1443,6 +1444,7 @@ private void succeedingTestForElementsInfos(UUID networkUuid, String variantId,
14431444
if (withOptionalLoading) {
14441445
queryParams.add(String.format(QUERY_FORMAT_ADDITIONAL_PARAMS, QUERY_PARAM_LOAD_OPERATIONAL_LIMIT_GROUPS), String.valueOf(true));
14451446
queryParams.add(String.format(QUERY_FORMAT_ADDITIONAL_PARAMS, QUERY_PARAM_LOAD_REGULATING_TERMINALS), String.valueOf(true));
1447+
queryParams.add(String.format(QUERY_FORMAT_ADDITIONAL_PARAMS, QUERY_PARAM_LOAD_NETWORK_COMPONENTS), String.valueOf(true));
14461448
}
14471449
MvcResult mvcResult = mvc.perform(post("/v1/networks/{networkUuid}/elements", networkUuid)
14481450
.queryParams(queryParams)
@@ -1529,7 +1531,8 @@ private void succeedingTestForAllEquipmentsInfos(UUID networkUuid, String varian
15291531
String.valueOf(ElementType.BRANCH), Map.of(QUERY_PARAM_LOAD_OPERATIONAL_LIMIT_GROUPS, String.valueOf(true)),
15301532
String.valueOf(ElementType.LINE), Map.of(QUERY_PARAM_LOAD_OPERATIONAL_LIMIT_GROUPS, String.valueOf(true)),
15311533
String.valueOf(ElementType.TWO_WINDINGS_TRANSFORMER), Map.of(QUERY_PARAM_LOAD_OPERATIONAL_LIMIT_GROUPS, String.valueOf(true)),
1532-
String.valueOf(ElementType.GENERATOR), Map.of(QUERY_PARAM_LOAD_REGULATING_TERMINALS, String.valueOf(true))
1534+
String.valueOf(ElementType.GENERATOR), Map.of(QUERY_PARAM_LOAD_REGULATING_TERMINALS, String.valueOf(true)),
1535+
String.valueOf(ElementType.BUS), Map.of(QUERY_PARAM_LOAD_NETWORK_COMPONENTS, String.valueOf(true))
15331536
);
15341537
} else {
15351538
body = Map.of();

src/test/resources/all-data-without-optionals.json

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,8 +2165,6 @@
21652165
"id": "VLGEN_0",
21662166
"v": "NaN",
21672167
"angle": "NaN",
2168-
"synchronousComponentNum": 0,
2169-
"connectedComponentNum": 0,
21702168
"voltageLevelId": "VLGEN",
21712169
"nominalVoltage": 24.0,
21722170
"country": "FR",
@@ -2181,8 +2179,6 @@
21812179
"id": "VLHV1_0",
21822180
"v": "NaN",
21832181
"angle": "NaN",
2184-
"synchronousComponentNum": 0,
2185-
"connectedComponentNum": 0,
21862182
"voltageLevelId": "VLHV1",
21872183
"nominalVoltage": 380.0,
21882184
"country": "FR",
@@ -2194,26 +2190,20 @@
21942190
"id": "VLHV2_0",
21952191
"v": "NaN",
21962192
"angle": "NaN",
2197-
"synchronousComponentNum": 0,
2198-
"connectedComponentNum": 0,
21992193
"voltageLevelId": "VLHV2",
22002194
"nominalVoltage": 380.0
22012195
},
22022196
{
22032197
"id": "VLLOAD_0",
22042198
"v": "NaN",
22052199
"angle": "NaN",
2206-
"synchronousComponentNum": 0,
2207-
"connectedComponentNum": 0,
22082200
"voltageLevelId": "VLLOAD",
22092201
"nominalVoltage": 150.0
22102202
},
22112203
{
22122204
"id": "VLNEW2_0",
22132205
"v": "NaN",
22142206
"angle": "NaN",
2215-
"synchronousComponentNum": 0,
2216-
"connectedComponentNum": 0,
22172207
"voltageLevelId": "VLNEW2",
22182208
"nominalVoltage": 225.0,
22192209
"country": "FR",
@@ -2228,8 +2218,6 @@
22282218
"id": "VLGEN3_0",
22292219
"v": "NaN",
22302220
"angle": "NaN",
2231-
"synchronousComponentNum": 0,
2232-
"connectedComponentNum": 0,
22332221
"voltageLevelId": "VLGEN3",
22342222
"nominalVoltage": 24.0,
22352223
"country": "FR",
@@ -2241,8 +2229,6 @@
22412229
"id": "VLGEN6_0",
22422230
"v": "NaN",
22432231
"angle": "NaN",
2244-
"synchronousComponentNum": 0,
2245-
"connectedComponentNum": 0,
22462232
"voltageLevelId": "VLGEN6",
22472233
"nominalVoltage": 24.0,
22482234
"country": "FR"
@@ -2251,8 +2237,6 @@
22512237
"id": "VLGEN4_0",
22522238
"v": "NaN",
22532239
"angle": "NaN",
2254-
"synchronousComponentNum": 1,
2255-
"connectedComponentNum": 1,
22562240
"voltageLevelId": "VLGEN4",
22572241
"nominalVoltage": 24.0,
22582242
"country": "FR"

0 commit comments

Comments
 (0)