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

AC equations simplification #559

Merged
merged 2 commits into from
Jun 18, 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 @@ -16,6 +16,8 @@
import java.util.List;
import java.util.Objects;

import static com.powsybl.openloadflow.network.PiModel.A2;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
Expand Down Expand Up @@ -83,6 +85,14 @@ protected double a1() {
return a1Var != null ? sv.get(a1Var.getRow()) : branch.getPiModel().getA1();
}

public static double theta1(double ksi, double ph1, double a1, double ph2) {
return ksi - a1 + A2 - ph1 + ph2;
}

public static double theta2(double ksi, double ph1, double a1, double ph2) {
return ksi + a1 - A2 + ph1 - ph2;
}

protected abstract double calculateSensi(double dph1, double dph2, double dv1, double dv2, double da1, double dr1);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import java.util.Objects;

import static com.powsybl.openloadflow.network.PiModel.A2;
import static com.powsybl.openloadflow.network.PiModel.R2;

/**
Expand All @@ -30,69 +29,66 @@ public ClosedBranchSide1ActiveFlowEquationTerm(LfBranch branch, LfBus bus1, LfBu

protected double calculateSensi(double dph1, double dph2, double dv1, double dv2, double da1, double dr1) {
double v1 = v1();
double ph1 = ph1();
double r1 = r1();
double a1 = a1();
double v2 = v2();
double ph2 = ph2();
return dp1dph1(y, ksi, v1, ph1, r1, a1, v2, ph2) * dph1
+ dp1dph2(y, ksi, v1, ph1, r1, a1, v2, ph2) * dph2
+ dp1dv1(y, ksi, FastMath.sin(ksi), g1, v1, ph1, r1, a1, v2, ph2) * dv1
+ dp1dv2(y, ksi, v1, ph1, r1, a1, ph2) * dv2;
double theta = theta1(ksi, ph1(), a1(), ph2());
double cosTheta = FastMath.cos(theta);
double sinTheta = FastMath.sin(theta);
return dp1dph1(y, v1, r1, v2, cosTheta) * dph1
+ dp1dph2(y, v1, r1, v2, cosTheta) * dph2
+ dp1dv1(y, FastMath.sin(ksi), g1, v1, r1, v2, sinTheta) * dv1
+ dp1dv2(y, v1, r1, sinTheta) * dv2;
}

private static double theta(double ksi, double ph1, double a1, double ph2) {
return ksi - a1 + A2 - ph1 + ph2;
public static double p1(double y, double sinKsi, double g1, double v1, double r1, double v2, double sinTheta) {
return r1 * v1 * (g1 * r1 * v1 + y * r1 * v1 * sinKsi - y * R2 * v2 * sinTheta);
}

public static double p1(double y, double ksi, double sinKsi, double g1, double v1, double ph1, double r1, double a1, double v2, double ph2) {
return r1 * v1 * (g1 * r1 * v1 + y * r1 * v1 * sinKsi - y * R2 * v2 * FastMath.sin(theta(ksi, ph1, a1, ph2)));
private static double dp1dv1(double y, double sinKsi, double g1, double v1, double r1, double v2, double sinTheta) {
return r1 * (2 * g1 * r1 * v1 + 2 * y * r1 * v1 * sinKsi - y * R2 * v2 * sinTheta);
}

private static double dp1dv1(double y, double ksi, double sinKsi, double g1, double v1, double ph1, double r1, double a1, double v2, double ph2) {
return r1 * (2 * g1 * r1 * v1 + 2 * y * r1 * v1 * sinKsi - y * R2 * v2 * FastMath.sin(theta(ksi, ph1, a1, ph2)));
private static double dp1dv2(double y, double v1, double r1, double sinTheta) {
return -y * r1 * R2 * v1 * sinTheta;
}

private static double dp1dv2(double y, double ksi, double v1, double ph1, double r1, double a1, double ph2) {
return -y * r1 * R2 * v1 * FastMath.sin(theta(ksi, ph1, a1, ph2));
private static double dp1dph1(double y, double v1, double r1, double v2, double cosTheta) {
return y * r1 * R2 * v1 * v2 * cosTheta;
}

private static double dp1dph1(double y, double ksi, double v1, double ph1, double r1, double a1, double v2, double ph2) {
return y * r1 * R2 * v1 * v2 * FastMath.cos(theta(ksi, ph1, a1, ph2));
private static double dp1dph2(double y, double v1, double r1, double v2, double cosTheta) {
return -dp1dph1(y, v1, r1, v2, cosTheta);
}

private static double dp1dph2(double y, double ksi, double v1, double ph1, double r1, double a1, double v2, double ph2) {
return -dp1dph1(y, ksi, v1, ph1, r1, a1, v2, ph2);
private static double dp1da1(double y, double v1, double r1, double v2, double cosTheta) {
return dp1dph1(y, v1, r1, v2, cosTheta);
}

private static double dp1da1(double y, double ksi, double v1, double ph1, double r1, double a1, double v2, double ph2) {
return dp1dph1(y, ksi, v1, ph1, r1, a1, v2, ph2);
}

private static double dp1dr1(double y, double ksi, double sinKsi, double g1, double v1, double ph1, double r1, double a1, double v2, double ph2) {
return v1 * (2 * r1 * v1 * (g1 + y * sinKsi) - y * R2 * v2 * FastMath.sin(theta(ksi, ph1, a1, ph2)));
private static double dp1dr1(double y, double sinKsi, double g1, double v1, double r1, double v2, double sinTheta) {
return v1 * (2 * r1 * v1 * (g1 + y * sinKsi) - y * R2 * v2 * sinTheta);
}

@Override
public double eval() {
return p1(y, ksi, FastMath.sin(ksi), g1, v1(), ph1(), r1(), a1(), v2(), ph2());
return p1(y, FastMath.sin(ksi), g1, v1(), r1(), v2(), FastMath.sin(theta1(ksi, ph1(), a1(), ph2())));
}

@Override
public double der(Variable<AcVariableType> variable) {
Objects.requireNonNull(variable);
double theta = theta1(ksi, ph1(), a1(), ph2());
if (variable.equals(v1Var)) {
return dp1dv1(y, ksi, FastMath.sin(ksi), g1, v1(), ph1(), r1(), a1(), v2(), ph2());
return dp1dv1(y, FastMath.sin(ksi), g1, v1(), r1(), v2(), FastMath.sin(theta));
} else if (variable.equals(v2Var)) {
return dp1dv2(y, ksi, v1(), ph1(), r1(), a1(), ph2());
return dp1dv2(y, v1(), r1(), FastMath.sin(theta));
} else if (variable.equals(ph1Var)) {
return dp1dph1(y, ksi, v1(), ph1(), r1(), a1(), v2(), ph2());
return dp1dph1(y, v1(), r1(), v2(), FastMath.cos(theta));
} else if (variable.equals(ph2Var)) {
return dp1dph2(y, ksi, v1(), ph1(), r1(), a1(), v2(), ph2());
return dp1dph2(y, v1(), r1(), v2(), FastMath.cos(theta));
} else if (variable.equals(a1Var)) {
return dp1da1(y, ksi, v1(), ph1(), r1(), a1(), v2(), ph2());
return dp1da1(y, v1(), r1(), v2(), FastMath.cos(theta));
} else if (variable.equals(r1Var)) {
return dp1dr1(y, ksi, FastMath.sin(ksi), g1, v1(), ph1(), r1(), a1(), v2(), ph2());
return dp1dr1(y, FastMath.sin(ksi), g1, v1(), r1(), v2(), FastMath.sin(theta));
} else {
throw new IllegalStateException("Unknown variable: " + variable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import java.util.Objects;

import static com.powsybl.openloadflow.network.PiModel.A2;
import static com.powsybl.openloadflow.network.PiModel.R2;

/**
Expand All @@ -30,71 +29,68 @@ public ClosedBranchSide1ReactiveFlowEquationTerm(LfBranch branch, LfBus bus1, Lf

protected double calculateSensi(double dph1, double dph2, double dv1, double dv2, double da1, double dr1) {
double v1 = v1();
double ph1 = ph1();
double r1 = r1();
double a1 = a1();
double v2 = v2();
double ph2 = ph2();
return dq1dph1(y, ksi, v1, ph1, r1, a1, v2, ph2) * dph1
+ dq1dph2(y, ksi, v1, ph1, r1, a1, v2, ph2) * dph2
+ dq1dv1(y, ksi, FastMath.cos(ksi), b1, v1, ph1, r1, a1, v2, ph2) * dv1
+ dq1dv2(y, ksi, v1, ph1, r1, a1, ph2) * dv2;
double theta = theta1(ksi, ph1(), a1(), ph2());
double cosTheta = FastMath.cos(theta);
double sinTheta = FastMath.sin(theta);
return dq1dph1(y, v1, r1, v2, sinTheta) * dph1
+ dq1dph2(y, v1, r1, v2, sinTheta) * dph2
+ dq1dv1(y, FastMath.cos(ksi), b1, v1, r1, v2, cosTheta) * dv1
+ dq1dv2(y, v1, r1, cosTheta) * dv2;
}

private static double theta(double ksi, double ph1, double a1, double ph2) {
return ksi - a1 + A2 - ph1 + ph2;
}

public static double q1(double y, double ksi, double cosKsi, double b1, double v1, double ph1, double r1, double a1, double v2, double ph2) {
public static double q1(double y, double cosKsi, double b1, double v1, double r1, double v2, double cosTheta) {
return r1 * v1 * (-b1 * r1 * v1 + y * r1 * v1 * cosKsi
- y * R2 * v2 * FastMath.cos(theta(ksi, ph1, a1, ph2)));
- y * R2 * v2 * cosTheta);
}

private static double dq1dv1(double y, double ksi, double cosKsi, double b1, double v1, double ph1, double r1, double a1, double v2, double ph2) {
private static double dq1dv1(double y, double cosKsi, double b1, double v1, double r1, double v2, double cosTheta) {
return r1 * (-2 * b1 * r1 * v1 + 2 * y * r1 * v1 * cosKsi
- y * R2 * v2 * FastMath.cos(theta(ksi, ph1, a1, ph2)));
- y * R2 * v2 * cosTheta);
}

private static double dq1dv2(double y, double ksi, double v1, double ph1, double r1, double a1, double ph2) {
return -y * r1 * R2 * v1 * FastMath.cos(theta(ksi, ph1, a1, ph2));
private static double dq1dv2(double y, double v1, double r1, double cosTheta) {
return -y * r1 * R2 * v1 * cosTheta;
}

private static double dq1dph1(double y, double ksi, double v1, double ph1, double r1, double a1, double v2, double ph2) {
return -y * r1 * R2 * v1 * v2 * FastMath.sin(theta(ksi, ph1, a1, ph2));
private static double dq1dph1(double y, double v1, double r1, double v2, double sinTheta) {
return -y * r1 * R2 * v1 * v2 * sinTheta;
}

private static double dq1dph2(double y, double ksi, double v1, double ph1, double r1, double a1, double v2, double ph2) {
return -dq1dph1(y, ksi, v1, ph1, r1, a1, v2, ph2);
private static double dq1dph2(double y, double v1, double r1, double v2, double sinTheta) {
return -dq1dph1(y, v1, r1, v2, sinTheta);
}

private static double dq1da1(double y, double ksi, double v1, double ph1, double r1, double a1, double v2, double ph2) {
return dq1dph1(y, ksi, v1, ph1, r1, a1, v2, ph2);
private static double dq1da1(double y, double v1, double r1, double v2, double sinTheta) {
return dq1dph1(y, v1, r1, v2, sinTheta);
}

private static double dq1dr1(double y, double ksi, double cosKsi, double b1, double v1, double ph1, double r1, double a1, double v2, double ph2) {
return v1 * (2 * r1 * v1 * (-b1 + y * cosKsi) - y * R2 * v2 * FastMath.cos(theta(ksi, ph1, a1, ph2)));
private static double dq1dr1(double y, double cosKsi, double b1, double v1, double r1, double v2, double cosTheta) {
return v1 * (2 * r1 * v1 * (-b1 + y * cosKsi) - y * R2 * v2 * cosTheta);
}

@Override
public double eval() {
return q1(y, ksi, FastMath.cos(ksi), b1, v1(), ph1(), r1(), a1(), v2(), ph2());
return q1(y, FastMath.cos(ksi), b1, v1(), r1(), v2(), FastMath.cos(theta1(ksi, ph1(), a1(), ph2())));
}

@Override
public double der(Variable<AcVariableType> variable) {
Objects.requireNonNull(variable);
double theta = theta1(ksi, ph1(), a1(), ph2());
if (variable.equals(v1Var)) {
return dq1dv1(y, ksi, FastMath.cos(ksi), b1, v1(), ph1(), r1(), a1(), v2(), ph2());
return dq1dv1(y, FastMath.cos(ksi), b1, v1(), r1(), v2(), FastMath.cos(theta));
} else if (variable.equals(v2Var)) {
return dq1dv2(y, ksi, v1(), ph1(), r1(), a1(), ph2());
return dq1dv2(y, v1(), r1(), FastMath.cos(theta));
} else if (variable.equals(ph1Var)) {
return dq1dph1(y, ksi, v1(), ph1(), r1(), a1(), v2(), ph2());
return dq1dph1(y, v1(), r1(), v2(), FastMath.sin(theta));
} else if (variable.equals(ph2Var)) {
return dq1dph2(y, ksi, v1(), ph1(), r1(), a1(), v2(), ph2());
return dq1dph2(y, v1(), r1(), v2(), FastMath.sin(theta));
} else if (variable.equals(a1Var)) {
return dq1da1(y, ksi, v1(), ph1(), r1(), a1(), v2(), ph2());
return dq1da1(y, v1(), r1(), v2(), FastMath.sin(theta));
} else if (variable.equals(r1Var)) {
return dq1dr1(y, ksi, FastMath.cos(ksi), b1, v1(), ph1(), r1(), a1(), v2(), ph2());
return dq1dr1(y, FastMath.cos(ksi), b1, v1(), r1(), v2(), FastMath.cos(theta));
} else {
throw new IllegalStateException("Unknown variable: " + variable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import java.util.Objects;

import static com.powsybl.openloadflow.network.PiModel.A2;
import static com.powsybl.openloadflow.network.PiModel.R2;

/**
Expand All @@ -30,69 +29,66 @@ public ClosedBranchSide2ActiveFlowEquationTerm(LfBranch branch, LfBus bus1, LfBu

protected double calculateSensi(double dph1, double dph2, double dv1, double dv2, double da1, double dr1) {
double v1 = v1();
double ph1 = ph1();
double r1 = r1();
double a1 = a1();
double v2 = v2();
double ph2 = ph2();
return dp2dph1(y, ksi, v1, ph1, r1, a1, v2, ph2) * dph1
+ dp2dph2(y, ksi, v1, ph1, r1, a1, v2, ph2) * dph2
+ dp2dv1(y, ksi, ph1, r1, a1, v2, ph2) * dv1
+ dp2dv2(y, ksi, FastMath.sin(ksi), g2, v1, ph1, r1, a1, v2, ph2) * dv2;
double theta = theta2(ksi, ph1(), a1(), ph2());
double cosTheta = FastMath.cos(theta);
double sinTheta = FastMath.sin(theta);
return dp2dph1(y, v1, r1, v2, cosTheta) * dph1
+ dp2dph2(y, v1, r1, v2, cosTheta) * dph2
+ dp2dv1(y, r1, v2, sinTheta) * dv1
+ dp2dv2(y, FastMath.sin(ksi), g2, v1, r1, v2, sinTheta) * dv2;
}

private static double theta(double ksi, double ph1, double a1, double ph2) {
return ksi + a1 - A2 + ph1 - ph2;
public static double p2(double y, double sinKsi, double g2, double v1, double r1, double v2, double sinTheta) {
return R2 * v2 * (g2 * R2 * v2 - y * r1 * v1 * sinTheta + y * R2 * v2 * sinKsi);
}

public static double p2(double y, double ksi, double sinKsi, double g2, double v1, double ph1, double r1, double a1, double v2, double ph2) {
return R2 * v2 * (g2 * R2 * v2 - y * r1 * v1 * FastMath.sin(theta(ksi, ph1, a1, ph2)) + y * R2 * v2 * sinKsi);
private static double dp2dv1(double y, double r1, double v2, double sinTheta) {
return -y * r1 * R2 * v2 * sinTheta;
}

private static double dp2dv1(double y, double ksi, double ph1, double r1, double a1, double v2, double ph2) {
return -y * r1 * R2 * v2 * FastMath.sin(theta(ksi, ph1, a1, ph2));
private static double dp2dv2(double y, double sinKsi, double g2, double v1, double r1, double v2, double sinTheta) {
return R2 * (2 * g2 * R2 * v2 - y * r1 * v1 * sinTheta + 2 * y * R2 * v2 * sinKsi);
}

private static double dp2dv2(double y, double ksi, double sinKsi, double g2, double v1, double ph1, double r1, double a1, double v2, double ph2) {
return R2 * (2 * g2 * R2 * v2 - y * r1 * v1 * FastMath.sin(theta(ksi, ph1, a1, ph2)) + 2 * y * R2 * v2 * sinKsi);
private static double dp2dph1(double y, double v1, double r1, double v2, double cosTheta) {
return -y * r1 * R2 * v1 * v2 * cosTheta;
}

private static double dp2dph1(double y, double ksi, double v1, double ph1, double r1, double a1, double v2, double ph2) {
return -y * r1 * R2 * v1 * v2 * FastMath.cos(theta(ksi, ph1, a1, ph2));
private static double dp2dph2(double y, double v1, double r1, double v2, double cosTheta) {
return -dp2dph1(y, v1, r1, v2, cosTheta);
}

private static double dp2dph2(double y, double ksi, double v1, double ph1, double r1, double a1, double v2, double ph2) {
return -dp2dph1(y, ksi, v1, ph1, r1, a1, v2, ph2);
private static double dp2da1(double y, double v1, double r1, double v2, double cosTheta) {
return dp2dph1(y, v1, r1, v2, cosTheta);
}

private static double dp2da1(double y, double ksi, double v1, double ph1, double r1, double a1, double v2, double ph2) {
return dp2dph1(y, ksi, v1, ph1, r1, a1, v2, ph2);
}

private static double dp2dr1(double y, double ksi, double v1, double ph1, double a1, double v2, double ph2) {
return -y * R2 * v1 * v2 * FastMath.sin(theta(ksi, ph1, a1, ph2));
private static double dp2dr1(double y, double v1, double v2, double sinTheta) {
return -y * R2 * v1 * v2 * sinTheta;
}

@Override
public double eval() {
return p2(y, ksi, FastMath.sin(ksi), g2, v1(), ph1(), r1(), a1(), v2(), ph2());
return p2(y, FastMath.sin(ksi), g2, v1(), r1(), v2(), FastMath.sin(theta2(ksi, ph1(), a1(), ph2())));
}

@Override
public double der(Variable<AcVariableType> variable) {
Objects.requireNonNull(variable);
double theta = theta2(ksi, ph1(), a1(), ph2());
if (variable.equals(v1Var)) {
return dp2dv1(y, ksi, ph1(), r1(), a1(), v2(), ph2());
return dp2dv1(y, r1(), v2(), FastMath.sin(theta));
} else if (variable.equals(v2Var)) {
return dp2dv2(y, ksi, FastMath.sin(ksi), g2, v1(), ph1(), r1(), a1(), v2(), ph2());
return dp2dv2(y, FastMath.sin(ksi), g2, v1(), r1(), v2(), FastMath.sin(theta));
} else if (variable.equals(ph1Var)) {
return dp2dph1(y, ksi, v1(), ph1(), r1(), a1(), v2(), ph2());
return dp2dph1(y, v1(), r1(), v2(), FastMath.cos(theta));
} else if (variable.equals(ph2Var)) {
return dp2dph2(y, ksi, v1(), ph1(), r1(), a1(), v2(), ph2());
return dp2dph2(y, v1(), r1(), v2(), FastMath.cos(theta));
} else if (variable.equals(a1Var)) {
return dp2da1(y, ksi, v1(), ph1(), r1(), a1(), v2(), ph2());
return dp2da1(y, v1(), r1(), v2(), FastMath.cos(theta));
} else if (variable.equals(r1Var)) {
return dp2dr1(y, ksi, v1(), ph1(), a1(), v2(), ph2());
return dp2dr1(y, v1(), v2(), FastMath.sin(theta));
} else {
throw new IllegalStateException("Unknown variable: " + variable);
}
Expand Down
Loading