13#ifndef dealii_sparse_matrix_ez_h
14#define dealii_sparse_matrix_ez_h
33template <
typename number>
35template <
typename number>
103template <
typename number>
186 static_cast<unsigned short>(-1);
208 const unsigned short index);
260 const unsigned short index);
338 const unsigned int default_increment = 1);
373 const unsigned int default_increment = 1,
432 template <
typename StreamType>
449 std::vector<size_type> &used_by_line,
450 const bool compute_by_line)
const;
477 const bool elide_zero_values =
true);
506 template <
typename number2>
508 add(
const std::vector<size_type> &indices,
510 const bool elide_zero_values =
true);
517 template <
typename number2>
519 add(
const std::vector<size_type> &row_indices,
520 const std::vector<size_type> &col_indices,
522 const bool elide_zero_values =
true);
533 template <
typename number2>
536 const std::vector<size_type> &col_indices,
537 const std::vector<number2> &values,
538 const bool elide_zero_values =
true);
549 template <
typename number2>
554 const number2 *values,
555 const bool elide_zero_values =
true,
556 const bool col_indices_are_sorted =
false);
592 template <
typename MatrixType>
594 copy_from(
const MatrixType &source,
const bool elide_zero_values =
true);
603 template <
typename MatrixType>
605 add(
const number factor,
const MatrixType &matrix);
654 template <
typename somenumber>
663 template <
typename somenumber>
671 template <
typename somenumber>
680 template <
typename somenumber>
703 template <
typename somenumber>
707 const number omega = 1.)
const;
712 template <
typename somenumber>
716 const number om = 1.,
717 const std::vector<std::size_t> &pos_right_of_diagonal =
718 std::vector<std::size_t>())
const;
724 template <
typename somenumber>
728 const number om = 1.)
const;
734 template <
typename somenumber>
738 const number om = 1.)
const;
748 template <
typename MatrixTypeA,
typename MatrixTypeB>
751 const MatrixTypeB &B,
819 const unsigned int precision = 3,
820 const bool scientific =
true,
821 const unsigned int width = 0,
822 const char *zero_string =
" ",
823 const double denominator = 1.,
824 const char *separator =
" ")
const;
864 <<
"The entry with index (" << arg1 <<
',' << arg2
865 <<
") does not exist.");
870 <<
"An entry with index (" << arg1 <<
',' << arg2
871 <<
") cannot be allocated.");
921 template <
typename somenumber>
933 template <
typename somenumber>
938 somenumber *partial_sum)
const;
945 template <
typename somenumber>
951 somenumber *partial_sum)
const;
988template <
typename number>
997template <
typename number>
1004template <
typename number>
1008 , diagonal(invalid_diagonal)
1013template <
typename number>
1017 const unsigned short i)
1024template <
typename number>
1032template <
typename number>
1036 return matrix->data[matrix->row_info[a_row].start + a_index].column;
1040template <
typename number>
1041inline unsigned short
1049template <
typename number>
1053 return matrix->data[matrix->row_info[a_row].start + a_index].value;
1057template <
typename number>
1061 const unsigned short i)
1091template <
typename number>
1098 ++(accessor.a_index);
1102 if (accessor.a_index >= accessor.matrix->row_info[accessor.a_row].length)
1104 accessor.a_index = 0;
1111 while (accessor.a_row < accessor.matrix->m() &&
1112 accessor.matrix->row_info[accessor.a_row].length == 0);
1118template <
typename number>
1126template <
typename number>
1134template <
typename number>
1144template <
typename number>
1149 return !(*
this == other);
1153template <
typename number>
1165template <
typename number>
1173template <
typename number>
1181template <
typename number>
1193 if (entry->
column == col)
1203template <
typename number>
1208 return t->
locate(row, col);
1212template <
typename number>
1229 while (i <
end &&
data[i].column < col)
1233 if (i !=
end &&
data[i].column == col)
1272 Entry temp = *entry;
1299 std::swap(
data[j], temp);
1310template <
typename number>
1315 const bool elide_zero_values)
1322 if (elide_zero_values && value == 0.)
1325 if (entry !=
nullptr)
1331 entry->
value = value;
1337template <
typename number>
1353 entry->
value += value;
1357template <
typename number>
1358template <
typename number2>
1362 const bool elide_zero_values)
1365 for (
size_type i = 0; i < indices.size(); ++i)
1366 for (
size_type j = 0; j < indices.size(); ++j)
1367 if ((full_matrix(i, j) != 0) || (elide_zero_values ==
false))
1368 add(indices[i], indices[j], full_matrix(i, j));
1373template <
typename number>
1374template <
typename number2>
1377 const std::vector<size_type> &col_indices,
1379 const bool elide_zero_values)
1382 for (
size_type i = 0; i < row_indices.size(); ++i)
1383 for (
size_type j = 0; j < col_indices.size(); ++j)
1384 if ((full_matrix(i, j) != 0) || (elide_zero_values ==
false))
1385 add(row_indices[i], col_indices[j], full_matrix(i, j));
1390template <
typename number>
1391template <
typename number2>
1394 const std::vector<size_type> &col_indices,
1395 const std::vector<number2> &values,
1396 const bool elide_zero_values)
1399 for (
size_type j = 0; j < col_indices.size(); ++j)
1400 if ((values[j] != 0) || (elide_zero_values ==
false))
1401 add(row, col_indices[j], values[j]);
1406template <
typename number>
1407template <
typename number2>
1412 const number2 *values,
1413 const bool elide_zero_values,
1418 if ((
std::abs(values[j]) != 0) || (elide_zero_values ==
false))
1419 add(row, col_indices[j], values[j]);
1423template <
typename number>
1428 entry.value *= factor;
1435template <
typename number>
1441 const number factor_inv = number(1.) / factor;
1444 entry.value *= factor_inv;
1450template <
typename number>
1456 return entry->
value;
1461template <
typename number>
1470 return entry->
value;
1477template <
typename number>
1487 set(i, i, number());
1491 return entry->
value;
1496template <
typename number>
1502 return entry->
value;
1508template <
typename number>
1516template <
typename number>
1523template <
typename number>
1532template <
typename number>
1541template <
typename number>
1542template <
typename MatrixType>
1545 const bool elide_zero_values)
1547 reinit(M.m(), M.n(), this->saved_default_row_length, this->increment);
1552 for (
size_type row = 0; row < M.m(); ++row)
1554 const typename MatrixType::const_iterator end_row = M.end(row);
1555 for (
typename MatrixType::const_iterator entry = M.begin(row);
1558 set(row, entry->column(), entry->value(), elide_zero_values);
1564template <
typename number>
1565template <
typename MatrixType>
1578 for (
size_type row = 0; row < M.m(); ++row)
1580 const typename MatrixType::const_iterator end_row = M.end(row);
1581 for (
typename MatrixType::const_iterator entry = M.begin(row);
1584 if (entry->value() != 0)
1585 add(row, entry->column(), factor * entry->value());
1591template <
typename number>
1592template <
typename MatrixTypeA,
typename MatrixTypeB>
1595 const MatrixTypeB &B,
1614 typename MatrixTypeB::const_iterator b1 = B.begin();
1615 const typename MatrixTypeB::const_iterator b_final = B.end();
1617 while (b1 != b_final)
1621 typename MatrixTypeB::const_iterator b2 = B.begin();
1622 while (b2 != b_final)
1627 const typename MatrixTypeA::value_type a = A.el(k, l);
1630 add(i, j, a * b1->value() * b2->value());
1641 std::vector<size_type> minrow(B.n(), B.m());
1642 std::vector<size_type> maxrow(B.n(), 0);
1643 while (b1 != b_final)
1646 if (r < minrow[b1->column()])
1647 minrow[b1->column()] = r;
1648 if (r > maxrow[b1->column()])
1649 maxrow[b1->column()] = r;
1653 typename MatrixTypeA::const_iterator ai = A.begin();
1654 const typename MatrixTypeA::const_iterator ae = A.end();
1658 const typename MatrixTypeA::value_type a = ai->value();
1668 b1 = B.begin(minrow[ai->row()]);
1669 const typename MatrixTypeB::const_iterator be1 =
1670 B.end(maxrow[ai->row()]);
1671 const typename MatrixTypeB::const_iterator be2 =
1672 B.end(maxrow[ai->column()]);
1676 const double b1v = b1->value();
1681 if (b1->column() == ai->row() && (b1v != 0.))
1685 typename MatrixTypeB::const_iterator b2 =
1686 B.begin(minrow[ai->column()]);
1689 if (b2->column() == ai->column())
1692 add(i, j, a * b1v * b2->value());
1705template <
typename number>
1706template <
typename StreamType>
1713 std::vector<size_type> used_by_line;
1717 out <<
"SparseMatrixEZ:used entries:" << used << std::endl
1718 <<
"SparseMatrixEZ:allocated entries:" << allocated << std::endl
1719 <<
"SparseMatrixEZ:reserved entries:" << reserved << std::endl;
1723 for (
size_type i = 0; i < used_by_line.size(); ++i)
1724 if (used_by_line[i] != 0)
1725 out <<
"SparseMatrixEZ:entries\t" << i <<
"\trows\t"
1726 << used_by_line[i] << std::endl;
1731template <
typename number>
1740template <
typename number>
* * const_iterator()=default
unsigned short index() const
const SparseMatrixEZ< number > * matrix
Accessor(const SparseMatrixEZ< number > *matrix, const size_type row, const unsigned short index)
const Accessor & operator*() const
const_iterator(const SparseMatrixEZ< number > *matrix, const size_type row, const unsigned short index)
bool operator<(const const_iterator &) const
bool operator==(const const_iterator &) const
bool operator!=(const const_iterator &) const
const_iterator & operator++()
const Accessor * operator->() 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 char *separator=" ") const
void block_read(std::istream &in)
SparseMatrixEZ< number > & copy_from(const MatrixType &source, const bool elide_zero_values=true)
std::vector< Entry > data
void print_statistics(StreamType &s, bool full=false)
void Tvmult_add(Vector< somenumber > &dst, const Vector< somenumber > &src) const
void block_write(std::ostream &out) const
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
SparseMatrixEZ(const SparseMatrixEZ &)
number operator()(const size_type i, const size_type j) const
const Entry * locate(const size_type row, const size_type col) const
~SparseMatrixEZ() override=default
Entry * allocate(const size_type row, const size_type col)
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
size_type get_row_length(const size_type row) const
void precondition_TSOR(Vector< somenumber > &dst, const Vector< somenumber > &src, const number om=1.) const
std::size_t memory_consumption() const
size_type n_nonzero_elements() const
void print(std::ostream &out) const
SparseMatrixEZ< number > & operator=(const SparseMatrixEZ< number > &)
SparseMatrixEZ(const size_type n_rows, const size_type n_columns, const size_type default_row_length=0, const unsigned int default_increment=1)
void conjugate_add(const MatrixTypeA &A, const MatrixTypeB &B, const bool transpose=false)
void Tvmult(Vector< somenumber > &dst, const Vector< somenumber > &src) const
SparseMatrixEZ< number > & operator=(const double d)
void threaded_vmult(Vector< somenumber > &dst, const Vector< somenumber > &src, const size_type begin_row, const size_type end_row) const
void vmult_add(Vector< somenumber > &dst, const Vector< somenumber > &src) const
SparseMatrixEZ & operator*=(const number factor)
void reinit(const size_type n_rows, const size_type n_columns, const size_type default_row_length=0, const unsigned int default_increment=1, const size_type reserve=0)
void precondition_Jacobi(Vector< somenumber > &dst, const Vector< somenumber > &src, const number omega=1.) const
const_iterator end() const
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
std::vector< RowInfo > row_info
SparseMatrixEZ & operator/=(const number factor)
number el(const size_type i, const size_type j) const
const_iterator begin() const
void threaded_matrix_norm_square(const Vector< somenumber > &v, const size_type begin_row, const size_type end_row, somenumber *partial_sum) const
unsigned int saved_default_row_length
void set(const size_type i, const size_type j, const number value, const bool elide_zero_values=true)
number diag_element(const size_type i) const
void add(const size_type i, const size_type j, const number value)
void precondition_SOR(Vector< somenumber > &dst, const Vector< somenumber > &src, const number om=1.) const
void vmult(Vector< somenumber > &dst, const Vector< somenumber > &src) const
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define DeclException0(Exception0)
static ::ExceptionBase & ExcInvalidEntry(int arg1, int arg2)
static ::ExceptionBase & ExcNoDiagonal()
#define Assert(cond, exc)
static ::ExceptionBase & ExcIteratorPastEnd()
#define AssertIsFinite(number)
#define DeclException2(Exception2, type1, type2, outsequence)
static ::ExceptionBase & ExcEntryAllocationFailure(int arg1, int arg2)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcDivideByZero()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcNotQuadratic()
constexpr types::global_dof_index invalid_size_type
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)
unsigned int global_dof_index
static const size_type invalid
static const unsigned short invalid_diagonal
RowInfo(const size_type start=Entry::invalid)
static const bool zero_addition_can_be_elided