DPsim
Loading...
Searching...
No Matches
PLL.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 <vector>
12
13#include <dpsim-models/SimPowerComp.h>
14#include <dpsim-models/SimSignalComp.h>
15#include <dpsim-models/Task.h>
16
17namespace CPS {
18namespace Signal {
19class PLL : public SimSignalComp, public SharedFactory<PLL> {
20
21protected:
23 Real mKp;
25 Real mKi;
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:
43 const Attribute<Real>::Ptr mInputRef;
44
46 const Attribute<Matrix>::Ptr mInputPrev;
48 const Attribute<Matrix>::Ptr mInputCurr;
50 const Attribute<Matrix>::Ptr mStatePrev;
52 const Attribute<Matrix>::Ptr mStateCurr;
54 const Attribute<Matrix>::Ptr mOutputPrev;
56 const Attribute<Matrix>::Ptr mOutputCurr;
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
80 Task::List getTasks();
81
82 class PreStep : public Task {
83 public:
84 PreStep(PLL &pll) : Task(**pll.mName + ".PreStep"), mPLL(pll) {
85 mPLL.signalAddPreStepDependencies(
86 mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes);
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(
100 mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes);
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
const Attribute< String >::Ptr mName
Human readable name.
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
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
Real mKi
Integration constant of PI controller.
Definition PLL.h:25