13#ifndef dealii_full_matrix_h
14#define dealii_full_matrix_h
36template <
typename number>
38template <
typename number>
75template <
typename number>
87 std::is_arithmetic_v<typename numbers::NumberTraits<number>::real_type>,
88 "The FullMatrix class only supports basic numeric types. In particular, it "
89 "does not support automatically differentiated numbers.");
182 template <
typename number2>
211 template <
typename number2>
221 template <
typename MatrixType>
230 template <
typename MatrixType>
244 const unsigned int src_r_i = 0,
245 const unsigned int src_r_j = dim - 1,
246 const unsigned int src_c_i = 0,
247 const unsigned int src_c_j = dim - 1,
265 const unsigned int dst_r = 0,
266 const unsigned int dst_c = 0)
const;
280 template <
typename MatrixType,
typename index_type>
283 const std::vector<index_type> &row_index_set,
284 const std::vector<index_type> &column_index_set);
298 template <
typename MatrixType,
typename index_type>
301 const std::vector<index_type> &column_index_set,
302 MatrixType &matrix)
const;
314 template <
typename number2>
326 template <
typename number2>
341 template <
typename number2>
344 const std::vector<size_type> &p_rows,
345 const std::vector<size_type> &p_cols);
412 template <
typename number2>
425 template <
typename number2>
487 template <
typename StreamType>
490 const unsigned int width = 5,
491 const unsigned int precision = 2)
const;
521 const unsigned int precision = 3,
522 const bool scientific =
true,
523 const unsigned int width = 0,
524 const char *zero_string =
" ",
525 const double denominator = 1.,
526 const double threshold = 0.,
527 const char *separator =
" ")
const;
591 template <
typename number2>
602 template <
typename number2>
617 template <
typename number2>
637 template <
typename number2>
651 template <
typename number2>
666 template <
typename number2>
690 template <
typename number2,
typename index_type>
694 const index_type *col_indices,
695 const number2 *values,
696 const bool elide_zero_values =
true,
697 const bool col_indices_are_sorted =
false);
758 permute(
const std::vector<unsigned int> &row_perm,
759 const std::vector<unsigned int> &col_perm);
771 template <
typename number2>
778 template <
typename number2>
788 template <
typename number2>
829 template <
typename number2>
841 template <
typename number2>
849 template <
typename number2>
858 template <
typename number2>
867 template <
typename number2>
895 template <
typename number2>
899 const bool adding =
false)
const;
919 template <
typename number2>
923 const bool adding =
false)
const;
943 template <
typename number2>
947 const bool adding =
false)
const;
968 template <
typename number2>
972 const bool adding =
false)
const;
988 const bool transpose_B =
false,
989 const bool transpose_D =
false,
990 const number scaling = number(1.));
1042 template <
typename... Rest>
1046 const Rest &...rest);
1061 template <
typename number2>
1065 const bool adding =
false)
const;
1072 template <
typename number2>
1089 template <
typename number2>
1093 const bool adding =
false)
const;
1101 template <
typename number2>
1110 template <
typename somenumber>
1114 const number omega = 1.)
const;
1122 template <
typename number2,
typename number3>
1138 template <
typename number2>
1149 template <
typename number2>
1176 <<
"The maximal pivot is " << arg1
1177 <<
", which is below the threshold. The matrix may be singular.");
1185 <<
"Target region not in matrix: size in this direction="
1186 << arg1 <<
", size of new matrix=" << arg2
1187 <<
", offset=" << arg3);
1192 "You are attempting an operation on two vectors that "
1193 "are the same object, but the operation requires that the "
1194 "two objects are in fact different.");
1209template <
typename number>
1213 return this->n_rows();
1218template <
typename number>
1222 return this->n_cols();
1227template <
typename number>
1233 if (this->n_elements() != 0)
1234 this->reset_values();
1241template <
typename number>
1242template <
typename number2>
1251template <
typename number>
1252template <
typename MatrixType>
1256 this->
reinit(M.m(), M.n());
1261 for (size_type row = 0; row < M.m(); ++row)
1263 const typename MatrixType::const_iterator end_row = M.end(row);
1264 for (
typename MatrixType::const_iterator entry = M.begin(row);
1267 this->el(row, entry->column()) = entry->value();
1273template <
typename number>
1277 const unsigned int src_r_i,
1278 const unsigned int src_r_j,
1279 const unsigned int src_c_i,
1280 const unsigned int src_c_j,
1281 const size_type dst_r,
1282 const size_type dst_c)
1284 Assert(!this->empty(), ExcEmptyMatrix());
1292 for (size_type i = 0; i < src_r_j - src_r_i + 1; ++i)
1293 for (size_type j = 0; j < src_c_j - src_c_i + 1; ++j)
1295 const unsigned int src_r_index =
static_cast<unsigned int>(i + src_r_i);
1296 const unsigned int src_c_index =
static_cast<unsigned int>(j + src_c_i);
1297 (*this)(i + dst_r, j + dst_c) = number(T[src_r_index][src_c_index]);
1303template <
typename number>
1307 const size_type src_r_i,
1308 const size_type src_r_j,
1309 const size_type src_c_i,
1310 const size_type src_c_j,
1311 const unsigned int dst_r,
1312 const unsigned int dst_c)
const
1314 Assert(!this->empty(), ExcEmptyMatrix());
1322 for (size_type i = 0; i < src_r_j - src_r_i + 1; ++i)
1323 for (size_type j = 0; j < src_c_j - src_c_i + 1; ++j)
1325 const unsigned int dst_r_index =
static_cast<unsigned int>(i + dst_r);
1326 const unsigned int dst_c_index =
static_cast<unsigned int>(j + dst_c);
1327 T[dst_r_index][dst_c_index] = double((*
this)(i + src_r_i, j + src_c_i));
1333template <
typename number>
1334template <
typename MatrixType>
1338 this->
reinit(M.n(), M.m());
1343 for (size_type row = 0; row < M.m(); ++row)
1345 const typename MatrixType::const_iterator end_row = M.end(row);
1346 for (
typename MatrixType::const_iterator entry = M.begin(row);
1349 this->el(entry->column(), row) = entry->value();
1355template <
typename number>
1356template <
typename MatrixType,
typename index_type>
1359 const MatrixType &matrix,
1360 const std::vector<index_type> &row_index_set,
1361 const std::vector<index_type> &column_index_set)
1366 const size_type n_rows_submatrix = row_index_set.size();
1367 const size_type n_cols_submatrix = column_index_set.size();
1369 for (size_type sub_row = 0; sub_row < n_rows_submatrix; ++sub_row)
1370 for (size_type sub_col = 0; sub_col < n_cols_submatrix; ++sub_col)
1371 (*
this)(sub_row, sub_col) =
1372 matrix.el(row_index_set[sub_row], column_index_set[sub_col]);
1377template <
typename number>
1378template <
typename MatrixType,
typename index_type>
1381 const std::vector<index_type> &row_index_set,
1382 const std::vector<index_type> &column_index_set,
1383 MatrixType &matrix)
const
1388 const size_type n_rows_submatrix = row_index_set.size();
1389 const size_type n_cols_submatrix = column_index_set.size();
1391 for (size_type sub_row = 0; sub_row < n_rows_submatrix; ++sub_row)
1392 for (size_type sub_col = 0; sub_col < n_cols_submatrix; ++sub_col)
1393 matrix.set(row_index_set[sub_row],
1394 column_index_set[sub_col],
1395 (*
this)(sub_row, sub_col));
1399template <
typename number>
1405 (*this)(i, j) = value;
1410template <
typename number>
1411template <
typename number2>
1420template <
typename number>
1421template <
typename number2>
1431template <
typename number>
1441template <
typename number>
1451template <
typename number>
1461template <
typename number>
1471template <
typename number>
1483template <
typename number>
1484template <
typename number2,
typename index_type>
1487 const size_type n_cols,
1488 const index_type *col_indices,
1489 const number2 *values,
1494 for (size_type col = 0; col < n_cols; ++col)
1502template <
typename number>
1503template <
typename StreamType>
1506 const unsigned int w,
1507 const unsigned int p)
const
1509 Assert(!this->empty(), ExcEmptyMatrix());
1512 const std::streamsize old_precision = s.precision(p);
1513 const std::streamsize old_width = s.width(w);
1515 for (size_type i = 0; i < this->m(); ++i)
1517 for (size_type j = 0; j < this->n(); ++j)
1521 s << this->el(i, j);
1527 s.precision(old_precision);
1532template <
typename number>
1533template <
typename... Rest>
1537 const Rest &...rest)
1539 this->kronecker_product(A, B,
false);
1542 (std::is_same_v<std::remove_cv_t<std::remove_reference_t<Rest>>,
1545 "kronecker_product: all variadic arguments must be ::FullMatrix<number>");
1547 if constexpr (
sizeof...(rest) != 0)
1551 this->kronecker_product(tmp, rest...);
* * Point< dim > operator()(const Point< dim > &p) const *
* * const_iterator()=default
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)
void permute(const std::vector< unsigned int > &row_perm, const std::vector< unsigned int > &col_perm)
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 kronecker_product(const FullMatrix< number > &A, const FullMatrix< number > &B, const Rest &...rest)
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
void kronecker_product(const FullMatrix< number > &A, const FullMatrix< number > &B, const bool adding)
Compute the Kronecker product of two matrices.
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)