9 #include <dpsim-models/DP/DP_Ph1_Resistor.h>
22 auto copy = Resistor::make(name, mLogLevel);
23 copy->setParameters(**mResistance);
29 Complex impedance = {**mResistance, 0};
30 (**mIntfVoltage)(0, 0) = initialSingleVoltage(1) - initialSingleVoltage(0);
31 (**mIntfCurrent)(0, 0) = (**mIntfVoltage)(0, 0) / impedance;
33 SPDLOG_LOGGER_INFO(mSLog,
34 "\nResistance [Ohm]: {:s}"
35 "\nImpedance [Ohm]: {:s}",
36 Logger::realToString(**mResistance),
37 Logger::complexToString(impedance));
38 SPDLOG_LOGGER_INFO(mSLog,
39 "\n--- Initialization from powerflow ---"
40 "\nVoltage across: {:s}"
42 "\nTerminal 0 voltage: {:s}"
43 "\nTerminal 1 voltage: {:s}"
44 "\n--- Initialization from powerflow finished ---",
45 Logger::phasorToString((**mIntfVoltage)(0, 0)),
46 Logger::phasorToString((**mIntfCurrent)(0, 0)),
47 Logger::phasorToString(initialSingleVoltage(0)),
48 Logger::phasorToString(initialSingleVoltage(1)));
52 void DP::Ph1::Resistor::mnaCompInitialize(Real omega, Real timeStep,
54 updateMatrixNodeIndices();
56 **mRightVector = Matrix::Zero(0, 0);
58 SPDLOG_LOGGER_INFO(mSLog,
59 "\n--- MNA initialization ---"
60 "\nInitial voltage {:s}"
61 "\nInitial current {:s}"
62 "\n--- MNA initialization finished ---",
63 Logger::phasorToString((**mIntfVoltage)(0, 0)),
64 Logger::phasorToString((**mIntfCurrent)(0, 0)));
67 void DP::Ph1::Resistor::mnaCompInitializeHarm(
68 Real omega, Real timeStep,
70 updateMatrixNodeIndices();
72 mMnaTasks.push_back(std::make_shared<MnaPostStepHarm>(*
this, leftVectors));
76 SparseMatrixRow &systemMatrix) {
77 Complex conductance = Complex(1. / **mResistance, 0);
79 for (UInt freq = 0; freq < mNumFreqs; freq++) {
80 MNAStampUtils::stampAdmittance(
81 conductance, systemMatrix, matrixNodeIndex(0), matrixNodeIndex(1),
82 terminalNotGrounded(0), terminalNotGrounded(1), mSLog, mNumFreqs, freq);
87 SparseMatrixRow &systemMatrix, Int freqIdx) {
88 Complex conductance = Complex(1. / **mResistance, 0);
90 MNAStampUtils::stampAdmittance(conductance, systemMatrix, matrixNodeIndex(0),
91 matrixNodeIndex(1), terminalNotGrounded(0),
92 terminalNotGrounded(1), mSLog);
96 AttributeBase::List &prevStepDependencies,
97 AttributeBase::List &attributeDependencies,
98 AttributeBase::List &modifiedAttributes,
100 attributeDependencies.push_back(leftVector);
101 modifiedAttributes.push_back(this->mIntfVoltage);
102 modifiedAttributes.push_back(this->mIntfCurrent);
107 this->mnaUpdateVoltage(**leftVector);
108 this->mnaUpdateCurrent(**leftVector);
111 void DP::Ph1::Resistor::MnaPostStepHarm::execute(Real time, Int timeStepCount) {
112 for (UInt freq = 0; freq < mResistor.mNumFreqs; freq++)
113 mResistor.mnaCompUpdateVoltageHarm(**mLeftVectors[freq], freq);
114 mResistor.mnaCompUpdateCurrentHarm();
119 for (UInt freq = 0; freq < mNumFreqs; freq++) {
120 (**mIntfVoltage)(0, freq) = 0;
121 if (terminalNotGrounded(1))
122 (**mIntfVoltage)(0, freq) = Math::complexFromVectorElement(
123 leftVector, matrixNodeIndex(1), mNumFreqs, freq);
124 if (terminalNotGrounded(0))
125 (**mIntfVoltage)(0, freq) =
126 (**mIntfVoltage)(0, freq) -
127 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0),
130 SPDLOG_LOGGER_DEBUG(mSLog,
"Voltage {:s}",
131 Logger::phasorToString((**mIntfVoltage)(0, freq)));
136 for (UInt freq = 0; freq < mNumFreqs; freq++) {
137 (**mIntfCurrent)(0, freq) = (**mIntfVoltage)(0, freq) / **mResistance;
138 SPDLOG_LOGGER_DEBUG(mSLog,
"Current {:s}",
139 Logger::phasorToString((**mIntfCurrent)(0, freq)));
143 void DP::Ph1::Resistor::mnaCompUpdateVoltageHarm(
const Matrix &leftVector,
146 (**mIntfVoltage)(0, freqIdx) = 0;
147 if (terminalNotGrounded(1))
148 (**mIntfVoltage)(0, freqIdx) =
149 Math::complexFromVectorElement(leftVector, matrixNodeIndex(1));
150 if (terminalNotGrounded(0))
151 (**mIntfVoltage)(0, freqIdx) =
152 (**mIntfVoltage)(0, freqIdx) -
153 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0));
155 SPDLOG_LOGGER_DEBUG(mSLog,
"Voltage {:s}",
156 Logger::phasorToString((**mIntfVoltage)(0, freqIdx)));
159 void DP::Ph1::Resistor::mnaCompUpdateCurrentHarm() {
160 for (UInt freq = 0; freq < mNumFreqs; freq++) {
161 (**mIntfCurrent)(0, freq) = (**mIntfVoltage)(0, freq) / **mResistance;
162 SPDLOG_LOGGER_DEBUG(mSLog,
"Current {:s}",
163 Logger::phasorToString((**mIntfCurrent)(0, freq)));
167 void DP::Ph1::Resistor::mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix) {
168 Math::addToMatrixElement(tearMatrix, mTearIdx, mTearIdx,
169 Complex(**mResistance, 0));
175 const double dstate_dt[],
double resid[],
176 std::vector<int> &off) {
192 int Pos1 = matrixNodeIndex(0);
193 int Pos2 = matrixNodeIndex(1);
194 int c_offset = off[0] + off[1];
199 resid[c_offset] = (state[Pos2] - state[Pos1]) -
202 resid[n_offset_1] += 1.0 / **mResistance * state[c_offset];
203 resid[n_offset_2] += 1.0 / **mResistance * state[c_offset];
Dynamic phasor resistor model.
Complex daeInitialize()
Voltage Getter.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector)
add MNA pre and post step dependencies
void mnaCompApplySystemMatrixStampHarm(SparseMatrixRow &systemMatrix, Int freqIdx)
Stamps system matrix considering the frequency index.
Resistor(String uid, String name, Logger::Level loglevel=Logger::Level::off)
Defines UID, name and logging level.
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector)
MNA pre and post step operations.
void daeResidual(double ttime, const double state[], const double dstate_dt[], double resid[], std::vector< int > &off)
Residual Function for DAE Solver.
void mnaCompUpdateCurrent(const Matrix &leftVector)
Update interface current from MNA system result.
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix)
Stamps system matrix.
SimPowerComp< Complex >::Ptr clone(String name)
Returns a modified copy of the component with the given suffix added to the name and without.
void mnaCompUpdateVoltage(const Matrix &leftVector)
Update interface voltage from MNA system result.
void initializeFromNodesAndTerminals(Real frequency)
Initializes component from power flow data.
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.