25 const std::vector<Int> &modulHarms,
42 SPDLOG_LOGGER_INFO(
mSLog,
"Add carrier harmonic {0}", m);
46 SPDLOG_LOGGER_INFO(
mSLog,
"Add modulation harmonic {0}", n);
53 SPDLOG_LOGGER_INFO(
mSLog,
"\n--- Initialization ---");
59 throw std::invalid_argument(
60 "Number of carrier and modulation harmonics must be equal.");
83 SPDLOG_LOGGER_INFO(
mSLog,
86 "\n--- End of initialization ---",
102 (**mIntfVoltage)(0, h + 1) =
107 SPDLOG_LOGGER_DEBUG(
mSLog,
108 "\n--- Phasor calculation ---"
111 "\n--- Phasor calculation end ---",
128 mMnaTasks.push_back(std::make_shared<MnaPreStepHarm>(*
this));
129 mMnaTasks.push_back(std::make_shared<MnaPostStepHarm>(*
this, leftVectors));
137 SPDLOG_LOGGER_INFO(
mSLog,
"--- Stamping into system matrix ---");
140 SPDLOG_LOGGER_INFO(
mSLog,
"Stamp frequency {:d}", freq);
151 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:f} to system at ({:d},{:d})", 1.,
154 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:f} to system at ({:d},{:d})", 1.,
159 SPDLOG_LOGGER_INFO(
mSLog,
"--- Stamping into system matrix end ---");
164 SPDLOG_LOGGER_INFO(
mSLog,
"Stamp frequency {:d}", freqIdx);
173 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:f} to system at ({:d},{:d})", 1.,
175 SPDLOG_LOGGER_INFO(
mSLog,
"Add {:f} to system at ({:d},{:d})", 1.,
181 SPDLOG_LOGGER_DEBUG(
mSLog,
"Stamp harmonics into source vector");
187 SPDLOG_LOGGER_DEBUG(
mSLog,
188 "Add {:s} to source vector at {:d}, harmonic {:d}",
197 SPDLOG_LOGGER_DEBUG(
mSLog,
"Stamp harmonics into source vector");
226 mInverter.calculatePhasors();
227 mInverter.mnaCompApplyRightSideVectorStampHarm(**mInverter.mRightVector);
235 attributeDependencies.push_back(leftVector);
251 for (
Int k = 0; k <= k_max; ++k) {
253 pow(x / 2., 2. * k + n);
262 for (
Int k = 0; k <= k_max; ++k) {
264 pow(x / 2., 2. * k + n);
271 return (n == 1 || n == 0) ? 1 :
factorial(n - 1) * n;
285 return 1. / std::tgamma(n);
AttributePointer< Attribute< T > > Ptr
void execute(Real time, Int timeStepCount)
void execute(Real time, Int timeStepCount)
Int mMaxModulHarm
Maximum number of modulation signal harmonics.
void mnaCompInitializeHarm(Real omega, Real timeStep, std::vector< Attribute< Matrix >::Ptr > leftVectors) override
void setParameters(const std::vector< Int > &carrierHarms, const std::vector< Int > &modulHarms, Real inputVoltage, Real ratio, Real phase)
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
std::vector< Int > mModHarms
Vector of modulation signal harmonics.
void mnaCompApplySystemMatrixStampHarm(SparseMatrixRow &systemMatrix, Int freqIdx) override
Real multInvIntGamma(Real n) const
Real mModIdx
Modulation Index.
void mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
Real mFreqMod
system frequency (should be updated every step)
void mnaCompApplyRightSideVectorStampHarm(Matrix &rightVector) override
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
Real multInvFactorial(Int n) const
void generateFrequencies()
UInt mHarNum
Number of harmonics.
Int mMaxCarrierHarm
Maximum number of carrier signal harmonics.
Matrix mPhasorPhases
Vector of phasor phases.
Real mPhaseCar
Carrier phase.
void initialize(Matrix frequencies) override
Initialize components with correct network frequencies.
Real besselFirstKind_n(Int n, Int k_max, Real x) const
Bessel function.
Real besselFirstKind_n_opt(Int n, Int k_max, Real x)
Bessel function using look up tables for factorials.
Inverter(String name, String uid, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
std::map< Int, Real > mMultInvFactorials
Real mFreqCar
switching frequency (constant)
Matrix mPhasorMags
Vector of phasor magnitudes.
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
Stamps right side (source) vector.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes Component variables according to power flow data stored in Nodes.
std::vector< Real > mFactorials
long long factorial(Int n) const
Int mMaxBesselSumIdx
Maximum upper limit for Bessel function 1st kind summation.
void mnaCompPreStep(Real time, Int timeStepCount) override
Real mPhaseMod
Modulation phase.
std::vector< Int > mCarHarms
Vector of carrier signal harmonics.
Matrix mPhasorFreqs
Vector of phasor frequencies.
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
Initializes internal variables of the component.
Real mVfund
voltage part of system fundamental
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
String uid()
Returns unique id.
spdlog::level::level_enum Level
static String complexToString(const Complex &num)
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
Attribute< Matrix >::Ptr mRightVector
static void setVectorElement(Matrix &mat, Matrix::Index row, Complex value, Int maxFreq=1, Int freqIdx=0, Matrix::Index colOffset=0)
static void setMatrixElement(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.
void setVirtualNodeNumber(UInt num)
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
SimNode< Complex >::List mVirtualNodes
Bool terminalNotGrounded(UInt index)
void updateMatrixNodeIndices()
void setTerminalNumber(UInt num)
bool mParametersSet
Flag indicating that parameters are set via setParameters() function.
Logger::Log mSLog
Component logger.
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).