Skip to content

Commit 09e4eaa

Browse files
Get transformers and shunt compensators targetV modifications (#43)
* Get transformers and shunt compensators targetV modifications * Modifications after powsybl upgrade to 2024.0.3 * Fix field names Signed-off-by: Franck LECUYER <[email protected]>
1 parent 0c42cf1 commit 09e4eaa

File tree

6 files changed

+94
-23
lines changed

6 files changed

+94
-23
lines changed

src/main/java/org/gridsuite/voltageinit/server/dto/GeneratorModificationInfos.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public class GeneratorModificationInfos {
2121
private String generatorId;
2222

2323
@JsonInclude(JsonInclude.Include.NON_NULL)
24-
private Double voltageSetpoint;
24+
private Double targetV;
2525

2626
@JsonInclude(JsonInclude.Include.NON_NULL)
27-
private Double reactivePowerSetpoint;
27+
private Double targetQ;
2828
}

src/main/java/org/gridsuite/voltageinit/server/dto/ShuntCompensatorModificationInfos.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@ public class ShuntCompensatorModificationInfos {
2525

2626
@JsonInclude(JsonInclude.Include.NON_NULL)
2727
private Boolean connect;
28+
29+
@JsonInclude(JsonInclude.Include.NON_NULL)
30+
private Double targetV;
2831
}

src/main/java/org/gridsuite/voltageinit/server/dto/TransformerModificationInfos.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public class TransformerModificationInfos {
2424
@JsonInclude(JsonInclude.Include.NON_NULL)
2525
private Integer ratioTapChangerPosition;
2626

27+
@JsonInclude(JsonInclude.Include.NON_NULL)
28+
private Double ratioTapChangerTargetV;
29+
2730
@JsonInclude(JsonInclude.Include.NON_NULL)
2831
private ThreeSides legSide;
2932
}

src/main/java/org/gridsuite/voltageinit/server/service/NetworkModificationService.java

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,20 @@
1010
import com.fasterxml.jackson.databind.ObjectMapper;
1111

1212
import com.powsybl.commons.PowsyblException;
13+
import com.powsybl.iidm.network.Bus;
14+
import com.powsybl.iidm.network.Identifiable;
15+
import com.powsybl.iidm.network.Network;
16+
import com.powsybl.iidm.network.ShuntCompensator;
17+
import com.powsybl.iidm.network.Terminal;
18+
import com.powsybl.iidm.network.TwoWindingsTransformer;
1319
import com.powsybl.openreac.parameters.output.OpenReacResult;
1420
import org.gridsuite.voltageinit.server.dto.GeneratorModificationInfos;
1521
import org.gridsuite.voltageinit.server.dto.ShuntCompensatorModificationInfos;
1622
import org.gridsuite.voltageinit.server.dto.StaticVarCompensatorModificationInfos;
1723
import org.gridsuite.voltageinit.server.dto.TransformerModificationInfos;
1824
import org.gridsuite.voltageinit.server.dto.VoltageInitModificationInfos;
1925
import org.gridsuite.voltageinit.server.dto.VscConverterStationModificationInfos;
26+
import org.jgrapht.alg.util.Pair;
2027
import org.springframework.beans.factory.annotation.Autowired;
2128
import org.springframework.beans.factory.annotation.Value;
2229
import org.springframework.http.HttpEntity;
@@ -28,8 +35,13 @@
2835
import org.springframework.web.client.RestTemplate;
2936
import org.springframework.web.util.UriComponentsBuilder;
3037

38+
import java.util.Map;
3139
import java.util.Objects;
40+
import java.util.Optional;
3241
import java.util.UUID;
42+
import java.util.concurrent.atomic.AtomicReference;
43+
44+
import static com.powsybl.iidm.network.IdentifiableType.TWO_WINDINGS_TRANSFORMER;
3345

3446
/**
3547
* @author Franck Lecuyer <franck.lecuyer at rte-france.com>
@@ -76,28 +88,50 @@ public void deleteModificationsGroup(UUID groupUUid) {
7688
}
7789
}
7890

79-
public UUID createVoltageInitModificationGroup(OpenReacResult result) {
80-
UUID modificationsGroupUuid = null;
91+
private Optional<Bus> getRegulatingBus(Terminal terminal) {
92+
return terminal != null && terminal.getBusView().getBus() != null ? Optional.of(terminal.getBusView().getBus()) : Optional.empty();
93+
}
94+
95+
public UUID createVoltageInitModificationGroup(Network network, OpenReacResult result) {
96+
UUID modificationsGroupUuid;
8197

8298
try {
8399
VoltageInitModificationInfos voltageInitModificationInfos = new VoltageInitModificationInfos();
84100

101+
Map<String, Pair<Double, Double>> voltageProfile = result.getVoltageProfile();
102+
85103
// generator modifications
86104
result.getGeneratorModifications().forEach(gm -> {
87105
if (gm.getModifs().getTargetV() != null || gm.getModifs().getTargetQ() != null) {
88106
GeneratorModificationInfos.GeneratorModificationInfosBuilder builder = GeneratorModificationInfos.builder()
89107
.generatorId(gm.getGeneratorId())
90-
.voltageSetpoint(gm.getModifs().getTargetV())
91-
.reactivePowerSetpoint(gm.getModifs().getTargetQ());
108+
.targetV(gm.getModifs().getTargetV())
109+
.targetQ(gm.getModifs().getTargetQ());
92110
voltageInitModificationInfos.addGeneratorModification(builder.build());
93111
}
94112
});
95113

96114
// transformer modifications
115+
AtomicReference<Double> targetV = new AtomicReference<>();
97116
result.getTapPositionModifications().forEach(tp -> {
117+
targetV.set(null);
118+
Identifiable<?> identifiable = network.getIdentifiable(tp.getTransformerId());
119+
if (identifiable != null && identifiable.getType() == TWO_WINDINGS_TRANSFORMER) { // Only for 2WT
120+
TwoWindingsTransformer twoWindingsTransformer = (TwoWindingsTransformer) identifiable;
121+
if (twoWindingsTransformer.getRatioTapChanger() != null) {
122+
Optional<Bus> bus = getRegulatingBus(twoWindingsTransformer.getRatioTapChanger().getRegulationTerminal());
123+
bus.ifPresent(b -> {
124+
Pair<Double, Double> busUpdate = voltageProfile.get(b.getId());
125+
if (busUpdate != null) {
126+
targetV.set(busUpdate.getFirst() * b.getVoltageLevel().getNominalV());
127+
}
128+
});
129+
}
130+
}
98131
TransformerModificationInfos.TransformerModificationInfosBuilder builder = TransformerModificationInfos.builder()
99132
.transformerId(tp.getTransformerId())
100133
.ratioTapChangerPosition(tp.getTapPosition())
134+
.ratioTapChangerTargetV(targetV.get())
101135
.legSide(tp.getLegSide());
102136
voltageInitModificationInfos.addTransformerModification(builder.build());
103137
});
@@ -126,10 +160,22 @@ public UUID createVoltageInitModificationGroup(OpenReacResult result) {
126160

127161
// shunt compensator modifications
128162
result.getShuntsModifications().forEach(shuntCompensatorModification -> {
163+
targetV.set(null);
164+
ShuntCompensator shuntCompensator = network.getShuntCompensator(shuntCompensatorModification.getShuntCompensatorId());
165+
if (shuntCompensator != null) {
166+
Optional<Bus> bus = getRegulatingBus(shuntCompensator.getRegulatingTerminal());
167+
bus.ifPresent(b -> {
168+
Pair<Double, Double> busUpdate = voltageProfile.get(b.getId());
169+
if (busUpdate != null) {
170+
targetV.set(busUpdate.getFirst() * b.getVoltageLevel().getNominalV());
171+
}
172+
});
173+
}
129174
ShuntCompensatorModificationInfos.ShuntCompensatorModificationInfosBuilder builder = ShuntCompensatorModificationInfos.builder()
130175
.shuntCompensatorId(shuntCompensatorModification.getShuntCompensatorId())
131176
.sectionCount(shuntCompensatorModification.getSectionCount())
132-
.connect(shuntCompensatorModification.getConnect());
177+
.connect(shuntCompensatorModification.getConnect())
178+
.targetV(targetV.get());
133179
voltageInitModificationInfos.addShuntCompensatorModification(builder.build());
134180
});
135181

src/main/java/org/gridsuite/voltageinit/server/service/VoltageInitWorkerService.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.powsybl.openreac.parameters.output.OpenReacResult;
2323
import com.powsybl.openreac.parameters.output.OpenReacStatus;
2424
import org.apache.commons.lang3.StringUtils;
25+
import org.apache.commons.lang3.tuple.Pair;
2526
import org.gridsuite.voltageinit.server.repository.VoltageInitResultRepository;
2627
import org.gridsuite.voltageinit.server.service.parameters.VoltageInitParametersService;
2728
import org.slf4j.Logger;
@@ -125,7 +126,7 @@ public static void addRestrictedVoltageLevelReport(Map<String, Double> voltageLe
125126
}
126127
}
127128

128-
private OpenReacResult run(VoltageInitRunContext context, UUID resultUuid) throws Exception {
129+
private Pair<Network, OpenReacResult> run(VoltageInitRunContext context, UUID resultUuid) throws Exception {
129130
Objects.requireNonNull(context);
130131

131132
LOGGER.info("Run voltage init...");
@@ -149,7 +150,7 @@ private OpenReacResult run(VoltageInitRunContext context, UUID resultUuid) throw
149150
reportService.sendReport(context.getReportUuid(), rootReporter.get()));
150151
}
151152

152-
return future == null ? null : voltageInitObserver.observeRun("run", future::get);
153+
return future == null ? Pair.of(network, null) : Pair.of(network, voltageInitObserver.observeRun("run", future::get));
153154
}
154155

155156
public CompletableFuture<OpenReacResult> runVoltageInitAsync(VoltageInitRunContext context, Network network, UUID resultUuid) {
@@ -202,18 +203,20 @@ public Consumer<Message<String>> consumeRun() {
202203
AtomicReference<Long> startTime = new AtomicReference<>();
203204

204205
startTime.set(System.nanoTime());
205-
OpenReacResult result = run(resultContext.getRunContext(), resultContext.getResultUuid());
206+
Pair<Network, OpenReacResult> res = run(resultContext.getRunContext(), resultContext.getResultUuid());
207+
Network network = res.getLeft();
208+
OpenReacResult openReacResult = res.getRight();
206209
long nanoTime = System.nanoTime();
207210
LOGGER.info("Just run in {}s", TimeUnit.NANOSECONDS.toSeconds(nanoTime - startTime.getAndSet(nanoTime)));
208211

209-
UUID modificationsGroupUuid = networkModificationService.createVoltageInitModificationGroup(result);
210-
voltageInitObserver.observe("results.save", () ->
211-
resultRepository.insert(resultContext.getResultUuid(), result, modificationsGroupUuid, result.getStatus().name()));
212-
LOGGER.info("Status : {}", result.getStatus());
213-
LOGGER.info("Reactive slacks : {}", result.getReactiveSlacks());
214-
LOGGER.info("Indicators : {}", result.getIndicators());
212+
if (openReacResult != null) { // result available
213+
UUID modificationsGroupUuid = networkModificationService.createVoltageInitModificationGroup(network, openReacResult);
214+
voltageInitObserver.observe("results.save", () ->
215+
resultRepository.insert(resultContext.getResultUuid(), openReacResult, modificationsGroupUuid, openReacResult.getStatus().name()));
216+
LOGGER.info("Status : {}", openReacResult.getStatus());
217+
LOGGER.info("Reactive slacks : {}", openReacResult.getReactiveSlacks());
218+
LOGGER.info("Indicators : {}", openReacResult.getIndicators());
215219

216-
if (result != null) { // result available
217220
notificationService.sendResultMessage(resultContext.getResultUuid(), resultContext.getRunContext().getReceiver());
218221
LOGGER.info("Voltage initialization complete (resultUuid='{}')", resultContext.getResultUuid());
219222
} else { // result not available : stop computation request

src/test/java/org/gridsuite/voltageinit/server/VoltageInitControllerTest.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.gridsuite.voltageinit.server.service.UuidGeneratorService;
4545
import org.gridsuite.voltageinit.server.service.parameters.FilterService;
4646
import org.gridsuite.voltageinit.server.util.annotations.PostCompletionAdapter;
47+
import org.jgrapht.alg.util.Pair;
4748
import org.junit.After;
4849
import org.junit.Before;
4950
import org.junit.Test;
@@ -134,9 +135,6 @@ public class VoltageInitControllerTest {
134135
private final ObjectMapper mapper = restTemplateConfig.objectMapper();
135136

136137
private Network network;
137-
private Network network1;
138-
private Network networkForMergingView;
139-
private Network otherNetworkForMergingView;
140138
OpenReacParameters openReacParameters;
141139
OpenReacResult openReacResult;
142140
CompletableFutureTask<OpenReacResult> completableFutureResultsTask;
@@ -155,10 +153,16 @@ private OpenReacResult buildOpenReacResult() {
155153
openReacAmplIOFiles.getNetworkModifications().getGeneratorModifications().add(new GeneratorModification("GEN2", m2));
156154

157155
openReacAmplIOFiles.getNetworkModifications().getTapPositionModifications().add(new RatioTapPositionModification("NHV2_NLOAD", 2));
156+
openReacAmplIOFiles.getNetworkModifications().getTapPositionModifications().add(new RatioTapPositionModification("unknown2WT", 2));
158157

159158
openReacAmplIOFiles.getNetworkModifications().getSvcModifications().add(new StaticVarCompensatorModification("SVC_1", 227., 50.));
160159
openReacAmplIOFiles.getNetworkModifications().getVscModifications().add(new VscConverterStationModification("VSC_1", 385., 70.));
161160
openReacAmplIOFiles.getNetworkModifications().getShuntModifications().add(new ShuntCompensatorModification("SHUNT_1", true, 1));
161+
openReacAmplIOFiles.getNetworkModifications().getShuntModifications().add(new ShuntCompensatorModification("unknownShunt", true, 1));
162+
163+
Map<String, Pair<Double, Double>> voltageProfile = openReacAmplIOFiles.getVoltageProfileOutput().getVoltageProfile();
164+
voltageProfile.put("NHV2_NLOAD_busId1", Pair.of(100., 100.));
165+
voltageProfile.put("SHUNT_1_busId1", Pair.of(100., 100.));
162166

163167
openReacResult = new OpenReacResult(OpenReacStatus.OK, openReacAmplIOFiles, INDICATORS);
164168
return openReacResult;
@@ -213,6 +217,21 @@ public void setUp() throws Exception {
213217

214218
// network store service mocking
215219
network = EurostagTutorialExample1Factory.createWithMoreGenerators(new NetworkFactoryImpl());
220+
network.getVoltageLevel("VLGEN").newShuntCompensator()
221+
.setId("SHUNT_1")
222+
.setBus("NGEN")
223+
.setConnectableBus("NGEN")
224+
.setTargetV(30.)
225+
.setTargetDeadband(10)
226+
.setVoltageRegulatorOn(false)
227+
.newLinearModel()
228+
.setMaximumSectionCount(1)
229+
.setBPerSection(1)
230+
.setGPerSection(1)
231+
.add()
232+
.setSectionCount(1)
233+
.add();
234+
216235
network.getVariantManager().cloneVariant(VariantManagerConstants.INITIAL_VARIANT_ID, VARIANT_1_ID);
217236
network.getVariantManager().cloneVariant(VariantManagerConstants.INITIAL_VARIANT_ID, VARIANT_2_ID);
218237
network.getVariantManager().cloneVariant(VariantManagerConstants.INITIAL_VARIANT_ID, VARIANT_3_ID);
@@ -221,9 +240,6 @@ public void setUp() throws Exception {
221240
given(networkStoreService.getNetwork(NETWORK_UUID, PreloadingStrategy.COLLECTION)).willReturn(network);
222241
given(networkStoreService.getNetwork(OTHER_NETWORK_UUID, PreloadingStrategy.ALL_COLLECTIONS_NEEDED_FOR_BUS_VIEW)).willThrow(new PowsyblException("Not found"));
223242

224-
network1 = EurostagTutorialExample1Factory.createWithMoreGenerators(new NetworkFactoryImpl());
225-
network1.getVariantManager().cloneVariant(VariantManagerConstants.INITIAL_VARIANT_ID, VARIANT_2_ID);
226-
227243
// OpenReac run mocking
228244
openReacParameters = new OpenReacParameters();
229245
openReacResult = buildOpenReacResult();

0 commit comments

Comments
 (0)