From a3deeea5fb551803bd648e5487c21e4716a3b395 Mon Sep 17 00:00:00 2001 From: Geoffroy Jamgotchian Date: Fri, 10 Jun 2022 22:15:25 +0200 Subject: [PATCH] Optimize cos and sin of ksi Signed-off-by: Geoffroy Jamgotchian --- ...ractOpenSide1BranchAcFlowEquationTerm.java | 5 +- ...ractOpenSide2BranchAcFlowEquationTerm.java | 6 +-- ...osedBranchSide1ActiveFlowEquationTerm.java | 22 ++++----- ...edBranchSide1ReactiveFlowEquationTerm.java | 22 ++++----- ...osedBranchSide2ActiveFlowEquationTerm.java | 14 +++--- ...edBranchSide2ReactiveFlowEquationTerm.java | 14 +++--- ...OpenBranchSide1ActiveFlowEquationTerm.java | 16 +++---- ...anchSide1CurrentMagnitudeEquationTerm.java | 46 +++++++++---------- ...enBranchSide1ReactiveFlowEquationTerm.java | 16 +++---- ...OpenBranchSide2ActiveFlowEquationTerm.java | 16 +++---- ...anchSide2CurrentMagnitudeEquationTerm.java | 46 +++++++++---------- ...enBranchSide2ReactiveFlowEquationTerm.java | 16 +++---- 12 files changed, 117 insertions(+), 122 deletions(-) diff --git a/src/main/java/com/powsybl/openloadflow/ac/equations/AbstractOpenSide1BranchAcFlowEquationTerm.java b/src/main/java/com/powsybl/openloadflow/ac/equations/AbstractOpenSide1BranchAcFlowEquationTerm.java index 473e946193..f58583a17b 100644 --- a/src/main/java/com/powsybl/openloadflow/ac/equations/AbstractOpenSide1BranchAcFlowEquationTerm.java +++ b/src/main/java/com/powsybl/openloadflow/ac/equations/AbstractOpenSide1BranchAcFlowEquationTerm.java @@ -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; @@ -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); } diff --git a/src/main/java/com/powsybl/openloadflow/ac/equations/AbstractOpenSide2BranchAcFlowEquationTerm.java b/src/main/java/com/powsybl/openloadflow/ac/equations/AbstractOpenSide2BranchAcFlowEquationTerm.java index a7668f3b2f..1faf8fa1d6 100644 --- a/src/main/java/com/powsybl/openloadflow/ac/equations/AbstractOpenSide2BranchAcFlowEquationTerm.java +++ b/src/main/java/com/powsybl/openloadflow/ac/equations/AbstractOpenSide2BranchAcFlowEquationTerm.java @@ -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; @@ -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 diff --git a/src/main/java/com/powsybl/openloadflow/ac/equations/ClosedBranchSide1ActiveFlowEquationTerm.java b/src/main/java/com/powsybl/openloadflow/ac/equations/ClosedBranchSide1ActiveFlowEquationTerm.java index 7a53a9d5fc..788bd61fec 100644 --- a/src/main/java/com/powsybl/openloadflow/ac/equations/ClosedBranchSide1ActiveFlowEquationTerm.java +++ b/src/main/java/com/powsybl/openloadflow/ac/equations/ClosedBranchSide1ActiveFlowEquationTerm.java @@ -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) { @@ -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 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)) { @@ -92,7 +92,7 @@ public double der(Variable 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); } diff --git a/src/main/java/com/powsybl/openloadflow/ac/equations/ClosedBranchSide1ReactiveFlowEquationTerm.java b/src/main/java/com/powsybl/openloadflow/ac/equations/ClosedBranchSide1ReactiveFlowEquationTerm.java index d8e5fab16e..0d67098219 100644 --- a/src/main/java/com/powsybl/openloadflow/ac/equations/ClosedBranchSide1ReactiveFlowEquationTerm.java +++ b/src/main/java/com/powsybl/openloadflow/ac/equations/ClosedBranchSide1ReactiveFlowEquationTerm.java @@ -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))); } @@ -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 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)) { @@ -94,7 +94,7 @@ public double der(Variable 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); } diff --git a/src/main/java/com/powsybl/openloadflow/ac/equations/ClosedBranchSide2ActiveFlowEquationTerm.java b/src/main/java/com/powsybl/openloadflow/ac/equations/ClosedBranchSide2ActiveFlowEquationTerm.java index 0887d2b8a8..ec9586f71a 100644 --- a/src/main/java/com/powsybl/openloadflow/ac/equations/ClosedBranchSide2ActiveFlowEquationTerm.java +++ b/src/main/java/com/powsybl/openloadflow/ac/equations/ClosedBranchSide2ActiveFlowEquationTerm.java @@ -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) { @@ -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 @@ -84,7 +84,7 @@ public double der(Variable 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)) { diff --git a/src/main/java/com/powsybl/openloadflow/ac/equations/ClosedBranchSide2ReactiveFlowEquationTerm.java b/src/main/java/com/powsybl/openloadflow/ac/equations/ClosedBranchSide2ReactiveFlowEquationTerm.java index c92924c6a3..8419ad3580 100644 --- a/src/main/java/com/powsybl/openloadflow/ac/equations/ClosedBranchSide2ReactiveFlowEquationTerm.java +++ b/src/main/java/com/powsybl/openloadflow/ac/equations/ClosedBranchSide2ReactiveFlowEquationTerm.java @@ -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) { @@ -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 @@ -84,7 +84,7 @@ public double der(Variable 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)) { diff --git a/src/main/java/com/powsybl/openloadflow/ac/equations/OpenBranchSide1ActiveFlowEquationTerm.java b/src/main/java/com/powsybl/openloadflow/ac/equations/OpenBranchSide1ActiveFlowEquationTerm.java index 272f7b3b3d..1b411b3054 100644 --- a/src/main/java/com/powsybl/openloadflow/ac/equations/OpenBranchSide1ActiveFlowEquationTerm.java +++ b/src/main/java/com/powsybl/openloadflow/ac/equations/OpenBranchSide1ActiveFlowEquationTerm.java @@ -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 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); } diff --git a/src/main/java/com/powsybl/openloadflow/ac/equations/OpenBranchSide1CurrentMagnitudeEquationTerm.java b/src/main/java/com/powsybl/openloadflow/ac/equations/OpenBranchSide1CurrentMagnitudeEquationTerm.java index 6cbbf9c53e..51ae08d65d 100644 --- a/src/main/java/com/powsybl/openloadflow/ac/equations/OpenBranchSide1CurrentMagnitudeEquationTerm.java +++ b/src/main/java/com/powsybl/openloadflow/ac/equations/OpenBranchSide1CurrentMagnitudeEquationTerm.java @@ -41,53 +41,53 @@ private double ph2() { return sv.get(ph2Var.getRow()); } - private static double gres(double y, double ksi, double g1, double b1, double g2, double shunt) { - return g2 + (y * y * g1 + (b1 * b1 + g1 * g1) * y * FastMath.sin(ksi)) / shunt; + private static double gres(double y, double sinKsi, double g1, double b1, double g2, double shunt) { + return g2 + (y * y * g1 + (b1 * b1 + g1 * g1) * y * sinKsi) / shunt; } - private static double bres(double y, double ksi, double g1, double b1, double b2, double shunt) { - return b2 + (y * y * b1 - (b1 * b1 + g1 * g1) * y * FastMath.cos(ksi)) / shunt; + private static double bres(double y, double cosKsi, double g1, double b1, double b2, double shunt) { + return b2 + (y * y * b1 - (b1 * b1 + g1 * g1) * y * cosKsi) / shunt; } - private static double reI2(double y, double ksi, double g1, double b1, double g2, double b2, double v2, double ph2) { - double shunt = shunt(y, ksi, g1, b1); - return R2 * R2 * v2 * (gres(y, ksi, g1, b1, g2, shunt) * FastMath.cos(ph2) - bres(y, ksi, g1, b1, b2, shunt) * FastMath.sin(ph2)); + private static double reI2(double y, double cosKsi, double sinKsi, double g1, double b1, double g2, double b2, double v2, double ph2) { + double shunt = shunt(y, cosKsi, sinKsi, g1, b1); + return R2 * R2 * v2 * (gres(y, sinKsi, g1, b1, g2, shunt) * FastMath.cos(ph2) - bres(y, cosKsi, g1, b1, b2, shunt) * FastMath.sin(ph2)); } - private static double imI2(double y, double ksi, double g1, double b1, double g2, double b2, double v2, double ph2) { - double shunt = shunt(y, ksi, g1, b1); - return R2 * R2 * v2 * (gres(y, ksi, g1, b1, g2, shunt) * FastMath.sin(ph2) + bres(y, ksi, g1, b1, b2, shunt) * FastMath.cos(ph2)); + private static double imI2(double y, double cosKsi, double sinKsi, double g1, double b1, double g2, double b2, double v2, double ph2) { + double shunt = shunt(y, cosKsi, sinKsi, g1, b1); + return R2 * R2 * v2 * (gres(y, sinKsi, g1, b1, g2, shunt) * FastMath.sin(ph2) + bres(y, cosKsi, g1, b1, b2, shunt) * FastMath.cos(ph2)); } - private static double i2(double y, double ksi, double g1, double b1, double g2, double b2, double v2, double ph2) { - return FastMath.hypot(reI2(y, ksi, g1, b1, g2, b2, v2, ph2), imI2(y, ksi, g1, b1, g2, b2, v2, ph2)); + private static double i2(double y, double cosKsi, double sinKsi, double g1, double b1, double g2, double b2, double v2, double ph2) { + return FastMath.hypot(reI2(y, cosKsi, sinKsi, g1, b1, g2, b2, v2, ph2), imI2(y, cosKsi, sinKsi, g1, b1, g2, b2, v2, ph2)); } - private static double dreI2dv2(double y, double ksi, double g1, double b1, double g2, double b2, double ph2) { - double shunt = shunt(y, ksi, g1, b1); - return R2 * R2 * (gres(y, ksi, g1, b1, g2, shunt) * FastMath.cos(ph2) - bres(y, ksi, g1, b1, b2, shunt) * FastMath.sin(ph2)); + private static double dreI2dv2(double y, double cosKsi, double sinKsi, double g1, double b1, double g2, double b2, double ph2) { + double shunt = shunt(y, cosKsi, sinKsi, g1, b1); + return R2 * R2 * (gres(y, sinKsi, g1, b1, g2, shunt) * FastMath.cos(ph2) - bres(y, cosKsi, g1, b1, b2, shunt) * FastMath.sin(ph2)); } - private static double dimI2dv2(double y, double ksi, double g1, double b1, double g2, double b2, double ph2) { - double shunt = shunt(y, ksi, g1, b1); - return R2 * R2 * (gres(y, ksi, g1, b1, g2, shunt) * FastMath.sin(ph2) + bres(y, ksi, g1, b1, b2, shunt) * FastMath.cos(ph2)); + private static double dimI2dv2(double y, double cosKsi, double sinKsi, double g1, double b1, double g2, double b2, double ph2) { + double shunt = shunt(y, cosKsi, sinKsi, g1, b1); + return R2 * R2 * (gres(y, sinKsi, g1, b1, g2, shunt) * FastMath.sin(ph2) + bres(y, cosKsi, g1, b1, b2, shunt) * FastMath.cos(ph2)); } - private static double di2dv2(double y, double ksi, double g1, double b1, double g2, double b2, double v2, double ph2) { - return (reI2(y, ksi, g1, b1, g2, b2, v2, ph2) * dreI2dv2(y, ksi, g1, b1, g2, b2, ph2) - + imI2(y, ksi, g1, b1, g2, b2, v2, ph2) * dimI2dv2(y, ksi, g1, b1, g2, b2, ph2)) / i2(y, ksi, g1, b1, g2, b2, v2, ph2); + private static double di2dv2(double y, double cosKsi, double sinKsi, double g1, double b1, double g2, double b2, double v2, double ph2) { + return (reI2(y, cosKsi, sinKsi, g1, b1, g2, b2, v2, ph2) * dreI2dv2(y, cosKsi, sinKsi, g1, b1, g2, b2, ph2) + + imI2(y, cosKsi, sinKsi, g1, b1, g2, b2, v2, ph2) * dimI2dv2(y, cosKsi, sinKsi, g1, b1, g2, b2, ph2)) / i2(y, cosKsi, sinKsi, g1, b1, g2, b2, v2, ph2); } @Override public double eval() { - return i2(y, ksi, g1, b1, g2, b2, v2(), ph2()); + return i2(y, FastMath.cos(ksi), FastMath.sin(ksi), g1, b1, g2, b2, v2(), ph2()); } @Override public double der(Variable variable) { Objects.requireNonNull(variable); if (variable.equals(v2Var)) { - return di2dv2(y, ksi, g1, b1, g2, b2, v2(), ph2()); + return di2dv2(y, FastMath.cos(ksi), FastMath.sin(ksi), g1, b1, g2, b2, v2(), ph2()); } else { throw new IllegalStateException("Unknown variable: " + variable); } diff --git a/src/main/java/com/powsybl/openloadflow/ac/equations/OpenBranchSide1ReactiveFlowEquationTerm.java b/src/main/java/com/powsybl/openloadflow/ac/equations/OpenBranchSide1ReactiveFlowEquationTerm.java index 9fa099544f..bf9da8928a 100644 --- a/src/main/java/com/powsybl/openloadflow/ac/equations/OpenBranchSide1ReactiveFlowEquationTerm.java +++ b/src/main/java/com/powsybl/openloadflow/ac/equations/OpenBranchSide1ReactiveFlowEquationTerm.java @@ -33,26 +33,26 @@ private double v2() { return sv.get(v2Var.getRow()); } - private static double q2(double y, double ksi, double g1, double b1, double b2, double v2) { - double shunt = shunt(y, ksi, g1, b1); - return -R2 * R2 * v2 * v2 * (b2 + y * y * b1 / shunt - (b1 * b1 + g1 * g1) * y * FastMath.cos(ksi) / shunt); + private static double q2(double y, double cosKsi, double sinKsi, double g1, double b1, double b2, double v2) { + double shunt = shunt(y, cosKsi, sinKsi, g1, b1); + return -R2 * R2 * v2 * v2 * (b2 + y * y * b1 / shunt - (b1 * b1 + g1 * g1) * y * cosKsi / shunt); } - private static double dq2dv2(double y, double ksi, double g1, double b1, double b2, double v2) { - double shunt = shunt(y, ksi, g1, b1); - return -2 * v2 * R2 * R2 * (b2 + y * y * b1 / shunt - (b1 * b1 + g1 * g1) * y * FastMath.cos(ksi) / shunt); + private static double dq2dv2(double y, double cosKsi, double sinKsi, double g1, double b1, double b2, double v2) { + double shunt = shunt(y, cosKsi, sinKsi, g1, b1); + return -2 * v2 * R2 * R2 * (b2 + y * y * b1 / shunt - (b1 * b1 + g1 * g1) * y * cosKsi / shunt); } @Override public double eval() { - return q2(y, ksi, g1, b1, b2, v2()); + return q2(y, FastMath.cos(ksi), FastMath.sin(ksi), g1, b1, b2, v2()); } @Override public double der(Variable variable) { Objects.requireNonNull(variable); if (variable.equals(v2Var)) { - return dq2dv2(y, ksi, g1, b1, b2, v2()); + return dq2dv2(y, FastMath.cos(ksi), FastMath.sin(ksi), g1, b1, b2, v2()); } else { throw new IllegalStateException("Unknown variable: " + variable); } diff --git a/src/main/java/com/powsybl/openloadflow/ac/equations/OpenBranchSide2ActiveFlowEquationTerm.java b/src/main/java/com/powsybl/openloadflow/ac/equations/OpenBranchSide2ActiveFlowEquationTerm.java index 9ba9fbd668..ac4c64e15e 100644 --- a/src/main/java/com/powsybl/openloadflow/ac/equations/OpenBranchSide2ActiveFlowEquationTerm.java +++ b/src/main/java/com/powsybl/openloadflow/ac/equations/OpenBranchSide2ActiveFlowEquationTerm.java @@ -35,26 +35,26 @@ private double r1() { return branch.getPiModel().getR1(); } - private static double p2(double y, double ksi, double g1, double g2, double b2, double v1, double r1) { - double shunt = shunt(y, ksi, g2, b2); - return r1 * r1 * v1 * v1 * (g1 + y * y * g2 / shunt + (b2 * b2 + g2 * g2) * y * FastMath.sin(ksi) / shunt); + private static double p2(double y, double cosKsi, double sinKsi, double g1, double g2, double b2, double v1, double r1) { + double shunt = shunt(y, cosKsi, sinKsi, g2, b2); + return r1 * r1 * v1 * v1 * (g1 + y * y * g2 / shunt + (b2 * b2 + g2 * g2) * y * sinKsi / shunt); } - private static double dp2dv1(double y, double ksi, double g1, double g2, double b2, double v1, double r1) { - double shunt = shunt(y, ksi, g2, b2); - return 2 * r1 * r1 * v1 * (g1 + y * y * g2 / shunt + (b2 * b2 + g2 * g2) * y * FastMath.sin(ksi) / shunt); + private static double dp2dv1(double y, double cosKsi, double sinKsi, double g1, double g2, double b2, double v1, double r1) { + double shunt = shunt(y, cosKsi, sinKsi, g2, b2); + return 2 * r1 * r1 * v1 * (g1 + y * y * g2 / shunt + (b2 * b2 + g2 * g2) * y * sinKsi / shunt); } @Override public double eval() { - return p2(y, ksi, g1, g2, b2, v1(), r1()); + return p2(y, FastMath.cos(ksi), FastMath.sin(ksi), g1, g2, b2, v1(), r1()); } @Override public double der(Variable variable) { Objects.requireNonNull(variable); if (variable.equals(v1Var)) { - return dp2dv1(y, ksi, g1, g2, b2, v1(), r1()); + return dp2dv1(y, FastMath.cos(ksi), FastMath.sin(ksi), g1, g2, b2, v1(), r1()); } else { throw new IllegalStateException("Unknown variable: " + variable); } diff --git a/src/main/java/com/powsybl/openloadflow/ac/equations/OpenBranchSide2CurrentMagnitudeEquationTerm.java b/src/main/java/com/powsybl/openloadflow/ac/equations/OpenBranchSide2CurrentMagnitudeEquationTerm.java index b42aaf001e..0c4b993d54 100644 --- a/src/main/java/com/powsybl/openloadflow/ac/equations/OpenBranchSide2CurrentMagnitudeEquationTerm.java +++ b/src/main/java/com/powsybl/openloadflow/ac/equations/OpenBranchSide2CurrentMagnitudeEquationTerm.java @@ -48,53 +48,53 @@ private double r1() { return r1Var != null ? sv.get(r1Var.getRow()) : branch.getPiModel().getR1(); } - private static double gres(double y, double ksi, double g1, double g2, double b2, double shunt) { - return g1 + (y * y * g2 + (b2 * b2 + g2 * g2) * y * FastMath.sin(ksi)) / shunt; + private static double gres(double y, double sinksi, double g1, double g2, double b2, double shunt) { + return g1 + (y * y * g2 + (b2 * b2 + g2 * g2) * y * sinksi) / shunt; } - private static double bres(double y, double ksi, double b1, double g2, double b2, double shunt) { - return b1 + (y * y * b2 - (b2 * b2 + g2 * g2) * y * FastMath.cos(ksi)) / shunt; + private static double bres(double y, double cosKsi, double b1, double g2, double b2, double shunt) { + return b1 + (y * y * b2 - (b2 * b2 + g2 * g2) * y * cosKsi) / shunt; } - private static double reI2(double y, double ksi, double g1, double b1, double g2, double b2, double v1, double ph1, double r1) { - double shunt = shunt(y, ksi, g2, b2); - return r1 * r1 * v1 * (gres(y, ksi, g1, g2, b2, shunt) * FastMath.cos(ph1) - bres(y, ksi, b1, g2, b2, shunt) * FastMath.sin(ph1)); + private static double reI2(double y, double cosKsi, double sinKsi, double g1, double b1, double g2, double b2, double v1, double ph1, double r1) { + double shunt = shunt(y, cosKsi, sinKsi, g2, b2); + return r1 * r1 * v1 * (gres(y, sinKsi, g1, g2, b2, shunt) * FastMath.cos(ph1) - bres(y, cosKsi, b1, g2, b2, shunt) * FastMath.sin(ph1)); } - private static double imI2(double y, double ksi, double g1, double b1, double g2, double b2, double v1, double ph1, double r1) { - double shunt = shunt(y, ksi, g2, b2); - return r1 * r1 * v1 * (gres(y, ksi, g1, g2, b2, shunt) * FastMath.sin(ph1) + bres(y, ksi, b1, g2, b2, shunt) * FastMath.cos(ph1)); + private static double imI2(double y, double cosKsi, double sinKsi, double g1, double b1, double g2, double b2, double v1, double ph1, double r1) { + double shunt = shunt(y, cosKsi, sinKsi, g2, b2); + return r1 * r1 * v1 * (gres(y, sinKsi, g1, g2, b2, shunt) * FastMath.sin(ph1) + bres(y, cosKsi, b1, g2, b2, shunt) * FastMath.cos(ph1)); } - private static double i2(double y, double ksi, double g1, double b1, double g2, double b2, double v1, double ph1, double r1) { - return FastMath.hypot(reI2(y, ksi, g1, b1, g2, b2, v1, ph1, r1), imI2(y, ksi, g1, b1, g2, b2, v1, ph1, r1)); + private static double i2(double y, double cosKsi, double sinKsi, double g1, double b1, double g2, double b2, double v1, double ph1, double r1) { + return FastMath.hypot(reI2(y, cosKsi, sinKsi, g1, b1, g2, b2, v1, ph1, r1), imI2(y, cosKsi, sinKsi, g1, b1, g2, b2, v1, ph1, r1)); } - private static double dreI2dv1(double y, double ksi, double g1, double b1, double g2, double b2, double ph1, double r1) { - double shunt = shunt(y, ksi, g2, b2); - return r1 * r1 * (gres(y, ksi, g1, g2, b2, shunt) * FastMath.cos(ph1) - bres(y, ksi, b1, g2, b2, shunt) * FastMath.sin(ph1)); + private static double dreI2dv1(double y, double cosKsi, double sinKsi, double g1, double b1, double g2, double b2, double ph1, double r1) { + double shunt = shunt(y, cosKsi, sinKsi, g2, b2); + return r1 * r1 * (gres(y, sinKsi, g1, g2, b2, shunt) * FastMath.cos(ph1) - bres(y, cosKsi, b1, g2, b2, shunt) * FastMath.sin(ph1)); } - private static double dimI2dv1(double y, double ksi, double g1, double b1, double g2, double b2, double ph1, double r1) { - double shunt = shunt(y, ksi, g2, b2); - return r1 * r1 * (gres(y, ksi, g1, g2, b2, shunt) * FastMath.sin(ph1) + bres(y, ksi, b1, g2, b2, shunt) * FastMath.cos(ph1)); + private static double dimI2dv1(double y, double cosKsi, double sinKsi, double g1, double b1, double g2, double b2, double ph1, double r1) { + double shunt = shunt(y, cosKsi, sinKsi, g2, b2); + return r1 * r1 * (gres(y, sinKsi, g1, g2, b2, shunt) * FastMath.sin(ph1) + bres(y, cosKsi, b1, g2, b2, shunt) * FastMath.cos(ph1)); } - private static double di2dv1(double y, double ksi, double g1, double b1, double g2, double b2, double v1, double ph1, double r1) { - return (reI2(y, ksi, g1, b1, g2, b2, v1, ph1, r1) * dreI2dv1(y, ksi, g1, b1, g2, b2, ph1, r1) - + imI2(y, ksi, g1, b1, g2, b2, v1, ph1, r1) * dimI2dv1(y, ksi, g1, b1, g2, b2, ph1, r1)) / i2(y, ksi, g1, b1, g2, b2, v1, ph1, r1); + private static double di2dv1(double y, double cosKsi, double sinKsi, double g1, double b1, double g2, double b2, double v1, double ph1, double r1) { + return (reI2(y, cosKsi, sinKsi, g1, b1, g2, b2, v1, ph1, r1) * dreI2dv1(y, cosKsi, sinKsi, g1, b1, g2, b2, ph1, r1) + + imI2(y, cosKsi, sinKsi, g1, b1, g2, b2, v1, ph1, r1) * dimI2dv1(y, cosKsi, sinKsi, g1, b1, g2, b2, ph1, r1)) / i2(y, cosKsi, sinKsi, g1, b1, g2, b2, v1, ph1, r1); } @Override public double eval() { - return i2(y, ksi, g1, b1, g2, b2, v1(), ph1(), r1()); + return i2(y, FastMath.cos(ksi), FastMath.sin(ksi), g1, b1, g2, b2, v1(), ph1(), r1()); } @Override public double der(Variable variable) { Objects.requireNonNull(variable); if (variable.equals(v1Var)) { - return di2dv1(y, ksi, g1, b1, g2, b2, v1(), ph1(), r1()); + return di2dv1(y, FastMath.cos(ksi), FastMath.sin(ksi), g1, b1, g2, b2, v1(), ph1(), r1()); } else { throw new IllegalStateException("Unknown variable: " + variable); } diff --git a/src/main/java/com/powsybl/openloadflow/ac/equations/OpenBranchSide2ReactiveFlowEquationTerm.java b/src/main/java/com/powsybl/openloadflow/ac/equations/OpenBranchSide2ReactiveFlowEquationTerm.java index 93ca3aa527..a104f91bcd 100644 --- a/src/main/java/com/powsybl/openloadflow/ac/equations/OpenBranchSide2ReactiveFlowEquationTerm.java +++ b/src/main/java/com/powsybl/openloadflow/ac/equations/OpenBranchSide2ReactiveFlowEquationTerm.java @@ -35,26 +35,26 @@ private double r1() { return branch.getPiModel().getR1(); } - private static double q2(double y, double ksi, double b1, double g2, double b2, double v1, double r1) { - double shunt = shunt(y, ksi, g2, b2); - return -r1 * r1 * v1 * v1 * (b1 + y * y * b2 / shunt - (b2 * b2 + g2 * g2) * y * FastMath.cos(ksi) / shunt); + private static double q2(double y, double cosKsi, double sinKsi, double b1, double g2, double b2, double v1, double r1) { + double shunt = shunt(y, cosKsi, sinKsi, g2, b2); + return -r1 * r1 * v1 * v1 * (b1 + y * y * b2 / shunt - (b2 * b2 + g2 * g2) * y * cosKsi / shunt); } - private static double dq2dv1(double y, double ksi, double b1, double g2, double b2, double v1, double r1) { - double shunt = shunt(y, ksi, g2, b2); - return -2 * v1 * r1 * r1 * (b1 + y * y * b2 / shunt - (b2 * b2 + g2 * g2) * y * FastMath.cos(ksi) / shunt); + private static double dq2dv1(double y, double cosKsi, double sinKsi, double b1, double g2, double b2, double v1, double r1) { + double shunt = shunt(y, cosKsi, sinKsi, g2, b2); + return -2 * v1 * r1 * r1 * (b1 + y * y * b2 / shunt - (b2 * b2 + g2 * g2) * y * cosKsi / shunt); } @Override public double eval() { - return q2(y, ksi, b1, g2, b2, v1(), r1()); + return q2(y, FastMath.cos(ksi), FastMath.sin(ksi), b1, g2, b2, v1(), r1()); } @Override public double der(Variable variable) { Objects.requireNonNull(variable); if (variable.equals(v1Var)) { - return dq2dv1(y, ksi, b1, g2, b2, v1(), r1()); + return dq2dv1(y, FastMath.cos(ksi), FastMath.sin(ksi), b1, g2, b2, v1(), r1()); } else { throw new IllegalStateException("Unknown variable: " + variable); }