DPsim
Loading...
Searching...
No Matches
SimNode.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/Task.h>
12#include <dpsim-models/TopologicalNode.h>
13
14namespace CPS {
15
16template <typename VarType>
17class SimNode : public TopologicalNode,
18 public std::enable_shared_from_this<SimNode<VarType>>,
19 public SharedFactory<SimNode<VarType>> {
20protected:
22 std::vector<UInt> mMatrixNodeIndex = {0};
26 UInt mNumFreqs = 0;
28 Task::List mMnaTasks;
29
30public:
31 typedef VarType Type;
32 typedef std::shared_ptr<SimNode<VarType>> Ptr;
33 typedef std::vector<Ptr> List;
35 static Ptr GND;
36
38 const typename Attribute<MatrixVar<VarType>>::Ptr mVoltage;
41
43 SimNode(String uid, String name, std::vector<UInt> matrixNodeIndex,
44 PhaseType phaseType, const std::vector<Complex> &initialVoltage);
46 SimNode(PhaseType phaseType = PhaseType::Single);
49 SimNode(String name, PhaseType phaseType = PhaseType::Single,
50 const std::vector<Complex> &initialVoltage = {0, 0, 0})
51 : SimNode(name, name, {0, 0, 0}, phaseType, initialVoltage) {}
52
54 SimNode(String uid, String name, UInt matrixNodeIndex,
55 PhaseType phaseType = PhaseType::Single,
56 const std::vector<Complex> &initialVoltage = {0, 0, 0})
57 : SimNode(uid, name,
59 phaseType, initialVoltage) {}
60
62 SimNode(UInt matrixNodeIndex, PhaseType phaseType = PhaseType::Single)
63 : SimNode("N" + std::to_string(matrixNodeIndex),
64 "N" + std::to_string(matrixNodeIndex), matrixNodeIndex,
65 phaseType) {}
66
67 std::shared_ptr<TopologicalNode> clone(String name);
68
70 void initialize();
72 void initialize(Matrix frequencies);
74 UInt matrixNodeIndex(PhaseType phaseType = PhaseType::Single) override;
76 std::vector<UInt> matrixNodeIndices() override;
78 VarType singleVoltage(PhaseType phaseType = PhaseType::Single);
80 MatrixVar<VarType> voltage();
82 void setMatrixNodeIndex(UInt phase, UInt matrixNodeIndex) override;
84 void setVoltage(VarType newVoltage) {}
86 void setPower(VarType newPower) {}
87
88 // #### MNA Section ####
90 void mnaUpdateVoltage(const Matrix &leftVector);
92 void mnaInitializeHarm(std::vector<Attribute<Matrix>::Ptr> leftVector);
94 void mnaUpdateVoltageHarm(const Matrix &leftVector, Int freqIdx);
96 const Task::List &mnaTasks();
98 class MnaPostStepHarm : public Task {
99 public:
100 MnaPostStepHarm(SimNode &node,
101 const std::vector<Attribute<Matrix>::Ptr> &leftVectors)
102 : Task(**node.mName + ".MnaPostStepHarm"), mNode(node),
103 mLeftVectors(leftVectors) {
104 for (UInt i = 0; i < mLeftVectors.size(); i++)
105 mAttributeDependencies.push_back(mLeftVectors[i]);
106 mModifiedAttributes.push_back(mNode.attribute("v"));
107 }
108 void execute(Real time, Int timeStepCount);
109
110 private:
111 SimNode &mNode;
112 std::vector<Attribute<Matrix>::Ptr> mLeftVectors;
113 };
114};
115
116namespace SP {
118}
119namespace DP {
120typedef CPS::SimNode<Complex> SimNode;
121}
122namespace EMT {
123typedef CPS::SimNode<Real> SimNode;
124}
125
126template <typename VarType>
127typename SimNode<VarType>::Ptr SimNode<VarType>::GND = SimNode<VarType>::make();
128
129template <> void SimNode<Real>::mnaUpdateVoltage(const Matrix &leftVector);
130
131template <> void SimNode<Complex>::mnaUpdateVoltage(const Matrix &leftVector);
132
133template <>
134void SimNode<Complex>::mnaInitializeHarm(
135 std::vector<Attribute<Matrix>::Ptr> leftVector);
136
137template <> void SimNode<Complex>::setVoltage(Complex newVoltage);
138
139template <> void SimNode<Complex>::setPower(Complex newPower);
140} // namespace CPS
const Attribute< String >::Ptr mName
Human readable name.
String uid()
Returns unique id.
SimNode(String uid, String name, std::vector< UInt > matrixNodeIndex, PhaseType phaseType, const std::vector< Complex > &initialVoltage)
This very general constructor is used by other constructors.
Definition SimNode.cpp:14
void initialize()
Initialize mVoltage according to mInitialVoltage.
void initialize(Matrix frequencies)
Initialize state matrices with size according to phase type and frequency number.
Definition SimNode.cpp:57
const Task::List & mnaTasks()
Return list of MNA tasks.
Definition SimNode.cpp:118
SimNode(String uid, String name, UInt matrixNodeIndex, PhaseType phaseType=PhaseType::Single, const std::vector< Complex > &initialVoltage={0, 0, 0})
Definition SimNode.h:54
UInt matrixNodeIndex(PhaseType phaseType=PhaseType::Single) override
std::vector< UInt > matrixNodeIndices() override
Returns all matrix indices.
Definition SimNode.cpp:98
SimNode(String name, PhaseType phaseType=PhaseType::Single, const std::vector< Complex > &initialVoltage={0, 0, 0})
Definition SimNode.h:49
SimNode(PhaseType phaseType=PhaseType::Single)
Create ground node if no parameters are given.
Definition SimNode.cpp:34
SimNode(UInt matrixNodeIndex, PhaseType phaseType=PhaseType::Single)
Definition SimNode.h:62
const Attribute< MatrixVar< Complex > >::Ptr mApparentPower
Definition SimNode.h:40