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>
123 number
value()
const;
235 const number *entries);
260 template <
typename number2>
289 template <
typename number2>
299 template <
typename MatrixType>
307 template <
typename MatrixType>
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>
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);
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>
693 template <
typename number2>
694 void Tadd (
const number s,
708 template <
typename number2>
732 template <
typename number2,
typename index_type>
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);
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.");
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>
1171 if (this->n_elements() != 0)
1172 this->reset_values();
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>
1357 accessor(matrix, r, c)
1361 template <
typename number>
1369 if (accessor.a_col >= accessor.matrix->n())
1378 template <
typename number>
1387 template <
typename number>
1396 template <
typename number>
1402 return (accessor.row() == other.accessor.row() &&
1403 accessor.column() == other.accessor.column());
1407 template <
typename number>
1413 return ! (*
this == other);
1417 template <
typename number>
1421 operator < (
const const_iterator &other)
const 1423 return (accessor.row() < other.accessor.row() ||
1424 (accessor.row() == other.accessor.row() &&
1425 accessor.column() < other.accessor.column()));
1429 template <
typename number>
1433 operator > (
const const_iterator &other)
const 1435 return (other < *
this);
1439 template <
typename number>
1444 return const_iterator(
this, 0, 0);
1448 template <
typename number>
1453 return const_iterator(
this,
m(), 0);
1457 template <
typename number>
1463 return const_iterator(
this, r, 0);
1468 template <
typename number>
1474 return const_iterator(
this, r+1, 0);
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)
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);
1538 s.precision(old_precision);
1545 DEAL_II_NAMESPACE_CLOSE
types::global_dof_index size_type
number determinant() const
const Accessor & operator*() const
void diagadd(const number s)
bool operator==(const FullMatrix< number > &) const
static ::ExceptionBase & ExcEmptyMatrix()
#define AssertDimension(dim1, dim2)
void vmult_add(Vector< number2 > &w, const Vector< number2 > &v) const
void vmult(Vector< number2 > &w, const Vector< number2 > &v, const bool adding=false) 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
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)
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 left_invert(const FullMatrix< number2 > &M)
void Tadd(const number s, const FullMatrix< number2 > &B)
void copy_transposed(const MatrixType &)
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
real_type l1_norm() 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.))
const Accessor * operator->() const
real_type frobenius_norm() const
const FullMatrix< number > * matrix
void Tmmult(FullMatrix< number2 > &C, const FullMatrix< number2 > &B, const bool adding=false) const
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)
#define DeclException1(Exception1, type1, outsequence)
real_type linfty_norm() const
void invert(const FullMatrix< number2 > &M)
#define Assert(cond, exc)
bool operator!=(const const_iterator &) const
bool operator<(const const_iterator &) const
#define DeclException0(Exception0)
AlignedVector< T >::reference el(const TableIndices< N > &indices)
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
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)
static ::ExceptionBase & ExcIteratorPastEnd()
void mmult(FullMatrix< number2 > &C, const FullMatrix< number2 > &B, const bool adding=false) 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 &)
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
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()
AlignedVector< T >::size_type size_type
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)
void mTmult(FullMatrix< number2 > &C, const FullMatrix< number2 > &B, const bool adding=false) const