DPsim
Loading...
Searching...
No Matches
MNASimPowerComp.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2
3#pragma once
4
8
9namespace CPS {
10
12template <typename VarType>
13class MNASimPowerComp : public SimPowerComp<VarType>, public MNAInterface {
14
15private:
16 Bool mHasPreStep;
17 Bool mHasPostStep;
18
19public:
20 using Type = VarType;
21 using Ptr = std::shared_ptr<MNASimPowerComp<VarType>>;
22 using List = std::vector<Ptr>;
23
27
30
32 MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep,
33 Logger::Level logLevel)
34 : SimPowerComp<VarType>(uid, name, logLevel), mHasPreStep(hasPreStep),
35 mHasPostStep(hasPostStep),
37 "right_vector")){};
38
40 explicit MNASimPowerComp(String name, Bool hasPreStep = true,
41 Bool hasPostStep = true,
42 Logger::Level logLevel = Logger::Level::off)
43 : MNASimPowerComp<VarType>(name, name, hasPreStep, hasPostStep,
44 logLevel){};
45
47 virtual ~MNASimPowerComp() = default;
48
49 // Implementation of MNAInterface methods
50 void mnaInitialize(Real omega, Real timeStep) final;
51 void mnaInitialize(Real omega, Real timeStep,
52 Attribute<Matrix>::Ptr leftVector) final;
53 void mnaApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) final;
54 void mnaApplyRightSideVectorStamp(Matrix &rightVector) final;
55 void mnaUpdateVoltage(const Matrix &leftVector) final;
56 void mnaUpdateCurrent(const Matrix &leftVector) final;
57 void mnaPreStep(Real time, Int timeStepCount) final;
58 void mnaPostStep(Real time, Int timeStepCount,
59 Attribute<Matrix>::Ptr &leftVector) final;
60 void mnaAddPreStepDependencies(AttributeBase::List &prevStepDependencies,
61 AttributeBase::List &attributeDependencies,
62 AttributeBase::List &modifiedAttributes) final;
63 void mnaAddPostStepDependencies(AttributeBase::List &prevStepDependencies,
64 AttributeBase::List &attributeDependencies,
65 AttributeBase::List &modifiedAttributes,
66 Attribute<Matrix>::Ptr &leftVector) final;
67 void mnaInitializeHarm(Real omega, Real timeStep,
68 std::vector<Attribute<Matrix>::Ptr> leftVector) final;
70 Int freqIdx) final;
71 void mnaApplyRightSideVectorStampHarm(Matrix &sourceVector) final;
73 Int freqIdx) final;
74
75 // MNA Interface methods that can be overridden by components
76 virtual void mnaCompInitialize(Real omega, Real timeStep,
77 Attribute<Matrix>::Ptr leftVector);
78 virtual void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix);
79 virtual void mnaCompApplyRightSideVectorStamp(Matrix &rightVector);
80 virtual void mnaCompUpdateVoltage(const Matrix &leftVector);
81 virtual void mnaCompUpdateCurrent(const Matrix &leftVector);
82 virtual void mnaCompPreStep(Real time, Int timeStepCount);
83 virtual void mnaCompPostStep(Real time, Int timeStepCount,
84 Attribute<Matrix>::Ptr &leftVector);
85 virtual void
87 AttributeBase::List &attributeDependencies,
88 AttributeBase::List &modifiedAttributes);
89 virtual void
91 AttributeBase::List &attributeDependencies,
92 AttributeBase::List &modifiedAttributes,
93 Attribute<Matrix>::Ptr &leftVector);
94 virtual void
95 mnaCompInitializeHarm(Real omega, Real timeStep,
96 std::vector<Attribute<Matrix>::Ptr> leftVector);
97 virtual void mnaCompApplySystemMatrixStampHarm(SparseMatrixRow &systemMatrix,
98 Int freqIdx);
99 virtual void mnaCompApplyRightSideVectorStampHarm(Matrix &sourceVector);
100 virtual void mnaCompApplyRightSideVectorStampHarm(Matrix &sourceVector,
101 Int freqIdx);
102
103 const Task::List &mnaTasks() const final;
104 Attribute<Matrix>::Ptr getRightVector() const final;
105
106 class MnaPreStep : public CPS::Task {
107 public:
109 : Task(**comp.mName + ".MnaPreStep"), mComp(comp) {
110 mComp.mnaAddPreStepDependencies(
112 }
113 void execute(Real time, Int timeStepCount) override {
114 mComp.mnaPreStep(time, timeStepCount);
115 };
116
117 private:
119 };
120
121 class MnaPostStep : public CPS::Task {
122 public:
124 Attribute<Matrix>::Ptr leftVector)
125 : Task(**comp.mName + ".MnaPostStep"), mComp(comp),
126 mLeftVector(leftVector) {
127 mComp.mnaAddPostStepDependencies(mPrevStepDependencies,
129 mModifiedAttributes, mLeftVector);
130 }
131 void execute(Real time, Int timeStepCount) override {
132 mComp.mnaPostStep(time, timeStepCount, mLeftVector);
133 };
134
135 private:
137 Attribute<Matrix>::Ptr mLeftVector;
138 };
139};
140} // namespace CPS
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:250
String uid()
Returns unique id.
AttributeList::Ptr mAttributes
Attribute List.
spdlog::level::level_enum Level
Definition Logger.h:33
Interface to be implemented by all models used by the MNA solver.
MnaPostStep(MNASimPowerComp< VarType > &comp, Attribute< Matrix >::Ptr leftVector)
void execute(Real time, Int timeStepCount) override
void execute(Real time, Int timeStepCount) override
MnaPreStep(MNASimPowerComp< VarType > &comp)
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
virtual ~MNASimPowerComp()=default
Destructor - does not do anything.
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.
std::vector< Ptr > List
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)
std::shared_ptr< MNASimPowerComp< VarType > > Ptr
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
Basic constructor that takes UID, name and log level.
Attribute< Matrix >::Ptr mRightVector
MNASimPowerComp(String name, Bool hasPreStep=true, Bool hasPostStep=true, Logger::Level logLevel=Logger::Level::off)
Basic constructor that takes name and log level and sets the UID to name as well.
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)
SimPowerComp(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Basic constructor that takes UID, name and log level.
Tasks to be defined by every component.
Definition Task.h:25
std::vector< AttributeBase::Ptr > mModifiedAttributes
Definition Task.h:53
std::vector< AttributeBase::Ptr > mPrevStepDependencies
Definition Task.h:54
std::vector< AttributeBase::Ptr > mAttributeDependencies
Definition Task.h:52
Task()
Definition Task.h:30
std::vector< Ptr > List
Definition Task.h:28
std::string mName
Definition Task.h:51
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > Matrix
Dense matrix for real numbers.
Definition Definitions.h:81
std::string String
Definition Definitions.h:65
double Real
Definition Definitions.h:62
int Int
Definition Definitions.h:61
bool Bool
Definition Definitions.h:64
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:74