7
7
package com .powsybl .network .store .iidm .impl ;
8
8
9
9
import com .powsybl .commons .PowsyblException ;
10
- import com .powsybl .iidm .network .*;
10
+ import com .powsybl .iidm .network .TieLine ;
11
+ import com .powsybl .iidm .network .Validable ;
12
+ import com .powsybl .iidm .network .ValidationException ;
13
+ import com .powsybl .iidm .network .ValidationUtil ;
11
14
import com .powsybl .network .store .model .LineAttributes ;
12
15
import com .powsybl .network .store .model .Resource ;
13
16
@@ -28,7 +31,7 @@ public TieLineImpl(NetworkObjectIndex index, Resource<LineAttributes> resource)
28
31
}
29
32
}
30
33
31
- class HalfLineImpl implements HalfLine {
34
+ class HalfLineImpl implements HalfLine , Validable {
32
35
33
36
private final boolean one ;
34
37
@@ -38,40 +41,59 @@ public HalfLineImpl(boolean one) {
38
41
39
42
@ Override
40
43
public String getId () {
41
- return one ? resource .getAttributes ().getMergedXnode ().getLine1Name ()
42
- : resource .getAttributes ().getMergedXnode ().getLine2Name ();
44
+ return one ? resource .getAttributes ().getMergedXnode ().getLine1Id ()
45
+ : resource .getAttributes ().getMergedXnode ().getLine2Id ();
43
46
}
44
47
45
48
@ Override
46
49
public String getName () {
47
- return getId ();
50
+ String name = one ? resource .getAttributes ().getMergedXnode ().getLine1Name ()
51
+ : resource .getAttributes ().getMergedXnode ().getLine2Name ();
52
+ return name != null ? name : getId ();
53
+ }
54
+
55
+ @ Override
56
+ public boolean isFictitious () {
57
+ return one ? resource .getAttributes ().getMergedXnode ().isLine1Fictitious ()
58
+ : resource .getAttributes ().getMergedXnode ().isLine2Fictitious ();
48
59
}
49
60
50
61
@ Override
51
62
public double getXnodeP () {
52
63
return one ? resource .getAttributes ().getMergedXnode ().getXnodeP1 ()
53
- : resource .getAttributes ().getMergedXnode ().getXnodeP2 ();
64
+ : resource .getAttributes ().getMergedXnode ().getXnodeP2 ();
54
65
}
55
66
56
67
@ Override
57
68
public HalfLineImpl setXnodeP (double xnodeP ) {
69
+ checkValidationXnodeP (xnodeP );
70
+ double oldValue = getXnodeP ();
58
71
if (one ) {
59
72
resource .getAttributes ().getMergedXnode ().setXnodeP1 (xnodeP );
60
73
} else {
61
74
resource .getAttributes ().getMergedXnode ().setXnodeP2 (xnodeP );
62
75
}
76
+ index .notifyUpdate (TieLineImpl .this , getHalfLineAttribute () + ".xnodeP" , oldValue , xnodeP );
63
77
return this ;
64
78
}
65
79
66
80
@ Override
67
81
public double getXnodeQ () {
68
82
return one ? resource .getAttributes ().getMergedXnode ().getXnodeQ1 ()
69
- : resource .getAttributes ().getMergedXnode ().getXnodeQ2 ();
83
+ : resource .getAttributes ().getMergedXnode ().getXnodeQ2 ();
70
84
}
71
85
72
86
@ Override
73
87
public HalfLineImpl setXnodeQ (double xnodeQ ) {
74
- throw new UnsupportedOperationException ("TODO" );
88
+ checkValidationXnodeQ (xnodeQ );
89
+ double oldValue = getXnodeQ ();
90
+ if (one ) {
91
+ resource .getAttributes ().getMergedXnode ().setXnodeQ1 (xnodeQ );
92
+ } else {
93
+ resource .getAttributes ().getMergedXnode ().setXnodeQ2 (xnodeQ );
94
+ }
95
+ index .notifyUpdate (TieLineImpl .this , getHalfLineAttribute () + ".xnodeQ" , oldValue , xnodeQ );
96
+ return this ;
75
97
}
76
98
77
99
@ Override
@@ -81,7 +103,16 @@ public double getR() {
81
103
82
104
@ Override
83
105
public HalfLineImpl setR (double r ) {
84
- throw new UnsupportedOperationException ("TODO" );
106
+ ValidationUtil .checkR (this , r );
107
+ double oldValue = getR ();
108
+ double newR1 = one ? r : TieLineImpl .this .getR () * (resource .getAttributes ().getMergedXnode ().getRdp ());
109
+ double newR2 = !one ? r : TieLineImpl .this .getR () * (1 - resource .getAttributes ().getMergedXnode ().getRdp ());
110
+ double newR = newR1 + newR2 ;
111
+ double newRdp = newR == 0 ? 0.5 : newR1 / newR ;
112
+ resource .getAttributes ().setR (newR );
113
+ resource .getAttributes ().getMergedXnode ().setRdp ((float ) newRdp );
114
+ index .notifyUpdate (TieLineImpl .this , getHalfLineAttribute () + ".r" , oldValue , r );
115
+ return this ;
85
116
}
86
117
87
118
@ Override
@@ -91,50 +122,162 @@ public double getX() {
91
122
92
123
@ Override
93
124
public HalfLineImpl setX (double x ) {
94
- throw new UnsupportedOperationException ("TODO" );
125
+ ValidationUtil .checkX (this , x );
126
+ double oldValue = getX ();
127
+ double newX1 = one ? x : TieLineImpl .this .getX () * (resource .getAttributes ().getMergedXnode ().getXdp ());
128
+ double newX2 = !one ? x : TieLineImpl .this .getX () * (1 - resource .getAttributes ().getMergedXnode ().getXdp ());
129
+ double newX = newX1 + newX2 ;
130
+ double newXdp = newX == 0 ? 0.5 : newX1 / newX ;
131
+ resource .getAttributes ().setX (newX );
132
+ resource .getAttributes ().getMergedXnode ().setXdp ((float ) newXdp );
133
+ index .notifyUpdate (TieLineImpl .this , getHalfLineAttribute () + ".x" , oldValue , x );
134
+ return this ;
95
135
}
96
136
97
137
@ Override
98
138
public double getG1 () {
99
- return one ? TieLineImpl . this . getG1 () / 2 : TieLineImpl . this . getG2 () / 2 ;
139
+ return one ? resource . getAttributes (). getMergedXnode (). getLine1G1 () : resource . getAttributes (). getMergedXnode (). getLine2G1 () ;
100
140
}
101
141
102
142
@ Override
103
143
public HalfLineImpl setG1 (double g1 ) {
104
- throw new UnsupportedOperationException ("TODO" );
144
+ ValidationUtil .checkG1 (this , g1 );
145
+ double oldValue = getG1 ();
146
+ if (one ) {
147
+ double g2 = resource .getAttributes ().getMergedXnode ().getLine1G2 ();
148
+ resource .getAttributes ().getMergedXnode ().setLine1G1 (g1 );
149
+ resource .getAttributes ().setG1 (g1 + g2 );
150
+ } else {
151
+ double g2 = resource .getAttributes ().getMergedXnode ().getLine2G2 ();
152
+ resource .getAttributes ().getMergedXnode ().setLine2G1 (g1 );
153
+ resource .getAttributes ().setG2 (g1 + g2 );
154
+ }
155
+ index .notifyUpdate (TieLineImpl .this , getHalfLineAttribute () + ".g1" , oldValue , g1 );
156
+ return this ;
105
157
}
106
158
107
159
@ Override
108
160
public double getG2 () {
109
- return one ? TieLineImpl . this . getG1 () / 2 : TieLineImpl . this . getG2 () / 2 ;
161
+ return one ? resource . getAttributes (). getMergedXnode (). getLine1G2 () : resource . getAttributes (). getMergedXnode (). getLine2G2 () ;
110
162
}
111
163
112
164
@ Override
113
165
public HalfLineImpl setG2 (double g2 ) {
114
- throw new UnsupportedOperationException ("TODO" );
166
+ ValidationUtil .checkG2 (this , g2 );
167
+ double oldValue = getG2 ();
168
+ if (one ) {
169
+ double g1 = resource .getAttributes ().getMergedXnode ().getLine1G1 ();
170
+ resource .getAttributes ().getMergedXnode ().setLine1G2 (g2 );
171
+ resource .getAttributes ().setG1 (g1 + g2 );
172
+ } else {
173
+ double g1 = resource .getAttributes ().getMergedXnode ().getLine2G1 ();
174
+ resource .getAttributes ().getMergedXnode ().setLine2G2 (g2 );
175
+ resource .getAttributes ().setG2 (g1 + g2 );
176
+ }
177
+ index .notifyUpdate (TieLineImpl .this , getHalfLineAttribute () + ".g2" , oldValue , g2 );
178
+ return this ;
115
179
}
116
180
117
181
@ Override
118
182
public double getB1 () {
119
- return one ? TieLineImpl . this . getB1 () / 2 : TieLineImpl . this . getB2 () / 2 ;
183
+ return one ? resource . getAttributes (). getMergedXnode (). getLine1B1 () : resource . getAttributes (). getMergedXnode (). getLine2B1 () ;
120
184
}
121
185
122
186
@ Override
123
187
public HalfLineImpl setB1 (double b1 ) {
124
- throw new UnsupportedOperationException ("TODO" );
188
+ ValidationUtil .checkB1 (this , b1 );
189
+ double oldValue = getB1 ();
190
+ if (one ) {
191
+ double b2 = resource .getAttributes ().getMergedXnode ().getLine1B2 ();
192
+ resource .getAttributes ().getMergedXnode ().setLine1B1 (b1 );
193
+ resource .getAttributes ().setB1 (b1 + b2 );
194
+ } else {
195
+ double b2 = resource .getAttributes ().getMergedXnode ().getLine2B2 ();
196
+ resource .getAttributes ().getMergedXnode ().setLine2B1 (b1 );
197
+ resource .getAttributes ().setB2 (b1 + b2 );
198
+ }
199
+ index .notifyUpdate (TieLineImpl .this , getHalfLineAttribute () + ".b1" , oldValue , b1 );
200
+ return this ;
125
201
}
126
202
127
203
@ Override
128
204
public double getB2 () {
129
- return one ? TieLineImpl . this . getB1 () / 2 : TieLineImpl . this . getB2 () / 2 ;
205
+ return one ? resource . getAttributes (). getMergedXnode (). getLine1B2 () : resource . getAttributes (). getMergedXnode (). getLine2B2 () ;
130
206
}
131
207
132
208
@ Override
133
209
public HalfLineImpl setB2 (double b2 ) {
134
- throw new UnsupportedOperationException ("TODO" );
210
+ ValidationUtil .checkB2 (this , b2 );
211
+ double oldValue = getB2 ();
212
+ if (one ) {
213
+ double b1 = resource .getAttributes ().getMergedXnode ().getLine1B1 ();
214
+ resource .getAttributes ().getMergedXnode ().setLine1B2 (b2 );
215
+ resource .getAttributes ().setB1 (b1 + b2 );
216
+ } else {
217
+ double b1 = resource .getAttributes ().getMergedXnode ().getLine2B1 ();
218
+ resource .getAttributes ().getMergedXnode ().setLine2B2 (b2 );
219
+ resource .getAttributes ().setB2 (b1 + b2 );
220
+ }
221
+ index .notifyUpdate (TieLineImpl .this , getHalfLineAttribute () + ".b2" , oldValue , b2 );
222
+ return this ;
223
+ }
224
+
225
+ private String getHalfLineAttribute () {
226
+ return "half" + (one ? "1" : "2" );
227
+ }
228
+
229
+ @ Override
230
+ public String getMessageHeader () {
231
+ return String .format ("Tie line side %s '%s':" , one ? "1" : "2" , TieLineImpl .this .getId ());
232
+ }
233
+
234
+ private void checkValidationXnodeP (double xnodeP ) {
235
+ if (Double .isNaN (xnodeP )) {
236
+ throw new ValidationException (TieLineImpl .this , "xnodeP is invalid" );
237
+ }
238
+ }
239
+
240
+ private void checkValidationXnodeQ (double xnodeQ ) {
241
+ if (Double .isNaN (xnodeQ )) {
242
+ throw new ValidationException (TieLineImpl .this , "xnodeQ is invalid" );
243
+ }
135
244
}
136
245
}
137
246
247
+ private ValidationException createNotSupportedForTieLines () {
248
+ return new ValidationException (this , "direct modification of characteristics not supported for tie lines" );
249
+ }
250
+
251
+ @ Override
252
+ public TieLineImpl setR (double r ) {
253
+ throw createNotSupportedForTieLines ();
254
+ }
255
+
256
+ @ Override
257
+ public TieLineImpl setX (double x ) {
258
+ throw createNotSupportedForTieLines ();
259
+ }
260
+
261
+ @ Override
262
+ public TieLineImpl setG1 (double g1 ) {
263
+ throw createNotSupportedForTieLines ();
264
+ }
265
+
266
+ @ Override
267
+ public TieLineImpl setB1 (double b1 ) {
268
+ throw createNotSupportedForTieLines ();
269
+ }
270
+
271
+ @ Override
272
+ public TieLineImpl setG2 (double g2 ) {
273
+ throw createNotSupportedForTieLines ();
274
+ }
275
+
276
+ @ Override
277
+ public TieLineImpl setB2 (double b2 ) {
278
+ throw createNotSupportedForTieLines ();
279
+ }
280
+
138
281
@ Override
139
282
public String getUcteXnodeCode () {
140
283
return resource .getAttributes ().getMergedXnode ().getCode ();
0 commit comments