DPsim
Loading...
Searching...
No Matches
EMT_Ph3_AvVoltSourceInverterStateSpace.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Institute for Automation of Complex Power Systems, EONERC, RWTH Aachen University
2// SPDX-License-Identifier: MPL-2.0
3
4#include <cmath>
5#include <stdexcept>
6
8
9using namespace CPS;
10
11namespace {
12void buildParkTransformPair(Real theta, Matrix &parkTransform,
13 Matrix &inverseParkTransform) {
14 const Real k = std::sqrt(2.0 / 3.0);
15 const Real angles[3] = {theta, theta - 2.0 * PI / 3.0,
16 theta + 2.0 * PI / 3.0};
17
18 for (Int phase = 0; phase < 3; ++phase) {
19 const Real cosine = std::cos(angles[phase]);
20 const Real sine = std::sin(angles[phase]);
21 parkTransform(0, phase) = k * cosine;
22 parkTransform(1, phase) = -k * sine;
23 inverseParkTransform(phase, 0) = k * cosine;
24 inverseParkTransform(phase, 1) = -k * sine;
25 }
26}
27} // namespace
28
31 : TwoTerminalVTypeVariableSSNComp(uid, name, logLevel), mLf(0.0), mCf(0.0),
32 mRf(0.0), mRc(0.0), mOmegaN(0.0), mKpPLL(0.0), mKiPLL(0.0),
33 mOmegaCutoff(0.0), mPRef(0.0), mQRef(0.0), mKpPowerCtrl(0.0),
34 mKiPowerCtrl(0.0), mKpCurrCtrl(0.0), mKiCurrCtrl(0.0),
35 mVcD(mAttributes->create<Real>("vc_d")),
36 mVcQ(mAttributes->create<Real>("vc_q")),
37 mIrcD(mAttributes->create<Real>("irc_d")),
38 mIrcQ(mAttributes->create<Real>("irc_q")),
39 mPInst(mAttributes->create<Real>("p_inst")),
40 mQInst(mAttributes->create<Real>("q_inst")),
41 mOmegaPLL(mAttributes->create<Real>("omega_pll")) {
42 **mIntfVoltage = Matrix::Zero(3, 1);
43 **mIntfCurrent = Matrix::Zero(3, 1);
44
45 **mVcD = 0.0;
46 **mVcQ = 0.0;
47 **mIrcD = 0.0;
48 **mIrcQ = 0.0;
49 **mPInst = 0.0;
50 **mQInst = 0.0;
51 **mOmegaPLL = 0.0;
52}
53
54std::vector<String>
56 return {
57 "theta_pll", "phi_pll", "p_filtered", "q_filtered", "phi_d",
58 "phi_q", "gamma_d", "gamma_q", "vc_a", "vc_b",
59 "vc_c", "if_a", "if_b", "if_c",
60 };
61}
62
63std::vector<EMT::SSNComp::LocalAbcStateBlock>
65 return {
66 {{static_cast<UInt>(VcA), static_cast<UInt>(VcB), static_cast<UInt>(VcC)},
67 "vc"},
68 {{static_cast<UInt>(IfA), static_cast<UInt>(IfB), static_cast<UInt>(IfC)},
69 "if"},
70 };
71}
72
74 Real lf, Real cf, Real rf, Real rc, Real omegaN, Real kpPLL, Real kiPLL,
75 Real omegaCutoff, Real pRef, Real qRef, Real kpPowerCtrl, Real kiPowerCtrl,
76 Real kpCurrCtrl, Real kiCurrCtrl) {
77 if (lf <= 0.0)
78 throw std::invalid_argument("Filter inductance lf must be positive.");
79
80 if (cf <= 0.0)
81 throw std::invalid_argument("Filter capacitance cf must be positive.");
82
83 if (rf < 0.0)
84 throw std::invalid_argument("Filter resistance rf must be non-negative.");
85
86 if (rc <= 0.0)
87 throw std::invalid_argument("Coupling resistance rc must be positive.");
88
89 if (omegaN <= 0.0)
90 throw std::invalid_argument(
91 "Nominal angular frequency omegaN must be positive.");
92
93 if (omegaCutoff < 0.0)
94 throw std::invalid_argument(
95 "Power-filter cutoff frequency omegaCutoff must be non-negative.");
96
97 if (kiPLL == 0.0)
98 throw std::invalid_argument("PLL integral gain kiPLL must be non-zero.");
99
100 if (kiPowerCtrl == 0.0)
101 throw std::invalid_argument(
102 "Power-control integral gain kiPowerCtrl must be non-zero.");
103
104 if (kiCurrCtrl == 0.0)
105 throw std::invalid_argument(
106 "Current-control integral gain kiCurrCtrl must be non-zero.");
107
108 mLf = lf;
109 mCf = cf;
110 mRf = rf;
111 mRc = rc;
112
113 mOmegaN = omegaN;
114 mKpPLL = kpPLL;
115 mKiPLL = kiPLL;
116
117 mOmegaCutoff = omegaCutoff;
118 mPRef = pRef;
119 mQRef = qRef;
120 mKpPowerCtrl = kpPowerCtrl;
121 mKiPowerCtrl = kiPowerCtrl;
122 mKpCurrCtrl = kpCurrCtrl;
123 mKiCurrCtrl = kiCurrCtrl;
124
125 const Matrix x0 = Matrix::Zero(mStateSize, 1);
126 const Matrix u0 = Matrix::Zero(3, 1);
127
128 Matrix aMatrix;
129 Matrix bMatrix;
130 Matrix cMatrix;
131 Matrix dMatrix;
132 Matrix eVector;
133 Matrix fVector;
134 buildStateSpaceModel(x0, u0, aMatrix, bMatrix, cMatrix, dMatrix, eVector,
135 fVector);
136
137 VTypeVariableSSNComp::setParameters(aMatrix, bMatrix, cMatrix, dMatrix,
138 eVector, fVector);
139}
140
141Matrix EMT::Ph3::AvVoltSourceInverterStateSpace::getParkTransformMatrix(
142 Real theta) const {
143 Matrix transform(2, 3);
144 const Real k = std::sqrt(2.0 / 3.0);
145
146 transform.row(0) << k * std::cos(theta), k * std::cos(theta - 2.0 * PI / 3.0),
147 k * std::cos(theta + 2.0 * PI / 3.0);
148
149 transform.row(1) << -k * std::sin(theta),
150 -k * std::sin(theta - 2.0 * PI / 3.0),
151 -k * std::sin(theta + 2.0 * PI / 3.0);
152
153 return transform;
154}
155
156Matrix EMT::Ph3::AvVoltSourceInverterStateSpace::getInverseParkTransformMatrix(
157 Real theta) const {
158 Matrix transform(3, 2);
159 const Real k = std::sqrt(2.0 / 3.0);
160
161 transform << k * std::cos(theta), -k * std::sin(theta),
162 k * std::cos(theta - 2.0 * PI / 3.0),
163 -k * std::sin(theta - 2.0 * PI / 3.0),
164 k * std::cos(theta + 2.0 * PI / 3.0),
165 -k * std::sin(theta + 2.0 * PI / 3.0);
166
167 return transform;
168}
169
171 const Matrix &u) const {
172 const Matrix &x = **mX;
173
174 const Matrix parkTransform = getParkTransformMatrix(x(ThetaPLL, 0));
175 const Matrix vcAbc = x.block(VcA, 0, 3, 1);
176 const Matrix iGridAbc = (vcAbc - u) / mRc;
177
178 **mVcD = (parkTransform.row(0) * vcAbc)(0, 0);
179 **mVcQ = (parkTransform.row(1) * vcAbc)(0, 0);
180 **mIrcD = (parkTransform.row(0) * iGridAbc)(0, 0);
181 **mIrcQ = (parkTransform.row(1) * iGridAbc)(0, 0);
182
183 **mPInst = **mVcD * **mIrcD + **mVcQ * **mIrcQ;
184 **mQInst = -**mVcD * **mIrcQ + **mVcQ * **mIrcD;
185
186 **mOmegaPLL = mOmegaN + mKpPLL * **mVcQ + mKiPLL * x(PhiPLL, 0);
187}
188
190 Real frequency) {
191 if (!mParametersSet)
192 throw std::logic_error("setParameters() must be called before "
193 "initializeFromNodesAndTerminals().");
194
195 // The generic SSN phasor initialization is not used because this component
196 // mixes EMT abc electrical states with dq-frame controller states. The filter
197 // states are initialized from balanced phasors; the controller states are
198 // initialized algebraically from the corresponding dq operating point.
199
200 const Real omega = 2.0 * PI * frequency;
201 const Complex j(0.0, 1.0);
202 const Complex powerRef(mPRef, mQRef);
203
204 const MatrixComp uPhasor = buildInitialInputFromNodes(frequency);
205
206 MatrixComp vcPhasor = uPhasor;
207 MatrixComp iInjPhasor = MatrixComp::Zero(3, 1);
208
209 for (Int iter = 0; iter < mInitializationMaxIterations; ++iter) {
210 const Complex vcA = vcPhasor(0, 0);
211
212 if (std::abs(vcA) < mInitializationTolerance) {
213 iInjPhasor.setZero();
214 break;
215 }
216
217 const Complex iA = std::conj(powerRef / (1.5 * vcA));
218
219 MatrixComp iNext(3, 1);
220 iNext << iA, iA * SHIFT_TO_PHASE_B, iA * SHIFT_TO_PHASE_C;
221
222 const MatrixComp vcNext = uPhasor + mRc * iNext;
223
224 iInjPhasor = iNext;
225
226 if ((vcNext - vcPhasor).norm() < mInitializationTolerance) {
227 vcPhasor = vcNext;
228 break;
229 }
230
231 vcPhasor = vcNext;
232 }
233
234 const MatrixComp ifPhasor = j * omega * mCf * vcPhasor + iInjPhasor;
235 const MatrixComp vRefPhasor = vcPhasor + (mRf + j * omega * mLf) * ifPhasor;
236
237 const Matrix vcAbc0 = vcPhasor.real();
238 const Matrix ifAbc0 = ifPhasor.real();
239 const Matrix iInjAbc0 = iInjPhasor.real();
240 const Matrix vRefAbc0 = vRefPhasor.real();
241
242 const Real theta0 = std::arg(vcPhasor(0, 0));
243 const Matrix parkTransform = getParkTransformMatrix(theta0);
244
245 const Matrix vcDq = parkTransform * vcAbc0;
246 const Matrix iDq = parkTransform * iInjAbc0;
247 const Matrix vRefDq = parkTransform * vRefAbc0;
248
249 const Real vcD = vcDq(0, 0);
250 const Real vcQ = vcDq(1, 0);
251 const Real ircD = iDq(0, 0);
252 const Real ircQ = iDq(1, 0);
253
254 const Real pInit = vcD * ircD + vcQ * ircQ;
255 const Real qInit = -vcD * ircQ + vcQ * ircD;
256
257 Matrix x0 = Matrix::Zero(mStateSize, 1);
258
259 x0(ThetaPLL, 0) = theta0;
260 x0(PhiPLL, 0) = (omega - mOmegaN) / mKiPLL;
261 x0(PFiltered, 0) = pInit;
262 x0(QFiltered, 0) = qInit;
263
264 x0(PhiD, 0) = (ircD + mKpPowerCtrl * (pInit - mPRef)) / mKiPowerCtrl;
265 x0(PhiQ, 0) = (ircQ - mKpPowerCtrl * (qInit - mQRef)) / mKiPowerCtrl;
266
267 const Real iRefD =
268 -mKpPowerCtrl * pInit + mKiPowerCtrl * x0(PhiD, 0) + mKpPowerCtrl * mPRef;
269 const Real iRefQ =
270 mKpPowerCtrl * qInit + mKiPowerCtrl * x0(PhiQ, 0) - mKpPowerCtrl * mQRef;
271
272 x0(GammaD, 0) = (vRefDq(0, 0) + mKpCurrCtrl * (ircD - iRefD)) / mKiCurrCtrl;
273 x0(GammaQ, 0) = (vRefDq(1, 0) + mKpCurrCtrl * (ircQ - iRefQ)) / mKiCurrCtrl;
274
275 x0.block(VcA, 0, 3, 1) = vcAbc0;
276 x0.block(IfA, 0, 3, 1) = ifAbc0;
277
278 **mX = x0;
279 **mIntfVoltage = uPhasor.real();
280 **mIntfCurrent = ((uPhasor - vcPhasor) / mRc).real();
281
284
285 SPDLOG_LOGGER_INFO(mSLog,
286 "\n--- Inverter SSN phasor/dq initialization ---"
287 "\nInput u: {:s}"
288 "\nOutput y: {:s}"
289 "\nState x: {:s}"
290 "\nP/Q init: [{:.6e}, {:.6e}]"
291 "\nVc dq: [{:.6e}, {:.6e}]"
292 "\nIinj dq: [{:.6e}, {:.6e}]"
293 "\n--- Initialization finished ---",
296 Logger::matrixToString(**mX), pInit, qInit, vcD, vcQ, ircD,
297 ircQ);
298}
299
300void EMT::Ph3::AvVoltSourceInverterStateSpace::buildStateSpaceModel(
301 const Matrix &x, const Matrix &u, Matrix &A, Matrix &B, Matrix &C,
302 Matrix &D, Matrix &E, Matrix &F) const {
303 // -------------------------------------------------------------------------
304 // 1) Operating point and Park transformation
305 // -------------------------------------------------------------------------
306 const Real theta0 = x(ThetaPLL, 0);
307 const Real pFiltered0 = x(PFiltered, 0);
308 const Real qFiltered0 = x(QFiltered, 0);
309 const Real phiD0 = x(PhiD, 0);
310 const Real phiQ0 = x(PhiQ, 0);
311 const Real gammaD0 = x(GammaD, 0);
312 const Real gammaQ0 = x(GammaQ, 0);
313 const Matrix vcAbc0 = x.block(VcA, 0, 3, 1);
314
315 const Matrix identity3 = Matrix::Identity(3, 3);
316
317 Matrix parkTransform(2, 3);
318 Matrix inverseParkTransform(3, 2);
319 buildParkTransformPair(theta0, parkTransform, inverseParkTransform);
320 const Matrix tD = parkTransform.row(0);
321 const Matrix tQ = parkTransform.row(1);
322 const Matrix sD = inverseParkTransform.col(0);
323 const Matrix sQ = inverseParkTransform.col(1);
324
325 const Matrix dTdTheta = tQ;
326 const Matrix dTqTheta = -tD;
327 const Matrix dSdTheta = sQ;
328 const Matrix dSqTheta = -sD;
329
330 // -------------------------------------------------------------------------
331 // 2) PLL measurement equation
332 //
333 // vq(theta, Vc) ≈ aThetaPLL * theta + aVPLL * Vc + bVq
334 //
335 // theta_dot = omegaN + KpPLL * vq + KiPLL * phiPLL
336 // phiPLL_dot = vq
337 // -------------------------------------------------------------------------
338 const Real vq0 = (tQ * vcAbc0)(0, 0);
339 const Real aThetaPLL = (dTqTheta * vcAbc0)(0, 0);
340 const Matrix aVPLL = tQ;
341 const Real bVq = vq0 - aThetaPLL * theta0 - (aVPLL * vcAbc0)(0, 0);
342
343 // -------------------------------------------------------------------------
344 // 3) Grid-current measurement in dq
345 //
346 // i_rc = (Vc - u) / Rc
347 // i_dq = T(theta) * i_rc
348 //
349 // The controller uses positive current as inverter injection into the grid.
350 // The SSN output uses the opposite sign:
351 //
352 // y = (u - Vc) / Rc
353 // -------------------------------------------------------------------------
354 const Matrix iInjAbc0 = (vcAbc0 - u) / mRc;
355
356 const Real vcD0 = (tD * vcAbc0)(0, 0);
357 const Real vcQ0 = (tQ * vcAbc0)(0, 0);
358 const Real ircD0 = (tD * iInjAbc0)(0, 0);
359 const Real ircQ0 = (tQ * iInjAbc0)(0, 0);
360
361 const Matrix dVcDByVc = tD;
362 const Matrix dVcQByVc = tQ;
363 const Matrix dIrcDByVc = tD / mRc;
364 const Matrix dIrcQByVc = tQ / mRc;
365 const Matrix dIrcDByU = -tD / mRc;
366 const Matrix dIrcQByU = -tQ / mRc;
367
368 const Real dVcDByTheta = (dTdTheta * vcAbc0)(0, 0);
369 const Real dVcQByTheta = (dTqTheta * vcAbc0)(0, 0);
370 const Real dIrcDByTheta = (dTdTheta * iInjAbc0)(0, 0);
371 const Real dIrcQByTheta = (dTqTheta * iInjAbc0)(0, 0);
372
373 const Real bIrcD = ircD0 - dIrcDByTheta * theta0 -
374 (dIrcDByVc * vcAbc0)(0, 0) - (dIrcDByU * u)(0, 0);
375
376 const Real bIrcQ = ircQ0 - dIrcQByTheta * theta0 -
377 (dIrcQByVc * vcAbc0)(0, 0) - (dIrcQByU * u)(0, 0);
378
379 // -------------------------------------------------------------------------
380 // 4) Power measurement and power-filter states
381 //
382 // p = vc_d * irc_d + vc_q * irc_q
383 // q = -vc_d * irc_q + vc_q * irc_d
384 //
385 // P_dot = omegaCutoff * (p - P)
386 // Q_dot = omegaCutoff * (q - Q)
387 // -------------------------------------------------------------------------
388 const Real p0 = vcD0 * ircD0 + vcQ0 * ircQ0;
389 const Real dPByTheta = ircD0 * dVcDByTheta + vcD0 * dIrcDByTheta +
390 ircQ0 * dVcQByTheta + vcQ0 * dIrcQByTheta;
391 const Matrix dPByVc =
392 ircD0 * dVcDByVc + vcD0 * dIrcDByVc + ircQ0 * dVcQByVc + vcQ0 * dIrcQByVc;
393 const Matrix dPByU = vcD0 * dIrcDByU + vcQ0 * dIrcQByU;
394 const Real bP =
395 p0 - dPByTheta * theta0 - (dPByVc * vcAbc0)(0, 0) - (dPByU * u)(0, 0);
396
397 const Real q0 = -vcD0 * ircQ0 + vcQ0 * ircD0;
398 const Real dQByTheta = -ircQ0 * dVcDByTheta - vcD0 * dIrcQByTheta +
399 ircD0 * dVcQByTheta + vcQ0 * dIrcDByTheta;
400 const Matrix dQByVc = -ircQ0 * dVcDByVc - vcD0 * dIrcQByVc +
401 ircD0 * dVcQByVc + vcQ0 * dIrcDByVc;
402 const Matrix dQByU = -vcD0 * dIrcQByU + vcQ0 * dIrcDByU;
403 const Real bQ =
404 q0 - dQByTheta * theta0 - (dQByVc * vcAbc0)(0, 0) - (dQByU * u)(0, 0);
405
406 // -------------------------------------------------------------------------
407 // 5) Outer power control
408 //
409 // phi_d_dot = Pref - P
410 // phi_q_dot = Q - Qref
411 //
412 // iRef_d = KpP * (Pref - P) + KiP * phi_d
413 // iRef_q = KpP * (Q - Qref) + KiP * phi_q
414 // -------------------------------------------------------------------------
415 const Real iRefD0 =
416 -mKpPowerCtrl * pFiltered0 + mKiPowerCtrl * phiD0 + mKpPowerCtrl * mPRef;
417 const Real iRefQ0 =
418 mKpPowerCtrl * qFiltered0 + mKiPowerCtrl * phiQ0 - mKpPowerCtrl * mQRef;
419
420 // -------------------------------------------------------------------------
421 // 6) Inner current control and bridge-voltage reference
422 //
423 // gamma_d_dot = iRef_d - irc_d
424 // gamma_q_dot = iRef_q - irc_q
425 //
426 // vRef_d = KpI * (iRef_d - irc_d) + KiI * gamma_d
427 // vRef_q = KpI * (iRef_q - irc_q) + KiI * gamma_q
428 //
429 // vRef_abc = T_inv(theta) * [vRef_d, vRef_q]
430 // -------------------------------------------------------------------------
431 const Real vRefD0 =
432 -mKpCurrCtrl * ircD0 + mKiCurrCtrl * gammaD0 + mKpCurrCtrl * iRefD0;
433 const Real vRefQ0 =
434 -mKpCurrCtrl * ircQ0 + mKiCurrCtrl * gammaQ0 + mKpCurrCtrl * iRefQ0;
435
436 const Matrix vRefAbc0 = sD * vRefD0 + sQ * vRefQ0;
437
438 const Real dVRefDByTheta = -mKpCurrCtrl * dIrcDByTheta;
439 const Matrix dVRefDByVc = -mKpCurrCtrl * dIrcDByVc;
440 const Matrix dVRefDByU = -mKpCurrCtrl * dIrcDByU;
441
442 const Real dVRefQByTheta = -mKpCurrCtrl * dIrcQByTheta;
443 const Matrix dVRefQByVc = -mKpCurrCtrl * dIrcQByVc;
444 const Matrix dVRefQByU = -mKpCurrCtrl * dIrcQByU;
445
446 Matrix dVRefAbcByX = Matrix::Zero(3, mStateSize);
447 Matrix dVRefAbcByU = Matrix::Zero(3, 3);
448
449 dVRefAbcByX.col(ThetaPLL) = dSdTheta * vRefD0 + dSqTheta * vRefQ0 +
450 sD * dVRefDByTheta + sQ * dVRefQByTheta;
451
452 dVRefAbcByX.col(PFiltered) += sD * (-mKpCurrCtrl * mKpPowerCtrl);
453 dVRefAbcByX.col(PhiD) += sD * (mKpCurrCtrl * mKiPowerCtrl);
454 dVRefAbcByX.col(GammaD) += sD * mKiCurrCtrl;
455
456 dVRefAbcByX.col(QFiltered) += sQ * (mKpCurrCtrl * mKpPowerCtrl);
457 dVRefAbcByX.col(PhiQ) += sQ * (mKpCurrCtrl * mKiPowerCtrl);
458 dVRefAbcByX.col(GammaQ) += sQ * mKiCurrCtrl;
459
460 dVRefAbcByX.block(0, VcA, 3, 3) += sD * dVRefDByVc + sQ * dVRefQByVc;
461
462 dVRefAbcByU = sD * dVRefDByU + sQ * dVRefQByU;
463
464 const Matrix vRefAbcOffset = vRefAbc0 - dVRefAbcByX * x - dVRefAbcByU * u;
465
466 // -------------------------------------------------------------------------
467 // 7) Initialize affine state-space matrices
468 //
469 // x_dot ≈ A * x + B * u + E
470 // y ≈ C * x + D * u + F
471 // -------------------------------------------------------------------------
472 A.setZero(mStateSize, mStateSize);
473 B.setZero(mStateSize, 3);
474 C.setZero(3, mStateSize);
475 D.setZero(3, 3);
476 E.setZero(mStateSize, 1);
477 F.setZero(3, 1);
478
479 // -------------------------------------------------------------------------
480 // 8) Stamp PLL rows
481 // -------------------------------------------------------------------------
482 A(ThetaPLL, ThetaPLL) = mKpPLL * aThetaPLL;
483 A(ThetaPLL, PhiPLL) = mKiPLL;
484 A.block(ThetaPLL, VcA, 1, 3) = mKpPLL * aVPLL;
485
486 A(PhiPLL, ThetaPLL) = aThetaPLL;
487 A.block(PhiPLL, VcA, 1, 3) = aVPLL;
488
489 E(ThetaPLL, 0) = mOmegaN + mKpPLL * bVq;
490 E(PhiPLL, 0) = bVq;
491
492 // -------------------------------------------------------------------------
493 // 9) Stamp power-filter rows
494 // -------------------------------------------------------------------------
495 A(PFiltered, ThetaPLL) = mOmegaCutoff * dPByTheta;
496 A(PFiltered, PFiltered) = -mOmegaCutoff;
497 A.block(PFiltered, VcA, 1, 3) = mOmegaCutoff * dPByVc;
498 B.block(PFiltered, 0, 1, 3) = mOmegaCutoff * dPByU;
499 E(PFiltered, 0) = mOmegaCutoff * bP;
500
501 A(QFiltered, ThetaPLL) = mOmegaCutoff * dQByTheta;
502 A(QFiltered, QFiltered) = -mOmegaCutoff;
503 A.block(QFiltered, VcA, 1, 3) = mOmegaCutoff * dQByVc;
504 B.block(QFiltered, 0, 1, 3) = mOmegaCutoff * dQByU;
505 E(QFiltered, 0) = mOmegaCutoff * bQ;
506
507 // -------------------------------------------------------------------------
508 // 10) Stamp outer-loop integrator rows
509 // -------------------------------------------------------------------------
510 A(PhiD, PFiltered) = -1.0;
511 E(PhiD, 0) = mPRef;
512
513 A(PhiQ, QFiltered) = 1.0;
514 E(PhiQ, 0) = -mQRef;
515
516 // -------------------------------------------------------------------------
517 // 11) Stamp current-loop integrator rows
518 // -------------------------------------------------------------------------
519 A(GammaD, PFiltered) = -mKpPowerCtrl;
520 A(GammaD, PhiD) = mKiPowerCtrl;
521 A(GammaD, ThetaPLL) = -dIrcDByTheta;
522 A.block(GammaD, VcA, 1, 3) = -dIrcDByVc;
523 B.block(GammaD, 0, 1, 3) = -dIrcDByU;
524 E(GammaD, 0) = mKpPowerCtrl * mPRef - bIrcD;
525
526 A(GammaQ, QFiltered) = mKpPowerCtrl;
527 A(GammaQ, PhiQ) = mKiPowerCtrl;
528 A(GammaQ, ThetaPLL) = -dIrcQByTheta;
529 A.block(GammaQ, VcA, 1, 3) = -dIrcQByVc;
530 B.block(GammaQ, 0, 1, 3) = -dIrcQByU;
531 E(GammaQ, 0) = -mKpPowerCtrl * mQRef - bIrcQ;
532
533 // -------------------------------------------------------------------------
534 // 12) Stamp electrical filter plant
535 //
536 // Vc_dot = If / Cf + (u - Vc) / (Cf * Rc)
537 // If_dot = (vRef_abc - Vc - Rf * If) / Lf
538 // -------------------------------------------------------------------------
539 A.block(VcA, VcA, 3, 3) = -1.0 / (mCf * mRc) * identity3;
540 A.block(VcA, IfA, 3, 3) = 1.0 / mCf * identity3;
541 B.block(VcA, 0, 3, 3) = 1.0 / (mCf * mRc) * identity3;
542
543 A.block(IfA, 0, 3, mStateSize) = (1.0 / mLf) * dVRefAbcByX;
544 A.block(IfA, VcA, 3, 3) += -1.0 / mLf * identity3;
545 A.block(IfA, IfA, 3, 3) += -mRf / mLf * identity3;
546 B.block(IfA, 0, 3, 3) = (1.0 / mLf) * dVRefAbcByU;
547 E.block(IfA, 0, 3, 1) = (1.0 / mLf) * vRefAbcOffset;
548
549 // -------------------------------------------------------------------------
550 // 13) Stamp SSN output
551 //
552 // y = (u - Vc) / Rc
553 // -------------------------------------------------------------------------
554 C.block(0, VcA, 3, 3) = -1.0 / mRc * identity3;
555 D = 1.0 / mRc * identity3;
556}
557
559 // The local linearized SSN model is time-varying because the network abc
560 // states are coupled with dq-frame control through the Park transformation.
561 // Therefore the stamp is recomputed every step and the change check is
562 // intentionally skipped.
563 buildStateSpaceModel(**mX, **mIntfVoltage, mA, mB, mC, mD,
564 mParameterStateOffset, mParameterOutputOffset);
565
566 setStateOffset(mParameterStateOffset);
567 setOutputOffset(mParameterOutputOffset);
568
569 return true;
570}
void setParameters(Real lf, Real cf, Real rf, Real rc, Real omegaN, Real kpPLL, Real kiPLL, Real omegaCutoff, Real pRef, Real qRef, Real kpPowerCtrl, Real kiPowerCtrl, Real kpCurrCtrl, Real kiCurrCtrl)
std::vector< SSNComp::LocalAbcStateBlock > getLocalAbcStateBlocks() const override final
std::vector< String > getLocalStateNames() const override final
AvVoltSourceInverterStateSpace(String uid, String name, Logger::Level logLevel=Logger::Level::off)
void initializeFromNodesAndTerminals(Real frequency) override final
Initializes Component variables according to power flow data stored in Nodes.
void updateLogAttributes(const Matrix &u) const override final
Update derived attributes used for logging/inspection.
TwoTerminalVTypeVariableSSNComp(String uid, String name, Logger::Level logLevel=Logger::Level::off)
const Attribute< Matrix >::Ptr mX
Definition EMT_SSNComp.h:48
void setParameters(const Matrix &A, const Matrix &B, const Matrix &C, const Matrix &D)
static constexpr Real mInitializationTolerance
static constexpr Int mInitializationMaxIterations
String uid()
Returns unique id.
AttributeList::Ptr mAttributes
Attribute List.
spdlog::level::level_enum Level
Definition Logger.h:33
static String matrixToString(const Matrix &mat)
Definition Logger.cpp:31
const Attribute< MatrixVar< Real > >::Ptr mIntfCurrent
const Attribute< MatrixVar< Real > >::Ptr mIntfVoltage
bool mParametersSet
Flag indicating that parameters are set via setParameters() function.
Logger::Log mSLog
Component logger.
#define PI
Definition Definitions.h:43
#define SHIFT_TO_PHASE_C
Definition Definitions.h:47
#define SHIFT_TO_PHASE_B
Definition Definitions.h:46
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
std::complex< Real > Complex
Definition Definitions.h:61
Eigen::Matrix< Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixComp
Dense matrix for complex numbers.
Definition Definitions.h:82
bool Bool
Definition Definitions.h:62
unsigned int UInt
Definition Definitions.h:58