42 Real omega = 2. *
PI * frequency;
45 (**mIntfCurrent)(0, 0) = (**
mIntfVoltage)(0, 0) / impedance;
47 SPDLOG_LOGGER_INFO(
mSLog,
48 "\nInductance [H]: {:s}"
49 "\nImpedance [Ohm]: {:s}",
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 ---",
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};
82 (**mIntfCurrent)(0, freq) =
83 mEquivCond(freq, 0) * (**mIntfVoltage)(0, freq) +
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 ---",
111 mMnaTasks.push_back(std::make_shared<MnaPreStepHarm>(*
this));
112 mMnaTasks.push_back(std::make_shared<MnaPostStepHarm>(*
this, leftVectors));
147 SPDLOG_LOGGER_DEBUG(
mSLog,
"MNA EquivCurrent {:s}",
150 SPDLOG_LOGGER_DEBUG(
mSLog,
"Add {:s} to source vector at {:d}",
154 SPDLOG_LOGGER_DEBUG(
mSLog,
"Add {:s} to source vector at {:d}",
195 attributeDependencies.push_back(leftVector);
207 mInductor.mnaCompApplyRightSideVectorStampHarm(**mInductor.mRightVector);
211 for (
UInt freq = 0; freq < mInductor.mNumFreqs; freq++)
212 mInductor.mnaCompUpdateVoltageHarm(**mLeftVectors[freq], freq);
213 mInductor.mnaCompUpdateCurrentHarm();
219 (**mIntfVoltage)(0, freq) = 0;
224 (**mIntfVoltage)(0, freq) =
229 SPDLOG_LOGGER_DEBUG(
mSLog,
"Voltage {:s}",
237 (**mIntfVoltage)(0, freqIdx) = 0;
239 (**mIntfVoltage)(0, freqIdx) =
242 (**mIntfVoltage)(0, freqIdx) =
246 SPDLOG_LOGGER_DEBUG(
mSLog,
"Voltage {:s}",
252 (**mIntfCurrent)(0, freq) =
253 mEquivCond(freq, 0) * (**mIntfVoltage)(0, freq) +
255 SPDLOG_LOGGER_DEBUG(
mSLog,
"Current {:s}",
262 (**mIntfCurrent)(0, freq) =
263 mEquivCond(freq, 0) * (**mIntfVoltage)(0, freq) +
265 SPDLOG_LOGGER_DEBUG(
mSLog,
"Current {:s}",
288 (**mIntfVoltage)(0, 0) = voltage;
AttributePointer< Attribute< T > > Ptr
const CPS::Attribute< Real >::Ptr mInductance
Inductance [H].
void execute(Real time, Int timeStepCount)
void execute(Real time, Int timeStepCount)
void mnaCompUpdateCurrentHarm()
void mnaTearApplyVoltageStamp(Matrix &voltageVector) override
MatrixComp mEquivCond
Equivalent conductance for harmonics [S].
void mnaTearApplyMatrixStamp(SparseMatrixRow &tearMatrix) override
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Update interface current from MNA system results.
void mnaCompInitializeHarm(Real omega, Real timeStep, std::vector< Attribute< Matrix >::Ptr > leftVectors) override
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
void mnaCompApplySystemMatrixStampHarm(SparseMatrixRow &systemMatrix, Int freqIdx) override
void mnaCompUpdateVoltageHarm(const Matrix &leftVector, Int freqIdx)
void initVars(Real timeStep)
void mnaTearInitialize(Real omega, Real timestep) override
SimPowerComp< Complex >::Ptr clone(String name) override
Return new instance with the same parameters.
MatrixComp mEquivCurrent
DC equivalent current source for harmonics [A].
void mnaTearPostStep(Complex voltage, Complex current) override
void mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
Initializes MNA specific variables.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Update interface voltage from MNA system results.
Complex getMNAConductance() const
Return single-frequency MNA companion conductance.
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
MNA post step operations.
MatrixComp mPrevCurrFac
Coefficient in front of previous current value for harmonics.
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
Stamps right side (source) vector.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes states from power flow data.
void initialize(Matrix frequencies) override
Initializes state variables considering the number of frequencies.
void mnaCompApplyRightSideVectorStampHarm(Matrix &rightVector) override
void mnaCompPreStep(Real time, Int timeStepCount) override
MNA pre step operations.
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
Inductor(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and log level.
String uid()
Returns unique id.
AttributeList::Ptr mAttributes
Attribute List.
spdlog::level::level_enum Level
static String complexToString(const Complex &num)
static String realToString(const Real &num)
static String phasorToString(const Complex &num)
void mnaUpdateCurrent(const Matrix &leftVector) final
void mnaUpdateVoltage(const Matrix &leftVector) final
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
Attribute< Matrix >::Ptr mRightVector
void mnaApplyRightSideVectorStamp(Matrix &rightVector) final
static void stampAdmittance(Complex admittance, SparseMatrixRow &mat, UInt node1Index, UInt node2Index, Bool isTerminal1NotGrounded, Bool isTerminal2NotGrounded, const Logger::Log &mSLog, Int maxFreq=1, Int freqIdx=0)
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< Inductor > 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).