DPsim
Loading...
Searching...
No Matches
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
11using namespace CPS;
12
13DP::Ph3::SynchronGeneratorDQTrapez::SynchronGeneratorDQTrapez(
14 String uid, String name, Logger::Level logLevel)
15 : SynchronGeneratorDQ(uid, name, logLevel) {}
16
17DP::Ph3::SynchronGeneratorDQTrapez::SynchronGeneratorDQTrapez(
18 String name, Logger::Level logLevel)
19 : SynchronGeneratorDQ(name, name, logLevel) {}
20
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
43void DP::Ph3::SynchronGeneratorDQTrapez::mnaCompPreStep(Real time,
44 Int timeStepCount) {
45 stepInPerUnit(time); //former system solve (trapezoidal)
46 mnaCompApplyRightSideVectorStamp(**mRightVector);
47}
48
49void 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
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
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,
92 mBase_OmElec * mVsr, mTimeStep / mMultisamplingRate);
93 } else {
94 mPsisr = Math::StateSpaceTrapezoidal(
95 mPsisr,
97 mBase_OmElec * mVsr, mTimeStep / mMultisamplingRate);
98 }
99
100 // Calculate new currents from fluxes
102 }
103
104 mIdq0(0, 0) = mIsr(0, 0);
105 mIdq0(1, 0) = mIsr(3, 0);
106 mIdq0(2, 0) = mIsr(6, 0);
108}
Matrix mIsr
Vector of stator and rotor currents.
Real mTimeStep
Simulation time step.
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.
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.
Matrix mOmegaFluxMat
Omega-flux matrix for state space system.
Matrix mIdq0
dq0 current calculated from terminal current
Real mBase_OmElec
base electrical angular frequency
Matrix mVdq0
dq0 voltage calculated from terminal voltage
Real mBase_OmMech
base mechanical angular frequency
Real mBase_V
base stator voltage (phase-to-ground peak)
const Attribute< Real >::Ptr mOmMech
rotor speed omega_r
Bool mHasTurbineGovernor
Determines if Turbine and Governor are activated.
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
Matrix abcToDq0Transform(Real theta, MatrixComp &abc)
Park transform as described in Krause.
MatrixComp dq0ToAbcTransform(Real theta, Matrix &dq0)
Inverse Park transform as described in Krause.
void mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
Initializes variables of component.
Attribute< Matrix >::Ptr mRightVector
const Attribute< MatrixVar< Complex > >::Ptr mIntfCurrent
const Attribute< MatrixVar< Complex > >::Ptr mIntfVoltage
Logger::Log mSLog
Component logger.