Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DanglingLineData and TwtData (#379) #432

Open
wants to merge 4 commits into
base: integration/v1.6.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/powsybl/iidm/util/DanglingLineBoundary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ class Boundary : public iidm::Boundary {

Boundary& operator=(Boundary&&) noexcept = delete;

private:
static bool valid(double p0, double q0);

private:
DanglingLine& m_parent;
};
Expand Down
51 changes: 51 additions & 0 deletions include/powsybl/iidm/util/DanglingLineData.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Copyright (c) 2022, 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/.
*/

#ifndef POWSYBL_IIDM_UTIL_DANGLINGLINEDATA_HPP
#define POWSYBL_IIDM_UTIL_DANGLINGLINEDATA_HPP

#include <string>

#include <powsybl/stdcxx/math.hpp>

namespace powsybl {

namespace iidm {

class DanglingLine;

class DanglingLineData {
public:
explicit DanglingLineData(const DanglingLine& danglingLine);

DanglingLineData(const DanglingLine& danglingLine, bool splitShuntAdmittance);

double getBoundaryBusTheta() const;

double getBoundaryBusU() const;

const std::string& getId() const;

private:
static double getTheta(const DanglingLine& danglingLine);

static double getV(const DanglingLine& danglingLine);

static bool valid(double v, double theta);

private:
const DanglingLine& m_danglingLine;

double m_boundaryBusU = stdcxx::nan();
double m_boundaryBusTheta = stdcxx::nan();
};

} // namespace iidm

} // namespace powsybl

#endif // POWSYBL_IIDM_UTIL_DANGLINGLINEDATA_HPP
31 changes: 28 additions & 3 deletions include/powsybl/iidm/util/LinkData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include <complex>

#include <powsybl/iidm/Branch.hpp>

namespace powsybl {

namespace iidm {
Expand All @@ -23,7 +25,12 @@ 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;

Expand All @@ -34,8 +41,26 @@ struct BranchAdmittanceMatrix {
std::complex<double> y22;
};

BranchAdmittanceMatrix calculateBranchAdmittance(double r, double x, double ratio1, double angle1,
double ratio2, double angle2, const std::complex<double>& ysh1, const std::complex<double>& ysh2);
BranchAdmittanceMatrix calculateBranchAdmittance(double r, double x, double ratio1, double angle1, double ratio2, double angle2, const std::complex<double>& ysh1,
const std::complex<double>& ysh2);

Flow flowBothEnds(const std::complex<double>& y11, const std::complex<double>& y12, const std::complex<double>& y21, const std::complex<double>& y22, double u1,
double theta1, double u2, double theta2);

Flow flowBothEnds(const std::complex<double>& y11, const std::complex<double>& y12, const std::complex<double>& y21, const std::complex<double>& y22,
const std::complex<double>& v1, const std::complex<double>& v2);

std::complex<double> flowYshunt(const std::complex<double>& ysh, double u, double theta);

double getFixedX(double x, double epsilonX, bool applyReactanceCorrection);

double getPhaseAngleClockDegrees(int phaseAngleClock);

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

BranchAdmittanceMatrix kronChain(const BranchAdmittanceMatrix& firstAdm, const Branch::Side& firstChainNodeSide, const BranchAdmittanceMatrix& secondAdm,
const Branch::Side& secondChainNodeSide);
sebalaig marked this conversation as resolved.
Show resolved Hide resolved

} // namespace LinkData

Expand Down
210 changes: 210 additions & 0 deletions include/powsybl/iidm/util/TwtData.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
/**
* Copyright (c) 2022, 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/.
*/

#ifndef POWSYBL_IIDM_UTIL_TWTDATA_HPP
#define POWSYBL_IIDM_UTIL_TWTDATA_HPP

#include <complex>
#include <string>

#include <powsybl/iidm/ThreeWindingsTransformer.hpp>
#include <powsybl/iidm/util/LinkData.hpp>

namespace powsybl {

namespace iidm {

class ThreeWindingsTransformer;

class TwtData {
public:
TwtData(const ThreeWindingsTransformer& twt, double epsilonX, bool applyReactanceCorrection);

TwtData(const ThreeWindingsTransformer& twt, double epsilonX, bool applyReactanceCorrection, bool twtSplitShuntAdmittance);

TwtData(const ThreeWindingsTransformer& twt, int phaseAngleClock2, int phaseAngleClock3, double epsilonX, bool applyReactanceCorrection,
bool twtSplitShuntAdmittance);

double getB1(const ThreeWindingsTransformer::Side& side) const;

double getB2(const ThreeWindingsTransformer::Side& side) const;

double getComputedP(const ThreeWindingsTransformer::Side& side) const;

double getComputedQ(const ThreeWindingsTransformer::Side& side) const;

double getG1(const ThreeWindingsTransformer::Side& side) const;

double getG2(const ThreeWindingsTransformer::Side& side) const;

const std::string& getId() const;

double getP(const ThreeWindingsTransformer::Side& side) const;

double getQ(const ThreeWindingsTransformer::Side& side) const;

double getR(const ThreeWindingsTransformer::Side& side) const;

double getRatedU(const ThreeWindingsTransformer::Side& side) const;

double getStarTheta() const;

double getStarU() const;

double getTheta(const ThreeWindingsTransformer::Side& side) const;

double getU(const ThreeWindingsTransformer::Side& side) const;

double getX(const ThreeWindingsTransformer::Side& side) const;

bool isConnected(const ThreeWindingsTransformer::Side& side) const;

bool isMainComponent(const ThreeWindingsTransformer::Side& side) const;

int getPhaseAngleClock2() const;

int getPhaseAngleClock3() const;

double getRatedU0() const;

private:
static double alpha(const ThreeWindingsTransformer::Leg& leg);

static double getB1(const ThreeWindingsTransformer::Leg& leg, bool twtSplitShuntAdmittance);

static double getB2(const ThreeWindingsTransformer::Leg& leg, bool twtSplitShuntAdmittance);

static double getG1(const ThreeWindingsTransformer::Leg& leg, bool twtSplitShuntAdmittance);

static double getG2(const ThreeWindingsTransformer::Leg& leg, bool twtSplitShuntAdmittance);

static double getR(const ThreeWindingsTransformer::Leg& leg);

static double getTheta(const ThreeWindingsTransformer::Leg& leg);

static double getV(const ThreeWindingsTransformer::Leg& leg);

static double getValue(double initialValue, double rtcStepValue, double ptcStepValue);

static double getX(const ThreeWindingsTransformer::Leg& leg);

static bool isMainComponent(const ThreeWindingsTransformer::Leg& leg);

static double rho(const ThreeWindingsTransformer::Leg& leg, double ratedU0);

static bool valid(double voltage, double theta);

private:
std::complex<double> calculateOneConnectedLegFlow(double u, double theta,
const LinkData::BranchAdmittanceMatrix& admittanceMatrixLeg,
const LinkData::BranchAdmittanceMatrix& admittanceMatrixFirstOpenLeg,
const LinkData::BranchAdmittanceMatrix& admittanceMatrixSecondOpenLeg) const;

std::complex<double> calculateOneConnectedLegShunt(const LinkData::BranchAdmittanceMatrix& closeLeg,
const LinkData::BranchAdmittanceMatrix& firstOpenLeg,
const LinkData::BranchAdmittanceMatrix& secondOpenLeg) const;

std::complex<double> calculateOneConnectedLegStarBusVoltage(double u, double theta,
const LinkData::BranchAdmittanceMatrix& admittanceMatrixLeg,
const LinkData::BranchAdmittanceMatrix& admittanceMatrixFirstOpenLeg,
const LinkData::BranchAdmittanceMatrix& admittanceMatrixSecondOpenLeg) const;

void calculateThreeConnectedLegsFlowAndStarBusVoltage(double u1, double theta1, double u2, double theta2,
double u3, double theta3,
const LinkData::BranchAdmittanceMatrix& branchAdmittanceLeg1,
const LinkData::BranchAdmittanceMatrix& branchAdmittanceLeg2,
const LinkData::BranchAdmittanceMatrix& branchAdmittanceLeg3);

LinkData::BranchAdmittanceMatrix calculateTwoConnectedLegsAdmittance(const LinkData::BranchAdmittanceMatrix& firstCloseLeg,
const LinkData::BranchAdmittanceMatrix& secondCloseLeg,
const LinkData::BranchAdmittanceMatrix& openLeg) const;

LinkData::Flow calculateTwoConnectedLegsFlow(double u1, double theta1, double u2, double theta2,
const LinkData::BranchAdmittanceMatrix& admittanceMatrixLeg1,
const LinkData::BranchAdmittanceMatrix& admittanceMatrixLeg2,
const LinkData::BranchAdmittanceMatrix& admittanceMatrixOpenLeg) const;

std::complex<double> calculateTwoConnectedLegsStarBusVoltage(double u1, double theta1, double u2, double theta2,
const LinkData::BranchAdmittanceMatrix& admittanceMatrixLeg1,
const LinkData::BranchAdmittanceMatrix& admittanceMatrixLeg2,
const LinkData::BranchAdmittanceMatrix& admittanceMatrixOpenLeg) const;

private:
std::string m_id;

double m_p1;
double m_q1;
double m_p2;
double m_q2;
double m_p3;
double m_q3;

double m_u1;
double m_theta1;
double m_u2;
double m_theta2;
double m_u3;
double m_theta3;

double m_r1;
double m_x1;
double m_r2;
double m_x2;
double m_r3;
double m_x3;

double m_g11;
double m_b11;
double m_g12;
double m_b12;
double m_g21;
double m_b21;
double m_g22;
double m_b22;
double m_g31;
double m_b31;
double m_g32;
double m_b32;

double m_rho1;
double m_alpha1;
double m_rho2;
double m_alpha2;
double m_rho3;
double m_alpha3;

double m_ratedU1;
double m_ratedU2;
double m_ratedU3;

bool m_connected1;
bool m_connected2;
bool m_connected3;
bool m_mainComponent1;
bool m_mainComponent2;
bool m_mainComponent3;

double m_computedP1;
double m_computedQ1;
double m_computedP2;
double m_computedQ2;
double m_computedP3;
double m_computedQ3;

double m_starU;
double m_starTheta;

int m_phaseAngleClock2;
int m_phaseAngleClock3;
double m_ratedU0;
};

} // namespace iidm

} // namespace powsybl

#endif // POWSYBL_IIDM_UTIL_TWTDATA_HPP
27 changes: 27 additions & 0 deletions include/powsybl/math/ComplexUtils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (c) 2022, 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/.
*/

#ifndef POWSYBL_MATH_COMPLEXUTILS_HPP
#define POWSYBL_MATH_COMPLEXUTILS_HPP

#include <complex>

namespace powsybl {

namespace math {

namespace ComplexUtils {

std::complex<double> polar2Complex(double r, double theta);

} // namespace ComplexUtils

} // namespace math

} // namespace powsybl

#endif // POWSYBL_MATH_COMPLEXUTILS_HPP
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ set(IIDM_SOURCES
iidm/util/AbstractHalfLineBoundary.cpp
iidm/util/ConnectedComponents.cpp
iidm/util/DanglingLineBoundary.cpp
iidm/util/DanglingLineData.cpp
iidm/util/DistinctPredicate.cpp
iidm/util/Identifiables.cpp
iidm/util/LimitViolationUtils.cpp
Expand All @@ -209,6 +210,7 @@ set(IIDM_SOURCES
iidm/util/Substations.cpp
iidm/util/SV.cpp
iidm/util/TerminalFinder.cpp
iidm/util/TwtData.cpp
iidm/util/VoltageLevels.cpp

logging/ConsoleLogger.cpp
Expand All @@ -218,6 +220,7 @@ set(IIDM_SOURCES
logging/LogMessage.cpp
logging/NoopLogger.cpp

math/ComplexUtils.cpp
math/ConnectedComponentsComputationResult.cpp
math/GraphUtil.cpp

Expand Down
Loading