16 #ifndef dealii_sparse_matrix_ez_h 17 # define dealii_sparse_matrix_ez_h 20 # include <deal.II/base/config.h> 22 # include <deal.II/base/smartpointer.h> 23 # include <deal.II/base/subscriptor.h> 25 # include <deal.II/lac/exceptions.h> 29 DEAL_II_NAMESPACE_OPEN
31 template <
typename number>
33 template <
typename number>
103 template <
typename number>
171 static_cast<unsigned short>(-1);
193 const unsigned short index);
247 const unsigned short index);
331 const unsigned int default_increment = 1);
366 unsigned int default_increment = 1,
425 template <
class StreamType>
442 std::vector<size_type> &used_by_line,
443 const bool compute_by_line)
const;
469 const bool elide_zero_values =
true);
493 template <
typename number2>
495 add(
const std::vector<size_type> &indices,
497 const bool elide_zero_values =
true);
504 template <
typename number2>
506 add(
const std::vector<size_type> &row_indices,
507 const std::vector<size_type> &col_indices,
509 const bool elide_zero_values =
true);
520 template <
typename number2>
523 const std::vector<size_type> &col_indices,
524 const std::vector<number2> & values,
525 const bool elide_zero_values =
true);
536 template <
typename number2>
541 const number2 * values,
542 const bool elide_zero_values =
true,
543 const bool col_indices_are_sorted =
false);
566 template <
typename MatrixType>
568 copy_from(
const MatrixType &source,
const bool elide_zero_values =
true);
577 template <
typename MatrixType>
579 add(
const number factor,
const MatrixType &matrix);
612 template <
typename somenumber>
614 vmult(Vector<somenumber> &dst,
const Vector<somenumber> &src)
const;
621 template <
typename somenumber>
623 Tvmult(Vector<somenumber> &dst,
const Vector<somenumber> &src)
const;
629 template <
typename somenumber>
631 vmult_add(Vector<somenumber> &dst,
const Vector<somenumber> &src)
const;
638 template <
typename somenumber>
640 Tvmult_add(Vector<somenumber> &dst,
const Vector<somenumber> &src)
const;
661 template <
typename somenumber>
664 const Vector<somenumber> &src,
665 const number omega = 1.)
const;
670 template <
typename somenumber>
673 const Vector<somenumber> & src,
674 const number om = 1.,
675 const std::vector<std::size_t> &pos_right_of_diagonal =
676 std::vector<std::size_t>())
const;
682 template <
typename somenumber>
685 const Vector<somenumber> &src,
686 const number om = 1.)
const;
692 template <
typename somenumber>
695 const Vector<somenumber> &src,
696 const number om = 1.)
const;
706 template <
typename MatrixTypeA,
typename MatrixTypeB>
709 const MatrixTypeB &B,
751 print(std::ostream &out)
const;
775 const unsigned int precision = 3,
776 const bool scientific =
true,
777 const unsigned int width = 0,
778 const char * zero_string =
" ",
779 const double denominator = 1.)
const;
819 <<
"The entry with index (" << arg1 <<
',' << arg2
820 <<
") does not exist.");
825 <<
"An entry with index (" << arg1 <<
',' << arg2
826 <<
") cannot be allocated.");
854 template <
typename somenumber>
857 const Vector<somenumber> &src,
866 template <
typename somenumber>
871 somenumber * partial_sum)
const;
878 template <
typename somenumber>
881 const Vector<somenumber> &v,
884 somenumber * partial_sum)
const;
917 template <
typename number>
919 const number & value)
926 template <
typename number>
933 template <
typename number>
937 , diagonal(invalid_diagonal)
942 template <
typename number>
946 const unsigned short i)
953 template <
typename number>
961 template <
typename number>
965 return matrix->data[matrix->row_info[a_row].start + a_index].column;
969 template <
typename number>
970 inline unsigned short 978 template <
typename number>
982 return matrix->data[matrix->row_info[a_row].start + a_index].value;
986 template <
typename number>
990 const unsigned short i)
1020 template <
typename number>
1027 ++(accessor.a_index);
1031 if (accessor.a_index >= accessor.matrix->row_info[accessor.a_row].length)
1033 accessor.a_index = 0;
1040 while (accessor.a_row < accessor.matrix->m() &&
1041 accessor.matrix->row_info[accessor.a_row].length == 0);
1047 template <
typename number>
1055 template <
typename number>
1063 template <
typename number>
1073 template <
typename number>
1078 return !(*
this == other);
1082 template <
typename number>
1094 template <
typename number>
1102 template <
typename number>
1110 template <
typename number>
1122 if (entry->
column == col)
1132 template <
typename number>
1137 return t->
locate(row, col);
1141 template <
typename number>
1158 while (i <
end &&
data[i].column < col)
1162 if (i !=
end &&
data[i].column == col)
1201 Entry temp = *entry;
1239 template <
typename number>
1244 const bool elide_zero_values)
1251 if (elide_zero_values && value == 0.)
1254 if (entry !=
nullptr)
1260 entry->
value = value;
1266 template <
typename number>
1278 if (std::abs(value) == 0.)
1282 entry->
value += value;
1286 template <
typename number>
1287 template <
typename number2>
1291 const bool elide_zero_values)
1294 for (
size_type i = 0; i < indices.size(); ++i)
1295 for (
size_type j = 0; j < indices.size(); ++j)
1296 if ((full_matrix(i, j) != 0) || (elide_zero_values ==
false))
1297 add(indices[i], indices[j], full_matrix(i, j));
1302 template <
typename number>
1303 template <
typename number2>
1306 const std::vector<size_type> &col_indices,
1308 const bool elide_zero_values)
1311 for (
size_type i = 0; i < row_indices.size(); ++i)
1312 for (
size_type j = 0; j < col_indices.size(); ++j)
1313 if ((full_matrix(i, j) != 0) || (elide_zero_values ==
false))
1314 add(row_indices[i], col_indices[j], full_matrix(i, j));
1319 template <
typename number>
1320 template <
typename number2>
1323 const std::vector<size_type> &col_indices,
1324 const std::vector<number2> & values,
1325 const bool elide_zero_values)
1328 for (
size_type j = 0; j < col_indices.size(); ++j)
1329 if ((values[j] != 0) || (elide_zero_values ==
false))
1330 add(row, col_indices[j], values[j]);
1335 template <
typename number>
1336 template <
typename number2>
1341 const number2 * values,
1342 const bool elide_zero_values,
1347 if ((std::abs(values[j]) != 0) || (elide_zero_values ==
false))
1348 add(row, col_indices[j], values[j]);
1353 template <
typename number>
1359 return entry->
value;
1365 template <
typename number>
1371 return entry->
value;
1377 template <
typename number>
1385 template <
typename number>
1392 template <
typename number>
1401 template <
typename number>
1410 template <
typename number>
1411 template <
typename MatrixType>
1414 const bool elide_zero_values)
1421 for (
size_type row = 0; row < M.m(); ++row)
1423 const typename MatrixType::const_iterator end_row = M.end(row);
1424 for (
typename MatrixType::const_iterator entry = M.begin(row);
1427 set(row, entry->column(), entry->value(), elide_zero_values);
1433 template <
typename number>
1434 template <
typename MatrixType>
1447 for (
size_type row = 0; row < M.m(); ++row)
1449 const typename MatrixType::const_iterator end_row = M.end(row);
1450 for (
typename MatrixType::const_iterator entry = M.begin(row);
1453 if (entry->value() != 0)
1454 add(row, entry->column(), factor * entry->value());
1460 template <
typename number>
1461 template <
typename MatrixTypeA,
typename MatrixTypeB>
1464 const MatrixTypeB &B,
1483 typename MatrixTypeB::const_iterator b1 = B.begin();
1484 const typename MatrixTypeB::const_iterator b_final = B.end();
1486 while (b1 != b_final)
1490 typename MatrixTypeB::const_iterator b2 = B.begin();
1491 while (b2 != b_final)
1496 const typename MatrixTypeA::value_type a = A.el(k, l);
1499 add(i, j, a * b1->value() * b2->value());
1510 std::vector<size_type> minrow(B.n(), B.m());
1511 std::vector<size_type> maxrow(B.n(), 0);
1512 while (b1 != b_final)
1515 if (r < minrow[b1->column()])
1516 minrow[b1->column()] = r;
1517 if (r > maxrow[b1->column()])
1518 maxrow[b1->column()] = r;
1522 typename MatrixTypeA::const_iterator ai = A.begin();
1523 const typename MatrixTypeA::const_iterator ae = A.end();
1527 const typename MatrixTypeA::value_type a = ai->value();
1537 b1 = B.begin(minrow[ai->row()]);
1538 const typename MatrixTypeB::const_iterator be1 =
1539 B.end(maxrow[ai->row()]);
1540 const typename MatrixTypeB::const_iterator be2 =
1541 B.end(maxrow[ai->column()]);
1545 const double b1v = b1->value();
1550 if (b1->column() == ai->row() && (b1v != 0.))
1554 typename MatrixTypeB::const_iterator b2 =
1555 B.begin(minrow[ai->column()]);
1558 if (b2->column() == ai->column())
1561 add(i, j, a * b1v * b2->value());
1574 template <
typename number>
1575 template <
class StreamType>
1582 std::vector<size_type> used_by_line;
1586 out <<
"SparseMatrixEZ:used entries:" << used << std::endl
1587 <<
"SparseMatrixEZ:allocated entries:" << allocated << std::endl
1588 <<
"SparseMatrixEZ:reserved entries:" << reserved << std::endl;
1592 for (
size_type i = 0; i < used_by_line.size(); ++i)
1593 if (used_by_line[i] != 0)
1594 out <<
"SparseMatrixEZ:entries\t" << i <<
"\trows\t" 1595 << used_by_line[i] << std::endl;
1600 DEAL_II_NAMESPACE_CLOSE
size_type get_row_length(const size_type row) const
const types::global_dof_index invalid_size_type
void Tvmult_add(Vector< somenumber > &dst, const Vector< somenumber > &src) const
const_iterator & operator++()
static ::ExceptionBase & ExcEntryAllocationFailure(int arg1, int arg2)
#define DeclException2(Exception2, type1, type2, outsequence)
void add(const size_type i, const size_type j, const number value)
void compute_statistics(size_type &used, size_type &allocated, size_type &reserved, std::vector< size_type > &used_by_line, const bool compute_by_line) const
number operator()(const size_type i, const size_type j) const
SparseMatrixEZ< number > & copy_from(const MatrixType &source, const bool elide_zero_values=true)
void set(const size_type i, const size_type j, const number value, const bool elide_zero_values=true)
void conjugate_add(const MatrixTypeA &A, const MatrixTypeB &B, const bool transpose=false)
void block_read(std::istream &in)
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
bool operator<(const const_iterator &) const
void vmult_add(Vector< somenumber > &dst, const Vector< somenumber > &src) const
LinearAlgebra::distributed::Vector< Number > Vector
void vmult(Vector< somenumber > &dst, const Vector< somenumber > &src) const
static const size_type invalid
const Accessor & operator*() const
std::size_t memory_consumption() const
void threaded_matrix_norm_square(const Vector< somenumber > &v, const size_type begin_row, const size_type end_row, somenumber *partial_sum) const
void threaded_matrix_scalar_product(const Vector< somenumber > &u, const Vector< somenumber > &v, const size_type begin_row, const size_type end_row, somenumber *partial_sum) const
bool operator==(const const_iterator &) const
void print(std::ostream &out) const
static ::ExceptionBase & ExcNoDiagonal()
void precondition_SOR(Vector< somenumber > &dst, const Vector< somenumber > &src, const number om=1.) const
SparseMatrixEZ< number > & operator=(const SparseMatrixEZ< number > &)
Accessor(const SparseMatrixEZ< number > *matrix, const size_type row, const unsigned short index)
#define Assert(cond, exc)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
void reinit(const size_type n_rows, const size_type n_columns, size_type default_row_length=0, unsigned int default_increment=1, size_type reserve=0)
bool operator!=(const const_iterator &) const
const_iterator(const SparseMatrixEZ< number > *matrix, const size_type row, const unsigned short index)
#define DeclException0(Exception0)
const SparseMatrixEZ< number > * matrix
std::vector< Entry > data
Entry * allocate(const size_type row, const size_type col)
SymmetricTensor< rank_, dim, Number > transpose(const SymmetricTensor< rank_, dim, Number > &t)
RowInfo(const size_type start=Entry::invalid)
void print_statistics(StreamType &s, bool full=false)
static ::ExceptionBase & ExcIteratorPastEnd()
void swap(Vector< Number > &u, Vector< Number > &v)
unsigned int global_dof_index
void block_write(std::ostream &out) const
const Accessor * operator->() const
void precondition_TSOR(Vector< somenumber > &dst, const Vector< somenumber > &src, const number om=1.) const
unsigned short index() const
number el(const size_type i, const size_type j) const
const Entry * locate(const size_type row, const size_type col) const
const_iterator begin() const
static ::ExceptionBase & ExcInvalidEntry(int arg1, int arg2)
void precondition_Jacobi(Vector< somenumber > &dst, const Vector< somenumber > &src, const number omega=1.) const
void threaded_vmult(Vector< somenumber > &dst, const Vector< somenumber > &src, const size_type begin_row, const size_type end_row) const
~SparseMatrixEZ() override=default
void Tvmult(Vector< somenumber > &dst, const Vector< somenumber > &src) const
static const unsigned short invalid_diagonal
void precondition_SSOR(Vector< somenumber > &dst, const Vector< somenumber > &src, const number om=1., const std::vector< std::size_t > &pos_right_of_diagonal=std::vector< std::size_t >()) const
const_iterator end() const
types::global_dof_index size_type
#define AssertIsFinite(number)
unsigned int saved_default_row_length
std::vector< RowInfo > row_info
static ::ExceptionBase & ExcInternalError()
size_type n_nonzero_elements() 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