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 **mIntfVoltage = MatrixComp::Zero(3, 1);
21 **mIntfCurrent = MatrixComp::Zero(3, 1);
22}
23
25 auto copy = Inductor::make(name, mLogLevel);
26 copy->setParameters(**mInductance);
27 return copy;
28}
29
31 const Real omega = 2.0 * PI * frequency;
32
33 MatrixComp reactance = MatrixComp::Zero(3, 3);
34
35 for (UInt row = 0; row < 3; ++row) {
36 for (UInt col = 0; col < 3; ++col) {
37 reactance(row, col) = Complex(0.0, omega * (**mInductance)(row, col));
38 }
39 }
40
41 // ---------------------------------------------------------------------------
42 // IMPORTANT DP / PF CONVENTION CONVERSION
43 // ---------------------------------------------------------------------------
44 // Power-flow node voltages are line-line RMS phasors.
45 // DP::Ph3 electrical states use phase-peak complex envelopes.
46 //
47 // This conversion is already used by DP::Ph3::PiLine and must also be used
48 // by the primitive inductor. The previous implementation omitted the
49 // RMS3PH_TO_PEAK1PH factor here, which initialized the inductor state too
50 // small by sqrt(3/2) and produced a startup transient after PF initialization.
51 // ---------------------------------------------------------------------------
52
53 MatrixComp vInitABC = MatrixComp::Zero(3, 1);
54
55 vInitABC(0, 0) =
57
58 vInitABC(1, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_B;
59
60 vInitABC(2, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_C;
61
62 **mIntfVoltage = vInitABC;
63 **mIntfCurrent = reactance.inverse() * vInitABC;
64
65 SPDLOG_LOGGER_INFO(
66 mSLog,
67 "\n--- Initialization from powerflow ---"
68 "\nDP convention: phase-peak complex envelopes"
69 "\nVoltage across:"
70 "\n{:s}"
71 "\nCurrent:"
72 "\n{:s}"
73 "\nTerminal 0 PF voltage converted to phase peak: {:s}"
74 "\nTerminal 1 PF voltage converted to phase peak: {:s}"
75 "\n--- Initialization from powerflow finished ---",
80}
81
82void DP::Ph3::Inductor::initVars(Real omega, Real timeStep) {
83 Matrix a = timeStep / 2.0 * (**mInductance).inverse();
84
85 const Real b = timeStep * omega / 2.0;
86
87 Matrix equivCondReal = a / (1.0 + b * b);
88
89 Matrix equivCondImag = -a * b / (1.0 + b * b);
90
91 mEquivCond = MatrixComp::Zero(3, 3);
92
93 for (UInt row = 0; row < 3; ++row) {
94 for (UInt col = 0; col < 3; ++col) {
95 mEquivCond(row, col) =
96 Complex(equivCondReal(row, col), equivCondImag(row, col));
97 }
98 }
99
100 const Real preCurrFracReal = (1.0 - b * b) / (1.0 + b * b);
101
102 const Real preCurrFracImag = (-2.0 * b) / (1.0 + b * b);
103
104 mPrevCurrFac = Complex(preCurrFracReal, preCurrFracImag);
105
106 // Initialize the history source consistently with the initialized
107 // phase-peak DP voltage/current envelopes.
109}
110
112 Attribute<Matrix>::Ptr leftVector) {
114 initVars(omega, timeStep);
115
116 SPDLOG_LOGGER_INFO(mSLog, "Initial phase-A DP voltage envelope: {} < {} rad",
117 Math::abs((**mIntfVoltage)(0, 0)),
118 Math::phase((**mIntfVoltage)(0, 0)));
119
120 SPDLOG_LOGGER_INFO(mSLog, "Initial phase-A DP current envelope: {} < {} rad",
121 Math::abs((**mIntfCurrent)(0, 0)),
122 Math::phase((**mIntfCurrent)(0, 0)));
123}
124
131
133 // Companion-model history source for the next time step.
135
136 if (terminalNotGrounded(0)) {
137 Math::setVectorElement(rightVector, matrixNodeIndex(0, 0),
138 mEquivCurrent(0, 0));
139
140 Math::setVectorElement(rightVector, matrixNodeIndex(0, 1),
141 mEquivCurrent(1, 0));
142
143 Math::setVectorElement(rightVector, matrixNodeIndex(0, 2),
144 mEquivCurrent(2, 0));
145 }
146
147 if (terminalNotGrounded(1)) {
148 Math::setVectorElement(rightVector, matrixNodeIndex(1, 0),
149 -mEquivCurrent(0, 0));
150
151 Math::setVectorElement(rightVector, matrixNodeIndex(1, 1),
152 -mEquivCurrent(1, 0));
153
154 Math::setVectorElement(rightVector, matrixNodeIndex(1, 2),
155 -mEquivCurrent(2, 0));
156 }
157}
158
160 AttributeBase::List &prevStepDependencies,
161 AttributeBase::List &attributeDependencies,
162 AttributeBase::List &modifiedAttributes) {
163 modifiedAttributes.push_back(mRightVector);
164 prevStepDependencies.push_back(mIntfVoltage);
165 prevStepDependencies.push_back(mIntfCurrent);
166}
167
171
173 AttributeBase::List &prevStepDependencies,
174 AttributeBase::List &attributeDependencies,
175 AttributeBase::List &modifiedAttributes,
176 Attribute<Matrix>::Ptr &leftVector) {
177 attributeDependencies.push_back(leftVector);
178 modifiedAttributes.push_back(mIntfVoltage);
179 modifiedAttributes.push_back(mIntfCurrent);
180}
181
183 Attribute<Matrix>::Ptr &leftVector) {
184 mnaCompUpdateVoltage(**leftVector);
185 mnaCompUpdateCurrent(**leftVector);
186}
187
189 **mIntfVoltage = MatrixComp::Zero(3, 1);
190
191 if (terminalNotGrounded(1)) {
192 (**mIntfVoltage)(0, 0) =
194
195 (**mIntfVoltage)(1, 0) =
197
198 (**mIntfVoltage)(2, 0) =
200 }
201
202 if (terminalNotGrounded(0)) {
203 (**mIntfVoltage)(0, 0) -=
205
206 (**mIntfVoltage)(1, 0) -=
208
209 (**mIntfVoltage)(2, 0) -=
211 }
212}
213
217
218// #### Tear Methods ####
219
221 initVars(omega, timeStep);
222}
223
225 Math::addToMatrixElement(tearMatrix, mTearIdx * 3, mTearIdx * 3,
226 1.0 / mEquivCond(0, 0));
227
228 Math::addToMatrixElement(tearMatrix, mTearIdx * 3 + 1, mTearIdx * 3 + 1,
229 1.0 / mEquivCond(1, 1));
230
231 Math::addToMatrixElement(tearMatrix, mTearIdx * 3 + 2, mTearIdx * 3 + 2,
232 1.0 / mEquivCond(2, 2));
233}
234
237
238 Math::addToVectorElement(voltageVector, mTearIdx * 3,
239 mEquivCurrent(0, 0) / mEquivCond(0, 0));
240
241 Math::addToVectorElement(voltageVector, mTearIdx * 3 + 1,
242 mEquivCurrent(1, 0) / mEquivCond(1, 1));
243
244 Math::addToVectorElement(voltageVector, mTearIdx * 3 + 2,
245 mEquivCurrent(2, 0) / mEquivCond(2, 2));
246}
247
249 MatrixComp current) {
250 **mIntfVoltage = voltage;
251 **mIntfCurrent = mEquivCond * voltage + mEquivCurrent;
252}
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.
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
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 Complex complexFromVectorElement(const Matrix &mat, Matrix::Index row, Int maxFreq=1, Int freqIdx=0)
Definition MathUtils.cpp:94
static void setVectorElement(Matrix &mat, Matrix::Index row, Complex value, Int maxFreq=1, Int freqIdx=0, Matrix::Index colOffset=0)
Definition MathUtils.cpp:73
static void addToVectorElement(Matrix &mat, Matrix::Index row, Complex value, Int maxFreq=1, Int freqIdx=0)
Definition MathUtils.cpp:83
static Real phase(Complex value)
Definition MathUtils.cpp:23
static Real abs(Complex value)
Definition MathUtils.cpp:27
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:81
std::string String
Definition Definitions.h:65
double Real
Definition Definitions.h:62
int Int
Definition Definitions.h:61
std::complex< Real > Complex
Definition Definitions.h:63
Eigen::Matrix< Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixComp
Dense matrix for complex numbers.
Definition Definitions.h:84
unsigned int UInt
Definition Definitions.h:60
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:74