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};
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;
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),
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",
63std::vector<EMT::SSNComp::LocalAbcStateBlock>
66 {{
static_cast<UInt>(VcA),
static_cast<UInt>(VcB),
static_cast<UInt>(VcC)},
68 {{
static_cast<UInt>(IfA),
static_cast<UInt>(IfB),
static_cast<UInt>(IfC)},
78 throw std::invalid_argument(
"Filter inductance lf must be positive.");
81 throw std::invalid_argument(
"Filter capacitance cf must be positive.");
84 throw std::invalid_argument(
"Filter resistance rf must be non-negative.");
87 throw std::invalid_argument(
"Coupling resistance rc must be positive.");
90 throw std::invalid_argument(
91 "Nominal angular frequency omegaN must be positive.");
93 if (omegaCutoff < 0.0)
94 throw std::invalid_argument(
95 "Power-filter cutoff frequency omegaCutoff must be non-negative.");
98 throw std::invalid_argument(
"PLL integral gain kiPLL must be non-zero.");
100 if (kiPowerCtrl == 0.0)
101 throw std::invalid_argument(
102 "Power-control integral gain kiPowerCtrl must be non-zero.");
104 if (kiCurrCtrl == 0.0)
105 throw std::invalid_argument(
106 "Current-control integral gain kiCurrCtrl must be non-zero.");
117 mOmegaCutoff = omegaCutoff;
120 mKpPowerCtrl = kpPowerCtrl;
121 mKiPowerCtrl = kiPowerCtrl;
122 mKpCurrCtrl = kpCurrCtrl;
123 mKiCurrCtrl = kiCurrCtrl;
125 const Matrix x0 = Matrix::Zero(mStateSize, 1);
126 const Matrix u0 = Matrix::Zero(3, 1);
134 buildStateSpaceModel(x0, u0, aMatrix, bMatrix, cMatrix, dMatrix, eVector,
141Matrix EMT::Ph3::AvVoltSourceInverterStateSpace::getParkTransformMatrix(
144 const Real k = std::sqrt(2.0 / 3.0);
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);
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);
156Matrix EMT::Ph3::AvVoltSourceInverterStateSpace::getInverseParkTransformMatrix(
159 const Real k = std::sqrt(2.0 / 3.0);
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);
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;
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);
183 **mPInst = **mVcD * **mIrcD + **mVcQ * **mIrcQ;
184 **mQInst = -**mVcD * **mIrcQ + **mVcQ * **mIrcD;
186 **mOmegaPLL = mOmegaN + mKpPLL * **mVcQ + mKiPLL * x(PhiPLL, 0);
192 throw std::logic_error(
"setParameters() must be called before "
193 "initializeFromNodesAndTerminals().");
200 const Real omega = 2.0 *
PI * frequency;
202 const Complex powerRef(mPRef, mQRef);
207 MatrixComp iInjPhasor = MatrixComp::Zero(3, 1);
210 const Complex vcA = vcPhasor(0, 0);
213 iInjPhasor.setZero();
217 const Complex iA = std::conj(powerRef / (1.5 * vcA));
222 const MatrixComp vcNext = uPhasor + mRc * iNext;
234 const MatrixComp ifPhasor = j * omega * mCf * vcPhasor + iInjPhasor;
235 const MatrixComp vRefPhasor = vcPhasor + (mRf + j * omega * mLf) * ifPhasor;
237 const Matrix vcAbc0 = vcPhasor.real();
238 const Matrix ifAbc0 = ifPhasor.real();
239 const Matrix iInjAbc0 = iInjPhasor.real();
240 const Matrix vRefAbc0 = vRefPhasor.real();
242 const Real theta0 = std::arg(vcPhasor(0, 0));
243 const Matrix parkTransform = getParkTransformMatrix(theta0);
245 const Matrix vcDq = parkTransform * vcAbc0;
246 const Matrix iDq = parkTransform * iInjAbc0;
247 const Matrix vRefDq = parkTransform * vRefAbc0;
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);
254 const Real pInit = vcD * ircD + vcQ * ircQ;
255 const Real qInit = -vcD * ircQ + vcQ * ircD;
257 Matrix x0 = Matrix::Zero(mStateSize, 1);
259 x0(ThetaPLL, 0) = theta0;
260 x0(PhiPLL, 0) = (omega - mOmegaN) / mKiPLL;
261 x0(PFiltered, 0) = pInit;
262 x0(QFiltered, 0) = qInit;
264 x0(PhiD, 0) = (ircD + mKpPowerCtrl * (pInit - mPRef)) / mKiPowerCtrl;
265 x0(PhiQ, 0) = (ircQ - mKpPowerCtrl * (qInit - mQRef)) / mKiPowerCtrl;
268 -mKpPowerCtrl * pInit + mKiPowerCtrl * x0(PhiD, 0) + mKpPowerCtrl * mPRef;
270 mKpPowerCtrl * qInit + mKiPowerCtrl * x0(PhiQ, 0) - mKpPowerCtrl * mQRef;
272 x0(GammaD, 0) = (vRefDq(0, 0) + mKpCurrCtrl * (ircD - iRefD)) / mKiCurrCtrl;
273 x0(GammaQ, 0) = (vRefDq(1, 0) + mKpCurrCtrl * (ircQ - iRefQ)) / mKiCurrCtrl;
275 x0.block(VcA, 0, 3, 1) = vcAbc0;
276 x0.block(IfA, 0, 3, 1) = ifAbc0;
285 SPDLOG_LOGGER_INFO(
mSLog,
286 "\n--- Inverter SSN phasor/dq initialization ---"
290 "\nP/Q init: [{:.6e}, {:.6e}]"
291 "\nVc dq: [{:.6e}, {:.6e}]"
292 "\nIinj dq: [{:.6e}, {:.6e}]"
293 "\n--- Initialization finished ---",
300void EMT::Ph3::AvVoltSourceInverterStateSpace::buildStateSpaceModel(
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);
315 const Matrix identity3 = Matrix::Identity(3, 3);
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);
325 const Matrix dTdTheta = tQ;
326 const Matrix dTqTheta = -tD;
327 const Matrix dSdTheta = sQ;
328 const Matrix dSqTheta = -sD;
338 const Real vq0 = (tQ * vcAbc0)(0, 0);
339 const Real aThetaPLL = (dTqTheta * vcAbc0)(0, 0);
341 const Real bVq = vq0 - aThetaPLL * theta0 - (aVPLL * vcAbc0)(0, 0);
354 const Matrix iInjAbc0 = (vcAbc0 - u) / mRc;
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);
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;
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);
373 const Real bIrcD = ircD0 - dIrcDByTheta * theta0 -
374 (dIrcDByVc * vcAbc0)(0, 0) - (dIrcDByU * u)(0, 0);
376 const Real bIrcQ = ircQ0 - dIrcQByTheta * theta0 -
377 (dIrcQByVc * vcAbc0)(0, 0) - (dIrcQByU * u)(0, 0);
388 const Real p0 = vcD0 * ircD0 + vcQ0 * ircQ0;
389 const Real dPByTheta = ircD0 * dVcDByTheta + vcD0 * dIrcDByTheta +
390 ircQ0 * dVcQByTheta + vcQ0 * dIrcQByTheta;
392 ircD0 * dVcDByVc + vcD0 * dIrcDByVc + ircQ0 * dVcQByVc + vcQ0 * dIrcQByVc;
393 const Matrix dPByU = vcD0 * dIrcDByU + vcQ0 * dIrcQByU;
395 p0 - dPByTheta * theta0 - (dPByVc * vcAbc0)(0, 0) - (dPByU * u)(0, 0);
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;
404 q0 - dQByTheta * theta0 - (dQByVc * vcAbc0)(0, 0) - (dQByU * u)(0, 0);
416 -mKpPowerCtrl * pFiltered0 + mKiPowerCtrl * phiD0 + mKpPowerCtrl * mPRef;
418 mKpPowerCtrl * qFiltered0 + mKiPowerCtrl * phiQ0 - mKpPowerCtrl * mQRef;
432 -mKpCurrCtrl * ircD0 + mKiCurrCtrl * gammaD0 + mKpCurrCtrl * iRefD0;
434 -mKpCurrCtrl * ircQ0 + mKiCurrCtrl * gammaQ0 + mKpCurrCtrl * iRefQ0;
436 const Matrix vRefAbc0 = sD * vRefD0 + sQ * vRefQ0;
438 const Real dVRefDByTheta = -mKpCurrCtrl * dIrcDByTheta;
439 const Matrix dVRefDByVc = -mKpCurrCtrl * dIrcDByVc;
440 const Matrix dVRefDByU = -mKpCurrCtrl * dIrcDByU;
442 const Real dVRefQByTheta = -mKpCurrCtrl * dIrcQByTheta;
443 const Matrix dVRefQByVc = -mKpCurrCtrl * dIrcQByVc;
444 const Matrix dVRefQByU = -mKpCurrCtrl * dIrcQByU;
446 Matrix dVRefAbcByX = Matrix::Zero(3, mStateSize);
447 Matrix dVRefAbcByU = Matrix::Zero(3, 3);
449 dVRefAbcByX.col(ThetaPLL) = dSdTheta * vRefD0 + dSqTheta * vRefQ0 +
450 sD * dVRefDByTheta + sQ * dVRefQByTheta;
452 dVRefAbcByX.col(PFiltered) += sD * (-mKpCurrCtrl * mKpPowerCtrl);
453 dVRefAbcByX.col(PhiD) += sD * (mKpCurrCtrl * mKiPowerCtrl);
454 dVRefAbcByX.col(GammaD) += sD * mKiCurrCtrl;
456 dVRefAbcByX.col(QFiltered) += sQ * (mKpCurrCtrl * mKpPowerCtrl);
457 dVRefAbcByX.col(PhiQ) += sQ * (mKpCurrCtrl * mKiPowerCtrl);
458 dVRefAbcByX.col(GammaQ) += sQ * mKiCurrCtrl;
460 dVRefAbcByX.block(0, VcA, 3, 3) += sD * dVRefDByVc + sQ * dVRefQByVc;
462 dVRefAbcByU = sD * dVRefDByU + sQ * dVRefQByU;
464 const Matrix vRefAbcOffset = vRefAbc0 - dVRefAbcByX * x - dVRefAbcByU * u;
472 A.setZero(mStateSize, mStateSize);
473 B.setZero(mStateSize, 3);
474 C.setZero(3, mStateSize);
476 E.setZero(mStateSize, 1);
482 A(ThetaPLL, ThetaPLL) = mKpPLL * aThetaPLL;
483 A(ThetaPLL, PhiPLL) = mKiPLL;
484 A.block(ThetaPLL, VcA, 1, 3) = mKpPLL * aVPLL;
486 A(PhiPLL, ThetaPLL) = aThetaPLL;
487 A.block(PhiPLL, VcA, 1, 3) = aVPLL;
489 E(ThetaPLL, 0) = mOmegaN + mKpPLL * bVq;
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;
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;
510 A(PhiD, PFiltered) = -1.0;
513 A(PhiQ, QFiltered) = 1.0;
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;
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;
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;
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;
554 C.block(0, VcA, 3, 3) = -1.0 / mRc * identity3;
555 D = 1.0 / mRc * identity3;
564 mParameterStateOffset, mParameterOutputOffset);
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
Bool updateComponentParameters() 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)
MatrixComp buildInitialInputFromNodes(Real frequency) override final
const Attribute< Matrix >::Ptr mX
void setStateOffset(const Matrix &E)
void setParameters(const Matrix &A, const Matrix &B, const Matrix &C, const Matrix &D)
static constexpr Real mInitializationTolerance
void setOutputOffset(const Matrix &F)
static constexpr Int mInitializationMaxIterations
String uid()
Returns unique id.
AttributeList::Ptr mAttributes
Attribute List.
spdlog::level::level_enum Level
static String matrixToString(const Matrix &mat)
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.
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > Matrix
Dense matrix for real numbers.
std::complex< Real > Complex
Eigen::Matrix< Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixComp
Dense matrix for complex numbers.