DPsim
Loading...
Searching...
No Matches
Base_ReducedOrderSynchronGenerator.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
11
12using namespace CPS;
13
14template <>
16 String uid, String name, Logger::Level logLevel)
17 : MNASimPowerComp<Real>(uid, name, true, true, logLevel),
18 mVdq0(mAttributes->create<Matrix>("Vdq0")),
19 mIdq0(mAttributes->create<Matrix>("Idq0")),
20 mElecTorque(mAttributes->create<Real>("Te")),
21 mMechTorque(mAttributes->create<Real>("Tm")),
22 mOmMech(mAttributes->create<Real>("w_r")),
23 mThetaMech(mAttributes->create<Real>("Theta")),
24 mDelta(mAttributes->create<Real>("delta")),
25 mEf(mAttributes->create<Real>("Ef")) {
26
27 mSimTime = 0.0;
28
29 // declare state variables
30 **mVdq0 = Matrix::Zero(3, 1);
31 **mIdq0 = Matrix::Zero(3, 1);
32
33 // default model is Norton equivalent
34 mModelAsNortonSource = true;
35 SPDLOG_LOGGER_DEBUG(this->mSLog,
36 "SG per default modelled as Norton equivalent");
37}
38
39template <>
41 String uid, String name, Logger::Level logLevel)
42 : MNASimPowerComp<Complex>(uid, name, true, true, logLevel),
43 mVdq(mAttributes->create<Matrix>("Vdq0")),
44 mIdq(mAttributes->create<Matrix>("Idq0")),
45 mElecTorque(mAttributes->create<Real>("Te")),
46 mMechTorque(mAttributes->create<Real>("Tm")),
47 mOmMech(mAttributes->create<Real>("w_r")),
48 mThetaMech(mAttributes->create<Real>("Theta")),
49 mDelta(mAttributes->create<Real>("delta")),
50 mEf(mAttributes->create<Real>("Ef")) {
51
52 mSimTime = 0.0;
53
54 // declare state variables
56 **mVdq = Matrix::Zero(2, 1);
57 **mIdq = Matrix::Zero(2, 1);
58
59 // default model is Norton equivalent
60 mModelAsNortonSource = true;
61 SPDLOG_LOGGER_DEBUG(this->mSLog,
62 "SG per default modelled as Norton equivalent");
63}
64
65template <typename VarType>
67 Bool modelAsCurrentSource) {
68 mModelAsNortonSource = modelAsCurrentSource;
69
71 this->setVirtualNodeNumber(0);
72 SPDLOG_LOGGER_DEBUG(this->mSLog, "Setting SG model to Norton equivalent");
73 } else {
74 this->setVirtualNodeNumber(2);
75 SPDLOG_LOGGER_DEBUG(this->mSLog, "Setting SG model to Thevenin equivalent");
76 }
77}
78
79template <typename VarType>
81 Real nomPower, Real nomVolt, Real nomFreq) {
82
83 /// used p.u. system: Lad-Base reciprocal per unit system (Kundur, p. 84-88)
84
85 // set base nominal values
86 mNomPower = nomPower;
87 mNomVolt = nomVolt;
88 mNomFreq = nomFreq;
89 mNomOmega = nomFreq * 2 * PI;
90
91 // Set base stator values
93 mBase_V = mNomVolt / sqrt(3) * sqrt(2);
95 mBase_I = mNomPower / ((3. / 2.) * mBase_V);
101
102template <typename VarType>
104 VarType>::setOperationalParametersPerUnit(Real nomPower, Real nomVolt,
105 Real nomFreq, Real H, Real Ld,
106 Real Lq, Real L0, Real Ld_t,
107 Real Td0_t) {
108
109 setBaseParameters(nomPower, nomVolt, nomFreq);
110
111 mLd = Ld;
112 mLq = Lq;
113 mL0 = L0;
114 mLd_t = Ld_t;
115 mTd0_t = Td0_t;
116 mH = H;
118 SPDLOG_LOGGER_INFO(this->mSLog,
119 "Set base parameters: \n"
120 "nomPower: {:e}\nnomVolt: {:e}\nnomFreq: {:e}\n",
122
123 SPDLOG_LOGGER_INFO(this->mSLog,
124 "Set operational parameters in per unit: \n"
125 "inertia: {:e}\n"
126 "Ld: {:e}\nLq: {:e}\nL0: {:e}\n"
127 "Ld_t: {:e}\nTd0_t: {:e}\n",
128 mH, mLd, mLq, mL0, mLd_t, mTd0_t);
130
131template <typename VarType>
133 VarType>::setOperationalParametersPerUnit(Real nomPower, Real nomVolt,
134 Real nomFreq, Real H, Real Ld,
135 Real Lq, Real L0, Real Ld_t,
136 Real Lq_t, Real Td0_t,
137 Real Tq0_t) {
138
139 setBaseParameters(nomPower, nomVolt, nomFreq);
140
141 mLd = Ld;
142 mLq = Lq;
143 mL0 = L0;
144 mLd_t = Ld_t;
145 mLq_t = Lq_t;
146 mTd0_t = Td0_t;
147 mTq0_t = Tq0_t;
148 mH = H;
149
150 SPDLOG_LOGGER_INFO(this->mSLog,
151 "Set base parameters: \n"
152 "nomPower: {:e}\nnomVolt: {:e}\nnomFreq: {:e}\n",
154
155 SPDLOG_LOGGER_INFO(this->mSLog,
156 "Set operational parameters in per unit: \n"
157 "inertia: {:e}\n"
158 "Ld: {:e}\nLq: {:e}\nL0: {:e}\n"
159 "Ld_t: {:e}\nLq_t: {:e}\n"
160 "Td0_t: {:e}\nTq0_t: {:e}\n",
162}
164template <typename VarType>
166 VarType>::setOperationalParametersPerUnit(Real nomPower, Real nomVolt,
167 Real nomFreq, Real H, Real Ld,
168 Real Lq, Real L0, Real Ld_t,
169 Real Lq_t, Real Td0_t, Real Tq0_t,
170 Real Ld_s, Real Lq_s, Real Td0_s,
171 Real Tq0_s, Real Taa) {
172
173 setBaseParameters(nomPower, nomVolt, nomFreq);
174
175 mLd = Ld;
176 mLq = Lq;
177 mL0 = L0;
178 mLd_t = Ld_t;
179 mLq_t = Lq_t;
180 mLd_s = Ld_s;
181 mLq_s = Lq_s;
182 mTd0_t = Td0_t;
183 mTq0_t = Tq0_t;
184 mTd0_s = Td0_s;
185 mTq0_s = Tq0_s;
186 mTaa = Taa;
187 mH = H;
188
189 SPDLOG_LOGGER_INFO(this->mSLog,
190 "Set base parameters: \n"
191 "nomPower: {:e}\nnomVolt: {:e}\nnomFreq: {:e}\n",
193
194 SPDLOG_LOGGER_INFO(this->mSLog,
195 "Set operational parameters in per unit: \n"
196 "inertia: {:e}\n"
197 "Ld: {:e}\nLq: {:e}\nL0: {:e}\n"
198 "Ld_t: {:e}\nLq_t: {:e}\n"
199 "Td0_t: {:e}\nTq0_t: {:e}\n"
200 "Ld_s: {:e}\nLq_s: {:e}\n"
201 "Td0_s: {:e}\nTq0_s: {:e}\n"
202 "Taa: {:e}\n",
205}
206
207template <typename VarType>
209 Real scalingFactor) {
210 mH = mH * scalingFactor;
211 SPDLOG_LOGGER_INFO(
212 this->mSLog,
213 "Scaling inertia with factor {:e}:\n resulting inertia: {:e}\n",
214 scalingFactor, mH);
215}
216
217template <typename VarType>
219
220 Real Tf = 0;
222 mYd = (mTd0_s / mTd0_t) * (mLd_s / mLd_t) * (mLd - mLd_t);
223 mYq = 0.0;
224 Tf = mTaa / mTd0_t;
225 } else if (mSGOrder == SGOrder::SG6aOrder) {
226 mYd = (mTd0_s / mTd0_t) * (mLd_s / mLd_t) * (mLd - mLd_t);
227 mYq = (mTq0_s / mTq0_t) * (mLq_s / mLq_t) * (mLq - mLq_t);
228 Tf = mTaa / mTd0_t;
229 } else {
230 mYd = 0;
231 mYq = 0;
232 }
233
234 Real Zq_t = mLd - mLd_t - mYd;
235 Real Zd_t = mLq - mLq_t - mYq;
236 Real Zq_s = mLd_t - mLd_s + mYd;
237 Real Zd_s = mLq_t - mLq_s + mYq;
238
239 mAd_t = mTimeStep * Zd_t / (2 * mTq0_t + mTimeStep);
240 mBd_t = (2 * mTq0_t - mTimeStep) / (2 * mTq0_t + mTimeStep);
241 mAq_t = -mTimeStep * Zq_t / (2 * mTd0_t + mTimeStep);
242 mBq_t = (2 * mTd0_t - mTimeStep) / (2 * mTd0_t + mTimeStep);
243 mDq_t = mTimeStep * (1 - Tf) / (2 * mTd0_t + mTimeStep);
244
246 mAd_s = (mTimeStep * (mLq - mLq_s)) / (2 * mTq0_s + mTimeStep);
247 mCd_s = (2 * mTq0_s - mTimeStep) / (2 * mTq0_s + mTimeStep);
248 mAq_s = (-mTimeStep * Zq_s + mTimeStep * mAq_t) / (2 * mTd0_s + mTimeStep);
249 mBq_s = (mTimeStep * mBq_t + mTimeStep) / (2 * mTd0_s + mTimeStep);
250 mCq_s = (2 * mTd0_s - mTimeStep) / (2 * mTd0_s + mTimeStep);
251 mDq_s = (mTimeStep * mDq_t + Tf * mTimeStep) / (2 * mTd0_s + mTimeStep);
253 mAd_s = (mTimeStep * Zd_s + mTimeStep * mAd_t) / (2 * mTq0_s + mTimeStep);
254 mBd_s = (mTimeStep * mBd_t + mTimeStep) / (2 * mTq0_s + mTimeStep);
255 mCd_s = (2 * mTq0_s - mTimeStep) / (2 * mTq0_s + mTimeStep);
256 mAq_s = (-mTimeStep * Zq_s + mTimeStep * mAq_t) / (2 * mTd0_s + mTimeStep);
257 mBq_s = (mTimeStep * mBq_t + mTimeStep) / (2 * mTd0_s + mTimeStep);
258 mCq_s = (2 * mTd0_s - mTimeStep) / (2 * mTd0_s + mTimeStep);
259 mDq_s = (mTimeStep * mDq_t + Tf * mTimeStep) / (2 * mTd0_s + mTimeStep);
260 }
261}
262
263template <typename VarType>
267 mA = -mLq;
268 mB = mLd_t - mAq_t;
269 }
271 mA = -mAd_t - mLq_t;
272 mB = mLd_t - mAq_t;
273 }
276 mA = -mLq_s - mAd_s;
277 mB = mLd_s - mAq_s;
278 }
279}
280
281template <typename VarType>
283 Complex initComplexElectricalPower, Real initMechanicalPower,
284 Complex initTerminalVoltage) {
285
286 mInitElecPower = initComplexElectricalPower;
287 mInitMechPower = initMechanicalPower;
288
289 mInitVoltage = initTerminalVoltage;
291
294
297
298 mInitialValuesSet = true;
299
300 SPDLOG_LOGGER_DEBUG(this->mSLog,
301 "\n--- Set initial values ---"
302 "\nInitial active power: {:}W = {:} p.u."
303 "\nInitial reactive power W: {:}W = {:} p.u."
304 "\nInitial terminal voltage magnitude: {:} p.u."
305 "\nInitial terminal voltage phase: {:} rad = ({:}°)"
306 "\nInitial current magnitude: {:} p.u."
307 "\nInitial current phase: {:} rad = ({:}°)"
308 "\n--- Set initial values finished ---\n",
309
310 mInitElecPower.real(), mInitElecPower.real() / mNomPower,
311 mInitElecPower.imag(), mInitElecPower.imag() / mNomPower,
315 this->mSLog->flush();
316}
317
318template <>
320 Real frequency) {
321
322 this->updateMatrixNodeIndices();
323
324 if (!mInitialValuesSet)
325 this->setInitialValues(-this->terminal(0)->singlePower(),
326 -this->terminal(0)->singlePower().real(),
327 this->initialSingleVoltage(0));
328
329 // Initialize mechanical torque
330 **mMechTorque = mInitMechPower / mNomPower;
331 mMechTorque_prev = **mMechTorque;
332
333 // calculate steady state machine emf (i.e. voltage behind synchronous reactance)
334 Complex Eq0 = mInitVoltage + Complex(0, mLq) * mInitCurrent;
335
336 // Load angle
337 **mDelta = Math::phase(Eq0);
338
339 // convert currrents to dq reference frame
340 (**mIdq0)(0, 0) = Math::abs(mInitCurrent) * sin(**mDelta - mInitCurrentAngle);
341 (**mIdq0)(1, 0) = Math::abs(mInitCurrent) * cos(**mDelta - mInitCurrentAngle);
342
343 // convert voltages to dq reference frame
344 (**mVdq0)(0, 0) = Math::abs(mInitVoltage) * sin(**mDelta - mInitVoltageAngle);
345 (**mVdq0)(1, 0) = Math::abs(mInitVoltage) * cos(**mDelta - mInitVoltageAngle);
346
347 // calculate Ef
348 **mEf = Math::abs(Eq0) + (mLd - mLq) * (**mIdq0)(0, 0);
349 mEf_prev = **mEf;
350
351 // Initialize controllers
352 if (mHasExciter) {
353 mExciter->initializeStates(Math::abs(mInitVoltage), **mEf);
354 }
355 if (mHasTurbineGovernor) {
356 mTurbineGovernor->initializeStates(**mMechTorque);
357 }
358 if (mHasGovernorAndTurbine) {
359 mGovernor->initializeStates(**mMechTorque);
360 mTurbine->initializeStates(**mMechTorque);
361 }
362 if (mHasPSS) {
363 mPSS->initializeStates(mNomOmega / mBase_OmMech, **mMechTorque,
364 (**mVdq0)(0, 0), (**mVdq0)(1, 0));
365 }
366
367 // initial electrical torque
368 **mElecTorque =
369 (**mVdq0)(0, 0) * (**mIdq0)(0, 0) + (**mVdq0)(1, 0) * (**mIdq0)(1, 0);
370
371 // Initialize omega mech with nominal system frequency
372 **mOmMech = mNomOmega / mBase_OmMech;
373
374 // initialize theta and calculate transform matrix
375 **mThetaMech = **mDelta - PI / 2.;
376
377 // set initial interface current
378 (**mIntfCurrent)(0, 0) = (mInitCurrent * mBase_I).real();
379 (**mIntfCurrent)(1, 0) = (mInitCurrent * mBase_I * SHIFT_TO_PHASE_B).real();
380 (**mIntfCurrent)(2, 0) = (mInitCurrent * mBase_I * SHIFT_TO_PHASE_C).real();
381
382 // set initial interface voltage
383 (**mIntfVoltage)(0, 0) = (mInitVoltage * mBase_V).real();
384 (**mIntfVoltage)(1, 0) = (mInitVoltage * mBase_V * SHIFT_TO_PHASE_B).real();
385 (**mIntfVoltage)(2, 0) = (mInitVoltage * mBase_V * SHIFT_TO_PHASE_C).real();
386
387 SPDLOG_LOGGER_DEBUG(this->mSLog,
388 "\n--- Initialization from power flow ---"
389 "\nInitial Vd (per unit): {:f}"
390 "\nInitial Vq (per unit): {:f}"
391 "\nInitial Id (per unit): {:f}"
392 "\nInitial Iq (per unit): {:f}"
393 "\nInitial Ef (per unit): {:f}"
394 "\nInitial mechanical torque (per unit): {:f}"
395 "\nInitial electrical torque (per unit): {:f}"
396 "\nInitial initial mechanical theta (per unit): {:f}"
397 "\nInitial delta (per unit): {:f} (= {:f}°)"
398 "\n--- Initialization from power flow finished ---",
399
400 (**mVdq0)(0, 0), (**mVdq0)(1, 0), (**mIdq0)(0, 0),
401 (**mIdq0)(1, 0), **mEf, **mMechTorque, **mElecTorque,
402 **mThetaMech, **mDelta, **mDelta * 180 / PI);
403 this->mSLog->flush();
404}
405
406template <>
408 Complex>::initializeFromNodesAndTerminals(Real frequency) {
409
410 this->updateMatrixNodeIndices();
411
412 if (!mInitialValuesSet)
413 this->setInitialValues(-this->terminal(0)->singlePower(),
414 -this->terminal(0)->singlePower().real(),
415 this->initialSingleVoltage(0));
416
417 // Initialize mechanical torque
418 **mMechTorque = mInitMechPower / mNomPower;
419 mMechTorque_prev = **mMechTorque;
420
421 // calculate steady state machine emf (i.e. voltage behind synchronous reactance)
422 Complex Eq0 = mInitVoltage + Complex(0, mLq) * mInitCurrent;
423
424 // Load angle
425 **mDelta = Math::phase(Eq0);
426
427 // convert currrents to dq reference frame
428 (**mIdq)(0, 0) = Math::abs(mInitCurrent) * sin(**mDelta - mInitCurrentAngle);
429 (**mIdq)(1, 0) = Math::abs(mInitCurrent) * cos(**mDelta - mInitCurrentAngle);
430
431 // convert voltages to dq reference frame
432 (**mVdq)(0, 0) = Math::abs(mInitVoltage) * sin(**mDelta - mInitVoltageAngle);
433 (**mVdq)(1, 0) = Math::abs(mInitVoltage) * cos(**mDelta - mInitVoltageAngle);
434
435 // calculate Ef
436 **mEf = Math::abs(Eq0) + (mLd - mLq) * (**mIdq)(0, 0);
437 mEf_prev = **mEf;
438
439 // Initialize controllers
440 if (mHasExciter) {
441 mExciter->initializeStates(Math::abs(mInitVoltage), **mEf);
442 }
443 if (mHasTurbineGovernor) {
444 mTurbineGovernor->initializeStates(**mMechTorque);
445 }
446 if (mHasGovernorAndTurbine) {
447 mGovernor->initializeStates(**mMechTorque);
448 mTurbine->initializeStates(**mMechTorque);
449 }
450 if (mHasPSS) {
451 mPSS->initializeStates(mNomOmega / mBase_OmMech, **mMechTorque,
452 (**mVdq)(0, 0), (**mVdq)(1, 0));
453 }
454
455 // initial electrical torque
456 **mElecTorque =
457 (**mVdq)(0, 0) * (**mIdq)(0, 0) + (**mVdq)(1, 0) * (**mIdq)(1, 0);
458
459 // Initialize omega mech with nominal system frequency
460 **mOmMech = mNomOmega / mBase_OmMech;
461
462 // initialize theta and calculate transform matrix
463 **mThetaMech = **mDelta - PI / 2.;
464
465 // set initial value of current
466 (**mIntfCurrent)(0, 0) = mInitCurrent * mBase_I_RMS;
467
468 // set initial interface voltage
469 (**mIntfVoltage)(0, 0) = mInitVoltage * mBase_V_RMS;
470
471 SPDLOG_LOGGER_DEBUG(this->mSLog,
472 "\n--- Initialization from power flow ---"
473 "\nInitial Vd (per unit): {:f}"
474 "\nInitial Vq (per unit): {:f}"
475 "\nInitial Id (per unit): {:f}"
476 "\nInitial Iq (per unit): {:f}"
477 "\nInitial Ef (per unit): {:f}"
478 "\nInitial mechanical torque (per unit): {:f}"
479 "\nInitial electrical torque (per unit): {:f}"
480 "\nInitial initial mechanical theta (per unit): {:f}"
481 "\nInitial delta (per unit): {:f} (= {:f}°)"
482 "\n--- Initialization from power flow finished ---",
483
484 (**mVdq)(0, 0), (**mVdq)(1, 0), (**mIdq)(0, 0),
485 (**mIdq)(1, 0), **mEf, **mMechTorque, **mElecTorque,
486 **mThetaMech, **mDelta, **mDelta * 180 / PI);
487 this->mSLog->flush();
488}
489
490template <typename VarType>
501
502template <>
504 Real time, Int timeStepCount) {
505 if (mDeviceManaged)
506 return;
507 mSimTime = time;
508
509 // update controller variables
510 if (mHasExciter) {
511 Real Vpss = mHasPSS ? mPSS->step(**mOmMech, **mElecTorque, (**mVdq)(0, 0),
512 (**mVdq)(1, 0), mTimeStep)
513 : 0.0;
514 mEf_prev = **mEf;
515 **mEf = mExciter->step((**mVdq)(0, 0), (**mVdq)(1, 0), mTimeStep, Vpss);
516 }
517 if (mHasGovernorAndTurbine) {
518 mMechTorque_prev = **mMechTorque;
519 Real Pgv = mGovernor->step(**mOmMech, mTimeStep);
520 **mMechTorque = mTurbine->step(Pgv, mTimeStep);
521 } else if (mHasTurbineGovernor) {
522 mMechTorque_prev = **mMechTorque;
523 **mMechTorque = mTurbineGovernor->step(**mOmMech, mTimeStep);
524 }
525
526 // calculate mechanical variables at t=k+1 with forward euler
527 **mElecTorque =
528 (**mVdq)(0, 0) * (**mIdq)(0, 0) + (**mVdq)(1, 0) * (**mIdq)(1, 0);
529 **mOmMech = **mOmMech + mTimeStep * (1. / (2. * mH) *
530 (mMechTorque_prev - **mElecTorque -
531 mDamping * (**mOmMech - 1.)));
532 **mThetaMech = **mThetaMech + mTimeStep * (**mOmMech * mBase_OmMech);
533 **mDelta = **mDelta + mTimeStep * (**mOmMech - 1.) * mBase_OmMech;
534
535 // model specific calculation of electrical vars
536 stepInPerUnit();
537
538 // stamp model specific right side vector after calculation of electrical vars
539 (**mRightVector).setZero();
540 mnaCompApplyRightSideVectorStamp(**mRightVector);
541}
542
543template <>
545 Real time, Int timeStepCount) {
546 if (mDeviceManaged)
547 return;
548 mSimTime = time;
549
550 // update controller variables
551 if (mHasExciter) {
552 Real Vpss = mHasPSS ? mPSS->step(**mOmMech, **mElecTorque, (**mVdq0)(0, 0),
553 (**mVdq0)(1, 0), mTimeStep)
554 : 0.0;
555 mEf_prev = **mEf;
556 **mEf = mExciter->step((**mVdq0)(0, 0), (**mVdq0)(1, 0), mTimeStep, Vpss);
557 }
558 if (mHasGovernorAndTurbine) {
559 mMechTorque_prev = **mMechTorque;
560 Real Pgv = mGovernor->step(**mOmMech, mTimeStep);
561 **mMechTorque = mTurbine->step(Pgv, mTimeStep);
562 } else if (mHasTurbineGovernor) {
563 mMechTorque_prev = **mMechTorque;
564 **mMechTorque = mTurbineGovernor->step(**mOmMech, mTimeStep);
565 }
566
567 // calculate mechanical variables at t=k+1 with forward euler
568 **mElecTorque =
569 ((**mVdq0)(0, 0) * (**mIdq0)(0, 0) + (**mVdq0)(1, 0) * (**mIdq0)(1, 0));
570 **mOmMech = **mOmMech + mTimeStep * (1. / (2. * mH) *
571 (mMechTorque_prev - **mElecTorque -
572 mDamping * (**mOmMech - 1.)));
573 **mThetaMech = **mThetaMech + mTimeStep * (**mOmMech * mBase_OmMech);
574 **mDelta = **mDelta + mTimeStep * (**mOmMech - 1.) * mBase_OmMech;
575
576 // model specific calculation of electrical vars
577 stepInPerUnit();
578
579 // stamp model specific right side vector after calculation of electrical vars
580 (**mRightVector).setZero();
581 mnaCompApplyRightSideVectorStamp(**mRightVector);
582}
583
584template <typename VarType>
587 AttributeBase::List &attributeDependencies,
588 AttributeBase::List &modifiedAttributes) {
589 modifiedAttributes.push_back(mRightVector);
590 prevStepDependencies.push_back(mIntfVoltage);
591}
592
593template <typename VarType>
595 Real time, Int timeStepCount) {
596 if (mDeviceManaged)
597 return;
598 mSimTime = time;
600 (**mRightVector).setZero();
602}
603
604template <typename VarType>
607 AttributeBase::List &attributeDependencies,
608 AttributeBase::List &modifiedAttributes,
609 Attribute<Matrix>::Ptr &leftVector) {
610 attributeDependencies.push_back(leftVector);
611 modifiedAttributes.push_back(mIntfVoltage);
612}
613
614template <typename VarType>
616 Real time, Int timeStepCount, Attribute<Matrix>::Ptr &leftVector) {
617 if (mDeviceManaged)
618 return;
619 mnaCompPostStep(**leftVector);
620}
621
622template <typename VarType>
624 std::shared_ptr<Base::Exciter> exciter,
625 std::shared_ptr<Base::ExciterParameters> params) {
626 mExciter = exciter;
627 mHasExciter = static_cast<bool>(mExciter);
628 if (!mExciter) {
629 SPDLOG_LOGGER_ERROR(
630 this->mSLog, "addExciter called with null exciter on {}", *this->mName);
631 return;
632 }
633 if (!params) {
634 SPDLOG_LOGGER_WARN(this->mSLog,
635 "addExciter called without parameters on {}",
636 *this->mName);
637 return;
638 }
639 mExciter->setParameters(params);
640}
641
642template <typename VarType>
644 std::shared_ptr<Base::Exciter> exciter) {
645 mExciter = exciter;
646 mHasExciter = static_cast<bool>(mExciter);
647 if (!mExciter) {
648 SPDLOG_LOGGER_ERROR(
649 this->mSLog, "addExciter called with null exciter on {}", *this->mName);
650 return;
651 }
652}
653
654// Deprecated: only for compatibility
655template <typename VarType>
657 Real Ta, Real Ka, Real Te, Real Ke, Real Tf, Real Kf, Real Tr) {
658 SPDLOG_LOGGER_WARN(
659 this->mSLog,
660 "Deprecated API addExciter(Ta,Ka,Te,Ke,Tf,Kf,Tr) called on {}. "
661 "This overload will be removed in the future. "
662 "Please create an ExciterDC1Simp and parameters explicitly.",
663 *this->mName);
664
665 auto params = std::make_shared<CPS::Signal::ExciterDC1SimpParameters>();
666 params->Ta = Ta;
667 params->Ka = Ka;
668 params->Tef = Te; // map Te → Tef
669 params->Kef = Ke; // map Ke → Kef
670 params->Tf = Tf;
671 params->Kf = Kf;
672 params->Tr = Tr;
673
674 // Keep saturation disabled unless explicitly set elsewhere
675 params->Aef = 0.0;
676 params->Bef = 0.0;
677
678 // Apply legacy amplifier limits for the deprecated path
679 params->MaxVa = 1.0;
680 params->MinVa = -0.9;
681
682 auto name = (**this->mName) + std::string("_Exciter");
683 mExciter =
684 std::make_shared<CPS::Signal::ExciterDC1Simp>(name, this->mLogLevel);
685 mExciter->setParameters(params);
686 mHasExciter = true;
687
688 SPDLOG_LOGGER_INFO(
689 this->mSLog,
690 "Attached ExciterDC1Simp to {} (Ka={:.3g}, Ta={:.3g}, Kef={:.3g}, "
691 "Tef={:.3g}, "
692 "Kf={:.3g}, Tf={:.3g}, Tr={:.3g}, MaxVa={:.3g}, MinVa={:.3g})",
693 *this->mName, params->Ka, params->Ta, params->Kef, params->Tef,
694 params->Kf, params->Tf, params->Tr, params->MaxVa, params->MinVa);
695}
696
697template <typename VarType>
699 Real T3, Real T4, Real T5, Real Tc, Real Ts, Real R, Real Pmin, Real Pmax,
700 Real OmRef, Real TmRef) {
702 **this->mName + "_TurbineGovernor", this->mLogLevel);
703 mTurbineGovernor->setParameters(T3, T4, T5, Tc, Ts, R, Pmin, Pmax, OmRef);
704 mTurbineGovernor->initializeStates(TmRef);
705 mHasTurbineGovernor = true;
706}
707
708template <typename VarType>
710 std::shared_ptr<Signal::TurbineGovernorType1> turbineGovernor) {
711 if (!turbineGovernor) {
712 SPDLOG_LOGGER_ERROR(
713 this->mSLog, "addGovernor called with null TurbineGovernorType1 on {}",
714 *this->mName);
715 return;
716 }
717 mTurbineGovernor = turbineGovernor;
718 mHasTurbineGovernor = true;
719}
720
721template <typename VarType>
723 std::shared_ptr<Base::Governor> governor,
724 std::shared_ptr<Base::GovernorParameters> govParams,
725 std::shared_ptr<Base::Turbine> turbine,
726 std::shared_ptr<Base::TurbineParameters> turbineParams) {
727 if (!governor) {
728 SPDLOG_LOGGER_ERROR(this->mSLog,
729 "addGovernorAndTurbine called with null governor on {}",
730 *this->mName);
731 return;
732 }
733 if (!turbine) {
734 SPDLOG_LOGGER_ERROR(this->mSLog,
735 "addGovernorAndTurbine called with null turbine on {}",
736 *this->mName);
737 return;
738 }
739 governor->setParameters(govParams);
740 turbine->setParameters(turbineParams);
741 mGovernor = governor;
742 mTurbine = turbine;
744}
745
746template <typename VarType>
748 std::shared_ptr<Base::Governor> governor,
749 std::shared_ptr<Base::Turbine> turbine) {
750 if (!governor) {
751 SPDLOG_LOGGER_ERROR(this->mSLog,
752 "addGovernorAndTurbine called with null governor on {}",
753 *this->mName);
754 return;
755 }
756 if (!turbine) {
757 SPDLOG_LOGGER_ERROR(this->mSLog,
758 "addGovernorAndTurbine called with null turbine on {}",
759 *this->mName);
760 return;
761 }
762 mGovernor = governor;
763 mTurbine = turbine;
765}
766
767template <typename VarType>
769 std::shared_ptr<Base::PSS> pss,
770 std::shared_ptr<Base::PSSParameters> parameters) {
771 if (!mHasExciter) {
772 SPDLOG_LOGGER_ERROR(this->mSLog, "Cannot attach PSS: no exciter present. "
773 "Attach an exciter first.");
775 }
776 if (!pss) {
777 SPDLOG_LOGGER_ERROR(this->mSLog, "addPSS called with null PSS on {}",
778 *this->mName);
779 return;
780 }
781 mPSS = pss;
782 mPSS->setParameters(parameters);
783 mHasPSS = true;
784}
785
786template <typename VarType>
788 std::shared_ptr<Base::PSS> pss) {
789 if (!mHasExciter) {
790 SPDLOG_LOGGER_ERROR(this->mSLog, "Cannot attach PSS: no exciter present. "
791 "Attach an exciter first.");
793 }
794 if (!pss) {
795 SPDLOG_LOGGER_ERROR(this->mSLog, "addPSS called with null PSS on {}",
796 *this->mName);
797 return;
798 }
799 mPSS = pss;
800 mHasPSS = true;
801}
802
803// Declare specializations to move definitions to .cpp
std::vector< Ptr > List
Definition Attribute.h:123
AttributePointer< Attribute< T > > Ptr
Definition Attribute.h:249
Bool mInitialValuesSet
Flag to remember when initial values are set.
void addGovernorAndTurbine(std::shared_ptr< Base::Governor > governor, std::shared_ptr< Base::GovernorParameters > govParams, std::shared_ptr< Base::Turbine > turbine, std::shared_ptr< Base::TurbineParameters > turbineParams)
Add a modular governor + turbine pair (new API for SteamTurbineGovernor / SteamTurbine)
Complex mInitVoltage
initial terminal voltage phase a (p.u.)
void setBaseParameters(Real nomPower, Real nomVolt, Real nomFreq)
virtual void specificInitialization()=0
Function to initialize the specific variables of each SG model.
void addPSS(std::shared_ptr< Base::PSS > pss, std::shared_ptr< Base::PSSParameters > parameters)
Attach a PSS (initialises parameters) to this generator.
void setInitialValues(Complex initComplexElectricalPower, Real initMechanicalPower, Complex initTerminalVoltage)
Complex mInitCurrent
initial armature voltage phase a (p.u.)
Bool mHasTurbineGovernor
Determines if TurbineGovernorType1 is activated.
void setOperationalParametersPerUnit(Real nomPower, Real nomVolt, Real nomFreq, Real H, Real Ld, Real Lq, Real L0, Real Ld_t, Real Td0_t)
Initialization for 3 Order SynGen.
Bool mHasGovernorAndTurbine
Determines if modular Governor + Turbine pair is activated.
void mnaCompAddPostStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes, Attribute< Matrix >::Ptr &leftVector) override
Add MNA post step dependencies.
Bool mModelAsNortonSource
Model flag indicating whether the machine is modelled as Norton or Thevenin equivalent.
virtual void setModelAsNortonSource(Bool modelAsCurrentSource)
std::shared_ptr< Base::Governor > mGovernor
Modular governor (SteamTurbineGovernor / HydroTurbineGovernor)
void addExciter(std::shared_ptr< Base::Exciter > exciter, std::shared_ptr< Base::ExciterParameters > params)
Add voltage regulator and exciter.
Real mInitVoltageAngle
angle of initial armature voltage
void mnaCompInitialize(Real omega, Real timeStep, Attribute< Matrix >::Ptr leftVector) override
std::shared_ptr< Base::PSS > mPSS
Power system stabilizer.
std::shared_ptr< Base::Exciter > mExciter
Signal component modelling voltage regulator and exciter.
void initializeFromNodesAndTerminals(Real frequency) override
Initializes Component variables according to power flow data stored in Nodes.
void mnaCompPreStep(Real time, Int timeStepCount) override
void mnaCompAddPreStepDependencies(AttributeBase::List &prevStepDependencies, AttributeBase::List &attributeDependencies, AttributeBase::List &modifiedAttributes) override
Add MNA pre step dependencies.
virtual void stepInPerUnit()=0
Model specific step.
Real mInitCurrentAngle
angle of initial armature current
std::shared_ptr< Base::Turbine > mTurbine
Modular turbine (SteamTurbine / HydroTurbine)
void addGovernor(Real T3, Real T4, Real T5, Real Tc, Real Ts, Real R, Real Pmin, Real Pmax, Real OmRef, Real TmRef)
Add governor and turbine (TurbineGovernorType1 legacy API)
Bool mHasExciter
Determines if Exciter is activated.
ReducedOrderSynchronGenerator(String uid, String name, Logger::Level logLevel)
void mnaCompPostStep(Real time, Int timeStepCount, Attribute< Matrix >::Ptr &leftVector) final
std::shared_ptr< Signal::TurbineGovernorType1 > mTurbineGovernor
TurbineGovernorType1 (legacy)
const Attribute< String >::Ptr mName
Human readable name.
spdlog::level::level_enum Level
Definition Logger.h:33
Base class for all MNA components that are transmitting power.
Attribute< Matrix >::Ptr mRightVector
virtual void mnaCompApplyRightSideVectorStamp(Matrix &rightVector)
static Real phaseDeg(Complex value)
Definition MathUtils.cpp:69
static Real phase(Complex value)
Definition MathUtils.cpp:67
static Real abs(Complex value)
Definition MathUtils.cpp:71
void setVirtualNodeNumber(UInt num)
const Attribute< MatrixVar< VarType > >::Ptr mIntfVoltage
Voltage between terminals.
void updateMatrixNodeIndices()
Update the "cached" mMatrixNodeIndices and mMatrixNodeIndexIsGround members.
Logger::Level mLogLevel
Component logger control for internal variables.
Logger::Log mSLog
Component logger.
static std::shared_ptr< TurbineGovernorType1 > make(Args &&...args)
Definition PtrFactory.h:19
#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
bool Bool
Definition Definitions.h:62