DPsim
Loading...
Searching...
No Matches
DP_Ph3_Inductor.cpp
Go to the documentation of this file.
1/* Copyright 2017-2021 Institute for Automation of Complex Power Systems,
2 * EONERC, RWTH Aachen University
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7 *********************************************************************************/
8
10
11using namespace CPS;
12
14 : MNASimPowerComp<Complex>(uid, name, true, true, logLevel),
18
19 mEquivCurrent = MatrixComp::Zero(3, 1);
20 mEquivImpedance = MatrixComp::Zero(3, 3);
21 **mIntfVoltage = MatrixComp::Zero(3, 1);
22 **mIntfCurrent = MatrixComp::Zero(3, 1);
23}
24
26 auto copy = Inductor::make(name, mLogLevel);
27 copy->setParameters(**mInductance);
28 return copy;
29}
30
32 const Real omega = 2.0 * PI * frequency;
33
34 MatrixComp reactance = MatrixComp::Zero(3, 3);
35
36 for (UInt row = 0; row < 3; ++row) {
37 for (UInt col = 0; col < 3; ++col) {
38 reactance(row, col) = Complex(0.0, omega * (**mInductance)(row, col));
39 }
40 }
41
42 MatrixComp vInitABC = MatrixComp::Zero(3, 1);
43
44 vInitABC(0, 0) =
46
47 vInitABC(1, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_B;
48
49 vInitABC(2, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_C;
50
51 **mIntfVoltage = vInitABC;
52 **mIntfCurrent = reactance.inverse() * vInitABC;
53
54 SPDLOG_LOGGER_INFO(
55 mSLog,
56 "\n--- Initialization from powerflow ---"
57 "\nDP convention: phase-peak complex envelopes"
58 "\nVoltage across:"
59 "\n{:s}"
60 "\nCurrent:"
61 "\n{:s}"
62 "\nTerminal 0 PF voltage converted to phase peak: {:s}"
63 "\nTerminal 1 PF voltage converted to phase peak: {:s}"
64 "\n--- Initialization from powerflow finished ---",
69}
70
71void DP::Ph3::Inductor::initVars(Real omega, Real timeStep) {
72 Matrix a = timeStep / 2.0 * (**mInductance).inverse();
73
74 const Real b = timeStep * omega / 2.0;
75
76 Matrix equivCondReal = a / (1.0 + b * b);
77
78 Matrix equivCondImag = -a * b / (1.0 + b * b);
79
80 mEquivCond = MatrixComp::Zero(3, 3);
81
82 for (UInt row = 0; row < 3; ++row) {
83 for (UInt col = 0; col < 3; ++col) {
84 mEquivCond(row, col) =
85 Complex(equivCondReal(row, col), equivCondImag(row, col));
86 }
87 }
88
89 const Real preCurrFracReal = (1.0 - b * b) / (1.0 + b * b);
90
91 const Real preCurrFracImag = (-2.0 * b) / (1.0 + b * b);
92
93 mPrevCurrFac = Complex(preCurrFracReal, preCurrFracImag);
94
95 // Initialize the history source consistently with the initialized
96 // phase-peak DP voltage/current envelopes.
97 mEquivImpedance = mEquivCond.inverse();
99}
100
102 Attribute<Matrix>::Ptr leftVector) {
104 initVars(omega, timeStep);
105
106 SPDLOG_LOGGER_INFO(mSLog, "Initial phase-A DP voltage envelope: {} < {} rad",
107 Math::abs((**mIntfVoltage)(0, 0)),
108 Math::phase((**mIntfVoltage)(0, 0)));
109
110 SPDLOG_LOGGER_INFO(mSLog, "Initial phase-A DP current envelope: {} < {} rad",
111 Math::abs((**mIntfCurrent)(0, 0)),
112 Math::phase((**mIntfCurrent)(0, 0)));
113}
114
121
123 // Companion-model history source for the next time step.
125
126 if (terminalNotGrounded(0)) {
127 Math::setVectorElement(rightVector, matrixNodeIndex(0, 0),
128 mEquivCurrent(0, 0));
129
130 Math::setVectorElement(rightVector, matrixNodeIndex(0, 1),
131 mEquivCurrent(1, 0));
132
133 Math::setVectorElement(rightVector, matrixNodeIndex(0, 2),
134 mEquivCurrent(2, 0));
135 }
136
137 if (terminalNotGrounded(1)) {
138 Math::setVectorElement(rightVector, matrixNodeIndex(1, 0),
139 -mEquivCurrent(0, 0));
140
141 Math::setVectorElement(rightVector, matrixNodeIndex(1, 1),
142 -mEquivCurrent(1, 0));
143
144 Math::setVectorElement(rightVector, matrixNodeIndex(1, 2),
145 -mEquivCurrent(2, 0));
146 }
147}
148
150 const MatrixComp &history = mEquivCurrent;
151 if (terminalNotGrounded(0))
152 for (UInt phase = 0; phase < 3; ++phase)
153 Math::addToVectorElement(rightVector, matrixNodeIndex(0, phase),
154 history(phase, 0));
155 if (terminalNotGrounded(1))
156 for (UInt phase = 0; phase < 3; ++phase)
157 Math::addToVectorElement(rightVector, matrixNodeIndex(1, phase),
158 -history(phase, 0));
159}
160
162 AttributeBase::List &prevStepDependencies,
163 AttributeBase::List &attributeDependencies,
164 AttributeBase::List &modifiedAttributes) {
165 modifiedAttributes.push_back(mRightVector);
166 prevStepDependencies.push_back(mIntfVoltage);
167 prevStepDependencies.push_back(mIntfCurrent);
168}
169
173
175 AttributeBase::List &prevStepDependencies,
176 AttributeBase::List &attributeDependencies,
177 AttributeBase::List &modifiedAttributes,
178 Attribute<Matrix>::Ptr &leftVector) {
179 attributeDependencies.push_back(leftVector);
180 modifiedAttributes.push_back(mIntfVoltage);
181 modifiedAttributes.push_back(mIntfCurrent);
182}
183
185 Attribute<Matrix>::Ptr &leftVector) {
186 mnaCompUpdateVoltage(**leftVector);
187 mnaCompUpdateCurrent(**leftVector);
188}
189
191 const bool terminal0Connected = terminalNotGrounded(0);
192 const bool terminal1Connected = terminalNotGrounded(1);
193 const Matrix::Index imaginaryOffset = leftVector.rows() / 2;
194 for (UInt phase = 0; phase < 3; ++phase) {
195 Complex voltage(0., 0.);
196 if (terminal1Connected) {
197 const Matrix::Index row = matrixNodeIndex(1, phase);
198 voltage =
199 Complex(leftVector(row, 0), leftVector(row + imaginaryOffset, 0));
200 }
201 if (terminal0Connected) {
202 const Matrix::Index row = matrixNodeIndex(0, phase);
203 voltage -=
204 Complex(leftVector(row, 0), leftVector(row + imaginaryOffset, 0));
205 }
206 (**mIntfVoltage)(phase, 0) = voltage;
207 }
208}
209
211 // Fuse the fixed-size matrix-vector product with the history term.
212 const MatrixComp &voltage = **mIntfVoltage;
213 MatrixComp &current = **mIntfCurrent;
214 for (Int phase = 0; phase < 3; ++phase)
215 current(phase, 0) = mEquivCond(phase, 0) * voltage(0, 0) +
216 mEquivCond(phase, 1) * voltage(1, 0) +
217 mEquivCond(phase, 2) * voltage(2, 0) +
218 mEquivCurrent(phase, 0);
219}
220
221// #### Tear Methods ####
222
224 initVars(omega, timeStep);
225}
226
228 // A three-phase inductor may have mutual inductances. The normal MNA stamp
229 // keeps those off-diagonal terms, so the tear-domain impedance stamp must
230 // retain the full inverse companion-admittance matrix as well.
231 for (UInt row = 0; row < 3; ++row) {
232 for (UInt col = 0; col < 3; ++col) {
233 Math::addToMatrixElement(tearMatrix, mTearIdx * 3 + row,
234 mTearIdx * 3 + col, mEquivImpedance(row, col));
235 }
236 }
237}
238
241 const MatrixComp equivVoltage = mEquivImpedance * mEquivCurrent;
242
243 for (UInt phase = 0; phase < 3; ++phase) {
244 Math::addToVectorElement(voltageVector, mTearIdx * 3 + phase,
245 equivVoltage(phase, 0));
246 }
247}
248
250 MatrixComp current) {
251 **mIntfVoltage = voltage;
252 **mIntfCurrent = mEquivCond * voltage + mEquivCurrent;
253}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:249
const CPS::Attribute< Matrix >::Ptr mInductance
Inductance [H].
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
void initializeFromNodesAndTerminals(Real frequency) override
Initialize DP phase-peak envelopes from line-line RMS PF node voltages.
MatrixComp mEquivImpedance
Inverse companion impedance [Ohm], cached for SSN tearing.
Complex mPrevCurrFac
Coefficient multiplying the previous current value.
void mnaTearPostStep(MatrixComp voltage, MatrixComp current) override
MatrixComp mEquivCurrent
Equivalent current source [A].
void mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Inductor(String uid, String name, Logger::Level logLevel=Logger::Level::off)
void mnaCompUpdateCurrent(const Matrix &leftVector) override
void mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix) override
void mnaAddCompactRightSideVectorStamp(Matrix &rightVector) override
MatrixComp mEquivCond
Equivalent conductance [S].
void initVars(Real omega, Real timeStep)
void mnaTearInitialize(Real omega, Real timestep) override
SimPowerComp< Complex >::Ptr clone(String name) override
Returns a modified copy of the component with the given suffix added to the name and without.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
void mnaCompPreStep(Real time, Int timeStepCount) override
void mnaTearApplyVoltageStamp(Matrix &voltageVector) override
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
String uid()
Returns unique id.
AttributeList::Ptr mAttributes
Attribute List.
spdlog::level::level_enum Level
Definition Logger.h:33
static String matrixCompToString(const MatrixComp &mat)
Definition Logger.cpp:37
static String phasorToString(const Complex &num)
Definition Logger.cpp:57
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
Attribute< Matrix >::Ptr mRightVector
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 void setVectorElement(Matrix &mat, Matrix::Index row, Complex value, Int maxFreq=1, Int freqIdx=0, Matrix::Index colOffset=0)
static void addToVectorElement(Matrix &mat, Matrix::Index row, Complex value, Int maxFreq=1, Int freqIdx=0)
static Real phase(Complex value)
Definition MathUtils.cpp:67
static Real abs(Complex value)
Definition MathUtils.cpp:71
static void addToMatrixElement(SparseMatrixRow &mat, Matrix::Index row, Matrix::Index column, Complex value, Int maxFreq=1, Int freqIdx=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< Inductor > 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
int Int
Definition Definitions.h:59
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