DPsim
PowerControllerVSI.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 
17 namespace CPS {
18 namespace Signal {
20  public SharedFactory<PowerControllerVSI> {
21 
22 protected:
24  Real mTimeStep;
25 
26  // Power parameters
27  Real mPref = 0;
28  Real mQref = 0;
29 
30  // Power controller
31  Real mOmegaCutoff;
32  Real mKiPowerCtrld;
33  Real mKiPowerCtrlq;
34  Real mKpPowerCtrld;
35  Real mKpPowerCtrlq;
36 
37  // Current controller
38  Real mKiCurrCtrld;
39  Real mKiCurrCtrlq;
40  Real mKpCurrCtrld;
41  Real mKpCurrCtrlq;
42 
44  Real mPInit = 0;
45  Real mQInit = 0;
46  Real mPhi_dInit = 0;
47  Real mPhi_qInit = 0;
48  Real mGamma_dInit = 0;
49  Real mGamma_qInit = 0;
50 
51  // state space matrices
53  Matrix mA = Matrix::Zero(6, 6);
55  Matrix mB = Matrix::Zero(6, 6);
57  Matrix mC = Matrix::Zero(2, 6);
59  Matrix mD = Matrix::Zero(2, 6);
60 
61 public:
62  // attributes of input references
65  const Attribute<Real>::Ptr mVc_q;
66  const Attribute<Real>::Ptr mIrc_d;
67  const Attribute<Real>::Ptr mIrc_q;
68 
69  // input, state and output vectors
82 
83  PowerControllerVSI(String name, Logger::Level logLevel = Logger::Level::off);
84 
86  void setParameters(Real Pref, Real Qref);
88  void setControllerParameters(Real Kp_powerCtrl, Real Ki_powerCtrl,
89  Real Kp_currCtrl, Real Ki_currCtrl,
90  Real Omega_cutoff);
92  void setInitialStateValues(Real pInit, Real qInit, Real phi_dInit,
93  Real phi_qInit, Real gamma_dInit,
94  Real gamma_qInit);
95 
97  void initializeStateSpaceModel(Real omega, Real timeStep,
98  Attribute<Matrix>::Ptr leftVector);
101 
103  void signalPreStep(Real time, Int timeStepCount);
105  void signalAddPreStepDependencies(AttributeBase::List &prevStepDependencies,
106  AttributeBase::List &attributeDependencies,
107  AttributeBase::List &modifiedAttributes);
109  void signalStep(Real time, Int timeStepCount);
111  void signalAddStepDependencies(AttributeBase::List &prevStepDependencies,
112  AttributeBase::List &attributeDependencies,
113  AttributeBase::List &modifiedAttributes);
114 
115  Task::List getTasks();
116 
117  class PreStep : public Task {
118  public:
119  PreStep(PowerControllerVSI &powerControllerVSI)
120  : Task(**powerControllerVSI.mName + ".PreStep"),
121  mPowerControllerVSI(powerControllerVSI) {
122  mPowerControllerVSI.signalAddPreStepDependencies(
123  mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes);
124  }
125  void execute(Real time, Int timeStepCount) {
126  mPowerControllerVSI.signalPreStep(time, timeStepCount);
127  };
128 
129  private:
130  PowerControllerVSI &mPowerControllerVSI;
131  };
132  class Step : public Task {
133  public:
134  Step(PowerControllerVSI &powerControllerVSI)
135  : Task(**powerControllerVSI.mName + ".Step"),
136  mPowerControllerVSI(powerControllerVSI) {
137  mPowerControllerVSI.signalAddStepDependencies(
138  mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes);
139  }
140  void execute(Real time, Int timeStepCount) {
141  mPowerControllerVSI.signalStep(time, timeStepCount);
142  };
143 
144  private:
145  PowerControllerVSI &mPowerControllerVSI;
146  };
147 };
148 } // namespace Signal
149 } // namespace CPS
const Attribute< String >::Ptr mName
Human readable name.
Real mTimeStep
Simulation time step.
void setControllerParameters(Real Kp_powerCtrl, Real Ki_powerCtrl, Real Kp_currCtrl, Real Ki_currCtrl, Real Omega_cutoff)
Setter for parameters of control loops.
const Attribute< Matrix >::Ptr mInputPrev
Previous Input.
Matrix mD
matrix D of state space model
Matrix mC
matrix C of state space model
void setParameters(Real Pref, Real Qref)
Setter for general parameters.
void signalAddStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes)
add step dependencies
Real mPInit
initial values for states
void setInitialStateValues(Real pInit, Real qInit, Real phi_dInit, Real phi_qInit, Real gamma_dInit, Real gamma_qInit)
Setter for initial state values.
void updateBMatrixStateSpaceModel()
Update B matrix due to its dependence on the input.
const Attribute< Matrix >::Ptr mStateCurr
Current State.
void signalStep(Real time, Int timeStepCount)
step operations
void initializeStateSpaceModel(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector)
Initialize vectors of state space model.
const Attribute< Real >::Ptr mVc_d
These are never explicitely set to reference anything, so the outside code is responsible for setting...
void signalPreStep(Real time, Int timeStepCount)
pre step operations
const Attribute< Matrix >::Ptr mOutputCurr
Current Output.
void signalAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes)
pre step dependencies
const Attribute< Matrix >::Ptr mInputCurr
Current Input.
const Attribute< Matrix >::Ptr mStatePrev
Previous State.
Matrix mA
matrix A of state space model
const Attribute< Matrix >::Ptr mOutputPrev
Previous Output.
Matrix mB
matrix B of state space model
Tasks to be defined by every component.
Definition: Task.h:25