9 #include <dpsim-models/SP/SP_Ph3_Resistor.h>
16 mPhaseType = PhaseType::ABC;
23 auto copy = Resistor::make(name, mLogLevel);
24 copy->setParameters(**mResistance);
30 Real voltMag = Math::abs((**mIntfVoltage)(0, 0));
31 Real voltPhase = Math::phase((**mIntfVoltage)(0, 0));
32 (**mIntfVoltage)(1, 0) = Complex(voltMag * cos(voltPhase - 2. / 3. * M_PI),
33 voltMag * sin(voltPhase - 2. / 3. * M_PI));
34 (**mIntfVoltage)(2, 0) = Complex(voltMag * cos(voltPhase + 2. / 3. * M_PI),
35 voltMag * sin(voltPhase + 2. / 3. * M_PI));
36 **mIntfCurrent = (**mResistance).inverse() * **mIntfVoltage;
38 SPDLOG_LOGGER_INFO(mSLog,
"Node 1 : {}",
39 Logger::phasorToString(initialVoltage(0)(0, 0)));
40 SPDLOG_LOGGER_INFO(mSLog,
"Node 2 : {}",
41 Logger::phasorToString(initialVoltage(1)(0, 0)));
42 SPDLOG_LOGGER_INFO(mSLog,
"initialize {} {} voltage to {} and current to {}",
43 this->type(), this->name(),
44 Logger::phasorToString((**mIntfVoltage)(0, 0)),
45 Logger::phasorToString((**mIntfCurrent)(0, 0)));
48 void SP::Ph3::Resistor::mnaCompInitialize(Real omega, Real timeStep,
50 updateMatrixNodeIndices();
51 **mRightVector = Matrix::Zero(0, 0);
55 SparseMatrixRow &systemMatrix) {
56 MatrixFixedSizeComp<3, 3> conductance = Matrix::Zero(3, 3);
57 conductance.real() = (**mResistance).inverse();
59 MNAStampUtils::stampAdmittanceMatrix(
60 conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1),
61 terminalNotGrounded(0), terminalNotGrounded(1), mSLog);
65 AttributeBase::List &prevStepDependencies,
66 AttributeBase::List &attributeDependencies,
67 AttributeBase::List &modifiedAttributes,
69 attributeDependencies.push_back(leftVector);
70 modifiedAttributes.push_back(mIntfVoltage);
71 modifiedAttributes.push_back(mIntfCurrent);
74 void SP::Ph3::Resistor::mnaCompPostStep(Real time, Int timeStepCount,
76 mnaCompUpdateVoltage(**leftVector);
77 mnaCompUpdateCurrent(**leftVector);
80 void SP::Ph3::Resistor::mnaCompUpdateVoltage(
const Matrix &leftVector) {
82 **mIntfVoltage = MatrixComp::Zero(3, 1);
83 if (terminalNotGrounded(1)) {
84 (**mIntfVoltage)(0, 0) =
85 Math::complexFromVectorElement(leftVector, matrixNodeIndex(1, 0));
86 (**mIntfVoltage)(1, 0) =
87 Math::complexFromVectorElement(leftVector, matrixNodeIndex(1, 1));
88 (**mIntfVoltage)(2, 0) =
89 Math::complexFromVectorElement(leftVector, matrixNodeIndex(1, 2));
91 if (terminalNotGrounded(0)) {
92 (**mIntfVoltage)(0, 0) =
93 (**mIntfVoltage)(0, 0) -
94 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0, 0));
95 (**mIntfVoltage)(1, 0) =
96 (**mIntfVoltage)(1, 0) -
97 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0, 1));
98 (**mIntfVoltage)(2, 0) =
99 (**mIntfVoltage)(2, 0) -
100 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0, 2));
107 void SP::Ph3::Resistor::mnaCompUpdateCurrent(
const Matrix &leftVector) {
108 **mIntfCurrent = (**mResistance).inverse() * **mIntfVoltage;
113 void SP::Ph3::Resistor::mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix) {
115 Math::addToMatrixElement(tearMatrix, mTearIdx, mTearIdx,
116 Complex((**mResistance)(0, 0), 0));
117 Math::addToMatrixElement(tearMatrix, mTearIdx, mTearIdx,
118 Complex((**mResistance)(1, 1), 0));
119 Math::addToMatrixElement(tearMatrix, mTearIdx, mTearIdx,
120 Complex((**mResistance)(2, 2), 0));
Base class for all MNA components that are transmitting power.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
SimPowerComp< Complex >::Ptr clone(String name) override
Returns a modified copy of the component with the given suffix added to the name and without.
Resistor(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
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.