DPsim
Loading...
Searching...
No Matches
CompositePowerComp.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2
3#pragma once
4
6
7namespace CPS {
13
15template <typename VarType>
16class CompositePowerComp : public MNASimPowerComp<VarType> {
17
18private:
19 MNAInterface::List mSubcomponentsMNA;
20 MNAInterface::List mSubcomponentsPreStepBeforeParent;
21 MNAInterface::List mSubcomponentsPreStepAfterParent;
22 MNAInterface::List mSubcomponentsPostStepBeforeParent;
23 MNAInterface::List mSubcomponentsPostStepAfterParent;
24
25 std::vector<CPS::Attribute<Matrix>::Ptr> mRightVectorStamps;
26 std::vector<typename SimPowerComp<VarType>::Ptr> mRightVectorStampComponents;
27 std::vector<std::vector<UInt>> mRightVectorStampIndices;
28 std::vector<UInt> mRightVectorAffectedIndices;
29 Bool mRightVectorStampIndicesInitialized = false;
30
31protected:
34 bool mSubCompCreated = false;
35
36public:
37 using Type = VarType;
38 using Ptr = std::shared_ptr<CompositePowerComp<VarType>>;
39 using List = std::vector<Ptr>;
40
42 CompositePowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep,
43 Logger::Level logLevel)
44 : MNASimPowerComp<VarType>(uid, name, hasPreStep, hasPostStep, logLevel) {
45 }
46
48 CompositePowerComp(String name, Bool hasPreStep = true,
49 Bool hasPostStep = true,
50 Logger::Level logLevel = Logger::Level::off)
51 : CompositePowerComp<VarType>(name, name, hasPreStep, hasPostStep,
52 logLevel) {}
53
55 virtual ~CompositePowerComp() = default;
56
61 const MNAInterface::List &mnaSubComponents() const noexcept {
62 return mSubcomponentsMNA;
63 }
64
68 void initializeFromNodesAndTerminals(Real frequency) override final;
69
75 virtual void initializeParentFromNodesAndTerminals(Real frequency) = 0;
76
82 MNA_SUBCOMP_TASK_ORDER preStepOrder,
83 MNA_SUBCOMP_TASK_ORDER postStepOrder,
84 Bool contributeToRightVector);
85
86 // #### MNA Interface Functions ####
88 void mnaCompInitialize(Real omega, Real timeStep,
89 Attribute<Matrix>::Ptr leftVector) override;
91 void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override;
93 void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override;
96 return mRightVectorStampIndicesInitialized;
97 }
98 void mnaAddCompactRightSideVectorStamp(Matrix &rightVector) override;
100 void mnaCompPreStep(Real time, Int timeStepCount) override;
102 void mnaCompPostStep(Real time, Int timeStepCount,
103 Attribute<Matrix>::Ptr &leftVector) override;
106 AttributeBase::List &prevStepDependencies,
107 AttributeBase::List &attributeDependencies,
108 AttributeBase::List &modifiedAttributes) override;
110 void
112 AttributeBase::List &attributeDependencies,
113 AttributeBase::List &modifiedAttributes,
114 Attribute<Matrix>::Ptr &leftVector) override;
115
116 // #### MNA Parent Functions ####
117 virtual void mnaParentInitialize(Real omega, Real timeStep,
118 Attribute<Matrix>::Ptr leftVector){
119 // By default, the parent has no custom initialization beyond what is done in CompositePowerComp::mnaCompInitialize
120 };
122 // By default, the parent has no custom stamp on the system matrix, only the subcomponents are stamped
123 };
124 virtual void mnaParentApplyRightSideVectorStamp(Matrix &rightVector){
125 // By default, the parent has no custom stamp on the right vector, only the subcomponents are stamped
126 };
127 virtual void mnaParentPreStep(Real time, Int timeStepCount){
128 // By default, the parent has no custom pre-step, only the subcomponents' pre-steps are executed
129 };
130 virtual void mnaParentPostStep(Real time, Int timeStepCount,
131 Attribute<Matrix>::Ptr &leftVector){
132 // By default, the parent has no custom post-step, only the subcomponents' post-steps are executed
133 };
134 virtual void
136 AttributeBase::List &attributeDependencies,
137 AttributeBase::List &modifiedAttributes){
138 // By default, the parent has no custom pre-step-dependencies, only the subcomponents' dependencies are added
139 };
140 virtual void
142 AttributeBase::List &attributeDependencies,
143 AttributeBase::List &modifiedAttributes,
144 Attribute<Matrix>::Ptr &leftVector){
145 // By default, the parent has no custom post-step-dependencies, only the subcomponents' dependencies are added
146 };
147};
148} // namespace CPS
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:249
virtual void mnaParentApplySystemMatrixStamp(SparseMatrixRow &systemMatrix)
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
Initializes variables of components.
void addMNASubComponent(typename SimPowerComp< VarType >::Ptr subc, MNA_SUBCOMP_TASK_ORDER preStepOrder, MNA_SUBCOMP_TASK_ORDER postStepOrder, Bool contributeToRightVector)
Add a new subcomponent implementing MNA methods.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
virtual void initializeParentFromNodesAndTerminals(Real frequency)=0
CompositePowerComp(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.
Bool mnaHasCompactRightSideVectorStamp() const override
Composite stamps touch only their cached terminal and virtual-node rows.
std::shared_ptr< CompositePowerComp< VarType > > Ptr
virtual void mnaParentApplyRightSideVectorStamp(Matrix &rightVector)
const MNAInterface::List & mnaSubComponents() const noexcept
void initializeFromNodesAndTerminals(Real frequency) override final
void mnaAddCompactRightSideVectorStamp(Matrix &rightVector) override
virtual void mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes)
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
virtual void mnaParentPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector)
virtual void mnaParentInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector)
void mnaCompPreStep(Real time, Int timeStepCount) override
MNA pre step operations.
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
Stamps right side (source) vector.
virtual ~CompositePowerComp()=default
Destructor - does not do anything.
virtual void mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector)
void mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
virtual void mnaParentPreStep(Real time, Int timeStepCount)
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
MNA post step operations.
CompositePowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
Basic constructor that takes UID, name and log level.
String uid()
Returns unique id.
spdlog::level::level_enum Level
Definition Logger.h:33
std::vector< Ptr > List
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
Basic constructor that takes UID, name and log level.
std::shared_ptr< SimPowerComp< VarType > > Ptr
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > Matrix
Dense matrix for real numbers.
Definition Definitions.h:79
std::string String
Definition Definitions.h:63
MNA_SUBCOMP_TASK_ORDER
double Real
Definition Definitions.h:60
int Int
Definition Definitions.h:59
bool Bool
Definition Definitions.h:62
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:72