16 #ifndef dealii__full_matrix_h 17 #define dealii__full_matrix_h 20 #include <deal.II/base/config.h> 21 #include <deal.II/base/numbers.h> 22 #include <deal.II/base/table.h> 23 #include <deal.II/lac/exceptions.h> 24 #include <deal.II/lac/identity_matrix.h> 25 #include <deal.II/base/tensor.h> 31 DEAL_II_NAMESPACE_OPEN
35 template <
typename number>
class Vector;
63 template <
typename number>
108 const size_type col);
113 size_type
row()
const;
123 number
value()
const;
158 const size_type col);
178 const Accessor *operator-> ()
const;
227 const size_type cols);
245 const size_type cols,
246 const number *entries);
279 template <
typename number2>
308 template <
typename number2>
318 template <
typename MatrixType>
326 template <
typename MatrixType>
339 const size_type src_r_i=0,
340 const size_type src_r_j=dim-1,
341 const size_type src_c_i=0,
342 const size_type src_c_j=dim-1,
343 const size_type dst_r=0,
344 const size_type dst_c=0);
356 const size_type src_r_i=0,
357 const size_type src_r_j=dim-1,
358 const size_type src_c_i=0,
359 const size_type src_c_j=dim-1,
360 const size_type dst_r=0,
361 const size_type dst_c=0)
const;
375 template <
typename MatrixType,
typename index_type>
377 const std::vector<index_type> &row_index_set,
378 const std::vector<index_type> &column_index_set);
392 template <
typename MatrixType,
typename index_type>
395 const std::vector<index_type> &column_index_set,
396 MatrixType &
matrix)
const;
408 template <
typename number2>
410 const size_type dst_offset_i = 0,
411 const size_type dst_offset_j = 0,
412 const size_type src_offset_i = 0,
413 const size_type src_offset_j = 0);
419 template <
typename number2>
420 void fill (
const number2 *);
433 template <
typename number2>
435 const std::vector<size_type> &p_rows,
436 const std::vector<size_type> &p_cols);
448 void set (
const size_type i,
472 size_type
m ()
const;
478 size_type
n ()
const;
502 template <
typename number2>
514 template <
typename number2>
561 number
trace ()
const;
569 template <
class StreamType>
570 void print (StreamType &s,
571 const unsigned int width=5,
572 const unsigned int precision=2)
const;
597 const unsigned int precision=3,
598 const bool scientific =
true,
599 const unsigned int width = 0,
600 const char *zero_string =
" ",
601 const double denominator = 1.,
602 const double threshold = 0.)
const;
655 template <
typename number2>
656 void add (
const number a,
666 template <
typename number2>
667 void add (
const number a,
680 template <
typename number2>
681 void add (
const number a,
699 template <
typename number2>
702 const size_type dst_offset_i = 0,
703 const size_type dst_offset_j = 0,
704 const size_type src_offset_i = 0,
705 const size_type src_offset_j = 0);
712 template <
typename number2>
713 void Tadd (
const number s,
727 template <
typename number2>
730 const size_type dst_offset_i = 0,
731 const size_type dst_offset_j = 0,
732 const size_type src_offset_i = 0,
733 const size_type src_offset_j = 0);
738 void add (
const size_type
row,
751 template <
typename number2,
typename index_type>
752 void add (
const size_type
row,
753 const unsigned int n_cols,
754 const index_type *col_indices,
756 const bool elide_zero_values =
true,
757 const bool col_indices_are_sorted =
false);
762 void add_row (
const size_type i,
770 void add_row (
const size_type i,
771 const number s,
const size_type j,
772 const number t,
const size_type k);
777 void add_col (
const size_type i,
785 void add_col (
const size_type i,
786 const number s,
const size_type j,
787 const number t,
const size_type k);
810 template <
typename number2>
811 void equ (
const number a,
817 template <
typename number2>
818 void equ (
const number a,
826 template <
typename number2>
827 void equ (
const number a,
864 template <
typename number2>
874 template <
typename number2>
881 template <
typename number2>
890 template <
typename number2>
898 template <
typename number2>
923 template <
typename number2>
926 const bool adding=
false)
const;
946 template <
typename number2>
949 const bool adding=
false)
const;
969 template <
typename number2>
972 const bool adding=
false)
const;
993 template <
typename number2>
996 const bool adding=
false)
const;
1011 const bool transpose_B =
false,
1012 const bool transpose_D =
false,
1013 const number scaling = number(1.));
1027 template <
typename number2>
1030 const bool adding=
false)
const;
1037 template <
typename number2>
1054 template <
typename number2>
1057 const bool adding=
false)
const;
1065 template <
typename number2>
1074 template <
typename somenumber>
1077 const number omega = 1.)
const;
1085 template <
typename number2,
typename number3>
1100 template <
typename number2>
1111 template <
typename number2>
1132 <<
"The maximal pivot is " << arg1
1133 <<
", which is below the threshold. The matrix may be singular.");
1138 size_type, size_type, size_type,
1139 <<
"Target region not in matrix: size in this direction=" 1140 << arg1 <<
", size of new matrix=" << arg2
1141 <<
", offset=" << arg3);
1163 template <
typename number>
1168 return this->n_rows();
1173 template <
typename number>
1178 return this->n_cols();
1183 template <
typename number>
1187 Assert (d==number(0), ExcScalarAssignmentOnlyForZeroValue());
1198 template <
typename number>
1199 template <
typename number2>
1208 template <
typename number>
1209 template <
typename MatrixType>
1213 this->
reinit (M.m(), M.n());
1218 for (size_type
row = 0;
row < M.m(); ++
row)
1220 const typename MatrixType::const_iterator end_row = M.end(
row);
1221 for (
typename MatrixType::const_iterator entry = M.begin(
row);
1222 entry != end_row; ++entry)
1223 this->
el(
row, entry->column()) = entry->value();
1229 template <
typename number>
1230 template <
typename MatrixType>
1234 this->
reinit (M.n(), M.m());
1239 for (size_type
row = 0;
row < M.m(); ++
row)
1241 const typename MatrixType::const_iterator end_row = M.end(
row);
1242 for (
typename MatrixType::const_iterator entry = M.begin(
row);
1243 entry != end_row; ++entry)
1244 this->
el(entry->column(),
row) = entry->value();
1250 template <
typename number>
1251 template <
typename MatrixType,
typename index_type>
1255 const std::vector<index_type> &row_index_set,
1256 const std::vector<index_type> &column_index_set)
1261 const size_type n_rows_submatrix = row_index_set.size();
1262 const size_type n_cols_submatrix = column_index_set.size();
1264 for (size_type sub_row = 0; sub_row < n_rows_submatrix; ++sub_row)
1265 for (size_type sub_col = 0; sub_col < n_cols_submatrix; ++sub_col)
1266 (*
this)(sub_row, sub_col) = matrix.el(row_index_set[sub_row], column_index_set[sub_col]);
1271 template <
typename number>
1272 template <
typename MatrixType,
typename index_type>
1276 const std::vector<index_type> &column_index_set,
1277 MatrixType &matrix)
const 1282 const size_type n_rows_submatrix = row_index_set.size();
1283 const size_type n_cols_submatrix = column_index_set.size();
1285 for (size_type sub_row = 0; sub_row < n_rows_submatrix; ++sub_row)
1286 for (size_type sub_col = 0; sub_col < n_cols_submatrix; ++sub_col)
1287 matrix.set(row_index_set[sub_row],
1288 column_index_set[sub_col],
1289 (*
this)(sub_row, sub_col));
1293 template <
typename number>
1300 (*this)(i,j) = value;
1305 template <
typename number>
1306 template <
typename number2>
1315 template <
typename number>
1316 template <
typename number2>
1328 template <
typename number>
1341 template <
typename number>
1350 template <
typename number>
1359 template <
typename number>
1365 return matrix->el(a_row, a_col);
1369 template <
typename number>
1380 template <
typename number>
1397 template <
typename number>
1406 template <
typename number>
1415 template <
typename number>
1426 template <
typename number>
1432 return ! (*
this == other);
1436 template <
typename number>
1448 template <
typename number>
1454 return (other < *
this);
1458 template <
typename number>
1467 template <
typename number>
1476 template <
typename number>
1481 Assert (r<
m(), ExcIndexRange(r,0,
m()));
1487 template <
typename number>
1492 Assert (r<
m(), ExcIndexRange(r,0,
m()));
1498 template <
typename number>
1511 template <
typename number>
1512 template <
typename number2,
typename index_type>
1516 const unsigned int n_cols,
1517 const index_type *col_indices,
1523 for (size_type col=0; col<n_cols; ++col)
1526 this->
operator()(row,col_indices[col]) += values[col];
1531 template <
typename number>
1532 template <
class StreamType>
1536 const unsigned int w,
1537 const unsigned int p)
const 1542 const unsigned int old_precision = s.precision (p);
1543 const unsigned int old_width = s.width (w);
1545 for (size_type i=0; i<this->
m(); ++i)
1547 for (size_type j=0; j<this->
n(); ++j)
1557 s.precision(old_precision);
1564 DEAL_II_NAMESPACE_CLOSE
number determinant() const
const Accessor & operator*() const
void diagadd(const number s)
bool operator==(const FullMatrix< number > &) const
#define AssertDimension(dim1, dim2)
void vmult_add(Vector< number2 > &w, const Vector< number2 > &v) const
const_iterator(const FullMatrix< number > *matrix, const size_type row, const size_type col)
number2 matrix_scalar_product(const Vector< number2 > &u, const Vector< number2 > &v) const
FullMatrix(const size_type n=0)
bool operator==(const const_iterator &) const
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
void cholesky(const FullMatrix< number2 > &A)
void add_row(const size_type i, const number s, const size_type j)
bool operator>(const const_iterator &) const
const_iterator begin() const
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 invert(const FullMatrix< number2 > &M)
void left_invert(const FullMatrix< number2 > &M)
void Tadd(const number s, const FullMatrix< number2 > &B)
void Tvmult(Vector< number2 > &w, const Vector< number2 > &v, const bool adding=false) const
void copy_transposed(const MatrixType &)
size_type n_elements() const
void mTmult(FullMatrix< number2 > &C, const FullMatrix< number2 > &B, const bool adding=false) const
real_type l1_norm() const
FullMatrix & operator*=(const number factor)
const_iterator & operator++()
void vmult(Vector< number2 > &w, const Vector< number2 > &v, const bool adding=false) const
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.))
const Accessor * operator->() const
real_type frobenius_norm() const
DeclException3(ExcInvalidDestination, size_type, size_type, size_type,<< "Target region not in matrix: size in this direction="<< arg1<< ", size of new matrix="<< arg2<< ", offset="<< arg3)
const FullMatrix< number > * matrix
void backward(Vector< number2 > &dst, const Vector< number2 > &src) const
numbers::NumberTraits< number >::real_type real_type
Accessor(const FullMatrix< number > *matrix, const size_type row, const size_type col)
void swap_row(const size_type i, const size_type j)
real_type linfty_norm() const
void reinit(const TableIndices< N > &new_size, const bool omit_default_initialization=false)
#define Assert(cond, exc)
bool operator!=(const const_iterator &) const
DeclException0(ExcEmptyMatrix)
bool operator<(const const_iterator &) const
AlignedVector< T >::reference el(const TableIndices< N > &indices)
void mmult(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_add(Vector< number2 > &w, const Vector< number2 > &v) const
const_iterator end() const
real_type relative_symmetry_norm2() const
number residual(Vector< number2 > &dst, const Vector< number2 > &x, const Vector< number3 > &b) const
number2 matrix_norm_square(const Vector< number2 > &v) const
void add_col(const size_type i, const number s, const size_type j)
std::size_t memory_consumption() const
void forward(Vector< number2 > &dst, const Vector< number2 > &src) const
void swap_col(const size_type i, const size_type j)
void copy_from(const MatrixType &)
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 size_type dst_r=0, const size_type dst_c=0) const
DeclException1(ExcNotRegular, number,<< "The maximal pivot is "<< arg1<< ", which is below the threshold. The matrix may be singular.")
FullMatrix< number > & operator=(const FullMatrix< number > &)
void add(const number a, const FullMatrix< number2 > &A)
void TmTmult(FullMatrix< number2 > &C, const FullMatrix< number2 > &B, const bool adding=false) const
void precondition_Jacobi(Vector< somenumber > &dst, const Vector< somenumber > &src, const number omega=1.) const
void Tmmult(FullMatrix< number2 > &C, const FullMatrix< number2 > &B, const bool adding=false) const
void print(StreamType &s, const unsigned int width=5, const unsigned int precision=2) const
AlignedVector< T >::reference operator()(const TableIndices< N > &indices)
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)