16#ifndef dealii_sparse_matrix_ez_h
17# define dealii_sparse_matrix_ez_h
33template <
typename number>
35template <
typename number>
103template <
typename number>
171 static_cast<unsigned short>(-1);
193 const unsigned short index);
245 const unsigned short index);
321 const unsigned int default_increment = 1);
356 unsigned int default_increment = 1,
415 template <
class StreamType>
432 std::vector<size_type> &used_by_line,
433 const bool compute_by_line)
const;
460 const bool elide_zero_values =
true);
489 template <
typename number2>
491 add(
const std::vector<size_type> &indices,
493 const bool elide_zero_values =
true);
500 template <
typename number2>
502 add(
const std::vector<size_type> &row_indices,
503 const std::vector<size_type> &col_indices,
505 const bool elide_zero_values =
true);
516 template <
typename number2>
519 const std::vector<size_type> &col_indices,
520 const std::vector<number2> &
values,
521 const bool elide_zero_values =
true);
532 template <
typename number2>
538 const bool elide_zero_values =
true,
539 const bool col_indices_are_sorted =
false);
562 template <
typename MatrixType>
564 copy_from(
const MatrixType &source,
const bool elide_zero_values =
true);
573 template <
typename MatrixType>
575 add(
const number factor,
const MatrixType &
matrix);
608 template <
typename somenumber>
617 template <
typename somenumber>
625 template <
typename somenumber>
634 template <
typename somenumber>
657 template <
typename somenumber>
661 const number omega = 1.)
const;
666 template <
typename somenumber>
670 const number om = 1.,
671 const std::vector<std::size_t> &pos_right_of_diagonal =
672 std::vector<std::size_t>())
const;
678 template <
typename somenumber>
682 const number om = 1.)
const;
688 template <
typename somenumber>
692 const number om = 1.)
const;
702 template <
typename MatrixTypeA,
typename MatrixTypeB>
705 const MatrixTypeB &B,
771 const unsigned int precision = 3,
772 const bool scientific =
true,
773 const unsigned int width = 0,
774 const char * zero_string =
" ",
775 const double denominator = 1.)
const;
815 <<
"The entry with index (" << arg1 <<
',' << arg2
816 <<
") does not exist.");
821 <<
"An entry with index (" << arg1 <<
',' << arg2
822 <<
") cannot be allocated.");
850 template <
typename somenumber>
862 template <
typename somenumber>
867 somenumber * partial_sum)
const;
874 template <
typename somenumber>
880 somenumber * partial_sum)
const;
913template <
typename number>
915 const number & value)
922template <
typename number>
929template <
typename number>
938template <
typename number>
942 const unsigned short i)
949template <
typename number>
957template <
typename number>
961 return matrix->data[
matrix->row_info[a_row].start + a_index].column;
965template <
typename number>
974template <
typename number>
978 return matrix->data[
matrix->row_info[a_row].start + a_index].value;
982template <
typename number>
986 const unsigned short i)
1016template <
typename number>
1023 ++(accessor.a_index);
1027 if (accessor.a_index >= accessor.matrix->row_info[accessor.a_row].length)
1029 accessor.a_index = 0;
1036 while (accessor.a_row < accessor.matrix->m() &&
1037 accessor.matrix->row_info[accessor.a_row].length == 0);
1043template <
typename number>
1051template <
typename number>
1059template <
typename number>
1069template <
typename number>
1074 return !(*
this == other);
1078template <
typename number>
1090template <
typename number>
1098template <
typename number>
1106template <
typename number>
1118 if (entry->
column == col)
1128template <
typename number>
1133 return t->
locate(row, col);
1137template <
typename number>
1154 while (i <
end &&
data[i].column < col)
1158 if (i !=
end &&
data[i].column == col)
1197 Entry temp = *entry;
1235template <
typename number>
1240 const bool elide_zero_values)
1247 if (elide_zero_values && value == 0.)
1250 if (entry !=
nullptr)
1256 entry->
value = value;
1262template <
typename number>
1278 entry->
value += value;
1282template <
typename number>
1283template <
typename number2>
1287 const bool elide_zero_values)
1290 for (
size_type i = 0; i < indices.size(); ++i)
1291 for (
size_type j = 0; j < indices.size(); ++j)
1292 if ((full_matrix(i, j) != 0) || (elide_zero_values ==
false))
1293 add(indices[i], indices[j], full_matrix(i, j));
1298template <
typename number>
1299template <
typename number2>
1302 const std::vector<size_type> &col_indices,
1304 const bool elide_zero_values)
1307 for (
size_type i = 0; i < row_indices.size(); ++i)
1308 for (
size_type j = 0; j < col_indices.size(); ++j)
1309 if ((full_matrix(i, j) != 0) || (elide_zero_values ==
false))
1310 add(row_indices[i], col_indices[j], full_matrix(i, j));
1315template <
typename number>
1316template <
typename number2>
1319 const std::vector<size_type> &col_indices,
1320 const std::vector<number2> &
values,
1321 const bool elide_zero_values)
1324 for (
size_type j = 0; j < col_indices.size(); ++j)
1325 if ((
values[j] != 0) || (elide_zero_values ==
false))
1331template <
typename number>
1332template <
typename number2>
1338 const bool elide_zero_values,
1349template <
typename number>
1355 return entry->
value;
1361template <
typename number>
1367 return entry->
value;
1373template <
typename number>
1381template <
typename number>
1388template <
typename number>
1397template <
typename number>
1406template <
typename number>
1407template <
typename MatrixType>
1410 const bool elide_zero_values)
1412 reinit(M.m(), M.n(), this->saved_default_row_length, this->increment);
1417 for (
size_type row = 0; row < M.m(); ++row)
1419 const typename MatrixType::const_iterator end_row = M.end(row);
1420 for (
typename MatrixType::const_iterator entry = M.begin(row);
1423 set(row, entry->column(), entry->value(), elide_zero_values);
1429template <
typename number>
1430template <
typename MatrixType>
1443 for (
size_type row = 0; row < M.m(); ++row)
1445 const typename MatrixType::const_iterator end_row = M.end(row);
1446 for (
typename MatrixType::const_iterator entry = M.begin(row);
1449 if (entry->value() != 0)
1450 add(row, entry->column(), factor * entry->value());
1456template <
typename number>
1457template <
typename MatrixTypeA,
typename MatrixTypeB>
1460 const MatrixTypeB &B,
1479 typename MatrixTypeB::const_iterator b1 = B.begin();
1480 const typename MatrixTypeB::const_iterator b_final = B.end();
1482 while (b1 != b_final)
1486 typename MatrixTypeB::const_iterator b2 = B.begin();
1487 while (b2 != b_final)
1492 const typename MatrixTypeA::value_type a =
A.el(k,
l);
1495 add(i, j, a * b1->value() * b2->value());
1506 std::vector<size_type> minrow(B.n(), B.m());
1507 std::vector<size_type> maxrow(B.n(), 0);
1508 while (b1 != b_final)
1511 if (r < minrow[b1->column()])
1512 minrow[b1->column()] = r;
1513 if (r > maxrow[b1->column()])
1514 maxrow[b1->column()] = r;
1518 typename MatrixTypeA::const_iterator ai =
A.begin();
1519 const typename MatrixTypeA::const_iterator ae =
A.end();
1523 const typename MatrixTypeA::value_type a = ai->value();
1533 b1 = B.begin(minrow[ai->row()]);
1534 const typename MatrixTypeB::const_iterator be1 =
1535 B.end(maxrow[ai->row()]);
1536 const typename MatrixTypeB::const_iterator be2 =
1537 B.end(maxrow[ai->column()]);
1541 const double b1v = b1->value();
1546 if (b1->column() == ai->row() && (b1v != 0.))
1550 typename MatrixTypeB::const_iterator b2 =
1551 B.begin(minrow[ai->column()]);
1554 if (b2->column() == ai->column())
1557 add(i, j, a * b1v * b2->value());
1570template <
typename number>
1571template <
class StreamType>
1578 std::vector<size_type> used_by_line;
1582 out <<
"SparseMatrixEZ:used entries:" << used << std::endl
1583 <<
"SparseMatrixEZ:allocated entries:" << allocated << std::endl
1584 <<
"SparseMatrixEZ:reserved entries:" << reserved << std::endl;
1588 for (
size_type i = 0; i < used_by_line.size(); ++i)
1589 if (used_by_line[i] != 0)
1590 out <<
"SparseMatrixEZ:entries\t" << i <<
"\trows\t"
1591 << used_by_line[i] << std::endl;
SparseMatrixEZ< number > & copy_from(const MatrixType &source, const bool elide_zero_values=true)
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)
void print_statistics(StreamType &s, bool full=false)
void Tvmult_add(Vector< somenumber > &dst, const Vector< somenumber > &src) 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
~SparseMatrixEZ() override=default
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
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 vmult_add(Vector< somenumber > &dst, const Vector< somenumber > &src) const
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
number el(const size_type i, const size_type j) const
const_iterator begin() const
void set(const size_type i, const size_type j, const number value, const bool elide_zero_values=true)
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
void block_read(std::istream &in)
#define DeclException0(Exception0)
std::vector< Entry > data
static ::ExceptionBase & ExcInvalidEntry(int arg1, int arg2)
const Accessor & operator*() const
const_iterator(const SparseMatrixEZ< number > *matrix, const size_type row, const unsigned short index)
void block_write(std::ostream &out) const
bool operator<(const const_iterator &) const
const Entry * locate(const size_type row, const size_type col) const
static const size_type invalid
static ::ExceptionBase & ExcNoDiagonal()
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
static const unsigned short invalid_diagonal
#define Assert(cond, exc)
unsigned short index() const
static ::ExceptionBase & ExcIteratorPastEnd()
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
#define AssertIsFinite(number)
#define DeclException2(Exception2, type1, type2, outsequence)
static ::ExceptionBase & ExcEntryAllocationFailure(int arg1, int arg2)
bool operator==(const const_iterator &) const
void print(std::ostream &out) const
RowInfo(const size_type start=Entry::invalid)
void threaded_vmult(Vector< somenumber > &dst, const Vector< somenumber > &src, const size_type begin_row, const size_type end_row) const
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
bool operator!=(const const_iterator &) const
const_iterator & operator++()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
std::vector< RowInfo > row_info
const SparseMatrixEZ< number > * matrix
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
const Accessor * operator->() const
Accessor(const SparseMatrixEZ< number > *matrix, const size_type row, const unsigned short index)
@ matrix
Contents is actually a matrix.
@ diagonal
Matrix is diagonal.
void swap(MemorySpaceData< Number, MemorySpace > &, MemorySpaceData< Number, MemorySpace > &)
Tensor< 2, dim, Number > l(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
const types::global_dof_index invalid_size_type
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)
unsigned int global_dof_index