16 #ifndef dealii_sparse_matrix_ez_h
17 # define dealii_sparse_matrix_ez_h
33 template <
typename number>
35 template <
typename number>
106 template <
typename number>
174 static_cast<unsigned short>(-1);
196 const unsigned short index);
248 const unsigned short index);
324 const unsigned int default_increment = 1);
359 unsigned int default_increment = 1,
418 template <
class StreamType>
435 std::vector<size_type> &used_by_line,
436 const bool compute_by_line)
const;
462 const bool elide_zero_values =
true);
486 template <
typename number2>
488 add(
const std::vector<size_type> &indices,
490 const bool elide_zero_values =
true);
497 template <
typename number2>
499 add(
const std::vector<size_type> &row_indices,
500 const std::vector<size_type> &col_indices,
502 const bool elide_zero_values =
true);
513 template <
typename number2>
516 const std::vector<size_type> &col_indices,
517 const std::vector<number2> & values,
518 const bool elide_zero_values =
true);
529 template <
typename number2>
534 const number2 * values,
535 const bool elide_zero_values =
true,
536 const bool col_indices_are_sorted =
false);
559 template <
typename MatrixType>
561 copy_from(
const MatrixType &source,
const bool elide_zero_values =
true);
570 template <
typename MatrixType>
572 add(
const number factor,
const MatrixType &
matrix);
605 template <
typename somenumber>
607 vmult(Vector<somenumber> &dst,
const Vector<somenumber> &src)
const;
614 template <
typename somenumber>
616 Tvmult(Vector<somenumber> &dst,
const Vector<somenumber> &src)
const;
622 template <
typename somenumber>
624 vmult_add(Vector<somenumber> &dst,
const Vector<somenumber> &src)
const;
631 template <
typename somenumber>
633 Tvmult_add(Vector<somenumber> &dst,
const Vector<somenumber> &src)
const;
654 template <
typename somenumber>
657 const Vector<somenumber> &src,
658 const number omega = 1.)
const;
663 template <
typename somenumber>
666 const Vector<somenumber> & src,
667 const number om = 1.,
668 const std::vector<std::size_t> &pos_right_of_diagonal =
669 std::vector<std::size_t>())
const;
675 template <
typename somenumber>
678 const Vector<somenumber> &src,
679 const number om = 1.)
const;
685 template <
typename somenumber>
688 const Vector<somenumber> &src,
689 const number om = 1.)
const;
699 template <
typename MatrixTypeA,
typename MatrixTypeB>
702 const MatrixTypeB &B,
744 print(std::ostream &out)
const;
768 const unsigned int precision = 3,
769 const bool scientific =
true,
770 const unsigned int width = 0,
771 const char * zero_string =
" ",
772 const double denominator = 1.)
const;
812 <<
"The entry with index (" << arg1 <<
',' << arg2
813 <<
") does not exist.");
818 <<
"An entry with index (" << arg1 <<
',' << arg2
819 <<
") cannot be allocated.");
847 template <
typename somenumber>
850 const Vector<somenumber> &src,
859 template <
typename somenumber>
864 somenumber * partial_sum)
const;
871 template <
typename somenumber>
874 const Vector<somenumber> &v,
877 somenumber * partial_sum)
const;
910 template <
typename number>
912 const number &
value)
919 template <
typename number>
926 template <
typename number>
935 template <
typename number>
939 const unsigned short i)
946 template <
typename number>
954 template <
typename number>
958 return matrix->data[
matrix->row_info[a_row].start + a_index].column;
962 template <
typename number>
963 inline unsigned short
971 template <
typename number>
975 return matrix->data[
matrix->row_info[a_row].start + a_index].value;
979 template <
typename number>
983 const unsigned short i)
1013 template <
typename number>
1020 ++(accessor.a_index);
1024 if (accessor.a_index >= accessor.matrix->row_info[accessor.a_row].length)
1026 accessor.a_index = 0;
1033 while (accessor.a_row < accessor.matrix->m() &&
1034 accessor.matrix->row_info[accessor.a_row].length == 0);
1040 template <
typename number>
1048 template <
typename number>
1056 template <
typename number>
1066 template <
typename number>
1071 return !(*
this == other);
1075 template <
typename number>
1087 template <
typename number>
1095 template <
typename number>
1103 template <
typename number>
1114 Entry *
const entry = &
data[i];
1115 if (entry->column == col)
1125 template <
typename number>
1130 return t->
locate(row, col);
1134 template <
typename number>
1151 while (i <
end &&
data[i].column < col)
1155 if (i !=
end &&
data[i].column == col)
1188 data.push_back(Entry());
1192 Entry *entry = &
data[i];
1194 Entry temp = *entry;
1199 entry->column = col;
1204 r.diagonal = i - r.start;
1232 template <
typename number>
1237 const bool elide_zero_values)
1244 if (elide_zero_values &&
value == 0.)
1246 Entry *entry =
locate(i, j);
1247 if (entry !=
nullptr)
1253 entry->value =
value;
1259 template <
typename number>
1271 if (std::abs(
value) == 0.)
1275 entry->value +=
value;
1279 template <
typename number>
1280 template <
typename number2>
1284 const bool elide_zero_values)
1287 for (
size_type i = 0; i < indices.size(); ++i)
1288 for (
size_type j = 0; j < indices.size(); ++j)
1289 if ((full_matrix(i, j) != 0) || (elide_zero_values ==
false))
1290 add(indices[i], indices[j], full_matrix(i, j));
1295 template <
typename number>
1296 template <
typename number2>
1299 const std::vector<size_type> &col_indices,
1301 const bool elide_zero_values)
1304 for (
size_type i = 0; i < row_indices.size(); ++i)
1305 for (
size_type j = 0; j < col_indices.size(); ++j)
1306 if ((full_matrix(i, j) != 0) || (elide_zero_values ==
false))
1307 add(row_indices[i], col_indices[j], full_matrix(i, j));
1312 template <
typename number>
1313 template <
typename number2>
1316 const std::vector<size_type> &col_indices,
1317 const std::vector<number2> & values,
1318 const bool elide_zero_values)
1321 for (
size_type j = 0; j < col_indices.size(); ++j)
1322 if ((values[j] != 0) || (elide_zero_values ==
false))
1323 add(row, col_indices[j], values[j]);
1328 template <
typename number>
1329 template <
typename number2>
1334 const number2 * values,
1335 const bool elide_zero_values,
1340 if ((std::abs(values[j]) != 0) || (elide_zero_values ==
false))
1341 add(row, col_indices[j], values[j]);
1346 template <
typename number>
1350 const Entry *entry =
locate(i, j);
1352 return entry->value;
1358 template <
typename number>
1362 const Entry *entry =
locate(i, j);
1364 return entry->value;
1370 template <
typename number>
1374 const_iterator result(
this, 0, 0);
1378 template <
typename number>
1382 return const_iterator(
this,
m(), 0);
1385 template <
typename number>
1390 const_iterator result(
this, r, 0);
1394 template <
typename number>
1399 const_iterator result(
this, r + 1, 0);
1403 template <
typename number>
1404 template <
typename MatrixType>
1407 const bool elide_zero_values)
1409 reinit(M.m(), M.n(), this->saved_default_row_length, this->increment);
1414 for (
size_type row = 0; row < M.m(); ++row)
1416 const typename MatrixType::const_iterator end_row = M.end(row);
1417 for (
typename MatrixType::const_iterator entry = M.begin(row);
1420 set(row, entry->column(), entry->value(), elide_zero_values);
1426 template <
typename number>
1427 template <
typename MatrixType>
1440 for (
size_type row = 0; row < M.m(); ++row)
1442 const typename MatrixType::const_iterator end_row = M.end(row);
1443 for (
typename MatrixType::const_iterator entry = M.begin(row);
1446 if (entry->value() != 0)
1447 add(row, entry->column(), factor * entry->value());
1453 template <
typename number>
1454 template <
typename MatrixTypeA,
typename MatrixTypeB>
1457 const MatrixTypeB &B,
1476 typename MatrixTypeB::const_iterator b1 = B.begin();
1477 const typename MatrixTypeB::const_iterator b_final = B.end();
1479 while (b1 != b_final)
1483 typename MatrixTypeB::const_iterator b2 = B.begin();
1484 while (b2 != b_final)
1489 const typename MatrixTypeA::value_type a =
A.el(k,
l);
1492 add(i, j, a * b1->value() * b2->value());
1503 std::vector<size_type> minrow(B.n(), B.m());
1504 std::vector<size_type> maxrow(B.n(), 0);
1505 while (b1 != b_final)
1508 if (r < minrow[b1->column()])
1509 minrow[b1->column()] = r;
1510 if (r > maxrow[b1->column()])
1511 maxrow[b1->column()] = r;
1515 typename MatrixTypeA::const_iterator ai =
A.begin();
1516 const typename MatrixTypeA::const_iterator ae =
A.end();
1520 const typename MatrixTypeA::value_type a = ai->value();
1530 b1 = B.begin(minrow[ai->row()]);
1531 const typename MatrixTypeB::const_iterator be1 =
1532 B.end(maxrow[ai->row()]);
1533 const typename MatrixTypeB::const_iterator be2 =
1534 B.end(maxrow[ai->column()]);
1538 const double b1v = b1->value();
1543 if (b1->column() == ai->row() && (b1v != 0.))
1547 typename MatrixTypeB::const_iterator b2 =
1548 B.begin(minrow[ai->column()]);
1551 if (b2->column() == ai->column())
1554 add(i, j, a * b1v * b2->value());
1567 template <
typename number>
1568 template <
class StreamType>
1575 std::vector<size_type> used_by_line;
1579 out <<
"SparseMatrixEZ:used entries:" << used << std::endl
1580 <<
"SparseMatrixEZ:allocated entries:" << allocated << std::endl
1581 <<
"SparseMatrixEZ:reserved entries:" << reserved << std::endl;
1585 for (
size_type i = 0; i < used_by_line.size(); ++i)
1586 if (used_by_line[i] != 0)
1587 out <<
"SparseMatrixEZ:entries\t" << i <<
"\trows\t"
1588 << used_by_line[i] << std::endl;