DPsim
Loading...
Searching...
No Matches
MNASimPowerComp.cpp
1// SPDX-License-Identifier: Apache-2.0
2
3#include <dpsim-models/MNASimPowerComp.h>
4
5using namespace CPS;
6
7template <typename VarType>
8const Task::List &MNASimPowerComp<VarType>::mnaTasks() const {
9 return mMnaTasks;
10}
11
12template <typename VarType>
13Attribute<Matrix>::Ptr MNASimPowerComp<VarType>::getRightVector() const {
14 return mRightVector;
15}
16
17template <typename VarType>
18void MNASimPowerComp<VarType>::mnaInitialize(Real omega, Real timeStep) {
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>
42void MNASimPowerComp<VarType>::mnaInitializeHarm(
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) {
58 this->mnaCompApplyRightSideVectorStamp(rightVector);
59};
61template <typename VarType>
62void MNASimPowerComp<VarType>::mnaUpdateVoltage(const Matrix &leftVector) {
63 this->mnaCompUpdateVoltage(leftVector);
64};
65
66template <typename VarType>
67void MNASimPowerComp<VarType>::mnaUpdateCurrent(const Matrix &leftVector) {
68 this->mnaCompUpdateCurrent(leftVector);
69};
70
71template <typename VarType>
72void MNASimPowerComp<VarType>::mnaPreStep(Real time, Int timeStepCount) {
73 this->mnaCompPreStep(time, timeStepCount);
74};
75
76template <typename VarType>
77void MNASimPowerComp<VarType>::mnaPostStep(Real time, Int timeStepCount,
78 Attribute<Matrix>::Ptr &leftVector) {
79 this->mnaCompPostStep(time, timeStepCount, leftVector);
80};
81
82template <typename VarType>
84 AttributeBase::List &prevStepDependencies,
85 AttributeBase::List &attributeDependencies,
86 AttributeBase::List &modifiedAttributes) {
87 this->mnaCompAddPreStepDependencies(
88 prevStepDependencies, attributeDependencies, modifiedAttributes);
89};
90
91template <typename VarType>
92void MNASimPowerComp<VarType>::mnaAddPostStepDependencies(
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
102template <typename VarType>
104 SparseMatrixRow &systemMatrix, Int freqIdx) {
105 this->mnaCompApplySystemMatrixStampHarm(systemMatrix, freqIdx);
106};
107
108template <typename VarType>
110 Matrix &sourceVector) {
111 this->mnaCompApplyRightSideVectorStampHarm(sourceVector);
112};
113
114template <typename VarType>
116 Matrix &sourceVector, Int freqIdx) {
117 this->mnaCompApplyRightSideVectorStampHarm(sourceVector, freqIdx);
118};
119
120template <typename VarType>
121void MNASimPowerComp<VarType>::mnaCompInitialize(
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>
127void MNASimPowerComp<VarType>::mnaCompApplySystemMatrixStamp(
128 SparseMatrixRow &systemMatrix) {
129 // Empty default implementation. Can be overridden by child classes if desired.
130}
131
132template <typename VarType>
133void MNASimPowerComp<VarType>::mnaCompApplyRightSideVectorStamp(
134 Matrix &rightVector) {
135 // Empty default implementation. Can be overridden by child classes if desired.
136}
137
138template <typename VarType>
139void MNASimPowerComp<VarType>::mnaCompUpdateVoltage(const Matrix &leftVector) {
140 // Empty default implementation. Can be overridden by child classes if desired.
141}
142
143template <typename VarType>
144void MNASimPowerComp<VarType>::mnaCompUpdateCurrent(const Matrix &leftVector) {
145 // Empty default implementation. Can be overridden by child classes if desired.
146}
147
148template <typename VarType>
149void MNASimPowerComp<VarType>::mnaCompPreStep(Real time, Int timeStepCount) {
150 // Empty default implementation. Can be overridden by child classes if desired.
151}
152
153template <typename VarType>
154void MNASimPowerComp<VarType>::mnaCompPostStep(
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>
160void MNASimPowerComp<VarType>::mnaCompAddPreStepDependencies(
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>
168void MNASimPowerComp<VarType>::mnaCompAddPostStepDependencies(
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>
177void MNASimPowerComp<VarType>::mnaCompInitializeHarm(
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>
183void MNASimPowerComp<VarType>::mnaCompApplySystemMatrixStampHarm(
184 SparseMatrixRow &systemMatrix, Int freqIdx) {
185 // Empty default implementation. Can be overridden by child classes if desired.
186}
187
188template <typename VarType>
189void MNASimPowerComp<VarType>::mnaCompApplyRightSideVectorStampHarm(
190 Matrix &sourceVector) {
191 // Empty default implementation. Can be overridden by child classes if desired.
192}
193
194template <typename VarType>
195void MNASimPowerComp<VarType>::mnaCompApplyRightSideVectorStampHarm(
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>;
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.
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.
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.