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);
234 const size_type cols,
235 const number *entries);
260 template <
typename number2>
289 template <
typename number2>
299 template <
typename MatrixType>
307 template <
typename MatrixType>
320 const size_type src_r_i=0,
321 const size_type src_r_j=dim-1,
322 const size_type src_c_i=0,
323 const size_type src_c_j=dim-1,
324 const size_type dst_r=0,
325 const size_type dst_c=0);
337 const size_type src_r_i=0,
338 const size_type src_r_j=dim-1,
339 const size_type src_c_i=0,
340 const size_type src_c_j=dim-1,
341 const size_type dst_r=0,
342 const size_type dst_c=0)
const;
356 template <
typename MatrixType,
typename index_type>
358 const std::vector<index_type> &row_index_set,
359 const std::vector<index_type> &column_index_set);
373 template <
typename MatrixType,
typename index_type>
376 const std::vector<index_type> &column_index_set,
377 MatrixType &
matrix)
const;
389 template <
typename number2>
391 const size_type dst_offset_i = 0,
392 const size_type dst_offset_j = 0,
393 const size_type src_offset_i = 0,
394 const size_type src_offset_j = 0);
400 template <
typename number2>
401 void fill (
const number2 *);
414 template <
typename number2>
416 const std::vector<size_type> &p_rows,
417 const std::vector<size_type> &p_cols);
429 void set (
const size_type i,
453 size_type
m ()
const;
459 size_type
n ()
const;
483 template <
typename number2>
495 template <
typename number2>
542 number
trace ()
const;
550 template <
class StreamType>
551 void print (StreamType &s,
552 const unsigned int width=5,
553 const unsigned int precision=2)
const;
578 const unsigned int precision=3,
579 const bool scientific =
true,
580 const unsigned int width = 0,
581 const char *zero_string =
" ",
582 const double denominator = 1.,
583 const double threshold = 0.)
const;
636 template <
typename number2>
637 void add (
const number a,
647 template <
typename number2>
648 void add (
const number a,
661 template <
typename number2>
662 void add (
const number a,
680 template <
typename number2>
683 const size_type dst_offset_i = 0,
684 const size_type dst_offset_j = 0,
685 const size_type src_offset_i = 0,
686 const size_type src_offset_j = 0);
693 template <
typename number2>
694 void Tadd (
const number s,
708 template <
typename number2>
711 const size_type dst_offset_i = 0,
712 const size_type dst_offset_j = 0,
713 const size_type src_offset_i = 0,
714 const size_type src_offset_j = 0);
719 void add (
const size_type
row,
732 template <
typename number2,
typename index_type>
733 void add (
const size_type
row,
734 const unsigned int n_cols,
735 const index_type *col_indices,
737 const bool elide_zero_values =
true,
738 const bool col_indices_are_sorted =
false);
743 void add_row (
const size_type i,
751 void add_row (
const size_type i,
752 const number s,
const size_type j,
753 const number t,
const size_type k);
758 void add_col (
const size_type i,
766 void add_col (
const size_type i,
767 const number s,
const size_type j,
768 const number t,
const size_type k);
791 template <
typename number2>
792 void equ (
const number a,
798 template <
typename number2>
799 void equ (
const number a,
807 template <
typename number2>
808 void equ (
const number a,
845 template <
typename number2>
855 template <
typename number2>
862 template <
typename number2>
871 template <
typename number2>
879 template <
typename number2>
904 template <
typename number2>
907 const bool adding=
false)
const;
927 template <
typename number2>
930 const bool adding=
false)
const;
950 template <
typename number2>
953 const bool adding=
false)
const;
974 template <
typename number2>
977 const bool adding=
false)
const;
992 const bool transpose_B =
false,
993 const bool transpose_D =
false,
994 const number scaling = number(1.));
1008 template <
typename number2>
1011 const bool adding=
false)
const;
1018 template <
typename number2>
1035 template <
typename number2>
1038 const bool adding=
false)
const;
1046 template <
typename number2>
1055 template <
typename somenumber>
1058 const number omega = 1.)
const;
1066 template <
typename number2,
typename number3>
1081 template <
typename number2>
1092 template <
typename number2>
1113 <<
"The maximal pivot is " << arg1
1114 <<
", which is below the threshold. The matrix may be singular.");
1119 size_type, size_type, size_type,
1120 <<
"Target region not in matrix: size in this direction=" 1121 << arg1 <<
", size of new matrix=" << arg2
1122 <<
", offset=" << arg3);
1144 template <
typename number>
1149 return this->n_rows();
1154 template <
typename number>
1159 return this->n_cols();
1164 template <
typename number>
1179 template <
typename number>
1180 template <
typename number2>
1189 template <
typename number>
1190 template <
typename MatrixType>
1194 this->
reinit (M.m(), M.n());
1199 for (size_type
row = 0;
row < M.m(); ++
row)
1201 const typename MatrixType::const_iterator end_row = M.end(
row);
1202 for (
typename MatrixType::const_iterator entry = M.begin(
row);
1203 entry != end_row; ++entry)
1204 this->
el(
row, entry->column()) = entry->value();
1210 template <
typename number>
1211 template <
typename MatrixType>
1215 this->
reinit (M.n(), M.m());
1220 for (size_type
row = 0;
row < M.m(); ++
row)
1222 const typename MatrixType::const_iterator end_row = M.end(
row);
1223 for (
typename MatrixType::const_iterator entry = M.begin(
row);
1224 entry != end_row; ++entry)
1225 this->
el(entry->column(),
row) = entry->value();
1231 template <
typename number>
1232 template <
typename MatrixType,
typename index_type>
1236 const std::vector<index_type> &row_index_set,
1237 const std::vector<index_type> &column_index_set)
1242 const size_type n_rows_submatrix = row_index_set.size();
1243 const size_type n_cols_submatrix = column_index_set.size();
1245 for (size_type sub_row = 0; sub_row < n_rows_submatrix; ++sub_row)
1246 for (size_type sub_col = 0; sub_col < n_cols_submatrix; ++sub_col)
1247 (*
this)(sub_row, sub_col) = matrix.el(row_index_set[sub_row], column_index_set[sub_col]);
1252 template <
typename number>
1253 template <
typename MatrixType,
typename index_type>
1257 const std::vector<index_type> &column_index_set,
1258 MatrixType &matrix)
const 1263 const size_type n_rows_submatrix = row_index_set.size();
1264 const size_type n_cols_submatrix = column_index_set.size();
1266 for (size_type sub_row = 0; sub_row < n_rows_submatrix; ++sub_row)
1267 for (size_type sub_col = 0; sub_col < n_cols_submatrix; ++sub_col)
1268 matrix.set(row_index_set[sub_row],
1269 column_index_set[sub_col],
1270 (*
this)(sub_row, sub_col));
1274 template <
typename number>
1281 (*this)(i,j) = value;
1286 template <
typename number>
1287 template <
typename number2>
1296 template <
typename number>
1297 template <
typename number2>
1309 template <
typename number>
1322 template <
typename number>
1331 template <
typename number>
1340 template <
typename number>
1346 return matrix->el(a_row, a_col);
1350 template <
typename number>
1361 template <
typename number>
1378 template <
typename number>
1387 template <
typename number>
1396 template <
typename number>
1407 template <
typename number>
1413 return ! (*
this == other);
1417 template <
typename number>
1429 template <
typename number>
1435 return (other < *
this);
1439 template <
typename number>
1448 template <
typename number>
1457 template <
typename number>
1468 template <
typename number>
1479 template <
typename number>
1492 template <
typename number>
1493 template <
typename number2,
typename index_type>
1497 const unsigned int n_cols,
1498 const index_type *col_indices,
1504 for (size_type col=0; col<n_cols; ++col)
1507 this->
operator()(row,col_indices[col]) += values[col];
1512 template <
typename number>
1513 template <
class StreamType>
1517 const unsigned int w,
1518 const unsigned int p)
const 1523 const unsigned int old_precision = s.precision (p);
1524 const unsigned int old_width = s.width (w);
1526 for (size_type i=0; i<this->
m(); ++i)
1528 for (size_type j=0; j<this->
n(); ++j)
1538 s.precision(old_precision);
1545 DEAL_II_NAMESPACE_CLOSE
void vmult_add(Vector< number2 > &w, const Vector< number2 > &v) const
void diagadd(const number s)
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
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 &)
static::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
void scatter_matrix_to(const std::vector< index_type > &row_index_set, const std::vector< index_type > &column_index_set, MatrixType &matrix) const
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
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)
#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 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 &)
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
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