9 #include <dpsim-models/DP/DP_Ph3_Capacitor.h>
12 using namespace CPS::DP::Ph3;
17 mPhaseType = PhaseType::ABC;
25 auto copy = Capacitor::make(name, mLogLevel);
26 copy->setParameters(**mCapacitance);
32 Real omega = 2 * PI * frequency;
33 MatrixComp susceptance = Matrix::Zero(3, 3);
35 susceptance << Complex(0, omega * (**mCapacitance)(0, 0)),
36 Complex(0, omega * (**mCapacitance)(0, 1)),
37 Complex(0, omega * (**mCapacitance)(0, 2)),
38 Complex(0, omega * (**mCapacitance)(1, 0)),
39 Complex(0, omega * (**mCapacitance)(1, 1)),
40 Complex(0, omega * (**mCapacitance)(1, 2)),
41 Complex(0, omega * (**mCapacitance)(2, 0)),
42 Complex(0, omega * (**mCapacitance)(2, 1)),
43 Complex(0, omega * (**mCapacitance)(2, 2));
46 (**mIntfVoltage)(0, 0) = initialSingleVoltage(1) - initialSingleVoltage(0);
47 Real voltMag = Math::abs((**mIntfVoltage)(0, 0));
48 Real voltPhase = Math::phase((**mIntfVoltage)(0, 0));
49 (**mIntfVoltage)(1, 0) = Complex(voltMag * cos(voltPhase - 2. / 3. * M_PI),
50 voltMag * sin(voltPhase - 2. / 3. * M_PI));
51 (**mIntfVoltage)(2, 0) = Complex(voltMag * cos(voltPhase + 2. / 3. * M_PI),
52 voltMag * sin(voltPhase + 2. / 3. * M_PI));
54 **mIntfCurrent = susceptance * **mIntfVoltage;
56 SPDLOG_LOGGER_INFO(mSLog,
"\n--- Initialize from power flow ---");
70 Matrix a = timeStep / 2 * (**mCapacitance).inverse();
71 Real b = timeStep * omega / 2.;
73 Matrix equivCondReal = a.inverse();
74 Matrix equivCondImag = b * equivCondReal;
75 mEquivCond = Matrix::Zero(3, 3);
76 mEquivCond << Complex(equivCondReal(0, 0), equivCondImag(0, 0)),
77 Complex(equivCondReal(0, 1), equivCondImag(0, 1)),
78 Complex(equivCondReal(0, 2), equivCondImag(0, 2)),
79 Complex(equivCondReal(1, 0), equivCondImag(1, 0)),
80 Complex(equivCondReal(1, 1), equivCondImag(1, 1)),
81 Complex(equivCondReal(1, 2), equivCondImag(1, 2)),
82 Complex(equivCondReal(2, 0), equivCondImag(2, 0)),
83 Complex(equivCondReal(2, 1), equivCondImag(2, 1)),
84 Complex(equivCondReal(2, 2), equivCondImag(2, 2));
90 Matrix mPrevVoltCoeffReal = equivCondReal;
91 Matrix mPrevVoltCoeffImag = -b * equivCondReal;
93 mPrevVoltCoeff = Matrix::Zero(3, 3);
94 mPrevVoltCoeff << Complex(mPrevVoltCoeffReal(0, 0), mPrevVoltCoeffImag(0, 0)),
95 Complex(mPrevVoltCoeffReal(0, 1), mPrevVoltCoeffImag(0, 1)),
96 Complex(mPrevVoltCoeffReal(0, 2), mPrevVoltCoeffImag(0, 2)),
97 Complex(mPrevVoltCoeffReal(1, 0), mPrevVoltCoeffImag(1, 0)),
98 Complex(mPrevVoltCoeffReal(1, 1), mPrevVoltCoeffImag(1, 1)),
99 Complex(mPrevVoltCoeffReal(1, 2), mPrevVoltCoeffImag(1, 2)),
100 Complex(mPrevVoltCoeffReal(2, 0), mPrevVoltCoeffImag(2, 0)),
101 Complex(mPrevVoltCoeffReal(2, 1), mPrevVoltCoeffImag(2, 1)),
102 Complex(mPrevVoltCoeffReal(2, 2), mPrevVoltCoeffImag(2, 2));
104 mEquivCurrent = -mPrevVoltCoeff * **mIntfVoltage - **mIntfCurrent;
109 updateMatrixNodeIndices();
110 initVars(omega, timeStep);
140 SparseMatrixRow &systemMatrix) {
141 MNAStampUtils::stampAdmittanceMatrix(
142 mEquivCond, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1),
143 terminalNotGrounded(0), terminalNotGrounded(1), mSLog);
150 mEquivCurrent = -**mIntfCurrent + -mPrevVoltCoeff * **mIntfVoltage;
152 if (terminalNotGrounded(0)) {
153 Math::setVectorElement(rightVector, matrixNodeIndex(0, 0),
154 mEquivCurrent(0, 0));
155 Math::setVectorElement(rightVector, matrixNodeIndex(0, 1),
156 mEquivCurrent(1, 0));
157 Math::setVectorElement(rightVector, matrixNodeIndex(0, 2),
158 mEquivCurrent(2, 0));
160 if (terminalNotGrounded(1)) {
161 Math::setVectorElement(rightVector, matrixNodeIndex(1, 0),
162 -mEquivCurrent(0, 0));
163 Math::setVectorElement(rightVector, matrixNodeIndex(1, 1),
164 -mEquivCurrent(1, 0));
165 Math::setVectorElement(rightVector, matrixNodeIndex(1, 2),
166 -mEquivCurrent(2, 0));
171 AttributeBase::List &prevStepDependencies,
172 AttributeBase::List &attributeDependencies,
173 AttributeBase::List &modifiedAttributes) {
175 modifiedAttributes.push_back(mRightVector);
176 prevStepDependencies.push_back(mIntfCurrent);
177 prevStepDependencies.push_back(mIntfVoltage);
180 void DP::Ph3::Capacitor::mnaCompPreStep(Real time, Int timeStepCount) {
181 mnaCompApplyRightSideVectorStamp(**mRightVector);
185 AttributeBase::List &prevStepDependencies,
186 AttributeBase::List &attributeDependencies,
187 AttributeBase::List &modifiedAttributes,
189 attributeDependencies.push_back(leftVector);
190 modifiedAttributes.push_back(mIntfVoltage);
191 modifiedAttributes.push_back(mIntfCurrent);
194 void DP::Ph3::Capacitor::mnaCompPostStep(Real time, Int timeStepCount,
196 mnaCompUpdateVoltage(**leftVector);
197 mnaCompUpdateCurrent(**leftVector);
202 **mIntfVoltage = Matrix::Zero(3, 1);
203 if (terminalNotGrounded(1)) {
204 (**mIntfVoltage)(0, 0) =
205 Math::complexFromVectorElement(leftVector, matrixNodeIndex(1, 0));
206 (**mIntfVoltage)(1, 0) =
207 Math::complexFromVectorElement(leftVector, matrixNodeIndex(1, 1));
208 (**mIntfVoltage)(2, 0) =
209 Math::complexFromVectorElement(leftVector, matrixNodeIndex(1, 2));
211 if (terminalNotGrounded(0)) {
212 (**mIntfVoltage)(0, 0) =
213 (**mIntfVoltage)(0, 0) -
214 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0, 0));
215 (**mIntfVoltage)(1, 0) =
216 (**mIntfVoltage)(1, 0) -
217 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0, 1));
218 (**mIntfVoltage)(2, 0) =
219 (**mIntfVoltage)(2, 0) -
220 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0, 2));
225 **mIntfCurrent = mEquivCond * **mIntfVoltage + mEquivCurrent;
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
Capacitor(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
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 mnaCompUpdateCurrent(const Matrix &leftVector) override
Update interface current from MNA system result.
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 mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
Stamps right side (source) vector.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
void initVars(Real omega, Real timeStep)
init resistive companion model of capacitor
MatrixComp mEquivCurrent
DC equivalent current source [A].
Base class for all MNA components that are transmitting power.
Base class for all components that are transmitting power.
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
Current through component.
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
Voltage between terminals.