SimplifiedVBR.cpp 8.32 KB
Newer Older
Viviane Sapucaia's avatar
Viviane Sapucaia committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/** Simplified Voltage behind reactance (EMT)
*
* @author Markus Mirz <mmirz@eonerc.rwth-aachen.de>
* @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
* @license GNU General Public License (version 3)
*
* DPsim
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*********************************************************************************/

#include "SimplifiedVBR.h"
#include "../IntegrationMethod.h"

using namespace DPsim;

SimplifiedVBR::SimplifiedVBR(String name, Int node1, Int node2, Int node3,
	Real nomPower, Real nomVolt, Real nomFreq, Int poleNumber, Real nomFieldCur,
	Real Rs, Real Ll, Real Lmd, Real Lmd0, Real Lmq, Real Lmq0,
	Real Rfd, Real Llfd, Real Rkd, Real Llkd,
	Real Rkq1, Real Llkq1, Real Rkq2, Real Llkq2,
	Real inertia, bool logActive)
	: SynchGenBase(name, node1, node2, node3, nomPower, nomVolt, nomFreq, poleNumber, nomFieldCur,
		Rs, Ll, Lmd, Lmd0, Lmq, Lmq0, Rfd, Llfd, Rkd, Llkd, Rkq1, Llkq1, Rkq2, Llkq2,
		inertia, logActive) {

Viviane Sapucaia's avatar
Viviane Sapucaia committed
38
39
	

Viviane Sapucaia's avatar
Viviane Sapucaia committed
40
41
42
43
44
45
46
47
}

SimplifiedVBR::~SimplifiedVBR() {
	if (mLogActive) {
		delete mLog;
	}
}

Viviane Sapucaia's avatar
Viviane Sapucaia committed
48
49
void SimplifiedVBR::AddExciter(Real Ta, Real Ka, Real Te, Real Ke, Real Tf, Real Kf, Real Tr, Real Lad, Real Rfd) {
	mExciter = Exciter(Ta, Ka, Te, Ke, Tf, Kf, Tr, Lad, Rfd, mVfd);
50
	WithExciter = true;
Viviane Sapucaia's avatar
Viviane Sapucaia committed
51
}
Viviane Sapucaia's avatar
Viviane Sapucaia committed
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

void SimplifiedVBR::init(Real om, Real dt,
	Real initActivePower, Real initReactivePower, Real initTerminalVolt, Real initVoltAngle, Real initFieldVoltage, Real initMechPower) {

	mResistanceMat = Matrix::Zero(3, 3);
	mResistanceMat <<
		mRs, 0, 0,
		0, mRs, 0,
		0, 0, mRs;

	R_load <<
		1037.8378 / mBase_Z, 0, 0,
		0, 1037.8378 / mBase_Z, 0,
		0, 0, 1037.8378 / mBase_Z;

	//Dynamic mutual inductances

	mDLmd = 1. / (1. / mLmd + 1. / mLlfd + 1. / mLlkd);

	mDLmq = 1. / (1. / mLmq + 1. / mLlkq1 + 1. / mLlkq2);

	A_flux <<
		-mRkq1 / mLlkq1*(1 - mDLmq / mLlkq1), mRkq1 / mLlkq1*(mDLmq / mLlkq2), 0, 0,
		mRkq2 / mLlkq2*(mDLmq / mLlkq1), -mRkq2 / mLlkq2*(1 - mDLmq / mLlkq2), 0, 0,
		0, 0, -mRfd / mLlfd*(1 - mDLmd / mLlfd), mRfd / mLlfd*(mDLmd / mLlkd),
		0, 0, mRkd / mLlkd*(mDLmd / mLlfd), -mRkd / mLlkd*(1 - mDLmd / mLlkd);
	B_flux <<
		mRkq1*mDLmq / mLlkq1, 0,
		mRkq2*mDLmq / mLlkq2, 0,
		0, mRfd*mDLmd / mLlfd,
		0, mRkd*mDLmd / mLlkd;

	mLa = (mDLmq + mDLmd) / 3.;
	mLb = (mDLmd - mDLmq) / 3.;

	mDLd = mLl + mDLmd;
	mDLq = mLl + mDLmq;

	// steady state per unit initial value
	initStatesInPerUnit(initActivePower, initReactivePower, initTerminalVolt, initVoltAngle, initFieldVoltage, initMechPower);

	// Correcting variables
	mThetaMech = mThetaMech + PI / 2;
	mMechTorque = -mMechTorque;
96
97
	mIq = -mIq;
	mId = -mId;
Viviane Sapucaia's avatar
Viviane Sapucaia committed
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153

	// #### VBR Model Dynamic variables #######################################

	mDPsid = mDLmd*(mPsifd / mLlfd) + mDLmd*(mPsikd / mLlkd);
	mDPsiq = mDLmq*(mPsikq1 / mLlkq1) + mDLmq*(mPsikq2 / mLlkq2);

	mDVq = mOmMech*mDPsid;
	mPsimq = mDLmq*(mPsikq1 / mLlkq1 + mPsikq2 / mLlkq2 + mIq);


	mDVd = -mOmMech*mDPsiq;
	mPsimd = mDLmd*(mPsifd / mLlfd + mPsikd / mLlkd + mId);

	mDVqd <<
		mDVq,
		mDVd;

	mVa = inverseParkTransform(mThetaMech, mVq, mVd, mV0)(0);
	mVb = inverseParkTransform(mThetaMech, mVq, mVd, mV0)(1);
	mVc = inverseParkTransform(mThetaMech, mVq, mVd, mV0)(2);

	mIa = inverseParkTransform(mThetaMech, mIq, mId, mI0)(0);
	mIb = inverseParkTransform(mThetaMech, mIq, mId, mI0)(1);
	mIc = inverseParkTransform(mThetaMech, mIq, mId, mI0)(2);

}


void SimplifiedVBR::step(SystemModel& system, Real time) {

	stepInPerUnit(system.getOmega(), system.getTimeStep(), time, system.getNumMethod());

	// Update current source accordingly
	if (mNode1 >= 0) {
		system.addRealToRightSideVector(mNode1, -mIa*mBase_i);
	}
	if (mNode2 >= 0) {
		system.addRealToRightSideVector(mNode2, -mIb*mBase_i);
	}
	if (mNode3 >= 0) {
		system.addRealToRightSideVector(mNode3, -mIc*mBase_i);
	}

	if (mLogActive) {
		Matrix logValues(getRotorFluxes().rows() + getDqStatorCurrents().rows() + 3, 1);
		logValues << getRotorFluxes(), getDqStatorCurrents(), getElectricalTorque(), getRotationalSpeed(), getRotorPosition();
		mLog->LogDataLine(time, logValues);
	}

}


void SimplifiedVBR::stepInPerUnit(Real om, Real dt, Real time, NumericalMethod numMethod) {

	// Calculate mechanical variables with euler
	mElecTorque = (mPsimd*mIq - mPsimq*mId);
154
	mOmMech = mOmMech + dt * (1. / (2. * mH) * (mElecTorque - mMechTorque));
Viviane Sapucaia's avatar
Viviane Sapucaia committed
155
156
157
158
159
160
161
162
163
164
165
166
	mThetaMech = mThetaMech + dt * (mOmMech* mBase_OmMech);

	Matrix R(2, 2);
	R <<
		-(mRs + R_load(0, 0)), -mOmMech*mDLd,
		mOmMech*mDLq, -(mRs + R_load(1, 1));

	mDqStatorCurrents = R.inverse()*mDVqd;

	mIq = mDqStatorCurrents(0, 0);
	mId = mDqStatorCurrents(1, 0);

167
168
169
170
	mIa_hist = mIa;
	mIb_hist = mIb;
	mIc_hist = mIc;

Viviane Sapucaia's avatar
Viviane Sapucaia committed
171
172
173
174
	mIa = inverseParkTransform(mThetaMech, mIq, mId, 0)(0);
	mIb = inverseParkTransform(mThetaMech, mIq, mId, 0)(1);
	mIc = inverseParkTransform(mThetaMech, mIq, mId, 0)(2);

175
176
177
	if (WithExciter == true) {
		mVq = -mRs*mIq - mOmMech*mDLd*mId + mDVq;
		mVd = -mRs*mId + mOmMech*mDLq*mIq + mDVd;
Viviane Sapucaia's avatar
Viviane Sapucaia committed
178

179
180
		mVfd = mExciter.step(mVd, mVq, 1, dt);
	}
Viviane Sapucaia's avatar
Viviane Sapucaia committed
181
182


183
184
185
186
187
	C_flux <<
		0,
		0,
		mVfd,
		0;
Viviane Sapucaia's avatar
Viviane Sapucaia committed
188

189
190
191
192
193
	mRotorFlux <<
		mPsikq1,
		mPsikq2,
		mPsifd,
		mPsikd;
Viviane Sapucaia's avatar
Viviane Sapucaia committed
194

195
	mRotorFlux = Trapezoidal(mRotorFlux, A_flux, B_flux, C_flux, dt*mBase_OmElec, mDqStatorCurrents);
Viviane Sapucaia's avatar
Viviane Sapucaia committed
196

197
198
199
200
	mPsikq1 = mRotorFlux(0);
	mPsikq2 = mRotorFlux(1);
	mPsifd = mRotorFlux(2);
	mPsikd = mRotorFlux(3);
Viviane Sapucaia's avatar
Viviane Sapucaia committed
201
202


203
	// Calculate dynamic flux likages
Viviane Sapucaia's avatar
Viviane Sapucaia committed
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
	mDPsiq = mDLmq*(mPsikq1 / mLlkq1) + mDLmq*(mPsikq2 / mLlkq2);
	mPsimq = mDLmq*(mPsikq1 / mLlkq1 + mPsikq2 / mLlkq2 + mIq);
	mDPsid = mDLmd*(mPsifd / mLlfd) + mDLmd*(mPsikd / mLlkd);
	mPsimd = mDLmd*(mPsifd / mLlfd + mPsikd / mLlkd + mId);

	// Calculate dynamic voltages
	mDVq = mOmMech*mDPsid;
	mDVd = -mOmMech*mDPsiq;

	mDVqd <<
		mDVq,
		mDVd;


	// Load resistance
219
	if (time < 0.1)
220
	{
221
222
223
224
		Ra = 1037.8378 / mBase_Z;
		Rb = 1037.8378 / mBase_Z;
		Rc = 1037.8378 / mBase_Z;

Viviane Sapucaia's avatar
Viviane Sapucaia committed
225
		R_load <<
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
			Ra, 0, 0,
			0, Rb, 0,
			0, 0, Rc;
	}
	else if (time > 0.2)
	{
		
		if (signbit(mIa) != signbit(mIa_hist)) 
			Ra = 1037.8378 / mBase_Z;
		if (signbit(mIb) != signbit(mIb_hist))
			Rb = 1037.8378 / mBase_Z;
		if (signbit(mIc) != signbit(mIc_hist))
			Rc = 1037.8378 / mBase_Z;

		R_load <<
			Ra, 0, 0,
			0, Rb, 0,
			0, 0, Rc;
244
245
246
	}
	else
	{
247
248
249
250
		Ra = 0.001 / mBase_Z;
		Rb = 0.001 / mBase_Z;
		Rc = 0.001 / mBase_Z;

251
		R_load <<
252
253
254
			Ra, 0, 0,
			0, Rb, 0,
			0, 0, Rc;
255
	}
Viviane Sapucaia's avatar
Viviane Sapucaia committed
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311

}


void SimplifiedVBR::postStep(SystemModel& system) {

}

void SimplifiedVBR::CalculateLandpL() {
	mDInductanceMat <<
		mLl + mLa - mLb*cos(2 * mThetaMech), -mLa / 2 - mLb*cos(2 * mThetaMech - 2 * PI / 3), -mLa / 2 - mLb*cos(2 * mThetaMech + 2 * PI / 3),
		-mLa / 2 - mLb*cos(2 * mThetaMech - 2 * PI / 3), mLl + mLa - mLb*cos(2 * mThetaMech - 4 * PI / 3), -mLa / 2 - mLb*cos(2 * mThetaMech),
		-mLa / 2 - mLb*cos(2 * mThetaMech + 2 * PI / 3), -mLa / 2 - mLb*cos(2 * mThetaMech), mLl + mLa - mLb*cos(2 * mThetaMech + 4 * PI / 3);
	pmDInductanceMat <<
		mLb*sin(2 * mThetaMech), mLb*sin(2 * mThetaMech - 2 * PI / 3), mLb*sin(2 * mThetaMech + 2 * PI / 3),
		mLb*sin(2 * mThetaMech - 2 * PI / 3), mLb*sin(2 * mThetaMech - 4 * PI / 3), mLb*sin(2 * mThetaMech),
		mLb*sin(2 * mThetaMech + 2 * PI / 3), mLb*sin(2 * mThetaMech), mLb*sin(2 * mThetaMech + 4 * PI / 3);
	pmDInductanceMat = pmDInductanceMat * 2 * mOmMech;
}


Matrix SimplifiedVBR::parkTransform(Real theta, Real a, Real b, Real c) {

	Matrix dq0vector(3, 1);

	Real q, d;

	q = 2. / 3. * cos(theta)*a + 2. / 3. * cos(theta - 2. * M_PI / 3.)*b + 2. / 3. * cos(theta + 2. * M_PI / 3.)*c;
	d = 2. / 3. * sin(theta)*a + 2. / 3. * sin(theta - 2. * M_PI / 3.)*b + 2. / 3. * sin(theta + 2. * M_PI / 3.)*c;

	dq0vector << q,
		d,
		0;

	return dq0vector;
}



Matrix SimplifiedVBR::inverseParkTransform(Real theta, Real q, Real d, Real zero) {

	Matrix abcVector(3, 1);

	Real a, b, c;

	a = cos(theta)*q + sin(theta)*d + 1.*zero;
	b = cos(theta - 2. * M_PI / 3.)*q + sin(theta - 2. * M_PI / 3.)*d + 1.*zero;
	c = cos(theta + 2. * M_PI / 3.)*q + sin(theta + 2. * M_PI / 3.)*d + 1.*zero;

	abcVector << a,
		b,
		c;

	return abcVector;
}