Commit d101f38b authored by Jan Dinkelbach's avatar Jan Dinkelbach
Browse files

first version of averaged inverter model with PowerControllerVSI

parent 77a9d270
......@@ -16,13 +16,6 @@ namespace Base {
/// @brief Base model of average inverter
class AvVoltageSourceInverterDQ {
protected:
/// Complex nominal voltage [V]
Real mVnom;
/// Power parameters
Real mPref;
Real mQref;
/// filter parameters
Real mLf;
Real mCf;
......@@ -34,70 +27,12 @@ namespace Base {
Real mTransformerInductance;
Real mTransformerRatioAbs;
Real mTransformerRatioPhase;
/// PLL
Real mOmegaN;
Real mKiPLL;
Real mKpPLL;
/// Power controller
Real mOmegaCutoff;
Real mKiPowerCtrld;
Real mKiPowerCtrlq;
Real mKpPowerCtrld;
Real mKpPowerCtrlq;
/// Current controller
Real mKiCurrCtrld;
Real mKiCurrCtrlq;
Real mKpCurrCtrld;
Real mKpCurrCtrlq;
/// states
Real mThetaPLL = 0;
Real mPhiPLL;
Real mP;
Real mQ;
Real mPhi_d;
Real mPhi_q;
Real mGamma_d;
Real mGamma_q;
/// initial values for states
Real mThetaPLLInit = 0;
Real mPhiPLLInit = 0;
Real mPInit = 0;
Real mQInit = 0;
Real mPhi_dInit = 0;
Real mPhi_qInit = 0;
Real mGamma_dInit = 0;
Real mGamma_qInit = 0;
/// state space matrices
Matrix mA = Matrix::Zero(8, 8);
Matrix mB = Matrix::Zero(8, 7);
Matrix mC = Matrix::Zero(2, 8);
Matrix mD = Matrix::Zero(2, 7);
/// state vector
Matrix mStates = Matrix::Zero(8, 1);
/// input vector
Matrix mU = Matrix::Zero(7, 1);
public:
/// Setter for general parameters
void setParameters(Real sysOmega, Real sysVoltNom, Real Pref, Real Qref);
/// Setter for parameters of control loops
void setControllerParameters(Real Kp_pll, Real Ki_pll, Real Kp_powerCtrl, Real Ki_powerCtrl, Real Kp_currCtrl, Real Ki_currCtrl, Real Omega_cutoff);
/// Setter for filter parameters
void setFilterParameters(Real Lf, Real Cf, Real Rf, Real Rc);
/// Setter for optional connection transformer
void setTransformerParameters(Real nomVoltageEnd1, Real nomVoltageEnd2, Real ratedPower, Real ratioAbs,
Real ratioPhase, Real resistance, Real inductance, Real omega);
/// Setter for initial state values
void setInitialStateValues(Real thetaPLLInit, Real phiPLLInit, Real pInit, Real qInit,
Real phi_dInit, Real phi_qInit, Real gamma_dInit, Real gamma_qInit);
};
}
}
/* Copyright 2017-2020 Institute for Automation of Complex Power Systems,
* EONERC, RWTH Aachen University
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*********************************************************************************/
#pragma once
#include <cps/Definitions.h>
#include <cps/TopologicalPowerComp.h>
namespace CPS {
namespace Base {
/// @brief Base model of average inverter
class AvVoltageSourceInverterDQWithStateSpace {
protected:
/// Complex nominal voltage [V]
Real mVnom;
/// Power parameters
Real mPref;
Real mQref;
/// filter parameters
Real mLf;
Real mCf;
Real mRf;
Real mRc;
/// transformer
Real mTransformerResistance;
Real mTransformerInductance;
Real mTransformerRatioAbs;
Real mTransformerRatioPhase;
/// PLL
Real mOmegaN;
Real mKiPLL;
Real mKpPLL;
/// Power controller
Real mOmegaCutoff;
Real mKiPowerCtrld;
Real mKiPowerCtrlq;
Real mKpPowerCtrld;
Real mKpPowerCtrlq;
/// Current controller
Real mKiCurrCtrld;
Real mKiCurrCtrlq;
Real mKpCurrCtrld;
Real mKpCurrCtrlq;
/// states
Real mThetaPLL = 0;
Real mPhiPLL;
Real mP;
Real mQ;
Real mPhi_d;
Real mPhi_q;
Real mGamma_d;
Real mGamma_q;
/// initial values for states
Real mThetaPLLInit = 0;
Real mPhiPLLInit = 0;
Real mPInit = 0;
Real mQInit = 0;
Real mPhi_dInit = 0;
Real mPhi_qInit = 0;
Real mGamma_dInit = 0;
Real mGamma_qInit = 0;
/// state space matrices
Matrix mA = Matrix::Zero(8, 8);
Matrix mB = Matrix::Zero(8, 7);
Matrix mC = Matrix::Zero(2, 8);
Matrix mD = Matrix::Zero(2, 7);
/// state vector
Matrix mStates = Matrix::Zero(8, 1);
/// input vector
Matrix mU = Matrix::Zero(7, 1);
public:
/// Setter for general parameters
void setParameters(Real sysOmega, Real sysVoltNom, Real Pref, Real Qref);
/// Setter for parameters of control loops
void setControllerParameters(Real Kp_pll, Real Ki_pll, Real Kp_powerCtrl, Real Ki_powerCtrl, Real Kp_currCtrl, Real Ki_currCtrl, Real Omega_cutoff);
/// Setter for filter parameters
void setFilterParameters(Real Lf, Real Cf, Real Rf, Real Rc);
/// Setter for optional connection transformer
void setTransformerParameters(Real nomVoltageEnd1, Real nomVoltageEnd2, Real ratedPower, Real ratioAbs,
Real ratioPhase, Real resistance, Real inductance, Real omega);
/// Setter for initial state values
void setInitialStateValues(Real thetaPLLInit, Real phiPLLInit, Real pInit, Real qInit,
Real phi_dInit, Real phi_qInit, Real gamma_dInit, Real gamma_qInit);
};
}
}
......@@ -19,6 +19,7 @@
#include <cps/Base/Base_AvVoltageSourceInverterDQ.h>
#include <cps/PowerProfile.h>
#include <cps/Signal/PLL.h>
#include <cps/Signal/PowerControllerVSI.h>
namespace CPS {
namespace DP {
......@@ -29,9 +30,24 @@ namespace Ph1 {
public MNAInterface,
public SharedFactory<AvVoltageSourceInverterDQ> {
protected:
// ### General Parameters ###
/// Nominal frequency
Real mOmegaN;
/// Nominal voltage
Real mVnom;
/// Simulation step
Real mTimeStep;
/// Active power reference
Real mPref;
/// Reactive power reference
Real mQref;
// ### Control Subcomponents ###
/// PLL
std::shared_ptr<Signal::PLL> mPLL;
/// Power Controller
std::shared_ptr<Signal::PowerControllerVSI> mPowerControllerVSI;
// ### Electrical Subcomponents ###
/// Controlled voltage source
......@@ -47,11 +63,11 @@ namespace Ph1 {
/// Optional connection transformer
std::shared_ptr<DP::Ph1::Transformer> mConnectionTransformer;
// ### Inverter Variables ###
// ### Inverter Interfacing Variables ###
// Control inputs
///
/// Measured voltage in local reference frame
Matrix mVcdq = Matrix::Zero(2, 1);
///
/// Measured current in local reference frame
Matrix mIrcdq = Matrix::Zero(2, 1);
// Control outputs
/// Control output before transformation interface
......@@ -59,35 +75,19 @@ namespace Ph1 {
/// Control output before transformation interface
MatrixComp mControllerOutput = MatrixComp::Zero(1,1);
/// instantaneous omega
Real mOmegaInst=0;
/// instantaneous frequency
Real mFreqInst=0;
///
Bool mIsLoad=false;
///
Bool mWithConnectionTransformer=false;
/// in case variable time step simulation should be developed in the future
Real mTimeStep;
///
std::vector<Real>* mGenProfile = nullptr;
///
std::vector<Real>::iterator mCurrentPower;
///
std::vector<PQData>::iterator mCurrentLoad;
///
UInt mProfileUndateRate = 1000;
///
Attribute<Real>::Ptr mQRefInput;
// /// instantaneous omega
// Real mOmegaInst=0;
// /// instantaneous frequency
// Real mFreqInst=0;
/// Boolean for connection transformer usage
Bool mWithConnectionTransformer=false;
// #### solver ####
///
std::vector<const Matrix*> mRightVectorStamps;
public:
///
std::vector<PQData> mLoadProfile;
/// Defines name amd logging level
AvVoltageSourceInverterDQ(String name, Logger::Level logLevel = Logger::Level::off)
: AvVoltageSourceInverterDQ(name, name, logLevel) {}
......@@ -97,20 +97,18 @@ namespace Ph1 {
// #### General ####
/// Initializes component from power flow data
void initializeFromPowerflow(Real frequency);
///
/// General initalization
void initialize(Matrix frequencies);
///
SimPowerComp<Complex>::Ptr clone(String copySuffix);
///
/// Setter for general parameters of inverter
void setParameters(Real sysOmega, Real sysVoltNom, Real Pref, Real Qref);
/// Setter for parameters of control loops
void setControllerParameters(Real Kp_pll, Real Ki_pll, Real Kp_powerCtrl, Real Ki_powerCtrl, Real Kp_currCtrl, Real Ki_currCtrl, Real Omega_cutoff);
///
/// Setter for parameters of transformer
void setTransformerParameters(Real nomVoltageEnd1, Real nomVoltageEnd2,
Real ratedPower, Real ratioAbs, Real ratioPhase, Real resistance, Real inductance, Real omega);
///
/// Setter for parameters of filter
void setFilterParameters(Real Lf, Real Cf, Real Rf, Real Rc);
///
/// Setter for initial values applied in controllers
void setInitialStateValues(Real thetaPLLInit, Real phiPLLInit, Real pInit, Real qInit,
Real phi_dInit, Real phi_qInit, Real gamma_dInit, Real gamma_qInit);
......@@ -135,18 +133,8 @@ namespace Ph1 {
void mnaAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute<Matrix>::Ptr &leftVector);
// #### Control section ####
///
void initializeStateSpaceModel(Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector);
///
void updateInputStateSpaceModel(Real time);
///
void updateStates();
///
void updateBMatrixStateSpaceModel();
/// convert between two rotating frames
Complex rotatingFrame2to1(Complex f, Real theta1, Real theta2);
///
void step(Real time, Int timeStepCount);
/// Control pre step operations
void controlPreStep(Real time, Int timeStepCount);
/// Perform step of controller
......@@ -156,20 +144,6 @@ namespace Ph1 {
/// Add control step dependencies
void addControlStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes);
// #### Profile handling ####
///
void addGenProfile(std::vector<Real>* genProfile);
///
void addAggregatedGenProfile(std::vector<Real>* genProfile, Real customerNumber);
///
void makeLoad(Bool isLoad){mIsLoad=isLoad;};
///
Bool isLoad(){return mIsLoad;};
///
void setProfileUpdateRate(UInt rate){mProfileUndateRate=rate;};
///
void updatePowerGeneration();
class ControlPreStep : public CPS::Task {
public:
ControlPreStep(AvVoltageSourceInverterDQ& AvVoltageSourceInverterDQ) :
......
......@@ -16,13 +16,13 @@
#include <cps/EMT/EMT_Ph3_Capacitor.h>
#include <cps/EMT/EMT_Ph3_ControlledVoltageSource.h>
#include <cps/EMT/EMT_Ph3_Transformer.h>
#include <cps/Base/Base_AvVoltageSourceInverterDQ.h>
#include <cps/Base/Base_AvVoltageSourceInverterDQWithStateSpace.h>
namespace CPS {
namespace EMT {
namespace Ph3 {
class AvVoltageSourceInverterDQ :
public Base::AvVoltageSourceInverterDQ,
public Base::AvVoltageSourceInverterDQWithStateSpace,
public SimPowerComp<Real>,
public MNAInterface,
public SharedFactory<AvVoltageSourceInverterDQ> {
......
/* Copyright 2017-2020 Institute for Automation of Complex Power Systems,
* EONERC, RWTH Aachen University
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*********************************************************************************/
#pragma once
#include <vector>
#include <cps/SimPowerComp.h>
#include <cps/SimSignalComp.h>
#include <cps/Task.h>
namespace CPS {
namespace Signal {
class PowerControllerVSI :
public SimSignalComp,
public SharedFactory<PowerControllerVSI> {
protected:
Real mTimeStep;
/// Complex nominal voltage [V]
Real mVnom;
/// Power parameters
Real mPref;
Real mQref;
/// PLL
Real mOmegaN;
Real mKiPLL;
Real mKpPLL;
/// Power controller
Real mOmegaCutoff;
Real mKiPowerCtrld;
Real mKiPowerCtrlq;
Real mKpPowerCtrld;
Real mKpPowerCtrlq;
/// Current controller
Real mKiCurrCtrld;
Real mKiCurrCtrlq;
Real mKpCurrCtrld;
Real mKpCurrCtrlq;
/// states
Real mThetaPLL = 0;
Real mPhiPLL;
Real mP;
Real mQ;
Real mPhi_d;
Real mPhi_q;
Real mGamma_d;
Real mGamma_q;
/// initial values for states
Real mThetaPLLInit = 0;
Real mPhiPLLInit = 0;
Real mPInit = 0;
Real mQInit = 0;
Real mPhi_dInit = 0;
Real mPhi_qInit = 0;
Real mGamma_dInit = 0;
Real mGamma_qInit = 0;
/// state space matrices
Matrix mA = Matrix::Zero(8, 8);
Matrix mB = Matrix::Zero(8, 7);
Matrix mC = Matrix::Zero(2, 8);
Matrix mD = Matrix::Zero(2, 7);
/// state vector
Matrix mStates = Matrix::Zero(8, 1);
/// input vector
Matrix mU = Matrix::Zero(7, 1);
public:
PowerControllerVSI(String name, Logger::Level logLevel = Logger::Level::off);
/// Setter for general parameters
void setParameters(Real sysOmega, Real sysVoltNom, Real Pref, Real Qref);
/// Setter for parameters of control loops
void setControllerParameters(Real Kp_pll, Real Ki_pll, Real Kp_powerCtrl, Real Ki_powerCtrl, Real Kp_currCtrl, Real Ki_currCtrl, Real Omega_cutoff);
/// Setter for initial state values
void setInitialStateValues(Real thetaPLLInit, Real phiPLLInit, Real pInit, Real qInit,
Real phi_dInit, Real phi_qInit, Real gamma_dInit, Real gamma_qInit);
///
void initializeStateSpaceModel(Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector);
///
void updateBMatrixStateSpaceModel();
/// step operations
void signalStep(Real time, Int timeStepCount);
/// add step dependencies
void signalAddStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) {};
Task::List getTasks();
class Step : public Task {
public:
Step(PowerControllerVSI& powerControllerVSI) :
Task(powerControllerVSI.mName + ".Step"), mPowerControllerVSI(powerControllerVSI) {
mPowerControllerVSI.signalAddStepDependencies(mPrevStepDependencies, mAttributeDependencies, mModifiedAttributes);
}
void execute(Real time, Int timeStepCount) { mPowerControllerVSI.signalStep(time, timeStepCount); };
private:
PowerControllerVSI& mPowerControllerVSI;
};
};
}
}
......@@ -19,80 +19,9 @@ void Base::AvVoltageSourceInverterDQ::setTransformerParameters(Real nomVoltageEn
mTransformerRatioPhase = ratioPhase;
};
void Base::AvVoltageSourceInverterDQ::setParameters(Real sysOmega, Real sysVoltNom, Real Pref, Real Qref) {
mPref = Pref;
mQref = Qref;
mVnom = sysVoltNom;
mOmegaN = sysOmega;
// use Pref and Qref as init values for states P and Q
// init values for other states remain zero (if not changed using setInitialStateValues)
mPInit = Pref;
mQInit = Qref;
}
void Base::AvVoltageSourceInverterDQ::setControllerParameters(Real Kp_pll, Real Ki_pll,
Real Kp_powerCtrl, Real Ki_powerCtrl, Real Kp_currCtrl, Real Ki_currCtrl, Real Omega_cutoff) {
mKpPLL = Kp_pll;
mKiPLL = Ki_pll;
mKiPowerCtrld = Ki_powerCtrl;
mKiPowerCtrlq = Ki_powerCtrl;
mKpPowerCtrld = Kp_powerCtrl;
mKpPowerCtrlq = Kp_powerCtrl;
mKiCurrCtrld = Ki_currCtrl;
mKiCurrCtrlq = Ki_currCtrl;
mKpCurrCtrld = Kp_currCtrl;
mKpCurrCtrlq = Kp_currCtrl;
mOmegaCutoff = Omega_cutoff;
// Set state space matrices using controller parameters
mA <<
0, mKiPLL, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, -mOmegaCutoff, 0, 0, 0, 0, 0,
0, 0, 0, -mOmegaCutoff, 0, 0, 0, 0,
0, 0, -1, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0,
0, 0, -mKpPowerCtrld, 0, mKiPowerCtrld, 0, 0, 0,
0, 0, 0, mKpPowerCtrlq, 0, mKiPowerCtrlq, 0, 0;
mB <<
1, 0, 0, 0, mKpPLL, 0, 0,
0, 0, 0, 0, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,
0, 1, 0, 0, 0, 0, 0,
0, 0, -1, 0, 0, 0, 0,
0, mKpPowerCtrld, 0, 0, 0, -1, 0,
0, 0, -mKpPowerCtrlq, 0, 0, 0, -1;
mC <<
0, 0, -mKpPowerCtrld * mKpCurrCtrld, 0, mKpCurrCtrld * mKiPowerCtrld, 0, mKiCurrCtrld, 0,
0, 0, 0, mKpPowerCtrlq * mKpCurrCtrlq, 0, mKpCurrCtrlq*mKiPowerCtrlq, 0, mKiCurrCtrlq;
mD <<
0, mKpCurrCtrld*mKpPowerCtrld, 0, 0, 0, -mKpCurrCtrld, 0,
0, 0, -mKpCurrCtrlq * mKpPowerCtrlq, 0, 0, 0, -mKpCurrCtrlq;
}
void Base::AvVoltageSourceInverterDQ::setFilterParameters(Real Lf, Real Cf, Real Rf, Real Rc) {
mLf = Lf;
mCf = Cf;
mRf = Rf;
mRc = Rc;
}
void Base::AvVoltageSourceInverterDQ::setInitialStateValues(Real thetaPLLInit, Real phiPLLInit, Real pInit, Real qInit,
Real phi_dInit, Real phi_qInit, Real gamma_dInit, Real gamma_qInit) {
mThetaPLLInit = thetaPLLInit;
mPhiPLLInit = phiPLLInit;
mPInit = pInit;
mQInit = qInit;
mPhi_dInit = phi_dInit;
mPhi_qInit = phi_qInit;
mGamma_dInit = gamma_dInit;
mGamma_qInit = gamma_qInit;
}
}
\ No newline at end of file
/* Copyright 2017-2020 Institute for Automation of Complex Power Systems,
* EONERC, RWTH Aachen University
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*********************************************************************************/
#include <cps/Base/Base_AvVoltageSourceInverterDQWithStateSpace.h>
using namespace CPS;
void Base::AvVoltageSourceInverterDQWithStateSpace::setTransformerParameters(Real nomVoltageEnd1, Real nomVoltageEnd2, Real ratedPower, Real ratioAbs,
Real ratioPhase, Real resistance, Real inductance, Real omega) {
mTransformerResistance = resistance;
mTransformerInductance = inductance;
mTransformerRatioAbs = ratioAbs;
mTransformerRatioPhase = ratioPhase;
};
void Base::AvVoltageSourceInverterDQWithStateSpace::setParameters(Real sysOmega, Real sysVoltNom, Real Pref, Real Qref) {
mPref = Pref;
mQref = Qref;
mVnom = sysVoltNom;
mOmegaN = sysOmega;
// use Pref and Qref as init values for states P and Q
// init values for other states remain zero (if not changed using setInitialStateValues)