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
57 const MNAInterface::List &mnaSubComponents() const noexcept {
58 return mSubcomponentsMNA;
59 }
60
64 void initializeFromNodesAndTerminals(Real frequency) override final;
65
71 virtual void initializeParentFromNodesAndTerminals(Real frequency) = 0;
72
77 void addMNASubComponent(typename SimPowerComp<VarType>::Ptr subc,
78 MNA_SUBCOMP_TASK_ORDER preStepOrder,
79 MNA_SUBCOMP_TASK_ORDER postStepOrder,
80 Bool contributeToRightVector);
81
82 // #### MNA Interface Functions ####
84 void mnaCompInitialize(Real omega, Real timeStep,
85 Attribute<Matrix>::Ptr leftVector) override;
87 void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override;
89 void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override;
91 void mnaCompPreStep(Real time, Int timeStepCount) override;
93 void mnaCompPostStep(Real time, Int timeStepCount,
94 Attribute<Matrix>::Ptr &leftVector) override;
97 AttributeBase::List &prevStepDependencies,
98 AttributeBase::List &attributeDependencies,
99 AttributeBase::List &modifiedAttributes) override;
101 void
102 mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies,
103 AttributeBase::List &attributeDependencies,
104 AttributeBase::List &modifiedAttributes,
105 Attribute<Matrix>::Ptr &leftVector) override;
106
107 // #### MNA Parent Functions ####
108 virtual void mnaParentInitialize(Real omega, Real timeStep,
109 Attribute<Matrix>::Ptr leftVector){
110 // By default, the parent has no custom initialization beyond what is done in CompositePowerComp::mnaCompInitialize
111 };
112 virtual void mnaParentApplySystemMatrixStamp(SparseMatrixRow &systemMatrix){
113 // By default, the parent has no custom stamp on the system matrix, only the subcomponents are stamped
114 };
115 virtual void mnaParentApplyRightSideVectorStamp(Matrix &rightVector){
116 // By default, the parent has no custom stamp on the right vector, only the subcomponents are stamped
117 };
118 virtual void mnaParentPreStep(Real time, Int timeStepCount){
119 // By default, the parent has no custom pre-step, only the subcomponents' pre-steps are executed
120 };
121 virtual void mnaParentPostStep(Real time, Int timeStepCount,
122 Attribute<Matrix>::Ptr &leftVector){
123 // By default, the parent has no custom post-step, only the subcomponents' post-steps are executed
124 };
125 virtual void
126 mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies,
127 AttributeBase::List &attributeDependencies,
128 AttributeBase::List &modifiedAttributes){
129 // By default, the parent has no custom pre-step-dependencies, only the subcomponents' dependencies are added
130 };
131 virtual void
132 mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies,
133 AttributeBase::List &attributeDependencies,
134 AttributeBase::List &modifiedAttributes,
135 Attribute<Matrix>::Ptr &leftVector){
136 // By default, the parent has no custom post-step-dependencies, only the subcomponents' dependencies are added
137 };
138};
139} // 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.
const MNAInterface::List & mnaSubComponents() const noexcept
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.