libMesh
dense_matrix.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 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 # include <petscsys.h>
35 # ifndef LIBMESH_SAW_I
36 # undef I // Avoid complex.h contamination
37 # endif
38 #endif
39 
40 // C++ includes
41 #include <vector>
42 #include <algorithm>
43 
44 #ifdef LIBMESH_HAVE_METAPHYSICL
45 namespace MetaPhysicL
46 {
47 template <typename, typename>
48 class DualNumber;
49 }
50 namespace std
51 {
52 // These declarations must be visible to the DenseMatrix method declarations that use
53 // a std::abs trailing return type in order to instantiate a DenseMatrix<DualNumber>
54 template <typename T, typename D>
56 template <typename T, typename D>
58 }
59 #endif
60 
61 namespace libMesh
62 {
63 
64 // Forward Declarations
65 template <typename T> class DenseVector;
66 
77 template<typename T>
78 class DenseMatrix : public DenseMatrixBase<T>
79 {
80 public:
81 
85  DenseMatrix(const unsigned int new_m=0,
86  const unsigned int new_n=0);
87 
92  DenseMatrix (DenseMatrix &&) = default;
93  DenseMatrix (const DenseMatrix &) = default;
94  DenseMatrix & operator= (const DenseMatrix &) = default;
95  DenseMatrix & operator= (DenseMatrix &&) = default;
96  virtual ~DenseMatrix() = default;
97 
98  virtual void zero() override;
99 
103  DenseMatrix sub_matrix(unsigned int row_id, unsigned int row_size,
104  unsigned int col_id, unsigned int col_size) const;
105 
109  T operator() (const unsigned int i,
110  const unsigned int j) const;
111 
115  T & operator() (const unsigned int i,
116  const unsigned int j);
117 
118  virtual T el(const unsigned int i,
119  const unsigned int j) const override
120  { return (*this)(i,j); }
121 
122  virtual T & el(const unsigned int i,
123  const unsigned int j) override
124  { return (*this)(i,j); }
125 
126  virtual void left_multiply (const DenseMatrixBase<T> & M2) override;
127 
131  template <typename T2>
132  void left_multiply (const DenseMatrixBase<T2> & M2);
133 
134  virtual void right_multiply (const DenseMatrixBase<T> & M2) override;
135 
139  template <typename T2>
140  void right_multiply (const DenseMatrixBase<T2> & M2);
141 
146  void vector_mult (DenseVector<T> & dest,
147  const DenseVector<T> & arg) const;
148 
154  template <typename T2>
156  const DenseVector<T2> & arg) const;
157 
163  const DenseVector<T> & arg) const;
164 
170  template <typename T2>
172  const DenseVector<T2> & arg) const;
173 
178  void vector_mult_add (DenseVector<T> & dest,
179  const T factor,
180  const DenseVector<T> & arg) const;
181 
187  template <typename T2, typename T3>
188  void vector_mult_add (DenseVector<typename CompareTypes<T, typename CompareTypes<T2,T3>::supertype>::supertype> & dest,
189  const T2 factor,
190  const DenseVector<T3> & arg) const;
191 
195  void get_principal_submatrix (unsigned int sub_m, unsigned int sub_n, DenseMatrix<T> & dest) const;
196 
200  void get_principal_submatrix (unsigned int sub_m, DenseMatrix<T> & dest) const;
201 
219  void outer_product(const DenseVector<T> & a, const DenseVector<T> & b);
220 
230  template <typename T2>
231  DenseMatrix<T> & operator = (const DenseMatrix<T2> & other_matrix);
232 
236  void swap(DenseMatrix<T> & other_matrix);
237 
242  void resize(const unsigned int new_m,
243  const unsigned int new_n);
244 
248  void scale (const T factor);
249 
253  void scale_column (const unsigned int col, const T factor);
254 
260  DenseMatrix<T> & operator *= (const T factor);
261 
267  template<typename T2, typename T3>
268  typename boostcopy::enable_if_c<
269  ScalarTraits<T2>::value, void >::type add (const T2 factor,
270  const DenseMatrix<T3> & mat);
271 
275  bool operator== (const DenseMatrix<T> & mat) const;
276 
280  bool operator!= (const DenseMatrix<T> & mat) const;
281 
288 
295 
300  auto min () const -> decltype(libmesh_real(T(0)));
301 
306  auto max () const -> decltype(libmesh_real(T(0)));
307 
316  auto l1_norm () const -> decltype(std::abs(T(0)));
317 
326  auto linfty_norm () const -> decltype(std::abs(T(0)));
327 
331  void left_multiply_transpose (const DenseMatrix<T> & A);
332 
337  template <typename T2>
338  void left_multiply_transpose (const DenseMatrix<T2> & A);
339 
340 
344  void right_multiply_transpose (const DenseMatrix<T> & A);
345 
350  template <typename T2>
351  void right_multiply_transpose (const DenseMatrix<T2> & A);
352 
356  T transpose (const unsigned int i,
357  const unsigned int j) const;
358 
362  void get_transpose(DenseMatrix<T> & dest) const;
363 
371  std::vector<T> & get_values() { return _val; }
372 
376  const std::vector<T> & get_values() const { return _val; }
377 
384  void condense(const unsigned int i,
385  const unsigned int j,
386  const T val,
387  DenseVector<T> & rhs)
388  { DenseMatrixBase<T>::condense (i, j, val, rhs); }
389 
395  void lu_solve (const DenseVector<T> & b,
396  DenseVector<T> & x);
397 
409  template <typename T2>
410  void cholesky_solve(const DenseVector<T2> & b,
411  DenseVector<T2> & x);
412 
421  void svd(DenseVector<Real> & sigma);
422 
434  void svd(DenseVector<Real> & sigma,
436  DenseMatrix<Number> & VT);
437 
455  void svd_solve(const DenseVector<T> & rhs,
456  DenseVector<T> & x,
457  Real rcond=std::numeric_limits<Real>::epsilon()) const;
458 
466  void evd(DenseVector<T> & lambda_real,
467  DenseVector<T> & lambda_imag);
468 
487  void evd_left(DenseVector<T> & lambda_real,
488  DenseVector<T> & lambda_imag,
489  DenseMatrix<T> & VL);
490 
509  void evd_right(DenseVector<T> & lambda_real,
510  DenseVector<T> & lambda_imag,
511  DenseMatrix<T> & VR);
512 
523  void evd_left_and_right(DenseVector<T> & lambda_real,
524  DenseVector<T> & lambda_imag,
525  DenseMatrix<T> & VL,
526  DenseMatrix<T> & VR);
527 
535  T det();
536 
548  // void inverse();
549 
556 
557 private:
558 
562  std::vector<T> _val;
563 
569  void _lu_decompose ();
570 
576  void _lu_back_substitute (const DenseVector<T> & b,
577  DenseVector<T> & x) const;
578 
586  void _cholesky_decompose();
587 
595  template <typename T2>
597  DenseVector<T2> & x) const;
598 
607 
613 
623  };
624 
632  void _multiply_blas(const DenseMatrixBase<T> & other,
633  _BLAS_Multiply_Flag flag);
634 
644  void _lu_decompose_lapack();
645 
651  void _svd_lapack(DenseVector<Real> & sigma);
652 
658  void _svd_lapack(DenseVector<Real> & sigma,
660  DenseMatrix<Number> & VT);
661 
665  void _svd_solve_lapack(const DenseVector<T> & rhs,
666  DenseVector<T> & x,
667  Real rcond) const;
668 
673  void _svd_helper (char JOBU,
674  char JOBVT,
675  std::vector<Real> & sigma_val,
676  std::vector<Number> & U_val,
677  std::vector<Number> & VT_val);
678 
687  void _evd_lapack(DenseVector<T> & lambda_real,
688  DenseVector<T> & lambda_imag,
689  DenseMatrix<T> * VL = nullptr,
690  DenseMatrix<T> * VR = nullptr);
691 
697 #if (LIBMESH_HAVE_PETSC && LIBMESH_USE_REAL_NUMBERS)
698  typedef PetscBLASInt pivot_index_t;
699 #else
700  typedef int pivot_index_t;
701 #endif
702  std::vector<pivot_index_t> _pivots;
703 
714  DenseVector<T> & x);
715 
728  void _matvec_blas(T alpha, T beta,
729  DenseVector<T> & dest,
730  const DenseVector<T> & arg,
731  bool trans=false) const;
732 };
733 
734 
735 
736 
737 
738 // ------------------------------------------------------------
742 namespace DenseMatrices
743 {
744 
750 
759 
760 }
761 
762 
763 
764 using namespace DenseMatrices;
765 
766 
767 
768 
769 
770 // ------------------------------------------------------------
771 // Dense Matrix member functions
772 template<typename T>
773 inline
774 DenseMatrix<T>::DenseMatrix(const unsigned int new_m,
775  const unsigned int new_n) :
776  DenseMatrixBase<T>(new_m,new_n),
777 #if defined(LIBMESH_HAVE_PETSC) && defined(LIBMESH_USE_REAL_NUMBERS) && defined(LIBMESH_DEFAULT_DOUBLE_PRECISION)
778  use_blas_lapack(true),
779 #else
780  use_blas_lapack(false),
781 #endif
782  _val(),
783  _decomposition_type(NONE)
784 {
785  this->resize(new_m,new_n);
786 }
787 
788 
789 
790 template<typename T>
791 inline
793 {
794  std::swap(this->_m, other_matrix._m);
795  std::swap(this->_n, other_matrix._n);
796  _val.swap(other_matrix._val);
797  DecompositionType _temp = _decomposition_type;
798  _decomposition_type = other_matrix._decomposition_type;
799  other_matrix._decomposition_type = _temp;
800 }
801 
802 
803 template <typename T>
804 template <typename T2>
805 inline
808 {
809  unsigned int mat_m = mat.m(), mat_n = mat.n();
810  this->resize(mat_m, mat_n);
811  for (unsigned int i=0; i<mat_m; i++)
812  for (unsigned int j=0; j<mat_n; j++)
813  (*this)(i,j) = mat(i,j);
814 
815  return *this;
816 }
817 
818 
819 
820 template<typename T>
821 inline
822 void DenseMatrix<T>::resize(const unsigned int new_m,
823  const unsigned int new_n)
824 {
825  _val.resize(new_m*new_n);
826 
827  this->_m = new_m;
828  this->_n = new_n;
829 
830  // zero and set decomposition_type to NONE
831  this->zero();
832 }
833 
834 
835 
836 template<typename T>
837 inline
839 {
840  _decomposition_type = NONE;
841 
842  std::fill (_val.begin(), _val.end(), static_cast<T>(0));
843 }
844 
845 
846 
847 template<typename T>
848 inline
849 DenseMatrix<T> DenseMatrix<T>::sub_matrix(unsigned int row_id, unsigned int row_size,
850  unsigned int col_id, unsigned int col_size) const
851 {
852  libmesh_assert_less (row_id + row_size - 1, this->_m);
853  libmesh_assert_less (col_id + col_size - 1, this->_n);
854 
855  DenseMatrix<T> sub;
856  sub._m = row_size;
857  sub._n = col_size;
858  sub._val.resize(row_size * col_size);
859 
860  unsigned int end_col = this->_n - col_size - col_id;
861  unsigned int p = row_id * this->_n;
862  unsigned int q = 0;
863  for (unsigned int i=0; i<row_size; i++)
864  {
865  // skip the beginning columns
866  p += col_id;
867  for (unsigned int j=0; j<col_size; j++)
868  sub._val[q++] = _val[p++];
869  // skip the rest columns
870  p += end_col;
871  }
872 
873  return sub;
874 }
875 
876 
877 
878 template<typename T>
879 inline
880 T DenseMatrix<T>::operator () (const unsigned int i,
881  const unsigned int j) const
882 {
883  libmesh_assert_less (i*j, _val.size());
884  libmesh_assert_less (i, this->_m);
885  libmesh_assert_less (j, this->_n);
886 
887 
888  // return _val[(i) + (this->_m)*(j)]; // col-major
889  return _val[(i)*(this->_n) + (j)]; // row-major
890 }
891 
892 
893 
894 template<typename T>
895 inline
896 T & DenseMatrix<T>::operator () (const unsigned int i,
897  const unsigned int j)
898 {
899  libmesh_assert_less (i*j, _val.size());
900  libmesh_assert_less (i, this->_m);
901  libmesh_assert_less (j, this->_n);
902 
903  //return _val[(i) + (this->_m)*(j)]; // col-major
904  return _val[(i)*(this->_n) + (j)]; // row-major
905 }
906 
907 
908 
909 
910 
911 template<typename T>
912 inline
913 void DenseMatrix<T>::scale (const T factor)
914 {
915  for (auto & v : _val)
916  v *= factor;
917 }
918 
919 
920 template<typename T>
921 inline
922 void DenseMatrix<T>::scale_column (const unsigned int col, const T factor)
923 {
924  for (auto i : IntRange<unsigned int>(0, this->m()))
925  (*this)(i, col) *= factor;
926 }
927 
928 
929 
930 template<typename T>
931 inline
933 {
934  this->scale(factor);
935  return *this;
936 }
937 
938 
939 
940 template<typename T>
941 template<typename T2, typename T3>
942 inline
943 typename boostcopy::enable_if_c<
944  ScalarTraits<T2>::value, void >::type
945 DenseMatrix<T>::add (const T2 factor,
946  const DenseMatrix<T3> & mat)
947 {
948  libmesh_assert_equal_to (this->m(), mat.m());
949  libmesh_assert_equal_to (this->n(), mat.n());
950 
951  for (auto i : IntRange<unsigned int>(0, this->m()))
952  for (auto j : IntRange<unsigned int>(0, this->n()))
953  (*this)(i,j) += factor * mat(i,j);
954 }
955 
956 
957 
958 template<typename T>
959 inline
961 {
962  for (auto i : index_range(_val))
963  if (_val[i] != mat._val[i])
964  return false;
965 
966  return true;
967 }
968 
969 
970 
971 template<typename T>
972 inline
974 {
975  for (auto i : index_range(_val))
976  if (_val[i] != mat._val[i])
977  return true;
978 
979  return false;
980 }
981 
982 
983 
984 template<typename T>
985 inline
987 {
988  for (auto i : index_range(_val))
989  _val[i] += mat._val[i];
990 
991  return *this;
992 }
993 
994 
995 
996 template<typename T>
997 inline
999 {
1000  for (auto i : index_range(_val))
1001  _val[i] -= mat._val[i];
1002 
1003  return *this;
1004 }
1005 
1006 
1007 
1008 template<typename T>
1009 inline
1010 auto DenseMatrix<T>::min () const -> decltype(libmesh_real(T(0)))
1011 {
1012  libmesh_assert (this->_m);
1013  libmesh_assert (this->_n);
1014  auto my_min = libmesh_real((*this)(0,0));
1015 
1016  for (unsigned int i=0; i!=this->_m; i++)
1017  {
1018  for (unsigned int j=0; j!=this->_n; j++)
1019  {
1020  auto current = libmesh_real((*this)(i,j));
1021  my_min = (my_min < current? my_min : current);
1022  }
1023  }
1024  return my_min;
1025 }
1026 
1027 
1028 
1029 template<typename T>
1030 inline
1031 auto DenseMatrix<T>::max () const -> decltype(libmesh_real(T(0)))
1032 {
1033  libmesh_assert (this->_m);
1034  libmesh_assert (this->_n);
1035  auto my_max = libmesh_real((*this)(0,0));
1036 
1037  for (unsigned int i=0; i!=this->_m; i++)
1038  {
1039  for (unsigned int j=0; j!=this->_n; j++)
1040  {
1041  auto current = libmesh_real((*this)(i,j));
1042  my_max = (my_max > current? my_max : current);
1043  }
1044  }
1045  return my_max;
1046 }
1047 
1048 
1049 
1050 template<typename T>
1051 inline
1052 auto DenseMatrix<T>::l1_norm () const -> decltype(std::abs(T(0)))
1053 {
1054  libmesh_assert (this->_m);
1055  libmesh_assert (this->_n);
1056 
1057  auto columnsum = std::abs(T(0));
1058  for (unsigned int i=0; i!=this->_m; i++)
1059  {
1060  columnsum += std::abs((*this)(i,0));
1061  }
1062  auto my_max = columnsum;
1063  for (unsigned int j=1; j!=this->_n; j++)
1064  {
1065  columnsum = 0.;
1066  for (unsigned int i=0; i!=this->_m; i++)
1067  {
1068  columnsum += std::abs((*this)(i,j));
1069  }
1070  my_max = (my_max > columnsum? my_max : columnsum);
1071  }
1072  return my_max;
1073 }
1074 
1075 
1076 
1077 template<typename T>
1078 inline
1079 auto DenseMatrix<T>::linfty_norm () const -> decltype(std::abs(T(0)))
1080 {
1081  libmesh_assert (this->_m);
1082  libmesh_assert (this->_n);
1083 
1084  auto rowsum = std::abs(T(0));
1085  for (unsigned int j=0; j!=this->_n; j++)
1086  {
1087  rowsum += std::abs((*this)(0,j));
1088  }
1089  auto my_max = rowsum;
1090  for (unsigned int i=1; i!=this->_m; i++)
1091  {
1092  rowsum = 0.;
1093  for (unsigned int j=0; j!=this->_n; j++)
1094  {
1095  rowsum += std::abs((*this)(i,j));
1096  }
1097  my_max = (my_max > rowsum? my_max : rowsum);
1098  }
1099  return my_max;
1100 }
1101 
1102 
1103 
1104 template<typename T>
1105 inline
1106 T DenseMatrix<T>::transpose (const unsigned int i,
1107  const unsigned int j) const
1108 {
1109  // Implement in terms of operator()
1110  return (*this)(j,i);
1111 }
1112 
1113 
1114 
1115 
1116 
1117 // template<typename T>
1118 // inline
1119 // void DenseMatrix<T>::condense(const unsigned int iv,
1120 // const unsigned int jv,
1121 // const T val,
1122 // DenseVector<T> & rhs)
1123 // {
1124 // libmesh_assert_equal_to (this->_m, rhs.size());
1125 // libmesh_assert_equal_to (iv, jv);
1126 
1127 
1128 // // move the known value into the RHS
1129 // // and zero the column
1130 // for (auto i : IntRange<unsigned int>(0, this->m()))
1131 // {
1132 // rhs(i) -= ((*this)(i,jv))*val;
1133 // (*this)(i,jv) = 0.;
1134 // }
1135 
1136 // // zero the row
1137 // for (auto j : IntRange<unsigned int>(0, this->n()))
1138 // (*this)(iv,j) = 0.;
1139 
1140 // (*this)(iv,jv) = 1.;
1141 // rhs(iv) = val;
1142 
1143 // }
1144 
1145 
1146 
1147 
1148 } // namespace libMesh
1149 
1150 
1151 
1152 
1153 #endif // LIBMESH_DENSE_MATRIX_H
libMesh::DenseMatrix::_svd_lapack
void _svd_lapack(DenseVector< Real > &sigma)
Computes an SVD of the matrix using the Lapack routine "getsvd".
Definition: dense_matrix_blas_lapack.C:278
libMesh::DenseMatrix::min
auto min() const -> decltype(libmesh_real(T(0)))
Definition: dense_matrix.h:1010
libMesh::DenseMatrix::use_blas_lapack
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:555
libMesh::DenseMatrix::get_transpose
void get_transpose(DenseMatrix< T > &dest) const
Put the tranposed matrix into dest.
Definition: dense_matrix_impl.h:612
libMesh::DenseMatrices::ComplexDenseMatrix
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:758
libMesh::DenseMatrix::LU
Definition: dense_matrix.h:606
libMesh::DenseMatrix::_pivots
std::vector< pivot_index_t > _pivots
Definition: dense_matrix.h:702
libMesh::DenseMatrix::left_multiply_transpose
void left_multiply_transpose(const DenseMatrix< T > &A)
Left multiplies by the transpose of the matrix A.
Definition: dense_matrix_impl.h:106
libMesh::DenseMatrix::get_values
const std::vector< T > & get_values() const
Definition: dense_matrix.h:376
libMesh::DenseMatrix::right_multiply_transpose
void right_multiply_transpose(const DenseMatrix< T > &A)
Right multiplies by the transpose of the matrix A.
Definition: dense_matrix_impl.h:278
libMesh::DenseMatrix::operator==
bool operator==(const DenseMatrix< T > &mat) const
Definition: dense_matrix.h:960
libMesh::DenseMatrix::_svd_solve_lapack
void _svd_solve_lapack(const DenseVector< T > &rhs, DenseVector< T > &x, Real rcond) const
Called by svd_solve(rhs).
Definition: dense_matrix_blas_lapack.C:532
libMesh::DenseMatrix::RIGHT_MULTIPLY_TRANSPOSE
Definition: dense_matrix.h:622
libMesh::DenseMatrix::_cholesky_back_substitute
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.
Definition: dense_matrix_impl.h:1025
libMesh::libmesh_real
T libmesh_real(T a)
Definition: libmesh_common.h:166
libMesh::DenseMatrix::_val
std::vector< T > _val
The actual data values, stored as a 1D array.
Definition: dense_matrix.h:562
libMesh::DenseMatrix::DenseMatrix
DenseMatrix(const unsigned int new_m=0, const unsigned int new_n=0)
Constructor.
Definition: dense_matrix.h:774
libMesh::index_range
IntRange< std::size_t > index_range(const std::vector< T > &vec)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition: int_range.h:106
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::DenseMatrix::add
boostcopy::enable_if_c< ScalarTraits< T2 >::value, void >::type add(const T2 factor, const DenseMatrix< T3 > &mat)
Adds factor times mat to this matrix.
Definition: dense_matrix.h:945
libMesh::DenseMatrix::_svd_helper
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.
Definition: dense_matrix_blas_lapack.C:385
libMesh::DenseMatrix::LEFT_MULTIPLY
Definition: dense_matrix.h:619
libMesh::DenseMatrix::evd_right
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,...
Definition: dense_matrix_impl.h:863
libMesh::DenseMatrix::evd
void evd(DenseVector< T > &lambda_real, DenseVector< T > &lambda_imag)
Compute the eigenvalues (both real and imaginary parts) of a general matrix.
Definition: dense_matrix_impl.h:842
libMesh::DenseMatrix
Defines a dense matrix for use in Finite Element-type computations.
Definition: dof_map.h:73
libMesh::DenseMatrix::_cholesky_decompose
void _cholesky_decompose()
Decomposes a symmetric positive definite matrix into a product of two lower triangular matrices accor...
Definition: dense_matrix_impl.h:979
libMesh::DenseMatrix::CHOLESKY
Definition: dense_matrix.h:606
MetaPhysicL
Definition: dense_matrix.h:45
libMesh::DenseMatrix::scale_column
void scale_column(const unsigned int col, const T factor)
Multiplies every element in the column col matrix by factor.
Definition: dense_matrix.h:922
libMesh::DenseMatrix::operator*=
DenseMatrix< T > & operator*=(const T factor)
Multiplies every element in the matrix by factor.
Definition: dense_matrix.h:932
libMesh::DenseMatrix::pivot_index_t
int pivot_index_t
Definition: dense_matrix.h:700
libMesh::CompareTypes
Definition: compare_types.h:99
libMesh::DenseMatrix::get_values
std::vector< T > & get_values()
Definition: dense_matrix.h:371
libMesh::DenseMatrix::sub_matrix
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:849
libMesh::boostcopy::enable_if_c
Definition: compare_types.h:38
libMesh::if
if(subdm)
Definition: petsc_dm_wrapper.C:77
libMesh::DenseMatrixBase::condense
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.
Definition: dense_matrix_base_impl.h:73
libMesh::DenseMatrix::LU_BLAS_LAPACK
Definition: dense_matrix.h:606
libMesh::DenseMatrix::NONE
Definition: dense_matrix.h:606
libMesh::DenseMatrix::LEFT_MULTIPLY_TRANSPOSE
Definition: dense_matrix.h:621
libMesh::DenseMatrix::right_multiply
virtual void right_multiply(const DenseMatrixBase< T > &M2) override
Performs the operation: (*this) <- (*this) * M3.
Definition: dense_matrix_impl.h:231
libMesh::DenseMatrix::resize
void resize(const unsigned int new_m, const unsigned int new_n)
Resize the matrix.
Definition: dense_matrix.h:822
libMesh::DenseMatrix::operator+=
DenseMatrix< T > & operator+=(const DenseMatrix< T > &mat)
Adds mat to this matrix.
Definition: dense_matrix.h:986
libMesh::DenseMatrix::max
auto max() const -> decltype(libmesh_real(T(0)))
Definition: dense_matrix.h:1031
libMesh::zero
const Number zero
.
Definition: libmesh.h:243
libMesh::libmesh_assert
libmesh_assert(ctx)
libMesh::IntRange
The IntRange templated class is intended to make it easy to loop over integers which are indices of a...
Definition: int_range.h:53
libMesh::DenseMatrix::swap
void swap(DenseMatrix< T > &other_matrix)
STL-like swap method.
Definition: dense_matrix.h:792
libMesh::DenseMatrix::vector_mult
void vector_mult(DenseVector< T > &dest, const DenseVector< T > &arg) const
Performs the matrix-vector multiplication, dest := (*this) * arg.
Definition: dense_matrix_impl.h:403
libMesh::DenseMatrix::~DenseMatrix
virtual ~DenseMatrix()=default
std::abs
MetaPhysicL::DualNumber< T, D > abs(const MetaPhysicL::DualNumber< T, D > &in)
libMesh::DenseMatrix::_matvec_blas
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.
Definition: dense_matrix_blas_lapack.C:1009
libMesh::DenseMatrixBase
Defines an abstract dense matrix base class for use in Finite Element-type computations.
Definition: dense_matrix_base.h:46
operator!=
bool operator!=(const variant_filter_iterator< Predicate, Type, ReferenceType, PointerType > &x, const variant_filter_iterator< Predicate, Type, ReferenceType, PointerType > &y)
Definition: variant_filter_iterator.h:534
libMesh::DenseMatrix::pivot_index_t
PetscBLASInt pivot_index_t
Array used to store pivot indices.
Definition: dense_matrix.h:698
libMesh::DenseMatrix::_lu_back_substitute
void _lu_back_substitute(const DenseVector< T > &b, DenseVector< T > &x) const
Solves the system Ax=b through back substitution.
Definition: dense_matrix_impl.h:684
libMesh::DenseMatrix::vector_mult_transpose
void vector_mult_transpose(DenseVector< T > &dest, const DenseVector< T > &arg) const
Performs the matrix-vector multiplication, dest := (*this)^T * arg.
Definition: dense_matrix_impl.h:459
std::abs
MetaPhysicL::DualNumber< T, D > abs(MetaPhysicL::DualNumber< T, D > &&in)
libMesh::DenseMatrix::evd_left_and_right
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...
Definition: dense_matrix_impl.h:874
libMesh::ScalarTraits
Definition: compare_types.h:63
MetaPhysicL::DualNumber
Definition: dense_matrix.h:48
libMesh::DenseMatrix::vector_mult_add
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.
Definition: dense_matrix_impl.h:529
A
static PetscErrorCode Mat * A
Definition: petscdmlibmeshimpl.C:1026
libMesh::DenseMatrix::svd_solve
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.
Definition: dense_matrix_impl.h:832
libMesh::DenseMatrix< Real >::_BLAS_Multiply_Flag
_BLAS_Multiply_Flag
Enumeration used to determine the behavior of the _multiply_blas function.
Definition: dense_matrix.h:618
libMesh::DenseMatrix::condense
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:384
libMesh::CompareTypes::supertype
void supertype
Definition: compare_types.h:100
libMesh::DenseMatrix::evd_left
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,...
Definition: dense_matrix_impl.h:852
libMesh::DenseMatrix::zero
virtual void zero() override
Set every element in the matrix to 0.
Definition: dense_matrix.h:838
libMesh::DenseMatrix::el
virtual T & el(const unsigned int i, const unsigned int j) override
Definition: dense_matrix.h:122
libMesh::DenseMatrix::_lu_back_substitute_lapack
void _lu_back_substitute_lapack(const DenseVector< T > &b, DenseVector< T > &x)
Companion function to _lu_decompose_lapack().
Definition: dense_matrix_blas_lapack.C:919
libMesh::DenseMatrix::cholesky_solve
void cholesky_solve(const DenseVector< T2 > &b, DenseVector< T2 > &x)
For symmetric positive definite (SPD) matrices.
Definition: dense_matrix_impl.h:947
libMesh::DenseMatrix::_lu_decompose_lapack
void _lu_decompose_lapack()
Computes an LU factorization of the matrix using the Lapack routine "getrf".
Definition: dense_matrix_blas_lapack.C:210
libMesh::DenseMatrix::operator!=
bool operator!=(const DenseMatrix< T > &mat) const
Definition: dense_matrix.h:973
libMesh::DenseMatrices::RealDenseMatrix
DenseMatrix< Real > RealDenseMatrix
Convenient definition of a real-only dense matrix.
Definition: dense_matrix.h:749
swap
void swap(Iterator &lhs, Iterator &rhs)
swap, used to implement op=
Definition: variant_filter_iterator.h:478
libMesh::DenseMatrix::left_multiply
virtual void left_multiply(const DenseMatrixBase< T > &M2) override
Performs the operation: (*this) <- M2 * (*this)
Definition: dense_matrix_impl.h:58
libMesh::DenseMatrix::DecompositionType
DecompositionType
The decomposition schemes above change the entries of the matrix A.
Definition: dense_matrix.h:606
libMesh::DenseMatrix::_multiply_blas
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.
Definition: dense_matrix_blas_lapack.C:37
std
Definition: float128_shims.h:27
operator=
Iterator & operator=(const Iterator &rhs)
Assignment operator.
Definition: variant_filter_iterator.h:493
libMesh::DenseMatrix::get_principal_submatrix
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.
Definition: dense_matrix_impl.h:574
libMesh::DenseMatrix::det
T det()
Definition: dense_matrix_impl.h:886
libMesh::DenseMatrix::outer_product
void outer_product(const DenseVector< T > &a, const DenseVector< T > &b)
Computes the outer (dyadic) product of two vectors and stores in (*this).
Definition: dense_matrix_impl.h:589
libMesh::DenseMatrix::svd
void svd(DenseVector< Real > &sigma)
Compute the singular value decomposition of the matrix.
Definition: dense_matrix_impl.h:813
libMesh::DenseMatrix::transpose
T transpose(const unsigned int i, const unsigned int j) const
Definition: dense_matrix.h:1106
libMesh::DenseMatrix::operator()
T operator()(const unsigned int i, const unsigned int j) const
Definition: dense_matrix.h:880
libMesh::DenseMatrix::_evd_lapack
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".
Definition: dense_matrix_blas_lapack.C:711
operator==
bool operator==(const variant_filter_iterator< Predicate, Type, ReferenceType, PointerType > &x, const variant_filter_iterator< Predicate, Type, ReferenceType, PointerType > &y)
Definition: variant_filter_iterator.h:523
libMesh::DenseMatrix::l1_norm
auto l1_norm() const -> decltype(std::abs(T(0)))
Definition: dense_matrix.h:1052
libMesh::DenseMatrix::el
virtual T el(const unsigned int i, const unsigned int j) const override
Definition: dense_matrix.h:118
libMesh::DenseMatrix::lu_solve
void lu_solve(const DenseVector< T > &b, DenseVector< T > &x)
Solve the system Ax=b given the input vector b.
Definition: dense_matrix_impl.h:625
libMesh::DenseMatrix::RIGHT_MULTIPLY
Definition: dense_matrix.h:620
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::MeshTools::Modification::scale
void scale(MeshBase &mesh, const Real xs, const Real ys=0., const Real zs=0.)
Scales the mesh.
Definition: mesh_modification.C:243
libMesh::DenseMatrix::_lu_decompose
void _lu_decompose()
Form the LU decomposition of the matrix.
Definition: dense_matrix_impl.h:735
libMesh::DenseMatrix::scale
void scale(const T factor)
Multiplies every element in the matrix by factor.
Definition: dense_matrix.h:913
libMesh::DenseMatrix::operator=
DenseMatrix & operator=(const DenseMatrix &)=default
libMesh::DenseVector
Defines a dense vector for use in Finite Element-type computations.
Definition: meshless_interpolation_function.h:39
libMesh::DenseMatrix::linfty_norm
auto linfty_norm() const -> decltype(std::abs(T(0)))
Definition: dense_matrix.h:1079
libMesh::DenseMatrix::_decomposition_type
DecompositionType _decomposition_type
This flag keeps track of which type of decomposition has been performed on the matrix.
Definition: dense_matrix.h:612
libMesh::DenseMatrix::operator-=
DenseMatrix< T > & operator-=(const DenseMatrix< T > &mat)
Subtracts mat from this matrix.
Definition: dense_matrix.h:998