DPsim
Loading...
Searching...
No Matches
PLL.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 <vector>
12
15#include <dpsim-models/Task.h>
16
17namespace CPS {
18namespace Signal {
19class PLL : public SimSignalComp, public SharedFactory<PLL> {
20
21protected:
26
31
33 Matrix mA = Matrix::Zero(2, 2);
35 Matrix mB = Matrix::Zero(2, 2);
37 Matrix mC = Matrix::Zero(2, 2);
39 Matrix mD = Matrix::Zero(2, 2);
40
41public:
44
57
58 PLL(String name, Logger::Level logLevel = Logger::Level::off);
60 void setParameters(Real kpPLL, Real kiPLL, Real omegaNom);
62 void setSimulationParameters(Real timestep);
64 void setInitialValues(Real input_init, Matrix state_init, Matrix output_init);
68 void signalPreStep(Real time, Int timeStepCount);
70 void signalStep(Real time, Int timeStepCount);
72 void signalAddPreStepDependencies(AttributeBase::List &prevStepDependencies,
73 AttributeBase::List &attributeDependencies,
74 AttributeBase::List &modifiedAttributes);
76 void signalAddStepDependencies(AttributeBase::List &prevStepDependencies,
77 AttributeBase::List &attributeDependencies,
78 AttributeBase::List &modifiedAttributes);
79
81
82 class PreStep : public Task {
83 public:
84 PreStep(PLL &pll) : Task(**pll.mName + ".PreStep"), mPLL(pll) {
85 mPLL.signalAddPreStepDependencies(
87 }
88 void execute(Real time, Int timeStepCount) {
89 mPLL.signalPreStep(time, timeStepCount);
90 };
91
92 private:
93 PLL &mPLL;
94 };
95
96 class Step : public Task {
97 public:
98 Step(PLL &pll) : Task(**pll.mName + ".Step"), mPLL(pll) {
99 mPLL.signalAddStepDependencies(
101 }
102 void execute(Real time, Int timeStepCount) {
103 mPLL.signalStep(time, timeStepCount);
104 };
105
106 private:
107 PLL &mPLL;
108 };
109};
110} // namespace Signal
111} // namespace CPS
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:250
spdlog::level::level_enum Level
Definition Logger.h:33
PreStep(PLL &pll)
Definition PLL.h:84
void execute(Real time, Int timeStepCount)
Definition PLL.h:88
Step(PLL &pll)
Definition PLL.h:98
void execute(Real time, Int timeStepCount)
Definition PLL.h:102
void setInitialValues(Real input_init, Matrix state_init, Matrix output_init)
Setter for initial values.
Definition PLL.cpp:42
const Attribute< Matrix >::Ptr mOutputPrev
Previous Output.
Definition PLL.h:54
Real mKp
Proportional constant of PI controller.
Definition PLL.h:23
Real mTimeStep
Integration time step.
Definition PLL.h:30
void signalStep(Real time, Int timeStepCount)
step operations
Definition PLL.cpp:95
Matrix mD
matrix D of state space model
Definition PLL.h:39
const Attribute< Real >::Ptr mInputRef
This is never explicitely set to reference anything, so the outside code is responsible for setting u...
Definition PLL.h:43
const Attribute< Matrix >::Ptr mInputCurr
Current Input.
Definition PLL.h:48
const Attribute< Matrix >::Ptr mStatePrev
Previous State.
Definition PLL.h:50
void signalAddStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes)
add step dependencies
Definition PLL.cpp:87
Matrix mC
matrix C of state space model
Definition PLL.h:37
const Attribute< Matrix >::Ptr mOutputCurr
Current Output.
Definition PLL.h:56
void setSimulationParameters(Real timestep)
Setter for simulation parameters.
Definition PLL.cpp:37
Matrix mB
matrix B of state space model
Definition PLL.h:35
void setParameters(Real kpPLL, Real kiPLL, Real omegaNom)
Setter for PLL parameters.
Definition PLL.cpp:27
PLL(String name, Logger::Level logLevel=Logger::Level::off)
Definition PLL.cpp:14
Real mOmegaNom
Nominal frequency.
Definition PLL.h:28
void composeStateSpaceMatrices()
Composition of A, B, C, D matrices based on PLL parameters.
Definition PLL.cpp:58
Matrix mA
matrix A of state space model
Definition PLL.h:33
void signalAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes)
pre step dependencies
Definition PLL.cpp:71
const Attribute< Matrix >::Ptr mStateCurr
Current State.
Definition PLL.h:52
const Attribute< Matrix >::Ptr mInputPrev
Previous Input.
Definition PLL.h:46
void signalPreStep(Real time, Int timeStepCount)
pre step operations
Definition PLL.cpp:81
Task::List getTasks()
Definition PLL.cpp:117
Real mKi
Integration constant of PI controller.
Definition PLL.h:25
SimSignalComp(String uid, String name, Logger::Level logLevel=Logger::Level::off)
std::vector< AttributeBase::Ptr > mModifiedAttributes
Definition Task.h:53
std::vector< AttributeBase::Ptr > mPrevStepDependencies
Definition Task.h:54
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
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