DPsim
MNASimPowerComp.cpp
1 // SPDX-License-Identifier: Apache-2.0
2 
3 #include <dpsim-models/MNASimPowerComp.h>
4 
5 using namespace CPS;
6 
7 template <typename VarType>
8 const Task::List &MNASimPowerComp<VarType>::mnaTasks() const {
9  return mMnaTasks;
10 }
11 
12 template <typename VarType>
14  return mRightVector;
15 }
16 
17 template <typename VarType>
18 void MNASimPowerComp<VarType>::mnaInitialize(Real omega, Real timeStep) {
19  mMnaTasks.clear();
20 }
21 
22 template <typename VarType>
24  Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
25  mMnaTasks.clear();
26  **this->mRightVector = Matrix::Zero(leftVector->get().rows(), 1);
27 
28  if (mHasPreStep) {
29  this->mMnaTasks.push_back(
30  std::make_shared<typename MNASimPowerComp<VarType>::MnaPreStep>(*this));
31  }
32  if (mHasPostStep) {
33  this->mMnaTasks.push_back(
34  std::make_shared<typename MNASimPowerComp<VarType>::MnaPostStep>(
35  *this, leftVector));
36  }
37 
38  this->mnaCompInitialize(omega, timeStep, leftVector);
39 }
40 
41 template <typename VarType>
43  Real omega, Real timeStep, std::vector<Attribute<Matrix>::Ptr> leftVector) {
44  mMnaTasks.clear();
45  this->mnaCompInitializeHarm(omega, timeStep, leftVector);
46 }
47 
48 template <typename VarType>
50  SparseMatrixRow &systemMatrix) {
51  this->mnaCompApplySystemMatrixStamp(systemMatrix);
52  systemMatrix.makeCompressed();
53 };
54 
55 template <typename VarType>
57  Matrix &rightVector) {
58  this->mnaCompApplyRightSideVectorStamp(rightVector);
59 };
60 
61 template <typename VarType>
62 void MNASimPowerComp<VarType>::mnaUpdateVoltage(const Matrix &leftVector) {
63  this->mnaCompUpdateVoltage(leftVector);
64 };
65 
66 template <typename VarType>
67 void MNASimPowerComp<VarType>::mnaUpdateCurrent(const Matrix &leftVector) {
68  this->mnaCompUpdateCurrent(leftVector);
69 };
70 
71 template <typename VarType>
72 void MNASimPowerComp<VarType>::mnaPreStep(Real time, Int timeStepCount) {
73  this->mnaCompPreStep(time, timeStepCount);
74 };
75 
76 template <typename VarType>
77 void MNASimPowerComp<VarType>::mnaPostStep(Real time, Int timeStepCount,
78  Attribute<Matrix>::Ptr &leftVector) {
79  this->mnaCompPostStep(time, timeStepCount, leftVector);
80 };
81 
82 template <typename VarType>
84  AttributeBase::List &prevStepDependencies,
85  AttributeBase::List &attributeDependencies,
86  AttributeBase::List &modifiedAttributes) {
87  this->mnaCompAddPreStepDependencies(
88  prevStepDependencies, attributeDependencies, modifiedAttributes);
89 };
90 
91 template <typename VarType>
93  AttributeBase::List &prevStepDependencies,
94  AttributeBase::List &attributeDependencies,
95  AttributeBase::List &modifiedAttributes,
96  Attribute<Matrix>::Ptr &leftVector) {
97  this->mnaCompAddPostStepDependencies(prevStepDependencies,
98  attributeDependencies,
99  modifiedAttributes, leftVector);
100 };
101 
102 template <typename VarType>
104  SparseMatrixRow &systemMatrix, Int freqIdx) {
105  this->mnaCompApplySystemMatrixStampHarm(systemMatrix, freqIdx);
106 };
107 
108 template <typename VarType>
110  Matrix &sourceVector) {
111  this->mnaCompApplyRightSideVectorStampHarm(sourceVector);
112 };
113 
114 template <typename VarType>
116  Matrix &sourceVector, Int freqIdx) {
117  this->mnaCompApplyRightSideVectorStampHarm(sourceVector, freqIdx);
118 };
119 
120 template <typename VarType>
122  Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
123  // Empty default implementation. Can be overridden by child classes if desired.
124 }
125 
126 template <typename VarType>
128  SparseMatrixRow &systemMatrix) {
129  // Empty default implementation. Can be overridden by child classes if desired.
130 }
131 
132 template <typename VarType>
134  Matrix &rightVector) {
135  // Empty default implementation. Can be overridden by child classes if desired.
136 }
137 
138 template <typename VarType>
139 void MNASimPowerComp<VarType>::mnaCompUpdateVoltage(const Matrix &leftVector) {
140  // Empty default implementation. Can be overridden by child classes if desired.
141 }
142 
143 template <typename VarType>
144 void MNASimPowerComp<VarType>::mnaCompUpdateCurrent(const Matrix &leftVector) {
145  // Empty default implementation. Can be overridden by child classes if desired.
146 }
147 
148 template <typename VarType>
149 void MNASimPowerComp<VarType>::mnaCompPreStep(Real time, Int timeStepCount) {
150  // Empty default implementation. Can be overridden by child classes if desired.
151 }
152 
153 template <typename VarType>
155  Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
156  // Empty default implementation. Can be overridden by child classes if desired.
157 }
158 
159 template <typename VarType>
161  AttributeBase::List &prevStepDependencies,
162  AttributeBase::List &attributeDependencies,
163  AttributeBase::List &modifiedAttributes) {
164  // Empty default implementation. Can be overridden by child classes if desired.
165 }
166 
167 template <typename VarType>
169  AttributeBase::List &prevStepDependencies,
170  AttributeBase::List &attributeDependencies,
171  AttributeBase::List &modifiedAttributes,
172  Attribute<Matrix>::Ptr &leftVector) {
173  // Empty default implementation. Can be overridden by child classes if desired.
174 }
175 
176 template <typename VarType>
178  Real omega, Real timeStep, std::vector<Attribute<Matrix>::Ptr> leftVector) {
179  // Empty default implementation. Can be overridden by child classes if desired.
180 }
181 
182 template <typename VarType>
184  SparseMatrixRow &systemMatrix, Int freqIdx) {
185  // Empty default implementation. Can be overridden by child classes if desired.
186 }
187 
188 template <typename VarType>
190  Matrix &sourceVector) {
191  // Empty default implementation. Can be overridden by child classes if desired.
192 }
193 
194 template <typename VarType>
196  Matrix &sourceVector, Int freqIdx) {
197  // Empty default implementation. Can be overridden by child classes if desired.
198 }
199 
200 // Declare specializations to move definitions to .cpp
201 template class CPS::MNASimPowerComp<Real>;
202 template class CPS::MNASimPowerComp<Complex>;
virtual T & get()=0
Base class for all MNA components that are transmitting power.
void mnaAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) final
Add MNA pre step dependencies.
void mnaApplyRightSideVectorStampHarm(Matrix &sourceVector) final
Stamps right side (source) vector considering the frequency index.
void mnaApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) final
Stamps system matrix.
void mnaUpdateCurrent(const Matrix &leftVector) final
Update interface current from MNA system result.
void mnaUpdateVoltage(const Matrix &leftVector) final
Update interface voltage from MNA system result.
const Task::List & mnaTasks() const final
Return list of MNA tasks.
void mnaInitialize(Real omega, Real timeStep) final
Initializes variables of components.
void mnaPreStep(Real time, Int timeStepCount) final
MNA pre step operations.
void mnaApplySystemMatrixStampHarm(SparseMatrixRow &systemMatrix, Int freqIdx) final
Stamps system matrix considering the frequency index.
void mnaApplyRightSideVectorStamp(Matrix &rightVector) final
Stamps right side (source) vector.