DPsim
Loading...
Searching...
No Matches
CompositePowerComp.h
1// SPDX-License-Identifier: Apache-2.0
2
3#pragma once
4
5#include <dpsim-models/MNASimPowerComp.h>
6
7namespace CPS {
8enum class MNA_SUBCOMP_TASK_ORDER {
9 NO_TASK,
10 TASK_BEFORE_PARENT,
11 TASK_AFTER_PARENT
12};
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
27protected:
30 bool mSubCompCreated = false;
31
32public:
33 using Type = VarType;
34 using Ptr = std::shared_ptr<CompositePowerComp<VarType>>;
35 using List = std::vector<Ptr>;
36
38 CompositePowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep,
39 Logger::Level logLevel)
40 : MNASimPowerComp<VarType>(uid, name, hasPreStep, hasPostStep, logLevel) {
41 }
42
44 CompositePowerComp(String name, Bool hasPreStep = true,
45 Bool hasPostStep = true,
46 Logger::Level logLevel = Logger::Level::off)
47 : CompositePowerComp<VarType>(name, name, hasPreStep, hasPostStep,
48 logLevel) {}
49
51 virtual ~CompositePowerComp() = default;
52
56 void initializeFromNodesAndTerminals(Real frequency) override final;
57
63 virtual void initializeParentFromNodesAndTerminals(Real frequency) = 0;
64
69 void addMNASubComponent(typename SimPowerComp<VarType>::Ptr subc,
70 MNA_SUBCOMP_TASK_ORDER preStepOrder,
71 MNA_SUBCOMP_TASK_ORDER postStepOrder,
72 Bool contributeToRightVector);
73
74 // #### MNA Interface Functions ####
76 void mnaCompInitialize(Real omega, Real timeStep,
77 Attribute<Matrix>::Ptr leftVector) override;
79 void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override;
81 void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override;
83 void mnaCompPreStep(Real time, Int timeStepCount) override;
85 void mnaCompPostStep(Real time, Int timeStepCount,
86 Attribute<Matrix>::Ptr &leftVector) override;
89 AttributeBase::List &prevStepDependencies,
90 AttributeBase::List &attributeDependencies,
91 AttributeBase::List &modifiedAttributes) override;
93 void
94 mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies,
95 AttributeBase::List &attributeDependencies,
96 AttributeBase::List &modifiedAttributes,
97 Attribute<Matrix>::Ptr &leftVector) override;
98
99 // #### MNA Parent Functions ####
100 virtual void mnaParentInitialize(Real omega, Real timeStep,
101 Attribute<Matrix>::Ptr leftVector){
102 // By default, the parent has no custom initialization beyond what is done in CompositePowerComp::mnaCompInitialize
103 };
104 virtual void mnaParentApplySystemMatrixStamp(SparseMatrixRow &systemMatrix){
105 // By default, the parent has no custom stamp on the system matrix, only the subcomponents are stamped
106 };
107 virtual void mnaParentApplyRightSideVectorStamp(Matrix &rightVector){
108 // By default, the parent has no custom stamp on the right vector, only the subcomponents are stamped
109 };
110 virtual void mnaParentPreStep(Real time, Int timeStepCount){
111 // By default, the parent has no custom pre-step, only the subcomponents' pre-steps are executed
112 };
113 virtual void mnaParentPostStep(Real time, Int timeStepCount,
114 Attribute<Matrix>::Ptr &leftVector){
115 // By default, the parent has no custom post-step, only the subcomponents' post-steps are executed
116 };
117 virtual void
118 mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies,
119 AttributeBase::List &attributeDependencies,
120 AttributeBase::List &modifiedAttributes){
121 // By default, the parent has no custom pre-step-dependencies, only the subcomponents' dependencies are added
122 };
123 virtual void
124 mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies,
125 AttributeBase::List &attributeDependencies,
126 AttributeBase::List &modifiedAttributes,
127 Attribute<Matrix>::Ptr &leftVector){
128 // By default, the parent has no custom post-step-dependencies, only the subcomponents' dependencies are added
129 };
130};
131} // namespace CPS
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.
void initializeFromNodesAndTerminals(Real frequency) override final
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
Stamps system matrix.
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.
void mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
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.
MNASimPowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep, Logger::Level logLevel)
Basic constructor that takes UID, name and log level.