19
19
import org .apache .commons .collections4 .MapUtils ;
20
20
21
21
import java .util .*;
22
+ import java .util .Map .Entry ;
22
23
import java .util .function .Function ;
23
24
import java .util .function .ObjDoubleConsumer ;
24
25
import java .util .function .Predicate ;
25
- import java .util .function .ToDoubleFunction ;
26
26
import java .util .stream .Collectors ;
27
27
import java .util .stream .Stream ;
28
28
@@ -52,9 +52,6 @@ public final class CalculatedBus implements BaseBus {
52
52
53
53
private final Function <Terminal , Bus > getBusFromTerminal ;
54
54
55
- private static final String VOLTAGE = "v" ;
56
- private static final String ANGLE = "angle" ;
57
-
58
55
CalculatedBus (NetworkObjectIndex index , String voltageLevelId , String id , String name , Resource <VoltageLevelAttributes > voltageLevelResource ,
59
56
int calculatedBusNum , boolean isBusView ) {
60
57
this .index = Objects .requireNonNull (index );
@@ -142,24 +139,16 @@ private void setVInCalculatedBus(CalculatedBusAttributes calculatedBusAttributes
142
139
calculatedBusAttributes .setV (value );
143
140
}
144
141
145
- private void setVInConfiguredBus (ConfiguredBusAttributes configuredBusAttributes , double value ) {
146
- configuredBusAttributes .setV (value );
147
- }
148
-
149
- private double getVInBus (Bus bus ) {
150
- return bus .getV ();
142
+ private void setVInConfiguredBus (ConfiguredBusImpl configuredBus , double value ) {
143
+ configuredBus .setConfiguredBusV (value );
151
144
}
152
145
153
146
private void setAngleInCalculatedBus (CalculatedBusAttributes calculatedBusAttributes , double value ) {
154
147
calculatedBusAttributes .setAngle (value );
155
148
}
156
149
157
- private void setAngleInConfiguredBus (ConfiguredBusAttributes configuredBusAttributes , double value ) {
158
- configuredBusAttributes .setAngle (value );
159
- }
160
-
161
- private double getAngleInBus (Bus bus ) {
162
- return bus .getAngle ();
150
+ private void setAngleInConfiguredBus (ConfiguredBusImpl configuredBus , double value ) {
151
+ configuredBus .setConfiguredBusAngle (value );
163
152
}
164
153
165
154
@ Override
@@ -169,7 +158,8 @@ public Bus setV(double v) {
169
158
170
159
if (getVoltageLevel ().getTopologyKind () == TopologyKind .BUS_BREAKER ) {
171
160
// update V in configured buses
172
- updateConfiguredBuses (v , VOLTAGE , this ::getVInBus , this ::setVInConfiguredBus );
161
+ // this triggers network notifications for 'v' for each configured bus
162
+ updateConfiguredBuses (v , this ::setVInConfiguredBus );
173
163
} else {
174
164
// update V for buses in the other view (busView/busBreakerView)
175
165
updateBusesAttributes (v , this ::setVInCalculatedBus );
@@ -189,7 +179,8 @@ public Bus setAngle(double angle) {
189
179
190
180
if (getVoltageLevel ().getTopologyKind () == TopologyKind .BUS_BREAKER ) {
191
181
// update angle in configuredBus
192
- updateConfiguredBuses (angle , ANGLE , this ::getAngleInBus , this ::setAngleInConfiguredBus );
182
+ // this triggers network notifications for 'angle' for each configured bus
183
+ updateConfiguredBuses (angle , this ::setAngleInConfiguredBus );
193
184
} else {
194
185
// update angle for buses in the other view (busView/busBreakerView)
195
186
updateBusesAttributes (angle , this ::setAngleInCalculatedBus );
@@ -520,20 +511,19 @@ public int getCalculatedBusNum() {
520
511
}
521
512
522
513
private void updateBusesAttributes (double value , ObjDoubleConsumer <CalculatedBusAttributes > setValue ) {
514
+ // busnum of this bus -> nodes in this bus -> busnums in the other view -> buses of the other view
523
515
VoltageLevelAttributes vlAttributes = ((VoltageLevelImpl ) getVoltageLevel ()).getResource ().getAttributes ();
524
516
Map <Integer , Integer > nodesToCalculatedBuses = isBusView
525
517
? vlAttributes .getNodeToCalculatedBusForBusView ()
526
518
: vlAttributes .getNodeToCalculatedBusForBusBreakerView ();
527
- if (!MapUtils .isEmpty (nodesToCalculatedBuses )) {
528
- nodesToCalculatedBuses .entrySet ().stream ()
529
- .filter (entry -> getCalculatedBusNum () == entry .getValue ())
530
- .map (Map .Entry ::getKey )
531
- .forEach (node -> {
532
- Map <Integer , Integer > nodesToCalculatedBusesInOtherView = isBusView
533
- ? vlAttributes .getNodeToCalculatedBusForBusBreakerView ()
534
- : vlAttributes .getNodeToCalculatedBusForBusView ();
535
- if (!MapUtils .isEmpty (nodesToCalculatedBusesInOtherView ) &&
536
- nodesToCalculatedBusesInOtherView .containsKey (node )) {
519
+ Map <Integer , Integer > nodesToCalculatedBusesInOtherView = isBusView
520
+ ? vlAttributes .getNodeToCalculatedBusForBusBreakerView ()
521
+ : vlAttributes .getNodeToCalculatedBusForBusView ();
522
+ if (!MapUtils .isEmpty (nodesToCalculatedBuses ) && !MapUtils .isEmpty (nodesToCalculatedBusesInOtherView )) {
523
+ for (Entry <Integer , Integer > entry : nodesToCalculatedBuses .entrySet ()) {
524
+ if (getCalculatedBusNum () == entry .getValue ()) {
525
+ int node = entry .getKey ();
526
+ if (nodesToCalculatedBusesInOtherView .containsKey (node )) {
537
527
int busNumInOtherView = nodesToCalculatedBusesInOtherView .get (node );
538
528
List <CalculatedBusAttributes > calculatedBusAttributes = isBusView
539
529
? vlAttributes .getCalculatedBusesForBusBreakerView ()
@@ -543,35 +533,19 @@ private void updateBusesAttributes(double value, ObjDoubleConsumer<CalculatedBus
543
533
index .updateVoltageLevelResource (voltageLevelResource , AttributeFilter .SV );
544
534
}
545
535
}
546
- });
536
+ }
537
+ }
547
538
}
548
539
}
549
540
550
541
private void updateConfiguredBuses (double newValue ,
551
- String attributeName ,
552
- ToDoubleFunction <Bus > getValue ,
553
- ObjDoubleConsumer <ConfiguredBusAttributes > setValue ) {
554
- List <Bus > buses = ((VoltageLevelImpl ) getVoltageLevel ()).getResource ().getAttributes ()
555
- .getBusToCalculatedBusForBusView ().entrySet ().stream ()
556
- .filter (entry -> getCalculatedBusNum () == entry .getValue ())
557
- .map (Map .Entry ::getKey )
558
- .map (getVoltageLevel ().getBusBreakerView ()::getBus )
559
- .toList ();
560
-
561
- Map <Bus , Map .Entry <Double , Double >> oldNewValues = buses .stream ()
562
- .collect (Collectors .toMap (
563
- bus -> bus ,
564
- bus -> new AbstractMap .SimpleEntry <>(getValue .applyAsDouble (bus ), newValue )
565
- ));
566
-
567
- buses .forEach (bus -> {
568
- setValue .accept (((ConfiguredBusImpl ) bus ).getResource ().getAttributes (), newValue );
569
- index .updateConfiguredBusResource (((ConfiguredBusImpl ) bus ).getResource (), null );
570
- });
571
-
572
- String variantId = index .getNetwork ().getVariantManager ().getWorkingVariantId ();
573
- oldNewValues .forEach ((bus , oldNewValue ) ->
574
- index .notifyUpdate (bus , attributeName , variantId , oldNewValue .getKey (), oldNewValue .getValue ())
575
- );
542
+ ObjDoubleConsumer <ConfiguredBusImpl > setValue ) {
543
+ VoltageLevelAttributes vlAttributes = ((VoltageLevelImpl ) getVoltageLevel ()).getResource ().getAttributes ();
544
+ for (Entry <String , Integer > entry : vlAttributes .getBusToCalculatedBusForBusView ().entrySet ()) {
545
+ if (getCalculatedBusNum () == entry .getValue ()) {
546
+ Bus bus = getVoltageLevel ().getBusBreakerView ().getBus (entry .getKey ());
547
+ setValue .accept ((ConfiguredBusImpl ) bus , newValue );
548
+ }
549
+ }
576
550
}
577
551
}
0 commit comments