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
68 void initialize();
70 void initialize(Matrix frequencies);
72 UInt matrixNodeIndex(PhaseType phaseType = PhaseType::Single) override;
74 std::vector<UInt> matrixNodeIndices() override;
76 VarType singleVoltage(PhaseType phaseType = PhaseType::Single);
78 MatrixVar<VarType> voltage();
80 void setMatrixNodeIndex(UInt phase, UInt matrixNodeIndex) override;
82 void setVoltage(VarType newVoltage) {}
84 void setPower(VarType newPower) {}
85
86 // #### MNA Section ####
88 void mnaUpdateVoltage(const Matrix &leftVector);
90 void mnaInitializeHarm(std::vector<Attribute<Matrix>::Ptr> leftVector);
92 void mnaUpdateVoltageHarm(const Matrix &leftVector, Int freqIdx);
94 const Task::List &mnaTasks();
96 class MnaPostStepHarm : public Task {
97 public:
98 MnaPostStepHarm(SimNode &node,
99 const std::vector<Attribute<Matrix>::Ptr> &leftVectors)
100 : Task(**node.mName + ".MnaPostStepHarm"), mNode(node),
101 mLeftVectors(leftVectors) {
102 for (UInt i = 0; i < mLeftVectors.size(); i++)
103 mAttributeDependencies.push_back(mLeftVectors[i]);
104 mModifiedAttributes.push_back(mNode.attribute("v"));
105 }
106 void execute(Real time, Int timeStepCount);
107
108 private:
109 SimNode &mNode;
110 std::vector<Attribute<Matrix>::Ptr> mLeftVectors;
111 };
112};
113
114namespace SP {
116}
117namespace DP {
118typedef CPS::SimNode<Complex> SimNode;
119}
120namespace EMT {
121typedef CPS::SimNode<Real> SimNode;
122}
123
124template <typename VarType>
125typename SimNode<VarType>::Ptr SimNode<VarType>::GND = SimNode<VarType>::make();
126
127template <> void SimNode<Real>::mnaUpdateVoltage(const Matrix &leftVector);
128
129template <> void SimNode<Complex>::mnaUpdateVoltage(const Matrix &leftVector);
130
131template <>
132void SimNode<Complex>::mnaInitializeHarm(
133 std::vector<Attribute<Matrix>::Ptr> leftVector);
134
135template <> void SimNode<Complex>::setVoltage(Complex newVoltage);
136
137template <> void SimNode<Complex>::setPower(Complex newPower);
138} // 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:111
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:91
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