libMesh
dense_matrix.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2024 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_DENSE_MATRIX_H
21 #define LIBMESH_DENSE_MATRIX_H
22 
23 // Local Includes
24 #include "libmesh/libmesh_common.h"
25 #include "libmesh/dense_matrix_base.h"
26 #include "libmesh/int_range.h"
27 
28 // For the definition of PetscBLASInt.
29 #if (LIBMESH_HAVE_PETSC)
30 # include "libmesh/petsc_macro.h"
31 # ifdef I
32 # define LIBMESH_SAW_I
33 # endif
34 
35 #include "libmesh/ignore_warnings.h"
36 # include <petscsys.h>
37 #include "libmesh/restore_warnings.h"
38 
39 # ifndef LIBMESH_SAW_I
40 # undef I // Avoid complex.h contamination
41 # endif
42 #endif
43 
44 // C++ includes
45 #include <vector>
46 #include <algorithm>
47 #include <initializer_list>
48 
49 #ifdef LIBMESH_HAVE_METAPHYSICL
50 #include "metaphysicl/dualnumber_decl.h"
51 #include "metaphysicl/raw_type.h"
52 #endif
53 
54 namespace libMesh
55 {
56 
57 // Forward Declarations
58 template <typename T> class DenseVector;
59 
70 template<typename T>
71 class DenseMatrix : public DenseMatrixBase<T>
72 {
73 public:
74 
78  DenseMatrix(const unsigned int new_m=0,
79  const unsigned int new_n=0);
80 
86  template <typename T2>
87  DenseMatrix(unsigned int nrow,
88  unsigned int ncol,
89  std::initializer_list<T2> init_list);
90 
95  DenseMatrix (DenseMatrix &&) = default;
96  DenseMatrix (const DenseMatrix &) = default;
97  DenseMatrix & operator= (const DenseMatrix &) = default;
98  DenseMatrix & operator= (DenseMatrix &&) = default;
99  virtual ~DenseMatrix() = default;
100 
106  virtual void zero() override final;
107 
111  DenseMatrix sub_matrix(unsigned int row_id, unsigned int row_size,
112  unsigned int col_id, unsigned int col_size) const;
113 
117  T operator() (const unsigned int i,
118  const unsigned int j) const;
119 
123  T & operator() (const unsigned int i,
124  const unsigned int j);
125 
126  virtual T el(const unsigned int i,
127  const unsigned int j) const override final
128  { return (*this)(i,j); }
129 
130  virtual T & el(const unsigned int i,
131  const unsigned int j) override final
132  { return (*this)(i,j); }
133 
134  virtual void left_multiply (const DenseMatrixBase<T> & M2) override final;
135 
139  template <typename T2>
140  void left_multiply (const DenseMatrixBase<T2> & M2);
141 
142  virtual void right_multiply (const DenseMatrixBase<T> & M2) override final;
143 
147  template <typename T2>
148  void right_multiply (const DenseMatrixBase<T2> & M2);
149 
154  void vector_mult (DenseVector<T> & dest,
155  const DenseVector<T> & arg) const;
156 
162  template <typename T2>
164  const DenseVector<T2> & arg) const;
165 
171  const DenseVector<T> & arg) const;
172 
178  template <typename T2>
180  const DenseVector<T2> & arg) const;
181 
186  void vector_mult_add (DenseVector<T> & dest,
187  const T factor,
188  const DenseVector<T> & arg) const;
189 
195  template <typename T2, typename T3>
196  void vector_mult_add (DenseVector<typename CompareTypes<T, typename CompareTypes<T2,T3>::supertype>::supertype> & dest,
197  const T2 factor,
198  const DenseVector<T3> & arg) const;
199 
203  void get_principal_submatrix (unsigned int sub_m, unsigned int sub_n, DenseMatrix<T> & dest) const;
204 
208  void get_principal_submatrix (unsigned int sub_m, DenseMatrix<T> & dest) const;
209 
227  void outer_product(const DenseVector<T> & a, const DenseVector<T> & b);
228 
238  template <typename T2>
239  DenseMatrix<T> & operator = (const DenseMatrix<T2> & other_matrix);
240 
244  void swap(DenseMatrix<T> & other_matrix);
245 
253  void resize(const unsigned int new_m,
254  const unsigned int new_n);
255 
259  void scale (const T factor);
260 
264  void scale_column (const unsigned int col, const T factor);
265 
271  DenseMatrix<T> & operator *= (const T factor);
272 
278  template<typename T2, typename T3>
279  typename boostcopy::enable_if_c<
280  ScalarTraits<T2>::value, void >::type add (const T2 factor,
281  const DenseMatrix<T3> & mat);
282 
286  bool operator== (const DenseMatrix<T> & mat) const;
287 
291  bool operator!= (const DenseMatrix<T> & mat) const;
292 
299 
306 
311  auto min () const -> decltype(libmesh_real(T(0)));
312 
317  auto max () const -> decltype(libmesh_real(T(0)));
318 
327  auto l1_norm () const -> decltype(std::abs(T(0)));
328 
337  auto linfty_norm () const -> decltype(std::abs(T(0)));
338 
342  void left_multiply_transpose (const DenseMatrix<T> & A);
343 
348  template <typename T2>
349  void left_multiply_transpose (const DenseMatrix<T2> & A);
350 
351 
355  void right_multiply_transpose (const DenseMatrix<T> & A);
356 
361  template <typename T2>
362  void right_multiply_transpose (const DenseMatrix<T2> & A);
363 
367  T transpose (const unsigned int i,
368  const unsigned int j) const;
369 
373  void get_transpose(DenseMatrix<T> & dest) const;
374 
382  std::vector<T> & get_values() { return _val; }
383 
387  const std::vector<T> & get_values() const { return _val; }
388 
395  void condense(const unsigned int i,
396  const unsigned int j,
397  const T val,
398  DenseVector<T> & rhs)
399  { DenseMatrixBase<T>::condense (i, j, val, rhs); }
400 
415  void lu_solve (const DenseVector<T> & b,
416  DenseVector<T> & x);
417 
439  template <typename T2>
440  void cholesky_solve(const DenseVector<T2> & b,
441  DenseVector<T2> & x);
442 
451  void svd(DenseVector<Real> & sigma);
452 
464  void svd(DenseVector<Real> & sigma,
466  DenseMatrix<Number> & VT);
467 
485  void svd_solve(const DenseVector<T> & rhs,
486  DenseVector<T> & x,
487  Real rcond=std::numeric_limits<Real>::epsilon()) const;
488 
496  void evd(DenseVector<T> & lambda_real,
497  DenseVector<T> & lambda_imag);
498 
517  void evd_left(DenseVector<T> & lambda_real,
518  DenseVector<T> & lambda_imag,
519  DenseMatrix<T> & VL);
520 
539  void evd_right(DenseVector<T> & lambda_real,
540  DenseVector<T> & lambda_imag,
541  DenseMatrix<T> & VR);
542 
553  void evd_left_and_right(DenseVector<T> & lambda_real,
554  DenseVector<T> & lambda_imag,
555  DenseMatrix<T> & VL,
556  DenseMatrix<T> & VR);
557 
565  T det();
566 
578  // void inverse();
579 
586 
591  {
592  static const bool value = false;
593  };
594 
595 private:
596 
600  std::vector<T> _val;
601 
607  void _lu_decompose ();
608 
614  void _lu_back_substitute (const DenseVector<T> & b,
615  DenseVector<T> & x) const;
616 
624  void _cholesky_decompose();
625 
633  template <typename T2>
635  DenseVector<T2> & x) const;
636 
645 
651 
661  };
662 
670  void _multiply_blas(const DenseMatrixBase<T> & other,
671  _BLAS_Multiply_Flag flag);
672 
682  void _lu_decompose_lapack();
683 
689  void _svd_lapack(DenseVector<Real> & sigma);
690 
696  void _svd_lapack(DenseVector<Real> & sigma,
698  DenseMatrix<Number> & VT);
699 
703  void _svd_solve_lapack(const DenseVector<T> & rhs,
704  DenseVector<T> & x,
705  Real rcond) const;
706 
711  void _svd_helper (char JOBU,
712  char JOBVT,
713  std::vector<Real> & sigma_val,
714  std::vector<Number> & U_val,
715  std::vector<Number> & VT_val);
716 
725  void _evd_lapack(DenseVector<T> & lambda_real,
726  DenseVector<T> & lambda_imag,
727  DenseMatrix<T> * VL = nullptr,
728  DenseMatrix<T> * VR = nullptr);
729 
735 #if (LIBMESH_HAVE_PETSC && LIBMESH_USE_REAL_NUMBERS)
736  typedef PetscBLASInt pivot_index_t;
737 #else
738  typedef int pivot_index_t;
739 #endif
740  std::vector<pivot_index_t> _pivots;
741 
752  DenseVector<T> & x);
753 
766  void _matvec_blas(T alpha, T beta,
767  DenseVector<T> & dest,
768  const DenseVector<T> & arg,
769  bool trans=false) const;
770 
775  template <typename T2>
776  void _left_multiply_transpose (const DenseMatrix<T2> & A);
777 
782  template <typename T2>
784 };
785 
786 
787 
788 
789 
790 // ------------------------------------------------------------
794 namespace DenseMatrices
795 {
796 
802 
811 
812 }
813 
814 
815 
816 using namespace DenseMatrices;
817 
818 // The PETSc Lapack wrappers are only for PetscScalar, therefore we
819 // can't e.g. get a Lapack version of DenseMatrix<Real>::lu_solve()
820 // when libmesh/PETSc are compiled with complex numbers.
821 #if defined(LIBMESH_HAVE_PETSC) && \
822  defined(LIBMESH_USE_REAL_NUMBERS) && \
823  defined(LIBMESH_DEFAULT_DOUBLE_PRECISION)
824 template <>
825 struct DenseMatrix<double>::UseBlasLapack
826 {
827  static const bool value = true;
828 };
829 #endif
830 
831 
832 // ------------------------------------------------------------
833 // Dense Matrix member functions
834 template<typename T>
835 inline
836 DenseMatrix<T>::DenseMatrix(const unsigned int new_m,
837  const unsigned int new_n) :
838  DenseMatrixBase<T>(new_m,new_n),
839  use_blas_lapack(DenseMatrix<T>::UseBlasLapack::value),
840  _val(),
841  _decomposition_type(NONE)
842 {
843  this->resize(new_m,new_n);
844 }
845 
846 template <typename T>
847 template <typename T2>
848 DenseMatrix<T>::DenseMatrix(unsigned int nrow,
849  unsigned int ncol,
850  std::initializer_list<T2> init_list) :
851  DenseMatrixBase<T>(nrow, ncol),
852  use_blas_lapack(DenseMatrix<T>::UseBlasLapack::value),
853  _val(init_list.begin(), init_list.end()),
854  _decomposition_type(NONE)
855 {
856  // Make sure the user passed us an amount of data which is
857  // consistent with the size of the matrix.
858  libmesh_assert_equal_to(nrow * ncol, init_list.size());
859 }
860 
861 
862 
863 template<typename T>
864 inline
866 {
867  std::swap(this->_m, other_matrix._m);
868  std::swap(this->_n, other_matrix._n);
869  _val.swap(other_matrix._val);
870  DecompositionType _temp = _decomposition_type;
871  _decomposition_type = other_matrix._decomposition_type;
872  other_matrix._decomposition_type = _temp;
873 }
874 
875 
876 template <typename T>
877 template <typename T2>
878 inline
881 {
882  unsigned int mat_m = mat.m(), mat_n = mat.n();
883  this->resize(mat_m, mat_n);
884  for (unsigned int i=0; i<mat_m; i++)
885  for (unsigned int j=0; j<mat_n; j++)
886  (*this)(i,j) = mat(i,j);
887 
888  return *this;
889 }
890 
891 
892 
893 template<typename T>
894 inline
895 void DenseMatrix<T>::resize(const unsigned int new_m,
896  const unsigned int new_n)
897 {
898  _val.resize(new_m*new_n);
899 
900  this->_m = new_m;
901  this->_n = new_n;
902 
903  // zero and set decomposition_type to NONE
904  this->zero();
905 }
906 
907 
908 
909 template<typename T>
910 inline
912 {
913  _decomposition_type = NONE;
914 
915  std::fill (_val.begin(), _val.end(), static_cast<T>(0));
916 }
917 
918 
919 
920 template<typename T>
921 inline
922 DenseMatrix<T> DenseMatrix<T>::sub_matrix(unsigned int row_id, unsigned int row_size,
923  unsigned int col_id, unsigned int col_size) const
924 {
925  libmesh_assert_less (row_id + row_size - 1, this->_m);
926  libmesh_assert_less (col_id + col_size - 1, this->_n);
927 
928  DenseMatrix<T> sub;
929  sub._m = row_size;
930  sub._n = col_size;
931  sub._val.resize(row_size * col_size);
932 
933  unsigned int end_col = this->_n - col_size - col_id;
934  unsigned int p = row_id * this->_n;
935  unsigned int q = 0;
936  for (unsigned int i=0; i<row_size; i++)
937  {
938  // skip the beginning columns
939  p += col_id;
940  for (unsigned int j=0; j<col_size; j++)
941  sub._val[q++] = _val[p++];
942  // skip the rest columns
943  p += end_col;
944  }
945 
946  return sub;
947 }
948 
949 
950 
951 template<typename T>
952 inline
953 T DenseMatrix<T>::operator () (const unsigned int i,
954  const unsigned int j) const
955 {
956  libmesh_assert_less (i*j, _val.size());
957  libmesh_assert_less (i, this->_m);
958  libmesh_assert_less (j, this->_n);
959 
960 
961  // return _val[(i) + (this->_m)*(j)]; // col-major
962  return _val[(i)*(this->_n) + (j)]; // row-major
963 }
964 
965 
966 
967 template<typename T>
968 inline
969 T & DenseMatrix<T>::operator () (const unsigned int i,
970  const unsigned int j)
971 {
972  libmesh_assert_less (i*j, _val.size());
973  libmesh_assert_less (i, this->_m);
974  libmesh_assert_less (j, this->_n);
975 
976  //return _val[(i) + (this->_m)*(j)]; // col-major
977  return _val[(i)*(this->_n) + (j)]; // row-major
978 }
979 
980 
981 
982 
983 
984 template<typename T>
985 inline
986 void DenseMatrix<T>::scale (const T factor)
987 {
988  for (auto & v : _val)
989  v *= factor;
990 }
991 
992 
993 template<typename T>
994 inline
995 void DenseMatrix<T>::scale_column (const unsigned int col, const T factor)
996 {
997  for (auto i : make_range(this->m()))
998  (*this)(i, col) *= factor;
999 }
1000 
1001 
1002 
1003 template<typename T>
1004 inline
1006 {
1007  this->scale(factor);
1008  return *this;
1009 }
1010 
1011 
1012 
1013 template<typename T>
1014 template<typename T2, typename T3>
1015 inline
1016 typename boostcopy::enable_if_c<
1017  ScalarTraits<T2>::value, void >::type
1018 DenseMatrix<T>::add (const T2 factor,
1019  const DenseMatrix<T3> & mat)
1020 {
1021  libmesh_assert_equal_to (this->m(), mat.m());
1022  libmesh_assert_equal_to (this->n(), mat.n());
1023 
1024  for (auto i : make_range(this->m()))
1025  for (auto j : make_range(this->n()))
1026  (*this)(i,j) += factor * mat(i,j);
1027 }
1028 
1029 
1030 
1031 template<typename T>
1032 inline
1034 {
1035  for (auto i : index_range(_val))
1036  if (_val[i] != mat._val[i])
1037  return false;
1038 
1039  return true;
1040 }
1041 
1042 
1043 
1044 template<typename T>
1045 inline
1047 {
1048  for (auto i : index_range(_val))
1049  if (_val[i] != mat._val[i])
1050  return true;
1051 
1052  return false;
1053 }
1054 
1055 
1056 
1057 template<typename T>
1058 inline
1060 {
1061  for (auto i : index_range(_val))
1062  _val[i] += mat._val[i];
1063 
1064  return *this;
1065 }
1066 
1067 
1068 
1069 template<typename T>
1070 inline
1072 {
1073  for (auto i : index_range(_val))
1074  _val[i] -= mat._val[i];
1075 
1076  return *this;
1077 }
1078 
1079 
1080 
1081 template<typename T>
1082 inline
1083 auto DenseMatrix<T>::min () const -> decltype(libmesh_real(T(0)))
1084 {
1085  libmesh_assert (this->_m);
1086  libmesh_assert (this->_n);
1087  auto my_min = libmesh_real((*this)(0,0));
1088 
1089  for (unsigned int i=0; i!=this->_m; i++)
1090  {
1091  for (unsigned int j=0; j!=this->_n; j++)
1092  {
1093  auto current = libmesh_real((*this)(i,j));
1094  my_min = (my_min < current? my_min : current);
1095  }
1096  }
1097  return my_min;
1098 }
1099 
1100 
1101 
1102 template<typename T>
1103 inline
1104 auto DenseMatrix<T>::max () const -> decltype(libmesh_real(T(0)))
1105 {
1106  libmesh_assert (this->_m);
1107  libmesh_assert (this->_n);
1108  auto my_max = libmesh_real((*this)(0,0));
1109 
1110  for (unsigned int i=0; i!=this->_m; i++)
1111  {
1112  for (unsigned int j=0; j!=this->_n; j++)
1113  {
1114  auto current = libmesh_real((*this)(i,j));
1115  my_max = (my_max > current? my_max : current);
1116  }
1117  }
1118  return my_max;
1119 }
1120 
1121 
1122 
1123 template<typename T>
1124 inline
1125 auto DenseMatrix<T>::l1_norm () const -> decltype(std::abs(T(0)))
1126 {
1127  libmesh_assert (this->_m);
1128  libmesh_assert (this->_n);
1129 
1130  auto columnsum = std::abs(T(0));
1131  for (unsigned int i=0; i!=this->_m; i++)
1132  {
1133  columnsum += std::abs((*this)(i,0));
1134  }
1135  auto my_max = columnsum;
1136  for (unsigned int j=1; j!=this->_n; j++)
1137  {
1138  columnsum = 0.;
1139  for (unsigned int i=0; i!=this->_m; i++)
1140  {
1141  columnsum += std::abs((*this)(i,j));
1142  }
1143  my_max = (my_max > columnsum? my_max : columnsum);
1144  }
1145  return my_max;
1146 }
1147 
1148 
1149 
1150 template<typename T>
1151 inline
1152 auto DenseMatrix<T>::linfty_norm () const -> decltype(std::abs(T(0)))
1153 {
1154  libmesh_assert (this->_m);
1155  libmesh_assert (this->_n);
1156 
1157  auto rowsum = std::abs(T(0));
1158  for (unsigned int j=0; j!=this->_n; j++)
1159  {
1160  rowsum += std::abs((*this)(0,j));
1161  }
1162  auto my_max = rowsum;
1163  for (unsigned int i=1; i!=this->_m; i++)
1164  {
1165  rowsum = 0.;
1166  for (unsigned int j=0; j!=this->_n; j++)
1167  {
1168  rowsum += std::abs((*this)(i,j));
1169  }
1170  my_max = (my_max > rowsum? my_max : rowsum);
1171  }
1172  return my_max;
1173 }
1174 
1175 
1176 
1177 template<typename T>
1178 inline
1179 T DenseMatrix<T>::transpose (const unsigned int i,
1180  const unsigned int j) const
1181 {
1182  // Implement in terms of operator()
1183  return (*this)(j,i);
1184 }
1185 
1186 
1187 
1188 
1189 
1190 // template<typename T>
1191 // inline
1192 // void DenseMatrix<T>::condense(const unsigned int iv,
1193 // const unsigned int jv,
1194 // const T val,
1195 // DenseVector<T> & rhs)
1196 // {
1197 // libmesh_assert_equal_to (this->_m, rhs.size());
1198 // libmesh_assert_equal_to (iv, jv);
1199 
1200 
1201 // // move the known value into the RHS
1202 // // and zero the column
1203 // for (auto i : make_range(this->m()))
1204 // {
1205 // rhs(i) -= ((*this)(i,jv))*val;
1206 // (*this)(i,jv) = 0.;
1207 // }
1208 
1209 // // zero the row
1210 // for (auto j : make_range(this->n()))
1211 // (*this)(iv,j) = 0.;
1212 
1213 // (*this)(iv,jv) = 1.;
1214 // rhs(iv) = val;
1215 
1216 // }
1217 
1218 
1219 
1220 
1221 } // namespace libMesh
1222 
1223 #ifdef LIBMESH_HAVE_METAPHYSICL
1224 namespace MetaPhysicL
1225 {
1226 template <typename T>
1227 struct RawType<libMesh::DenseMatrix<T>>
1228 {
1230 
1232  {
1233  const auto m = in.m(), n = in.n();
1234  value_type ret(m, n);
1235  for (unsigned int i = 0; i < m; ++i)
1236  for (unsigned int j = 0; j < n; ++j)
1237  ret(i,j) = raw_value(in(i,j));
1238 
1239  return ret;
1240  }
1241 };
1242 }
1243 #endif
1244 
1245 
1246 #endif // LIBMESH_DENSE_MATRIX_H
T libmesh_real(T a)
void _cholesky_back_substitute(const DenseVector< T2 > &b, DenseVector< T2 > &x) const
Solves the equation Ax=b for the unknown value x and rhs b based on the Cholesky factorization of A...
void _matvec_blas(T alpha, T beta, DenseVector< T > &dest, const DenseVector< T > &arg, bool trans=false) const
Uses the BLAS GEMV function (through PETSc) to compute.
void _lu_back_substitute(const DenseVector< T > &b, DenseVector< T > &x) const
Solves the system Ax=b through back substitution.
T transpose(const unsigned int i, const unsigned int j) const
void swap(DenseMatrix< T > &other_matrix)
STL-like swap method.
Definition: dense_matrix.h:865
void condense(const unsigned int i, const unsigned int j, const T val, DenseVector< T > &rhs)
Condense-out the (i,j) entry of the matrix, forcing it to take on the value val.
Definition: dense_matrix.h:395
DenseMatrix< Complex > ComplexDenseMatrix
This typedef may be either a real-only matrix, or a truly complex matrix, depending on how Number was...
Definition: dense_matrix.h:810
void _lu_decompose_lapack()
Computes an LU factorization of the matrix using the Lapack routine "getrf".
auto max() const -> decltype(libmesh_real(T(0)))
_BLAS_Multiply_Flag
Enumeration used to determine the behavior of the _multiply_blas function.
Definition: dense_matrix.h:656
virtual void zero() override final
Sets all elements of the matrix to 0 and resets any decomposition flag which may have been previously...
Definition: dense_matrix.h:911
void scale(MeshBase &mesh, const Real xs, const Real ys=0., const Real zs=0.)
Scales the mesh.
DenseMatrix< T > & operator+=(const DenseMatrix< T > &mat)
Adds mat to this matrix.
DecompositionType _decomposition_type
This flag keeps track of which type of decomposition has been performed on the matrix.
Definition: dense_matrix.h:650
void _svd_solve_lapack(const DenseVector< T > &rhs, DenseVector< T > &x, Real rcond) const
Called by svd_solve(rhs).
void evd_left(DenseVector< T > &lambda_real, DenseVector< T > &lambda_imag, DenseMatrix< T > &VL)
Compute the eigenvalues (both real and imaginary parts) and left eigenvectors of a general matrix...
virtual ~DenseMatrix()=default
void evd_left_and_right(DenseVector< T > &lambda_real, DenseVector< T > &lambda_imag, DenseMatrix< T > &VL, DenseMatrix< T > &VR)
Compute the eigenvalues (both real and imaginary parts) as well as the left and right eigenvectors of...
auto l1_norm() const -> decltype(std::abs(T(0)))
unsigned int m() const
DenseMatrix< T > & operator-=(const DenseMatrix< T > &mat)
Subtracts mat from this matrix.
The libMesh namespace provides an interface to certain functionality in the library.
const Number zero
.
Definition: libmesh.h:280
bool use_blas_lapack
Computes the inverse of the dense matrix (assuming it is invertible) by first computing the LU decomp...
Definition: dense_matrix.h:585
bool operator==(const variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, OtherConstType, OtherConstReferenceType, OtherConstPointerType > &x, const variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, OtherConstType, OtherConstReferenceType, OtherConstPointerType > &y)
void _multiply_blas(const DenseMatrixBase< T > &other, _BLAS_Multiply_Flag flag)
The _multiply_blas function computes A <- op(A) * op(B) using BLAS gemm function. ...
DenseMatrix(const unsigned int new_m=0, const unsigned int new_n=0)
Constructor.
Definition: dense_matrix.h:836
const std::vector< T > & get_values() const
Definition: dense_matrix.h:387
void outer_product(const DenseVector< T > &a, const DenseVector< T > &b)
Computes the outer (dyadic) product of two vectors and stores in (*this).
void vector_mult_transpose(DenseVector< T > &dest, const DenseVector< T > &arg) const
Performs the matrix-vector multiplication, dest := (*this)^T * arg.
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
Definition: type_vector.h:57
void scale_column(const unsigned int col, const T factor)
Multiplies every element in the column col matrix by factor.
Definition: dense_matrix.h:995
libMesh::DenseMatrix< typename RawType< T >::value_type > value_type
DenseMatrix & operator=(const DenseMatrix &)=default
void vector_mult_add(DenseVector< T > &dest, const T factor, const DenseVector< T > &arg) const
Performs the scaled matrix-vector multiplication, dest += factor * (*this) * arg. ...
virtual T el(const unsigned int i, const unsigned int j) const override final
Definition: dense_matrix.h:126
void _lu_back_substitute_lapack(const DenseVector< T > &b, DenseVector< T > &x)
Companion function to _lu_decompose_lapack().
void svd(DenseVector< Real > &sigma)
Compute the singular value decomposition of the matrix.
auto linfty_norm() const -> decltype(std::abs(T(0)))
void _lu_decompose()
Form the LU decomposition of the matrix.
void get_transpose(DenseMatrix< T > &dest) const
Put the tranposed matrix into dest.
boostcopy::enable_if_c< ScalarTraits< T2 >::value, void >::type add(const T2 factor, const DenseMatrix< T3 > &mat)
Adds factor times mat to this matrix.
DenseMatrix< Real > RealDenseMatrix
Convenient definition of a real-only dense matrix.
Definition: dense_matrix.h:801
void evd_right(DenseVector< T > &lambda_real, DenseVector< T > &lambda_imag, DenseMatrix< T > &VR)
Compute the eigenvalues (both real and imaginary parts) and right eigenvectors of a general matrix...
libmesh_assert(ctx)
void _cholesky_decompose()
Decomposes a symmetric positive definite matrix into a product of two lower triangular matrices accor...
bool operator!=(const variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, OtherConstType, OtherConstReferenceType, OtherConstPointerType > &x, const variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, OtherConstType, OtherConstReferenceType, OtherConstPointerType > &y)
void get_principal_submatrix(unsigned int sub_m, unsigned int sub_n, DenseMatrix< T > &dest) const
Put the sub_m x sub_n principal submatrix into dest.
void _svd_lapack(DenseVector< Real > &sigma)
Computes an SVD of the matrix using the Lapack routine "getsvd".
std::vector< T > & get_values()
Definition: dense_matrix.h:382
bool operator==(const DenseMatrix< T > &mat) const
void right_multiply_transpose(const DenseMatrix< T > &A)
Right multiplies by the transpose of the matrix A.
void scale(const T factor)
Multiplies every element in the matrix by factor.
Definition: dense_matrix.h:986
void lu_solve(const DenseVector< T > &b, DenseVector< T > &x)
Solve the system Ax=b given the input vector b.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void _evd_lapack(DenseVector< T > &lambda_real, DenseVector< T > &lambda_imag, DenseMatrix< T > *VL=nullptr, DenseMatrix< T > *VR=nullptr)
Computes the eigenvalues of the matrix using the Lapack routine "DGEEV".
void evd(DenseVector< T > &lambda_real, DenseVector< T > &lambda_imag)
Compute the eigenvalues (both real and imaginary parts) of a general matrix.
void left_multiply_transpose(const DenseMatrix< T > &A)
Left multiplies by the transpose of the matrix A.
virtual void right_multiply(const DenseMatrixBase< T > &M2) override final
Performs the operation: (*this) <- (*this) * M3.
static value_type value(const libMesh::DenseMatrix< T > &in)
void _left_multiply_transpose(const DenseMatrix< T2 > &A)
Left multiplies by the transpose of the matrix A which may contain a different numerical type...
Helper structure for determining whether to use blas_lapack.
Definition: dense_matrix.h:590
static const bool value
Definition: xdr_io.C:54
void resize(const unsigned int new_m, const unsigned int new_n)
Resizes the matrix to the specified size and calls zero().
Definition: dense_matrix.h:895
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:134
auto min() const -> decltype(libmesh_real(T(0)))
std::vector< T > _val
The actual data values, stored as a 1D array.
Definition: dense_matrix.h:600
Defines a dense vector for use in Finite Element-type computations.
void cholesky_solve(const DenseVector< T2 > &b, DenseVector< T2 > &x)
For symmetric positive definite (SPD) matrices.
void _right_multiply_transpose(const DenseMatrix< T2 > &A)
Right multiplies by the transpose of the matrix A which may contain a different numerical type...
DenseMatrix< T > & operator*=(const T factor)
Multiplies every element in the matrix by factor.
Defines an abstract dense matrix base class for use in Finite Element-type computations.
unsigned int n() const
bool operator!=(const DenseMatrix< T > &mat) const
void _svd_helper(char JOBU, char JOBVT, std::vector< Real > &sigma_val, std::vector< Number > &U_val, std::vector< Number > &VT_val)
Helper function that actually performs the SVD.
DecompositionType
The decomposition schemes above change the entries of the matrix A.
Definition: dense_matrix.h:644
Defines a dense matrix for use in Finite Element-type computations.
Definition: dof_map.h:65
std::vector< pivot_index_t > _pivots
Definition: dense_matrix.h:740
DenseMatrix sub_matrix(unsigned int row_id, unsigned int row_size, unsigned int col_id, unsigned int col_size) const
Get submatrix with the smallest row and column indices and the submatrix size.
Definition: dense_matrix.h:922
void svd_solve(const DenseVector< T > &rhs, DenseVector< T > &x, Real rcond=std::numeric_limits< Real >::epsilon()) const
Solve the system of equations for in the least-squares sense.
PetscBLASInt pivot_index_t
Array used to store pivot indices.
Definition: dense_matrix.h:736
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition: int_range.h:111
void condense(const unsigned int i, const unsigned int j, const T val, DenseVectorBase< T > &rhs)
Condense-out the (i,j) entry of the matrix, forcing it to take on the value val.
virtual void left_multiply(const DenseMatrixBase< T > &M2) override final
Performs the operation: (*this) <- M2 * (*this)
virtual T & el(const unsigned int i, const unsigned int j) override final
Definition: dense_matrix.h:130
void vector_mult(DenseVector< T > &dest, const DenseVector< T > &arg) const
Performs the matrix-vector multiplication, dest := (*this) * arg.