9#include <dpsim-models/DP/DP_Ph1_Resistor.h>
22 auto copy = Resistor::make(name,
mLogLevel);
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}",
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 ---",
47 Logger::phasorToString(initialSingleVoltage(0)),
48 Logger::phasorToString(initialSingleVoltage(1)));
52void DP::Ph1::Resistor::mnaCompInitialize(Real omega, Real timeStep,
53 Attribute<Matrix>::Ptr leftVector) {
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)));
67void DP::Ph1::Resistor::mnaCompInitializeHarm(
68 Real omega, Real timeStep,
69 std::vector<Attribute<Matrix>::Ptr> leftVectors) {
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,
99 Attribute<Matrix>::Ptr &leftVector) {
100 attributeDependencies.push_back(leftVector);
106 Attribute<Matrix>::Ptr &leftVector) {
111void 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) =
127 Math::complexFromVectorElement(leftVector, matrixNodeIndex(0),
130 SPDLOG_LOGGER_DEBUG(
mSLog,
"Voltage {:s}",
136 for (UInt freq = 0; freq <
mNumFreqs; freq++) {
138 SPDLOG_LOGGER_DEBUG(
mSLog,
"Current {:s}",
143void 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)));
159void 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)));
167void 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) {
177 int Pos1 = matrixNodeIndex(0);
178 int Pos2 = matrixNodeIndex(1);
179 int c_offset = off[0] + off[1];
184 resid[c_offset] = (state[Pos2] - state[Pos1]) -
186 resid[n_offset_1] += 1.0 / **
mResistance * state[c_offset];
187 resid[n_offset_2] += 1.0 / **
mResistance * state[c_offset];
const CPS::Attribute< Real >::Ptr mResistance
Resistance [ohm].
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.
String uid()
Returns unique id.
AttributeList::Ptr mAttributes
Attribute List.
void mnaUpdateCurrent(const Matrix &leftVector) final
void mnaUpdateVoltage(const Matrix &leftVector) final
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
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.