DPsim
CompositePowerComp.h
1 // SPDX-License-Identifier: Apache-2.0
2 
3 #pragma once
4 
5 #include <dpsim-models/MNASimPowerComp.h>
6 
7 namespace CPS {
8 enum class MNA_SUBCOMP_TASK_ORDER {
9  NO_TASK,
10  TASK_BEFORE_PARENT,
11  TASK_AFTER_PARENT
12 };
13 
15 template <typename VarType>
16 class CompositePowerComp : public MNASimPowerComp<VarType> {
17 
18 private:
19  MNAInterface::List mSubcomponentsMNA;
20  MNAInterface::List mSubcomponentsBeforePreStep;
21  MNAInterface::List mSubcomponentsAfterPreStep;
22  MNAInterface::List mSubcomponentsBeforePostStep;
23  MNAInterface::List mSubcomponentsAfterPostStep;
24 
25  std::vector<CPS::Attribute<Matrix>::Ptr> mRightVectorStamps;
26 
27 public:
28  using Type = VarType;
29  using Ptr = std::shared_ptr<CompositePowerComp<VarType>>;
30  using List = std::vector<Ptr>;
31 
33  CompositePowerComp(String uid, String name, Bool hasPreStep, Bool hasPostStep,
34  Logger::Level logLevel)
35  : MNASimPowerComp<VarType>(uid, name, hasPreStep, hasPostStep, logLevel) {
36  }
37 
39  CompositePowerComp(String name, Bool hasPreStep = true,
40  Bool hasPostStep = true,
41  Logger::Level logLevel = Logger::Level::off)
42  : CompositePowerComp<VarType>(name, name, hasPreStep, hasPostStep,
43  logLevel) {}
44 
46  virtual ~CompositePowerComp() = default;
47 
52  void addMNASubComponent(typename SimPowerComp<VarType>::Ptr subc,
53  MNA_SUBCOMP_TASK_ORDER preStepOrder,
54  MNA_SUBCOMP_TASK_ORDER postStepOrder,
55  Bool contributeToRightVector);
56 
57  // #### MNA Interface Functions ####
59  void mnaCompInitialize(Real omega, Real timeStep,
60  Attribute<Matrix>::Ptr leftVector) override;
62  void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override;
64  void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override;
66  void mnaCompPreStep(Real time, Int timeStepCount) override;
68  void mnaCompPostStep(Real time, Int timeStepCount,
69  Attribute<Matrix>::Ptr &leftVector) override;
72  AttributeBase::List &prevStepDependencies,
73  AttributeBase::List &attributeDependencies,
74  AttributeBase::List &modifiedAttributes) override;
76  void
77  mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies,
78  AttributeBase::List &attributeDependencies,
79  AttributeBase::List &modifiedAttributes,
80  Attribute<Matrix>::Ptr &leftVector) override;
81 
82  // #### MNA Parent Functions ####
83  virtual void mnaParentInitialize(Real omega, Real timeStep,
84  Attribute<Matrix>::Ptr leftVector){
85  // By default, the parent has no custom initialization beyond what is done in CompositePowerComp::mnaCompInitialize
86  };
87  virtual void mnaParentApplySystemMatrixStamp(SparseMatrixRow &systemMatrix){
88  // By default, the parent has no custom stamp on the system matrix, only the subcomponents are stamped
89  };
90  virtual void mnaParentApplyRightSideVectorStamp(Matrix &rightVector){
91  // By default, the parent has no custom stamp on the right vector, only the subcomponents are stamped
92  };
93  virtual void mnaParentPreStep(Real time, Int timeStepCount){
94  // By default, the parent has no custom pre-step, only the subcomponents' pre-steps are executed
95  };
96  virtual void mnaParentPostStep(Real time, Int timeStepCount,
97  Attribute<Matrix>::Ptr &leftVector){
98  // By default, the parent has no custom post-step, only the subcomponents' post-steps are executed
99  };
100  virtual void
101  mnaParentAddPreStepDependencies(AttributeBase::List &prevStepDependencies,
102  AttributeBase::List &attributeDependencies,
103  AttributeBase::List &modifiedAttributes){
104  // By default, the parent has no custom pre-step-dependencies, only the subcomponents' dependencies are added
105  };
106  virtual void
107  mnaParentAddPostStepDependencies(AttributeBase::List &prevStepDependencies,
108  AttributeBase::List &attributeDependencies,
109  AttributeBase::List &modifiedAttributes,
110  Attribute<Matrix>::Ptr &leftVector){
111  // By default, the parent has no custom post-step-dependencies, only the subcomponents' dependencies are added
112  };
113 };
114 } // namespace CPS
Base class for composite power components.
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.
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 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.
Base class for all MNA components that are transmitting power.