Skip to content

Commit d5a6cc8

Browse files
authored
Distributed slack fixed (#114)
1 parent 43919ff commit d5a6cc8

16 files changed

+115
-74
lines changed

simple-loadflow/src/main/java/com/powsybl/loadflow/simple/ac/AcLoadFlowLogger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
package com.powsybl.loadflow.simple.ac;
88

9-
import com.powsybl.loadflow.simple.ac.observer.DefaultAcLoadFlowObserver;
9+
import com.powsybl.loadflow.simple.ac.macro.DefaultAcLoadFlowObserver;
1010
import com.powsybl.loadflow.simple.equations.Equation;
1111
import com.powsybl.loadflow.simple.equations.EquationSystem;
1212
import org.slf4j.Logger;

simple-loadflow/src/main/java/com/powsybl/loadflow/simple/ac/AcLoadFlowProfiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
package com.powsybl.loadflow.simple.ac;
88

99
import com.google.common.base.Stopwatch;
10-
import com.powsybl.loadflow.simple.ac.observer.DefaultAcLoadFlowObserver;
10+
import com.powsybl.loadflow.simple.ac.macro.DefaultAcLoadFlowObserver;
1111
import com.powsybl.loadflow.simple.equations.EquationSystem;
1212
import com.powsybl.math.matrix.Matrix;
1313
import org.slf4j.Logger;

simple-loadflow/src/main/java/com/powsybl/loadflow/simple/ac/DistributedSlackAction.java

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
package com.powsybl.loadflow.simple.ac;
88

99
import com.powsybl.commons.PowsyblException;
10+
import com.powsybl.loadflow.simple.ac.macro.MacroAction;
11+
import com.powsybl.loadflow.simple.ac.macro.MacroActionContext;
1012
import com.powsybl.loadflow.simple.network.LfBus;
1113
import com.powsybl.loadflow.simple.network.LfNetwork;
1214
import com.powsybl.loadflow.simple.network.PerUnit;
@@ -76,46 +78,7 @@ public boolean run(MacroActionContext context) {
7678
while (!participatingBuses.isEmpty()
7779
&& Math.abs(remainingMismatch) > SLACK_EPSILON) {
7880

79-
// normalize participation factors at each iteration start as some
80-
// buses might have reach a limit and have been discarded
81-
normalizeParticipationFactors(participatingBuses);
82-
83-
double done = 0d;
84-
Iterator<ParticipatingBus> it = participatingBuses.iterator();
85-
while (it.hasNext()) {
86-
ParticipatingBus participatingBus = it.next();
87-
LfBus bus = participatingBus.bus;
88-
double factor = participatingBus.factor;
89-
90-
double minP = bus.getMinP();
91-
double maxP = bus.getMaxP();
92-
double generationTargetP = bus.getGenerationTargetP();
93-
94-
// we don't want to change the generation sign
95-
if (generationTargetP < 0) {
96-
maxP = Math.min(maxP, 0);
97-
} else {
98-
minP = Math.max(minP, 0);
99-
}
100-
101-
double newGenerationTargetP = generationTargetP + remainingMismatch * factor;
102-
if (remainingMismatch > 0 && newGenerationTargetP > maxP) {
103-
newGenerationTargetP = maxP;
104-
it.remove();
105-
} else if (remainingMismatch < 0 && newGenerationTargetP < minP) {
106-
newGenerationTargetP = minP;
107-
it.remove();
108-
}
109-
110-
if (LOGGER.isTraceEnabled()) {
111-
LOGGER.trace("Rescale '{}' active power target: {} -> {}",
112-
bus.getId(), generationTargetP, newGenerationTargetP);
113-
}
114-
bus.setGenerationTargetP(newGenerationTargetP);
115-
done += newGenerationTargetP - generationTargetP;
116-
}
117-
118-
remainingMismatch -= done;
81+
remainingMismatch -= run(participatingBuses, remainingMismatch);
11982

12083
iteration++;
12184
}
@@ -135,4 +98,47 @@ public boolean run(MacroActionContext context) {
13598

13699
return false;
137100
}
101+
102+
private double run(List<ParticipatingBus> participatingBuses, double remainingMismatch) {
103+
// normalize participation factors at each iteration start as some
104+
// buses might have reach a limit and have been discarded
105+
normalizeParticipationFactors(participatingBuses);
106+
107+
double done = 0d;
108+
Iterator<ParticipatingBus> it = participatingBuses.iterator();
109+
while (it.hasNext()) {
110+
ParticipatingBus participatingBus = it.next();
111+
LfBus bus = participatingBus.bus;
112+
double factor = participatingBus.factor;
113+
114+
double minP = bus.getMinP();
115+
double maxP = bus.getMaxP();
116+
double generationTargetP = bus.getGenerationTargetP();
117+
118+
// we don't want to change the generation sign
119+
if (generationTargetP < 0) {
120+
maxP = Math.min(maxP, 0);
121+
} else {
122+
minP = Math.max(minP, 0);
123+
}
124+
125+
double newGenerationTargetP = generationTargetP + remainingMismatch * factor;
126+
if (remainingMismatch > 0 && newGenerationTargetP > maxP) {
127+
newGenerationTargetP = maxP;
128+
it.remove();
129+
} else if (remainingMismatch < 0 && newGenerationTargetP < minP) {
130+
newGenerationTargetP = minP;
131+
it.remove();
132+
}
133+
134+
if (LOGGER.isTraceEnabled()) {
135+
LOGGER.trace("Rescale '{}' active power target: {} -> {}",
136+
bus.getId(), generationTargetP, newGenerationTargetP);
137+
}
138+
bus.setGenerationTargetP(newGenerationTargetP);
139+
done += newGenerationTargetP - generationTargetP;
140+
}
141+
142+
return done;
143+
}
138144
}

simple-loadflow/src/main/java/com/powsybl/loadflow/simple/ac/SimpleAcLoadFlow.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212
import com.powsybl.loadflow.LoadFlowParameters;
1313
import com.powsybl.loadflow.LoadFlowResult;
1414
import com.powsybl.loadflow.LoadFlowResultImpl;
15+
import com.powsybl.loadflow.simple.ac.macro.AcLoadFlowObserver;
16+
import com.powsybl.loadflow.simple.ac.macro.AcLoadFlowResult;
17+
import com.powsybl.loadflow.simple.ac.macro.AcloadFlowEngine;
18+
import com.powsybl.loadflow.simple.ac.macro.MacroAction;
1519
import com.powsybl.loadflow.simple.ac.nr.NewtonRaphsonStatus;
1620
import com.powsybl.loadflow.simple.ac.nr.VoltageInitializer;
17-
import com.powsybl.loadflow.simple.ac.observer.AcLoadFlowObserver;
1821
import com.powsybl.loadflow.simple.network.LfNetwork;
1922
import com.powsybl.loadflow.simple.network.SlackBusSelector;
2023
import com.powsybl.loadflow.simple.network.impl.LfNetworks;
@@ -78,7 +81,7 @@ private AcLoadFlowObserver getObserver() {
7881
}
7982

8083
private static ImmutableMap<String, String> createMetrics(AcLoadFlowResult result) {
81-
return ImmutableMap.of("iterations", Integer.toString(result.getNewtowRaphsonIterations()),
84+
return ImmutableMap.of("iterations", Integer.toString(result.getNewtonRaphsonIterations()),
8285
"status", result.getNewtonRaphsonStatus().name());
8386
}
8487

simple-loadflow/src/main/java/com/powsybl/loadflow/simple/ac/observer/AcLoadFlowObserver.java renamed to simple-loadflow/src/main/java/com/powsybl/loadflow/simple/ac/macro/AcLoadFlowObserver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
7-
package com.powsybl.loadflow.simple.ac.observer;
7+
package com.powsybl.loadflow.simple.ac.macro;
88

99
import com.powsybl.loadflow.simple.equations.EquationSystem;
1010
import com.powsybl.math.matrix.Matrix;

simple-loadflow/src/main/java/com/powsybl/loadflow/simple/ac/AcLoadFlowResult.java renamed to simple-loadflow/src/main/java/com/powsybl/loadflow/simple/ac/macro/AcLoadFlowResult.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
7-
package com.powsybl.loadflow.simple.ac;
7+
package com.powsybl.loadflow.simple.ac.macro;
88

99
import com.powsybl.loadflow.simple.ac.nr.NewtonRaphsonStatus;
1010

@@ -15,22 +15,22 @@ public class AcLoadFlowResult {
1515

1616
private final int macroIterations;
1717

18-
private final int newtowRaphsonIterations;
18+
private final int newtonRaphsonIterations;
1919

2020
private final NewtonRaphsonStatus newtonRaphsonStatus;
2121

22-
public AcLoadFlowResult(int macroIterations, int newtowRaphsonIterations, NewtonRaphsonStatus newtonRaphsonStatus) {
22+
public AcLoadFlowResult(int macroIterations, int newtonRaphsonIterations, NewtonRaphsonStatus newtonRaphsonStatus) {
2323
this.macroIterations = macroIterations;
24-
this.newtowRaphsonIterations = newtowRaphsonIterations;
24+
this.newtonRaphsonIterations = newtonRaphsonIterations;
2525
this.newtonRaphsonStatus = newtonRaphsonStatus;
2626
}
2727

2828
public int getMacroIterations() {
2929
return macroIterations;
3030
}
3131

32-
public int getNewtowRaphsonIterations() {
33-
return newtowRaphsonIterations;
32+
public int getNewtonRaphsonIterations() {
33+
return newtonRaphsonIterations;
3434
}
3535

3636
public NewtonRaphsonStatus getNewtonRaphsonStatus() {

simple-loadflow/src/main/java/com/powsybl/loadflow/simple/ac/AcloadFlowEngine.java renamed to simple-loadflow/src/main/java/com/powsybl/loadflow/simple/ac/macro/AcloadFlowEngine.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
7-
package com.powsybl.loadflow.simple.ac;
7+
package com.powsybl.loadflow.simple.ac.macro;
88

99
import com.google.common.base.Stopwatch;
1010
import com.powsybl.loadflow.simple.ac.equations.AcEquationSystem;
1111
import com.powsybl.loadflow.simple.ac.nr.*;
12-
import com.powsybl.loadflow.simple.ac.observer.AcLoadFlowObserver;
1312
import com.powsybl.loadflow.simple.equations.EquationContext;
1413
import com.powsybl.loadflow.simple.equations.EquationSystem;
1514
import com.powsybl.loadflow.simple.network.PerUnit;
@@ -52,7 +51,7 @@ public AcloadFlowEngine(LfNetwork network, VoltageInitializer voltageInitializer
5251

5352
private NewtonRaphsonResult runNewtowRaphson(LfNetwork network, EquationContext equationContext,
5453
EquationSystem equationSystem, NewtonRaphsonParameters newtonRaphsonParameters,
55-
int newtowRaphsonIteration, int macroIteration, String macroActionName) {
54+
int newtonRaphsonIteration, int macroIteration, String macroActionName) {
5655
observer.beginMacroIteration(macroIteration, macroActionName);
5756

5857
// for next macro iteration, restart from previous voltage
@@ -61,7 +60,7 @@ private NewtonRaphsonResult runNewtowRaphson(LfNetwork network, EquationContext
6160

6261
NewtonRaphsonResult newtonRaphsonResult = new NewtonRaphson(network, matrixFactory, observer, equationContext,
6362
equationSystem, macroIterationVoltageInitializer,
64-
newtowRaphsonIteration)
63+
newtonRaphsonIteration)
6564
.run(newtonRaphsonParameters);
6665

6766
observer.endMacroIteration(macroIteration, macroActionName);
@@ -91,7 +90,7 @@ public AcLoadFlowResult run() {
9190
// for each macro action run macro iterations until stabilized
9291
// macro actions are nested: inner most loop first in the list
9392
for (MacroAction macroAction : macroActions) {
94-
// re-run macro action + newtow raphson until stabilization
93+
// re-run macro action + newton-raphson until stabilization
9594
boolean cont;
9695
do {
9796
observer.beforeMacroActionRun(macroIteration, macroAction.getName());

simple-loadflow/src/main/java/com/powsybl/loadflow/simple/ac/observer/DefaultAcLoadFlowObserver.java renamed to simple-loadflow/src/main/java/com/powsybl/loadflow/simple/ac/macro/DefaultAcLoadFlowObserver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
7-
package com.powsybl.loadflow.simple.ac.observer;
7+
package com.powsybl.loadflow.simple.ac.macro;
88

99
import com.powsybl.loadflow.simple.equations.EquationSystem;
1010
import com.powsybl.math.matrix.Matrix;

simple-loadflow/src/main/java/com/powsybl/loadflow/simple/ac/MacroAction.java renamed to simple-loadflow/src/main/java/com/powsybl/loadflow/simple/ac/macro/MacroAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
7-
package com.powsybl.loadflow.simple.ac;
7+
package com.powsybl.loadflow.simple.ac.macro;
88

99
/**
1010
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>

simple-loadflow/src/main/java/com/powsybl/loadflow/simple/ac/MacroActionContext.java renamed to simple-loadflow/src/main/java/com/powsybl/loadflow/simple/ac/macro/MacroActionContext.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
7-
package com.powsybl.loadflow.simple.ac;
7+
package com.powsybl.loadflow.simple.ac.macro;
88

99
import com.powsybl.loadflow.simple.ac.nr.NewtonRaphsonResult;
1010
import com.powsybl.loadflow.simple.network.LfNetwork;
@@ -14,7 +14,7 @@
1414
/**
1515
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
1616
*/
17-
class MacroActionContext {
17+
public class MacroActionContext {
1818

1919
private final int macroIteration;
2020

@@ -28,15 +28,15 @@ class MacroActionContext {
2828
this.newtonRaphsonResult = Objects.requireNonNull(newtonRaphsonResult);
2929
}
3030

31-
int getMacroIteration() {
31+
public int getMacroIteration() {
3232
return macroIteration;
3333
}
3434

35-
LfNetwork getNetwork() {
35+
public LfNetwork getNetwork() {
3636
return network;
3737
}
3838

39-
NewtonRaphsonResult getNewtonRaphsonResult() {
39+
public NewtonRaphsonResult getNewtonRaphsonResult() {
4040
return newtonRaphsonResult;
4141
}
4242
}

0 commit comments

Comments
 (0)