DPsim
Loading...
Searching...
No Matches
EMT_Ph3_SSN_ImpedanceLoad.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Institute for Automation of Complex Power Systems, EONERC, RWTH Aachen University
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
7
8#include <algorithm>
9#include <cmath>
10#include <stdexcept>
11
12using namespace CPS;
13
15 Logger::Level logLevel)
16 : VTypeSSNComp(uid, name, 3, 3, logLevel) {
18 *mIntfVoltageValue = Matrix::Zero(3, 1);
19 *mIntfCurrentValue = Matrix::Zero(3, 1);
20}
21
23 auto copy = SharedFactory<ImpedanceLoad>::make(copySuffix, mLogLevel);
24 copy->setParameters(mActivePower, mReactivePower, mNominalVoltage,
25 mShuntConductance, mShuntSusceptance);
26 return copy;
27}
28
30 Real reactivePower,
31 Real nominalVoltage,
32 Real shuntConductance,
33 Real shuntSusceptance) {
34 if (!std::isfinite(activePower) || !std::isfinite(reactivePower) ||
35 !std::isfinite(nominalVoltage) || !std::isfinite(shuntConductance) ||
36 !std::isfinite(shuntSusceptance) ||
37 ((activePower != 0. || reactivePower != 0.) && nominalVoltage <= 0.))
38 throw std::invalid_argument("Invalid impedance-load parameters.");
39 mActivePower = activePower;
40 mReactivePower = reactivePower;
41 mNominalVoltage = nominalVoltage;
42 mShuntConductance = shuntConductance;
43 mShuntSusceptance = shuntSusceptance;
44 mLoadConductance = nominalVoltage > 0.
45 ? activePower / (nominalVoltage * nominalVoltage)
46 : 0.;
47 mTotalConductance = mLoadConductance + shuntConductance;
48 const Matrix zero = Matrix::Zero(3, 3);
49 SSNComp::setParameters(zero, zero, zero,
50 mTotalConductance * Matrix::Identity(3, 3));
51}
52
54 Real frequency) {
55 if (frequency <= 0.)
56 throw std::invalid_argument("Frequency must be positive.");
57 const Real omega = 2. * PI * frequency;
58 const Real loadSusceptance =
59 mNominalVoltage > 0.
60 ? mReactivePower / (mNominalVoltage * mNominalVoltage)
61 : 0.;
62 const Real inductiveSusceptance =
63 std::max(loadSusceptance, 0.) + std::max(-mShuntSusceptance, 0.);
64 const Real capacitiveSusceptance =
65 std::max(-loadSusceptance, 0.) + std::max(mShuntSusceptance, 0.);
66 mLoadInductance =
67 inductiveSusceptance > 0. ? 1. / (omega * inductiveSusceptance) : 0.;
68 mLoadCapacitance = capacitiveSusceptance / omega;
69
70 const Matrix identity = Matrix::Identity(3, 3);
71 Matrix inverseInductance = Matrix::Zero(3, 3);
72 Matrix c = Matrix::Zero(3, 3);
73 if (mLoadInductance > 0.) {
74 inverseInductance = (1. / mLoadInductance) * identity;
75 c = identity;
76 }
77 SSNComp::setParameters(Matrix::Zero(3, 3), inverseInductance, c,
78 mTotalConductance * identity,
79 mLoadCapacitance * identity);
81}
82
84 MatrixComp voltage = MatrixComp::Zero(3, 1);
86 voltage(0, 0) = phaseA;
87 voltage(1, 0) = phaseA * SHIFT_TO_PHASE_B;
88 voltage(2, 0) = phaseA * SHIFT_TO_PHASE_C;
89 return voltage;
90}
91
97
99 Matrix &rightVector) {
100 if (!terminalNotGrounded(0))
101 return;
102 for (UInt phase = 0; phase < 3; ++phase)
103 Math::setVectorElement(rightVector, matrixNodeIndex(0, phase),
104 -mYHist(phase, 0));
105}
106
108 const Matrix &leftVector) {
109 mIntfVoltageValue->setZero();
110 if (terminalNotGrounded(0))
111 for (UInt phase = 0; phase < 3; ++phase)
112 (*mIntfVoltageValue)(phase, 0) =
113 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, phase));
114}
SimPowerComp< Real >::Ptr clone(String copySuffix) override
Returns a modified copy of the component with the given suffix added to the name and without.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
void initializeFromNodesAndTerminals(Real frequency) override
Initializes Component variables according to power flow data stored in Nodes.
ImpedanceLoad(String uid, String name, Logger::Level logLevel=Logger::Level::off)
MatrixComp buildInitialInputFromNodes(Real frequency) override
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
void setParameters(Real activePower, Real reactivePower, Real nominalVoltage, Real shuntConductance=0., Real shuntSusceptance=0.)
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
void setParameters(const Matrix &A, const Matrix &B, const Matrix &C, const Matrix &D, const Matrix &D1=Matrix())
VTypeSSNComp(String uid, String name, Int inputSize, Int outputSize, Logger::Level logLevel=Logger::Level::off)
void initializeFromNodesAndTerminals(Real frequency) override
Initializes Component variables according to power flow data stored in Nodes.
String uid()
Returns unique id.
spdlog::level::level_enum Level
Definition Logger.h:33
static void stampConductanceMatrix(const Matrix &conductanceMat, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Bool isTerminal1NotGrounded, Bool isTerminal2NotGrounded, const Logger::Log &mSLog)
static Real realFromVectorElement(const Matrix &mat, Matrix::Index row)
static void setVectorElement(Matrix &mat, Matrix::Index row, Complex value, Int maxFreq=1, Int freqIdx=0, Matrix::Index colOffset=0)
UInt matrixNodeIndex(UInt nodeIndex)
MatrixVar< Real > * mIntfVoltageValue
MatrixVar< Real > * mIntfCurrentValue
std::shared_ptr< SimPowerComp< VarType > > Ptr
Bool terminalNotGrounded(UInt index)
Complex initialSingleVoltage(UInt index)
void setTerminalNumber(UInt num)
Logger::Level mLogLevel
Component logger control for internal variables.
Logger::Log mSLog
Component logger.
static std::shared_ptr< T > make(Args &&...args)
Definition PtrFactory.h:19
#define PI
Definition Definitions.h:43
#define RMS3PH_TO_PEAK1PH
Definition Definitions.h:50
#define SHIFT_TO_PHASE_C
Definition Definitions.h:47
#define SHIFT_TO_PHASE_B
Definition Definitions.h:46
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > Matrix
Dense matrix for real numbers.
Definition Definitions.h:79
std::string String
Definition Definitions.h:63
double Real
Definition Definitions.h:60
std::complex< Real > Complex
Definition Definitions.h:61
Eigen::Matrix< Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixComp
Dense matrix for complex numbers.
Definition Definitions.h:82
unsigned int UInt
Definition Definitions.h:58
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:72