4#include <dpsim-models/EMT/EMT_SSNComp.h>
8EMT::SSNComp::SSNComp(String uid, String name, Int inputSize, Int outputSize,
9 Logger::Level logLevel)
10 :
MNASimPowerComp<Real>(uid, name, true, true, logLevel), mTimeStep(0.0),
11 mW(Matrix::Zero(outputSize, inputSize)),
12 mYHist(Matrix::Zero(outputSize, 1)), mInputSize(inputSize),
13 mOutputSize(outputSize), mX(mAttributes->create<Matrix>(
"x")) {
14 mParametersSet =
false;
17void EMT::SSNComp::setParameters(
const Matrix &A,
const Matrix &B,
18 const Matrix &C,
const Matrix &D) {
21 if (A.rows() != A.cols())
22 throw std::invalid_argument(
"A must be square.");
24 if (B.rows() != A.rows() || B.cols() != mInputSize)
25 throw std::invalid_argument(
"B has invalid dimensions.");
27 if (C.rows() != mOutputSize || C.cols() != A.rows())
28 throw std::invalid_argument(
"C has invalid dimensions.");
30 if (D.rows() != mOutputSize || D.cols() != mInputSize)
31 throw std::invalid_argument(
"D has invalid dimensions.");
38 **mX = Matrix::Zero(mA.rows(), 1);
40 mdA = Matrix::Zero(mA.rows(), mA.cols());
41 mdB = Matrix::Zero(mB.rows(), mB.cols());
43 mW = Matrix::Zero(mOutputSize, mInputSize);
44 mYHist = Matrix::Zero(mOutputSize, 1);
49Matrix EMT::SSNComp::calculateHistoryVector()
const {
50 return mC * (mdA * (**mX) + mdB * (**inputAttribute()));
54EMT::SSNComp::calculateSteadyStateStateFromInput(
const MatrixComp &u,
55 Real frequency)
const {
56 const Real omega = 2.0 * PI * frequency;
58 Complex(0.0, omega) * MatrixComp::Identity(mA.rows(), mA.cols()) -
61 return h.inverse() * mB.cast<Complex>() * u;
65EMT::SSNComp::calculateSteadyStateOutputFromInput(
const MatrixComp &x,
66 const MatrixComp &u)
const {
67 return mC.cast<Complex>() * x + mD.cast<Complex>() * u;
70void EMT::SSNComp::updateState(
const Matrix &uOld,
const Matrix &uNew) {
71 **mX = mdA * (**mX) + mdB * (uNew + uOld);
74void EMT::SSNComp::recomputeDiscreteModel() {
83void EMT::SSNComp::mnaCompInitialize(Real, Real timeStep,
84 Attribute<Matrix>::Ptr) {
86 throw std::logic_error(
87 "setParameters() must be called before initialization.");
90 updateMatrixNodeIndices();
92 recomputeDiscreteModel();
93 mYHist = calculateHistoryVector();
96void EMT::SSNComp::mnaCompAddPreStepDependencies(
97 AttributeBase::List &prevStepDependencies,
98 AttributeBase::List &attributeDependencies,
99 AttributeBase::List &modifiedAttributes) {
100 modifiedAttributes.push_back(mRightVector);
101 prevStepDependencies.push_back(mX);
102 prevStepDependencies.push_back(inputAttribute());
105void EMT::SSNComp::mnaCompPreStep(Real time, Int timeStepCount) {
106 updateStateSpaceModel();
107 mYHist = calculateHistoryVector();
108 mnaCompApplyRightSideVectorStamp(**mRightVector);
111void EMT::SSNComp::mnaCompAddPostStepDependencies(
112 AttributeBase::List &prevStepDependencies,
113 AttributeBase::List &attributeDependencies,
114 AttributeBase::List &modifiedAttributes,
115 Attribute<Matrix>::Ptr &leftVector) {
116 attributeDependencies.push_back(leftVector);
117 modifiedAttributes.push_back(inputAttribute());
118 modifiedAttributes.push_back(outputAttribute());
119 modifiedAttributes.push_back(mX);
virtual void updateStateSpaceModel()
Hook for variable/time-varying SSN components.
Base class for all MNA components that are transmitting power.
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.
bool mParametersSet
Flag indicating that parameters are set via setParameters() function.