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 MatrixComp vInitABC = MatrixComp::Zero(3, 1);
42
43 vInitABC(0, 0) =
45
46 vInitABC(1, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_B;
47
48 vInitABC(2, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_C;
49
50 **mIntfVoltage = vInitABC;
51 **mIntfCurrent = reactance.inverse() * vInitABC;
52
53 SPDLOG_LOGGER_INFO(
54 mSLog,
55 "\n--- Initialization from powerflow ---"
56 "\nDP convention: phase-peak complex envelopes"
57 "\nVoltage across:"
58 "\n{:s}"
59 "\nCurrent:"
60 "\n{:s}"
61 "\nTerminal 0 PF voltage converted to phase peak: {:s}"
62 "\nTerminal 1 PF voltage converted to phase peak: {:s}"
63 "\n--- Initialization from powerflow finished ---",
68}
69
70void DP::Ph3::Inductor::initVars(Real omega, Real timeStep) {
71 Matrix a = timeStep / 2.0 * (**mInductance).inverse();
72
73 const Real b = timeStep * omega / 2.0;
74
75 Matrix equivCondReal = a / (1.0 + b * b);
76
77 Matrix equivCondImag = -a * b / (1.0 + b * b);
78
79 mEquivCond = MatrixComp::Zero(3, 3);
80
81 for (UInt row = 0; row < 3; ++row) {
82 for (UInt col = 0; col < 3; ++col) {
83 mEquivCond(row, col) =
84 Complex(equivCondReal(row, col), equivCondImag(row, col));
85 }
86 }
87
88 const Real preCurrFracReal = (1.0 - b * b) / (1.0 + b * b);
89
90 const Real preCurrFracImag = (-2.0 * b) / (1.0 + b * b);
91
92 mPrevCurrFac = Complex(preCurrFracReal, preCurrFracImag);
93
94 // Initialize the history source consistently with the initialized
95 // phase-peak DP voltage/current envelopes.
97}
98
100 Attribute<Matrix>::Ptr leftVector) {
102 initVars(omega, timeStep);
103
104 SPDLOG_LOGGER_INFO(mSLog, "Initial phase-A DP voltage envelope: {} < {} rad",
105 Math::abs((**mIntfVoltage)(0, 0)),
106 Math::phase((**mIntfVoltage)(0, 0)));
107
108 SPDLOG_LOGGER_INFO(mSLog, "Initial phase-A DP current envelope: {} < {} rad",
109 Math::abs((**mIntfCurrent)(0, 0)),
110 Math::phase((**mIntfCurrent)(0, 0)));
111}
112
119
121 // Companion-model history source for the next time step.
123
124 if (terminalNotGrounded(0)) {
125 Math::setVectorElement(rightVector, matrixNodeIndex(0, 0),
126 mEquivCurrent(0, 0));
127
128 Math::setVectorElement(rightVector, matrixNodeIndex(0, 1),
129 mEquivCurrent(1, 0));
130
131 Math::setVectorElement(rightVector, matrixNodeIndex(0, 2),
132 mEquivCurrent(2, 0));
133 }
134
135 if (terminalNotGrounded(1)) {
136 Math::setVectorElement(rightVector, matrixNodeIndex(1, 0),
137 -mEquivCurrent(0, 0));
138
139 Math::setVectorElement(rightVector, matrixNodeIndex(1, 1),
140 -mEquivCurrent(1, 0));
141
142 Math::setVectorElement(rightVector, matrixNodeIndex(1, 2),
143 -mEquivCurrent(2, 0));
144 }
145}
146
148 AttributeBase::List &prevStepDependencies,
149 AttributeBase::List &attributeDependencies,
150 AttributeBase::List &modifiedAttributes) {
151 modifiedAttributes.push_back(mRightVector);
152 prevStepDependencies.push_back(mIntfVoltage);
153 prevStepDependencies.push_back(mIntfCurrent);
154}
155
159
161 AttributeBase::List &prevStepDependencies,
162 AttributeBase::List &attributeDependencies,
163 AttributeBase::List &modifiedAttributes,
164 Attribute<Matrix>::Ptr &leftVector) {
165 attributeDependencies.push_back(leftVector);
166 modifiedAttributes.push_back(mIntfVoltage);
167 modifiedAttributes.push_back(mIntfCurrent);
168}
169
171 Attribute<Matrix>::Ptr &leftVector) {
172 mnaCompUpdateVoltage(**leftVector);
173 mnaCompUpdateCurrent(**leftVector);
174}
175
177 **mIntfVoltage = MatrixComp::Zero(3, 1);
178
179 if (terminalNotGrounded(1)) {
180 (**mIntfVoltage)(0, 0) =
182
183 (**mIntfVoltage)(1, 0) =
185
186 (**mIntfVoltage)(2, 0) =
188 }
189
190 if (terminalNotGrounded(0)) {
191 (**mIntfVoltage)(0, 0) -=
193
194 (**mIntfVoltage)(1, 0) -=
196
197 (**mIntfVoltage)(2, 0) -=
199 }
200}
201
205
206// #### Tear Methods ####
207
209 initVars(omega, timeStep);
210}
211
213 Math::addToMatrixElement(tearMatrix, mTearIdx * 3, mTearIdx * 3,
214 1.0 / mEquivCond(0, 0));
215
216 Math::addToMatrixElement(tearMatrix, mTearIdx * 3 + 1, mTearIdx * 3 + 1,
217 1.0 / mEquivCond(1, 1));
218
219 Math::addToMatrixElement(tearMatrix, mTearIdx * 3 + 2, mTearIdx * 3 + 2,
220 1.0 / mEquivCond(2, 2));
221}
222
225
226 Math::addToVectorElement(voltageVector, mTearIdx * 3,
227 mEquivCurrent(0, 0) / mEquivCond(0, 0));
228
229 Math::addToVectorElement(voltageVector, mTearIdx * 3 + 1,
230 mEquivCurrent(1, 0) / mEquivCond(1, 1));
231
232 Math::addToVectorElement(voltageVector, mTearIdx * 3 + 2,
233 mEquivCurrent(2, 0) / mEquivCond(2, 2));
234}
235
237 MatrixComp current) {
238 **mIntfVoltage = voltage;
239 **mIntfCurrent = mEquivCond * voltage + mEquivCurrent;
240}
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: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