9#include <dpsim-models/SimPowerComp.h>
13template <
typename VarType>
15 Logger::Level logLevel)
22template <
typename VarType>
31template <
typename VarType>
36template <
typename VarType>
44template <
typename VarType>
45UInt SimPowerComp<VarType>::matrixNodeIndex(UInt nodeIndex) {
46 return mMatrixNodeIndices[nodeIndex * 3];
49template <
typename VarType>
50UInt SimPowerComp<VarType>::matrixNodeIndex(UInt nodeIndex, UInt phaseIndex) {
54template <
typename VarType>
56 return node(index)->matrixNodeIndices();
71template <
typename VarType>
76template <
typename VarType>
77typename SimNode<VarType>::List &SimPowerComp<VarType>::virtualNodes() {
81template <
typename VarType>
86template <
typename VarType>
91template <
typename VarType>
92const MatrixVar<VarType> &SimPowerComp<VarType>::intfCurrent() {
96template <
typename VarType>
97const MatrixVar<VarType> &SimPowerComp<VarType>::intfVoltage() {
101template <
typename VarType>
102MatrixComp SimPowerComp<VarType>::initialVoltage(UInt index) {
106template <
typename VarType>
107Complex SimPowerComp<VarType>::initialSingleVoltage(UInt index) {
111template <
typename VarType>
112Bool SimPowerComp<VarType>::terminalNotGrounded(UInt index) {
116template <
typename VarType>
117void SimPowerComp<VarType>::setIntfCurrent(MatrixVar<VarType> current) {
121template <
typename VarType>
122void SimPowerComp<VarType>::setIntfVoltage(MatrixVar<VarType> voltage) {
123 **mIntfVoltage = voltage;
127template <
typename VarType>
133template <
typename VarType>
134Bool SimPowerComp<VarType>::hasUnconnectedTerminals() {
135 return (std::count(mTerminals.begin(), mTerminals.end(),
nullptr) > 0);
138template <
typename VarType>
139void SimPowerComp<VarType>::checkForUnconnectedTerminals() {
140 if (hasUnconnectedTerminals()) {
145template <
typename VarType>
153template <
typename VarType>
156 for (
typename SimTerminal<VarType>::Ptr term :
mTerminals) {
162template <
typename VarType>
163void SimPowerComp<VarType>::setTerminalNumber(UInt num) {
165 mTerminals.resize(mNumTerminals,
nullptr);
166 mMatrixNodeIndices.resize(3 * num);
167 mMatrixNodeIndexIsGround.resize(num);
170template <
typename VarType>
172 typename SimTerminal<VarType>::List
terminals) {
175 mSLog,
"Number of Terminals is too large for Component {} - Ignoring",
182template <
typename VarType>
184 typename SimTerminal<VarType>::Ptr
terminal, UInt terminalPosition) {
187 mSLog,
"Terminal position number too large for Component {} - Ignoring",
193 mSLog,
"Set Terminal at position {} to Node {}, simulation node {}",
195 mTerminals[terminalPosition]->matrixNodeIndex());
198template <
typename VarType>
202 node(nodeIdx)->matrixNodeIndex(PhaseType::A);
204 node(nodeIdx)->matrixNodeIndex(PhaseType::B);
206 node(nodeIdx)->matrixNodeIndex(PhaseType::C);
213 return static_cast<UInt
>(
217template <
typename VarType>
219 TopologicalNode::List nodes;
220 for (
typename SimTerminal<VarType>::Ptr term :
mTerminals) {
221 nodes.push_back(term->node());
227template <
typename VarType>
228void SimPowerComp<VarType>::setVirtualNodeNumber(UInt num) {
229 mNumVirtualNodes = num;
230 mVirtualNodes.resize(mNumVirtualNodes,
nullptr);
232 for (UInt idx = 0; idx < mNumVirtualNodes; idx++) {
233 String nodeName = **mName +
"_vnode_" + std::to_string(idx);
239template <
typename VarType>
241 typename SimNode<VarType>::Ptr
virtualNode, UInt nodeNum) {
245 "Virtual Node position number too large for Component {} - Ignoring",
250 mSLog,
"Set virtual Node at position {} to Node {}, simulation node {}",
255template <
typename VarType>
264template <
typename VarType>
268 mSLog,
"Number of Nodes is too large for Component {} - Ignoring",
272 for (UInt i = 0; i < nodes.size(); i++) {
273 if (nodes[i] ==
nullptr) {
275 fmt::format(
"Node is nullptr for Component {}", **
mName));
277 String name = **
mName +
"_T" + std::to_string(i);
278 typename SimTerminal<VarType>::Ptr
terminal =
279 SimTerminal<VarType>::make(name);
285template <
typename VarType>
290 if (mPhaseType != PhaseType::ABC) {
299 node->initialize(frequencies);
const Attribute< String >::Ptr mName
Human readable name.
String uid()
Returns unique id.
const Attribute< String >::Ptr mUID
Unique identifier.
AttributeList::Ptr mAttributes
Attribute List.
Base class for all components that are transmitting power.
UInt mNumFreqs
Number of network frequencies.
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.
Bool hasVirtualNodes()
Returns true if virtual node number is greater than zero.
std::vector< bool > mMatrixNodeIndexIsGround
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.
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.
std::vector< UInt > mMatrixNodeIndices
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.
SimTerminal< VarType >::List terminals()
Return list of Terminal pointers.
std::vector< UInt > virtualMatrixNodeIndices(UInt index)
Get vector of simulation node numbers from virtual Node.
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.
SimNode< Complex >::Ptr virtualNode(UInt index)
TopologicalNode::List topologicalNodes()
Get nodes as base type TopologicalNode.
UInt terminalNumberConnected()
Returns the number of connected Terminals.
SimNode< Complex >::List mVirtualNodes
std::vector< std::shared_ptr< SimPowerComp< VarType > > > mSubComponents
void setTerminals(typename SimTerminal< VarType >::List terminals)
Bool hasSubComponents()
Returns true if subcomponents included in this component.
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.
TopologicalTerminal::List topologicalTerminals()
Returns the list of terminals as TopologicalTerminal pointers.
std::vector< UInt > matrixNodeIndices(UInt index)
TODO replace with access to mMatrixNodeIndices.
UInt mNumTerminals
Determines the number of Terminals which can be connected to network Nodes.
UInt mNumVirtualNodes
Determines the number of virtual or internal Nodes.
Logger::Log mSLog
Component logger.
TopologicalPowerComp(String uid, String name, Logger::Level logLevel=Logger::Level::off)
Basic constructor that takes UID, name and log level.