9 #include <dpsim-models/EMT/EMT_Ph3_Capacitor.h>
16 mPhaseType = PhaseType::ABC;
24 auto copy = Capacitor::make(name, mLogLevel);
25 copy->setParameters(**mCapacitance);
30 Real omega = 2 * PI * frequency;
31 MatrixComp admittance = MatrixComp::Zero(3, 3);
32 admittance << Complex(0, omega * (**mCapacitance)(0, 0)),
33 Complex(0, omega * (**mCapacitance)(0, 1)),
34 Complex(0, omega * (**mCapacitance)(0, 2)),
35 Complex(0, omega * (**mCapacitance)(1, 0)),
36 Complex(0, omega * (**mCapacitance)(1, 1)),
37 Complex(0, omega * (**mCapacitance)(1, 2)),
38 Complex(0, omega * (**mCapacitance)(2, 0)),
39 Complex(0, omega * (**mCapacitance)(2, 1)),
40 Complex(0, omega * (**mCapacitance)(2, 2));
42 MatrixComp vInitABC = Matrix::Zero(3, 1);
43 vInitABC(0, 0) = RMS3PH_TO_PEAK1PH * initialSingleVoltage(1) -
44 RMS3PH_TO_PEAK1PH * initialSingleVoltage(0);
45 vInitABC(1, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_B;
46 vInitABC(2, 0) = vInitABC(0, 0) * SHIFT_TO_PHASE_C;
47 **mIntfVoltage = vInitABC.real();
48 **mIntfCurrent = (admittance * vInitABC).real();
50 SPDLOG_LOGGER_INFO(mSLog,
51 "\nCapacitance [F]: {:s}"
52 "\nAdmittance [S]: {:s}",
53 Logger::matrixToString(**mCapacitance),
54 Logger::matrixCompToString(admittance));
57 "\n--- Initialization from powerflow ---"
58 "\nVoltage across: {:s}"
60 "\nTerminal 0 voltage: {:s}"
61 "\nTerminal 1 voltage: {:s}"
62 "\n--- Initialization from powerflow finished ---",
63 Logger::matrixToString(**mIntfVoltage),
64 Logger::matrixToString(**mIntfCurrent),
65 Logger::phasorToString(RMS3PH_TO_PEAK1PH * initialSingleVoltage(0)),
66 Logger::phasorToString(RMS3PH_TO_PEAK1PH * initialSingleVoltage(1)));
71 updateMatrixNodeIndices();
72 mEquivCond = (2.0 * **mCapacitance) / timeStep;
74 mEquivCurrent = -**mIntfCurrent + -mEquivCond * **mIntfVoltage;
78 SparseMatrixRow &systemMatrix) {
79 MNAStampUtils::stampConductanceMatrix(
80 mEquivCond, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1),
81 terminalNotGrounded(0), terminalNotGrounded(1), mSLog);
83 SPDLOG_LOGGER_INFO(mSLog,
"\nEquivalent Conductance: {:s}",
84 Logger::matrixToString(mEquivCond));
88 Matrix &rightVector) {
89 mEquivCurrent = -**mIntfCurrent + -mEquivCond * **mIntfVoltage;
90 if (terminalNotGrounded(0)) {
91 Math::setVectorElement(rightVector, matrixNodeIndex(0, 0),
93 Math::setVectorElement(rightVector, matrixNodeIndex(0, 1),
95 Math::setVectorElement(rightVector, matrixNodeIndex(0, 2),
98 if (terminalNotGrounded(1)) {
99 Math::setVectorElement(rightVector, matrixNodeIndex(1, 0),
100 -mEquivCurrent(0, 0));
101 Math::setVectorElement(rightVector, matrixNodeIndex(1, 1),
102 -mEquivCurrent(1, 0));
103 Math::setVectorElement(rightVector, matrixNodeIndex(1, 2),
104 -mEquivCurrent(2, 0));
106 SPDLOG_LOGGER_DEBUG(mSLog,
"\nEquivalent Current: {:s}",
107 Logger::matrixToString(mEquivCurrent));
111 AttributeBase::List &prevStepDependencies,
112 AttributeBase::List &attributeDependencies,
113 AttributeBase::List &modifiedAttributes) {
115 prevStepDependencies.push_back(mIntfCurrent);
116 prevStepDependencies.push_back(mIntfVoltage);
117 modifiedAttributes.push_back(mRightVector);
121 mnaCompApplyRightSideVectorStamp(**mRightVector);
125 AttributeBase::List &prevStepDependencies,
126 AttributeBase::List &attributeDependencies,
127 AttributeBase::List &modifiedAttributes,
129 attributeDependencies.push_back(leftVector);
130 modifiedAttributes.push_back(mIntfVoltage);
131 modifiedAttributes.push_back(mIntfCurrent);
136 mnaCompUpdateVoltage(**leftVector);
137 mnaCompUpdateCurrent(**leftVector);
142 **mIntfVoltage = Matrix::Zero(3, 1);
143 if (terminalNotGrounded(1)) {
144 (**mIntfVoltage)(0, 0) =
145 Math::realFromVectorElement(leftVector, matrixNodeIndex(1, 0));
146 (**mIntfVoltage)(1, 0) =
147 Math::realFromVectorElement(leftVector, matrixNodeIndex(1, 1));
148 (**mIntfVoltage)(2, 0) =
149 Math::realFromVectorElement(leftVector, matrixNodeIndex(1, 2));
151 if (terminalNotGrounded(0)) {
152 (**mIntfVoltage)(0, 0) =
153 (**mIntfVoltage)(0, 0) -
154 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 0));
155 (**mIntfVoltage)(1, 0) =
156 (**mIntfVoltage)(1, 0) -
157 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 1));
158 (**mIntfVoltage)(2, 0) =
159 (**mIntfVoltage)(2, 0) -
160 Math::realFromVectorElement(leftVector, matrixNodeIndex(0, 2));
165 **mIntfCurrent = mEquivCond * **mIntfVoltage + mEquivCurrent;
166 SPDLOG_LOGGER_DEBUG(mSLog,
"\nCurrent: {:s}",
167 Logger::matrixToString(**mIntfCurrent));
Capacitor(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
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.
void mnaCompPreStep(Real time, Int timeStepCount) override
MNA pre step operations.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Update interface current from MNA system result.
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
Initializes internal variables of the component.
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 mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
MNA post step operations.
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
Stamps right side (source) vector.
Matrix 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< Real > >::Ptr mIntfCurrent
Current through component.
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
Voltage between terminals.