15#ifndef dealii_full_matrix_h
16#define dealii_full_matrix_h
38template <
typename number>
40template <
typename number>
77template <
typename number>
89 std::is_arithmetic_v<typename numbers::NumberTraits<number>::real_type>,
90 "The FullMatrix class only supports basic numeric types. In particular, it "
91 "does not support automatically differentiated numbers.");
184 template <
typename number2>
213 template <
typename number2>
223 template <
typename MatrixType>
232 template <
typename MatrixType>
246 const unsigned int src_r_i = 0,
247 const unsigned int src_r_j = dim - 1,
248 const unsigned int src_c_i = 0,
249 const unsigned int src_c_j = dim - 1,
267 const unsigned int dst_r = 0,
268 const unsigned int dst_c = 0)
const;
282 template <
typename MatrixType,
typename index_type>
285 const std::vector<index_type> &row_index_set,
286 const std::vector<index_type> &column_index_set);
300 template <
typename MatrixType,
typename index_type>
303 const std::vector<index_type> &column_index_set,
304 MatrixType &matrix)
const;
316 template <
typename number2>
328 template <
typename number2>
343 template <
typename number2>
346 const std::vector<size_type> &p_rows,
347 const std::vector<size_type> &p_cols);
414 template <
typename number2>
427 template <
typename number2>
489 template <
typename StreamType>
492 const unsigned int width = 5,
493 const unsigned int precision = 2)
const;
523 const unsigned int precision = 3,
524 const bool scientific =
true,
525 const unsigned int width = 0,
526 const char *zero_string =
" ",
527 const double denominator = 1.,
528 const double threshold = 0.,
529 const char *separator =
" ")
const;
593 template <
typename number2>
604 template <
typename number2>
619 template <
typename number2>
639 template <
typename number2>
653 template <
typename number2>
668 template <
typename number2>
692 template <
typename number2,
typename index_type>
696 const index_type *col_indices,
697 const number2 *values,
698 const bool elide_zero_values =
true,
699 const bool col_indices_are_sorted =
false);
757 template <
typename number2>
764 template <
typename number2>
774 template <
typename number2>
815 template <
typename number2>
827 template <
typename number2>
835 template <
typename number2>
844 template <
typename number2>
853 template <
typename number2>
881 template <
typename number2>
885 const bool adding =
false)
const;
905 template <
typename number2>
909 const bool adding =
false)
const;
929 template <
typename number2>
933 const bool adding =
false)
const;
954 template <
typename number2>
958 const bool adding =
false)
const;
974 const bool transpose_B =
false,
975 const bool transpose_D =
false,
976 const number scaling = number(1.));
990 template <
typename number2>
994 const bool adding =
false)
const;
1001 template <
typename number2>
1018 template <
typename number2>
1022 const bool adding =
false)
const;
1030 template <
typename number2>
1039 template <
typename somenumber>
1043 const number omega = 1.)
const;
1051 template <
typename number2,
typename number3>
1067 template <
typename number2>
1078 template <
typename number2>
1105 <<
"The maximal pivot is " << arg1
1106 <<
", which is below the threshold. The matrix may be singular.");
1114 <<
"Target region not in matrix: size in this direction="
1115 << arg1 <<
", size of new matrix=" << arg2
1116 <<
", offset=" << arg3);
1121 "You are attempting an operation on two vectors that "
1122 "are the same object, but the operation requires that the "
1123 "two objects are in fact different.");
1138template <
typename number>
1142 return this->n_rows();
1147template <
typename number>
1151 return this->n_cols();
1156template <
typename number>
1163 if (this->n_elements() != 0)
1164 this->reset_values();
1171template <
typename number>
1172template <
typename number2>
1181template <
typename number>
1182template <
typename MatrixType>
1186 this->
reinit(M.m(), M.n());
1191 for (size_type row = 0; row < M.m(); ++row)
1193 const typename MatrixType::const_iterator end_row = M.end(row);
1194 for (
typename MatrixType::const_iterator entry = M.begin(row);
1197 this->el(row, entry->column()) = entry->value();
1203template <
typename number>
1207 const unsigned int src_r_i,
1208 const unsigned int src_r_j,
1209 const unsigned int src_c_i,
1210 const unsigned int src_c_j,
1211 const size_type dst_r,
1212 const size_type dst_c)
1214 Assert(!this->empty(), ExcEmptyMatrix());
1222 for (size_type i = 0; i < src_r_j - src_r_i + 1; ++i)
1223 for (size_type j = 0; j < src_c_j - src_c_i + 1; ++j)
1225 const unsigned int src_r_index =
static_cast<unsigned int>(i + src_r_i);
1226 const unsigned int src_c_index =
static_cast<unsigned int>(j + src_c_i);
1227 (*this)(i + dst_r, j + dst_c) = number(T[src_r_index][src_c_index]);
1233template <
typename number>
1237 const size_type src_r_i,
1238 const size_type src_r_j,
1239 const size_type src_c_i,
1240 const size_type src_c_j,
1241 const unsigned int dst_r,
1242 const unsigned int dst_c)
const
1244 Assert(!this->empty(), ExcEmptyMatrix());
1252 for (size_type i = 0; i < src_r_j - src_r_i + 1; ++i)
1253 for (size_type j = 0; j < src_c_j - src_c_i + 1; ++j)
1255 const unsigned int dst_r_index =
static_cast<unsigned int>(i + dst_r);
1256 const unsigned int dst_c_index =
static_cast<unsigned int>(j + dst_c);
1257 T[dst_r_index][dst_c_index] = double((*
this)(i + src_r_i, j + src_c_i));
1263template <
typename number>
1264template <
typename MatrixType>
1268 this->
reinit(M.n(), M.m());
1273 for (size_type row = 0; row < M.m(); ++row)
1275 const typename MatrixType::const_iterator end_row = M.end(row);
1276 for (
typename MatrixType::const_iterator entry = M.begin(row);
1279 this->el(entry->column(), row) = entry->value();
1285template <
typename number>
1286template <
typename MatrixType,
typename index_type>
1289 const MatrixType &matrix,
1290 const std::vector<index_type> &row_index_set,
1291 const std::vector<index_type> &column_index_set)
1296 const size_type n_rows_submatrix = row_index_set.size();
1297 const size_type n_cols_submatrix = column_index_set.size();
1299 for (size_type sub_row = 0; sub_row < n_rows_submatrix; ++sub_row)
1300 for (size_type sub_col = 0; sub_col < n_cols_submatrix; ++sub_col)
1301 (*
this)(sub_row, sub_col) =
1302 matrix.el(row_index_set[sub_row], column_index_set[sub_col]);
1307template <
typename number>
1308template <
typename MatrixType,
typename index_type>
1311 const std::vector<index_type> &row_index_set,
1312 const std::vector<index_type> &column_index_set,
1313 MatrixType &matrix)
const
1318 const size_type n_rows_submatrix = row_index_set.size();
1319 const size_type n_cols_submatrix = column_index_set.size();
1321 for (size_type sub_row = 0; sub_row < n_rows_submatrix; ++sub_row)
1322 for (size_type sub_col = 0; sub_col < n_cols_submatrix; ++sub_col)
1323 matrix.set(row_index_set[sub_row],
1324 column_index_set[sub_col],
1325 (*
this)(sub_row, sub_col));
1329template <
typename number>
1335 (*this)(i, j) = value;
1340template <
typename number>
1341template <
typename number2>
1350template <
typename number>
1351template <
typename number2>
1361template <
typename number>
1366 return iterator(
this, r, 0);
1371template <
typename number>
1376 return iterator(
this, r + 1, 0);
1381template <
typename number>
1386 return const_iterator(
this, r, 0);
1391template <
typename number>
1396 return const_iterator(
this, r + 1, 0);
1401template <
typename number>
1408 this->operator()(r, c) += v;
1413template <
typename number>
1414template <
typename number2,
typename index_type>
1417 const size_type n_cols,
1418 const index_type *col_indices,
1419 const number2 *values,
1424 for (size_type col = 0; col < n_cols; ++col)
1427 this->operator()(row, col_indices[col]) +=
values[col];
1432template <
typename number>
1433template <
typename StreamType>
1436 const unsigned int w,
1437 const unsigned int p)
const
1439 Assert(!this->empty(), ExcEmptyMatrix());
1442 const std::streamsize old_precision = s.precision(p);
1443 const std::streamsize old_width = s.width(w);
1445 for (size_type i = 0; i < this->m(); ++i)
1447 for (size_type j = 0; j < this->n(); ++j)
1451 s << this->el(i, j);
1457 s.precision(old_precision);
typename numbers::NumberTraits< number >::real_type real_type
typename Table< 2, number >::const_iterator const_iterator
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.))
FullMatrix< number > & operator=(const number d)
void TmTmult(FullMatrix< number2 > &C, const FullMatrix< number2 > &B, const bool adding=false) const
FullMatrix(const size_type rows, const size_type cols)
number residual(Vector< number2 > &dst, const Vector< number2 > &x, const Vector< number3 > &b) const
std::size_t memory_consumption() const
void diagadd(const number s)
void fill_permutation(const FullMatrix< number2 > &src, const std::vector< size_type > &p_rows, const std::vector< size_type > &p_cols)
void add_row(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
real_type relative_symmetry_norm2() const
void add(const size_type row, const size_type column, const number value)
void copy_from(const Tensor< 2, dim > &T, const unsigned int src_r_i=0, const unsigned int src_r_j=dim - 1, const unsigned int src_c_i=0, const unsigned int src_c_j=dim - 1, const size_type dst_r=0, const size_type dst_c=0)
void equ(const number a, const FullMatrix< number2 > &A, const number b, const FullMatrix< number2 > &B)
void right_invert(const FullMatrix< number2 > &M)
FullMatrix< number > & operator=(const FullMatrix< number2 > &)
FullMatrix & operator/=(const number factor)
void set(const size_type i, const size_type j, const number value)
void add_row(const size_type i, const number s, const size_type j, const number t, const size_type k)
FullMatrix< number > & operator=(const IdentityMatrix &id)
typename Table< 2, number >::iterator iterator
void add(const number a, const FullMatrix< number2 > &A, const number b, const FullMatrix< number2 > &B, const number c, const FullMatrix< number2 > &C)
void Tadd(const number s, const FullMatrix< number2 > &B)
void vmult(Vector< number2 > &w, const Vector< number2 > &v, const bool adding=false) const
void add_col(const size_type i, const number s, const size_type j, const number t, const size_type k)
void scatter_matrix_to(const std::vector< index_type > &row_index_set, const std::vector< index_type > &column_index_set, MatrixType &matrix) const
void swap_row(const size_type i, const size_type j)
void add(const FullMatrix< number2 > &src, const number factor, 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 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
number2 matrix_norm_square(const Vector< number2 > &v) const
void equ(const number a, const FullMatrix< number2 > &A)
const_iterator end(const size_type r) const
FullMatrix(const size_type rows, const size_type cols, const number *entries)
bool operator==(const FullMatrix< number > &) const
void Tvmult(Vector< number2 > &w, const Vector< number2 > &v, const bool adding=false) 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 char *separator=" ") const
void Tmmult(FullMatrix< number2 > &C, const FullMatrix< number2 > &B, const bool adding=false) const
number2 matrix_scalar_product(const Vector< number2 > &u, const Vector< number2 > &v) const
void add(const size_type row, const size_type n_cols, const index_type *col_indices, const number2 *values, const bool elide_zero_values=true, const bool col_indices_are_sorted=false)
void add_col(const size_type i, const number s, const size_type j)
void precondition_Jacobi(Vector< somenumber > &dst, const Vector< somenumber > &src, const number omega=1.) const
FullMatrix(const IdentityMatrix &id)
void vmult_add(Vector< number2 > &w, const Vector< number2 > &v) const
void invert(const FullMatrix< number2 > &M)
void cholesky(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 add(const number a, const FullMatrix< number2 > &A)
number determinant() const
void equ(const number a, const FullMatrix< number2 > &A, const number b, const FullMatrix< number2 > &B, const number c, const FullMatrix< number2 > &C)
void fill(const number2 *)
void copy_transposed(const MatrixType &)
void print(StreamType &s, const unsigned int width=5, const unsigned int precision=2) const
FullMatrix< number > & operator=(const LAPACKFullMatrix< number2 > &)
FullMatrix & operator*=(const number factor)
void Tvmult_add(Vector< number2 > &w, const Vector< number2 > &v) const
void mTmult(FullMatrix< number2 > &C, const FullMatrix< number2 > &B, const bool adding=false) const
void left_invert(const FullMatrix< number2 > &M)
iterator begin(const size_type r)
iterator end(const size_type r)
void add(const number a, const FullMatrix< number2 > &A, const number b, const FullMatrix< number2 > &B)
void outer_product(const Vector< number2 > &V, const Vector< number2 > &W)
real_type frobenius_norm() const
void forward(Vector< number2 > &dst, const Vector< number2 > &src) const
void Tadd(const FullMatrix< number2 > &src, const number factor, 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)
FullMatrix(const size_type n=0)
void swap_col(const size_type i, const size_type j)
void extract_submatrix_from(const MatrixType &matrix, const std::vector< index_type > &row_index_set, const std::vector< index_type > &column_index_set)
void backward(Vector< number2 > &dst, const Vector< number2 > &src) const
void copy_from(const MatrixType &)
const_iterator begin(const size_type r) const
real_type l1_norm() const
real_type linfty_norm() const
void compress(VectorOperation::values)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define DeclException0(Exception0)
static ::ExceptionBase & ExcEmptyMatrix()
static ::ExceptionBase & ExcScalarAssignmentOnlyForZeroValue()
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcNotRegular(number arg1)
#define AssertIndexRange(index, range)
#define DeclExceptionMsg(Exception, defaulttext)
static ::ExceptionBase & ExcMatrixNotPositiveDefinite()
static ::ExceptionBase & ExcSourceEqualsDestination()
#define DeclException3(Exception3, type1, type2, type3, outsequence)
static ::ExceptionBase & ExcInvalidDestination(size_type arg1, size_type arg2, size_type arg3)
#define DeclException1(Exception1, type1, outsequence)
types::global_dof_index size_type
@ matrix
Contents is actually a matrix.
void reinit(MatrixBlock< MatrixType > &v, const BlockSparsityPattern &p)