DPsim
Loading...
Searching...
No Matches
EMT_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<Real>(uid, name, true, true, logLevel),
18 mEquivCurrent = Matrix::Zero(3, 1);
19 **mIntfVoltage = Matrix::Zero(3, 1);
20 **mIntfCurrent = Matrix::Zero(3, 1);
21}
22
24 auto copy = Inductor::make(name, mLogLevel);
25 copy->setParameters(**mInductance);
26 return copy;
27}
28
30
31 Real omega = 2 * PI * frequency;
32 MatrixComp impedance = MatrixComp::Zero(3, 3);
33 impedance << Complex(0, omega * (**mInductance)(0, 0)),
34 Complex(0, omega * (**mInductance)(0, 1)),
35 Complex(0, omega * (**mInductance)(0, 2)),
36 Complex(0, omega * (**mInductance)(1, 0)),
37 Complex(0, omega * (**mInductance)(1, 1)),
38 Complex(0, omega * (**mInductance)(1, 2)),
39 Complex(0, omega * (**mInductance)(2, 0)),
40 Complex(0, omega * (**mInductance)(2, 1)),
41 Complex(0, omega * (**mInductance)(2, 2));
42
43 MatrixComp vInitABC = Matrix::Zero(3, 1);
44 vInitABC(0, 0) = RMS3PH_TO_PEAK1PH * initialSingleVoltage(1) -
46 vInitABC(1, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_B;
47 vInitABC(2, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_C;
48 **mIntfVoltage = vInitABC.real();
49 MatrixComp admittance = impedance.inverse();
50 **mIntfCurrent = (admittance * vInitABC).real();
51
52 SPDLOG_LOGGER_INFO(mSLog,
53 "\nInductance [H]: {:s}"
54 "\nImpedance [Ohm]: {:s}",
57 SPDLOG_LOGGER_INFO(
58 mSLog,
59 "\n--- Initialization from powerflow ---"
60 "\nVoltage across: {:s}"
61 "\nCurrent: {:s}"
62 "\nTerminal 0 voltage: {:s}"
63 "\nTerminal 1 voltage: {:s}"
64 "\n--- Initialization from powerflow finished ---",
69}
70
72 Attribute<Matrix>::Ptr leftVector) {
73
75 mEquivCond = timeStep / 2. * (**mInductance).inverse();
76 // Update internal state
78
79 SPDLOG_LOGGER_INFO(mSLog,
80 "\n--- MNA initialization ---"
81 "\nInitial voltage {:s}"
82 "\nInitial current {:s}"
83 "\nEquiv. current {:s}"
84 "\n--- MNA initialization finished ---",
88 mSLog->flush();
89}
90
92 SparseMatrixRow &systemMatrix) {
94 mEquivCond, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1),
96
97 SPDLOG_LOGGER_INFO(mSLog, "\nEquivalent Conductance: {:s}",
99}
100
102 // Update internal state
104 if (terminalNotGrounded(0)) {
105 Math::setVectorElement(rightVector, matrixNodeIndex(0, 0),
106 mEquivCurrent(0, 0));
107 Math::setVectorElement(rightVector, matrixNodeIndex(0, 1),
108 mEquivCurrent(1, 0));
109 Math::setVectorElement(rightVector, matrixNodeIndex(0, 2),
110 mEquivCurrent(2, 0));
111 }
112 if (terminalNotGrounded(1)) {
113 Math::setVectorElement(rightVector, matrixNodeIndex(1, 0),
114 -mEquivCurrent(0, 0));
115 Math::setVectorElement(rightVector, matrixNodeIndex(1, 1),
116 -mEquivCurrent(1, 0));
117 Math::setVectorElement(rightVector, matrixNodeIndex(1, 2),
118 -mEquivCurrent(2, 0));
119 }
120 SPDLOG_LOGGER_DEBUG(
121 mSLog, "\nEquivalent Current (mnaCompApplyRightSideVectorStamp): {:s}",
123 mSLog->flush();
124}
125
127 AttributeBase::List &prevStepDependencies,
128 AttributeBase::List &attributeDependencies,
129 AttributeBase::List &modifiedAttributes) {
130 // actually depends on L, but then we'd have to modify the system matrix anyway
131 prevStepDependencies.push_back(mIntfVoltage);
132 prevStepDependencies.push_back(mIntfCurrent);
133 modifiedAttributes.push_back(mRightVector);
134}
135
139
141 AttributeBase::List &prevStepDependencies,
142 AttributeBase::List &attributeDependencies,
143 AttributeBase::List &modifiedAttributes,
144 Attribute<Matrix>::Ptr &leftVector) {
145 attributeDependencies.push_back(leftVector);
146 modifiedAttributes.push_back(mIntfVoltage);
147 modifiedAttributes.push_back(mIntfCurrent);
148}
149
151 Attribute<Matrix>::Ptr &leftVector) {
152 mnaCompUpdateVoltage(**leftVector);
153 mnaCompUpdateCurrent(**leftVector);
154}
155
157 // v1 - v0
158 **mIntfVoltage = Matrix::Zero(3, 1);
159 if (terminalNotGrounded(1)) {
160 (**mIntfVoltage)(0, 0) =
162 (**mIntfVoltage)(1, 0) =
164 (**mIntfVoltage)(2, 0) =
166 }
167 if (terminalNotGrounded(0)) {
168 (**mIntfVoltage)(0, 0) =
169 (**mIntfVoltage)(0, 0) -
171 (**mIntfVoltage)(1, 0) =
172 (**mIntfVoltage)(1, 0) -
174 (**mIntfVoltage)(2, 0) =
175 (**mIntfVoltage)(2, 0) -
177 }
178 SPDLOG_LOGGER_DEBUG(mSLog, "\nUpdate Voltage: {:s}",
180}
181
184 SPDLOG_LOGGER_DEBUG(mSLog, "\nUpdate Current: {:s}",
186 mSLog->flush();
187}
188
189// #### Tear Methods ####
191 //initVars(omega, timeStep);
193 mEquivCond = timeStep / 2. * (**mInductance).inverse();
194 // Update internal state
196}
197
199 // Set diagonal entries
200 Math::addToMatrixElement(tearMatrix, mTearIdx * 3, mTearIdx * 3,
201 1. / mEquivCond(0, 0)); // 1 /
202 Math::addToMatrixElement(tearMatrix, mTearIdx * 3 + 1, mTearIdx * 3 + 1,
203 1. / mEquivCond(1, 1));
204 Math::addToMatrixElement(tearMatrix, mTearIdx * 3 + 2, mTearIdx * 3 + 2,
205 1. / mEquivCond(2, 2));
206}
207
210 Math::addToVectorElement(voltageVector, mTearIdx * 3,
211 mEquivCurrent(0, 0) / mEquivCond(0, 0));
212 Math::addToVectorElement(voltageVector, mTearIdx * 3 + 1,
213 mEquivCurrent(1, 0) / mEquivCond(1, 1));
214 Math::addToVectorElement(voltageVector, mTearIdx * 3 + 2,
215 mEquivCurrent(2, 0) / mEquivCond(2, 2));
216}
217
219 MatrixComp current) {
220 (**mIntfVoltage) = voltage.real();
221 (**mIntfCurrent) = (mEquivCond * voltage).real() + mEquivCurrent;
222}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:250
const CPS::Attribute< Matrix >::Ptr mInductance
Inductance [H].
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
Initializes internal variables of the component.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Update interface voltage from MNA system result.
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
MNA post step operations.
void mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix) override
void mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
SimPowerComp< Real >::Ptr clone(String name) override
Returns a modified copy of the component with the given suffix added to the name and without.
Matrix mEquivCond
Equivalent conductance [S].
void mnaTearInitialize(Real omega, Real timestep) override
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
Stamps right side (source) vector.
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Update interface current from MNA system result.
Matrix mEquivCurrent
DC equivalent current source [A].
void mnaTearApplyVoltageStamp(Matrix &voltageVector) override
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
void mnaCompPreStep(Real time, Int timeStepCount) override
MNA pre step operations.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
void mnaTearPostStep(MatrixComp voltage, MatrixComp current) override
Inductor(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name, component parameters and logging level.
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 matrixToString(const Matrix &mat)
Definition Logger.cpp:31
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 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)
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 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< Real > >::Ptr mIntfCurrent
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
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< 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
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:74