Skip to content

Commit

Permalink
Review
Browse files Browse the repository at this point in the history
Signed-off-by: Sébastien LAIGRE <slaigre@silicom.fr>
  • Loading branch information
sebalaig committed May 24, 2022
1 parent feadf14 commit ffa4c16
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 42 deletions.
14 changes: 1 addition & 13 deletions include/powsybl/iidm/util/DanglingLineData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,7 @@ class DanglingLineData {
static bool valid(double v, double theta);

private:
std::string m_id;

double m_r;
double m_x;
double m_g1;
double m_g2;
double m_b1;
double m_b2;

double m_u1;
double m_theta1;
double m_p0;
double m_q0;
const DanglingLine& m_danglingLine;

double m_boundaryBusU = stdcxx::nan();
double m_boundaryBusTheta = stdcxx::nan();
Expand Down
3 changes: 2 additions & 1 deletion include/powsybl/iidm/util/LinkData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ struct Flow {
std::complex<double> toFrom;
};

struct BranchAdmittanceMatrix {
class BranchAdmittanceMatrix {
public:
BranchAdmittanceMatrix() = default;

BranchAdmittanceMatrix(const std::complex<double>& y11, const std::complex<double>& y12, const std::complex<double>& y21, const std::complex<double>& y22);

public:
std::complex<double> y11;

std::complex<double> y12;
Expand Down
40 changes: 20 additions & 20 deletions src/iidm/util/DanglingLineData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,33 @@ DanglingLineData::DanglingLineData(const DanglingLine& danglingLine) :
}

DanglingLineData::DanglingLineData(const DanglingLine& danglingLine, bool splitShuntAdmittance) :
m_id(danglingLine.getId()),
m_r(danglingLine.getR()),
m_x(danglingLine.getX()),
m_g1(splitShuntAdmittance ? danglingLine.getG() * 0.5 : danglingLine.getG()),
m_g2(splitShuntAdmittance ? danglingLine.getG() * 0.5 : 0.0),
m_b1(splitShuntAdmittance ? danglingLine.getB() * 0.5 : danglingLine.getB()),
m_b2(splitShuntAdmittance ? danglingLine.getB() * 0.5 : 0.0),
m_u1(getV(danglingLine)),
m_theta1(getTheta(danglingLine)),
m_p0(danglingLine.getP0()),
m_q0(danglingLine.getQ0()) {

if (!valid(m_u1, m_theta1)) {
m_danglingLine(danglingLine){

double g1 = splitShuntAdmittance ? danglingLine.getG() * 0.5 : danglingLine.getG();
double g2 = splitShuntAdmittance ? danglingLine.getG() * 0.5 : 0.0;
double b1 = splitShuntAdmittance ? danglingLine.getB() * 0.5 : danglingLine.getB();
double b2 = splitShuntAdmittance ? danglingLine.getB() * 0.5 : 0.0;

double u1 = getV(danglingLine);
double theta1 = getTheta(danglingLine);

if (!valid(u1, theta1)) {
m_boundaryBusU = stdcxx::nan();
m_boundaryBusTheta = stdcxx::nan();
return;
}

const std::complex<double>& v1 = math::ComplexUtils::polar2Complex(m_u1, m_theta1);
const std::complex<double>& v1 = math::ComplexUtils::polar2Complex(u1, theta1);

std::complex<double> vBoundaryBus(stdcxx::nan(), stdcxx::nan());
if (m_p0 == 0.0 && m_q0 == 0.0) {
LinkData::BranchAdmittanceMatrix adm = LinkData::calculateBranchAdmittance(m_r, m_x, 1.0, 0.0, 1.0, 0.0, std::complex<double>(m_g1, m_b1), std::complex<double>(m_g2, m_b2));
if (danglingLine.getP0() == 0.0 && danglingLine.getQ0() == 0.0) {
LinkData::BranchAdmittanceMatrix adm = LinkData::calculateBranchAdmittance(danglingLine.getR(), danglingLine.getX(), 1.0, 0.0, 1.0, 0.0, std::complex<double>(g1, b1), std::complex<double>(g2, b2));
vBoundaryBus = (- adm.y21 * v1) / adm.y22;
} else {
// Two buses Loadflow
std::complex<double> sBoundary(-m_p0, -m_q0);
std::complex<double> ytr = 1.0 / std::complex<double>(m_r, m_x);
std::complex<double> ysh2(m_g2, m_b2);
std::complex<double> sBoundary(-danglingLine.getP0(), -danglingLine.getQ0());
std::complex<double> ytr = 1.0 / std::complex<double>(danglingLine.getR(), danglingLine.getX());
std::complex<double> ysh2(g2, b2);
std::complex<double> zt = 1.0 / (ytr + ysh2);
std::complex<double> v0 = ytr * v1 / (ytr + ysh2);
double v02 = std::abs(v0) * std::abs(v0);
Expand All @@ -75,7 +75,7 @@ double DanglingLineData::getBoundaryBusU() const {
}

const std::string& DanglingLineData::getId() const {
return m_id;
return m_danglingLine.getId();
}

double DanglingLineData::getTheta(const DanglingLine& danglingLine) {
Expand Down
10 changes: 4 additions & 6 deletions src/iidm/util/LinkData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,15 @@ Flow flowBothEnds(const std::complex<double>& y11, const std::complex<double>& y
std::complex<double> flowYshunt(const std::complex<double>& ysh, double u, double theta) {
std::complex<double> v = math::ComplexUtils::polar2Complex(u, theta);

return std::conj(ysh) * std::conj(v) *v;
return std::conj(ysh) * std::conj(v) * v;
}

double getFixedX(double x, double epsilonX, bool applyReactanceCorrection) {
return std::abs(x) < epsilonX && applyReactanceCorrection ? epsilonX : x;
}

double getPhaseAngleClockDegrees(int phaseAngleClock) {
double phaseAngleClockDegree = 0.0;
phaseAngleClockDegree += phaseAngleClock * 30.0;
phaseAngleClockDegree = std::remainder(phaseAngleClockDegree, 360.0);
double phaseAngleClockDegree = std::remainder(phaseAngleClock * 30.0, 360.0);
if (phaseAngleClockDegree > 180.0) {
phaseAngleClockDegree -= 360.0;
}
Expand Down Expand Up @@ -139,8 +137,8 @@ BranchAdmittanceMatrix kronChain(const BranchAdmittanceMatrix& firstAdm, const B
}

admittance.y11 = yFirst11 - (yFirst1C * yFirstC1 / (yFirstCC + ySecondCC));
admittance.y12 = yFirst1C * ySecondC2 / -(yFirstCC + ySecondCC);
admittance.y21 = ySecond2C * yFirstC1 / -(yFirstCC + ySecondCC);
admittance.y12 = - yFirst1C * ySecondC2 / (yFirstCC + ySecondCC);
admittance.y21 = - ySecond2C * yFirstC1 / (yFirstCC + ySecondCC);
admittance.y22 = ySecond22 - (ySecond2C * ySecondC2 / (yFirstCC + ySecondCC));

return admittance;
Expand Down
4 changes: 2 additions & 2 deletions src/iidm/util/TwtData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ TwtData::TwtData(const ThreeWindingsTransformer& twt, int phaseAngleClock2, int
}

double TwtData::alpha(const ThreeWindingsTransformer::Leg& leg) {
return leg.getOptionalPhaseTapChanger() ? leg.getPhaseTapChanger().getCurrentStep().getAlpha() : 0.0;
return leg.getOptionalPhaseTapChanger() ? stdcxx::toRadians * leg.getPhaseTapChanger().getCurrentStep().getAlpha() : 0.0;
}

std::complex<double> TwtData::calculateOneConnectedLegFlow(double u, double theta,
Expand Down Expand Up @@ -313,7 +313,7 @@ std::complex<double> TwtData::calculateTwoConnectedLegsStarBusVoltage(double u1,
std::complex<double> v2 = math::ComplexUtils::polar2Complex(u2, theta2);

std::complex<double> yshO = LinkData::kronAntenna(admittanceMatrixOpenLeg.y11, admittanceMatrixOpenLeg.y12, admittanceMatrixOpenLeg.y21, admittanceMatrixOpenLeg.y22, true);
return -(admittanceMatrixLeg1.y21 * v1 + (admittanceMatrixLeg2.y21 * v2))
return -(admittanceMatrixLeg1.y21 * v1 + admittanceMatrixLeg2.y21 * v2)
/ (admittanceMatrixLeg1.y22 + admittanceMatrixLeg2.y22 + yshO);
}

Expand Down

0 comments on commit ffa4c16

Please sign in to comment.