9 #include <dpsim-models/EMT/EMT_Ph3_Inductor.h>
16 mPhaseType = PhaseType::ABC;
24 auto copy = Inductor::make(name, mLogLevel);
25 copy->setParameters(**mInductance);
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));
43 MatrixComp vInitABC = Matrix::Zero(3, 1);
44 vInitABC(0, 0) = RMS3PH_TO_PEAK1PH * initialSingleVoltage(1) -
45 RMS3PH_TO_PEAK1PH * initialSingleVoltage(0);
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();
52 SPDLOG_LOGGER_INFO(mSLog,
53 "\nInductance [H]: {:s}"
54 "\nImpedance [Ohm]: {:s}",
55 Logger::matrixToString(**mInductance),
56 Logger::matrixCompToString(impedance));
59 "\n--- Initialization from powerflow ---"
60 "\nVoltage across: {:s}"
62 "\nTerminal 0 voltage: {:s}"
63 "\nTerminal 1 voltage: {:s}"
64 "\n--- Initialization from powerflow finished ---",
65 Logger::matrixToString(**mIntfVoltage),
66 Logger::matrixToString(**mIntfCurrent),
67 Logger::phasorToString(RMS3PH_TO_PEAK1PH * initialSingleVoltage(0)),
68 Logger::phasorToString(RMS3PH_TO_PEAK1PH * initialSingleVoltage(1)));
74 updateMatrixNodeIndices();
75 mEquivCond = timeStep / 2. * (**mInductance).inverse();
77 mEquivCurrent = mEquivCond * **mIntfVoltage + **mIntfCurrent;
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 ---",
85 Logger::matrixToString(**mIntfVoltage),
86 Logger::matrixToString(**mIntfCurrent),
87 Logger::matrixToString(mEquivCurrent));
92 SparseMatrixRow &systemMatrix) {
93 MNAStampUtils::stampConductanceMatrix(
94 mEquivCond, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1),
95 terminalNotGrounded(0), terminalNotGrounded(1), mSLog);
97 SPDLOG_LOGGER_INFO(mSLog,
"\nEquivalent Conductance: {:s}",
98 Logger::matrixToString(mEquivCond));
103 mEquivCurrent = mEquivCond * **mIntfVoltage + **mIntfCurrent;
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));
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));
121 mSLog,
"\nEquivalent Current (mnaCompApplyRightSideVectorStamp): {:s}",
122 Logger::matrixToString(mEquivCurrent));
127 AttributeBase::List &prevStepDependencies,
128 AttributeBase::List &attributeDependencies,
129 AttributeBase::List &modifiedAttributes) {
131 prevStepDependencies.push_back(mIntfVoltage);
132 prevStepDependencies.push_back(mIntfCurrent);
133 modifiedAttributes.push_back(mRightVector);
137 mnaCompApplyRightSideVectorStamp(**mRightVector);
141 AttributeBase::List &prevStepDependencies,
142 AttributeBase::List &attributeDependencies,
143 AttributeBase::List &modifiedAttributes,
145 attributeDependencies.push_back(leftVector);
146 modifiedAttributes.push_back(mIntfVoltage);
147 modifiedAttributes.push_back(mIntfCurrent);
152 mnaCompUpdateVoltage(**leftVector);
153 mnaCompUpdateCurrent(**leftVector);
158 **mIntfVoltage = Matrix::Zero(3, 1);
159 if (terminalNotGrounded(1)) {
160 (**mIntfVoltage)(0, 0) =
161 Math::realFromVectorElement(leftVector, matrixNodeIndex(1, 0));
162 (**mIntfVoltage)(1, 0) =
163 Math::realFromVectorElement(leftVector, matrixNodeIndex(1, 1));
164 (**mIntfVoltage)(2, 0) =
165 Math::realFromVectorElement(leftVector, matrixNodeIndex(1, 2));
167 if (terminalNotGrounded(0)) {
168 (**mIntfVoltage)(0, 0) =
169 (**mIntfVoltage)(0, 0) -
170 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 0));
171 (**mIntfVoltage)(1, 0) =
172 (**mIntfVoltage)(1, 0) -
173 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 1));
174 (**mIntfVoltage)(2, 0) =
175 (**mIntfVoltage)(2, 0) -
176 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 2));
178 SPDLOG_LOGGER_DEBUG(mSLog,
"\nUpdate Voltage: {:s}",
179 Logger::matrixToString(**mIntfVoltage));
183 **mIntfCurrent = mEquivCond * **mIntfVoltage + mEquivCurrent;
184 SPDLOG_LOGGER_DEBUG(mSLog,
"\nUpdate Current: {:s}",
185 Logger::matrixToString(**mIntfCurrent));
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 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.
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 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.
Inductor(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name, component parameters and logging level.
Base class for all MNA components that are transmitting power.
Base class for all components that are transmitting power.
const Attribute< MatrixVar< Real > >::Ptr mIntfCurrent
Current through component.
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
Voltage between terminals.