16 #ifndef dealii_full_matrix_h 17 #define dealii_full_matrix_h 20 #include <deal.II/base/config.h> 22 #include <deal.II/base/numbers.h> 23 #include <deal.II/base/table.h> 24 #include <deal.II/base/tensor.h> 26 #include <deal.II/differentiation/ad/ad_number_traits.h> 28 #include <deal.II/lac/exceptions.h> 29 #include <deal.II/lac/identity_matrix.h> 35 DEAL_II_NAMESPACE_OPEN
39 template <
typename number>
41 template <
typename number>
69 template <
typename number>
77 "The FullMatrix class does not support auto-differentiable numbers.");
88 using value_type = number;
103 class const_iterator;
275 template <
typename number2>
304 template <
typename number2>
314 template <
typename MatrixType>
323 template <
typename MatrixType>
337 const unsigned int src_r_i = 0,
338 const unsigned int src_r_j = dim - 1,
339 const unsigned int src_c_i = 0,
340 const unsigned int src_c_j = dim - 1,
357 const unsigned int dst_r = 0,
358 const unsigned int dst_c = 0)
const;
372 template <
typename MatrixType,
typename index_type>
375 const std::vector<index_type> &row_index_set,
376 const std::vector<index_type> &column_index_set);
390 template <
typename MatrixType,
typename index_type>
393 const std::vector<index_type> &column_index_set,
394 MatrixType &
matrix)
const;
406 template <
typename number2>
418 template <
typename number2>
420 fill(
const number2 *);
433 template <
typename number2>
436 const std::vector<size_type> &p_rows,
437 const std::vector<size_type> &p_cols);
506 template <
typename number2>
519 template <
typename number2>
522 const Vector<number2> &v)
const;
581 template <
class StreamType>
583 print(StreamType & s,
584 const unsigned int width = 5,
585 const unsigned int precision = 2)
const;
611 const unsigned int precision = 3,
612 const bool scientific =
true,
613 const unsigned int width = 0,
614 const char * zero_string =
" ",
615 const double denominator = 1.,
616 const double threshold = 0.)
const;
676 template <
typename number2>
687 template <
typename number2>
702 template <
typename number2>
722 template <
typename number2>
736 template <
typename number2>
751 template <
typename number2>
775 template <
typename number2,
typename index_type>
779 const index_type *col_indices,
781 const bool elide_zero_values =
true,
782 const bool col_indices_are_sorted =
false);
840 template <
typename number2>
847 template <
typename number2>
857 template <
typename number2>
898 template <
typename number2>
910 template <
typename number2>
918 template <
typename number2>
920 outer_product(
const Vector<number2> &V,
const Vector<number2> &W);
927 template <
typename number2>
936 template <
typename number2>
962 template <
typename number2>
966 const bool adding =
false)
const;
986 template <
typename number2>
990 const bool adding =
false)
const;
1010 template <
typename number2>
1014 const bool adding =
false)
const;
1035 template <
typename number2>
1039 const bool adding =
false)
const;
1055 const bool transpose_B =
false,
1056 const bool transpose_D =
false,
1057 const number scaling = number(1.));
1071 template <
typename number2>
1073 vmult(Vector<number2> & w,
1074 const Vector<number2> &v,
1075 const bool adding =
false)
const;
1082 template <
typename number2>
1084 vmult_add(Vector<number2> &w,
const Vector<number2> &v)
const;
1099 template <
typename number2>
1101 Tvmult(Vector<number2> & w,
1102 const Vector<number2> &v,
1103 const bool adding =
false)
const;
1111 template <
typename number2>
1113 Tvmult_add(Vector<number2> &w,
const Vector<number2> &v)
const;
1120 template <
typename somenumber>
1123 const Vector<somenumber> &src,
1124 const number omega = 1.)
const;
1132 template <
typename number2,
typename number3>
1135 const Vector<number2> &x,
1136 const Vector<number3> &b)
const;
1148 template <
typename number2>
1150 forward(Vector<number2> &dst,
const Vector<number2> &src)
const;
1159 template <
typename number2>
1161 backward(Vector<number2> &dst,
const Vector<number2> &src)
const;
1181 <<
"The maximal pivot is " << arg1
1182 <<
", which is below the threshold. The matrix may be singular.");
1190 <<
"Target region not in matrix: size in this direction=" 1191 << arg1 <<
", size of new matrix=" << arg2
1192 <<
", offset=" << arg3);
1197 "You are attempting an operation on two matrices that " 1198 "are the same object, but the operation requires that the " 1199 "two objects are in fact different.");
1216 template <
typename number>
1220 return this->n_rows();
1225 template <
typename number>
1229 return this->n_cols();
1234 template <
typename number>
1249 template <
typename number>
1250 template <
typename number2>
1259 template <
typename number>
1260 template <
typename MatrixType>
1264 this->
reinit(M.m(), M.n());
1271 const typename MatrixType::const_iterator end_row = M.end(
row);
1272 for (
typename MatrixType::const_iterator entry = M.begin(
row);
1275 this->
el(
row, entry->column()) = entry->value();
1281 template <
typename number>
1282 template <
typename MatrixType>
1286 this->
reinit(M.n(), M.m());
1293 const typename MatrixType::const_iterator end_row = M.end(
row);
1294 for (
typename MatrixType::const_iterator entry = M.begin(
row);
1297 this->
el(entry->column(),
row) = entry->value();
1303 template <
typename number>
1304 template <
typename MatrixType,
typename index_type>
1307 const MatrixType &
matrix,
1308 const std::vector<index_type> &row_index_set,
1309 const std::vector<index_type> &column_index_set)
1314 const size_type n_rows_submatrix = row_index_set.size();
1315 const size_type n_cols_submatrix = column_index_set.size();
1317 for (
size_type sub_row = 0; sub_row < n_rows_submatrix; ++sub_row)
1318 for (
size_type sub_col = 0; sub_col < n_cols_submatrix; ++sub_col)
1319 (*
this)(sub_row, sub_col) =
1320 matrix.el(row_index_set[sub_row], column_index_set[sub_col]);
1325 template <
typename number>
1326 template <
typename MatrixType,
typename index_type>
1329 const std::vector<index_type> &row_index_set,
1330 const std::vector<index_type> &column_index_set,
1331 MatrixType & matrix)
const 1336 const size_type n_rows_submatrix = row_index_set.size();
1337 const size_type n_cols_submatrix = column_index_set.size();
1339 for (
size_type sub_row = 0; sub_row < n_rows_submatrix; ++sub_row)
1340 for (
size_type sub_col = 0; sub_col < n_cols_submatrix; ++sub_col)
1341 matrix.set(row_index_set[sub_row],
1342 column_index_set[sub_col],
1343 (*
this)(sub_row, sub_col));
1347 template <
typename number>
1353 (*this)(i, j) = value;
1358 template <
typename number>
1359 template <
typename number2>
1362 const Vector<number2> &v)
const 1368 template <
typename number>
1369 template <
typename number2>
1372 const Vector<number2> &v)
const 1381 template <
typename number>
1391 template <
typename number>
1399 template <
typename number>
1407 template <
typename number>
1412 return matrix->el(a_row, a_col);
1416 template <
typename number>
1425 template <
typename number>
1441 template <
typename number>
1452 template <
typename number>
1460 template <
typename number>
1468 template <
typename number>
1478 template <
typename number>
1483 return !(*
this == other);
1487 template <
typename number>
1497 template <
typename number>
1501 return (other < *
this);
1505 template <
typename number>
1513 template <
typename number>
1521 template <
typename number>
1531 template <
typename number>
1541 template <
typename number>
1553 template <
typename number>
1554 template <
typename number2,
typename index_type>
1558 const index_type *col_indices,
1564 for (
size_type col = 0; col < n_cols; ++col)
1567 this->
operator()(row, col_indices[col]) += values[col];
1572 template <
typename number>
1573 template <
class StreamType>
1576 const unsigned int w,
1577 const unsigned int p)
const 1582 const std::streamsize old_precision = s.precision(p);
1583 const std::streamsize old_width = s.width(w);
1591 s << this->
el(i, j);
1597 s.precision(old_precision);
1604 DEAL_II_NAMESPACE_CLOSE
void vmult_add(Vector< number2 > &w, const Vector< number2 > &v) const
void diagadd(const number s)
void copy_to(Tensor< 2, dim > &T, const size_type src_r_i=0, const size_type src_r_j=dim-1, const size_type src_c_i=0, const size_type src_c_j=dim-1, const unsigned int dst_r=0, const unsigned int dst_c=0) const
static::ExceptionBase & ExcEmptyMatrix()
#define AssertDimension(dim1, dim2)
void TmTmult(FullMatrix< number2 > &C, const FullMatrix< number2 > &B, const bool adding=false) const
real_type linfty_norm() const
typename numbers::NumberTraits< std::complex< double > >::real_type real_type
void backward(Vector< number2 > &dst, const Vector< number2 > &src) const
const_iterator(const FullMatrix< number > *matrix, const size_type row, const size_type col)
FullMatrix(const size_type n=0)
FullMatrix & operator/=(const number factor)
const Accessor & operator*() const
bool operator<(const const_iterator &) const
static::ExceptionBase & ExcNotRegular(number arg1)
static::ExceptionBase & ExcScalarAssignmentOnlyForZeroValue()
bool operator==(const FullMatrix< number > &) const
void cholesky(const FullMatrix< number2 > &A)
void add_row(const size_type i, const number s, const size_type j)
number residual(Vector< number2 > &dst, const Vector< number2 > &x, const Vector< number3 > &b) const
void outer_product(const Vector< number2 > &V, const Vector< number2 > &W)
#define AssertIndexRange(index, range)
void right_invert(const FullMatrix< number2 > &M)
void Tvmult_add(Vector< number2 > &w, const Vector< number2 > &v) const
void fill_permutation(const FullMatrix< number2 > &src, const std::vector< size_type > &p_rows, const std::vector< size_type > &p_cols)
void vmult(Vector< number2 > &w, const Vector< number2 > &v, const bool adding=false) const
void left_invert(const FullMatrix< number2 > &M)
void Tadd(const number s, const FullMatrix< number2 > &B)
bool operator!=(const const_iterator &) const
void copy_transposed(const MatrixType &)
void scatter_matrix_to(const std::vector< index_type > &row_index_set, const std::vector< index_type > &column_index_set, MatrixType &matrix) const
SymmetricTensor< rank_, dim, Number > operator*(const SymmetricTensor< rank_, dim, Number > &t, const Number &factor)
real_type relative_symmetry_norm2() const
FullMatrix & operator*=(const number factor)
const_iterator & operator++()
void set(const size_type i, const size_type j, const number value)
void triple_product(const FullMatrix< number > &A, const FullMatrix< number > &B, const FullMatrix< number > &D, const bool transpose_B=false, const bool transpose_D=false, const number scaling=number(1.))
void forward(Vector< number2 > &dst, const Vector< number2 > &src) const
number2 matrix_scalar_product(const Vector< number2 > &u, const Vector< number2 > &v) const
const FullMatrix< number > * matrix
std::size_t memory_consumption() const
Accessor(const FullMatrix< number > *matrix, const size_type row, const size_type col)
void swap_row(const size_type i, const size_type j)
#define DeclException1(Exception1, type1, outsequence)
number2 matrix_norm_square(const Vector< number2 > &v) const
void invert(const FullMatrix< number2 > &M)
void reinit(const TableIndices< N > &new_size, const bool omit_default_initialization=false)
#define Assert(cond, exc)
#define DeclExceptionMsg(Exception, defaulttext)
#define DeclException0(Exception0)
AlignedVector< T >::reference el(const TableIndices< N > &indices)
void mTmult(FullMatrix< number2 > &C, const FullMatrix< number2 > &B, const bool adding=false) const
void extract_submatrix_from(const MatrixType &matrix, const std::vector< index_type > &row_index_set, const std::vector< index_type > &column_index_set)
void Tvmult(Vector< number2 > &w, const Vector< number2 > &v, const bool adding=false) const
void mmult(FullMatrix< number2 > &C, const FullMatrix< number2 > &B, const bool adding=false) const
bool operator==(const const_iterator &) const
void print_formatted(std::ostream &out, const unsigned int precision=3, const bool scientific=true, const unsigned int width=0, const char *zero_string=" ", const double denominator=1., const double threshold=0.) const
FullMatrix< number > & operator=(const FullMatrix< number2 > &)
const_iterator begin() const
void Tmmult(FullMatrix< number2 > &C, const FullMatrix< number2 > &B, const bool adding=false) const
void add_col(const size_type i, const number s, const size_type j)
static::ExceptionBase & ExcIteratorPastEnd()
size_type n_elements() const
static::ExceptionBase & ExcSourceEqualsDestination()
void swap_col(const size_type i, const size_type j)
const Accessor * operator->() const
void copy_from(const MatrixType &)
typename AlignedVector< T >::size_type size_type
real_type l1_norm() const
void add(const number a, const FullMatrix< number2 > &A)
static::ExceptionBase & ExcInvalidDestination(size_type arg1, size_type arg2, size_type arg3)
real_type frobenius_norm() const
#define DeclException3(Exception3, type1, type2, type3, outsequence)
number determinant() const
bool operator>(const const_iterator &) const
static::ExceptionBase & ExcMatrixNotPositiveDefinite()
AlignedVector< T >::reference operator()(const TableIndices< N > &indices)
const_iterator end() const
AlignedVector< T > values
void equ(const number a, const FullMatrix< number2 > &A)
#define AssertIsFinite(number)
void fill(const FullMatrix< number2 > &src, const size_type dst_offset_i=0, const size_type dst_offset_j=0, const size_type src_offset_i=0, const size_type src_offset_j=0)
void fill(InputIterator entries, const bool C_style_indexing=true)
void print(StreamType &s, const unsigned int width=5, const unsigned int precision=2) const
void precondition_Jacobi(Vector< somenumber > &dst, const Vector< somenumber > &src, const number omega=1.) const