Skip to content

Commit

Permalink
style review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
qaumann committed Apr 30, 2020
1 parent 8618937 commit 30b50c0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,29 +104,29 @@ namespace { // helpers namespace
KRATOS_WARNING_IF("FeastEigensystemSolver", mOrder == "si") << "Attempting to sort by imaginary value. Falling back on \"sr\"" << std::endl;
KRATOS_WARNING_IF("FeastEigensystemSolver", mOrder == "li") << "Attempting to sort by imaginary value. Falling back on \"lr\"" << std::endl;

std::vector<size_t> idx(rEigenvalues.size());
std::vector<std::size_t> idx(rEigenvalues.size());
std::iota(idx.begin(), idx.end(), 0);

if( mOrder == "sr" || mOrder == "si" ) {
std::stable_sort(idx.begin(), idx.end(),
[&rEigenvalues](size_t i1, size_t i2) {return rEigenvalues[i1] < rEigenvalues[i2];});
[&rEigenvalues](std::size_t i1, std::size_t i2) {return rEigenvalues[i1] < rEigenvalues[i2];});
} else if( mOrder == "sm") {
std::stable_sort(idx.begin(), idx.end(),
[&rEigenvalues](size_t i1, size_t i2) {return std::abs(rEigenvalues[i1]) < std::abs(rEigenvalues[i2]);});
[&rEigenvalues](std::size_t i1, std::size_t i2) {return std::abs(rEigenvalues[i1]) < std::abs(rEigenvalues[i2]);});
} else if( mOrder == "lr" || mOrder == "li" ) {
std::stable_sort(idx.begin(), idx.end(),
[&rEigenvalues](size_t i1, size_t i2) {return rEigenvalues[i1] > rEigenvalues[i2];});
[&rEigenvalues](std::size_t i1, std::size_t i2) {return rEigenvalues[i1] > rEigenvalues[i2];});
} else if( mOrder == "lm") {
std::stable_sort(idx.begin(), idx.end(),
[&rEigenvalues](size_t i1, size_t i2) {return std::abs(rEigenvalues[i1]) > std::abs(rEigenvalues[i2]);});
[&rEigenvalues](std::size_t i1, std::size_t i2) {return std::abs(rEigenvalues[i1]) > std::abs(rEigenvalues[i2]);});
} else {
KRATOS_ERROR << "Invalid sort type. Allowed are sr, sm, si, lr, lm, li" << std::endl;
}

VectorType tmp_eigenvalues(rEigenvalues.size());
MatrixType tmp_eigenvectors(rEigenvectors.size1(), rEigenvectors.size2());

for( size_t i=0; i<rEigenvalues.size(); ++i ) {
for( std::size_t i=0; i<rEigenvalues.size(); ++i ) {
tmp_eigenvalues[i] = rEigenvalues[idx[i]];
column(tmp_eigenvectors, i).swap(column(rEigenvectors, idx[i]));
}
Expand All @@ -137,36 +137,35 @@ namespace { // helpers namespace
template<> template<typename MatrixType, typename VectorType>
void SortingHelper<std::complex<double>>::SortEigenvalues(VectorType &rEigenvalues, MatrixType &rEigenvectors)
{
std::vector<size_t> idx(rEigenvalues.size());
std::vector<std::size_t> idx(rEigenvalues.size());
std::iota(idx.begin(), idx.end(), 0);

// const std::string t = mParam["sort_order"].GetString();
if( mOrder == "sr" ) {
std::stable_sort(idx.begin(), idx.end(),
[&rEigenvalues](size_t i1, size_t i2) {return std::real(rEigenvalues[i1]) < std::real(rEigenvalues[i2]);});
[&rEigenvalues](std::size_t i1, std::size_t i2) {return std::real(rEigenvalues[i1]) < std::real(rEigenvalues[i2]);});
} else if( mOrder == "sm") {
std::stable_sort(idx.begin(), idx.end(),
[&rEigenvalues](size_t i1, size_t i2) {return std::abs(rEigenvalues[i1]) < std::abs(rEigenvalues[i2]);});
[&rEigenvalues](std::size_t i1, std::size_t i2) {return std::abs(rEigenvalues[i1]) < std::abs(rEigenvalues[i2]);});
} else if( mOrder == "si") {
std::stable_sort(idx.begin(), idx.end(),
[&rEigenvalues](size_t i1, size_t i2) {return std::imag(rEigenvalues[i1]) < std::imag(rEigenvalues[i2]);});
[&rEigenvalues](std::size_t i1, std::size_t i2) {return std::imag(rEigenvalues[i1]) < std::imag(rEigenvalues[i2]);});
} else if( mOrder == "lr" ) {
std::stable_sort(idx.begin(), idx.end(),
[&rEigenvalues](size_t i1, size_t i2) {return std::real(rEigenvalues[i1]) > std::real(rEigenvalues[i2]);});
[&rEigenvalues](std::size_t i1, std::size_t i2) {return std::real(rEigenvalues[i1]) > std::real(rEigenvalues[i2]);});
} else if( mOrder == "lm") {
std::stable_sort(idx.begin(), idx.end(),
[&rEigenvalues](size_t i1, size_t i2) {return std::abs(rEigenvalues[i1]) > std::abs(rEigenvalues[i2]);});
[&rEigenvalues](std::size_t i1, std::size_t i2) {return std::abs(rEigenvalues[i1]) > std::abs(rEigenvalues[i2]);});
} else if( mOrder == "li") {
std::stable_sort(idx.begin(), idx.end(),
[&rEigenvalues](size_t i1, size_t i2) {return std::imag(rEigenvalues[i1]) > std::imag(rEigenvalues[i2]);});
[&rEigenvalues](std::size_t i1, std::size_t i2) {return std::imag(rEigenvalues[i1]) > std::imag(rEigenvalues[i2]);});
} else {
KRATOS_ERROR << "Invalid sort type. Allowed are sr, sm, si, lr, lm, li" << std::endl;
}

VectorType tmp_eigenvalues(rEigenvalues.size());
MatrixType tmp_eigenvectors(rEigenvectors.size1(), rEigenvectors.size2());

for( size_t i=0; i<rEigenvalues.size(); ++i ) {
for( std::size_t i=0; i<rEigenvalues.size(); ++i ) {
tmp_eigenvalues[i] = rEigenvalues[idx[i]];
column(tmp_eigenvectors, i).swap(column(rEigenvectors, idx[i]));
}
Expand Down Expand Up @@ -271,14 +270,14 @@ class FEASTEigensystemSolver
{
// settings
const std::size_t system_size = rK.size1();
size_t subspace_size;
std::size_t subspace_size;

if( mParam["search_lowest_eigenvalues"].GetBool() || mParam["search_highest_eigenvalues"].GetBool() ) {
subspace_size = 2 * static_cast<size_t>(mParam["number_of_eigenvalues"].GetInt());
subspace_size = 2 * static_cast<std::size_t>(mParam["number_of_eigenvalues"].GetInt());
} else if( mParam["subspace_size"].GetInt() == 0 ) {
subspace_size = 1.5 * static_cast<size_t>(mParam["number_of_eigenvalues"].GetInt());
subspace_size = 1.5 * static_cast<std::size_t>(mParam["number_of_eigenvalues"].GetInt());
} else {
subspace_size = static_cast<size_t>(mParam["subspace_size"].GetInt());
subspace_size = static_cast<std::size_t>(mParam["subspace_size"].GetInt());
}

// create column based matrix for the fortran routine
Expand Down
20 changes: 4 additions & 16 deletions kratos/python_scripts/eigen_solver_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,8 @@ def ConstructSolver(settings):
if kratos_utils.CheckIfApplicationsAvailable("EigenSolversApplication"):
import KratosMultiphysics.EigenSolversApplication as EiSA
if EiSA.HasFEAST():
if settings.Has("symmetric"):
is_symmetric = settings["symmetric"].GetBool()
else:
is_symmetric = True
if is_symmetric:
eigen_solver = EiSA.FEASTSymmetricEigensystemSolver(settings)
else:
eigen_solver = EiSA.FEASTGeneralEigensystemSolver(settings)
is_symmetric = settings["symmetric"].GetBool() if settings.Has("symmetric") else True
eigen_solver = EiSA.FEASTSymmetricEigensystemSolver(settings) if is_symmetric else EiSA.FEASTGeneralEigensystemSolver(settings)
return eigen_solver
else:
raise Exception("FEAST not available in EigenSolversApplication")
Expand All @@ -40,14 +34,8 @@ def ConstructSolver(settings):
if kratos_utils.CheckIfApplicationsAvailable("EigenSolversApplication"):
import KratosMultiphysics.EigenSolversApplication as EiSA
if EiSA.HasFEAST():
if settings.Has("symmetric"):
is_symmetric = settings["symmetric"].GetBool()
else:
is_symmetric = True
if is_symmetric:
eigen_solver = EiSA.ComplexFEASTSymmetricEigensystemSolver(settings)
else:
eigen_solver = EiSA.ComplexFEASTGeneralEigensystemSolver(settings)
is_symmetric = settings["symmetric"].GetBool() if settings.Has("symmetric") else True
eigen_solver = EiSA.ComplexFEASTSymmetricEigensystemSolver(settings) if is_symmetric else EiSA.ComplexFEASTGeneralEigensystemSolver(settings)
return eigen_solver
else:
raise Exception("FEAST not available in EigenSolversApplication")
Expand Down

0 comments on commit 30b50c0

Please sign in to comment.