DPsim
Loading...
Searching...
No Matches
MNASimPowerComp.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2
4
5using namespace CPS;
6
7template <typename VarType>
11
12template <typename VarType>
16
17template <typename VarType>
19 mMnaTasks.clear();
20}
21
22template <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
41template <typename VarType>
43 Real omega, Real timeStep, std::vector<Attribute<Matrix>::Ptr> leftVector) {
44 mMnaTasks.clear();
45 this->mnaCompInitializeHarm(omega, timeStep, leftVector);
46}
47
48template <typename VarType>
50 SparseMatrixRow &systemMatrix) {
51 this->mnaCompApplySystemMatrixStamp(systemMatrix);
52 systemMatrix.makeCompressed();
53};
55template <typename VarType>
57 Matrix &rightVector) {
59};
61template <typename VarType>
63 this->mnaCompUpdateVoltage(leftVector);
64};
65
66template <typename VarType>
68 this->mnaCompUpdateCurrent(leftVector);
69};
70
71template <typename VarType>
73 this->mnaCompPreStep(time, timeStepCount);
74};
75
76template <typename VarType>
79 this->mnaCompPostStep(time, timeStepCount, leftVector);
80};
82template <typename VarType>
84 AttributeBase::List &prevStepDependencies,
85 AttributeBase::List &attributeDependencies,
86 AttributeBase::List &modifiedAttributes) {
88 prevStepDependencies, attributeDependencies, modifiedAttributes);
89};
91template <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);
101
102template <typename VarType>
104 SparseMatrixRow &systemMatrix, Int freqIdx) {
105 this->mnaCompApplySystemMatrixStampHarm(systemMatrix, freqIdx);
106};
107
108template <typename VarType>
113
114template <typename VarType>
116 Matrix &sourceVector, Int freqIdx) {
117 this->mnaCompApplyRightSideVectorStampHarm(sourceVector, freqIdx);
118};
119
120template <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
126template <typename VarType>
128 SparseMatrixRow &systemMatrix) {
129 // Empty default implementation. Can be overridden by child classes if desired.
130}
131
132template <typename VarType>
134 Matrix &rightVector) {
135 // Empty default implementation. Can be overridden by child classes if desired.
136}
137
138template <typename VarType>
140 // Empty default implementation. Can be overridden by child classes if desired.
141}
142
143template <typename VarType>
145 // Empty default implementation. Can be overridden by child classes if desired.
146}
147
148template <typename VarType>
150 // Empty default implementation. Can be overridden by child classes if desired.
151}
152
153template <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
159template <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
167template <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
176template <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
182template <typename VarType>
184 SparseMatrixRow &systemMatrix, Int freqIdx) {
185 // Empty default implementation. Can be overridden by child classes if desired.
186}
187
188template <typename VarType>
190 Matrix &sourceVector) {
191 // Empty default implementation. Can be overridden by child classes if desired.
192}
193
194template <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
201template class CPS::MNASimPowerComp<Real>;
202template class CPS::MNASimPowerComp<Complex>;
void mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes)
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector)
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:250
Base class for all MNA components that are transmitting power.
virtual void mnaCompPreStep(Real time, Int timeStepCount)
void mnaAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) final
Add MNA pre step dependencies.
virtual void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector)
virtual void mnaCompInitializeHarm(Real omega, Real timeStep, std::vector< Attribute< Matrix >::Ptr > leftVector)
Attribute< Matrix >::Ptr getRightVector() const final
Task::List mMnaTasks
List of tasks that relate to using MNA for this component (usually pre-step and/or post-step)
void mnaApplyRightSideVectorStampHarm(Matrix &sourceVector) final
Stamps right side (source) vector considering the frequency index.
virtual void mnaCompUpdateVoltage(const Matrix &leftVector)
void mnaApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) final
Stamps system matrix.
virtual void mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes)
virtual void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector)
void mnaAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) final
virtual void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix)
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.
virtual void mnaCompUpdateCurrent(const Matrix &leftVector)
const Task::List & mnaTasks() const final
Return list of MNA tasks.
void mnaInitialize(Real omega, Real timeStep) final
Initializes variables of components.
virtual void mnaCompApplyRightSideVectorStampHarm(Matrix &sourceVector)
Attribute< Matrix >::Ptr mRightVector
void mnaInitializeHarm(Real omega, Real timeStep, std::vector< Attribute< Matrix >::Ptr > leftVector) final
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.
virtual void mnaCompApplyRightSideVectorStamp(Matrix &rightVector)
void mnaApplyRightSideVectorStamp(Matrix &rightVector) final
Stamps right side (source) vector.
virtual void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector)
void mnaPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) final
virtual void mnaCompApplySystemMatrixStampHarm(SparseMatrixRow &systemMatrix, Int freqIdx)
std::vector< Ptr > List
Definition Task.h:28
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > Matrix
Dense matrix for real numbers.
Definition Definitions.h:81
double Real
Definition Definitions.h:62
int Int
Definition Definitions.h:61
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:74