47 Real omega = 2. *
PI * frequency;
50 (**mIntfCurrent)(0, 0) = (**
mIntfVoltage)(0, 0) / impedance;
52 SPDLOG_LOGGER_INFO(
mSLog,
53 "\nInductance [H]: {:s}"
54 "\nImpedance [Ohm]: {:s}",
57 SPDLOG_LOGGER_INFO(
mSLog,
58 "\n--- Initialization from powerflow ---"
59 "\nVoltage across: {:s}"
61 "\nTerminal 0 voltage: {:s}"
62 "\nTerminal 1 voltage: {:s}"
63 "\n--- Initialization from powerflow finished ---",
77 Real equivCondReal = a / (1. + b * b);
78 Real equivCondImag = -a * b / (1. + b * b);
79 mEquivCond(freq, 0) = {equivCondReal, equivCondImag};
80 Real preCurrFracReal = (1. - b * b) / (1. + b * b);
81 Real preCurrFracImag = (-2. * b) / (1. + b * b);
82 mPrevCurrFac(freq, 0) = {preCurrFracReal, preCurrFracImag};
87 (**mIntfCurrent)(0, freq) =
88 mEquivCond(freq, 0) * (**mIntfVoltage)(0, freq) +
98 SPDLOG_LOGGER_INFO(
mSLog,
99 "\n--- MNA initialization ---"
100 "\nInitial voltage {:s}"
101 "\nInitial current {:s}"
102 "\nEquiv. current {:s}"
103 "\n--- MNA initialization finished ---",
116 mMnaTasks.push_back(std::make_shared<MnaPreStepHarm>(*
this));
117 mMnaTasks.push_back(std::make_shared<MnaPostStepHarm>(*
this, leftVectors));
152 SPDLOG_LOGGER_DEBUG(
mSLog,
"MNA EquivCurrent {:s}",
155 SPDLOG_LOGGER_DEBUG(
mSLog,
"Add {:s} to source vector at {:d}",
159 SPDLOG_LOGGER_DEBUG(
mSLog,
"Add {:s} to source vector at {:d}",
200 attributeDependencies.push_back(leftVector);
212 mInductor.mnaCompApplyRightSideVectorStampHarm(**mInductor.mRightVector);
216 for (
UInt freq = 0; freq < mInductor.mNumFreqs; freq++)
217 mInductor.mnaCompUpdateVoltageHarm(**mLeftVectors[freq], freq);
218 mInductor.mnaCompUpdateCurrentHarm();
224 (**mIntfVoltage)(0, freq) = 0;
229 (**mIntfVoltage)(0, freq) =
234 SPDLOG_LOGGER_DEBUG(
mSLog,
"Voltage {:s}",
242 (**mIntfVoltage)(0, freqIdx) = 0;
244 (**mIntfVoltage)(0, freqIdx) =
247 (**mIntfVoltage)(0, freqIdx) =
251 SPDLOG_LOGGER_DEBUG(
mSLog,
"Voltage {:s}",
257 (**mIntfCurrent)(0, freq) =
258 mEquivCond(freq, 0) * (**mIntfVoltage)(0, freq) +
260 SPDLOG_LOGGER_DEBUG(
mSLog,
"Current {:s}",
267 (**mIntfCurrent)(0, freq) =
268 mEquivCond(freq, 0) * (**mIntfVoltage)(0, freq) +
270 SPDLOG_LOGGER_DEBUG(
mSLog,
"Current {:s}",
293 (**mIntfVoltage)(0, 0) = voltage;
AttributePointer< Attribute< T > > Ptr
void setParameters(Real inductance)
Sets model specific parameters.
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 updateInductance(Real inductance, Real timeStep)
Change inductance and refresh trapezoidal companion coefficients.
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).