DPsim
SimPowerComp.h
1 /* Copyright 2017-2021 Institute for Automation of Complex Power Systems,
2  * EONERC, RWTH Aachen University
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7  *********************************************************************************/
8 
9 #pragma once
10 
11 #include <dpsim-models/SimNode.h>
12 #include <dpsim-models/SimTerminal.h>
13 #include <dpsim-models/TopologicalPowerComp.h>
14 
15 namespace CPS {
17 template <typename VarType> class SimPowerComp : public TopologicalPowerComp {
18 
19 protected:
21  typename SimTerminal<VarType>::List mTerminals;
23  typename SimNode<VarType>::List mVirtualNodes;
25  Matrix mFrequencies;
27  UInt mNumFreqs = 0;
29  PhaseType mPhaseType = PhaseType::Single;
30 
33  typename std::vector<std::shared_ptr<SimPowerComp<VarType>>> mSubComponents;
35  std::vector<UInt> mMatrixNodeIndices;
37  std::vector<bool> mMatrixNodeIndexIsGround;
38 
39 public:
40  typedef VarType Type;
41  typedef std::shared_ptr<SimPowerComp<VarType>> Ptr;
42  typedef std::vector<Ptr> List;
43 
48 
50  SimPowerComp(String uid, String name,
51  Logger::Level logLevel = Logger::Level::off);
53  SimPowerComp(String name, Logger::Level logLevel = Logger::Level::off)
54  : SimPowerComp(name, name, logLevel) {}
56  virtual ~SimPowerComp() {}
57 
59  virtual typename SimPowerComp<VarType>::Ptr clone(String name);
60 
61  // #### Terminals ####
63  UInt terminalNumber();
67  Bool hasUnconnectedTerminals();
69  void checkForUnconnectedTerminals();
71  typename SimTerminal<VarType>::List terminals();
73  typename SimTerminal<VarType>::Ptr terminal(UInt index);
75  TopologicalTerminal::List topologicalTerminals();
77  void setTerminalNumber(UInt num);
80  void setTerminals(typename SimTerminal<VarType>::List terminals);
82  void setTerminalAt(typename SimTerminal<VarType>::Ptr terminal,
83  UInt terminalPosition);
84 
87 
88  // #### Nodes ####
90  UInt nodeNumber();
92  typename SimNode<VarType>::Ptr node(UInt index);
93 
94  UInt matrixNodeIndex(UInt nodeIndex);
95 
96  UInt matrixNodeIndex(UInt nodeIndex, UInt phaseIndex);
98  std::vector<UInt> matrixNodeIndices(UInt index);
100  TopologicalNode::List topologicalNodes();
101 
102  // #### Virtual Nodes ####
104  UInt virtualNodesNumber();
106  Bool hasVirtualNodes();
108  Bool hasSubComponents();
110  typename SimPowerComp<VarType>::List subComponents();
112  typename SimNode<VarType>::List &virtualNodes();
114  typename SimNode<VarType>::Ptr virtualNode(UInt index);
116  std::vector<UInt> virtualMatrixNodeIndices(UInt index);
118  UInt virtualSimNode(UInt nodeIndex, UInt phaseIndex = 0);
119 
120  // #### States ####
121  const MatrixVar<VarType> &intfCurrent();
123  const MatrixVar<VarType> &intfVoltage();
125  MatrixComp initialVoltage(UInt index);
127  Complex initialSingleVoltage(UInt index);
129  Bool terminalNotGrounded(UInt index);
130 
131  // #### Setters ####
132  void setIntfCurrent(MatrixVar<VarType> current);
134  void setIntfVoltage(MatrixVar<VarType> voltage);
136  void setVirtualNodeNumber(UInt num);
138  void setVirtualNodeAt(typename SimNode<VarType>::Ptr virtualNode,
139  UInt nodeNum);
141  void connect(typename SimNode<VarType>::List nodes);
142 
143  // #### Calculations ####
145  virtual void initialize(Matrix frequencies);
147  virtual void initializeFromNodesAndTerminals(Real frequency) {}
148 };
149 } // namespace CPS
String uid()
Returns unique id.
Base class for all components that are transmitting power.
Definition: SimPowerComp.h:17
UInt mNumFreqs
Number of network frequencies.
Definition: SimPowerComp.h:27
void setVirtualNodeAt(typename SimNode< VarType >::Ptr virtualNode, UInt nodeNum)
Sets the virtual node at index nodeNum.
SimTerminal< VarType >::List mTerminals
List of Terminals.
Definition: SimPowerComp.h:21
Bool hasVirtualNodes()
Returns true if virtual node number is greater than zero.
std::vector< bool > mMatrixNodeIndexIsGround
"Cached" flags for whether the connected nodes are grounded
Definition: SimPowerComp.h:37
UInt terminalNumber()
Returns nominal number of Terminals for this component type.
UInt virtualSimNode(UInt nodeIndex, UInt phaseIndex=0)
Get simulation node number from virtual node.
SimPowerComp(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Basic constructor that takes UID, name and log level.
virtual void initializeFromNodesAndTerminals(Real frequency)
Initializes Component variables according to power flow data stored in Nodes.
Definition: SimPowerComp.h:147
UInt nodeNumber()
Returns the actual number of Nodes / Terminals that are already set to valid Nodes.
SimNode< VarType >::Ptr node(UInt index)
Get pointer to node.
SimPowerComp(String name, Logger::Level logLevel=Logger::Level::off)
Basic constructor that takes name and log level and sets the UID to name as well.
Definition: SimPowerComp.h:53
std::vector< UInt > mMatrixNodeIndices
"Cached" list of simulation nodes (to avoid shared_ptr accesses during simulation)
Definition: SimPowerComp.h:35
Matrix mFrequencies
List of considered network frequencies.
Definition: SimPowerComp.h:25
virtual void initialize(Matrix frequencies)
Initialize components with correct network frequencies.
SimTerminal< VarType >::Ptr terminal(UInt index)
Get pointer to Terminal.
SimTerminal< VarType >::List terminals()
Return list of Terminal pointers.
std::vector< UInt > virtualMatrixNodeIndices(UInt index)
Get vector of simulation node numbers from virtual Node.
void connect(typename SimNode< VarType >::List nodes)
Sets all nodes and checks for nominal number of Nodes for this Component.
SimPowerComp< VarType >::List subComponents()
Get list of subcomponents.
UInt virtualNodesNumber()
Returns nominal number of virtual nodes for this component type.
void setTerminalAt(typename SimTerminal< VarType >::Ptr terminal, UInt terminalPosition)
Sets Terminal at index terminalPosition.
SimNode< VarType >::Ptr virtualNode(UInt index)
Get pointer to virtual node.
TopologicalNode::List topologicalNodes()
Get nodes as base type TopologicalNode.
UInt terminalNumberConnected()
Returns the number of connected Terminals.
SimNode< VarType >::List mVirtualNodes
List of virtual nodes.
Definition: SimPowerComp.h:23
std::vector< std::shared_ptr< SimPowerComp< VarType > > > mSubComponents
Definition: SimPowerComp.h:33
void setTerminals(typename SimTerminal< VarType >::List terminals)
const Attribute< MatrixVar< VarType > >::Ptr mIntfCurrent
Current through component.
Definition: SimPowerComp.h:47
Bool hasSubComponents()
Returns true if subcomponents included in this component.
virtual ~SimPowerComp()
Destructor - does not do anything.
Definition: SimPowerComp.h:56
void updateMatrixNodeIndices()
Update the "cached" mMatrixNodeIndices and mMatrixNodeIndexIsGround members.
virtual SimPowerComp< VarType >::Ptr clone(String name)
Returns a modified copy of the component with the given suffix added to the name and without.
const Attribute< MatrixVar< VarType > >::Ptr mIntfVoltage
Voltage between terminals.
Definition: SimPowerComp.h:45
TopologicalTerminal::List topologicalTerminals()
Returns the list of terminals as TopologicalTerminal pointers.
std::vector< UInt > matrixNodeIndices(UInt index)
TODO replace with access to mMatrixNodeIndices.