9 #include <dpsim-models/SimPowerComp.h>
13 template <
typename VarType>
15 Logger::Level logLevel)
17 mIntfVoltage(mAttributes->create<MatrixVar<VarType>>(
"v_intf")),
18 mIntfCurrent(mAttributes->create<MatrixVar<VarType>>(
"i_intf")) {
22 template <
typename VarType>
31 template <
typename VarType>
36 template <
typename VarType>
38 if (index >= mTerminals.size()) {
39 throw SystemError(
"Node not available for " + **mUID);
41 return mTerminals[index]->node();
44 template <
typename VarType>
46 return mMatrixNodeIndices[nodeIndex * 3];
49 template <
typename VarType>
51 return mMatrixNodeIndices[nodeIndex * 3 + phaseIndex];
54 template <
typename VarType>
56 return node(index)->matrixNodeIndices();
60 return mNumVirtualNodes;
64 return mNumVirtualNodes > 0;
68 return mSubComponents.size() > 0;
71 template <
typename VarType>
73 return mSubComponents;
76 template <
typename VarType>
81 template <
typename VarType>
83 return virtualNode(index)->matrixNodeIndices();
86 template <
typename VarType>
88 return virtualMatrixNodeIndices(nodeIndex)[phaseIndex];
91 template <
typename VarType>
93 return **mIntfCurrent;
96 template <
typename VarType>
98 return **mIntfVoltage;
101 template <
typename VarType>
103 return mTerminals[index]->initialVoltage();
106 template <
typename VarType>
108 return mTerminals[index]->initialSingleVoltage();
111 template <
typename VarType>
113 return !mMatrixNodeIndexIsGround[index];
116 template <
typename VarType>
118 **mIntfCurrent = current;
121 template <
typename VarType>
123 **mIntfVoltage = voltage;
127 template <
typename VarType>
129 return (UInt)(mNumTerminals -
130 std::count(mTerminals.begin(), mTerminals.end(),
nullptr));
133 template <
typename VarType>
135 return (std::count(mTerminals.begin(), mTerminals.end(),
nullptr) > 0);
138 template <
typename VarType>
140 if (hasUnconnectedTerminals()) {
145 template <
typename VarType>
147 if (index >= mTerminals.size()) {
148 throw SystemError(
"Terminal not available for " + **mUID);
150 return mTerminals[index];
153 template <
typename VarType>
155 TopologicalTerminal::List terminals;
156 for (
typename SimTerminal<VarType>::Ptr term : mTerminals) {
157 terminals.push_back(term);
162 template <
typename VarType>
165 mTerminals.resize(mNumTerminals,
nullptr);
166 mMatrixNodeIndices.resize(3 * num);
167 mMatrixNodeIndexIsGround.resize(num);
170 template <
typename VarType>
172 typename SimTerminal<VarType>::List terminals) {
173 if (mNumTerminals < terminals.size()) {
175 mSLog,
"Number of Terminals is too large for Component {} - Ignoring",
179 mTerminals = terminals;
182 template <
typename VarType>
184 typename SimTerminal<VarType>::Ptr terminal, UInt terminalPosition) {
185 if (mNumTerminals <= terminalPosition) {
187 mSLog,
"Terminal position number too large for Component {} - Ignoring",
191 mTerminals[terminalPosition] = terminal;
193 mSLog,
"Set Terminal at position {} to Node {}, simulation node {}",
194 terminalPosition, mTerminals[terminalPosition]->node()->name(),
195 mTerminals[terminalPosition]->matrixNodeIndex());
198 template <
typename VarType>
200 for (UInt nodeIdx = 0; nodeIdx < mNumTerminals; nodeIdx++) {
201 mMatrixNodeIndices[3 * nodeIdx] =
202 node(nodeIdx)->matrixNodeIndex(PhaseType::A);
203 mMatrixNodeIndices[3 * nodeIdx + 1] =
204 node(nodeIdx)->matrixNodeIndex(PhaseType::B);
205 mMatrixNodeIndices[3 * nodeIdx + 2] =
206 node(nodeIdx)->matrixNodeIndex(PhaseType::C);
207 mMatrixNodeIndexIsGround[nodeIdx] = node(nodeIdx)->isGround();
213 return static_cast<UInt
>(
214 std::count(mTerminals.begin(), mTerminals.end(),
nullptr));
217 template <
typename VarType>
219 TopologicalNode::List nodes;
220 for (
typename SimTerminal<VarType>::Ptr term : mTerminals) {
221 nodes.push_back(term->node());
227 template <
typename VarType>
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);
239 template <
typename VarType>
241 typename SimNode<VarType>::Ptr virtualNode, UInt nodeNum) {
242 if (mNumVirtualNodes <= nodeNum) {
245 "Virtual Node position number too large for Component {} - Ignoring",
248 mVirtualNodes[nodeNum] = virtualNode;
250 mSLog,
"Set virtual Node at position {} to Node {}, simulation node {}",
251 nodeNum, mVirtualNodes[nodeNum]->name(),
252 mVirtualNodes[nodeNum]->matrixNodeIndex());
255 template <
typename VarType>
257 if (index >= mVirtualNodes.size()) {
258 throw SystemError(
"Node not available for " + **mUID);
260 return mVirtualNodes[index];
264 template <
typename VarType>
266 if (mNumTerminals < nodes.size()) {
268 mSLog,
"Number of Nodes is too large for Component {} - Ignoring",
272 for (UInt i = 0; i < nodes.size(); i++) {
273 String name = **mName +
"_T" + std::to_string(i);
274 typename SimTerminal<VarType>::Ptr terminal =
276 terminal->setNode(nodes[i]);
277 setTerminalAt(terminal, i);
281 template <
typename VarType>
283 mFrequencies = frequencies;
284 mNumFreqs =
static_cast<UInt
>(mFrequencies.size());
286 if (mPhaseType != PhaseType::ABC) {
287 **mIntfVoltage = MatrixVar<VarType>::Zero(1, mNumFreqs);
288 **mIntfCurrent = MatrixVar<VarType>::Zero(1, mNumFreqs);
290 **mIntfVoltage = MatrixVar<VarType>::Zero(3, mNumFreqs);
291 **mIntfCurrent = MatrixVar<VarType>::Zero(3, mNumFreqs);
294 for (
auto node : mVirtualNodes)
295 node->initialize(frequencies);
Base class for all components that are transmitting power.
void setVirtualNodeAt(typename SimNode< VarType >::Ptr virtualNode, UInt nodeNum)
Sets the virtual node at index nodeNum.
SimTerminal< VarType >::List mTerminals
List of Terminals.
Bool hasVirtualNodes()
Returns true if virtual node number is greater than zero.
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.
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.
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.