|
10 | 10 | import com.fasterxml.jackson.databind.ObjectMapper;
|
11 | 11 |
|
12 | 12 | 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; |
13 | 19 | import com.powsybl.openreac.parameters.output.OpenReacResult;
|
14 | 20 | import org.gridsuite.voltageinit.server.dto.GeneratorModificationInfos;
|
15 | 21 | import org.gridsuite.voltageinit.server.dto.ShuntCompensatorModificationInfos;
|
16 | 22 | import org.gridsuite.voltageinit.server.dto.StaticVarCompensatorModificationInfos;
|
17 | 23 | import org.gridsuite.voltageinit.server.dto.TransformerModificationInfos;
|
18 | 24 | import org.gridsuite.voltageinit.server.dto.VoltageInitModificationInfos;
|
19 | 25 | import org.gridsuite.voltageinit.server.dto.VscConverterStationModificationInfos;
|
| 26 | +import org.jgrapht.alg.util.Pair; |
20 | 27 | import org.springframework.beans.factory.annotation.Autowired;
|
21 | 28 | import org.springframework.beans.factory.annotation.Value;
|
22 | 29 | import org.springframework.http.HttpEntity;
|
|
28 | 35 | import org.springframework.web.client.RestTemplate;
|
29 | 36 | import org.springframework.web.util.UriComponentsBuilder;
|
30 | 37 |
|
| 38 | +import java.util.Map; |
31 | 39 | import java.util.Objects;
|
| 40 | +import java.util.Optional; |
32 | 41 | import java.util.UUID;
|
| 42 | +import java.util.concurrent.atomic.AtomicReference; |
| 43 | + |
| 44 | +import static com.powsybl.iidm.network.IdentifiableType.TWO_WINDINGS_TRANSFORMER; |
33 | 45 |
|
34 | 46 | /**
|
35 | 47 | * @author Franck Lecuyer <franck.lecuyer at rte-france.com>
|
@@ -76,28 +88,50 @@ public void deleteModificationsGroup(UUID groupUUid) {
|
76 | 88 | }
|
77 | 89 | }
|
78 | 90 |
|
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; |
81 | 97 |
|
82 | 98 | try {
|
83 | 99 | VoltageInitModificationInfos voltageInitModificationInfos = new VoltageInitModificationInfos();
|
84 | 100 |
|
| 101 | + Map<String, Pair<Double, Double>> voltageProfile = result.getVoltageProfile(); |
| 102 | + |
85 | 103 | // generator modifications
|
86 | 104 | result.getGeneratorModifications().forEach(gm -> {
|
87 | 105 | if (gm.getModifs().getTargetV() != null || gm.getModifs().getTargetQ() != null) {
|
88 | 106 | GeneratorModificationInfos.GeneratorModificationInfosBuilder builder = GeneratorModificationInfos.builder()
|
89 | 107 | .generatorId(gm.getGeneratorId())
|
90 |
| - .voltageSetpoint(gm.getModifs().getTargetV()) |
91 |
| - .reactivePowerSetpoint(gm.getModifs().getTargetQ()); |
| 108 | + .targetV(gm.getModifs().getTargetV()) |
| 109 | + .targetQ(gm.getModifs().getTargetQ()); |
92 | 110 | voltageInitModificationInfos.addGeneratorModification(builder.build());
|
93 | 111 | }
|
94 | 112 | });
|
95 | 113 |
|
96 | 114 | // transformer modifications
|
| 115 | + AtomicReference<Double> targetV = new AtomicReference<>(); |
97 | 116 | 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 | + } |
98 | 131 | TransformerModificationInfos.TransformerModificationInfosBuilder builder = TransformerModificationInfos.builder()
|
99 | 132 | .transformerId(tp.getTransformerId())
|
100 | 133 | .ratioTapChangerPosition(tp.getTapPosition())
|
| 134 | + .ratioTapChangerTargetV(targetV.get()) |
101 | 135 | .legSide(tp.getLegSide());
|
102 | 136 | voltageInitModificationInfos.addTransformerModification(builder.build());
|
103 | 137 | });
|
@@ -126,10 +160,22 @@ public UUID createVoltageInitModificationGroup(OpenReacResult result) {
|
126 | 160 |
|
127 | 161 | // shunt compensator modifications
|
128 | 162 | 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 | + } |
129 | 174 | ShuntCompensatorModificationInfos.ShuntCompensatorModificationInfosBuilder builder = ShuntCompensatorModificationInfos.builder()
|
130 | 175 | .shuntCompensatorId(shuntCompensatorModification.getShuntCompensatorId())
|
131 | 176 | .sectionCount(shuntCompensatorModification.getSectionCount())
|
132 |
| - .connect(shuntCompensatorModification.getConnect()); |
| 177 | + .connect(shuntCompensatorModification.getConnect()) |
| 178 | + .targetV(targetV.get()); |
133 | 179 | voltageInitModificationInfos.addShuntCompensatorModification(builder.build());
|
134 | 180 | });
|
135 | 181 |
|
|
0 commit comments