8 #include <dpsim-models/DP/DP_Ph3_SeriesResistor.h>
13 Logger::Level logLevel)
16 mPhaseType = PhaseType::ABC;
23 auto copy = SeriesResistor::make(name, mLogLevel);
24 copy->setParameters(**mResistance);
30 mTerminals[0]->setPhaseType(PhaseType::ABC);
31 mTerminals[1]->setPhaseType(PhaseType::ABC);
33 Matrix impedance = Matrix::Zero(3, 1);
34 impedance << **mResistance, **mResistance, **mResistance;
35 (**mIntfVoltage)(0, 0) = initialSingleVoltage(1) - initialSingleVoltage(0);
37 Real voltMag = Math::abs((**mIntfVoltage)(0, 0));
38 Real voltPhase = Math::phase((**mIntfVoltage)(0, 0));
39 (**mIntfVoltage)(1, 0) = Complex(voltMag * cos(voltPhase - 2. / 3. * PI),
40 voltMag * sin(voltPhase - 2. / 3. * PI));
41 (**mIntfVoltage)(2, 0) = Complex(voltMag * cos(voltPhase + 2. / 3. * PI),
42 voltMag * sin(voltPhase + 2. / 3. * PI));
44 **mIntfCurrent = impedance.cwiseInverse().cwiseProduct(**mIntfVoltage);
46 SPDLOG_LOGGER_INFO(mSLog,
47 "\n--- Initialization from powerflow ---"
48 "\nVoltage across amplitude and phase: \n{:s}"
49 "\nCurrent amplitude and phase: \n{:s}"
50 "\nTerminal 0 voltage amplitude and phase: \n{:s}"
51 "\nTerminal 1 voltage amplitude and phase: \n{:s}"
52 "\n--- Initialization from powerflow finished ---",
53 Logger::phasorMatrixToString(**mIntfVoltage),
54 Logger::phasorMatrixToString(**mIntfCurrent),
55 Logger::phasorMatrixToString(initialVoltage(0)),
56 Logger::phasorMatrixToString(initialVoltage(1)));
59 void DP::Ph3::SeriesResistor::mnaCompInitialize(
61 updateMatrixNodeIndices();
62 **mRightVector = Matrix::Zero(0, 0);
66 SparseMatrixRow &systemMatrix) {
67 Complex conductance = {(1. / **mResistance), 0};
80 if (terminalNotGrounded(0)) {
81 Math::addToMatrixElement(systemMatrix, matrixNodeIndices(0),
82 matrixNodeIndices(0), conductance);
84 if (terminalNotGrounded(1)) {
85 Math::addToMatrixElement(systemMatrix, matrixNodeIndices(1),
86 matrixNodeIndices(1), conductance);
89 if (terminalNotGrounded(0) && terminalNotGrounded(1)) {
90 Math::addToMatrixElement(systemMatrix, matrixNodeIndices(0),
91 matrixNodeIndices(1), -conductance);
92 Math::addToMatrixElement(systemMatrix, matrixNodeIndices(1),
93 matrixNodeIndices(0), -conductance);
96 if (terminalNotGrounded(0))
97 SPDLOG_LOGGER_INFO(mSLog,
"Add {} to {}, {}", conductance,
98 matrixNodeIndex(0, 0), matrixNodeIndex(0, 0));
99 if (terminalNotGrounded(1))
100 SPDLOG_LOGGER_INFO(mSLog,
"Add {} to {}, {}", conductance,
101 matrixNodeIndex(1, 0), matrixNodeIndex(1, 0));
102 if (terminalNotGrounded(0) && terminalNotGrounded(1)) {
103 SPDLOG_LOGGER_INFO(mSLog,
"Add {} to {}, {}", -conductance,
104 matrixNodeIndex(0, 0), matrixNodeIndex(1, 0));
105 SPDLOG_LOGGER_INFO(mSLog,
"Add {} to {}, {}", -conductance,
106 matrixNodeIndex(1, 0), matrixNodeIndex(0, 0));
111 AttributeBase::List &prevStepDependencies,
112 AttributeBase::List &attributeDependencies,
113 AttributeBase::List &modifiedAttributes,
115 attributeDependencies.push_back(leftVector);
116 modifiedAttributes.push_back(mIntfVoltage);
117 modifiedAttributes.push_back(mIntfCurrent);
120 void DP::Ph3::SeriesResistor::mnaCompPostStep(
122 mnaCompUpdateVoltage(**leftVector);
123 mnaCompUpdateCurrent(**leftVector);
126 void DP::Ph3::SeriesResistor::mnaCompUpdateVoltage(
const Matrix &leftVector) {
128 **mIntfVoltage = MatrixComp::Zero(3, 1);
129 if (terminalNotGrounded(1)) {
130 (**mIntfVoltage)(0, 0) =
131 Math::complexFromVectorElement(leftVector, matrixNodeIndex(1, 0));
132 (**mIntfVoltage)(1, 0) =
133 Math::complexFromVectorElement(leftVector, matrixNodeIndex(1, 1));
134 (**mIntfVoltage)(2, 0) =
135 Math::complexFromVectorElement(leftVector, matrixNodeIndex(1, 2));
137 if (terminalNotGrounded(0)) {
138 (**mIntfVoltage)(0, 0) =
139 (**mIntfVoltage)(0, 0) -
140 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0, 0));
141 (**mIntfVoltage)(1, 0) =
142 (**mIntfVoltage)(1, 0) -
143 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0, 1));
144 (**mIntfVoltage)(2, 0) =
145 (**mIntfVoltage)(2, 0) -
146 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0, 2));
149 SPDLOG_LOGGER_DEBUG(mSLog,
"Voltage A: {} < {}",
150 std::abs((**mIntfVoltage)(0, 0)),
151 std::arg((**mIntfVoltage)(0, 0)));
154 void DP::Ph3::SeriesResistor::mnaCompUpdateCurrent(
const Matrix &leftVector) {
155 **mIntfCurrent = **mIntfVoltage / **mResistance;
157 SPDLOG_LOGGER_DEBUG(mSLog,
"Current A: {} < {}",
158 std::abs((**mIntfCurrent)(0, 0)),
159 std::arg((**mIntfCurrent)(0, 0)));
SeriesResistor(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
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.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
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.