30 if (
A.rows() !=
A.cols())
31 throw std::invalid_argument(
"A must be square.");
33 if (
B.rows() !=
A.rows() ||
B.cols() != mInputSize)
34 throw std::invalid_argument(
"B has invalid dimensions.");
36 if (
C.rows() != mOutputSize ||
C.cols() !=
A.rows())
37 throw std::invalid_argument(
"C has invalid dimensions.");
39 if (D.rows() != mOutputSize || D.cols() != mInputSize)
40 throw std::invalid_argument(
"D has invalid dimensions.");
47 **
mX = MatrixComp::Zero(
mA.rows(), 1);
52 mW = MatrixComp::Zero(mOutputSize, mInputSize);
53 mYHist = MatrixComp::Zero(mOutputSize, 1);
59 const Matrix::Index n =
mA.rows();
60 const Matrix wI = omega * Matrix::Identity(n, n);
62 Matrix aAug = Matrix::Zero(2 * n, 2 * n);
63 aAug.topLeftCorner(n, n) =
mA;
64 aAug.topRightCorner(n, n) = wI;
65 aAug.bottomLeftCorner(n, n) = -wI;
66 aAug.bottomRightCorner(n, n) =
mA;
71 const Matrix::Index n =
mA.rows();
73 Matrix bAug = Matrix::Zero(2 * n, 2 * mInputSize);
74 bAug.topLeftCorner(n, mInputSize) =
mB;
75 bAug.bottomRightCorner(n, mInputSize) =
mB;
80 const Matrix::Index n =
mA.rows();
85 Matrix dAaug = Matrix::Zero(2 * n, 2 * n);
86 Matrix dBaug = Matrix::Zero(2 * n, 2 * mInputSize);
94 dBaug.block(0, 0, n, mInputSize).cast<
Complex>() +
95 Complex(0., 1.) * dBaug.block(n, 0, n, mInputSize).cast<
Complex>();
108 Complex(0., omega) * MatrixComp::Identity(
mA.rows(),
mA.cols()) -
111 return h.inverse() *
mB.cast<
Complex>() * u;
131 throw std::logic_error(
132 "setParameters() must be called before initialization.");
135 throw std::logic_error(
136 "DP SSN components currently support a single carrier frequency.");
150 prevStepDependencies.push_back(
mX);
165 attributeDependencies.push_back(leftVector);
168 modifiedAttributes.push_back(
mX);
AttributePointer< Attribute< T > > Ptr
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override final
virtual void updateStateSpaceModel()
Hook for variable/time-varying SSN components.
virtual MatrixComp calculateHistoryVector() const
Matrix mA
Continuous-time real physical model (user-provided).
const MatrixComp & getDiscreteA() const
Get the complex discrete state-transition operator of the envelope model.
UInt getStateCount() const
Get number of internal state variables of the SSN model.
virtual void updateState(const MatrixComp &uOld, const MatrixComp &uNew)
MatrixComp mYHist
Complex history term.
virtual Attribute< MatrixComp >::Ptr inputAttribute() const =0
Matrix buildAugmentedA(Real omega) const
Build A_aug = [[A, w I], [-w I, A]].
virtual MatrixComp calculateSteadyStateStateFromInput(const MatrixComp &u, Real omega) const
Steady-state envelope state X_ss = (j w I - A)^-1 B u.
virtual void recomputeDiscreteModel(Real omega)
Discretize the augmented model and fold it into complex dA, dB, W.
void mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override final
MatrixComp mW
Complex Norton matrix W = C dB + D.
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override final
const Attribute< MatrixComp >::Ptr mX
Complex envelope state X.
const Matrix & getC() const
Get the continuous-time output matrix of the SSN model.
MatrixComp mDiscreteA
Complex envelope discrete operators (folded from the augmented model).
SSNComp(String uid, String name, Int inputSize, Int outputSize, Logger::Level logLevel=Logger::Level::off)
Matrix buildAugmentedB() const
Build B_aug = blkdiag(B, B).
const MatrixComp & getDiscreteB() const
Get the complex discrete input operator of the envelope model.
virtual MatrixComp calculateSteadyStateOutputFromInput(const MatrixComp &x, const MatrixComp &u) const
virtual Attribute< MatrixComp >::Ptr outputAttribute() const =0
void mnaCompPreStep(Real time, Int timeStepCount) override final
void setParameters(const Matrix &A, const Matrix &B, const Matrix &C, const Matrix &D)
String uid()
Returns unique id.
AttributeList::Ptr mAttributes
Attribute List.
spdlog::level::level_enum Level
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.
void updateMatrixNodeIndices()
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.