13 #if !defined(KRATOS_EIGEN_DENSE_JACOBI_SVD_H_INCLUDED)
14 #define KRATOS_EIGEN_DENSE_JACOBI_SVD_H_INCLUDED
46 template<
class TDenseSpace>
57 typedef typename TDenseSpace::DataType
DataType;
82 return "dense_jacobi_singular_value_decomposition";
94 "compute_thin_u" : true,
95 "compute_thin_v" : true
100 int decomposition_options = 0;
101 if (Settings[
"compute_u"].GetBool()) {
102 decomposition_options |= Settings[
"compute_thin_u"].
GetBool() ? Eigen::ComputeThinU : Eigen::ComputeFullU;
104 if (Settings[
"compute_v"].GetBool()) {
105 decomposition_options |= Settings[
"compute_thin_v"].
GetBool() ? Eigen::ComputeThinV : Eigen::ComputeFullV;
109 Eigen::Map<EigenMatrix> eigen_input_matrix_map(rInputMatrix.data().begin(), rInputMatrix.size1(), rInputMatrix.size2());
110 mJacobiSVD.compute(eigen_input_matrix_map, decomposition_options);
120 Compute(rInputMatrix, Settings);
128 KRATOS_ERROR_IF_NOT(mJacobiSVD.computeU()) <<
"Matrix U has not been computed. Switch \'compute_u\' to \'true\' in the \'Compute\' input settings." << std::endl;
130 const auto& r_matrix_U = mJacobiSVD.matrixU();
131 const std::size_t
m = r_matrix_U.rows();
132 const std::size_t
n = r_matrix_U.cols();
133 if (rMatrixU.size1() !=
m || rMatrixU.size2() !=
n) {
134 rMatrixU.resize(
m,
n);
137 Eigen::Map<EigenMatrix> matrix_u_map(rMatrixU.data().begin(), rMatrixU.size1(), rMatrixU.size2());
138 matrix_u_map = r_matrix_U;
143 KRATOS_ERROR_IF_NOT(mJacobiSVD.computeV()) <<
"Matrix V has not been computed. Switch \'compute_v\' to \'true\' in the \'Compute\' input settings." << std::endl;
145 const auto& r_matrix_V = mJacobiSVD.matrixV();
146 const std::size_t
m = r_matrix_V.rows();
147 const std::size_t
n = r_matrix_V.cols();
148 if (rMatrixV.size1() !=
m || rMatrixV.size2() !=
n) {
149 rMatrixV.resize(
m,
n);
152 Eigen::Map<EigenMatrix> matrix_v_map(rMatrixV.data().begin(), rMatrixV.size1(), rMatrixV.size2());
153 matrix_v_map = r_matrix_V;
158 const auto& r_vector_S = mJacobiSVD.singularValues();
159 const std::size_t
m = r_vector_S.rows();
160 if (rVectorS.size() !=
m) {
164 Eigen::Map<EigenVector> vector_s_map(rVectorS.data().begin(), rVectorS.size());
165 vector_s_map = r_vector_S;
170 return mJacobiSVD.nonzeroSingularValues();
175 mJacobiSVD.setThreshold(RelTolerance);
180 return mJacobiSVD.rank();
185 rOStream <<
"EigenDecomposition <" <<
Name() <<
"> finished.";
218 Eigen::JacobiSVD<EigenMatrix> mJacobiSVD;
Definition: dense_svd_decomposition.h:45
Definition: eigen_dense_jacobi_svd_decomposition.h:48
void SingularValues(VectorType &rVectorS) override
Definition: eigen_dense_jacobi_svd_decomposition.h:156
std::size_t Rank() override
Rank of the provided array Calculates and returns the rank of the array decomposed with the SVD.
Definition: eigen_dense_jacobi_svd_decomposition.h:178
TDenseSpace::MatrixType MatrixType
Definition: eigen_dense_jacobi_svd_decomposition.h:59
static std::string Name()
Definition: eigen_dense_jacobi_svd_decomposition.h:80
Kratos::EigenDynamicVector< DataType > EigenVector
Definition: eigen_dense_jacobi_svd_decomposition.h:61
EigenDenseJacobiSVD()=default
void SetThreshold(const double RelTolerance) override
Set the relative threshold tolerance This method sets the relative threshold tolerance to consider si...
Definition: eigen_dense_jacobi_svd_decomposition.h:173
std::size_t NonZeroSingularValues() override
Number of non-zero singular values This method returns the number of non-zero singular values.
Definition: eigen_dense_jacobi_svd_decomposition.h:168
KRATOS_CLASS_POINTER_DEFINITION(EigenDenseJacobiSVD)
Definition of the shared pointer of the class.
void MatrixU(MatrixType &rMatrixU) override
Definition: eigen_dense_jacobi_svd_decomposition.h:126
Kratos::EigenDynamicMatrix< DataType > EigenMatrix
Definition: eigen_dense_jacobi_svd_decomposition.h:62
TDenseSpace::VectorType VectorType
Definition: eigen_dense_jacobi_svd_decomposition.h:58
void MatrixV(MatrixType &rMatrixV) override
Definition: eigen_dense_jacobi_svd_decomposition.h:141
void PrintInfo(std::ostream &rOStream) const override
SVD information Outputs the SVD class information.
Definition: eigen_dense_jacobi_svd_decomposition.h:183
Eigen::DecompositionOptions DecompositionOptions
Definition: eigen_dense_jacobi_svd_decomposition.h:63
void Compute(MatrixType &rInputMatrix, VectorType &rVectorS, MatrixType &rMatrixU, MatrixType &rMatrixV, Parameters Settings) override
Definition: eigen_dense_jacobi_svd_decomposition.h:113
void Compute(MatrixType &rInputMatrix, Parameters Settings) override
Definition: eigen_dense_jacobi_svd_decomposition.h:85
TDenseSpace::DataType DataType
Definition: eigen_dense_jacobi_svd_decomposition.h:57
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
void ValidateAndAssignDefaults(const Parameters &rDefaultParameters)
This function is designed to verify that the parameters under testing match the form prescribed by th...
Definition: kratos_parameters.cpp:1306
bool GetBool() const
This method returns the boolean contained in the current Parameter.
Definition: kratos_parameters.cpp:675
#define KRATOS_ERROR_IF_NOT(conditional)
Definition: exception.h:163
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
Eigen::Matrix< _Scalar, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > EigenDynamicMatrix
Definition: linear_solvers_define.h:32
Eigen::Matrix< _Scalar, Eigen::Dynamic, 1 > EigenDynamicVector
Definition: linear_solvers_define.h:33
int n
manufactured solution and derivatives (u=0 at z=0 dudz=0 at z=domain_height)
Definition: ode_solve.py:402
int m
Definition: run_marine_rain_substepping.py:8