Skip to content

Commit

Permalink
Add AbstractElementEquationTerm (#686)
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 and Caio Luke committed Jan 10, 2023
1 parent 3889c43 commit 4bac019
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public ElementType getElementType() {
}
}

public static final class InitVmBusEquationTerm extends AbstractBusEquationTerm<InitVmVariableType, InitVmEquationType> {
public static final class InitVmBusEquationTerm extends AbstractElementEquationTerm<LfBus, InitVmVariableType, InitVmEquationType> {

private final List<Variable<InitVmVariableType>> variables;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
*/
package com.powsybl.openloadflow.ac.equations;

import com.powsybl.openloadflow.equations.AbstractBranchEquationTerm;
import com.powsybl.openloadflow.equations.AbstractElementEquationTerm;
import com.powsybl.openloadflow.network.LfBranch;
import com.powsybl.openloadflow.network.PiModel;

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

protected final double b1;
protected final double b2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ protected double ph2() {
}

protected double r1() {
return r1Var != null ? sv.get(r1Var.getRow()) : branch.getPiModel().getR1();
return r1Var != null ? sv.get(r1Var.getRow()) : element.getPiModel().getR1();
}

protected double a1() {
return a1Var != null ? sv.get(a1Var.getRow()) : branch.getPiModel().getA1();
return a1Var != null ? sv.get(a1Var.getRow()) : element.getPiModel().getA1();
}

public static double theta1(double ksi, double ph1, double a1, double ph2) {
Expand All @@ -106,8 +106,8 @@ public double calculateSensi(DenseMatrix dx, int column) {
double dph2 = dx.get(ph2Var.getRow(), column);
double dv1 = dx.get(v1Var.getRow(), column);
double dv2 = dx.get(v2Var.getRow(), column);
double da1 = a1Var != null ? dx.get(a1Var.getRow(), column) : branch.getPiModel().getA1();
double dr1 = r1Var != null ? dx.get(r1Var.getRow(), column) : branch.getPiModel().getR1();
double da1 = a1Var != null ? dx.get(a1Var.getRow(), column) : element.getPiModel().getA1();
double dr1 = r1Var != null ? dx.get(r1Var.getRow(), column) : element.getPiModel().getR1();
return calculateSensi(dph1, dph2, dv1, dv2, da1, dr1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,18 @@
*/
package com.powsybl.openloadflow.ac.equations;

import com.powsybl.openloadflow.equations.AbstractNamedEquationTerm;
import com.powsybl.openloadflow.equations.AbstractElementEquationTerm;
import com.powsybl.openloadflow.equations.Variable;
import com.powsybl.openloadflow.equations.VariableSet;
import com.powsybl.openloadflow.network.ElementType;
import com.powsybl.openloadflow.network.LfBus;
import com.powsybl.openloadflow.network.LfHvdc;

import java.util.List;
import java.util.Objects;

/**
* @author Anne Tilloy <anne.tilloy at rte-france.com>
*/
public abstract class AbstractHvdcAcEmulationFlowEquationTerm extends AbstractNamedEquationTerm<AcVariableType, AcEquationType> {

protected final LfHvdc hvdc;
public abstract class AbstractHvdcAcEmulationFlowEquationTerm extends AbstractElementEquationTerm<LfHvdc, AcVariableType, AcEquationType> {

protected final Variable<AcVariableType> ph1Var;

Expand All @@ -38,8 +34,7 @@ public abstract class AbstractHvdcAcEmulationFlowEquationTerm extends AbstractNa
protected final double lossFactor2;

protected AbstractHvdcAcEmulationFlowEquationTerm(LfHvdc hvdc, LfBus bus1, LfBus bus2, VariableSet<AcVariableType> variableSet) {
super(!Objects.requireNonNull(hvdc).isDisabled());
this.hvdc = hvdc;
super(hvdc);
ph1Var = variableSet.getVariable(bus1.getNum(), AcVariableType.BUS_PHI);
ph2Var = variableSet.getVariable(bus2.getNum(), AcVariableType.BUS_PHI);
variables = List.of(ph1Var, ph2Var);
Expand Down Expand Up @@ -70,14 +65,4 @@ public List<Variable<AcVariableType>> getVariables() {
public boolean hasRhs() {
return false;
}

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

@Override
public int getElementNum() {
return hvdc.getNum();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
*/
package com.powsybl.openloadflow.ac.equations;

import com.powsybl.openloadflow.equations.AbstractNamedEquationTerm;
import com.powsybl.openloadflow.equations.AbstractElementEquationTerm;
import com.powsybl.openloadflow.equations.Variable;
import com.powsybl.openloadflow.equations.VariableSet;
import com.powsybl.openloadflow.network.ElementType;
import com.powsybl.openloadflow.network.LfBus;
import com.powsybl.openloadflow.network.LfShunt;

Expand All @@ -18,30 +17,17 @@
/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public abstract class AbstractShuntCompensatorEquationTerm extends AbstractNamedEquationTerm<AcVariableType, AcEquationType> {

protected final LfShunt shunt;
public abstract class AbstractShuntCompensatorEquationTerm extends AbstractElementEquationTerm<LfShunt, AcVariableType, AcEquationType> {

protected final Variable<AcVariableType> vVar;

protected AbstractShuntCompensatorEquationTerm(LfShunt shunt, LfBus bus, VariableSet<AcVariableType> variableSet) {
super(!Objects.requireNonNull(shunt).isDisabled());
this.shunt = shunt;
super(shunt);
Objects.requireNonNull(bus);
Objects.requireNonNull(variableSet);
vVar = variableSet.getVariable(bus.getNum(), AcVariableType.BUS_V);
}

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

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

protected double v() {
return sv.get(vVar.getRow());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private double v1() {
}

private double r1() {
return branch.getPiModel().getR1();
return element.getPiModel().getR1();
}

private static double p1(double y, double cosKsi, double sinKsi, double g1, double g2, double b2, double v1, double r1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private double ph1() {
}

private double r1() {
return r1Var != null ? sv.get(r1Var.getRow()) : branch.getPiModel().getR1();
return r1Var != null ? sv.get(r1Var.getRow()) : element.getPiModel().getR1();
}

private static double gres(double y, double sinksi, double g1, double g2, double b2, double shunt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private double v1() {
}

private double r1() {
return branch.getPiModel().getR1();
return element.getPiModel().getR1();
}

private static double q1(double y, double cosKsi, double sinKsi, double b1, double g2, double b2, double v1, double r1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public List<Variable<AcVariableType>> getVariables() {
}

private double g() {
return shunt.getG();
return element.getG();
}

private static double p(double v, double g) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public List<Variable<AcVariableType>> getVariables() {
}

private double b() {
return bVar != null ? sv.get(bVar.getRow()) : shunt.getB();
return bVar != null ? sv.get(bVar.getRow()) : element.getB();
}

private static double q(double v, double b) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
package com.powsybl.openloadflow.dc.equations;

import com.powsybl.math.matrix.DenseMatrix;
import com.powsybl.openloadflow.equations.AbstractBranchEquationTerm;
import com.powsybl.openloadflow.equations.AbstractElementEquationTerm;
import com.powsybl.openloadflow.equations.Variable;
import com.powsybl.openloadflow.equations.VariableSet;
import com.powsybl.openloadflow.network.LfBranch;
Expand All @@ -22,7 +22,7 @@
/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public abstract class AbstractClosedBranchDcFlowEquationTerm extends AbstractBranchEquationTerm<DcVariableType, DcEquationType> {
public abstract class AbstractClosedBranchDcFlowEquationTerm extends AbstractElementEquationTerm<LfBranch, DcVariableType, DcEquationType> {

protected final Variable<DcVariableType> ph1Var;

Expand Down Expand Up @@ -65,7 +65,7 @@ public double calculateSensi(DenseMatrix dx, int column) {
Objects.requireNonNull(dx);
double dph1 = dx.get(ph1Var.getRow(), column);
double dph2 = dx.get(ph2Var.getRow(), column);
double da1 = a1Var != null ? dx.get(a1Var.getRow(), column) : branch.getPiModel().getA1();
double da1 = a1Var != null ? dx.get(a1Var.getRow(), column) : element.getPiModel().getA1();
return calculateSensi(dph1, dph2, da1);
}

Expand All @@ -80,7 +80,7 @@ protected double ph2() {
protected abstract double calculateSensi(double ph1, double ph2, double a1);

protected double a1() {
return a1Var != null ? sv.get(a1Var.getRow()) : branch.getPiModel().getA1();
return a1Var != null ? sv.get(a1Var.getRow()) : element.getPiModel().getA1();
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@
package com.powsybl.openloadflow.equations;

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

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> {
public abstract class AbstractElementEquationTerm<T extends LfElement, V extends Enum<V> & Quantity, E extends Enum<E> & Quantity> extends AbstractNamedEquationTerm<V, E> {

protected final LfBranch branch;
protected final T element;

protected AbstractBranchEquationTerm(LfBranch branch) {
super(!Objects.requireNonNull(branch).isDisabled());
this.branch = branch;
protected AbstractElementEquationTerm(T element) {
super(!Objects.requireNonNull(element).isDisabled());
this.element = element;
}

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

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

0 comments on commit 4bac019

Please sign in to comment.