13 #if !defined(KRATOS_FEAST_CONDITION_NUMBER_UTILITY )
14 #define KRATOS_FEAST_CONDITION_NUMBER_UTILITY
23 #ifdef USE_EIGEN_FEAST
53 template<
class TSparseSpace = UblasSpace<
double, CompressedMatrix, Vector>,
54 class TDenseSpace = UblasSpace<
double, Matrix, Vector>
99 #ifdef USE_EIGEN_FEAST
104 "solver_type" : "feast",
106 "number_of_eigenvalues" : 3,
107 "search_lowest_eigenvalues" : true,
108 "search_highest_eigenvalues" : false,
114 const std::size_t size_matrix = InputMatrix.size1();
125 identity_matrix.push_back(
i,
i, 1.0);
132 FEASTSolverType feast_solver_lowest(this_params);
135 feast_solver_lowest.Solve(copy_matrix, identity_matrix, eigen_values, eigen_vectors);
138 int dim_eigen_values = eigen_values.size();
141 #pragma omp parallel for
142 for (
int i = 0;
i < dim_eigen_values;
i++) {
143 eigen_values[
i] = std::abs(eigen_values[
i]);
147 std::sort(eigen_values.begin(), eigen_values.end());
149 const double lowest_eigen_value = eigen_values[0];
152 this_params[
"search_lowest_eigenvalues"].
SetBool(
false);
153 this_params[
"search_highest_eigenvalues"].
SetBool(
true);
154 FEASTSolverType feast_solver_highest(this_params);
157 copy_matrix = InputMatrix;
158 feast_solver_highest.Solve(copy_matrix, identity_matrix, eigen_values, eigen_vectors);
161 dim_eigen_values = eigen_values.size();
164 #pragma omp parallel for
165 for (
int i = 0;
i < dim_eigen_values;
i++) {
166 eigen_values[
i] = std::abs(eigen_values[
i]);
170 std::sort(eigen_values.begin(), eigen_values.end());
172 const double highest_eigen_value = eigen_values[dim_eigen_values - 1];
175 const double condition_number = highest_eigen_value/lowest_eigen_value;
177 const double condition_number = 0.0;
178 KRATOS_ERROR <<
"YOU MUST COMPILE FEAST IN ORDER TO USE THIS UTILITY" << std::endl;
181 return condition_number;
This utility uses the FEAST solver to obtain (estimate) the the condition number of a regular matrix.
Definition: feast_condition_number_utility.h:57
TDenseSpace::MatrixType DenseMatrixType
Dense space.
Definition: feast_condition_number_utility.h:75
std::size_t SizeType
Indexes.
Definition: feast_condition_number_utility.h:67
TSparseSpace::VectorType SparseVectorType
Definition: feast_condition_number_utility.h:72
KRATOS_CLASS_POINTER_DEFINITION(FEASTConditionNumberUtility)
Definition of the shared pointer of the class.
TSparseSpace::MatrixType SparseMatrixType
Sparse space.
Definition: feast_condition_number_utility.h:71
static double GetConditionNumber(const SparseMatrixType &InputMatrix)
Computes the condition number using the maximum and minimum eigenvalue of the system (in moduli)
Definition: feast_condition_number_utility.h:97
TDenseSpace::VectorType DenseVectorType
Definition: feast_condition_number_utility.h:76
std::size_t IndexType
Definition: feast_condition_number_utility.h:68
Definition: feast_eigensystem_solver.h:185
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
void SetDouble(const double Value)
This method sets the double contained in the current Parameter.
Definition: kratos_parameters.cpp:787
void SetBool(const bool Value)
This method sets the bool contained in the current Parameter.
Definition: kratos_parameters.cpp:803
#define KRATOS_ERROR
Definition: exception.h:161
double TwoNorm(SparseSpaceType &dummy, SparseSpaceType::VectorType &x)
Definition: add_strategies_to_python.cpp:164
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
integer i
Definition: TensorModule.f:17