Skip to content

Commit

Permalink
Support low impedance branches in adm matrix calculation
Browse files Browse the repository at this point in the history
Signed-off-by: Geoffroy Jamgotchian <[email protected]>
  • Loading branch information
geofjamg committed Nov 17, 2024
1 parent 1557c2c commit bf94e9c
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package com.powsybl.openloadflow;

import com.powsybl.math.matrix.MatrixFactory;
import com.powsybl.openloadflow.network.util.VoltageInitializer;

import java.util.Objects;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
import com.powsybl.openloadflow.equations.AbstractElementEquationTerm;
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;
import com.powsybl.openloadflow.network.*;

import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -67,18 +65,19 @@ protected AbstractAdmittanceEquationTerm(LfBranch branch, LfBus bus1, LfBus bus2
variables = List.of(v1xVar, v2xVar, v1yVar, v2yVar);

PiModel piModel = branch.getPiModel();
if (piModel.getX() == 0) {
throw new IllegalArgumentException("Branch '" + branch.getId() + "' has reactance equal to zero");
}
rho = piModel.getR1();
if (piModel.getZ() == 0) {
throw new IllegalArgumentException("Branch '" + branch.getId() + "' has Z equal to zero");
}

r = piModel.getR();
x = piModel.getX();
double z = Math.sqrt(r * r + x * x);
zInvSquare = 1 / (z * z);

piModel.getCutZ(LfNetworkParameters.LOW_IMPEDANCE_THRESHOLD_DEFAULT_VALUE, LoadFlowModel.AC).ifPresentOrElse(z -> {
r = z.getReal();
x = z.getImaginary();
double zMod = z.abs();
zInvSquare = 1 / (zMod * zMod);
}, () -> {
r = piModel.getR();
x = piModel.getX();
double z = Math.sqrt(r * r + x * x);
zInvSquare = 1 / (z * z);
});

double alpha = piModel.getA1();
cosA = Math.cos(Math.toRadians(alpha));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

import com.powsybl.openloadflow.equations.EquationSystem;
import com.powsybl.openloadflow.equations.VariableSet;
import com.powsybl.openloadflow.network.*;
import net.jafama.FastMath;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.powsybl.openloadflow.network.LfBranch;
import com.powsybl.openloadflow.network.LfBus;
import com.powsybl.openloadflow.network.LfNetwork;
import com.powsybl.openloadflow.network.LfShunt;

import java.util.Collection;
import java.util.Objects;
Expand All @@ -23,8 +23,6 @@
*/
public final class AdmittanceEquationSystem {

private static final Logger LOGGER = LoggerFactory.getLogger(AdmittanceEquationSystem.class);

private static final double B_EPSILON = 1e-8;

private final EquationSystem<AdmittanceVariableType, AdmittanceEquationType> equationSystem;
Expand All @@ -38,7 +36,7 @@ public EquationSystem<AdmittanceVariableType, AdmittanceEquationType> getEquatio
}

//Equations are created based on the branches connections
private static void createImpedantBranch(VariableSet<AdmittanceVariableType> variableSet, EquationSystem<AdmittanceVariableType, AdmittanceEquationType> equationSystem,
private static void createBranchEquation(VariableSet<AdmittanceVariableType> variableSet, EquationSystem<AdmittanceVariableType, AdmittanceEquationType> equationSystem,
LfBranch branch, LfBus bus1, LfBus bus2) {
if (bus1 != null && bus2 != null) {
// Equation system Y*V = I (expressed in cartesian coordinates x,y)
Expand All @@ -60,15 +58,7 @@ private static void createBranchEquations(Collection<LfBranch> branches, Variabl
for (LfBranch branch : branches) {
LfBus bus1 = branch.getBus1();
LfBus bus2 = branch.getBus2();
PiModel piModel = branch.getPiModel();
if (FastMath.abs(piModel.getX()) < LfNetworkParameters.LOW_IMPEDANCE_THRESHOLD_DEFAULT_VALUE) {
if (bus1 != null && bus2 != null) {
LOGGER.warn("Non impedant branches ({}) not supported in admittance matrix",
branch.getId());
}
} else {
createImpedantBranch(variableSet, equationSystem, branch, bus1, bus2);
}
createBranchEquation(variableSet, equationSystem, branch, bus1, bus2);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/powsybl/openloadflow/network/PiModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.powsybl.openloadflow.network;

import org.apache.commons.lang3.Range;
import org.apache.commons.math3.complex.Complex;

import java.util.Optional;

Expand Down Expand Up @@ -68,6 +69,8 @@ public interface PiModel {

Optional<Direction> updateTapPositionToReachNewA1(double deltaA1, int maxTapShift, AllowedDirection allowedDirection);

Optional<Complex> getCutZ(double minZ, LoadFlowModel loadFlowModel);

boolean setMinZ(double minZ, LoadFlowModel loadFlowModel);

void setBranch(LfBranch branch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.powsybl.openloadflow.network;

import org.apache.commons.lang3.Range;
import org.apache.commons.math3.complex.Complex;

import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -358,6 +359,11 @@ public Optional<Direction> updateTapPositionToReachNewA1(double deltaA1, int max
return direction;
}

@Override
public Optional<Complex> getCutZ(double minZ, LoadFlowModel loadFlowModel) {
return getModel().getCutZ(minZ, loadFlowModel);
}

@Override
public boolean setMinZ(double minZ, LoadFlowModel loadFlowModel) {
boolean done = false;
Expand Down
31 changes: 19 additions & 12 deletions src/main/java/com/powsybl/openloadflow/network/SimplePiModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

import net.jafama.FastMath;
import org.apache.commons.lang3.Range;
import org.apache.commons.math3.complex.Complex;

import java.util.Objects;
import java.util.Optional;

/**
Expand Down Expand Up @@ -171,27 +173,32 @@ public Optional<Direction> updateTapPositionToReachNewA1(double deltaA1, int max
throw new IllegalStateException(NO_TAP_POSITION_ERROR);
}

private void rescaleZ(double z) {
double ksi = getKsi();
r = z * FastMath.sin(ksi);
x = z * FastMath.cos(ksi);
}

@Override
public boolean setMinZ(double minZ, LoadFlowModel loadFlowModel) {
public Optional<Complex> getCutZ(double minZ, LoadFlowModel loadFlowModel) {
Objects.requireNonNull(loadFlowModel);
if (loadFlowModel == LoadFlowModel.DC) {
if (FastMath.abs(this.x) < minZ) {
this.x = minZ;
return true;
return Optional.of(Complex.valueOf(0, minZ));
}
} else {
double z = getZ();
if (z < minZ) {
rescaleZ(minZ);
return true;
double ksi = getKsi();
double newR = minZ * FastMath.sin(ksi);
double newX = minZ * FastMath.cos(ksi);
return Optional.of(Complex.valueOf(newR, newX));
}
}
return false;
return Optional.empty();
}

@Override
public boolean setMinZ(double minZ, LoadFlowModel loadFlowModel) {
return getCutZ(minZ, loadFlowModel).map(z -> {
SimplePiModel.this.r = z.getReal();
SimplePiModel.this.x = z.getImaginary();
return true;
}).orElse(false);
}

@Override
Expand Down

0 comments on commit bf94e9c

Please sign in to comment.