Skip to content

Commit

Permalink
Refactor branch equation term (#394)
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 4, 2021
1 parent 5244230 commit 6c0797b
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,15 @@
*/
package com.powsybl.openloadflow.ac.equations;

import com.powsybl.openloadflow.equations.AbstractNamedEquationTerm;
import com.powsybl.openloadflow.network.ElementType;
import com.powsybl.openloadflow.equations.AbstractBranchEquationTerm;
import com.powsybl.openloadflow.network.LfBranch;
import com.powsybl.openloadflow.network.PiModel;
import net.jafama.FastMath;

import java.util.Objects;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
abstract class AbstractBranchAcFlowEquationTerm extends AbstractNamedEquationTerm<AcVariableType, AcEquationType> {

protected final LfBranch branch;
abstract class AbstractBranchAcFlowEquationTerm extends AbstractBranchEquationTerm<AcVariableType, AcEquationType> {

protected final double b1;
protected final double b2;
Expand All @@ -31,7 +26,7 @@ abstract class AbstractBranchAcFlowEquationTerm extends AbstractNamedEquationTer
protected final double cosKsi;

protected AbstractBranchAcFlowEquationTerm(LfBranch branch) {
this.branch = Objects.requireNonNull(branch);
super(branch);
PiModel piModel = branch.getPiModel();
if (piModel.getR() == 0 && piModel.getX() == 0) {
throw new IllegalArgumentException("Non impedant branch not supported: " + branch.getId());
Expand All @@ -45,24 +40,4 @@ protected AbstractBranchAcFlowEquationTerm(LfBranch branch) {
sinKsi = FastMath.sin(ksi);
cosKsi = FastMath.cos(ksi);
}

@Override
public ElementType getElementType() {
return ElementType.BRANCH;
}

@Override
public int getElementNum() {
return branch.getNum();
}

@Override
public boolean hasRhs() {
return false;
}

@Override
public double rhs() {
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,6 @@ public double der(Variable<AcVariableType> variable) {
}
}

@Override
public boolean hasRhs() {
return false;
}

@Override
public double rhs() {
return 0;
}

@Override
protected String getName() {
return "ac_q_shunt";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

import com.google.common.collect.ImmutableList;
import com.powsybl.math.matrix.DenseMatrix;
import com.powsybl.openloadflow.equations.*;
import com.powsybl.openloadflow.network.ElementType;
import com.powsybl.openloadflow.equations.AbstractBranchEquationTerm;
import com.powsybl.openloadflow.equations.Variable;
import com.powsybl.openloadflow.equations.VariableSet;
import com.powsybl.openloadflow.network.LfBranch;
import com.powsybl.openloadflow.network.LfBus;
import com.powsybl.openloadflow.network.PiModel;
Expand All @@ -22,9 +23,7 @@
/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public abstract class AbstractClosedBranchDcFlowEquationTerm extends AbstractNamedEquationTerm<DcVariableType, DcEquationType> {

protected final LfBranch branch;
public abstract class AbstractClosedBranchDcFlowEquationTerm extends AbstractBranchEquationTerm<DcVariableType, DcEquationType> {

protected final Variable<DcVariableType> ph1Var;

Expand All @@ -38,7 +37,7 @@ public abstract class AbstractClosedBranchDcFlowEquationTerm extends AbstractNam

protected AbstractClosedBranchDcFlowEquationTerm(LfBranch branch, LfBus bus1, LfBus bus2, VariableSet<DcVariableType> variableSet,
boolean deriveA1, boolean useTransformerRatio) {
this.branch = Objects.requireNonNull(branch);
super(branch);
PiModel piModel = branch.getPiModel();
if (piModel.getX() == 0) {
throw new IllegalArgumentException("Branch '" + branch.getId() + "' has reactance equal to zero");
Expand Down Expand Up @@ -73,16 +72,6 @@ protected double getA1(double[] stateVector) {
return a1Var != null ? stateVector[a1Var.getRow()] : branch.getPiModel().getA1();
}

@Override
public ElementType getElementType() {
return ElementType.BRANCH;
}

@Override
public int getElementNum() {
return branch.getNum();
}

@Override
public List<Variable<DcVariableType>> getVariables() {
return variables;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright (c) 2021, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.openloadflow.equations;

import com.powsybl.openloadflow.network.ElementType;
import com.powsybl.openloadflow.network.LfBranch;

import java.util.Objects;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public abstract class AbstractBranchEquationTerm<V extends Enum<V> & Quantity, E extends Enum<E> & Quantity> extends AbstractNamedEquationTerm<V, E> {

protected final LfBranch branch;

protected AbstractBranchEquationTerm(LfBranch branch) {
this.branch = Objects.requireNonNull(branch);
}

@Override
public ElementType getElementType() {
return ElementType.BRANCH;
}

@Override
public int getElementNum() {
return branch.getNum();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,14 @@ public boolean isActive() {
public double calculateSensi(DenseMatrix x, int column) {
throw new UnsupportedOperationException("Not implemented");
}

@Override
public boolean hasRhs() {
return false;
}

@Override
public double rhs() {
return 0;
}
}
10 changes: 0 additions & 10 deletions src/main/java/com/powsybl/openloadflow/equations/EquationTerm.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,6 @@ public double der(Variable<V> variable) {
return 1;
}

@Override
public boolean hasRhs() {
return false;
}

@Override
public double rhs() {
return 0;
}

@Override
public double calculateSensi(DenseMatrix x, int column) {
return x.get(variables.get(0).getRow(), column);
Expand Down

0 comments on commit 6c0797b

Please sign in to comment.