43 const Real equivCondReal = 2. * capacitance / timeStep;
44 const Real prevVoltCoeffReal = equivCondReal;
49 Complex(prevVoltCoeffReal, -harmonicOmega * capacitance);
51 -(**mIntfCurrent)(0, freq) -
58 Real omega = 2 *
PI * frequency;
63 (**mIntfCurrent)(0, 0) =
66 SPDLOG_LOGGER_INFO(
mSLog,
67 "\nCapacitance [F]: {:s}"
68 "\nImpedance [Ohm]: {:s}",
71 SPDLOG_LOGGER_INFO(
mSLog,
72 "\n--- Initialization from powerflow ---"
73 "\nVoltage across: {:s}"
75 "\nTerminal 0 voltage: {:s}"
76 "\nTerminal 1 voltage: {:s}"
77 "\n--- Initialization from powerflow finished ---",
94 mEquivCond(freq, 0) = {equivCondReal, equivCondImag};
99 -(**mIntfCurrent)(0, freq) +
101 (**mIntfCurrent)(0, freq) =
102 mEquivCond(freq, 0) * (**mIntfVoltage)(0, freq) +
106 SPDLOG_LOGGER_INFO(
mSLog,
107 "\n--- MNA initialization ---"
108 "\nInitial voltage {:s}"
109 "\nInitial current {:s}"
110 "\nEquiv. current {:s}"
111 "\n--- MNA initialization finished ---",
128 mEquivCond(freq, 0) = {equivCondReal, equivCondImag};
133 -(**mIntfCurrent)(0, freq) +
135 (**mIntfCurrent)(0, freq) =
136 mEquivCond(freq, 0) * (**mIntfVoltage)(0, freq) +
140 mMnaTasks.push_back(std::make_shared<MnaPreStepHarm>(*
this));
141 mMnaTasks.push_back(std::make_shared<MnaPostStepHarm>(*
this, leftVectors));
168 -(**mIntfCurrent)(0, freq) +
178 SPDLOG_LOGGER_DEBUG(
mSLog,
"MNA EquivCurrent {:f}+j{:f}",
182 SPDLOG_LOGGER_DEBUG(
mSLog,
"Add {:f}+j{:f} to source vector at {:d}",
186 SPDLOG_LOGGER_DEBUG(
mSLog,
"Add {:f}+j{:f} to source vector at {:d}",
198 -(**mIntfCurrent)(0, freq) +
244 attributeDependencies.push_back(leftVector);
256 mCapacitor.mnaCompApplyRightSideVectorStampHarm(**mCapacitor.mRightVector);
261 for (
UInt freq = 0; freq < mCapacitor.mNumFreqs; freq++)
262 mCapacitor.mnaCompUpdateVoltageHarm(**mLeftVectors[freq], freq);
263 mCapacitor.mnaCompUpdateCurrentHarm();
269 (**mIntfVoltage)(0, freq) = 0;
274 (**mIntfVoltage)(0, freq) =
279 SPDLOG_LOGGER_DEBUG(
mSLog,
"Voltage {:e}<{:e}",
288 (**mIntfVoltage)(0, freqIdx) = 0;
290 (**mIntfVoltage)(0, freqIdx) =
293 (**mIntfVoltage)(0, freqIdx) =
297 SPDLOG_LOGGER_DEBUG(
mSLog,
"Voltage {:s}",
303 (**mIntfCurrent)(0, freq) =
304 mEquivCond(freq, 0) * (**mIntfVoltage)(0, freq) +
306 SPDLOG_LOGGER_DEBUG(
mSLog,
"Current {:s}",
313 (**mIntfCurrent)(0, freq) =
314 mEquivCond(freq, 0) * (**mIntfVoltage)(0, freq) +
316 SPDLOG_LOGGER_DEBUG(
mSLog,
"Current {:s}",
AttributePointer< Attribute< T > > Ptr
void setParameters(Real capacitance)
Sets model specific parameters.
const CPS::Attribute< Real >::Ptr mCapacitance
Capacitance [F].
void execute(Real time, Int timeStepCount)
void execute(Real time, Int timeStepCount)
void updateCapacitance(Real capacitance, Real timeStep)
Change capacitance and refresh trapezoidal companion coefficients.
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).