33 if (
A.rows() !=
A.cols())
34 throw std::invalid_argument(
"A must be square.");
36 if (
B.rows() !=
A.rows() ||
B.cols() != mInputSize)
37 throw std::invalid_argument(
"B has invalid dimensions.");
39 if (
C.rows() != mOutputSize ||
C.cols() !=
A.rows())
40 throw std::invalid_argument(
"C has invalid dimensions.");
42 if (D.rows() != mOutputSize || D.cols() != mInputSize)
43 throw std::invalid_argument(
"D has invalid dimensions.");
44 if (D1.size() != 0 && (D1.rows() != mOutputSize || D1.cols() != mInputSize))
45 throw std::invalid_argument(
"D1 has invalid dimensions.");
51 mD1 = D1.size() == 0 ? Matrix::Zero(mOutputSize, mInputSize) : D1;
53 **
mX = MatrixComp::Zero(
mA.rows(), 1);
58 mW = MatrixComp::Zero(mOutputSize, mInputSize);
59 mYHist = MatrixComp::Zero(mOutputSize, 1);
67 const Matrix::Index n =
mA.rows();
68 const Matrix wI = omega * Matrix::Identity(n, n);
70 Matrix aAug = Matrix::Zero(2 * n, 2 * n);
71 aAug.topLeftCorner(n, n) =
mA;
72 aAug.topRightCorner(n, n) = wI;
73 aAug.bottomLeftCorner(n, n) = -wI;
74 aAug.bottomRightCorner(n, n) =
mA;
79 const Matrix::Index n =
mA.rows();
81 Matrix bAug = Matrix::Zero(2 * n, 2 * mInputSize);
82 bAug.topLeftCorner(n, mInputSize) =
mB;
83 bAug.bottomRightCorner(n, mInputSize) =
mB;
88 const Matrix::Index n =
mA.rows();
93 Matrix dAaug = Matrix::Zero(2 * n, 2 * n);
94 Matrix dBaug = Matrix::Zero(2 * n, 2 * mInputSize);
102 dBaug.block(0, 0, n, mInputSize).cast<
Complex>() +
103 Complex(0., 1.) * dBaug.block(n, 0, n, mInputSize).cast<
Complex>();
126 Complex(0., omega) * MatrixComp::Identity(
mA.rows(),
mA.cols()) -
129 return h.inverse() *
mB.cast<
Complex>() * u;
152 throw std::logic_error(
153 "setParameters() must be called before initialization.");
156 throw std::logic_error(
157 "DP SSN components currently support a single carrier frequency.");
163 const UInt baseRowLimit =
static_cast<UInt>(leftVector->
get().rows() / 2);
167 if (index < baseRowLimit)
174 if (index < baseRowLimit)
188 mYHist.resize(mOutputSize, 1);
205 prevStepDependencies.push_back(
mX);
220 attributeDependencies.push_back(leftVector);
223 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
MatrixComp mStateUpdateInput
Reused post-step buffers for the trapezoidal state update.
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.
MatrixComp mHistoryState
Reused workspaces for the per-step history calculation.
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 + (2 / dt + j omega) D1.
void setParameters(const Matrix &A, const Matrix &B, const Matrix &C, const Matrix &D, const Matrix &D1=Matrix())
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override final
virtual void updateHistoryVector(MatrixComp &history)
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).
std::vector< UInt > mRightVectorAffectedIndices
MNA rows that may receive this component's compact history stamp.
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.
void mnaAddCompactRightSideVectorStamp(Matrix &rightVector) override final
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
Matrix mD1
Feedthrough from the envelope derivative of the input, for capacitive ports.
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 Complex complexFromVectorElement(const Matrix &mat, Matrix::Index row, Int maxFreq=1, Int freqIdx=0)
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.
static void addToVectorElement(Matrix &mat, Matrix::Index row, Complex value, Int maxFreq=1, Int freqIdx=0)
SimTerminal< Complex >::Ptr terminal(UInt index)
std::vector< UInt > virtualMatrixNodeIndices(UInt index)
UInt virtualNodesNumber()
SimNode< Complex >::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.