9 #include <dpsim-models/DP/DP_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,
39 "\n--- Initialization from powerflow ---"
40 "\nVoltage across amplitude and phase: \n{:s}"
41 "\nCurrent amplitude and phase: \n{:s}"
42 "\nTerminal 0 voltage amplitude and phase: \n{:s}"
43 "\nTerminal 1 voltage amplitude and phase: \n{:s}"
44 "\n--- Initialization from powerflow finished ---",
45 Logger::phasorMatrixToString(**mIntfVoltage),
46 Logger::phasorMatrixToString(**mIntfCurrent),
47 Logger::phasorMatrixToString(initialVoltage(0)),
48 Logger::phasorMatrixToString(initialVoltage(1)));
51 void DP::Ph3::Resistor::mnaCompInitialize(Real omega, Real timeStep,
53 updateMatrixNodeIndices();
54 **mRightVector = Matrix::Zero(0, 0);
58 SparseMatrixRow &systemMatrix) {
59 MatrixFixedSizeComp<3, 3> conductance = Matrix::Zero(3, 3);
60 conductance.real() = (**mResistance).inverse();
62 MNAStampUtils::stampAdmittanceMatrix(
63 conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1),
64 terminalNotGrounded(0), terminalNotGrounded(1), mSLog);
68 AttributeBase::List &prevStepDependencies,
69 AttributeBase::List &attributeDependencies,
70 AttributeBase::List &modifiedAttributes,
72 attributeDependencies.push_back(leftVector);
73 modifiedAttributes.push_back(mIntfVoltage);
74 modifiedAttributes.push_back(mIntfCurrent);
77 void DP::Ph3::Resistor::mnaCompPostStep(Real time, Int timeStepCount,
79 mnaCompUpdateVoltage(**leftVector);
80 mnaCompUpdateCurrent(**leftVector);
83 void DP::Ph3::Resistor::mnaCompUpdateVoltage(
const Matrix &leftVector) {
85 **mIntfVoltage = MatrixComp::Zero(3, 1);
86 if (terminalNotGrounded(1)) {
87 (**mIntfVoltage)(0, 0) =
88 Math::complexFromVectorElement(leftVector, matrixNodeIndex(1, 0));
89 (**mIntfVoltage)(1, 0) =
90 Math::complexFromVectorElement(leftVector, matrixNodeIndex(1, 1));
91 (**mIntfVoltage)(2, 0) =
92 Math::complexFromVectorElement(leftVector, matrixNodeIndex(1, 2));
94 if (terminalNotGrounded(0)) {
95 (**mIntfVoltage)(0, 0) =
96 (**mIntfVoltage)(0, 0) -
97 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0, 0));
98 (**mIntfVoltage)(1, 0) =
99 (**mIntfVoltage)(1, 0) -
100 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0, 1));
101 (**mIntfVoltage)(2, 0) =
102 (**mIntfVoltage)(2, 0) -
103 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0, 2));
106 SPDLOG_LOGGER_DEBUG(mSLog,
"Voltage A: {} < {}",
107 std::abs((**mIntfVoltage)(0, 0)),
108 std::arg((**mIntfVoltage)(0, 0)));
111 void DP::Ph3::Resistor::mnaCompUpdateCurrent(
const Matrix &leftVector) {
112 **mIntfCurrent = (**mResistance).inverse() * **mIntfVoltage;
114 SPDLOG_LOGGER_DEBUG(mSLog,
"Current A: {} < {}",
115 std::abs((**mIntfCurrent)(0, 0)),
116 std::arg((**mIntfCurrent)(0, 0)));
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 initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
Resistor(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
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.