20 #ifndef LIBMESH_DENSE_MATRIX_H 21 #define LIBMESH_DENSE_MATRIX_H 28 #if (LIBMESH_HAVE_PETSC) 30 # include <petscsys.h> 41 template <
typename T>
class DenseVector;
62 const unsigned int new_n=0);
74 virtual void zero()
override;
80 const unsigned int j)
const;
86 const unsigned int j);
88 virtual T
el(
const unsigned int i,
89 const unsigned int j)
const override 90 {
return (*
this)(i,j); }
92 virtual T &
el(
const unsigned int i,
93 const unsigned int j)
override 94 {
return (*
this)(i,j); }
101 template <
typename T2>
109 template <
typename T2>
124 template <
typename T2>
140 template <
typename T2>
157 template <
typename T2,
typename T3>
200 template <
typename T2>
212 void resize(
const unsigned int new_m,
213 const unsigned int new_n);
218 void scale (
const T factor);
223 void scale_column (
const unsigned int col,
const T factor);
237 template<
typename T2,
typename T3>
307 template <
typename T2>
320 template <
typename T2>
327 const unsigned int j)
const;
355 const unsigned int j,
379 template <
typename T2>
427 Real rcond=std::numeric_limits<Real>::epsilon())
const;
565 template <
typename T2>
645 std::vector<Real> & sigma_val,
646 std::vector<Number> & U_val,
647 std::vector<Number> & VT_val);
667 #if (LIBMESH_HAVE_PETSC && LIBMESH_USE_REAL_NUMBERS) 701 bool trans=
false)
const;
712 namespace DenseMatrices
734 using namespace DenseMatrices;
745 const unsigned int new_n) :
747 #
if defined(LIBMESH_HAVE_PETSC) && defined(LIBMESH_USE_REAL_NUMBERS) && defined(LIBMESH_DEFAULT_DOUBLE_PRECISION)
748 use_blas_lapack(true),
750 use_blas_lapack(false),
753 _decomposition_type(NONE)
755 this->resize(new_m,new_n);
766 _val.swap(other_matrix.
_val);
773 template <
typename T>
774 template <
typename T2>
779 unsigned int mat_m = mat.
m(), mat_n = mat.
n();
780 this->resize(mat_m, mat_n);
781 for (
unsigned int i=0; i<mat_m; i++)
782 for (
unsigned int j=0; j<mat_n; j++)
783 (*
this)(i,j) = mat(i,j);
793 const unsigned int new_n)
810 _decomposition_type = NONE;
812 std::fill (_val.begin(), _val.end(),
static_cast<T
>(0));
820 const unsigned int j)
const 822 libmesh_assert_less (i*j, _val.size());
823 libmesh_assert_less (i, this->_m);
824 libmesh_assert_less (j, this->_n);
828 return _val[(i)*(this->_n) + (j)];
836 const unsigned int j)
838 libmesh_assert_less (i*j, _val.size());
839 libmesh_assert_less (i, this->_m);
840 libmesh_assert_less (j, this->_n);
843 return _val[(i)*(this->_n) + (j)];
854 for (std::size_t i=0; i<_val.size(); i++)
863 for (
unsigned int i=0; i<this->m(); i++)
864 (*
this)(i, col) *= factor;
880 template<
typename T2,
typename T3>
887 libmesh_assert_equal_to (this->m(), mat.
m());
888 libmesh_assert_equal_to (this->n(), mat.
n());
890 for (
unsigned int i=0; i<this->m(); i++)
891 for (
unsigned int j=0; j<this->n(); j++)
892 (*
this)(i,j) += factor * mat(i,j);
901 for (std::size_t i=0; i<_val.size(); i++)
902 if (_val[i] != mat.
_val[i])
914 for (std::size_t i=0; i<_val.size(); i++)
915 if (_val[i] != mat.
_val[i])
927 for (std::size_t i=0; i<_val.size(); i++)
928 _val[i] += mat.
_val[i];
939 for (std::size_t i=0; i<_val.size(); i++)
940 _val[i] -= mat.
_val[i];
951 libmesh_assert (this->_m);
952 libmesh_assert (this->_n);
955 for (
unsigned int i=0; i!=this->_m; i++)
957 for (
unsigned int j=0; j!=this->_n; j++)
960 my_min = (my_min < current? my_min : current);
972 libmesh_assert (this->_m);
973 libmesh_assert (this->_n);
976 for (
unsigned int i=0; i!=this->_m; i++)
978 for (
unsigned int j=0; j!=this->_n; j++)
981 my_max = (my_max > current? my_max : current);
993 libmesh_assert (this->_m);
994 libmesh_assert (this->_n);
997 for (
unsigned int i=0; i!=this->_m; i++)
999 columnsum +=
std::abs((*
this)(i,0));
1001 Real my_max = columnsum;
1002 for (
unsigned int j=1; j!=this->_n; j++)
1005 for (
unsigned int i=0; i!=this->_m; i++)
1007 columnsum +=
std::abs((*
this)(i,j));
1009 my_max = (my_max > columnsum? my_max : columnsum);
1016 template<
typename T>
1020 libmesh_assert (this->_m);
1021 libmesh_assert (this->_n);
1024 for (
unsigned int j=0; j!=this->_n; j++)
1028 Real my_max = rowsum;
1029 for (
unsigned int i=1; i!=this->_m; i++)
1032 for (
unsigned int j=0; j!=this->_n; j++)
1036 my_max = (my_max > rowsum? my_max : rowsum);
1043 template<
typename T>
1046 const unsigned int j)
const 1049 return (*
this)(j,i);
1092 #endif // LIBMESH_DENSE_MATRIX_H
void _lu_back_substitute(const DenseVector< T > &b, DenseVector< T > &x) const
void _lu_decompose_lapack()
virtual T & el(const unsigned int i, const unsigned int j) override
T transpose(const unsigned int i, const unsigned int j) const
void swap(DenseMatrix< T > &other_matrix)
void condense(const unsigned int i, const unsigned int j, const T val, DenseVector< T > &rhs)
void _evd_lapack(DenseVector< T > &lambda_real, DenseVector< T > &lambda_imag, DenseMatrix< T > *VL=nullptr, DenseMatrix< T > *VR=nullptr)
DenseMatrix< Complex > ComplexDenseMatrix
DenseMatrix< T > & operator+=(const DenseMatrix< T > &mat)
DecompositionType _decomposition_type
void evd_left(DenseVector< T > &lambda_real, DenseVector< T > &lambda_imag, DenseMatrix< T > &VL)
if(!eq) SETERRQ2(((PetscObject) dm) -> comm, PETSC_ERR_ARG_WRONG, "DM of type %s, not of type %s",((PetscObject) dm) ->type, DMLIBMESH)
virtual ~DenseMatrix()=default
void evd_left_and_right(DenseVector< T > &lambda_real, DenseVector< T > &lambda_imag, DenseMatrix< T > &VL, DenseMatrix< T > &VR)
void _lu_back_substitute_lapack(const DenseVector< T > &b, DenseVector< T > &x)
DenseMatrix< T > & operator-=(const DenseMatrix< T > &mat)
void _svd_lapack(DenseVector< Real > &sigma)
T operator()(const unsigned int i, const unsigned int j) const
long double max(long double a, double b)
virtual T el(const unsigned int i, const unsigned int j) const override
DenseMatrix(const unsigned int new_m=0, const unsigned int new_n=0)
const std::vector< T > & get_values() const
void outer_product(const DenseVector< T > &a, const DenseVector< T > &b)
void vector_mult_transpose(DenseVector< T > &dest, const DenseVector< T > &arg) const
void scale_column(const unsigned int col, const T factor)
void _svd_solve_lapack(const DenseVector< T > &rhs, DenseVector< T > &x, Real rcond) const
void _multiply_blas(const DenseMatrixBase< T > &other, _BLAS_Multiply_Flag flag)
bool operator!=(const variant_filter_iterator< Predicate, Type, ReferenceType, PointerType > &x, const variant_filter_iterator< Predicate, Type, ReferenceType, PointerType > &y)
void _svd_helper(char JOBU, char JOBVT, std::vector< Real > &sigma_val, std::vector< Number > &U_val, std::vector< Number > &VT_val)
DenseMatrix & operator=(const DenseMatrix &)=default
void vector_mult_add(DenseVector< T > &dest, const T factor, const DenseVector< T > &arg) const
void svd(DenseVector< Real > &sigma)
void get_transpose(DenseMatrix< T > &dest) const
boostcopy::enable_if_c< ScalarTraits< T2 >::value, void >::type add(const T2 factor, const DenseMatrix< T3 > &mat)
virtual void right_multiply(const DenseMatrixBase< T > &M2) override
DenseMatrix< Real > RealDenseMatrix
void evd_right(DenseVector< T > &lambda_real, DenseVector< T > &lambda_imag, DenseMatrix< T > &VR)
void _cholesky_back_substitute(const DenseVector< T2 > &b, DenseVector< T2 > &x) const
void _cholesky_decompose()
void get_principal_submatrix(unsigned int sub_m, unsigned int sub_n, DenseMatrix< T > &dest) const
std::vector< T > & get_values()
bool operator==(const DenseMatrix< T > &mat) const
void right_multiply_transpose(const DenseMatrix< T > &A)
void scale(const T factor)
void lu_solve(const DenseVector< T > &b, DenseVector< T > &x)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void evd(DenseVector< T > &lambda_real, DenseVector< T > &lambda_imag)
void left_multiply_transpose(const DenseMatrix< T > &A)
static PetscErrorCode Mat * A
virtual void zero() override
void swap(Iterator &lhs, Iterator &rhs)
void _matvec_blas(T alpha, T beta, DenseVector< T > &dest, const DenseVector< T > &arg, bool trans=false) const
void resize(const unsigned int new_m, const unsigned int new_n)
bool operator==(const variant_filter_iterator< Predicate, Type, ReferenceType, PointerType > &x, const variant_filter_iterator< Predicate, Type, ReferenceType, PointerType > &y)
Iterator & operator=(const Iterator &rhs)
virtual void left_multiply(const DenseMatrixBase< T > &M2) override
void cholesky_solve(const DenseVector< T2 > &b, DenseVector< T2 > &x)
DenseMatrix< T > & operator*=(const T factor)
bool operator!=(const DenseMatrix< T > &mat) const
A matrix object used for finite element assembly and numerics.
std::vector< pivot_index_t > _pivots
long double min(long double a, double b)
void svd_solve(const DenseVector< T > &rhs, DenseVector< T > &x, Real rcond=std::numeric_limits< Real >::epsilon()) const
PetscBLASInt pivot_index_t
void condense(const unsigned int i, const unsigned int j, const T val, DenseVectorBase< T > &rhs)
void vector_mult(DenseVector< T > &dest, const DenseVector< T > &arg) const