Skip to content

Commit 1c9daaf

Browse files
committed
CurrentLimits, RatioTapChanger and PhaseTapChanger are no longer dynamically created on the fly from attributes (#163)
Signed-off-by: Slimane AMAR <[email protected]>
1 parent f0b75d0 commit 1c9daaf

10 files changed

+258
-89
lines changed

network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/AbstractBranchImpl.java

+47-13
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,23 @@ public abstract class AbstractBranchImpl<T extends Branch<T>, U extends BranchAt
3232

3333
private ConnectablePositionImpl<T> connectablePositionExtension;
3434

35+
private CurrentLimits currentLimits1;
36+
37+
private CurrentLimits currentLimits2;
38+
3539
protected AbstractBranchImpl(NetworkObjectIndex index, Resource<U> resource) {
3640
super(index, resource);
3741
terminal1 = TerminalImpl.create(index, new BranchToInjectionAttributesAdapter(this, resource.getAttributes(), true), getBranch());
3842
terminal2 = TerminalImpl.create(index, new BranchToInjectionAttributesAdapter(this, resource.getAttributes(), false), getBranch());
43+
44+
if (resource.getAttributes().getCurrentLimits1() != null) {
45+
currentLimits1 = new CurrentLimitsImpl(this, resource.getAttributes().getCurrentLimits1());
46+
}
47+
48+
if (resource.getAttributes().getCurrentLimits2() != null) {
49+
currentLimits1 = new CurrentLimitsImpl(this, resource.getAttributes().getCurrentLimits2());
50+
}
51+
3952
ConnectablePositionAttributes cpa1 = resource.getAttributes().getPosition1();
4053
ConnectablePositionAttributes cpa2 = resource.getAttributes().getPosition2();
4154
if (cpa1 != null && cpa2 != null) {
@@ -106,15 +119,22 @@ public void notifyUpdate(String attribute, Object oldValue, Object newValue, boo
106119
}
107120

108121
@Override
109-
public void setCurrentLimits(Branch.Side side, CurrentLimitsAttributes currentLimits) {
110-
if (side == Branch.Side.ONE) {
111-
CurrentLimitsAttributes oldCurrentLimits = resource.getAttributes().getCurrentLimits1();
112-
resource.getAttributes().setCurrentLimits1(currentLimits);
113-
index.notifyUpdate(this, "currentLimits1", oldCurrentLimits, currentLimits);
114-
} else if (side == Branch.Side.TWO) {
115-
CurrentLimitsAttributes oldCurrentLimits = resource.getAttributes().getCurrentLimits2();
116-
resource.getAttributes().setCurrentLimits2(currentLimits);
117-
index.notifyUpdate(this, "currentLimits2", oldCurrentLimits, currentLimits);
122+
public void setCurrentLimitsAttributes(Branch.Side side, CurrentLimitsAttributes currentLimits) {
123+
switch (side) {
124+
case ONE: {
125+
CurrentLimitsAttributes oldCurrentLimits = resource.getAttributes().getCurrentLimits1();
126+
resource.getAttributes().setCurrentLimits1(currentLimits);
127+
index.notifyUpdate(this, "currentLimits1", oldCurrentLimits, currentLimits);
128+
break;
129+
}
130+
case TWO: {
131+
CurrentLimitsAttributes oldCurrentLimits = resource.getAttributes().getCurrentLimits2();
132+
resource.getAttributes().setCurrentLimits2(currentLimits);
133+
index.notifyUpdate(this, "currentLimits2", oldCurrentLimits, currentLimits);
134+
break;
135+
}
136+
default:
137+
throw new IllegalStateException();
118138
}
119139
}
120140

@@ -137,22 +157,36 @@ public void remove() {
137157
public CurrentLimits getCurrentLimits(Branch.Side side) {
138158
switch (side) {
139159
case ONE:
140-
return getCurrentLimits1();
160+
return this.currentLimits1;
141161
case TWO:
142-
return getCurrentLimits2();
162+
return this.currentLimits2;
143163
default:
144164
throw new IllegalStateException();
145165
}
146166
}
147167

148168
@Override
149169
public CurrentLimits getCurrentLimits1() {
150-
return resource.getAttributes().getCurrentLimits1() != null ? new CurrentLimitsImpl(this, resource.getAttributes().getCurrentLimits1()) : null;
170+
return currentLimits1;
151171
}
152172

153173
@Override
154174
public CurrentLimits getCurrentLimits2() {
155-
return resource.getAttributes().getCurrentLimits2() != null ? new CurrentLimitsImpl(this, resource.getAttributes().getCurrentLimits2()) : null;
175+
return currentLimits2;
176+
}
177+
178+
@Override
179+
public void setCurrentLimits(Branch.Side side, CurrentLimits currentLimits) {
180+
switch (side) {
181+
case ONE:
182+
this.currentLimits1 = currentLimits;
183+
break;
184+
case TWO:
185+
this.currentLimits2 = currentLimits;
186+
break;
187+
default:
188+
throw new IllegalStateException();
189+
}
156190
}
157191

158192
@Override

network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CurrentLimitsAdderImpl.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ public CurrentLimits add() {
111111
.permanentLimit(permanentLimit)
112112
.temporaryLimits(temporaryLimits)
113113
.build();
114-
owner.setCurrentLimits(side, attributes);
115-
return new CurrentLimitsImpl(owner, attributes);
114+
owner.setCurrentLimitsAttributes(side, attributes);
115+
116+
owner.setCurrentLimits(side, new CurrentLimitsImpl(owner, attributes));
117+
118+
return owner.getCurrentLimits(side);
116119
}
117120
}

network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/CurrentLimitsOwner.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
package com.powsybl.network.store.iidm.impl;
88

9+
import com.powsybl.iidm.network.CurrentLimits;
910
import com.powsybl.iidm.network.Validable;
1011
import com.powsybl.network.store.model.CurrentLimitsAttributes;
1112

@@ -14,6 +15,9 @@
1415
*/
1516
public interface CurrentLimitsOwner<SIDE> extends Validable {
1617

17-
void setCurrentLimits(SIDE side, CurrentLimitsAttributes currentLimits);
18+
void setCurrentLimitsAttributes(SIDE side, CurrentLimitsAttributes currentLimitsAttributes);
1819

20+
void setCurrentLimits(SIDE side, CurrentLimits currentLimits);
21+
22+
CurrentLimits getCurrentLimits(SIDE side);
1923
}

network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/DanglingLineImpl.java

+18-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
*/
3636
public class DanglingLineImpl extends AbstractInjectionImpl<DanglingLine, DanglingLineAttributes> implements DanglingLine, CurrentLimitsOwner<Void> {
3737

38+
private CurrentLimits currentLimits;
39+
3840
static class GenerationImpl implements Generation, ReactiveLimitsOwner, Validable {
3941

4042
private final DanglingLineImpl danglingLine;
@@ -188,6 +190,10 @@ public String getMessageHeader() {
188190

189191
public DanglingLineImpl(NetworkObjectIndex index, Resource<DanglingLineAttributes> resource) {
190192
super(index, resource);
193+
194+
if (resource.getAttributes().getCurrentLimits() != null) {
195+
currentLimits = new CurrentLimitsImpl(this, resource.getAttributes().getCurrentLimits());
196+
}
191197
}
192198

193199
static DanglingLineImpl create(NetworkObjectIndex index, Resource<DanglingLineAttributes> resource) {
@@ -326,17 +332,25 @@ public DanglingLine setUcteXnodeCode(String ucteXnodeCode) {
326332
}
327333

328334
@Override
329-
public void setCurrentLimits(Void side, CurrentLimitsAttributes currentLimits) {
335+
public void setCurrentLimitsAttributes(Void side, CurrentLimitsAttributes currentLimits) {
330336
CurrentLimitsAttributes oldValue = resource.getAttributes().getCurrentLimits();
331337
resource.getAttributes().setCurrentLimits(currentLimits);
332338
notifyUpdate("currentLimits", oldValue, currentLimits);
333339
}
334340

335341
@Override
336342
public CurrentLimits getCurrentLimits() {
337-
return resource.getAttributes().getCurrentLimits() != null
338-
? new CurrentLimitsImpl(this, resource.getAttributes().getCurrentLimits())
339-
: null;
343+
return currentLimits;
344+
}
345+
346+
@Override
347+
public CurrentLimits getCurrentLimits(Void side) {
348+
return currentLimits;
349+
}
350+
351+
@Override
352+
public void setCurrentLimits(Void side, CurrentLimits currentLimits) {
353+
this.currentLimits = currentLimits;
340354
}
341355

342356
@Override

network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/PhaseTapChangerAdderImpl.java

+11-15
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@
66
*/
77
package com.powsybl.network.store.iidm.impl;
88

9-
import com.powsybl.iidm.network.PhaseTapChanger;
10-
import com.powsybl.iidm.network.PhaseTapChangerAdder;
11-
import com.powsybl.iidm.network.TapChanger;
12-
import com.powsybl.iidm.network.Terminal;
13-
import com.powsybl.iidm.network.ValidationException;
14-
import com.powsybl.iidm.network.ValidationUtil;
15-
import com.powsybl.network.store.model.*;
9+
import com.powsybl.iidm.network.*;
10+
import com.powsybl.network.store.model.PhaseTapChangerAttributes;
11+
import com.powsybl.network.store.model.PhaseTapChangerStepAttributes;
12+
import com.powsybl.network.store.model.TerminalRefAttributes;
1613
import org.slf4j.Logger;
1714
import org.slf4j.LoggerFactory;
1815

@@ -30,8 +27,6 @@ public class PhaseTapChangerAdderImpl extends AbstractTapChangerAdder implements
3027

3128
private final TapChangerParent tapChangerParent;
3229

33-
private final TapChangerParentAttributes tapChangerParentAttributes;
34-
3530
private final List<PhaseTapChangerStepAttributes> steps = new ArrayList<>();
3631

3732
private PhaseTapChanger.RegulationMode regulationMode = PhaseTapChanger.RegulationMode.FIXED_TAP;
@@ -125,10 +120,9 @@ public PhaseTapChangerAdder endStep() {
125120
}
126121
}
127122

128-
public PhaseTapChangerAdderImpl(TapChangerParent tapChangerParent, NetworkObjectIndex index, TapChangerParentAttributes tapChangerParentAttributes, String id) {
123+
public PhaseTapChangerAdderImpl(TapChangerParent tapChangerParent, NetworkObjectIndex index, String id) {
129124
super(index);
130125
this.tapChangerParent = tapChangerParent;
131-
this.tapChangerParentAttributes = tapChangerParentAttributes;
132126
this.id = id;
133127
}
134128

@@ -214,12 +208,14 @@ public PhaseTapChanger add() {
214208
.targetDeadband(targetDeadband)
215209
.regulatingTerminal(terminalRefAttributes)
216210
.build();
217-
tapChangerParentAttributes.setPhaseTapChangerAttributes(phaseTapChangerAttributes);
211+
tapChangerParent.setPhaseTapChangerAttributes(phaseTapChangerAttributes);
218212

219-
if (tapChangerParentAttributes.getRatioTapChangerAttributes() != null) {
220-
LOGGER.warn("{} has both Ratio and Phase Tap Changer", tapChangerParentAttributes);
213+
if (tapChangerParent.getRatioTapChangerAttributes() != null) {
214+
LOGGER.warn("{} has both Ratio and Phase Tap Changer", tapChangerParent.getRatioTapChangerAttributes());
221215
}
222216

223-
return new PhaseTapChangerImpl(tapChangerParent, index, phaseTapChangerAttributes);
217+
tapChangerParent.setPhaseTapChanger(new PhaseTapChangerImpl(tapChangerParent, index, phaseTapChangerAttributes));
218+
219+
return tapChangerParent.getPhaseTapChanger();
224220
}
225221
}

network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/RatioTapChangerAdderImpl.java

+11-15
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@
66
*/
77
package com.powsybl.network.store.iidm.impl;
88

9-
import com.powsybl.iidm.network.RatioTapChanger;
10-
import com.powsybl.iidm.network.RatioTapChangerAdder;
11-
import com.powsybl.iidm.network.TapChanger;
12-
import com.powsybl.iidm.network.Terminal;
13-
import com.powsybl.iidm.network.ValidationException;
14-
import com.powsybl.iidm.network.ValidationUtil;
15-
import com.powsybl.network.store.model.*;
9+
import com.powsybl.iidm.network.*;
10+
import com.powsybl.network.store.model.RatioTapChangerAttributes;
11+
import com.powsybl.network.store.model.RatioTapChangerStepAttributes;
12+
import com.powsybl.network.store.model.TerminalRefAttributes;
1613
import org.slf4j.Logger;
1714
import org.slf4j.LoggerFactory;
1815

@@ -30,8 +27,6 @@ public class RatioTapChangerAdderImpl extends AbstractTapChangerAdder implements
3027

3128
private final TapChangerParent tapChangerParent;
3229

33-
private final TapChangerParentAttributes tapChangerParentAttributes;
34-
3530
private final List<RatioTapChangerStepAttributes> steps = new ArrayList<>();
3631

3732
private boolean loadTapChangingCapabilities = false;
@@ -112,10 +107,9 @@ public RatioTapChangerAdder endStep() {
112107
}
113108
}
114109

115-
public RatioTapChangerAdderImpl(TapChangerParent tapChangerParent, NetworkObjectIndex index, TapChangerParentAttributes tapChangerParentAttributes, String id) {
110+
public RatioTapChangerAdderImpl(TapChangerParent tapChangerParent, NetworkObjectIndex index, String id) {
116111
super(index);
117112
this.tapChangerParent = tapChangerParent;
118-
this.tapChangerParentAttributes = tapChangerParentAttributes;
119113
this.id = id;
120114
}
121115

@@ -199,12 +193,14 @@ public RatioTapChanger add() {
199193
.steps(steps)
200194
.regulatingTerminal(terminalRefAttributes)
201195
.build();
202-
tapChangerParentAttributes.setRatioTapChangerAttributes(ratioTapChangerAttributes);
196+
tapChangerParent.setRatioTapChangerAttributes(ratioTapChangerAttributes);
203197

204-
if (tapChangerParentAttributes.getPhaseTapChangerAttributes() != null) {
205-
LOGGER.warn("{} has both Ratio and Phase Tap Changer", tapChangerParentAttributes);
198+
if (tapChangerParent.getPhaseTapChangerAttributes() != null) {
199+
LOGGER.warn("{} has both Ratio and Phase Tap Changer", tapChangerParent.getPhaseTapChangerAttributes());
206200
}
207201

208-
return new RatioTapChangerImpl(tapChangerParent, index, ratioTapChangerAttributes);
202+
tapChangerParent.setRatioTapChanger(new RatioTapChangerImpl(tapChangerParent, index, ratioTapChangerAttributes));
203+
204+
return tapChangerParent.getRatioTapChanger();
209205
}
210206
}

network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/TapChangerParent.java

+15-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
*/
77
package com.powsybl.network.store.iidm.impl;
88

9-
import com.powsybl.iidm.network.Identifiable;
10-
import com.powsybl.iidm.network.PhaseTapChanger;
11-
import com.powsybl.iidm.network.RatioTapChanger;
12-
import com.powsybl.iidm.network.TapChanger;
13-
import com.powsybl.iidm.network.Validable;
9+
import com.powsybl.iidm.network.*;
10+
import com.powsybl.network.store.model.PhaseTapChangerAttributes;
11+
import com.powsybl.network.store.model.RatioTapChangerAttributes;
1412

1513
import java.util.HashSet;
1614
import java.util.Set;
@@ -25,6 +23,14 @@ public interface TapChangerParent extends Validable {
2523

2624
String getTapChangerAttribute();
2725

26+
RatioTapChangerAttributes getRatioTapChangerAttributes();
27+
28+
void setRatioTapChangerAttributes(RatioTapChangerAttributes ratioTapChangerAttributes);
29+
30+
PhaseTapChangerAttributes getPhaseTapChangerAttributes();
31+
32+
void setPhaseTapChangerAttributes(PhaseTapChangerAttributes phaseTapChangerAttributes);
33+
2834
default Set<TapChanger> getAllTapChangers() {
2935
Set<TapChanger> tapChangers = new HashSet<>();
3036
RatioTapChanger ratioTapChanger = getRatioTapChanger();
@@ -40,5 +46,9 @@ default Set<TapChanger> getAllTapChangers() {
4046

4147
PhaseTapChanger getPhaseTapChanger();
4248

49+
void setPhaseTapChanger(PhaseTapChanger phaseTapChanger);
50+
4351
RatioTapChanger getRatioTapChanger();
52+
53+
void setRatioTapChanger(RatioTapChanger ratioTapChanger);
4454
}

network-store-iidm-impl/src/main/java/com/powsybl/network/store/iidm/impl/ThreeWindingsTransformerAdderImpl.java

+15-11
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@
66
*/
77
package com.powsybl.network.store.iidm.impl;
88

9-
import com.powsybl.iidm.network.ThreeWindingsTransformer;
10-
import com.powsybl.iidm.network.ThreeWindingsTransformerAdder;
11-
import com.powsybl.iidm.network.Validable;
12-
import com.powsybl.iidm.network.ValidationException;
13-
import com.powsybl.iidm.network.ValidationUtil;
14-
import com.powsybl.iidm.network.VoltageLevel;
9+
import com.powsybl.iidm.network.*;
1510
import com.powsybl.network.store.model.LegAttributes;
1611
import com.powsybl.network.store.model.Resource;
1712
import com.powsybl.network.store.model.ThreeWindingsTransformerAttributes;
@@ -153,7 +148,7 @@ protected void checkNodeBus() {
153148
}
154149

155150
if (node == null && connectionBus == null) {
156-
throw new ValidationException(this, "connectable bus leg " + legNumber + " is not set");
151+
throw new ValidationException(this, "connectable bus is not set");
157152
}
158153

159154
if (connectionBus != null && index.getBus(connectionBus).isEmpty()) {
@@ -230,7 +225,7 @@ public ThreeWindingsTransformerAdder add() {
230225

231226
@Override
232227
public String getMessageHeader() {
233-
return String.format("3 windings transformer leg%d: ", legNumber);
228+
return String.format("3 windings transformer leg%d in substation %s: ", legNumber, substation.getName());
234229
}
235230
}
236231

@@ -249,17 +244,26 @@ public String getMessageHeader() {
249244

250245
@Override
251246
public LegAdder newLeg1() {
252-
return new LegAdderImpl(1, this);
247+
LegAdder legAdder = new LegAdderImpl(1, this);
248+
legAdder.setG(0.0);
249+
legAdder.setB(0.0);
250+
return legAdder;
253251
}
254252

255253
@Override
256254
public LegAdder newLeg2() {
257-
return new LegAdderImpl(2, this);
255+
LegAdder legAdder = new LegAdderImpl(2, this);
256+
legAdder.setG(0.0);
257+
legAdder.setB(0.0);
258+
return legAdder;
258259
}
259260

260261
@Override
261262
public LegAdder newLeg3() {
262-
return new LegAdderImpl(3, this);
263+
LegAdder legAdder = new LegAdderImpl(3, this);
264+
legAdder.setG(0.0);
265+
legAdder.setB(0.0);
266+
return legAdder;
263267
}
264268

265269
@Override

0 commit comments

Comments
 (0)