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

Less cos(ski) and sin(ksi) computation #551

Merged
merged 1 commit into from
Jun 11, 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 @@ -10,7 +10,6 @@
import com.powsybl.openloadflow.equations.VariableSet;
import com.powsybl.openloadflow.network.LfBranch;
import com.powsybl.openloadflow.network.LfBus;
import net.jafama.FastMath;

import java.util.List;

Expand All @@ -31,9 +30,7 @@ protected AbstractOpenSide1BranchAcFlowEquationTerm(LfBranch branch, AcVariableT
}
}

protected static double shunt(double y, double ksi, double g1, double b1) {
double sinKsi = FastMath.sin(ksi);
double cosKsi = FastMath.cos(ksi);
protected static double shunt(double y, double cosKsi, double sinKsi, double g1, double b1) {
return (g1 + y * sinKsi) * (g1 + y * sinKsi) + (-b1 + y * cosKsi) * (-b1 + y * cosKsi);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.powsybl.openloadflow.equations.VariableSet;
import com.powsybl.openloadflow.network.LfBranch;
import com.powsybl.openloadflow.network.LfBus;
import net.jafama.FastMath;

import java.util.List;

Expand All @@ -31,9 +30,8 @@ protected AbstractOpenSide2BranchAcFlowEquationTerm(LfBranch branch, AcVariableT
}
}

protected static double shunt(double y, double ksi, double g2, double b2) {
double cosKsi = FastMath.cos(ksi);
return (g2 + y * FastMath.sin(ksi)) * (g2 + y * FastMath.sin(ksi)) + (-b2 + y * cosKsi) * (-b2 + y * cosKsi);
protected static double shunt(double y, double cosKsi, double sinKsi, double g2, double b2) {
return (g2 + y * sinKsi) * (g2 + y * sinKsi) + (-b2 + y * cosKsi) * (-b2 + y * cosKsi);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ protected double calculateSensi(double dph1, double dph2, double dv1, double dv2
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, g1, v1, ph1, r1, a1, v2, ph2) * dv1
+ dp1dv1(y, ksi, FastMath.sin(ksi), g1, v1, ph1, r1, a1, v2, ph2) * dv1
+ dp1dv2(y, ksi, v1, ph1, r1, a1, ph2) * dv2;
}

protected static double theta(double ksi, double ph1, double a1, double ph2) {
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 ksi, double g1, double v1, double ph1, double r1, double a1, double v2, double ph2) {
return r1 * v1 * (g1 * r1 * v1 + y * r1 * v1 * FastMath.sin(ksi) - y * R2 * v2 * FastMath.sin(theta(ksi, ph1, a1, ph2)));
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 ksi, double g1, double v1, double ph1, double r1, double a1, double v2, double ph2) {
return r1 * (2 * g1 * r1 * v1 + 2 * y * r1 * v1 * FastMath.sin(ksi) - y * R2 * v2 * FastMath.sin(theta(ksi, ph1, a1, ph2)));
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 ksi, double v1, double ph1, double r1, double a1, double ph2) {
Expand All @@ -69,20 +69,20 @@ private static double dp1da1(double y, double ksi, double v1, double ph1, double
return dp1dph1(y, ksi, v1, ph1, r1, a1, v2, ph2);
}

private static double dp1dr1(double y, double ksi, double g1, double v1, double ph1, double r1, double a1, double v2, double ph2) {
return v1 * (2 * r1 * v1 * (g1 + y * FastMath.sin(ksi)) - y * R2 * v2 * FastMath.sin(theta(ksi, ph1, a1, 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)));
}

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

@Override
public double der(Variable<AcVariableType> variable) {
Objects.requireNonNull(variable);
if (variable.equals(v1Var)) {
return dp1dv1(y, ksi, g1, v1(), ph1(), r1(), a1(), v2(), ph2());
return dp1dv1(y, ksi, FastMath.sin(ksi), g1, v1(), ph1(), r1(), a1(), v2(), ph2());
} else if (variable.equals(v2Var)) {
return dp1dv2(y, ksi, v1(), ph1(), r1(), a1(), ph2());
} else if (variable.equals(ph1Var)) {
Expand All @@ -92,7 +92,7 @@ public double der(Variable<AcVariableType> variable) {
} else if (variable.equals(a1Var)) {
return dp1da1(y, ksi, v1(), ph1(), r1(), a1(), v2(), ph2());
} else if (variable.equals(r1Var)) {
return dp1dr1(y, ksi, g1, v1(), ph1(), r1(), a1(), v2(), ph2());
return dp1dr1(y, ksi, FastMath.sin(ksi), g1, v1(), ph1(), r1(), a1(), v2(), ph2());
} else {
throw new IllegalStateException("Unknown variable: " + variable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,21 @@ protected double calculateSensi(double dph1, double dph2, double dv1, double dv2
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, b1, v1, ph1, r1, a1, v2, ph2) * dv1
+ dq1dv1(y, ksi, FastMath.cos(ksi), b1, v1, ph1, r1, a1, v2, ph2) * dv1
+ dq1dv2(y, ksi, v1, ph1, r1, a1, ph2) * dv2;
}

protected static double theta(double ksi, double ph1, double a1, double ph2) {
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 b1, double v1, double ph1, double r1, double a1, double v2, double ph2) {
return r1 * v1 * (-b1 * r1 * v1 + y * r1 * v1 * FastMath.cos(ksi)
public static double q1(double y, double ksi, double cosKsi, double b1, double v1, double ph1, double r1, double a1, double v2, double ph2) {
return r1 * v1 * (-b1 * r1 * v1 + y * r1 * v1 * cosKsi
- y * R2 * v2 * FastMath.cos(theta(ksi, ph1, a1, ph2)));
}

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

Expand All @@ -71,20 +71,20 @@ private static double dq1da1(double y, double ksi, double v1, double ph1, double
return dq1dph1(y, ksi, v1, ph1, r1, a1, v2, ph2);
}

private static double dq1dr1(double y, double ksi, double b1, double v1, double ph1, double r1, double a1, double v2, double ph2) {
return v1 * (2 * r1 * v1 * (-b1 + y * FastMath.cos(ksi)) - y * R2 * v2 * FastMath.cos(theta(ksi, ph1, a1, ph2)));
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)));
}

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

@Override
public double der(Variable<AcVariableType> variable) {
Objects.requireNonNull(variable);
if (variable.equals(v1Var)) {
return dq1dv1(y, ksi, b1, v1(), ph1(), r1(), a1(), v2(), ph2());
return dq1dv1(y, ksi, FastMath.cos(ksi), b1, v1(), ph1(), r1(), a1(), v2(), ph2());
} else if (variable.equals(v2Var)) {
return dq1dv2(y, ksi, v1(), ph1(), r1(), a1(), ph2());
} else if (variable.equals(ph1Var)) {
Expand All @@ -94,7 +94,7 @@ public double der(Variable<AcVariableType> variable) {
} else if (variable.equals(a1Var)) {
return dq1da1(y, ksi, v1(), ph1(), r1(), a1(), v2(), ph2());
} else if (variable.equals(r1Var)) {
return dq1dr1(y, ksi, b1, v1(), ph1(), r1(), a1(), v2(), ph2());
return dq1dr1(y, ksi, FastMath.cos(ksi), b1, v1(), ph1(), r1(), a1(), v2(), ph2());
} else {
throw new IllegalStateException("Unknown variable: " + variable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@ protected double calculateSensi(double dph1, double dph2, double dv1, double dv2
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, g2, v1, ph1, r1, a1, v2, ph2) * dv2;
+ dp2dv2(y, ksi, FastMath.sin(ksi), g2, v1, ph1, r1, a1, v2, ph2) * 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 ksi, 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 * FastMath.sin(ksi));
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 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 ksi, 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 * FastMath.sin(ksi));
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 ksi, double v1, double ph1, double r1, double a1, double v2, double ph2) {
Expand All @@ -75,7 +75,7 @@ private static double dp2dr1(double y, double ksi, double v1, double ph1, double

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

@Override
Expand All @@ -84,7 +84,7 @@ public double der(Variable<AcVariableType> variable) {
if (variable.equals(v1Var)) {
return dp2dv1(y, ksi, ph1(), r1(), a1(), v2(), ph2());
} else if (variable.equals(v2Var)) {
return dp2dv2(y, ksi, g2, v1(), ph1(), r1(), a1(), v2(), ph2());
return dp2dv2(y, ksi, FastMath.sin(ksi), g2, v1(), ph1(), r1(), a1(), v2(), ph2());
} else if (variable.equals(ph1Var)) {
return dp2dph1(y, ksi, v1(), ph1(), r1(), a1(), v2(), ph2());
} else if (variable.equals(ph2Var)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@ protected double calculateSensi(double dph1, double dph2, double dv1, double dv2
return dq2dph1(y, ksi, v1, ph1, r1, a1, v2, ph2) * dph1
+ dq2dph2(y, ksi, v1, ph1, r1, a1, v2, ph2) * dph2
+ dq2dv1(y, ksi, ph1, r1, a1, v2, ph2) * dv1
+ dq2dv2(y, ksi, b2, v1, ph1, r1, a1, v2, ph2) * dv2;
+ dq2dv2(y, ksi, FastMath.cos(ksi), b2, v1, ph1, r1, a1, v2, ph2) * dv2;
}

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

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

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

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

private static double dq2dph1(double y, double ksi, double v1, double ph1, double r1, double a1, double v2, double ph2) {
Expand All @@ -75,7 +75,7 @@ private static double dq2dr1(double y, double ksi, double v1, double ph1, double

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

@Override
Expand All @@ -84,7 +84,7 @@ public double der(Variable<AcVariableType> variable) {
if (variable.equals(v1Var)) {
return dq2dv1(y, ksi, ph1(), r1(), a1(), v2(), ph2());
} else if (variable.equals(v2Var)) {
return dq2dv2(y, ksi, b2, v1(), ph1(), r1(), a1(), v2(), ph2());
return dq2dv2(y, ksi, FastMath.cos(ksi), b2, v1(), ph1(), r1(), a1(), v2(), ph2());
} else if (variable.equals(ph1Var)) {
return dq2dph1(y, ksi, v1(), ph1(), r1(), a1(), v2(), ph2());
} else if (variable.equals(ph2Var)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,26 @@ private double v2() {
return sv.get(v2Var.getRow());
}

private static double p2(double y, double ksi, double g1, double b1, double g2, double v2) {
double shunt = shunt(y, ksi, g1, b1);
return R2 * R2 * v2 * v2 * (g2 + y * y * g1 / shunt + (b1 * b1 + g1 * g1) * y * FastMath.sin(ksi) / shunt);
private static double p2(double y, double cosKsi, double sinKsi, double g1, double b1, double g2, double v2) {
double shunt = shunt(y, cosKsi, sinKsi, g1, b1);
return R2 * R2 * v2 * v2 * (g2 + y * y * g1 / shunt + (b1 * b1 + g1 * g1) * y * sinKsi / shunt);
}

private static double dp2dv2(double y, double ksi, double g1, double b1, double g2, double v2) {
double shunt = shunt(y, ksi, g1, b1);
return 2 * R2 * R2 * v2 * (g2 + y * y * g1 / shunt + (b1 * b1 + g1 * g1) * y * FastMath.sin(ksi) / shunt);
private static double dp2dv2(double y, double cosKsi, double sinKsi, double g1, double b1, double g2, double v2) {
double shunt = shunt(y, cosKsi, sinKsi, g1, b1);
return 2 * R2 * R2 * v2 * (g2 + y * y * g1 / shunt + (b1 * b1 + g1 * g1) * y * sinKsi / shunt);
}

@Override
public double eval() {
return p2(y, ksi, g1, b1, g2, v2());
return p2(y, FastMath.cos(ksi), FastMath.sin(ksi), g1, b1, g2, v2());
}

@Override
public double der(Variable<AcVariableType> variable) {
Objects.requireNonNull(variable);
if (variable.equals(v2Var)) {
return dp2dv2(y, ksi, g1, b1, g2, v2());
return dp2dv2(y, FastMath.cos(ksi), FastMath.sin(ksi), g1, b1, g2, v2());
} else {
throw new IllegalStateException("Unknown variable: " + variable);
}
Expand Down
Loading