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);
41 Matrix mDiscreteA = Matrix::Zero(2, 2);
42 Matrix mDiscreteB = Matrix::Zero(2, 2);
43
44public:
47
60
61 PLL(String name, Logger::Level logLevel = Logger::Level::off);
63 void setParameters(Real kpPLL, Real kiPLL, Real omegaNom);
65 void setSimulationParameters(Real timestep);
67 void setInitialValues(Real input_init, Matrix state_init, Matrix output_init);
71 void signalPreStep(Real time, Int timeStepCount);
73 void signalStep(Real time, Int timeStepCount);
75 void signalAddPreStepDependencies(AttributeBase::List &prevStepDependencies,
76 AttributeBase::List &attributeDependencies,
77 AttributeBase::List &modifiedAttributes);
79 void signalAddStepDependencies(AttributeBase::List &prevStepDependencies,
80 AttributeBase::List &attributeDependencies,
81 AttributeBase::List &modifiedAttributes);
82
84
85 class PreStep : public Task {
86 public:
87 PreStep(PLL &pll) : Task(**pll.mName + ".PreStep"), mPLL(pll) {
88 mPLL.signalAddPreStepDependencies(
90 }
91 void execute(Real time, Int timeStepCount) {
92 mPLL.signalPreStep(time, timeStepCount);
93 };
94
95 private:
96 PLL &mPLL;
97 };
98
99 class Step : public Task {
100 public:
101 Step(PLL &pll) : Task(**pll.mName + ".Step"), mPLL(pll) {
102 mPLL.signalAddStepDependencies(
104 }
105 void execute(Real time, Int timeStepCount) {
106 mPLL.signalStep(time, timeStepCount);
107 };
108
109 private:
110 PLL &mPLL;
111 };
112};
113} // namespace Signal
114} // namespace CPS
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:249
spdlog::level::level_enum Level
Definition Logger.h:33
PreStep(PLL &pll)
Definition PLL.h:87
void execute(Real time, Int timeStepCount)
Definition PLL.h:91
Step(PLL &pll)
Definition PLL.h:101
void execute(Real time, Int timeStepCount)
Definition PLL.h:105
void setInitialValues(Real input_init, Matrix state_init, Matrix output_init)
Setter for initial values.
Definition PLL.cpp:44
const Attribute< Matrix >::Ptr mOutputPrev
Previous Output.
Definition PLL.h:57
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:97
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:46
const Attribute< Matrix >::Ptr mInputCurr
Current Input.
Definition PLL.h:51
const Attribute< Matrix >::Ptr mStatePrev
Previous State.
Definition PLL.h:53
void signalAddStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes)
add step dependencies
Definition PLL.cpp:89
Matrix mC
matrix C of state space model
Definition PLL.h:37
const Attribute< Matrix >::Ptr mOutputCurr
Current Output.
Definition PLL.h:59
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:60
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:73
Matrix mDiscreteA
Trapezoidal discrete maps cached when the simulation step is set.
Definition PLL.h:41
const Attribute< Matrix >::Ptr mStateCurr
Current State.
Definition PLL.h:55
const Attribute< Matrix >::Ptr mInputPrev
Previous Input.
Definition PLL.h:49
void signalPreStep(Real time, Int timeStepCount)
pre step operations
Definition PLL.cpp:83
Matrix mDiscreteB
Definition PLL.h:42
Task::List getTasks()
Definition PLL.cpp:119
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:70
std::vector< AttributeBase::Ptr > mPrevStepDependencies
Definition Task.h:71
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
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