9#include <dpsim-models/SP/SP_Ph3_Resistor.h>
16 mPhaseType = PhaseType::ABC;
23 auto copy = Resistor::make(name,
mLogLevel);
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));
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(),
48void SP::Ph3::Resistor::mnaCompInitialize(Real omega, Real timeStep,
49 Attribute<Matrix>::Ptr leftVector) {
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,
68 Attribute<Matrix>::Ptr &leftVector) {
69 attributeDependencies.push_back(leftVector);
74void SP::Ph3::Resistor::mnaCompPostStep(Real time, Int timeStepCount,
75 Attribute<Matrix>::Ptr &leftVector) {
76 mnaCompUpdateVoltage(**leftVector);
77 mnaCompUpdateCurrent(**leftVector);
80void 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));
107void SP::Ph3::Resistor::mnaCompUpdateCurrent(
const Matrix &leftVector) {
108 **mIntfCurrent = (**mResistance).inverse() * **mIntfVoltage;
113void 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));
const CPS::Attribute< Matrix >::Ptr mResistance
Resistance [ohm].
String uid()
Returns unique id.
String type()
Get component type (cross-platform)
AttributeList::Ptr mAttributes
Attribute List.
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
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.
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
Logger::Level mLogLevel
Component logger control for internal variables.
Logger::Log mSLog
Component logger.