DPsim
DP_Ph3_SynchronGeneratorDQTrapez.cpp
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 #include <dpsim-models/DP/DP_Ph3_SynchronGeneratorDQTrapez.h>
10 
11 using namespace CPS;
12 
13 DP::Ph3::SynchronGeneratorDQTrapez::SynchronGeneratorDQTrapez(
14  String uid, String name, Logger::Level logLevel)
15  : SynchronGeneratorDQ(uid, name, logLevel) {}
16 
17 DP::Ph3::SynchronGeneratorDQTrapez::SynchronGeneratorDQTrapez(
18  String name, Logger::Level logLevel)
19  : SynchronGeneratorDQ(name, name, logLevel) {}
20 
21 void DP::Ph3::SynchronGeneratorDQTrapez::mnaCompInitialize(
22  Real omega, Real timeStep, Attribute<Matrix>::Ptr leftVector) {
24  mTimeStep = timeStep;
25 
26  SPDLOG_LOGGER_INFO(mSLog,
27  "\nFluxStateSpaceMat: \n{}"
28  "\nOmegaFluxMat: \n{}"
29  "\nResistances: {} {} {}",
31  mVdq0(0, 0) / mIdq0(0, 0), mVdq0(1, 0) / mIdq0(1, 0),
32  mVdq0(2, 0) / mIdq0(2, 0));
33 }
34 
36  AttributeBase::List &prevStepDependencies,
37  AttributeBase::List &attributeDependencies,
38  AttributeBase::List &modifiedAttributes) {
39  modifiedAttributes.push_back(mRightVector);
40  prevStepDependencies.push_back(mIntfVoltage);
41 }
42 
43 void DP::Ph3::SynchronGeneratorDQTrapez::mnaCompPreStep(Real time,
44  Int timeStepCount) {
45  stepInPerUnit(time); //former system solve (trapezoidal)
46  mnaCompApplyRightSideVectorStamp(**mRightVector);
47 }
48 
49 void DP::Ph3::SynchronGeneratorDQTrapez::setMultisamplingRate(Int rate) {
50  mMultisamplingRate = rate;
51 }
52 
54  // Receives the voltage of time step k and has to
55  // calculate the current output for time step k+1
56  for (Int i = 0; i < mMultisamplingRate; i++) {
57  // Calculate per unit values and
58  // transform per unit voltages from abc to dq0
59  mVdq0 = abcToDq0Transform(mThetaMech, **mIntfVoltage);
60  mVdq0 = mVdq0 / mBase_V;
61  mVsr(0, 0) = mVdq0(0, 0);
62  mVsr(3, 0) = mVdq0(1, 0);
63  mVsr(6, 0) = mVdq0(2, 0);
64  // Current is already available in pu dq0 from previous step
65 
66  // Update of fd winding voltage from exciter
67  if (mHasExciter) {
68  //mVsr(1,0) = mExciter.step(mVsr(0,0), mVsr(3,0), 1, mTimeStep);
69  }
70 
71  // Update of mechanical torque from turbine governor
72  if (mHasTurbineGovernor == true) {
73  //mMechTorque = mTurbineGovernor.step(mOmMech, 1, 300e6 / 555e6, mTimeStep);
74  }
75 
76  // Calculation of electrical torque
77  **mElecTorque = (mPsisr(3, 0) * mIsr(0, 0) - mPsisr(0, 0) * mIsr(3, 0));
78 
79  // Update mechanical rotor angle with respect to electrical angle
80  // using Euler and previous states
81  mThetaMech = mThetaMech + mTimeStep * ((**mOmMech - 1) * mBase_OmMech);
82 
83  // Update of omega using Euler
84  **mOmMech = **mOmMech + mTimeStep * (1. / (2. * **mInertia) *
85  (**mMechTorque - **mElecTorque));
86 
87  // Update of fluxes
88  if (mNumericalMethod == NumericalMethod::Euler) {
89  mPsisr = Math::StateSpaceEuler(
90  mPsisr,
91  mBase_OmElec * (mFluxStateSpaceMat + mOmegaFluxMat * **mOmMech),
92  mBase_OmElec * mVsr, mTimeStep / mMultisamplingRate);
93  } else {
94  mPsisr = Math::StateSpaceTrapezoidal(
95  mPsisr,
96  mBase_OmElec * (mFluxStateSpaceMat + mOmegaFluxMat * **mOmMech),
97  mBase_OmElec * mVsr, mTimeStep / mMultisamplingRate);
98  }
99 
100  // Calculate new currents from fluxes
101  mIsr = mFluxToCurrentMat * mPsisr;
102  }
103 
104  mIdq0(0, 0) = mIsr(0, 0);
105  mIdq0(1, 0) = mIsr(3, 0);
106  mIdq0(2, 0) = mIsr(6, 0);
107  **mIntfCurrent = mBase_I * dq0ToAbcTransform(mThetaMech, mIdq0);
108 }
Real mTimeStep
Simulation time step.
Matrix mFluxStateSpaceMat
Flux state space matrix excluding omega term.
Matrix mOmegaFluxMat
Omega-flux matrix for state space system.
Matrix mIdq0
dq0 current calculated from terminal current
Matrix mVdq0
dq0 voltage calculated from terminal voltage
void mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
void updateMatrixNodeIndices()
Update the "cached" mMatrixNodeIndices and mMatrixNodeIndexIsGround members.
Logger::Log mSLog
Component logger.