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;
171 template <
typename number2>
200 template <
typename number2>
210 template <
typename MatrixType>
219 template <
typename MatrixType>
233 const unsigned int src_r_i = 0,
234 const unsigned int src_r_j = dim - 1,
235 const unsigned int src_c_i = 0,
236 const unsigned int src_c_j = dim - 1,
253 const unsigned int dst_r = 0,
254 const unsigned int dst_c = 0)
const;
268 template <
typename MatrixType,
typename index_type>
271 const std::vector<index_type> &row_index_set,
272 const std::vector<index_type> &column_index_set);
286 template <
typename MatrixType,
typename index_type>
289 const std::vector<index_type> &column_index_set,
290 MatrixType & matrix)
const;
302 template <
typename number2>
314 template <
typename number2>
316 fill(
const number2 *);
329 template <
typename number2>
332 const std::vector<size_type> &p_rows,
333 const std::vector<size_type> &p_cols);
402 template <
typename number2>
415 template <
typename number2>
418 const Vector<number2> &v)
const;
477 template <
class StreamType>
479 print(StreamType & s,
480 const unsigned int width = 5,
481 const unsigned int precision = 2)
const;
507 const unsigned int precision = 3,
508 const bool scientific =
true,
509 const unsigned int width = 0,
510 const char * zero_string =
" ",
511 const double denominator = 1.,
512 const double threshold = 0.)
const;
572 template <
typename number2>
583 template <
typename number2>
598 template <
typename number2>
618 template <
typename number2>
632 template <
typename number2>
647 template <
typename number2>
671 template <
typename number2,
typename index_type>
675 const index_type *col_indices,
677 const bool elide_zero_values =
true,
678 const bool col_indices_are_sorted =
false);
736 template <
typename number2>
743 template <
typename number2>
753 template <
typename number2>
794 template <
typename number2>
806 template <
typename number2>
814 template <
typename number2>
816 outer_product(
const Vector<number2> &V,
const Vector<number2> &W);
823 template <
typename number2>
832 template <
typename number2>
858 template <
typename number2>
862 const bool adding =
false)
const;
882 template <
typename number2>
886 const bool adding =
false)
const;
906 template <
typename number2>
910 const bool adding =
false)
const;
931 template <
typename number2>
935 const bool adding =
false)
const;
951 const bool transpose_B =
false,
952 const bool transpose_D =
false,
953 const number scaling = number(1.));
967 template <
typename number2>
969 vmult(Vector<number2> & w,
970 const Vector<number2> &v,
971 const bool adding =
false)
const;
978 template <
typename number2>
980 vmult_add(Vector<number2> &w,
const Vector<number2> &v)
const;
995 template <
typename number2>
997 Tvmult(Vector<number2> & w,
998 const Vector<number2> &v,
999 const bool adding =
false)
const;
1007 template <
typename number2>
1009 Tvmult_add(Vector<number2> &w,
const Vector<number2> &v)
const;
1016 template <
typename somenumber>
1019 const Vector<somenumber> &src,
1020 const number omega = 1.)
const;
1028 template <
typename number2,
typename number3>
1031 const Vector<number2> &x,
1032 const Vector<number3> &b)
const;
1044 template <
typename number2>
1046 forward(Vector<number2> &dst,
const Vector<number2> &src)
const;
1055 template <
typename number2>
1057 backward(Vector<number2> &dst,
const Vector<number2> &src)
const;
1077 <<
"The maximal pivot is " << arg1
1078 <<
", which is below the threshold. The matrix may be singular.");
1086 <<
"Target region not in matrix: size in this direction=" 1087 << arg1 <<
", size of new matrix=" << arg2
1088 <<
", offset=" << arg3);
1093 "You are attempting an operation on two matrices that " 1094 "are the same object, but the operation requires that the " 1095 "two objects are in fact different.");
1110 template <
typename number>
1114 return this->n_rows();
1119 template <
typename number>
1123 return this->n_cols();
1128 template <
typename number>
1135 if (this->n_elements() != 0)
1136 this->reset_values();
1143 template <
typename number>
1144 template <
typename number2>
1153 template <
typename number>
1154 template <
typename MatrixType>
1158 this->reinit(M.m(), M.n());
1163 for (size_type row = 0; row < M.m(); ++row)
1165 const typename MatrixType::const_iterator end_row = M.end(row);
1166 for (
typename MatrixType::const_iterator entry = M.begin(row);
1169 this->el(row, entry->column()) = entry->value();
1175 template <
typename number>
1176 template <
typename MatrixType>
1180 this->reinit(M.n(), M.m());
1185 for (size_type row = 0; row < M.m(); ++row)
1187 const typename MatrixType::const_iterator end_row = M.end(row);
1188 for (
typename MatrixType::const_iterator entry = M.begin(row);
1191 this->el(entry->column(), row) = entry->value();
1197 template <
typename number>
1198 template <
typename MatrixType,
typename index_type>
1201 const MatrixType & matrix,
1202 const std::vector<index_type> &row_index_set,
1203 const std::vector<index_type> &column_index_set)
1208 const size_type n_rows_submatrix = row_index_set.size();
1209 const size_type n_cols_submatrix = column_index_set.size();
1211 for (size_type sub_row = 0; sub_row < n_rows_submatrix; ++sub_row)
1212 for (size_type sub_col = 0; sub_col < n_cols_submatrix; ++sub_col)
1213 (*
this)(sub_row, sub_col) =
1214 matrix.el(row_index_set[sub_row], column_index_set[sub_col]);
1219 template <
typename number>
1220 template <
typename MatrixType,
typename index_type>
1223 const std::vector<index_type> &row_index_set,
1224 const std::vector<index_type> &column_index_set,
1225 MatrixType & matrix)
const 1230 const size_type n_rows_submatrix = row_index_set.size();
1231 const size_type n_cols_submatrix = column_index_set.size();
1233 for (size_type sub_row = 0; sub_row < n_rows_submatrix; ++sub_row)
1234 for (size_type sub_col = 0; sub_col < n_cols_submatrix; ++sub_col)
1235 matrix.set(row_index_set[sub_row],
1236 column_index_set[sub_col],
1237 (*
this)(sub_row, sub_col));
1241 template <
typename number>
1247 (*this)(i, j) = value;
1252 template <
typename number>
1253 template <
typename number2>
1256 const Vector<number2> &v)
const 1262 template <
typename number>
1263 template <
typename number2>
1266 const Vector<number2> &v)
const 1273 template <
typename number>
1278 return iterator(
this, r, 0);
1283 template <
typename number>
1288 return iterator(
this, r + 1, 0);
1293 template <
typename number>
1298 return const_iterator(
this, r, 0);
1303 template <
typename number>
1308 return const_iterator(
this, r + 1, 0);
1313 template <
typename number>
1320 this->operator()(r, c) += v;
1325 template <
typename number>
1326 template <
typename number2,
typename index_type>
1329 const size_type n_cols,
1330 const index_type *col_indices,
1331 const number2 * values,
1336 for (size_type col = 0; col < n_cols; ++col)
1339 this->operator()(row, col_indices[col]) += values[col];
1344 template <
typename number>
1345 template <
class StreamType>
1348 const unsigned int w,
1349 const unsigned int p)
const 1351 Assert(!this->empty(), ExcEmptyMatrix());
1354 const std::streamsize old_precision = s.precision(p);
1355 const std::streamsize old_width = s.width(w);
1357 for (size_type i = 0; i < this->m(); ++i)
1359 for (size_type j = 0; j < this->n(); ++j)
1363 s << this->el(i, j);
1369 s.precision(old_precision);
1376 DEAL_II_NAMESPACE_CLOSE
number determinant() const
void diagadd(const number s)
bool operator==(const FullMatrix< number > &) const
typename Table< 2, CoefficientType >::const_iterator const_iterator
static ::ExceptionBase & ExcEmptyMatrix()
#define AssertDimension(dim1, dim2)
void vmult_add(Vector< number2 > &w, const Vector< number2 > &v) const
typename numbers::NumberTraits< CoefficientType >::real_type real_type
void vmult(Vector< number2 > &w, const Vector< number2 > &v, const bool adding=false) const
number2 matrix_scalar_product(const Vector< number2 > &u, const Vector< number2 > &v) const
Contents is actually a matrix.
FullMatrix(const size_type n=0)
FullMatrix & operator/=(const number factor)
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
static ::ExceptionBase & ExcNotRegular(number arg1)
static ::ExceptionBase & ExcScalarAssignmentOnlyForZeroValue()
void cholesky(const FullMatrix< number2 > &A)
void add_row(const size_type i, const number s, const size_type j)
void outer_product(const Vector< number2 > &V, const Vector< number2 > &W)
#define AssertIndexRange(index, range)
void right_invert(const FullMatrix< number2 > &M)
void scatter_matrix_to(const std::vector< index_type > &row_index_set, const std::vector< index_type > &column_index_set, MatrixType &matrix) const
void fill_permutation(const FullMatrix< number2 > &src, const std::vector< size_type > &p_rows, const std::vector< size_type > &p_cols)
void left_invert(const FullMatrix< number2 > &M)
void Tadd(const number s, const FullMatrix< number2 > &B)
void copy_transposed(const MatrixType &)
real_type l1_norm() const
LinearAlgebra::distributed::Vector< Number > Vector
FullMatrix & operator*=(const number factor)
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.))
real_type frobenius_norm() const
void Tmmult(FullMatrix< number2 > &C, const FullMatrix< number2 > &B, const bool adding=false) const
void backward(Vector< number2 > &dst, const Vector< number2 > &src) const
void swap_row(const size_type i, const size_type j)
#define DeclException1(Exception1, type1, outsequence)
real_type linfty_norm() const
void invert(const FullMatrix< number2 > &M)
#define Assert(cond, exc)
#define DeclExceptionMsg(Exception, defaulttext)
#define DeclException0(Exception0)
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_add(Vector< number2 > &w, const Vector< number2 > &v) const
iterator end(const size_type r)
real_type relative_symmetry_norm2() const
number residual(Vector< number2 > &dst, const Vector< number2 > &x, const Vector< number3 > &b) const
FullMatrix< number > & operator=(const FullMatrix< number2 > &)
void TmTmult(FullMatrix< number2 > &C, const FullMatrix< number2 > &B, const bool adding=false) const
number2 matrix_norm_square(const Vector< number2 > &v) const
void add_col(const size_type i, const number s, const size_type j)
void mmult(FullMatrix< number2 > &C, const FullMatrix< number2 > &B, const bool adding=false) const
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
std::size_t memory_consumption() const
void Tvmult(Vector< number2 > &w, const Vector< number2 > &v, const bool adding=false) const
void forward(Vector< number2 > &dst, const Vector< number2 > &src) const
static ::ExceptionBase & ExcSourceEqualsDestination()
void swap_col(const size_type i, const size_type j)
void copy_from(const MatrixType &)
typename AlignedVector< T >::size_type size_type
void add(const number a, const FullMatrix< number2 > &A)
static ::ExceptionBase & ExcInvalidDestination(size_type arg1, size_type arg2, size_type arg3)
void precondition_Jacobi(Vector< somenumber > &dst, const Vector< somenumber > &src, const number omega=1.) const
void print(StreamType &s, const unsigned int width=5, const unsigned int precision=2) const
#define DeclException3(Exception3, type1, type2, type3, outsequence)
static ::ExceptionBase & ExcMatrixNotPositiveDefinite()
iterator begin(const size_type r)
AlignedVector< T > values
void equ(const number a, const FullMatrix< number2 > &A)
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 mTmult(FullMatrix< number2 > &C, const FullMatrix< number2 > &B, const bool adding=false) const
typename Table< 2, CoefficientType >::iterator iterator