-
Notifications
You must be signed in to change notification settings - Fork 19
/
EchUtil.java
236 lines (204 loc) · 8.77 KB
/
EchUtil.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/**
* Copyright (c) 2016, All partners of the iTesla project (http://www.itesla-project.eu/consortium)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package eu.itesla_project.iidm.eurostag.export;
import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.util.ConnectedComponents;
import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.stream.StreamSupport;
/**
*
* @author pihan
*
*/
public final class EchUtil {
private EchUtil() {
}
public static final String FAKE_AREA = "FA";
public static final String FAKE_NODE_NAME1 = "FAKENOD1";
public static final String FAKE_NODE_NAME2 = "FAKENOD2";
public static String getBusId(DanglingLine dl) {
return dl.getId() + "_BUS";
}
public static String getLoadId(DanglingLine dl) {
return dl.getId() + "_LOAD";
}
public static Bus getBus(Terminal t, boolean noswitch) {
if (noswitch) {
return t.getBusView().getBus();
} else {
return t.getBusBreakerView().getBus();
}
}
public static Bus getBus(Terminal t, EurostagEchExportConfig config) {
return EchUtil.getBus(t, config.isNoSwitch());
}
public static Iterable<Bus> getBuses(Network n, EurostagEchExportConfig config) {
if (config.isNoSwitch()) {
return n.getBusView().getBuses();
} else {
return n.getBusBreakerView().getBuses();
}
}
public static Iterable<Bus> getBuses(VoltageLevel vl, EurostagEchExportConfig config) {
if (config.isNoSwitch()) {
return vl.getBusView().getBuses();
} else {
return vl.getBusBreakerView().getBuses();
}
}
public static Bus getBus1(VoltageLevel vl, String switchId, EurostagEchExportConfig config) {
if (config.isNoSwitch()) {
throw new AssertionError("Should not happen");
} else {
return vl.getBusBreakerView().getBus1(switchId);
}
}
public static Bus getBus2(VoltageLevel vl, String switchId, EurostagEchExportConfig config) {
if (config.isNoSwitch()) {
throw new AssertionError("Should not happen");
} else {
return vl.getBusBreakerView().getBus2(switchId);
}
}
public static Iterable<Switch> getSwitches(VoltageLevel vl, EurostagEchExportConfig config) {
if (config.isNoSwitch()) {
return Collections.emptyList();
} else {
return vl.getBusBreakerView().getSwitches();
}
}
private static final class DecoratedBus {
Bus bus;
int branch = 0;
int regulatingGenerator = 0;
float maxP = 0;
float minP = 0;
float targetP = 0;
private DecoratedBus(Bus bus) {
this.bus = bus;
}
}
private static DecoratedBus decorate(Bus b) {
final DecoratedBus decoratedBus = new DecoratedBus(b);
b.visitConnectedEquipments(new DefaultTopologyVisitor() {
@Override
public void visitLine(Line line, Line.Side side) {
decoratedBus.branch++;
}
@Override
public void visitTwoWindingsTransformer(TwoWindingsTransformer transformer, TwoWindingsTransformer.Side side) {
decoratedBus.branch++;
}
@Override
public void visitThreeWindingsTransformer(ThreeWindingsTransformer transformer, ThreeWindingsTransformer.Side side) {
decoratedBus.branch++;
}
@Override
public void visitDanglingLine(DanglingLine danglingLine) {
decoratedBus.branch++;
}
@Override
public void visitGenerator(Generator generator) {
if (generator.isVoltageRegulatorOn()) {
decoratedBus.regulatingGenerator++;
decoratedBus.maxP += generator.getMaxP();
decoratedBus.minP += generator.getMinP();
decoratedBus.targetP += generator.getTargetP();
}
}
});
return decoratedBus;
}
/**
* Automatically find the best slack bus list
*/
public static Bus selectSlackbus(Network network, EurostagEchExportConfig config) {
// avoid buses connected to a switch because of Eurostag LF crash (LU factorisation issue)
Set<String> busesToAvoid = new HashSet<>();
for (VoltageLevel vl : network.getVoltageLevels()) {
for (Switch s : EchUtil.getSwitches(vl, config)) {
busesToAvoid.add(EchUtil.getBus1(vl, s.getId(), config).getId());
busesToAvoid.add(EchUtil.getBus2(vl, s.getId(), config).getId());
}
}
Bus bus = selectSlackbusCriteria1(network, config, busesToAvoid);
if (bus == null) {
bus = selectSlackbusCriteria1(network, config, Collections.emptySet());
}
return bus;
}
private static Bus selectSlackbusCriteria1(Network network, EurostagEchExportConfig config, Set<String> busesToAvoid) {
return StreamSupport.stream(EchUtil.getBuses(network, config).spliterator(), false)
.sorted((b1, b2) -> b1.getId().compareTo(b2.getId()))
.filter(b -> !busesToAvoid.contains(b.getId())
&& b.getConnectedComponent() != null && b.getConnectedComponent().getNum() == Component.MAIN_NUM)
.map(b -> decorate(b))
.filter(db -> db.regulatingGenerator > 0 && db.maxP > 100) // only keep bus with a regulating generator and a pmax > 100 MW
.sorted((db1, db2) -> Float.compare((db1.maxP - db1.minP) / 2 - db1.targetP, (db2.maxP - db2.minP) / 2 - db2.targetP)) // select first bus with a high margin
.limit(1)
.map(f -> f.bus)
.findFirst()
.orElse(null);
}
public static boolean isInMainCc(Bus bus) {
return ConnectedComponents.getCcNum(bus) == Component.MAIN_NUM;
}
public static boolean isInMainCc(Injection injection, boolean noswitch) {
return ConnectedComponents.getCcNum(EchUtil.getBus(injection.getTerminal(), noswitch)) == Component.MAIN_NUM;
}
public static boolean isInMainCc(Branch branch, boolean noswitch) {
return (ConnectedComponents.getCcNum(EchUtil.getBus(branch.getTerminal1(), noswitch)) == Component.MAIN_NUM)
&& (ConnectedComponents.getCcNum(EchUtil.getBus(branch.getTerminal2(), noswitch)) == Component.MAIN_NUM);
}
/**
* given an iIDM HVDC line , returns its DC voltage to be used with Eurostag
* Multiplying the line's nominalV by 2 corresponds to the fact that iIDM refers to the cable-ground voltage
* while Eurostag regulations to the cable-cable voltage
*/
public static float getHvdcLineDcVoltage(HvdcLine line) {
Objects.requireNonNull(line);
return line.getNominalV() * 2.0f;
}
public static boolean isPMode(HvdcConverterStation vscConv, HvdcLine hvdcLine) {
Objects.requireNonNull(vscConv);
Objects.requireNonNull(hvdcLine);
HvdcConverterStation side1Conv = hvdcLine.getConverterStation1();
HvdcConverterStation side2Conv = hvdcLine.getConverterStation2();
if ((hvdcLine.getConvertersMode().equals(HvdcLine.ConvertersMode.SIDE_1_RECTIFIER_SIDE_2_INVERTER))
&& (vscConv.getId().equals(side1Conv.getId()))) {
return true;
}
if ((hvdcLine.getConvertersMode().equals(HvdcLine.ConvertersMode.SIDE_1_INVERTER_SIDE_2_RECTIFIER))
&& (vscConv.getId().equals(side2Conv.getId()))) {
return true;
}
return false;
}
public static HvdcConverterStation getPStation(HvdcLine hvdcLine) {
Objects.requireNonNull(hvdcLine);
if (hvdcLine.getConvertersMode().equals(HvdcLine.ConvertersMode.SIDE_1_RECTIFIER_SIDE_2_INVERTER)) {
return hvdcLine.getConverterStation1();
}
if (hvdcLine.getConvertersMode().equals(HvdcLine.ConvertersMode.SIDE_1_INVERTER_SIDE_2_RECTIFIER)) {
return hvdcLine.getConverterStation2();
}
return null;
}
public static HvdcConverterStation getVStation(HvdcLine hvdcLine) {
Objects.requireNonNull(hvdcLine);
if (hvdcLine.getConvertersMode().equals(HvdcLine.ConvertersMode.SIDE_1_RECTIFIER_SIDE_2_INVERTER)) {
return hvdcLine.getConverterStation2();
}
if (hvdcLine.getConvertersMode().equals(HvdcLine.ConvertersMode.SIDE_1_INVERTER_SIDE_2_RECTIFIER)) {
return hvdcLine.getConverterStation1();
}
return null;
}
}