9#include <dpsim-models/DP/DP_Ph3_Inductor.h>
16 mPhaseType = PhaseType::ABC;
24 auto copy = Inductor::make(name,
mLogLevel);
31 Real omega = 2 * PI * frequency;
33 MatrixComp reactance = MatrixComp::Zero(3, 3);
34 reactance << Complex(0, omega * (**
mInductance)(0, 0)),
43 MatrixComp susceptance = reactance.inverse();
45 (**mIntfVoltage)(0, 0) = initialSingleVoltage(1) - initialSingleVoltage(0);
48 (**mIntfVoltage)(1, 0) = Complex(voltMag * cos(voltPhase - 2. / 3. * M_PI),
49 voltMag * sin(voltPhase - 2. / 3. * M_PI));
50 (**mIntfVoltage)(2, 0) = Complex(voltMag * cos(voltPhase + 2. / 3. * M_PI),
51 voltMag * sin(voltPhase + 2. / 3. * M_PI));
56 SPDLOG_LOGGER_INFO(
mSLog,
"--- Initialize according to power flow ---");
59void DP::Ph3::Inductor::initVars(Real omega, Real timeStep) {
60 Matrix a = timeStep / 2. * (**mInductance).inverse();
61 Real b = timeStep * omega / 2.;
63 Matrix equivCondReal = a / (1. + b * b);
64 Matrix equivCondImag = -a * b / (Real(1.) + b * b);
65 mEquivCond = MatrixComp::Zero(3, 3);
66 mEquivCond << Complex(equivCondReal(0, 0), equivCondImag(0, 0)),
67 Complex(equivCondReal(0, 1), equivCondImag(0, 1)),
68 Complex(equivCondReal(0, 2), equivCondImag(0, 2)),
69 Complex(equivCondReal(1, 0), equivCondImag(1, 0)),
70 Complex(equivCondReal(1, 1), equivCondImag(1, 1)),
71 Complex(equivCondReal(1, 2), equivCondImag(1, 2)),
72 Complex(equivCondReal(2, 0), equivCondImag(2, 0)),
73 Complex(equivCondReal(2, 1), equivCondImag(2, 1)),
74 Complex(equivCondReal(2, 2), equivCondImag(2, 2));
76 Real preCurrFracReal = (1. - b * b) / (1. + b * b);
77 Real preCurrFracImag = (-2. * b) / (1. + b * b);
78 mPrevCurrFac = Complex(preCurrFracReal, preCurrFracImag);
81 mEquivCurrent = mEquivCond * **mIntfVoltage + mPrevCurrFac * **mIntfCurrent;
85 Attribute<Matrix>::Ptr leftVector) {
87 initVars(omega, timeStep);
89 SPDLOG_LOGGER_INFO(
mSLog,
"Initial voltage {}",
94 SparseMatrixRow &systemMatrix) {
95 MNAStampUtils::stampAdmittanceMatrix(
96 mEquivCond, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1),
97 terminalNotGrounded(0), terminalNotGrounded(1),
mSLog);
105 if (terminalNotGrounded(0)) {
106 Math::setVectorElement(rightVector, matrixNodeIndex(0, 0),
108 Math::setVectorElement(rightVector, matrixNodeIndex(0, 1),
110 Math::setVectorElement(rightVector, matrixNodeIndex(0, 2),
113 if (terminalNotGrounded(1)) {
114 Math::setVectorElement(rightVector, matrixNodeIndex(1, 0),
116 Math::setVectorElement(rightVector, matrixNodeIndex(1, 1),
118 Math::setVectorElement(rightVector, matrixNodeIndex(1, 2),
124 AttributeBase::List &prevStepDependencies,
125 AttributeBase::List &attributeDependencies,
126 AttributeBase::List &modifiedAttributes) {
133void DP::Ph3::Inductor::mnaCompPreStep(Real time, Int timeStepCount) {
134 mnaCompApplyRightSideVectorStamp(**mRightVector);
138 AttributeBase::List &prevStepDependencies,
139 AttributeBase::List &attributeDependencies,
140 AttributeBase::List &modifiedAttributes,
141 Attribute<Matrix>::Ptr &leftVector) {
142 attributeDependencies.push_back(leftVector);
147void DP::Ph3::Inductor::mnaCompPostStep(Real time, Int timeStepCount,
148 Attribute<Matrix>::Ptr &leftVector) {
149 mnaCompUpdateVoltage(**leftVector);
150 mnaCompUpdateCurrent(**leftVector);
156 if (terminalNotGrounded(1)) {
157 (**mIntfVoltage)(0, 0) =
158 Math::complexFromVectorElement(leftVector, matrixNodeIndex(1, 0));
159 (**mIntfVoltage)(1, 0) =
160 Math::complexFromVectorElement(leftVector, matrixNodeIndex(1, 1));
161 (**mIntfVoltage)(2, 0) =
162 Math::complexFromVectorElement(leftVector, matrixNodeIndex(1, 2));
164 if (terminalNotGrounded(0)) {
165 (**mIntfVoltage)(0, 0) =
167 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0, 0));
168 (**mIntfVoltage)(1, 0) =
170 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0, 1));
171 (**mIntfVoltage)(2, 0) =
173 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0, 2));
181void DP::Ph3::Inductor::mnaTearInitialize(Real omega, Real timeStep) {
182 initVars(omega, timeStep);
185void DP::Ph3::Inductor::mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix) {}
187void DP::Ph3::Inductor::mnaTearApplyVoltageStamp(Matrix &voltageVector) {}
189void DP::Ph3::Inductor::mnaTearPostStep(Complex voltage, Complex current) {}
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 mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
Complex mPrevCurrFac
Coefficient in front of previous current value.
MatrixComp mEquivCurrent
DC equivalent current source [A].
void mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Update interface voltage from MNA system result.
Inductor(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name, component parameters and logging level.
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Update interface current from MNA system result.
MatrixComp mEquivCond
Equivalent conductance [S].
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
Add MNA post step dependencies.
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
Stamps right side (source) vector.
String uid()
Returns unique id.
AttributeList::Ptr mAttributes
Attribute List.
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
Attribute< Matrix >::Ptr mRightVector
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
void updateMatrixNodeIndices()
Logger::Level mLogLevel
Component logger control for internal variables.
Logger::Log mSLog
Component logger.