Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a P and Q bus equations for all buses #452

Merged
merged 2 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@ private AcEquationSystem() {
private static void createBusEquation(LfBus bus, LfNetworkParameters networkParameters,
EquationSystem<AcVariableType, AcEquationType> equationSystem,
AcEquationSystemCreationParameters creationParameters) {
var p = equationSystem.createEquation(bus.getNum(), AcEquationType.BUS_TARGET_P);
bus.setP(p);
var q = equationSystem.createEquation(bus.getNum(), AcEquationType.BUS_TARGET_Q);
bus.setQ(q);

if (bus.isSlack()) {
equationSystem.createEquation(bus.getNum(), AcEquationType.BUS_TARGET_PHI)
.addTerm(equationSystem.getVariable(bus.getNum(), AcVariableType.BUS_PHI)
.createTerm());
equationSystem.createEquation(bus.getNum(), AcEquationType.BUS_TARGET_P).setActive(false);
p.setActive(false);
}

createGeneratorControlEquations(bus, networkParameters, equationSystem, creationParameters);
Expand Down Expand Up @@ -282,17 +287,13 @@ private static void createNonImpedantBranch(LfBranch branch, LfBus bus1, LfBus b
bus1.setCalculatedV(vTerm);
// add a dummy reactive power variable to both sides of the non impedant branch and with an opposite sign
// to ensure we have the same number of equation and variables
Equation<AcVariableType, AcEquationType> sq1 = equationSystem.createEquation(bus1.getNum(), AcEquationType.BUS_TARGET_Q);
if (sq1.getTerms().isEmpty()) {
bus1.setQ(sq1);
}
sq1.addTerm(equationSystem.getVariable(branch.getNum(), AcVariableType.DUMMY_Q).createTerm());
equationSystem.getEquation(bus1.getNum(), AcEquationType.BUS_TARGET_Q)
.orElseThrow()
.addTerm(equationSystem.getVariable(branch.getNum(), AcVariableType.DUMMY_Q).createTerm());

Equation<AcVariableType, AcEquationType> sq2 = equationSystem.createEquation(bus2.getNum(), AcEquationType.BUS_TARGET_Q);
if (sq2.getTerms().isEmpty()) {
bus2.setQ(sq2);
}
sq2.addTerm(equationSystem.getVariable(branch.getNum(), AcVariableType.DUMMY_Q).<AcEquationType>createTerm()
equationSystem.getEquation(bus2.getNum(), AcEquationType.BUS_TARGET_Q)
.orElseThrow()
.addTerm(equationSystem.getVariable(branch.getNum(), AcVariableType.DUMMY_Q).<AcEquationType>createTerm()
.minus());
} else {
// nothing to do in case of v1 and v2 are found, we just have to ensure
Expand All @@ -311,17 +312,13 @@ private static void createNonImpedantBranch(LfBranch branch, LfBus bus1, LfBus b

// add a dummy active power variable to both sides of the non impedant branch and with an opposite sign
// to ensure we have the same number of equation and variables
Equation<AcVariableType, AcEquationType> sp1 = equationSystem.createEquation(bus1.getNum(), AcEquationType.BUS_TARGET_P);
if (sp1.getTerms().isEmpty()) {
bus1.setP(sp1);
}
sp1.addTerm(equationSystem.getVariable(branch.getNum(), AcVariableType.DUMMY_P).createTerm());
equationSystem.getEquation(bus1.getNum(), AcEquationType.BUS_TARGET_P)
.orElseThrow()
.addTerm(equationSystem.getVariable(branch.getNum(), AcVariableType.DUMMY_P).createTerm());

Equation<AcVariableType, AcEquationType> sp2 = equationSystem.createEquation(bus2.getNum(), AcEquationType.BUS_TARGET_P);
if (sp2.getTerms().isEmpty()) {
bus2.setP(sp2);
}
sp2.addTerm(equationSystem.getVariable(branch.getNum(), AcVariableType.DUMMY_P).<AcEquationType>createTerm()
equationSystem.getEquation(bus2.getNum(), AcEquationType.BUS_TARGET_P)
.orElseThrow()
.addTerm(equationSystem.getVariable(branch.getNum(), AcVariableType.DUMMY_P).<AcEquationType>createTerm()
.minus());
} else {
throw new IllegalStateException("Cannot happen because only there is one slack bus per model");
Expand Down Expand Up @@ -597,35 +594,27 @@ private static void createImpedantBranch(LfBranch branch, LfBus bus1, LfBus bus2
}

if (p1 != null) {
Equation<AcVariableType, AcEquationType> sp1 = equationSystem.createEquation(bus1.getNum(), AcEquationType.BUS_TARGET_P);
if (sp1.getTerms().isEmpty()) {
bus1.setP(sp1);
}
sp1.addTerm(p1);
equationSystem.getEquation(bus1.getNum(), AcEquationType.BUS_TARGET_P)
.orElseThrow()
.addTerm(p1);
branch.setP1(p1);
}
if (q1 != null) {
Equation<AcVariableType, AcEquationType> sq1 = equationSystem.createEquation(bus1.getNum(), AcEquationType.BUS_TARGET_Q);
if (sq1.getTerms().isEmpty()) {
bus1.setQ(sq1);
}
sq1.addTerm(q1);
equationSystem.getEquation(bus1.getNum(), AcEquationType.BUS_TARGET_Q)
.orElseThrow()
.addTerm(q1);
branch.setQ1(q1);
}
if (p2 != null) {
Equation<AcVariableType, AcEquationType> sp2 = equationSystem.createEquation(bus2.getNum(), AcEquationType.BUS_TARGET_P);
if (sp2.getTerms().isEmpty()) {
bus2.setP(sp2);
}
sp2.addTerm(p2);
equationSystem.getEquation(bus2.getNum(), AcEquationType.BUS_TARGET_P)
.orElseThrow()
.addTerm(p2);
branch.setP2(p2);
}
if (q2 != null) {
Equation<AcVariableType, AcEquationType> sq2 = equationSystem.createEquation(bus2.getNum(), AcEquationType.BUS_TARGET_Q);
if (sq2.getTerms().isEmpty()) {
bus2.setQ(sq2);
}
sq2.addTerm(q2);
equationSystem.getEquation(bus2.getNum(), AcEquationType.BUS_TARGET_Q)
.orElseThrow()
.addTerm(q2);
branch.setQ2(q2);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
package com.powsybl.openloadflow.dc.equations;

import com.powsybl.openloadflow.equations.Equation;
import com.powsybl.openloadflow.equations.EquationSystem;
import com.powsybl.openloadflow.equations.EquationSystemPostProcessor;
import com.powsybl.openloadflow.equations.EquationTerm;
Expand Down Expand Up @@ -36,10 +35,12 @@ private DcEquationSystem() {

private static void createBuses(LfNetwork network, EquationSystem<DcVariableType, DcEquationType> equationSystem) {
for (LfBus bus : network.getBuses()) {
var p = equationSystem.createEquation(bus.getNum(), DcEquationType.BUS_TARGET_P);
bus.setP(p);
if (bus.isSlack()) {
equationSystem.createEquation(bus.getNum(), DcEquationType.BUS_TARGET_PHI)
.addTerm(equationSystem.getVariable(bus.getNum(), DcVariableType.BUS_PHI).createTerm());
equationSystem.createEquation(bus.getNum(), DcEquationType.BUS_TARGET_P).setActive(false);
p.setActive(false);
}
}
}
Expand All @@ -58,19 +59,15 @@ public static void createNonImpedantBranch(EquationSystem<DcVariableType, DcEqua

// add a dummy active power variable to both sides of the non impedant branch and with an opposite sign
// to ensure we have the same number of equation and variables
Equation<DcVariableType, DcEquationType> sp1 = equationSystem.createEquation(bus1.getNum(), DcEquationType.BUS_TARGET_P);
if (sp1.getTerms().isEmpty()) {
bus1.setP(sp1);
}
sp1.addTerm(equationSystem.getVariable(branch.getNum(), DcVariableType.DUMMY_P)
.createTerm());

Equation<DcVariableType, DcEquationType> sp2 = equationSystem.createEquation(bus2.getNum(), DcEquationType.BUS_TARGET_P);
if (sp2.getTerms().isEmpty()) {
bus2.setP(sp2);
}
sp2.addTerm(equationSystem.getVariable(branch.getNum(), DcVariableType.DUMMY_P).<DcEquationType>createTerm()
.minus());
equationSystem.getEquation(bus1.getNum(), DcEquationType.BUS_TARGET_P)
.orElseThrow()
.addTerm(equationSystem.getVariable(branch.getNum(), DcVariableType.DUMMY_P)
.createTerm());

equationSystem.getEquation(bus2.getNum(), DcEquationType.BUS_TARGET_P)
.orElseThrow()
.addTerm(equationSystem.getVariable(branch.getNum(), DcVariableType.DUMMY_P).<DcEquationType>createTerm()
.minus());
} else {
throw new IllegalStateException("Cannot happen because only there is one slack bus per model");
}
Expand All @@ -83,16 +80,12 @@ private static void createImpedantBranch(EquationSystem<DcVariableType, DcEquati
boolean deriveA1 = creationParameters.isForcePhaseControlOffAndAddAngle1Var() && branch.hasPhaseControlCapability(); //TODO: phase control outer loop
ClosedBranchSide1DcFlowEquationTerm p1 = ClosedBranchSide1DcFlowEquationTerm.create(branch, bus1, bus2, equationSystem.getVariableSet(), deriveA1, creationParameters.isUseTransformerRatio());
ClosedBranchSide2DcFlowEquationTerm p2 = ClosedBranchSide2DcFlowEquationTerm.create(branch, bus1, bus2, equationSystem.getVariableSet(), deriveA1, creationParameters.isUseTransformerRatio());
Equation<DcVariableType, DcEquationType> sp1 = equationSystem.createEquation(bus1.getNum(), DcEquationType.BUS_TARGET_P);
if (sp1.getTerms().isEmpty()) {
bus1.setP(sp1);
}
sp1.addTerm(p1);
Equation<DcVariableType, DcEquationType> sp2 = equationSystem.createEquation(bus2.getNum(), DcEquationType.BUS_TARGET_P);
if (sp2.getTerms().isEmpty()) {
bus2.setP(sp2);
}
sp2.addTerm(p2);
equationSystem.getEquation(bus1.getNum(), DcEquationType.BUS_TARGET_P)
.orElseThrow()
.addTerm(p1);
equationSystem.getEquation(bus2.getNum(), DcEquationType.BUS_TARGET_P)
.orElseThrow()
.addTerm(p2);
if (deriveA1) {
if (creationParameters.isForcePhaseControlOffAndAddAngle1Var()) {
// use for sensitiviy analysis only: with this equation term, we force the a1 variable to be constant.
Expand Down