DPsim
Loading...
Searching...
No Matches
MathUtils.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
10
11#include <cmath>
12#include <cstdint>
13#include <cstring>
14#include <stdexcept>
15#include <unordered_map>
16
17using namespace CPS;
18
19namespace {
20using SparseCache = std::unordered_map<std::uint64_t, Eigen::Index>;
21thread_local Bool gZeroSkippingEnabled = true;
22std::unordered_map<const CPS::SparseMatrixRow *, SparseCache>
23 gSparseMatrixValueCaches;
24
25std::uint64_t sparseKey(Eigen::Index row, Eigen::Index column) {
26 return (static_cast<std::uint64_t>(row) << 32) |
27 static_cast<std::uint64_t>(column);
28}
29
30Real *cachedSparseValue(CPS::SparseMatrixRow &mat, Eigen::Index row,
31 Eigen::Index column) {
32 auto cacheIt = gSparseMatrixValueCaches.find(&mat);
33 if (cacheIt == gSparseMatrixValueCaches.end())
34 return nullptr;
35 auto valueIt = cacheIt->second.find(sparseKey(row, column));
36 if (valueIt == cacheIt->second.end())
37 return nullptr;
38 return mat.valuePtr() + valueIt->second;
39}
40
41Matrix trapezoidalStep(const Matrix &states, const Matrix &A,
42 const Matrix &input, Real dt) {
43 const Matrix identity = Matrix::Identity(states.rows(), states.rows());
44 const Matrix lhs = identity - (dt / 2.) * A;
45 const Matrix rhs = (identity + (dt / 2.) * A) * states + dt * input;
46 return lhs.partialPivLu().solve(rhs);
47}
48
49} // namespace
50
52 : mPrevious(gZeroSkippingEnabled) {
53 gZeroSkippingEnabled = enabled;
54}
55
57 gZeroSkippingEnabled = mPrevious;
58}
59
60Bool Math::zeroSkippingEnabled() { return gZeroSkippingEnabled; }
61
62// #### Angular Operations ####
63Real Math::radtoDeg(Real rad) { return rad * 180 / PI; }
64
65Real Math::degToRad(Real deg) { return deg * PI / 180; }
66
67Real Math::phase(Complex value) { return std::arg(value); }
68
69Real Math::phaseDeg(Complex value) { return radtoDeg(phase(value)); }
70
71Real Math::abs(Complex value) { return std::abs(value); }
72
74 size_t nRows = mat.rows();
75 size_t nCols = mat.cols();
76 Matrix res(mat.rows(), mat.cols());
77
78 for (size_t i = 0; i < nRows; ++i) {
79 for (size_t j = 0; j < nCols; ++j) {
80 res(i, j) = std::abs(mat(i, j));
81 }
82 }
83 return res;
84}
85
87 size_t nRows = mat.rows();
88 size_t nCols = mat.cols();
89 Matrix res(mat.rows(), mat.cols());
90
91 for (size_t i = 0; i < nRows; ++i) {
92 for (size_t j = 0; j < nCols; ++j) {
93 res(i, j) = std::arg(mat(i, j));
94 }
95 }
96 return res;
97}
98
100 return std::polar<Real>(abs, phase);
101}
102
104 return std::polar<Real>(abs, degToRad(phase));
105}
106
107bool Math::isFinite(Real value) {
108 uint64_t bits;
109 std::memcpy(&bits, &value, sizeof(bits));
110 return (bits & 0x7FF0000000000000ULL) != 0x7FF0000000000000ULL;
111}
112
114 return isFinite(value.real()) && isFinite(value.imag());
115}
116
117void Math::setVectorElement(Matrix &mat, Matrix::Index row, Complex value,
118 Int maxFreq, Int freqIdx, Matrix::Index colOffset) {
119 Eigen::Index harmonicOffset = mat.rows() / maxFreq;
120 Eigen::Index complexOffset = harmonicOffset / 2;
121 Eigen::Index harmRow = row + harmonicOffset * freqIdx;
122
123 mat(harmRow, colOffset) = value.real();
124 mat(harmRow + complexOffset, colOffset) = value.imag();
125}
126
127void Math::addToVectorElement(Matrix &mat, Matrix::Index row, Complex value,
128 Int maxFreq, Int freqIdx) {
129 Eigen::Index harmonicOffset = mat.rows() / maxFreq;
130 Eigen::Index complexOffset = harmonicOffset / 2;
131 Eigen::Index harmRow = row + harmonicOffset * freqIdx;
132
133 mat(harmRow, 0) = mat(harmRow, 0) + value.real();
134 mat(harmRow + complexOffset, 0) =
135 mat(harmRow + complexOffset, 0) + value.imag();
136}
137
138Complex Math::complexFromVectorElement(const Matrix &mat, Matrix::Index row,
139 Int maxFreq, Int freqIdx) {
140 Eigen::Index harmonicOffset = mat.rows() / maxFreq;
141 Eigen::Index complexOffset = harmonicOffset / 2;
142 Eigen::Index harmRow = row + harmonicOffset * freqIdx;
143
144 return Complex(mat(harmRow, 0), mat(harmRow + complexOffset, 0));
145}
146
147void Math::addToVectorElement(Matrix &mat, Matrix::Index row, Real value) {
148 mat(row, 0) = mat(row, 0) + value;
149}
150
151void Math::setVectorElement(Matrix &mat, Matrix::Index row, Real value) {
152 mat(row, 0) = value;
153}
154
155Real Math::realFromVectorElement(const Matrix &mat, Matrix::Index row) {
156 return mat(row, 0);
157}
158
159void Math::setMatrixElement(SparseMatrixRow &mat, Matrix::Index row,
160 Matrix::Index column, Complex value, Int maxFreq,
161 Int freqIdx) {
162 // Assume square matrix
163 Eigen::Index harmonicOffset = mat.rows() / maxFreq;
164 Eigen::Index complexOffset = harmonicOffset / 2;
165 Eigen::Index harmRow = row + harmonicOffset * freqIdx;
166 Eigen::Index harmCol = column + harmonicOffset * freqIdx;
167
168 auto set = [&mat](Eigen::Index r, Eigen::Index c, Real v) {
169 if (zeroSkippingEnabled() && v == 0. && mat.coeff(r, c) == 0.)
170 return;
171 if (Real *cached = cachedSparseValue(mat, r, c))
172 *cached = v;
173 else
174 mat.coeffRef(r, c) = v;
175 };
176 set(harmRow, harmCol, value.real());
177 set(harmRow + complexOffset, harmCol + complexOffset, value.real());
178 set(harmRow, harmCol + complexOffset, -value.imag());
179 set(harmRow + complexOffset, harmCol, value.imag());
180}
181
182void Math::addToMatrixElement(SparseMatrixRow &mat, Matrix::Index row,
183 Matrix::Index column, Complex value, Int maxFreq,
184 Int freqIdx) {
185 // Assume square matrix
186 Eigen::Index harmonicOffset = mat.rows() / maxFreq;
187 Eigen::Index complexOffset = harmonicOffset / 2;
188 Eigen::Index harmRow = row + harmonicOffset * freqIdx;
189 Eigen::Index harmCol = column + harmonicOffset * freqIdx;
190
191 auto add = [&mat](Eigen::Index r, Eigen::Index c, Real v) {
192 if (zeroSkippingEnabled() && v == 0.)
193 return;
194 if (Real *cached = cachedSparseValue(mat, r, c))
195 *cached += v;
196 else
197 mat.coeffRef(r, c) += v;
198 };
199 add(harmRow, harmCol, value.real());
200 add(harmRow + complexOffset, harmCol + complexOffset, value.real());
201 add(harmRow, harmCol + complexOffset, -value.imag());
202 add(harmRow + complexOffset, harmCol, value.imag());
203}
204
205void Math::addToMatrixElement(SparseMatrixRow &mat, Matrix::Index row,
206 Matrix::Index column, Matrix value, Int maxFreq,
207 Int freqIdx) {
208 // Assume square matrix
209 Eigen::Index harmonicOffset = mat.rows() / maxFreq;
210 Eigen::Index complexOffset = harmonicOffset / 2;
211 Eigen::Index harmRow = row + harmonicOffset * freqIdx;
212 Eigen::Index harmCol = column + harmonicOffset * freqIdx;
213
214 auto add = [&mat](Eigen::Index r, Eigen::Index c, Real v) {
215 if (zeroSkippingEnabled() && v == 0.)
216 return;
217 if (Real *cached = cachedSparseValue(mat, r, c))
218 *cached += v;
219 else
220 mat.coeffRef(r, c) += v;
221 };
222 add(harmRow, harmCol, value(0, 0));
223 add(harmRow + complexOffset, harmCol + complexOffset, value(1, 1));
224 add(harmRow, harmCol + complexOffset, value(0, 1));
225 add(harmRow + complexOffset, harmCol, value(1, 0));
226}
227
228void Math::setMatrixElement(SparseMatrixRow &mat, Matrix::Index row,
229 Matrix::Index column, Real value) {
230 if (zeroSkippingEnabled() && value == 0. && mat.coeff(row, column) == 0.)
231 return;
232 if (Real *cached = cachedSparseValue(mat, row, column))
233 *cached = value;
234 else
235 mat.coeffRef(row, column) = value;
236}
237
238void Math::addToMatrixElement(SparseMatrixRow &mat, std::vector<UInt> rows,
239 std::vector<UInt> columns, Complex value) {
240 for (UInt phase = 0; phase < rows.size(); phase++)
241 addToMatrixElement(mat, rows[phase], columns[phase], value);
242}
243
244void Math::addToMatrixElement(SparseMatrixRow &mat, Matrix::Index row,
245 Matrix::Index column, Real value) {
246 if (zeroSkippingEnabled() && value == 0.)
247 return;
248 if (Real *cached = cachedSparseValue(mat, row, column))
249 *cached += value;
250 else
251 mat.coeffRef(row, column) = mat.coeff(row, column) + value;
252}
253
255 Matrix::Index column, Complex value) {
256 if (zeroSkippingEnabled() && value == Complex(0., 0.))
257 return;
258 mat.coeffRef(row, column) += value;
259}
260
262 SparseCache cache;
263 cache.reserve(static_cast<std::size_t>(mat.nonZeros()));
264 for (Eigen::Index row = 0; row < mat.outerSize(); ++row) {
265 for (SparseMatrixRow::InnerIterator it(mat, row); it; ++it) {
266 cache.emplace(sparseKey(it.row(), it.col()),
267 &it.valueRef() - mat.valuePtr());
268 }
269 }
270 gSparseMatrixValueCaches[&mat] = std::move(cache);
271}
272
274 gSparseMatrixValueCaches.erase(&mat);
275}
276
277void Math::addToMatrixElement(SparseMatrixRow &mat, std::vector<UInt> rows,
278 std::vector<UInt> columns, Real value) {
279 for (UInt phase = 0; phase < rows.size(); phase++)
280 addToMatrixElement(mat, rows[phase], columns[phase], value);
281}
282
283void Math::invertMatrix(const Matrix &mat, Matrix &matInv) {
284 const Int n = Eigen::internal::convert_index<Int>(mat.cols());
285 if (n == 2) {
286 const Real determinant = mat(0, 0) * mat(1, 1) - mat(0, 1) * mat(1, 0);
287 matInv(0, 0) = mat(1, 1) / determinant;
288 matInv(0, 1) = -mat(0, 1) / determinant;
289 matInv(1, 0) = -mat(1, 0) / determinant;
290 matInv(1, 1) = mat(0, 0) / determinant;
291 } else if (n == 3) {
292 const Real determinant =
293 (mat(0, 0) * mat(1, 1) * mat(2, 2) + mat(0, 1) * mat(1, 2) * mat(2, 0) +
294 mat(1, 0) * mat(2, 1) * mat(0, 2)) -
295 (mat(2, 0) * mat(1, 1) * mat(0, 2) + mat(1, 0) * mat(0, 1) * mat(2, 2) +
296 mat(2, 1) * mat(1, 2) * mat(0, 0));
297 matInv(0, 0) =
298 (mat(1, 1) * mat(2, 2) - mat(1, 2) * mat(2, 1)) / determinant;
299 matInv(0, 1) =
300 (mat(0, 2) * mat(2, 1) - mat(0, 1) * mat(2, 2)) / determinant;
301 matInv(0, 2) =
302 (mat(0, 1) * mat(1, 2) - mat(0, 2) * mat(1, 1)) / determinant;
303 matInv(1, 0) =
304 (mat(1, 2) * mat(2, 0) - mat(1, 0) * mat(2, 2)) / determinant;
305 matInv(1, 1) =
306 (mat(0, 0) * mat(2, 2) - mat(0, 2) * mat(2, 0)) / determinant;
307 matInv(1, 2) =
308 (mat(0, 2) * mat(1, 0) - mat(0, 0) * mat(1, 2)) / determinant;
309 matInv(2, 0) =
310 (mat(1, 0) * mat(2, 1) - mat(1, 1) * mat(2, 0)) / determinant;
311 matInv(2, 1) =
312 (mat(0, 1) * mat(2, 0) - mat(0, 0) * mat(2, 1)) / determinant;
313 matInv(2, 2) =
314 (mat(0, 0) * mat(1, 1) - mat(0, 1) * mat(1, 0)) / determinant;
315 } else {
316 matInv = mat.inverse();
317 }
318}
319
321 MatrixComp var_3ph = MatrixComp::Zero(3, 1);
322 var_3ph << var_1ph, var_1ph * SHIFT_TO_PHASE_B, var_1ph * SHIFT_TO_PHASE_C;
323 return var_3ph;
324}
325
327 Matrix param_3ph = Matrix::Zero(3, 3);
328 param_3ph << parameter, 0., 0., 0., parameter, 0., 0, 0., parameter;
329 return param_3ph;
330}
331
333 Matrix power_3ph = Matrix::Zero(3, 3);
334 power_3ph << power / 3., 0., 0., 0., power / 3., 0., 0, 0., power / 3.;
335 return power_3ph;
336}
337
338std::pair<Real, Real> Math::pccPowerFromFilterPowerReference(Real pFilterRef,
339 Real qFilterRef,
340 Real rc,
341 Real vGridRmsLL) {
342 const Real vPccPeakPhase = RMS3PH_TO_PEAK1PH * vGridRmsLL;
343 if (std::abs(rc) < 1e-12 || vPccPeakPhase < 1e-9)
344 return {pFilterRef, qFilterRef};
345
346 const Real qPccRef = qFilterRef;
347 const Real a = rc / (1.5 * vPccPeakPhase * vPccPeakPhase);
348 const Real discriminant =
349 1.0 + 4.0 * a * (pFilterRef - a * qPccRef * qPccRef);
350 if (discriminant < 0.0)
351 throw std::runtime_error("No feasible PCC power for the given filter-side "
352 "power reference, rc, and PCC voltage estimate.");
353
354 const Real sqrtDisc = std::sqrt(discriminant);
355 const Real p1 = (-1.0 + sqrtDisc) / (2.0 * a);
356 const Real p2 = (-1.0 - sqrtDisc) / (2.0 * a);
357 const Real pPccRef =
358 std::abs(p1 - pFilterRef) < std::abs(p2 - pFilterRef) ? p1 : p2;
359 return {pPccRef, qPccRef};
360}
361
363 Matrix u_new, Matrix u_old) {
364 return StateSpaceTrapezoidalNoCopy(states, A, B, dt, u_new, u_old);
365}
366
368 Real dt, Matrix u_new, Matrix u_old) {
369 return StateSpaceTrapezoidalNoCopy(states, A, B, C, dt, u_new, u_old);
370}
371
373 Matrix u) {
374 return StateSpaceTrapezoidalNoCopy(states, A, B, dt, u);
375}
376
378 Real dt, Matrix u) {
379 return StateSpaceTrapezoidalNoCopy(states, A, B, C, dt, u);
380}
381
383 Real dt) {
384 return StateSpaceTrapezoidalNoCopy(states, A, input, dt);
385}
386
388 const Matrix &B, Real dt,
389 const Matrix &u_new,
390 const Matrix &u_old) {
391 return trapezoidalStep(states, A, (0.5 * B * (u_new + u_old)).eval(), dt);
392}
393
395 const Matrix &B, const Matrix &C,
396 Real dt, const Matrix &u_new,
397 const Matrix &u_old) {
398 const Matrix input = (0.5 * B * (u_new + u_old) + C).eval();
399 return trapezoidalStep(states, A, input, dt);
400}
401
403 const Matrix &B, const Matrix &C,
404 Real dt, const Matrix &u) {
405 const Matrix input = (B * u + C).eval();
406 return trapezoidalStep(states, A, input, dt);
407}
408
410 Real u) {
411 Real F1 = 1. + (dt / 2.) * A;
412 Real F2 = 1. - (dt / 2.) * A;
413 Real F2inv = 1. / F2;
414
415 return F2inv * F1 * states + F2inv * dt * B * u + F2inv * dt * C;
416}
417
419 const Matrix &B, Real dt,
420 const Matrix &u) {
421 return trapezoidalStep(states, A, (B * u).eval(), dt);
422}
423
425 const Matrix &input, Real dt) {
426 return trapezoidalStep(states, A, input, dt);
427}
428
430 Real F1 = 1. + (dt / 2.) * A;
431 Real F2 = 1. - (dt / 2.) * A;
432 Real F2inv = 1. / F2;
433
434 return F2inv * F1 * states + F2inv * dt * B * u;
435}
436
438 Matrix u) {
439 return StateSpaceEulerNoCopy(states, A, B, dt, u);
440}
441
443 Real dt, Matrix u) {
444 return StateSpaceEulerNoCopy(states, A, B, C, dt, u);
445}
446
448 return StateSpaceEulerNoCopy(states, A, input, dt);
449}
450
452 const Matrix &B, Real dt, const Matrix &u) {
453 return states + dt * (A * states + B * u);
454}
455
457 return states + dt * (A * states + B * u);
458}
459
461 const Matrix &B, const Matrix &C, Real dt,
462 const Matrix &u) {
463 return states + dt * (A * states + B * u + C);
464}
465
467 Real u) {
468 return states + dt * (A * states + B * u + C);
469}
470
472 const Matrix &input, Real dt) {
473 return states + dt * (A * states + input);
474}
475
477 const Matrix &B,
478 const Matrix &C,
479 const Real &dt, Matrix &Ad,
480 Matrix &Bd, Matrix &Cd) {
481 Matrix::Index n = A.rows();
482 Matrix I = Matrix::Identity(n, n);
483
484 Matrix F1 = I + (dt / 2.) * A;
485 Matrix F2 = I - (dt / 2.) * A;
486 Matrix F2inv = F2.inverse();
487
488 Ad = F2inv * F1;
489 Bd = F2inv * (dt / 2.) * B;
490 Cd = F2inv * dt * C;
491}
492
494 const Matrix &B,
495 const Real &dt, Matrix &Ad,
496 Matrix &Bd) {
497 Matrix::Index n = A.rows();
498 Matrix I = Matrix::Identity(n, n);
499
500 Matrix F1 = I + (dt / 2.) * A;
501 Matrix F2 = I - (dt / 2.) * A;
502 Matrix F2inv = F2.inverse();
503
504 Ad = F2inv * F1;
505 Bd = F2inv * (dt / 2.) * B;
506}
507
509 const Matrix &Bd,
510 const Matrix &Cd,
511 const Matrix &statesPrevStep,
512 const Matrix &inputCurrStep,
513 const Matrix &inputPrevStep) {
514 return Ad * statesPrevStep + Bd * (inputCurrStep + inputPrevStep) + Cd;
515}
516
517void Math::FFT(std::vector<Complex> &samples) {
518 // DFT
519 size_t N = samples.size();
520 size_t k = N;
521 size_t n;
522 double thetaT = M_PI / N;
523 Complex phiT = Complex(cos(thetaT), -sin(thetaT)), T;
524 while (k > 1) {
525 n = k;
526 k >>= 1;
527 phiT = phiT * phiT;
528 T = 1.0L;
529 for (size_t l = 0; l < k; l++) {
530 for (size_t a = l; a < N; a += n) {
531 size_t b = a + k;
532 Complex t = samples[a] - samples[b];
533 samples[a] += samples[b];
534 samples[b] = t * T;
535 }
536 T *= phiT;
537 }
538 }
539 // Decimate
540 UInt m = static_cast<UInt>(log2(N));
541 for (UInt a = 0; a < N; a++) {
542 UInt b = a;
543 // Reverse bits
544 b = (((b & 0xaaaaaaaa) >> 1) | ((b & 0x55555555) << 1));
545 b = (((b & 0xcccccccc) >> 2) | ((b & 0x33333333) << 2));
546 b = (((b & 0xf0f0f0f0) >> 4) | ((b & 0x0f0f0f0f) << 4));
547 b = (((b & 0xff00ff00) >> 8) | ((b & 0x00ff00ff) << 8));
548 b = ((b >> 16) | (b << 16)) >> (32 - m);
549 if (b > a) {
550 Complex t = samples[a];
551 samples[a] = samples[b];
552 samples[b] = t;
553 }
554 }
555}
556
558 Real delta = theta2 - theta1;
559 Real f1_real = f2.real() * cos(delta) - f2.imag() * sin(delta);
560 Real f1_imag = f2.real() * sin(delta) + f2.imag() * cos(delta);
561 return Complex(f1_real, f1_imag);
562}
563
565 return parkTransformMatrixPowerInvariant(theta) * fabc;
566}
567
569 Matrix transform = Matrix::Zero(2, 3);
570
571 const Real k = std::sqrt(2.0 / 3.0);
572
573 transform << k * std::cos(theta), k * std::cos(theta - 2.0 * M_PI / 3.0),
574 k * std::cos(theta + 2.0 * M_PI / 3.0), -k * std::sin(theta),
575 -k * std::sin(theta - 2.0 * M_PI / 3.0),
576 -k * std::sin(theta + 2.0 * M_PI / 3.0);
577
578 return transform;
579}
580
584
586 Matrix transform = Matrix::Zero(3, 2);
587
588 const Real k = std::sqrt(2.0 / 3.0);
589
590 transform << k * std::cos(theta), -k * std::sin(theta),
591 k * std::cos(theta - 2.0 * M_PI / 3.0),
592 -k * std::sin(theta - 2.0 * M_PI / 3.0),
593 k * std::cos(theta + 2.0 * M_PI / 3.0),
594 -k * std::sin(theta + 2.0 * M_PI / 3.0);
595
596 return transform;
597}
static void clearSparseMatrixValueCache(SparseMatrixRow &mat)
static Complex polar(Real abs, Real phase)
Definition MathUtils.cpp:99
static std::pair< Real, Real > pccPowerFromFilterPowerReference(Real pFilterRef, Real qFilterRef, Real rc, Real vGridRmsLL)
static Matrix singlePhasePowerToThreePhase(Real power)
To convert single phase power to symmetrical three phase.
static Complex polarDeg(Real abs, Real phase)
static Matrix StateSpaceEuler(Matrix states, Matrix A, Matrix B, Real dt, Matrix u)
static Matrix StateSpaceTrapezoidalNoCopy(const Matrix &states, const Matrix &A, const Matrix &B, Real dt, const Matrix &u_new, const Matrix &u_old)
static Complex complexFromVectorElement(const Matrix &mat, Matrix::Index row, Int maxFreq=1, Int freqIdx=0)
static Real degToRad(Real deg)
Definition MathUtils.cpp:65
static Real realFromVectorElement(const Matrix &mat, Matrix::Index row)
static void calculateStateSpaceTrapezoidalMatrices(const Matrix &A, const Matrix &B, const Matrix &C, const Real &dt, Matrix &Ad, Matrix &Bd, Matrix &Cd)
Calculate the discretized state space matrices Ad, Bd, Cd using trapezoidal rule.
static void setVectorElement(Matrix &mat, Matrix::Index row, Complex value, Int maxFreq=1, Int freqIdx=0, Matrix::Index colOffset=0)
static Bool zeroSkippingEnabled()
Definition MathUtils.cpp:60
static void addToVectorElement(Matrix &mat, Matrix::Index row, Complex value, Int maxFreq=1, Int freqIdx=0)
static Complex rotatingFrame2to1(Complex f2, Real theta1, Real theta2)
static Matrix inverseParkTransformMatrixPowerInvariant(Real theta)
static Real phaseDeg(Complex value)
Definition MathUtils.cpp:69
static Real phase(Complex value)
Definition MathUtils.cpp:67
static void setMatrixElement(SparseMatrixRow &mat, Matrix::Index row, Matrix::Index column, Complex value, Int maxFreq=1, Int freqIdx=0)
static Matrix parkTransformPowerInvariant(Real theta, const Matrix &fabc)
static Matrix applyStateSpaceTrapezoidalMatrices(const Matrix &Ad, const Matrix &Bd, const Matrix &Cd, const Matrix &statesPrevStep, const Matrix &inputCurrStep, const Matrix &inputPrevStep)
Apply the trapezoidal based state space matrices Ad, Bd, Cd to get the states at the current time ste...
static Matrix StateSpaceEulerNoCopy(const Matrix &states, const Matrix &A, const Matrix &B, Real dt, const Matrix &u)
static void prepareSparseMatrixValueCache(SparseMatrixRow &mat)
static Matrix singlePhaseParameterToThreePhase(Real parameter)
To convert single phase parameters to symmetrical three phase ones.
static bool isFinite(Real value)
static Real abs(Complex value)
Definition MathUtils.cpp:71
static void addToMatrixElement(SparseMatrixRow &mat, Matrix::Index row, Matrix::Index column, Complex value, Int maxFreq=1, Int freqIdx=0)
static void invertMatrix(const Matrix &mat, Matrix &matInv)
static Matrix inverseParkTransformPowerInvariant(Real theta, const Matrix &fdq)
static Matrix parkTransformMatrixPowerInvariant(Real theta)
static void FFT(std::vector< Complex > &samples)
static Real radtoDeg(Real rad)
Definition MathUtils.cpp:63
static MatrixComp singlePhaseVariableToThreePhase(Complex var_1ph)
To convert single phase complex variables (voltages, currents) to symmetrical three phase ones.
static Matrix StateSpaceTrapezoidal(Matrix states, Matrix A, Matrix B, Real dt, Matrix u_new, Matrix u_old)
#define PI
Definition Definitions.h:43
#define RMS3PH_TO_PEAK1PH
Definition Definitions.h:50
#define SHIFT_TO_PHASE_C
Definition Definitions.h:47
#define M_PI
Definition Definitions.h:41
#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
Eigen::SparseMatrix< Complex, Eigen::RowMajor > SparseMatrixCompRow
Sparse matrix for complex numbers (row major).
Definition Definitions.h:76
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
Eigen::SparseMatrix< Real, Eigen::RowMajor > SparseMatrixRow
Sparse matrix for real numbers (row major).
Definition Definitions.h:72