13 mW(
Matrix::Zero(outputSize, inputSize)),
14 mYHist(
Matrix::Zero(outputSize, 1)), mInputSize(inputSize),
21 return static_cast<UInt>(
mA.rows());
26std::vector<EMT::SSNComp::LocalAbcStateBlock>
44 if (
A.rows() !=
A.cols())
45 throw std::invalid_argument(
"A must be square.");
47 if (
B.rows() !=
A.rows() ||
B.cols() != mInputSize)
48 throw std::invalid_argument(
"B has invalid dimensions.");
50 if (
C.rows() != mOutputSize ||
C.cols() !=
A.rows())
51 throw std::invalid_argument(
"C has invalid dimensions.");
53 if (D.rows() != mOutputSize || D.cols() != mInputSize)
54 throw std::invalid_argument(
"D has invalid dimensions.");
55 if (D1.size() != 0 && (D1.rows() != mOutputSize || D1.cols() != mInputSize))
56 throw std::invalid_argument(
"D1 has invalid dimensions.");
62 mD1 = D1.size() == 0 ? Matrix::Zero(mOutputSize, mInputSize) : D1;
64 **
mX = Matrix::Zero(
mA.rows(), 1);
66 mdA = Matrix::Zero(
mA.rows(),
mA.cols());
67 mdB = Matrix::Zero(
mB.rows(),
mB.cols());
69 mW = Matrix::Zero(mOutputSize, mInputSize);
70 mYHist = Matrix::Zero(mOutputSize, 1);
93 Real frequency)
const {
94 const Real omega = 2.0 *
PI * frequency;
96 Complex(0.0, omega) * MatrixComp::Identity(
mA.rows(),
mA.cols()) -
99 return h.inverse() *
mB.cast<
Complex>() * u;
112 **
mX =
mdA * (**mX) +
mdB * (uNew + uOld);
131 throw std::logic_error(
132 "setParameters() must be called before initialization.");
143 if (index <
static_cast<UInt>(leftVector->
get().rows()))
150 if (index <
static_cast<UInt>(leftVector->
get().rows()))
168 rightVector(index, 0) += (*mRightVectorValue)(index, 0);
176 prevStepDependencies.push_back(
mX);
191 attributeDependencies.push_back(leftVector);
194 modifiedAttributes.push_back(
mX);
AttributePointer< Attribute< T > > Ptr
Matrix mD1
Feedthrough from the time derivative of the input, for capacitive ports.
virtual std::vector< String > getLocalStateNames() const
virtual void updateLogAttributes(const Matrix &u) const
Update derived attributes used for logging/inspection.
Matrix mHistoryState
Reused workspaces for the per-step linear history evaluation.
const Matrix & getDiscreteA() const
Get discrete state transition matrix used by the trapezoidal SSN model.
const Matrix & getDiscreteB() const
Get discrete input matrix used by the trapezoidal SSN model.
void mnaCompPreStep(Real time, Int timeStepCount) override final
const Attribute< Matrix >::Ptr mX
virtual void recomputeDiscreteModel()
virtual Attribute< Matrix >::Ptr inputAttribute() const =0
const Matrix & getC() const
Get continuous-time output matrix of the SSN model.
const Matrix & stateValue() const
void mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override final
const Matrix & inputValue() const
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override final
virtual void updateState(const Matrix &uOld, const Matrix &uNew)
const Matrix * mInputValue
virtual void updateStateSpaceModel()
Hook for variable/time-varying SSN components.
SSNComp(String uid, String name, Int inputSize, Int outputSize, Logger::Level logLevel=Logger::Level::off)
virtual MatrixComp calculateSteadyStateStateFromInput(const MatrixComp &u, Real frequency) const
virtual Attribute< Matrix >::Ptr outputAttribute() const =0
Matrix mPreviousInput
Reused storage for the previous SSN input during post-step updates.
virtual std::vector< LocalAbcStateBlock > getLocalAbcStateBlocks() const
void mnaAddCompactRightSideVectorStamp(Matrix &rightVector) override final
UInt getStateCount() const
Get number of internal state variables of the SSN model.
std::vector< UInt > mRightVectorAffectedIndices
virtual void calculateHistoryVector(Matrix &history) const
void setParameters(const Matrix &A, const Matrix &B, const Matrix &C, const Matrix &D, const Matrix &D1=Matrix())
virtual MatrixComp calculateSteadyStateOutputFromInput(const MatrixComp &x, const MatrixComp &u) const
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override final
String uid()
Returns unique id.
AttributeList::Ptr mAttributes
Attribute List.
spdlog::level::level_enum Level
Matrix * mRightVectorValue
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
Attribute< Matrix >::Ptr mRightVector
virtual void mnaCompApplyRightSideVectorStamp(Matrix &rightVector)
static void calculateStateSpaceTrapezoidalMatrices(const Matrix &A, const Matrix &B, const Matrix &C, const Real &dt, Matrix &Ad, Matrix &Bd, Matrix &Cd)
Calculate the discretized state space matrices Ad, Bd, Cd using trapezoidal rule.
SimTerminal< Real >::Ptr terminal(UInt index)
std::vector< UInt > virtualMatrixNodeIndices(UInt index)
UInt virtualNodesNumber()
SimNode< Real >::Ptr virtualNode(UInt index)
UInt terminalNumberConnected()
Bool terminalNotGrounded(UInt index)
void updateMatrixNodeIndices()
std::vector< UInt > matrixNodeIndices(UInt index)
bool mParametersSet
Flag indicating that parameters are set via setParameters() function.
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > Matrix
Dense matrix for real numbers.
std::complex< Real > Complex
Eigen::Matrix< Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixComp
Dense matrix for complex numbers.