libmesh解析
本工作只是尝试解析原libmesh的代码,供学习使用
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 
dense_matrix.h
浏览该文件的文档.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2023 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 
69 template<typename T>
70 class DenseMatrix : public DenseMatrixBase<T>
71 {
72 public:
73 
80  DenseMatrix(const unsigned int new_m=0,
81  const unsigned int new_n=0);
82 
90  template <typename T2>
91  DenseMatrix(unsigned int nrow,
92  unsigned int ncol,
93  std::initializer_list<T2> init_list);
94 
98  DenseMatrix (DenseMatrix &&) = default;
102  DenseMatrix (const DenseMatrix &) = default;
106  DenseMatrix & operator= (const DenseMatrix &) = default;
110  DenseMatrix & operator= (DenseMatrix &&) = default;
114  virtual ~DenseMatrix() = default;
115 
120  virtual void zero() override final;
121 
131  DenseMatrix sub_matrix(unsigned int row_id, unsigned int row_size,
132  unsigned int col_id, unsigned int col_size) const;
133 
141  T operator() (const unsigned int i,
142  const unsigned int j) const;
143 
151  T & operator() (const unsigned int i,
152  const unsigned int j);
160  virtual T el(const unsigned int i,
161  const unsigned int j) const override final
162  { return (*this)(i,j); }
163 
171  virtual T & el(const unsigned int i,
172  const unsigned int j) override final
173  { return (*this)(i,j); }
174 
180  virtual void left_multiply (const DenseMatrixBase<T> & M2) override final;
181 
188  template <typename T2>
189  void left_multiply (const DenseMatrixBase<T2> & M2);
190 
196  virtual void right_multiply (const DenseMatrixBase<T> & M2) override final;
197 
204  template <typename T2>
205  void right_multiply (const DenseMatrixBase<T2> & M2);
206 
213  void vector_mult (DenseVector<T> & dest,
214  const DenseVector<T> & arg) const;
215 
223  template <typename T2>
224  void vector_mult (DenseVector<typename CompareTypes<T,T2>::supertype> & dest,
225  const DenseVector<T2> & arg) const;
226 
234  const DenseVector<T> & arg) const;
235 
243  template <typename T2>
244  void vector_mult_transpose (DenseVector<typename CompareTypes<T,T2>::supertype> & dest,
245  const DenseVector<T2> & arg) const;
246 
255  void vector_mult_add (DenseVector<T> & dest,
256  const T factor,
257  const DenseVector<T> & arg) const;
258 
266  template <typename T2, typename T3>
267  void vector_mult_add (DenseVector<typename CompareTypes<T, typename CompareTypes<T2,T3>::supertype>::supertype> & dest,
268  const T2 factor,
269  const DenseVector<T3> & arg) const;
270 
278  void get_principal_submatrix (unsigned int sub_m, unsigned int sub_n, DenseMatrix<T> & dest) const;
279 
286  void get_principal_submatrix (unsigned int sub_m, DenseMatrix<T> & dest) const;
287 
304  void outer_product(const DenseVector<T> & a, const DenseVector<T> & b);
305 
314  template <typename T2>
315  DenseMatrix<T> & operator = (const DenseMatrix<T2> & other_matrix);
316 
322  void swap(DenseMatrix<T> & other_matrix);
323 
333  void resize(const unsigned int new_m,
334  const unsigned int new_n);
335 
341  void scale (const T factor);
342 
349  void scale_column (const unsigned int col, const T factor);
350 
356  DenseMatrix<T> & operator *= (const T factor);
357 
364  template<typename T2, typename T3>
365  typename boostcopy::enable_if_c<
366  ScalarTraits<T2>::value, void >::type add (const T2 factor,
367  const DenseMatrix<T3> & mat);
368 
375  bool operator== (const DenseMatrix<T> & mat) const;
376 
383  bool operator!= (const DenseMatrix<T> & mat) const;
384 
391 
398 
404  auto min () const -> decltype(libmesh_real(T(0)));
405 
411  auto max () const -> decltype(libmesh_real(T(0)));
412 
420  auto l1_norm () const -> decltype(std::abs(T(0)));
421 
429  auto linfty_norm () const -> decltype(std::abs(T(0)));
430 
436  void left_multiply_transpose (const DenseMatrix<T> & A);
437 
444  template <typename T2>
445  void left_multiply_transpose (const DenseMatrix<T2> & A);
446 
447 
453  void right_multiply_transpose (const DenseMatrix<T> & A);
454 
461  template <typename T2>
462  void right_multiply_transpose (const DenseMatrix<T2> & A);
463 
471  T transpose (const unsigned int i,
472  const unsigned int j) const;
473 
479  void get_transpose(DenseMatrix<T> & dest) const;
480 
488  std::vector<T> & get_values() { return _val; }
489 
495  const std::vector<T> & get_values() const { return _val; }
496 
507  void condense(const unsigned int i,
508  const unsigned int j,
509  const T val,
510  DenseVector<T> & rhs)
511  { DenseMatrixBase<T>::condense (i, j, val, rhs); }
512 
527  void lu_solve (const DenseVector<T> & b,
528  DenseVector<T> & x);
529 
546  template <typename T2>
547  void cholesky_solve(const DenseVector<T2> & b,
548  DenseVector<T2> & x);
549 
558  void svd(DenseVector<Real> & sigma);
559 
572  void svd(DenseVector<Real> & sigma,
574  DenseMatrix<Number> & VT);
575 
591  void svd_solve(const DenseVector<T> & rhs,
592  DenseVector<T> & x,
593  Real rcond=std::numeric_limits<Real>::epsilon()) const;
594 
605  void evd(DenseVector<T> & lambda_real,
606  DenseVector<T> & lambda_imag);
607 
626  void evd_left(DenseVector<T> & lambda_real,
627  DenseVector<T> & lambda_imag,
628  DenseMatrix<T> & VL);
629 
648  void evd_right(DenseVector<T> & lambda_real,
649  DenseVector<T> & lambda_imag,
650  DenseMatrix<T> & VR);
651 
665  void evd_left_and_right(DenseVector<T> & lambda_real,
666  DenseVector<T> & lambda_imag,
667  DenseMatrix<T> & VL,
668  DenseMatrix<T> & VR);
669 
678  T det();
679 
688  // void inverse();
689 
695 
700  {
701  static const bool value = false;
702  };
703 
704 private:
705 
709  std::vector<T> _val;
710 
714  void _lu_decompose ();
715 
719  void _lu_back_substitute (const DenseVector<T> & b,
720  DenseVector<T> & x) const;
721 
727  void _cholesky_decompose();
728 
738  template <typename T2>
740  DenseVector<T2> & x) const;
741 
747 
752 
761  };
762 
772  void _multiply_blas(const DenseMatrixBase<T> & other,
773  _BLAS_Multiply_Flag flag);
774 
780  void _lu_decompose_lapack();
781 
788  void _svd_lapack(DenseVector<Real> & sigma);
789 
798  void _svd_lapack(DenseVector<Real> & sigma,
800  DenseMatrix<Number> & VT);
801 
809  void _svd_solve_lapack(const DenseVector<T> & rhs,
810  DenseVector<T> & x,
811  Real rcond) const;
812 
823  void _svd_helper (char JOBU,
824  char JOBVT,
825  std::vector<Real> & sigma_val,
826  std::vector<Number> & U_val,
827  std::vector<Number> & VT_val);
828 
839  void _evd_lapack(DenseVector<T> & lambda_real,
840  DenseVector<T> & lambda_imag,
841  DenseMatrix<T> * VL = nullptr,
842  DenseMatrix<T> * VR = nullptr);
843 
848 #if (LIBMESH_HAVE_PETSC && LIBMESH_USE_REAL_NUMBERS)
849  typedef PetscBLASInt pivot_index_t;
850 #else
851  typedef int pivot_index_t;
852 #endif
853  std::vector<pivot_index_t> _pivots;
854 
865  DenseVector<T> & x);
866 
883  void _matvec_blas(T alpha, T beta,
884  DenseVector<T> & dest,
885  const DenseVector<T> & arg,
886  bool trans=false) const;
887 
894  template <typename T2>
895  void _left_multiply_transpose (const DenseMatrix<T2> & A);
896 
903  template <typename T2>
905 };
906 
907 
908 
909 
910 
911 // ------------------------------------------------------------
915 namespace DenseMatrices
916 {
917 
922 
929 
930 }
931 
932 
933 
934 using namespace DenseMatrices;
935 
936 // 由于 libmesh/PETSc 使用复数时,PETSc Lapack 包装器仅适用于 PetscScalar,
937 // 因此不能获得 DenseMatrix<Real>::lu_solve() 的 Lapack 版本,
938 // 当 libmesh/PETSc 用复数编译时。
939 #if defined(LIBMESH_HAVE_PETSC) && \
940  defined(LIBMESH_USE_REAL_NUMBERS) && \
941  defined(LIBMESH_DEFAULT_DOUBLE_PRECISION)
942 template <>
943 struct DenseMatrix<double>::UseBlasLapack
944 {
945  static const bool value = true;
946 };
947 #endif
948 
949 
950 // ------------------------------------------------------------
951 // Dense Matrix 成员函数
952 template<typename T>
953 inline
954 DenseMatrix<T>::DenseMatrix(const unsigned int new_m,
955  const unsigned int new_n) :
956  DenseMatrixBase<T>(new_m,new_n),
957  use_blas_lapack(DenseMatrix<T>::UseBlasLapack::value),
958  _val(),
959  _decomposition_type(NONE)
960 {
961  this->resize(new_m,new_n);
962 }
963 
964 template <typename T>
965 template <typename T2>
966 DenseMatrix<T>::DenseMatrix(unsigned int nrow,
967  unsigned int ncol,
968  std::initializer_list<T2> init_list) :
969  DenseMatrixBase<T>(nrow, ncol),
970  use_blas_lapack(DenseMatrix<T>::UseBlasLapack::value),
971  _val(init_list.begin(), init_list.end()),
972  _decomposition_type(NONE)
973 {
974  // 确保传递的数据量与矩阵大小一致。
975  libmesh_assert_equal_to(nrow * ncol, init_list.size());
976 }
977 
978 
979 
980 template<typename T>
981 inline
983 {
984  std::swap(this->_m, other_matrix._m);
985  std::swap(this->_n, other_matrix._n);
986  _val.swap(other_matrix._val);
987  DecompositionType _temp = _decomposition_type;
988  _decomposition_type = other_matrix._decomposition_type;
989  other_matrix._decomposition_type = _temp;
990 }
991 
992 
993 template <typename T>
994 template <typename T2>
995 inline
998 {
999  unsigned int mat_m = mat.m(), mat_n = mat.n();
1000  this->resize(mat_m, mat_n);
1001  for (unsigned int i=0; i<mat_m; i++)
1002  for (unsigned int j=0; j<mat_n; j++)
1003  (*this)(i,j) = mat(i,j);
1004 
1005  return *this;
1006 }
1007 
1008 
1009 
1010 template<typename T>
1011 inline
1012 void DenseMatrix<T>::resize(const unsigned int new_m,
1013  const unsigned int new_n)
1014 {
1015  _val.resize(new_m*new_n);
1016 
1017  this->_m = new_m;
1018  this->_n = new_n;
1019 
1020  // zero and set decomposition_type to NONE
1021  this->zero();
1022 }
1023 
1024 
1025 
1026 template<typename T>
1027 inline
1029 {
1030  _decomposition_type = NONE;
1031 
1032  std::fill (_val.begin(), _val.end(), static_cast<T>(0));
1033 }
1034 
1035 
1036 
1037 template<typename T>
1038 inline
1039 DenseMatrix<T> DenseMatrix<T>::sub_matrix(unsigned int row_id, unsigned int row_size,
1040  unsigned int col_id, unsigned int col_size) const
1041 {
1042  libmesh_assert_less (row_id + row_size - 1, this->_m);
1043  libmesh_assert_less (col_id + col_size - 1, this->_n);
1044 
1045  DenseMatrix<T> sub;
1046  sub._m = row_size;
1047  sub._n = col_size;
1048  sub._val.resize(row_size * col_size);
1049 
1050  unsigned int end_col = this->_n - col_size - col_id;
1051  unsigned int p = row_id * this->_n;
1052  unsigned int q = 0;
1053  for (unsigned int i=0; i<row_size; i++)
1054  {
1055  // 跳到开头的列
1056  p += col_id;
1057  for (unsigned int j=0; j<col_size; j++)
1058  sub._val[q++] = _val[p++];
1059  // 跳过剩余的列
1060  p += end_col;
1061  }
1062 
1063  return sub;
1064 }
1065 
1066 
1067 
1068 template<typename T>
1069 inline
1070 T DenseMatrix<T>::operator () (const unsigned int i,
1071  const unsigned int j) const
1072 {
1073  libmesh_assert_less (i*j, _val.size());
1074  libmesh_assert_less (i, this->_m);
1075  libmesh_assert_less (j, this->_n);
1076 
1077 
1078  // return _val[(i) + (this->_m)*(j)]; // col-major
1079  return _val[(i)*(this->_n) + (j)]; // row-major
1080 }
1081 
1082 
1083 
1084 template<typename T>
1085 inline
1086 T & DenseMatrix<T>::operator () (const unsigned int i,
1087  const unsigned int j)
1088 {
1089  libmesh_assert_less (i*j, _val.size());
1090  libmesh_assert_less (i, this->_m);
1091  libmesh_assert_less (j, this->_n);
1092 
1093  //return _val[(i) + (this->_m)*(j)]; // col-major
1094  return _val[(i)*(this->_n) + (j)]; // row-major
1095 }
1096 
1097 
1098 
1099 
1100 
1101 template<typename T>
1102 inline
1103 void DenseMatrix<T>::scale (const T factor)
1104 {
1105  for (auto & v : _val)
1106  v *= factor;
1107 }
1108 
1109 
1110 template<typename T>
1111 inline
1112 void DenseMatrix<T>::scale_column (const unsigned int col, const T factor)
1113 {
1114  for (auto i : make_range(this->m()))
1115  (*this)(i, col) *= factor;
1116 }
1117 
1118 
1119 
1120 template<typename T>
1121 inline
1123 {
1124  this->scale(factor);
1125  return *this;
1126 }
1127 
1128 
1129 
1130 template<typename T>
1131 template<typename T2, typename T3>
1132 inline
1133 typename boostcopy::enable_if_c<
1134  ScalarTraits<T2>::value, void >::type
1135 DenseMatrix<T>::add (const T2 factor,
1136  const DenseMatrix<T3> & mat)
1137 {
1138  libmesh_assert_equal_to (this->m(), mat.m());
1139  libmesh_assert_equal_to (this->n(), mat.n());
1140 
1141  for (auto i : make_range(this->m()))
1142  for (auto j : make_range(this->n()))
1143  (*this)(i,j) += factor * mat(i,j);
1144 }
1145 
1146 
1147 
1148 template<typename T>
1149 inline
1151 {
1152  for (auto i : index_range(_val))
1153  if (_val[i] != mat._val[i])
1154  return false;
1155 
1156  return true;
1157 }
1158 
1159 
1160 
1161 template<typename T>
1162 inline
1164 {
1165  for (auto i : index_range(_val))
1166  if (_val[i] != mat._val[i])
1167  return true;
1168 
1169  return false;
1170 }
1171 
1172 
1173 
1174 template<typename T>
1175 inline
1177 {
1178  for (auto i : index_range(_val))
1179  _val[i] += mat._val[i];
1180 
1181  return *this;
1182 }
1183 
1184 
1185 
1186 template<typename T>
1187 inline
1189 {
1190  for (auto i : index_range(_val))
1191  _val[i] -= mat._val[i];
1192 
1193  return *this;
1194 }
1195 
1196 
1197 
1198 template<typename T>
1199 inline
1200 auto DenseMatrix<T>::min () const -> decltype(libmesh_real(T(0)))
1201 {
1202  libmesh_assert (this->_m);
1203  libmesh_assert (this->_n);
1204  auto my_min = libmesh_real((*this)(0,0));
1205 
1206  for (unsigned int i=0; i!=this->_m; i++)
1207  {
1208  for (unsigned int j=0; j!=this->_n; j++)
1209  {
1210  auto current = libmesh_real((*this)(i,j));
1211  my_min = (my_min < current? my_min : current);
1212  }
1213  }
1214  return my_min;
1215 }
1216 
1217 
1218 
1219 template<typename T>
1220 inline
1221 auto DenseMatrix<T>::max () const -> decltype(libmesh_real(T(0)))
1222 {
1223  libmesh_assert (this->_m);
1224  libmesh_assert (this->_n);
1225  auto my_max = libmesh_real((*this)(0,0));
1226 
1227  for (unsigned int i=0; i!=this->_m; i++)
1228  {
1229  for (unsigned int j=0; j!=this->_n; j++)
1230  {
1231  auto current = libmesh_real((*this)(i,j));
1232  my_max = (my_max > current? my_max : current);
1233  }
1234  }
1235  return my_max;
1236 }
1237 
1238 
1239 
1240 template<typename T>
1241 inline
1242 auto DenseMatrix<T>::l1_norm () const -> decltype(std::abs(T(0)))
1243 {
1244  libmesh_assert (this->_m);
1245  libmesh_assert (this->_n);
1246 
1247  auto columnsum = std::abs(T(0));
1248  for (unsigned int i=0; i!=this->_m; i++)
1249  {
1250  columnsum += std::abs((*this)(i,0));
1251  }
1252  auto my_max = columnsum;
1253  for (unsigned int j=1; j!=this->_n; j++)
1254  {
1255  columnsum = 0.;
1256  for (unsigned int i=0; i!=this->_m; i++)
1257  {
1258  columnsum += std::abs((*this)(i,j));
1259  }
1260  my_max = (my_max > columnsum? my_max : columnsum);
1261  }
1262  return my_max;
1263 }
1264 
1265 
1266 
1267 template<typename T>
1268 inline
1269 auto DenseMatrix<T>::linfty_norm () const -> decltype(std::abs(T(0)))
1270 {
1271  libmesh_assert (this->_m);
1272  libmesh_assert (this->_n);
1273 
1274  auto rowsum = std::abs(T(0));
1275  for (unsigned int j=0; j!=this->_n; j++)
1276  {
1277  rowsum += std::abs((*this)(0,j));
1278  }
1279  auto my_max = rowsum;
1280  for (unsigned int i=1; i!=this->_m; i++)
1281  {
1282  rowsum = 0.;
1283  for (unsigned int j=0; j!=this->_n; j++)
1284  {
1285  rowsum += std::abs((*this)(i,j));
1286  }
1287  my_max = (my_max > rowsum? my_max : rowsum);
1288  }
1289  return my_max;
1290 }
1291 
1292 
1293 
1294 template<typename T>
1295 inline
1296 T DenseMatrix<T>::transpose (const unsigned int i,
1297  const unsigned int j) const
1298 {
1299  // Implement in terms of operator()
1300  return (*this)(j,i);
1301 }
1302 
1303 
1304 
1305 
1306 
1307 // template<typename T>
1308 // inline
1309 // void DenseMatrix<T>::condense(const unsigned int iv,
1310 // const unsigned int jv,
1311 // const T val,
1312 // DenseVector<T> & rhs)
1313 // {
1314 // libmesh_assert_equal_to (this->_m, rhs.size());
1315 // libmesh_assert_equal_to (iv, jv);
1316 
1317 
1318 // // move the known value into the RHS
1319 // // and zero the column
1320 // for (auto i : make_range(this->m()))
1321 // {
1322 // rhs(i) -= ((*this)(i,jv))*val;
1323 // (*this)(i,jv) = 0.;
1324 // }
1325 
1326 // // zero the row
1327 // for (auto j : make_range(this->n()))
1328 // (*this)(iv,j) = 0.;
1329 
1330 // (*this)(iv,jv) = 1.;
1331 // rhs(iv) = val;
1332 
1333 // }
1334 
1335 
1336 
1337 
1338 } // namespace libMesh
1339 
1340 #ifdef LIBMESH_HAVE_METAPHYSICL
1341 namespace MetaPhysicL
1342 {
1343 template <typename T>
1344 struct RawType<libMesh::DenseMatrix<T>>
1345 {
1347 
1349  {
1350  const auto m = in.m(), n = in.n();
1351  value_type ret(m, n);
1352  for (unsigned int i = 0; i < m; ++i)
1353  for (unsigned int j = 0; j < n; ++j)
1354  ret(i,j) = raw_value(in(i,j));
1355 
1356  return ret;
1357  }
1358 };
1359 }
1360 #endif
1361 
1362 
1363 #endif // LIBMESH_DENSE_MATRIX_H
T libmesh_real(T a)
bool operator!=(const DenseMatrix< T > &mat) const
检查矩阵是否与另一个矩阵 mat 完全不相等。
void _matvec_blas(T alpha, T beta, DenseVector< T > &dest, const DenseVector< T > &arg, bool trans=false) const
使用BLAS GEMV函数(通过PETSc)计算
void _lu_back_substitute(const DenseVector< T > &b, DenseVector< T > &x) const
通过回代步骤解方程Ax=b。此函数是私有的,因为它仅在lu_solve(...)函数的实现部分中被调用。
void swap(DenseMatrix< T > &other_matrix)
STL 风格的交换方法,交换值和分解方法。
Definition: dense_matrix.h:982
void condense(const unsigned int i, const unsigned int j, const T val, DenseVector< T > &rhs)
将矩阵的 (i,j) 元素凝聚出来,强制其取值为 val。
Definition: dense_matrix.h:507
unsigned int n() const
返回矩阵的列维度。
DenseMatrix< Complex > ComplexDenseMatrix
此typedef可能是仅包含实数的矩阵,也可能是真正的复数矩阵, 具体取决于 libmesh_common.h 中如何定义 Number。 此外,要注意对于实数数据,DenseMatrix&lt;T&gt; 可能比...
Definition: dense_matrix.h:928
void _lu_decompose_lapack()
使用Lapack例程“getrf”计算矩阵的LU分解。此例程只能由lu_solve()函数的“use_blas_lapack”分支使用。 调用此函数后,矩阵将被其因式分解版本替换,并且Decomposi...
void svd_solve(const DenseVector< T > &rhs, DenseVector< T > &x, Real rcond=std::numeric_limits< Real >::epsilon()) const
以最小二乘意义解方程组 。 可能是非方阵和/或秩亏的。 可以通过更改“rcond”参数来控制哪些奇异值被视为零。 对于满足S(i) &lt;= rcond*S(1)的奇异值S(i),在解的目的上被视为零。 ...
virtual void zero() overridefinal
将矩阵的所有元素设置为0,并重置任何可能先前设置的分解标志。 这允许例如计算新的LU分解,同时重用相同的存储空间。
auto max() const -> decltype(libmesh_real(T(0)))
返回矩阵的最大元素或复数情况下的最大实部。
_BLAS_Multiply_Flag
用于确定_multiply_blas函数行为的枚举。
Definition: dense_matrix.h:756
const std::vector< T > & get_values() const
返回底层数据存储矢量的常量引用。
Definition: dense_matrix.h:495
DenseMatrix< T > & operator+=(const DenseMatrix< T > &mat)
将矩阵 mat 添加到此矩阵。
virtual void left_multiply(const DenseMatrixBase< T > &M2) overridefinal
左乘以矩阵 M2。
DecompositionType _decomposition_type
此标志跟踪在矩阵上执行的分解类型。
Definition: dense_matrix.h:751
void vector_mult_transpose(DenseVector< T > &dest, const DenseVector< T > &arg) const
执行矩阵-向量乘法,dest := (*this)^T * arg。
bool operator==(const DenseMatrix< T > &mat) const
检查矩阵是否与另一个矩阵 mat 完全相等。
void evd_left(DenseVector< T > &lambda_real, DenseVector< T > &lambda_imag, DenseMatrix< T > &VL)
计算一般矩阵 的特征值(实部和虚部)和左特征向量。
virtual ~DenseMatrix()=default
析构函数。析构函数使用默认实现,因为该类不管理任何内存。
void _cholesky_back_substitute(const DenseVector< T2 > &b, DenseVector< T2 > &x) const
根据矩阵A的Cholesky分解解方程Ax=b,得到未知值x和rhs b。
void evd_left_and_right(DenseVector< T > &lambda_real, DenseVector< T > &lambda_imag, DenseMatrix< T > &VL, DenseMatrix< T > &VR)
计算一般矩阵的特征值(实部和虚部),以及左右特征向量。
auto l1_norm() const -> decltype(std::abs(T(0)))
返回矩阵的 l1-范数,即最大列和
void get_transpose(DenseMatrix< T > &dest) const
将转置矩阵存储在 dest 中。
DenseMatrix< T > & operator-=(const DenseMatrix< T > &mat)
从此矩阵中减去矩阵 mat。
const Number zero
.
Definition: libmesh.h:248
bool use_blas_lapack
计算密矩阵的逆(假设可逆性), 首先计算LU分解,然后执行多次回代步骤。 遵循在Web上提供的Numerical Recipes in C中的算法。
Definition: dense_matrix.h:694
T det()
返回矩阵的行列式。
void _multiply_blas(const DenseMatrixBase< T > &other, _BLAS_Multiply_Flag flag)
_multiply_blas函数使用BLAS gemm函数计算A &lt;- op(A) * op(B)。 用于right_multiply()、left_multiply()、right_multiply_...
DenseMatrix(const unsigned int new_m=0, const unsigned int new_n=0)
构造函数。创建一个维度为 m x n 的密集矩阵。
Definition: dense_matrix.h:954
void outer_product(const DenseVector< T > &a, const DenseVector< T > &b)
计算两个向量的外积并将结果存储在 (*this) 中。
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
计算自动微分实数向量的绝对值。
Definition: type_vector.h:112
void scale_column(const unsigned int col, const T factor)
将矩阵的第 col 列的每个元素乘以 factor。
libMesh::DenseMatrix< typename RawType< T >::value_type > value_type
DenseMatrix & operator=(const DenseMatrix &)=default
复制赋值运算符。复制赋值运算符使用默认实现,因为该类不管理任何内存。
unsigned int m() const
返回矩阵的行维度。
void _lu_back_substitute_lapack(const DenseVector< T > &b, DenseVector< T > &x)
与_lu_decompose_lapack()相对应的伴随函数。不要直接使用,通过公共lu_solve()接口调用。 由于我们只是调用LAPACK例程,该函数在逻辑上是const的,因为它不修改矩阵, ...
void svd(DenseVector< Real > &sigma)
计算矩阵的奇异值分解(SVD)。 在退出时,sigma包含所有奇异值(按降序排列)。
auto linfty_norm() const -> decltype(std::abs(T(0)))
返回矩阵的 linfty-范数,即最大行和
void _lu_decompose()
形成矩阵的LU分解。此函数是私有的,因为它仅在lu_solve(...)函数的实现部分中被调用。
void vector_mult_add(DenseVector< T > &dest, const T factor, const DenseVector< T > &arg) const
执行缩放矩阵-向量乘法,结果存储在 dest 中。 dest += factor * (*this) * arg.
T transpose(const unsigned int i, const unsigned int j) const
返回转置矩阵的 (i, j) 元素。
boostcopy::enable_if_c< ScalarTraits< T2 >::value, void >::type add(const T2 factor, const DenseMatrix< T3 > &mat)
将 factor 倍的矩阵 mat 添加到此矩阵。
void get_principal_submatrix(unsigned int sub_m, unsigned int sub_n, DenseMatrix< T > &dest) const
将 sub_m x sub_n 的主子矩阵放入 dest 中。
DenseMatrix< Real > RealDenseMatrix
仅包含实数的密集矩阵的方便定义。
Definition: dense_matrix.h:921
void evd_right(DenseVector< T > &lambda_real, DenseVector< T > &lambda_imag, DenseMatrix< T > &VR)
计算一般矩阵 的特征值(实部和虚部)和右特征向量。
virtual void right_multiply(const DenseMatrixBase< T > &M2) overridefinal
右乘以矩阵 M2。
void _cholesky_decompose()
将对称正定矩阵分解为两个下三角矩阵的乘积,即A = LL^T。
void _svd_lapack(DenseVector< Real > &sigma)
使用Lapack例程“getsvd”计算矩阵的奇异值分解。 [ 在dense_matrix_blas_lapack.C中实现 ]
std::vector< T > & get_values()
返回对应于存储向量的引用的底层数据存储矢量。
Definition: dense_matrix.h:488
T operator()(const unsigned int i, const unsigned int j) const
获取矩阵的 (i,j) 元素。
void right_multiply_transpose(const DenseMatrix< T > &A)
用矩阵 A 的转置右乘。
void scale(const T factor)
将矩阵的每个元素乘以 factor。
void lu_solve(const DenseVector< T > &b, DenseVector< T > &x)
解方程组 给定输入向量 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)
使用Lapack例程“DGEEV”计算矩阵的特征值。如果VR和/或VL不为nullptr, 则此函数还计算并返回右和/或左特征向量的矩阵。 [ 在dense_matrix_blas_lapack.C中实现 ]
void evd(DenseVector< T > &lambda_real, DenseVector< T > &lambda_imag)
计算一般矩阵的特征值(实部和虚部)。
void left_multiply_transpose(const DenseMatrix< T > &A)
用矩阵 A 的转置左乘。
static value_type value(const libMesh::DenseMatrix< T > &in)
void _left_multiply_transpose(const DenseMatrix< T2 > &A)
由矩阵 A 的转置左乘,该矩阵可能包含不同的数值类型。
用于确定是否使用blas_lapack的辅助结构。
Definition: dense_matrix.h:699
void resize(const unsigned int new_m, const unsigned int new_n)
调整矩阵的大小,并调用 zero() 方法。
auto min() const -> decltype(libmesh_real(T(0)))
返回矩阵的最小元素或复数情况下的最小实部。
DenseMatrix sub_matrix(unsigned int row_id, unsigned int row_size, unsigned int col_id, unsigned int col_size) const
获取具有最小行和列索引以及子矩阵大小的子矩阵。
std::vector< T > _val
实际的数据值,存储为1D数组。
Definition: dense_matrix.h:709
void cholesky_solve(const DenseVector< T2 > &b, DenseVector< T2 > &x)
对于对称正定矩阵(SPD),进行Cholesky分解。 分解为 A = L L^T,比标准LU分解大约快两倍。 因此,如果事先知道矩阵是SPD,则可以使用此方法。如果矩阵不是SPD,则会生成错误。 Ch...
定义用于有限元计算的稠密向量类。该类基本上是为了补充 DenseMatrix 类而设计的。 它相对于 std::vector 具有额外的功能,使其在有限元中特别有用,特别是对于方程组。 所有重写的虚拟函...
Definition: dof_map.h:64
void _svd_solve_lapack(const DenseVector< T > &rhs, DenseVector< T > &x, Real rcond) const
由svd_solve(rhs)调用。
void _right_multiply_transpose(const DenseMatrix< T2 > &A)
由矩阵 A 的转置右乘,该矩阵可能包含不同的数值类型。
DenseMatrix< T > & operator*=(const T factor)
将矩阵的每个元素乘以 factor。
为有限元类型的计算定义了一个抽象的稠密矩阵基类。例如 DenseSubMatrices 可以从这个类派生出来。
virtual T & el(const unsigned int i, const unsigned int j) overridefinal
获取矩阵的 (i,j) 元素的可写引用。
Definition: dense_matrix.h:171
void vector_mult(DenseVector< T > &dest, const DenseVector< T > &arg) const
执行矩阵-向量乘法,dest := (*this) * arg。
void _svd_helper(char JOBU, char JOBVT, std::vector< Real > &sigma_val, std::vector< Number > &U_val, std::vector< Number > &VT_val)
实际执行SVD的辅助函数。 [ 在dense_matrix_blas_lapack.C中实现 ]
DecompositionType
_cholesky_back_substitute 的分解方案会改变矩阵A的条目。因此,在调用A.lu_solve()后再次调用A.cholesky_solve()是错误的, 因为结果可能不符合任何预期...
Definition: dense_matrix.h:746
定义用于有限元类型计算的密集矩阵。 用于在求和成全局矩阵之前存储单元刚度矩阵。所有被覆盖的虚函数都记录在dense_matrix_base.h中。
Definition: dof_map.h:65
std::vector< pivot_index_t > _pivots
Definition: dense_matrix.h:853
PetscBLASInt pivot_index_t
用于存储枢轴索引的数组。可能被当前活动的任何因式分解使用, 类的客户端不应出于任何原因依赖它。
Definition: dense_matrix.h:849
void condense(const unsigned int i, const unsigned int j, const T val, DenseVectorBase< T > &rhs)
将矩阵的 (i,j) 条目压缩出来,强制它取值为 val。这对于在数值模拟中应用边界条件很有用。 保留矩阵的对称性。
virtual T el(const unsigned int i, const unsigned int j) const overridefinal
获取矩阵的 (i,j) 元素。
Definition: dense_matrix.h:160