DPsim
Loading...
Searching...
No Matches
EMT_Ph3_SynchronGeneratorDQTrapez.cpp
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
10
11using namespace CPS;
12
13// !!! TODO: Adaptions to use in EMT_Ph3 models phase-to-ground peak variables
14// !!! with initialization from phase-to-phase RMS variables
15
22
26
28 Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
30 mTimeStep = timeStep;
31
33 for (UInt row = 0; row < 3; ++row)
34 for (UInt col = 0; col < 3; ++col)
36 matrixNodeIndex(0, col));
37}
38
40 AttributeBase::List &prevStepDependencies,
41 AttributeBase::List &attributeDependencies,
42 AttributeBase::List &modifiedAttributes) {
43 modifiedAttributes.push_back(mRightVector);
44 prevStepDependencies.push_back(mIntfVoltage);
45}
46
48 Int timeStepCount) {
49 stepInPerUnit(time); //former system solve (trapezoidal)
51}
52
54 // Receives the voltage of time step k and has to
55 // calculate the current output for time step k+1
56
57 // Calculate per unit values and
58 // transform per unit voltages from abc to dq0
60 mVsr(0, 0) = mVdq0(0, 0);
61 mVsr(3, 0) = mVdq0(1, 0);
62 mVsr(6, 0) = mVdq0(2, 0);
63 // Current is already available in pu dq0 from previous step
64
65 // Update of fd winding voltage from exciter
66 if (mHasExciter) {
67 Real Vpss = mHasPSS ? mPSS->step(**mOmMech, **mElecTorque, mVsr(0, 0),
68 mVsr(3, 0), mTimeStep)
69 : 0.0;
70 // Note: scaled by Rfd/Lmd to transform from exciter pu system
71 // to the synchronous generator pu system
72 mVsr(1, 0) =
73 (mRfd / mLmd) * mExciter->step(mVsr(0, 0), mVsr(3, 0), mTimeStep, Vpss);
74 }
75
76 // Update of mechanical torque from turbine governor
78 Real Pgv = mGovernor->step(**mOmMech, mTimeStep);
79 **mMechTorque = mTurbine->step(Pgv, mTimeStep);
80 } else if (mHasTurbineGovernorType1)
82 else if (mHasTurbineGovernor)
85
86 // Calculation of electrical torque
87 **mElecTorque = (mPsisr(3, 0) * mIsr(0, 0) - mPsisr(0, 0) * mIsr(3, 0));
88
89 // Update mechanical rotor angle with respect to electrical angle
90 // using Euler and previous states
92
93 // Update of omega using Euler
94 **mOmMech = **mOmMech + mTimeStep * (1. / (2. * **mInertia) *
95 (**mMechTorque - **mElecTorque));
96
97 // Update using euler
98 **mDelta = **mDelta + mTimeStep * (**mOmMech - 1);
99
100 // Integrate the machine states as a linear function of the newly solved
101 // terminal voltage. The Norton matrix below carries that voltage
102 // dependence into the network solve, avoiding an unstable explicit
103 // current-source/line-capacitance feedback loop.
105 const Matrix stateMatrix =
107 const Matrix identity = Matrix::Identity(mPsisr.rows(), mPsisr.rows());
108 const Matrix lhs = identity - (mTimeStep / 2.0) * stateMatrix;
109 const Matrix lhsInverse = lhs.inverse();
110 mFluxF = lhsInverse * (identity + (mTimeStep / 2.0) * stateMatrix);
111
112 Matrix inputSelector = Matrix::Zero(mPsisr.rows(), mPsisr.rows());
113 inputSelector(0, 0) = 1.0;
114 inputSelector(3, 3) = 1.0;
115 inputSelector(6, 6) = 1.0;
116 mFluxK = lhsInverse * (mTimeStep * mBase_OmElec) * inputSelector;
119
120 Matrix currentSelector = Matrix::Zero(3, mIsr.rows());
121 Matrix voltageSelector = Matrix::Zero(mVsr.rows(), 3);
122 currentSelector(0, 0) = 1.0;
123 currentSelector(1, 3) = 1.0;
124 currentSelector(2, 6) = 1.0;
125 voltageSelector(0, 0) = 1.0;
126 voltageSelector(3, 1) = 1.0;
127 voltageSelector(6, 2) = 1.0;
128 const Matrix dqJacobian =
129 currentSelector * mFluxToCurrentMat * mFluxK * voltageSelector;
130 const Real theta = mThetaMech;
131 Matrix dq0ToAbc(3, 3);
132 Matrix abcToDq0(3, 3);
133 dq0ToAbc << cos(theta), -sin(theta), 1., cos(theta - 2. * PI / 3.),
134 -sin(theta - 2. * PI / 3.), 1., cos(theta + 2. * PI / 3.),
135 -sin(theta + 2. * PI / 3.), 1.;
136 abcToDq0 << 2. / 3. * cos(theta), 2. / 3. * cos(theta - 2. * PI / 3.),
137 2. / 3. * cos(theta + 2. * PI / 3.), -2. / 3. * sin(theta),
138 -2. / 3. * sin(theta - 2. * PI / 3.),
139 -2. / 3. * sin(theta + 2. * PI / 3.), 1. / 3., 1. / 3., 1. / 3.;
140 mNortonConductance = (mBase_I / mBase_V) * dq0ToAbc * dqJacobian * abcToDq0;
141 mIdq0(0, 0) = mIsr(0, 0);
142 mIdq0(1, 0) = mIsr(3, 0);
143 mIdq0(2, 0) = mIsr(6, 0);
145}
146
148 SparseMatrixRow &systemMatrix) {
149 if (!terminalNotGrounded(0))
150 return;
151 for (UInt row = 0; row < 3; ++row)
152 for (UInt col = 0; col < 3; ++col)
153 Math::addToMatrixElement(systemMatrix, matrixNodeIndex(0, row),
154 matrixNodeIndex(0, col),
155 mNortonConductance(row, col));
156}
157
159 Matrix &rightVector) {
160 const Matrix compensationCurrent = mNortonConductance * **mIntfVoltage;
161 for (UInt phase = 0; phase < 3; ++phase)
162 Math::setVectorElement(rightVector, matrixNodeIndex(0, phase),
163 -(**mIntfCurrent)(phase, 0) +
164 compensationCurrent(phase, 0));
165}
166
168 Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
169 mnaCompUpdateVoltage(**leftVector);
171 mVsr(0, 0) = mVdq0(0, 0);
172 mVsr(3, 0) = mVdq0(1, 0);
173 mVsr(6, 0) = mVdq0(2, 0);
174
177 mIdq0(0, 0) = mIsr(0, 0);
178 mIdq0(1, 0) = mIsr(3, 0);
179 mIdq0(2, 0) = mIsr(6, 0);
181}
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:249
Matrix mIsr
Vector of stator and rotor currents.
Bool mHasTurbineGovernorType1
Determines if TurbineGovernorType1 is activated.
Real mTimeStep
Simulation time step.
Real mLmd
d-axis mutual inductance Lmd [H]
Real mBase_I
base stator current peak
Bool mHasExciter
Determines if Exciter is activated.
const Attribute< Real >::Ptr mMechTorque
mechanical torque
Matrix mFluxToCurrentMat
Calculates currents from fluxes.
std::shared_ptr< Base::Exciter > mExciter
Signal component modelling voltage regulator and exciter.
std::shared_ptr< Base::Turbine > mTurbine
Modular turbine (SteamTurbine / HydroTurbine)
Matrix mFluxStateSpaceMat
Flux state space matrix excluding omega term.
Matrix mVsr
Vector of stator and rotor voltages.
Matrix mPsisr
Vector of stator and rotor fluxes.
Bool mHasGovernorAndTurbine
Determines if modular Governor + Turbine pair is activated.
std::shared_ptr< Base::PSS > mPSS
Power system stabilizer.
std::shared_ptr< Signal::TurbineGovernor > mTurbineGovernor
Signal component modelling governor control and steam turbine (legacy)
Matrix mOmegaFluxMat
Omega-flux matrix for state space system.
Matrix mIdq0
dq0 current calculated from terminal current
std::shared_ptr< Base::Governor > mGovernor
Modular governor (SteamTurbineGovernor / HydroTurbineGovernor)
Real mRfd
field resistance Rfd [Ohm]
Real mBase_OmElec
base electrical angular frequency
Matrix mVdq0
dq0 voltage calculated from terminal voltage
Real mBase_OmMech
base mechanical angular frequency
const Attribute< Real >::Ptr mDelta
rotor angle delta
Bool mHasPSS
Determines if PSS is activated.
Real mBase_V
base stator voltage (phase-to-ground peak)
Real mNomPower
nominal power Pn [VA]
const Attribute< Real >::Ptr mOmMech
rotor speed omega_r
Bool mHasTurbineGovernor
Determines if legacy TurbineGovernor is activated.
std::shared_ptr< Signal::TurbineGovernorType1 > mTurbineGovernorType1
Signal component modelling governor control and steam turbine (TurbineGovernorType1)
const Attribute< Real >::Ptr mInertia
inertia constant H [s] for per unit or moment of inertia J [kg*m^2]
const Attribute< Real >::Ptr mElecTorque
electrical torque
virtual void mnaCompUpdateVoltage(const Matrix &leftVector) override
Retrieves calculated voltage from simulation for next step.
void initializeMatrixAndStates()
Initializes internal states and matrix.
MatrixFixedSize< 3, 1 > dq0ToAbcTransform(Real theta, const Eigen::Ref< const Matrix > &dq0)
Inverse Park transform as described in Krause.
MatrixFixedSize< 3, 1 > abcToDq0Transform(Real theta, Matrix &abc)
Park transform as described in Krause.
SynchronGeneratorDQ(String name, String uid, Logger::Level logLevel=Logger::Level::off)
Defines UID, name and logging level.
void mnaCompPreStep(Real time, Int timeStepCount) override
void mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) override
void mnaCompApplySystemMatrixStamp(SparseMatrixRow &systemMatrix) override
void mnaCompApplyRightSideVectorStamp(Matrix &rightVector) override
SynchronGeneratorDQTrapez(String uid, String name, Logger::Level loglevel=Logger::Level::off)
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
String uid()
Returns unique id.
spdlog::level::level_enum Level
Definition Logger.h:33
Attribute< Matrix >::Ptr mRightVector
std::vector< std::pair< UInt, UInt > > mVariableSystemMatrixEntries
static void setVectorElement(Matrix &mat, Matrix::Index row, Complex value, Int maxFreq=1, Int freqIdx=0, Matrix::Index colOffset=0)
static void addToMatrixElement(SparseMatrixRow &mat, Matrix::Index row, Matrix::Index column, Complex value, Int maxFreq=1, Int freqIdx=0)
UInt matrixNodeIndex(UInt nodeIndex)
const Attribute< MatrixVar< Real > >::Ptr mIntfCurrent
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
Bool terminalNotGrounded(UInt index)
#define PI
Definition Definitions.h:43
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
unsigned int UInt
Definition Definitions.h:58
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:72