DPsim
Loading...
Searching...
No Matches
SimPowerComp.h
Go to the documentation of this file.
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
14
15namespace CPS {
17template <typename VarType> class SimPowerComp : public TopologicalPowerComp {
18
19protected:
30
33 typename std::vector<std::shared_ptr<SimPowerComp<VarType>>> mSubComponents;
35 std::vector<UInt> mMatrixNodeIndices;
37 std::vector<bool> mMatrixNodeIndexIsGround;
38
39public:
40 typedef VarType Type;
41 typedef std::shared_ptr<SimPowerComp<VarType>> Ptr;
42 typedef std::vector<Ptr> List;
43
48
49protected:
50 // The Attribute objects remain the authoritative dependency/public API
51 // storage. These pointers cache their stable payloads for tight numerical
52 // loops and avoid repeated virtual Attribute::get() dispatch.
55
56public:
59 Logger::Level logLevel = Logger::Level::off);
61 SimPowerComp(String name, Logger::Level logLevel = Logger::Level::off)
62 : SimPowerComp(name, name, logLevel) {}
63
64 virtual ~SimPowerComp() {}
65
68
69 // #### Terminals ####
85 void setTerminalNumber(UInt num);
91 UInt terminalPosition);
92
95
96 // #### Nodes ####
100 typename SimNode<VarType>::Ptr node(UInt index);
101
102 UInt matrixNodeIndex(UInt nodeIndex);
103
104 UInt matrixNodeIndex(UInt nodeIndex, UInt phaseIndex);
106 std::vector<UInt> matrixNodeIndices(UInt index);
109
110 // #### Virtual Nodes ####
122 typename SimNode<VarType>::Ptr virtualNode(UInt index);
124 std::vector<UInt> virtualMatrixNodeIndices(UInt index);
126 UInt virtualSimNode(UInt nodeIndex, UInt phaseIndex = 0);
127
128 // #### States ####
138
139 // #### Setters ####
144 void setVirtualNodeNumber(UInt num);
147 UInt nodeNum);
149 void connect(typename SimNode<VarType>::List nodes);
150
151 // #### Calculations ####
153 virtual void initialize(Matrix frequencies);
155 virtual void initializeFromNodesAndTerminals(Real frequency) {}
156};
157} // namespace CPS
String uid()
Returns unique id.
spdlog::level::level_enum Level
Definition Logger.h:33
std::shared_ptr< SimNode< VarType > > Ptr
Definition SimNode.h:34
std::vector< Ptr > List
Definition SimNode.h:35
UInt mNumFreqs
Number of network frequencies.
UInt matrixNodeIndex(UInt nodeIndex)
void setVirtualNodeAt(typename SimNode< VarType >::Ptr virtualNode, UInt nodeNum)
Sets the virtual node at index nodeNum.
const Attribute< MatrixVar< VarType > >::Ptr mIntfCurrent
Current through component.
SimTerminal< VarType >::List mTerminals
List of Terminals.
const MatrixVar< VarType > & intfVoltage()
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
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.
PhaseType mPhaseType
UInt nodeNumber()
Returns the actual number of Nodes / Terminals that are already set to valid Nodes.
void checkForUnconnectedTerminals()
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.
MatrixVar< VarType > * mIntfVoltageValue
std::vector< UInt > mMatrixNodeIndices
"Cached" list of simulation nodes (to avoid shared_ptr accesses during simulation)
Matrix mFrequencies
List of considered network frequencies.
virtual void initialize(Matrix frequencies)
Initialize components with correct network frequencies.
SimTerminal< VarType >::Ptr terminal(UInt index)
Get pointer to Terminal.
const MatrixVar< VarType > & intfCurrent()
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 setVirtualNodeNumber(UInt num)
const Attribute< MatrixVar< VarType > >::Ptr mIntfVoltage
Voltage between terminals.
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.
std::vector< Ptr > List
void setIntfVoltage(MatrixVar< VarType > voltage)
MatrixComp initialVoltage(UInt index)
SimNode< VarType >::Ptr virtualNode(UInt index)
Get pointer to virtual node.
MatrixVar< VarType > * mIntfCurrentValue
void setIntfCurrent(MatrixVar< VarType > current)
TopologicalNode::List topologicalNodes()
Get nodes as base type TopologicalNode.
UInt terminalNumberConnected()
Returns the number of connected Terminals.
std::shared_ptr< SimPowerComp< VarType > > Ptr
SimNode< VarType >::List mVirtualNodes
List of virtual nodes.
std::vector< std::shared_ptr< SimPowerComp< VarType > > > mSubComponents
void setTerminals(typename SimTerminal< VarType >::List terminals)
SimNode< VarType >::List & virtualNodes()
Bool terminalNotGrounded(UInt index)
Bool hasSubComponents()
Returns true if subcomponents included in this component.
virtual ~SimPowerComp()
Destructor - does not do anything.
Complex initialSingleVoltage(UInt index)
void updateMatrixNodeIndices()
Update the "cached" mMatrixNodeIndices and mMatrixNodeIndexIsGround members.
void setTerminalNumber(UInt num)
virtual SimPowerComp< VarType >::Ptr clone(String name)
Returns a modified copy of the component with the given suffix added to the name and without.
TopologicalTerminal::List topologicalTerminals()
Returns the list of terminals as TopologicalTerminal pointers.
std::vector< UInt > matrixNodeIndices(UInt index)
TODO replace with access to mMatrixNodeIndices.
std::shared_ptr< SimTerminal< VarType > > Ptr
Definition SimTerminal.h:24
std::vector< Ptr > List
Definition SimTerminal.h:25
std::vector< Ptr > List
TopologicalPowerComp(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Basic constructor that takes UID, name and log level.
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
double Real
Definition Definitions.h:60
Eigen::Matrix< VarType, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixVar
Definition Definitions.h:95
std::complex< Real > Complex
Definition Definitions.h:61
Eigen::Matrix< Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixComp
Dense matrix for complex numbers.
Definition Definitions.h:82
bool Bool
Definition Definitions.h:62
unsigned int UInt
Definition Definitions.h:58