DPsim
Loading...
Searching...
No Matches
DP_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 **mIntfVoltage = MatrixComp::Zero(3, 1);
19 **mIntfCurrent = MatrixComp::Zero(3, 1);
20}
21
24 auto copy = SharedFactory<ImpedanceLoad>::make(copySuffix, mLogLevel);
25 copy->setParameters(mActivePower, mReactivePower, mNominalVoltage,
26 mShuntConductance, mShuntSusceptance);
27 return copy;
28}
29
31 Real reactivePower,
32 Real nominalVoltage,
33 Real shuntConductance,
34 Real shuntSusceptance) {
35 if (!std::isfinite(activePower) || !std::isfinite(reactivePower) ||
36 !std::isfinite(nominalVoltage) || !std::isfinite(shuntConductance) ||
37 !std::isfinite(shuntSusceptance) ||
38 ((activePower != 0. || reactivePower != 0.) && nominalVoltage <= 0.))
39 throw std::invalid_argument("Invalid impedance-load parameters.");
40 mActivePower = activePower;
41 mReactivePower = reactivePower;
42 mNominalVoltage = nominalVoltage;
43 mShuntConductance = shuntConductance;
44 mShuntSusceptance = shuntSusceptance;
45 mLoadConductance = nominalVoltage > 0.
46 ? activePower / (nominalVoltage * nominalVoltage)
47 : 0.;
48 const Matrix zero = Matrix::Zero(3, 3);
49 SSNComp::setParameters(zero, zero, zero,
50 (mLoadConductance + mShuntConductance) *
51 Matrix::Identity(3, 3));
52}
53
55 Real frequency) {
56 if (frequency <= 0.)
57 throw std::invalid_argument("Frequency must be positive.");
58 const Real omega = 2. * PI * frequency;
59 const Real loadSusceptance =
60 mNominalVoltage > 0.
61 ? mReactivePower / (mNominalVoltage * mNominalVoltage)
62 : 0.;
63 const Real inductiveSusceptance =
64 std::max(loadSusceptance, 0.) + std::max(-mShuntSusceptance, 0.);
65 const Real capacitiveSusceptance =
66 std::max(-loadSusceptance, 0.) + std::max(mShuntSusceptance, 0.);
67 mLoadInductance =
68 inductiveSusceptance > 0. ? 1. / (omega * inductiveSusceptance) : 0.;
69 mLoadCapacitance = capacitiveSusceptance / omega;
70
71 const Matrix identity = Matrix::Identity(3, 3);
72 Matrix inverseInductance = Matrix::Zero(3, 3);
73 Matrix c = Matrix::Zero(3, 3);
74 if (mLoadInductance > 0.) {
75 inverseInductance = (1. / mLoadInductance) * identity;
76 c = identity;
77 }
78 SSNComp::setParameters(Matrix::Zero(3, 3), inverseInductance, c,
79 (mLoadConductance + mShuntConductance) * identity,
80 mLoadCapacitance * identity);
82}
83
85 MatrixComp voltage = MatrixComp::Zero(3, 1);
87 voltage(0, 0) = phaseA;
88 voltage(1, 0) = phaseA * SHIFT_TO_PHASE_B;
89 voltage(2, 0) = phaseA * SHIFT_TO_PHASE_C;
90 return voltage;
91}
92
98
100 Matrix &rightVector) {
101 if (!terminalNotGrounded(0))
102 return;
103 for (UInt phase = 0; phase < 3; ++phase)
104 Math::setVectorElement(rightVector, matrixNodeIndex(0, phase),
105 -mYHist(phase, 0));
106}
107
109 const Matrix &leftVector) {
110 (**mIntfVoltage).setZero();
111 if (terminalNotGrounded(0))
112 for (UInt phase = 0; phase < 3; ++phase)
113 (**mIntfVoltage)(phase, 0) =
114 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0, phase));
115}
void mnaCompUpdateVoltage(const Matrix &leftVector) override
void setParameters(Real activePower, Real reactivePower, Real nominalVoltage, Real shuntConductance=0., Real shuntSusceptance=0.)
MatrixComp buildInitialInputFromNodes(Real frequency) override
Reconstruct the initial input voltage from node/terminal phasors.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes Component variables according to power flow data stored in Nodes.
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
ImpedanceLoad(String uid, String name, Logger::Level logLevel=Logger::Level::off)
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
SimPowerComp< Complex >::Ptr clone(String copySuffix) override
Returns a modified copy of the component with the given suffix added to the name and without.
MatrixComp mYHist
Complex history term.
Definition DP_SSNComp.h:43
MatrixComp mW
Complex Norton matrix W = C dB + D + (2 / dt + j omega) D1.
Definition DP_SSNComp.h:41
void setParameters(const Matrix &A, const Matrix &B, const Matrix &C, const Matrix &D, const Matrix &D1=Matrix())
void initializeFromNodesAndTerminals(Real frequency) override
Initializes Component variables according to power flow data stored in Nodes.
VTypeSSNComp(String uid, String name, Int inputSize, Int outputSize, Logger::Level logLevel=Logger::Level::off)
String uid()
Returns unique id.
spdlog::level::level_enum Level
Definition Logger.h:33
static void stampAdmittanceMatrix(const MatrixComp &admittanceMat, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Bool isTerminal1NotGrounded, Bool isTerminal2NotGrounded, const Logger::Log &mSLog, Int maxFreq=1, Int freqIdx=0)
static Complex complexFromVectorElement(const Matrix &mat, Matrix::Index row, Int maxFreq=1, Int freqIdx=0)
static void setVectorElement(Matrix &mat, Matrix::Index row, Complex value, Int maxFreq=1, Int freqIdx=0, Matrix::Index colOffset=0)
UInt matrixNodeIndex(UInt nodeIndex)
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
std::shared_ptr< SimPowerComp< VarType > > Ptr
Bool terminalNotGrounded(UInt index)
Complex initialSingleVoltage(UInt index)
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