47 Real omega = 2. *
PI * frequency;
50 (**mIntfCurrent)(0, 0) = (**
mIntfVoltage)(0, 0) / impedance;
52 SPDLOG_LOGGER_INFO(
mSLog,
53 "\n--- Initialization from powerflow ---"
54 "\nVoltage across: {:s}"
56 "\nTerminal 0 voltage: {:s}"
57 "\nTerminal 1 voltage: {:s}"
58 "\n--- Initialization from powerflow finished ---",
67void DP::Ph1::ResIndSeries::initVars(
Real timeStep) {
68 for (
Int freq = 0; freq < mNumFreqs; freq++) {
69 Real a = timeStep / (2. * **mInductance);
70 Real b = timeStep * 2. *
PI * mFrequencies(freq, 0) / 2.;
72 Real equivCondReal = a / (1. + b * b);
73 Real equivCondImag = -a * b / (1. + b * b);
74 mEquivCond(freq, 0) = {equivCondReal, equivCondImag};
75 Real preCurrFracReal = (1. - b * b) / (1. + b * b);
76 Real preCurrFracImag = (-2. * b) / (1. + b * b);
77 mPrevCurrFac(freq, 0) = {preCurrFracReal, preCurrFracImag};
80 mEquivCurrent(freq, 0) = mEquivCond(freq, 0) * (**mIntfVoltage)(0, freq) +
81 mPrevCurrFac(freq, 0) * (**mIntfCurrent)(0, freq);
82 (**mIntfCurrent)(0, freq) =
83 mEquivCond(freq, 0) * (**mIntfVoltage)(0, freq) +
84 mEquivCurrent(freq, 0);
93 SPDLOG_LOGGER_INFO(
mSLog,
94 "\n--- MNA initialization ---"
95 "\nInitial voltage {:s}"
96 "\nInitial current {:s}"
97 "\nEquiv. current {:s}"
98 "\n--- MNA initialization finished ---",
107 updateMatrixNodeIndices();
111 mMnaTasks.push_back(std::make_shared<MnaPreStepHarm>(*
this));
112 mMnaTasks.push_back(std::make_shared<MnaPostStepHarm>(*
this, leftVectors));
113 **mRightVector = Matrix::Zero(leftVectors[0]->get().rows(), mNumFreqs);
136 SPDLOG_LOGGER_INFO(
mSLog,
"-- Stamp frequency {:d} ---", freq);
138 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
142 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
146 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
149 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:s} to system at ({:d},{:d})",
158 if (terminalNotGrounded(0))
160 matrixNodeIndex(0), mEquivCond(freqIdx, 0));
161 if (terminalNotGrounded(1))
163 matrixNodeIndex(1), mEquivCond(freqIdx, 0));
164 if (terminalNotGrounded(0) && terminalNotGrounded(1)) {
166 matrixNodeIndex(1), -mEquivCond(freqIdx, 0));
168 matrixNodeIndex(0), -mEquivCond(freqIdx, 0));
171 SPDLOG_LOGGER_INFO(mSLog,
"-- Stamp frequency {:d} ---", freqIdx);
172 if (terminalNotGrounded(0))
173 SPDLOG_LOGGER_INFO(mSLog,
"Add {:f}+j{:f} to system at ({:d},{:d})",
174 mEquivCond(freqIdx, 0).real(),
175 mEquivCond(freqIdx, 0).imag(), matrixNodeIndex(0),
177 if (terminalNotGrounded(1))
178 SPDLOG_LOGGER_INFO(mSLog,
"Add {:f}+j{:f} to system at ({:d},{:d})",
179 mEquivCond(freqIdx, 0).real(),
180 mEquivCond(freqIdx, 0).imag(), matrixNodeIndex(1),
182 if (terminalNotGrounded(0) && terminalNotGrounded(1)) {
183 SPDLOG_LOGGER_INFO(mSLog,
"Add {:f}+j{:f} to system at ({:d},{:d})",
184 -mEquivCond(freqIdx, 0).real(),
185 -mEquivCond(freqIdx, 0).imag(), matrixNodeIndex(0),
187 SPDLOG_LOGGER_INFO(mSLog,
"Add {:f}+j{:f} to system at ({:d},{:d})",
188 -mEquivCond(freqIdx, 0).real(),
189 -mEquivCond(freqIdx, 0).imag(), matrixNodeIndex(1),
208 SPDLOG_LOGGER_DEBUG(
mSLog,
"MNA EquivCurrent {:s}",
211 SPDLOG_LOGGER_DEBUG(
mSLog,
"Add {:s} to source vector at {:d}",
215 SPDLOG_LOGGER_DEBUG(
mSLog,
"Add {:s} to source vector at {:d}",
223 for (
Int freq = 0; freq < mNumFreqs; freq++) {
225 mEquivCurrent(freq, 0) = mEquivCond(freq, 0) * (**mIntfVoltage)(0, freq) +
226 mPrevCurrFac(freq, 0) * (**mIntfCurrent)(0, freq);
228 if (terminalNotGrounded(0))
230 mEquivCurrent(freq, 0), 1, 0, freq);
231 if (terminalNotGrounded(1))
233 -mEquivCurrent(freq, 0), 1, 0, freq);
241 modifiedAttributes.push_back(mRightVector);
242 prevStepDependencies.push_back(mIntfVoltage);
243 prevStepDependencies.push_back(mIntfCurrent);
247 mResIndSeries.mnaCompApplyRightSideVectorStamp(**
mRightVector);
250void DP::Ph1::ResIndSeries::MnaPreStepHarm::execute(
Real time,
252 mResIndSeries.mnaCompApplyRightSideVectorStampHarm(
253 **mResIndSeries.mRightVector);
260 attributeDependencies.push_back(leftVector);
261 modifiedAttributes.push_back(mIntfVoltage);
262 modifiedAttributes.push_back(mIntfCurrent);
271void DP::Ph1::ResIndSeries::MnaPostStepHarm::execute(
Real time,
273 for (
Int freq = 0; freq < mResIndSeries.mNumFreqs; freq++)
274 mResIndSeries.mnaCompUpdateVoltageHarm(**mLeftVectors[freq], freq);
275 mResIndSeries.mnaCompUpdateCurrentHarm();
281 (**mIntfVoltage)(0, freq) = 0;
286 (**mIntfVoltage)(0, freq) =
291 SPDLOG_LOGGER_DEBUG(
mSLog,
"Voltage {:s}",
296void DP::Ph1::ResIndSeries::mnaCompUpdateVoltageHarm(
const Matrix &leftVector,
299 (**mIntfVoltage)(0, freqIdx) = 0;
300 if (terminalNotGrounded(1))
301 (**mIntfVoltage)(0, freqIdx) =
303 if (terminalNotGrounded(0))
304 (**mIntfVoltage)(0, freqIdx) =
305 (**mIntfVoltage)(0, freqIdx) -
308 SPDLOG_LOGGER_DEBUG(mSLog,
"Voltage {:s}",
314 (**mIntfCurrent)(0, freq) =
315 mEquivCond(freq, 0) * (**mIntfVoltage)(0, freq) +
317 SPDLOG_LOGGER_DEBUG(
mSLog,
"Current {:s}",
322void DP::Ph1::ResIndSeries::mnaCompUpdateCurrentHarm() {
323 for (
Int freq = 0; freq < mNumFreqs; freq++) {
324 (**mIntfCurrent)(0, freq) =
325 mEquivCond(freq, 0) * (**mIntfVoltage)(0, freq) +
326 mEquivCurrent(freq, 0);
327 SPDLOG_LOGGER_DEBUG(mSLog,
"Current {:s}",
340 1. / mEquivCond(0, 0));
344 mEquivCurrent(0, 0) = mEquivCond(0, 0) * (**mIntfVoltage)(0, 0) +
345 mPrevCurrFac(0, 0) * (**mIntfCurrent)(0, 0);
347 mEquivCurrent(0, 0) / mEquivCond(0, 0));
351 (**mIntfVoltage)(0, 0) = voltage;
352 (**mIntfCurrent)(0, 0) = mEquivCond(0, 0) * voltage + mEquivCurrent(0, 0);
void mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes)
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector)
AttributePointer< Attribute< T > > Ptr
const Attribute< Real >::Ptr mInductance
Inductance [H].
void initialize(Matrix frequencies)
Initializes state variables considering the number of frequencies.
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector)
Initializes MNA specific variables.
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector)
Stamps right side (source) vector.
void mnaCompPreStep(Real time, Int timeStepCount) override
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix)
Stamps system matrix.
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
void initializeFromNodesAndTerminals(Real frequency)
Initializes states from power flow data.
const Attribute< Real >::Ptr mResistance
Resistance [ohm].
MatrixComp mEquivCurrent
DC equivalent current source for harmonics [A].
void mnaCompUpdateVoltage(const Matrix &leftVector)
Update interface voltage from MNA system results.
void setParameters(Real resistance, Real inductance)
Sets model specific parameters.
ResIndSeries(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and log level.
SimPowerComp< Complex >::Ptr clone(String name)
Return new instance with the same parameters.
MatrixComp mPrevCurrFac
Coefficient in front of previous current value for harmonics.
MatrixComp mEquivCond
Equivalent conductance for harmonics [S].
void mnaCompUpdateCurrent()
Update interface current from MNA system results.
String uid()
Returns unique id.
AttributeList::Ptr mAttributes
Attribute List.
spdlog::level::level_enum Level
static String complexToString(const Complex &num)
static String phasorToString(const Complex &num)
virtual void mnaCompInitializeHarm(Real omega, Real timeStep, std::vector< Attribute< Matrix >::Ptr > leftVector)
virtual void mnaCompApplyRightSideVectorStampHarm(Matrix &sourceVector)
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
Attribute< Matrix >::Ptr mRightVector
virtual void mnaCompApplySystemMatrixStampHarm(SparseMatrixRow &systemMatrix, Int freqIdx)
virtual void mnaTearInitialize(Real omega, Real timeStep)
virtual void mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix)=0
virtual void mnaTearPostStep(Complex voltage, Complex current)
virtual void mnaTearApplyVoltageStamp(Matrix ¤tVector)
static Complex complexFromVectorElement(const Matrix &mat, Matrix::Index row, Int maxFreq=1, Int freqIdx=0)
static void setVectorElement(Matrix &mat, Matrix::Index row, Complex value, Int maxFreq=1, Int freqIdx=0, Matrix::Index colOffset=0)
static void addToVectorElement(Matrix &mat, Matrix::Index row, Complex value, Int maxFreq=1, Int freqIdx=0)
static void addToMatrixElement(SparseMatrixRow &mat, Matrix::Index row, Matrix::Index column, Complex value, Int maxFreq=1, Int freqIdx=0)
UInt matrixNodeIndex(UInt nodeIndex)
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
virtual void initialize(Matrix frequencies)
Initialize components with correct network frequencies.
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
std::shared_ptr< SimPowerComp< VarType > > Ptr
Bool terminalNotGrounded(UInt index)
Complex initialSingleVoltage(UInt index)
void updateMatrixNodeIndices()
void setTerminalNumber(UInt num)
Logger::Level mLogLevel
Component logger control for internal variables.
Logger::Log mSLog
Component logger.
static std::shared_ptr< ResIndSeries > make(Args &&...args)
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > Matrix
Dense matrix for real numbers.
std::complex< Real > Complex
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).