DPsim
Loading...
Searching...
No Matches
SimNode.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
11#include <dpsim-models/Task.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};
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
41
44 PhaseType phaseType, const std::vector<Complex> &initialVoltage);
50 const std::vector<Complex> &initialVoltage = {0, 0, 0})
51 : SimNode(name, name, {0, 0, 0}, phaseType, initialVoltage) {}
52
60
66
67 std::shared_ptr<TopologicalNode> clone(String name);
68
70 void initialize();
72 void initialize(Matrix frequencies);
76 std::vector<UInt> matrixNodeIndices() 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);
98 class MnaPostStepHarm : public Task {
99 public:
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 {
121}
122namespace EMT {
124}
125
126template <typename VarType>
128
129template <> void SimNode<Real>::mnaUpdateVoltage(const Matrix &leftVector);
130
131template <> void SimNode<Complex>::mnaUpdateVoltage(const Matrix &leftVector);
132
133template <>
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
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:250
String uid()
Returns unique id.
MnaPostStepHarm(SimNode &node, const std::vector< Attribute< Matrix >::Ptr > &leftVectors)
Definition SimNode.h:100
void execute(Real time, Int timeStepCount)
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
std::shared_ptr< SimNode< VarType > > Ptr
Definition SimNode.h:32
void mnaUpdateVoltage(const Matrix &leftVector)
void setVoltage(VarType newVoltage)
Definition SimNode.h:84
void initialize()
Initialize mVoltage according to mInitialVoltage.
void setPower(VarType newPower)
Definition SimNode.h:86
void initialize(Matrix frequencies)
Initialize state matrices with size according to phase type and frequency number.
Definition SimNode.cpp:57
Task::List mMnaTasks
Definition SimNode.h:28
std::shared_ptr< TopologicalNode > clone(String name)
Definition SimNode.cpp:65
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
MatrixVar< VarType > voltage()
Definition SimNode.cpp:109
void setMatrixNodeIndex(UInt phase, UInt matrixNodeIndex) override
Definition SimNode.cpp:114
VarType Type
Definition SimNode.h:31
const Attribute< MatrixVar< Complex > >::Ptr mVoltage
Definition SimNode.h:38
VarType singleVoltage(PhaseType phaseType=PhaseType::Single)
Definition SimNode.cpp:72
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
void mnaUpdateVoltageHarm(const Matrix &leftVector, Int freqIdx)
void mnaInitializeHarm(std::vector< Attribute< Matrix >::Ptr > leftVector)
SimNode(UInt matrixNodeIndex, PhaseType phaseType=PhaseType::Single)
Definition SimNode.h:62
const Attribute< MatrixVar< Complex > >::Ptr mApparentPower
Definition SimNode.h:40
std::vector< Ptr > List
Definition SimNode.h:33
std::vector< UInt > mMatrixNodeIndex
Definition SimNode.h:22
std::vector< AttributeBase::Ptr > mModifiedAttributes
Definition Task.h:53
std::vector< AttributeBase::Ptr > mAttributeDependencies
Definition Task.h:52
Task()
Definition Task.h:30
std::vector< Ptr > List
Definition Task.h:28
std::string mName
Definition Task.h:51
PhaseType phaseType() const
MatrixComp initialVoltage() const
static std::shared_ptr< SimNode< VarType > > make(Args &&...args)
Definition PtrFactory.h:19
CPS::SimNode< Complex > SimNode
Definition SimNode.h:120
CPS::SimNode< Real > SimNode
Definition SimNode.h:123
CPS::SimNode< Complex > SimNode
Definition SimNode.h:117
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > Matrix
Dense matrix for real numbers.
Definition Definitions.h:81
std::string String
Definition Definitions.h:65
double Real
Definition Definitions.h:62
int Int
Definition Definitions.h:61
Eigen::Matrix< VarType, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixVar
Definition Definitions.h:97
std::complex< Real > Complex
Definition Definitions.h:63
unsigned int UInt
Definition Definitions.h:60