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};
31
32public:
33 typedef VarType Type;
34 typedef std::shared_ptr<SimNode<VarType>> Ptr;
35 typedef std::vector<Ptr> List;
37 static Ptr GND;
38
43
46 PhaseType phaseType, const std::vector<Complex> &initialVoltage);
52 const std::vector<Complex> &initialVoltage = {0, 0, 0})
53 : SimNode(name, name, {0, 0, 0}, phaseType, initialVoltage) {}
54
62
68
69 std::shared_ptr<TopologicalNode> clone(String name);
70
72 void initialize();
77
78 void initialize(Matrix frequencies);
82 std::vector<UInt> matrixNodeIndices() override;
90 void setVoltage(VarType newVoltage) {}
92 void setPower(VarType newPower) {}
93
94 // #### MNA Section ####
96 void mnaUpdateVoltage(const Matrix &leftVector);
98 void mnaInitializeHarm(std::vector<Attribute<Matrix>::Ptr> leftVector);
100 void mnaUpdateVoltageHarm(const Matrix &leftVector, Int freqIdx);
104 class MnaPostStepHarm : public Task {
105 public:
107 const std::vector<Attribute<Matrix>::Ptr> &leftVectors)
108 : Task(**node.mName + ".MnaPostStepHarm"), mNode(node),
109 mLeftVectors(leftVectors) {
110 for (UInt i = 0; i < mLeftVectors.size(); i++)
111 mAttributeDependencies.push_back(mLeftVectors[i]);
112 mModifiedAttributes.push_back(mNode.attribute("v"));
113 }
114 void execute(Real time, Int timeStepCount);
115
116 private:
117 SimNode &mNode;
118 std::vector<Attribute<Matrix>::Ptr> mLeftVectors;
119 };
120};
121
122namespace SP {
124}
125namespace DP {
127}
128namespace EMT {
130}
131
132template <typename VarType>
134
135template <> void SimNode<Real>::mnaUpdateVoltage(const Matrix &leftVector);
136
137template <> void SimNode<Complex>::mnaUpdateVoltage(const Matrix &leftVector);
138
139template <>
141 std::vector<Attribute<Matrix>::Ptr> leftVector);
142
143template <> void SimNode<Complex>::setVoltage(Complex newVoltage);
144
145template <> void SimNode<Complex>::setPower(Complex newPower);
146} // namespace CPS
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:249
String uid()
Returns unique id.
MnaPostStepHarm(SimNode &node, const std::vector< Attribute< Matrix >::Ptr > &leftVectors)
Definition SimNode.h:106
void execute(Real time, Int timeStepCount)
void setComplexInitialVoltageScale(Real scale)
Set the scale applied to an ABC complex node's stored PF phasors at init.
Definition SimNode.h:74
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:34
void mnaUpdateVoltage(const Matrix &leftVector)
void setVoltage(VarType newVoltage)
Definition SimNode.h:90
void initialize()
Initialize mVoltage according to mInitialVoltage.
void setPower(VarType newPower)
Definition SimNode.h:92
void initialize(Matrix frequencies)
Initialize state matrices with size according to phase type and frequency number.
Definition SimNode.cpp:61
Task::List mMnaTasks
Definition SimNode.h:30
std::shared_ptr< TopologicalNode > clone(String name)
Definition SimNode.cpp:69
const Task::List & mnaTasks()
Return list of MNA tasks.
Definition SimNode.cpp:137
SimNode(String uid, String name, UInt matrixNodeIndex, PhaseType phaseType=PhaseType::Single, const std::vector< Complex > &initialVoltage={0, 0, 0})
Definition SimNode.h:56
UInt matrixNodeIndex(PhaseType phaseType=PhaseType::Single) override
MatrixVar< VarType > voltage()
Definition SimNode.cpp:128
void setMatrixNodeIndex(UInt phase, UInt matrixNodeIndex) override
Definition SimNode.cpp:133
VarType Type
Definition SimNode.h:33
const Attribute< MatrixVar< Complex > >::Ptr mVoltage
Definition SimNode.h:40
VarType singleVoltage(PhaseType phaseType=PhaseType::Single)
Definition SimNode.cpp:77
std::vector< UInt > matrixNodeIndices() override
Returns all matrix indices.
Definition SimNode.cpp:117
SimNode(String name, PhaseType phaseType=PhaseType::Single, const std::vector< Complex > &initialVoltage={0, 0, 0})
Definition SimNode.h:51
SimNode(PhaseType phaseType=PhaseType::Single)
Create ground node if no parameters are given.
Definition SimNode.cpp:34
Real mComplexInitialVoltageScale
Definition SimNode.h:28
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:64
const Attribute< MatrixVar< Complex > >::Ptr mApparentPower
Definition SimNode.h:42
std::vector< Ptr > List
Definition SimNode.h:35
std::vector< UInt > mMatrixNodeIndex
Definition SimNode.h:22
std::vector< AttributeBase::Ptr > mModifiedAttributes
Definition Task.h:70
std::vector< AttributeBase::Ptr > mAttributeDependencies
Definition Task.h:69
Task()
Definition Task.h:30
std::vector< Ptr > List
Definition Task.h:28
std::string mName
Definition Task.h:68
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:126
CPS::SimNode< Real > SimNode
Definition SimNode.h:129
CPS::SimNode< Complex > SimNode
Definition SimNode.h:123
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > Matrix
Dense matrix for real numbers.
Definition Definitions.h:79
std::string String
Definition Definitions.h:63
double Real
Definition Definitions.h:60
int Int
Definition Definitions.h:59
Eigen::Matrix< VarType, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixVar
Definition Definitions.h:95
std::complex< Real > Complex
Definition Definitions.h:61
unsigned int UInt
Definition Definitions.h:58