-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a separate EigenvalueUtils class
Signed-off-by: Georgii Tishenin <[email protected]>
- Loading branch information
1 parent
6015122
commit bf1fd55
Showing
7 changed files
with
63 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
|
||
#include <dpsim/Definitions.h> | ||
|
||
namespace DPsim { | ||
class EigenvalueUtils { | ||
public: | ||
static MatrixComp returnNonZeroElements(const MatrixComp &mat); | ||
|
||
static MatrixComp | ||
convertRealEquivalentToComplexMatrix(const Matrix &realEquivalentMatrix); | ||
}; | ||
|
||
} // namespace DPsim |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include <dpsim/EigenvalueUtils.h> | ||
|
||
using namespace DPsim; | ||
|
||
// TODO: consider resizing existing matrix instead of creating a new one (performance, memory) | ||
MatrixComp EigenvalueUtils::returnNonZeroElements(const MatrixComp &mat) { | ||
Eigen::Matrix<bool, Eigen::Dynamic, Eigen::Dynamic> mask = | ||
(mat.array().abs() > 1e-14); | ||
int nonZeroCount = mask.cast<int>().sum(); | ||
|
||
Eigen::MatrixXcd nonZeroMatrix(nonZeroCount, 1); | ||
int index = 0; | ||
for (int i = 0; i < mask.rows(); ++i) { | ||
for (int j = 0; j < mask.cols(); ++j) { | ||
if (mask(i, j)) { | ||
nonZeroMatrix(index++) = mat(i, j); | ||
} | ||
} | ||
} | ||
return nonZeroMatrix; | ||
} | ||
|
||
MatrixComp EigenvalueUtils::convertRealEquivalentToComplexMatrix( | ||
const Matrix &realEquivalentMatrix) { | ||
// The size of the complex matrix is half the size of the real matrix | ||
int size = realEquivalentMatrix.rows() / 2; | ||
|
||
// Create a complex matrix of the appropriate size | ||
MatrixComp complexMatrix(size, size); | ||
|
||
// Iterate over the complex matrix | ||
for (int i = 0; i < size; ++i) { | ||
for (int j = 0; j < size; ++j) { | ||
// The real part is in the upper left quadrant of the real matrix | ||
double realPart = realEquivalentMatrix(i, j); | ||
|
||
// The imaginary part is in the lower left quadrant of the real matrix | ||
double imagPart = realEquivalentMatrix(i + size, j); | ||
|
||
// Assign the complex number to the complex matrix | ||
complexMatrix(i, j) = std::complex<double>(realPart, imagPart); | ||
} | ||
} | ||
return complexMatrix; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters