43 Real omega = 2 *
PI * frequency;
48 (**mIntfCurrent)(0, 0) =
51 SPDLOG_LOGGER_INFO(
mSLog,
52 "\nCapacitance [F]: {:s}"
53 "\nImpedance [Ohm]: {:s}",
56 SPDLOG_LOGGER_INFO(
mSLog,
57 "\n--- Initialization from powerflow ---"
58 "\nVoltage across: {:s}"
60 "\nTerminal 0 voltage: {:s}"
61 "\nTerminal 1 voltage: {:s}"
62 "\n--- Initialization from powerflow finished ---",
79 mEquivCond(freq, 0) = {equivCondReal, equivCondImag};
84 -(**mIntfCurrent)(0, freq) +
86 (**mIntfCurrent)(0, freq) =
87 mEquivCond(freq, 0) * (**mIntfVoltage)(0, freq) +
91 SPDLOG_LOGGER_INFO(
mSLog,
92 "\n--- MNA initialization ---"
93 "\nInitial voltage {:s}"
94 "\nInitial current {:s}"
95 "\nEquiv. current {:s}"
96 "\n--- MNA initialization finished ---",
113 mEquivCond(freq, 0) = {equivCondReal, equivCondImag};
118 -(**mIntfCurrent)(0, freq) +
120 (**mIntfCurrent)(0, freq) =
121 mEquivCond(freq, 0) * (**mIntfVoltage)(0, freq) +
125 mMnaTasks.push_back(std::make_shared<MnaPreStepHarm>(*
this));
126 mMnaTasks.push_back(std::make_shared<MnaPostStepHarm>(*
this, leftVectors));
153 -(**mIntfCurrent)(0, freq) +
163 SPDLOG_LOGGER_DEBUG(
mSLog,
"MNA EquivCurrent {:f}+j{:f}",
167 SPDLOG_LOGGER_DEBUG(
mSLog,
"Add {:f}+j{:f} to source vector at {:d}",
171 SPDLOG_LOGGER_DEBUG(
mSLog,
"Add {:f}+j{:f} to source vector at {:d}",
183 -(**mIntfCurrent)(0, freq) +
229 attributeDependencies.push_back(leftVector);
241 mCapacitor.mnaCompApplyRightSideVectorStampHarm(**mCapacitor.mRightVector);
246 for (
UInt freq = 0; freq < mCapacitor.mNumFreqs; freq++)
247 mCapacitor.mnaCompUpdateVoltageHarm(**mLeftVectors[freq], freq);
248 mCapacitor.mnaCompUpdateCurrentHarm();
254 (**mIntfVoltage)(0, freq) = 0;
259 (**mIntfVoltage)(0, freq) =
264 SPDLOG_LOGGER_DEBUG(
mSLog,
"Voltage {:e}<{:e}",
273 (**mIntfVoltage)(0, freqIdx) = 0;
275 (**mIntfVoltage)(0, freqIdx) =
278 (**mIntfVoltage)(0, freqIdx) =
282 SPDLOG_LOGGER_DEBUG(
mSLog,
"Voltage {:s}",
288 (**mIntfCurrent)(0, freq) =
289 mEquivCond(freq, 0) * (**mIntfVoltage)(0, freq) +
291 SPDLOG_LOGGER_DEBUG(
mSLog,
"Current {:s}",
298 (**mIntfCurrent)(0, freq) =
299 mEquivCond(freq, 0) * (**mIntfVoltage)(0, freq) +
301 SPDLOG_LOGGER_DEBUG(
mSLog,
"Current {:s}",
AttributePointer< Attribute< T > > Ptr
const CPS::Attribute< Real >::Ptr mCapacitance
Capacitance [F].
void execute(Real time, Int timeStepCount)
void execute(Real time, Int timeStepCount)
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
void mnaCompUpdateVoltageHarm(const Matrix &leftVector, Int freqIdx)
void mnaCompUpdateCurrentHarm()
Capacitor(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
void mnaCompPreStep(Real time, Int timeStepCount) override
MNA pre step operations.
void mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
void mnaCompApplySystemMatrixStampHarm(SparseMatrixRow &systemMatrix, Int freqIdx) override
void initializeFromNodesAndTerminals(Real frequency) override
Initializes component from power flow data.
MatrixComp mPrevVoltCoeff
Coefficient in front of previous voltage value for harmonics.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
void initialize(Matrix frequencies) override
Initialize components with correct network frequencies.
MatrixComp mEquivCurrent
DC equivalent current source for harmonics [A].
void mnaCompInitializeHarm(Real omega, Real timeStep, std::vector< Attribute< Matrix >::Ptr > leftVector) override
void mnaCompApplyRightSideVectorStampHarm(Matrix &rightVector) override
Complex getMNAConductance() const
Return single-frequency MNA companion conductance.
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
Initializes internal variables of the component.
void mnaCompUpdateVoltage(const Matrix &leftVector) override
Update interface voltage from MNA system result.
MatrixComp mEquivCond
Equivalent conductance for harmonics [S].
void mnaCompUpdateCurrent(const Matrix &leftVector) override
Update interface current from MNA system result.
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
Stamps right side (source) vector.
SimPowerComp< Complex >::Ptr clone(String name) override
Returns a modified copy of the component with the given suffix added to the name and without.
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
MNA post step operations.
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)
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< Capacitor > 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).