Skip to content

Commit

Permalink
Get RHS from equation (#673)
Browse files Browse the repository at this point in the history
Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@gmail.com>
  • Loading branch information
geofjamg authored Dec 17, 2022
1 parent 54614bc commit f600a3b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.powsybl.openloadflow.ac.equations.AcVariableType;
import com.powsybl.openloadflow.equations.Equation;
import com.powsybl.openloadflow.equations.EquationSystem;
import com.powsybl.openloadflow.equations.EquationTerm;
import com.powsybl.openloadflow.equations.TargetVector;
import com.powsybl.openloadflow.network.*;

Expand Down Expand Up @@ -129,11 +128,7 @@ public static void init(Equation<AcVariableType, AcEquationType> equation, LfNet
throw new IllegalStateException("Unknown state variable type: " + equation.getType());
}

for (EquationTerm<AcVariableType, AcEquationType> term : equation.getTerms()) {
if (term.isActive() && term.hasRhs()) {
targets[equation.getColumn()] -= term.rhs();
}
}
targets[equation.getColumn()] -= equation.rhs();
}

public AcTargetVector(LfNetwork network, EquationSystem<AcVariableType, AcEquationType> equationSystem) {
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/com/powsybl/openloadflow/dc/DcTargetVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import com.powsybl.openloadflow.dc.equations.DcVariableType;
import com.powsybl.openloadflow.equations.Equation;
import com.powsybl.openloadflow.equations.EquationSystem;
import com.powsybl.openloadflow.equations.EquationTerm;
import com.powsybl.openloadflow.equations.TargetVector;
import com.powsybl.openloadflow.network.*;
import com.powsybl.openloadflow.network.LfBranch;
import com.powsybl.openloadflow.network.LfNetwork;

/**
* @author Jean-Luc Bouchot (Artelys) <jlbouchot at gmail.com>
Expand Down Expand Up @@ -43,11 +43,7 @@ public static void init(Equation<DcVariableType, DcEquationType> equation, LfNet
throw new IllegalStateException("Unknown state variable type: " + equation.getType());
}

for (EquationTerm<DcVariableType, DcEquationType> term : equation.getTerms()) {
if (term.isActive() && term.hasRhs()) {
targets[equation.getColumn()] -= term.rhs();
}
}
targets[equation.getColumn()] -= equation.rhs();
}

public DcTargetVector(LfNetwork network, EquationSystem<DcVariableType, DcEquationType> equationSystem) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/powsybl/openloadflow/equations/Equation.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ public double eval() {
return value;
}

public double rhs() {
double rhs = 0;
for (var term : terms) {
if (term.isActive() && term.hasRhs()) {
rhs += term.rhs();
}
}
return rhs;
}

@Override
public int hashCode() {
return elementNum + type.hashCode();
Expand Down

0 comments on commit f600a3b

Please sign in to comment.