Reference documentation for deal.II version 9.0.0
petsc_matrix_base.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2004 - 2018 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_petsc_matrix_base_h
17 #define dealii_petsc_matrix_base_h
18 
19 
20 #include <deal.II/base/config.h>
21 
22 #ifdef DEAL_II_WITH_PETSC
23 
24 # include <deal.II/base/subscriptor.h>
25 # include <deal.II/lac/exceptions.h>
26 # include <deal.II/lac/full_matrix.h>
27 # include <deal.II/lac/petsc_compatibility.h>
28 # include <deal.II/lac/vector_operation.h>
29 # include <deal.II/lac/petsc_vector_base.h>
30 
31 # include <petscmat.h>
32 
33 # include <vector>
34 # include <cmath>
35 # include <memory>
36 
37 DEAL_II_NAMESPACE_OPEN
38 
39 template <typename Matrix> class BlockMatrixBase;
40 
41 
42 namespace PETScWrappers
43 {
44  // forward declarations
45  class MatrixBase;
46 
47  namespace MatrixIterators
48  {
64  {
65  private:
69  class Accessor
70  {
71  public:
76 
81  Accessor (const MatrixBase *matrix,
82  const size_type row,
83  const size_type index);
84 
88  size_type row() const;
89 
93  size_type index() const;
94 
98  size_type column() const;
99 
103  PetscScalar value() const;
104 
113  int, int, int,
114  << "You tried to access row " << arg1
115  << " of a distributed matrix, but only rows "
116  << arg2 << " through " << arg3
117  << " are stored locally and can be accessed.");
118 
119  private:
123  mutable MatrixBase *matrix;
124 
129 
134 
147  std::shared_ptr<const std::vector<size_type> > colnum_cache;
148 
152  std::shared_ptr<const std::vector<PetscScalar> > value_cache;
153 
159  void visit_present_row ();
160 
164  friend class const_iterator;
165  };
166 
167  public:
172 
177  const_iterator (const MatrixBase *matrix,
178  const size_type row,
179  const size_type index);
180 
185 
190 
194  const Accessor &operator* () const;
195 
199  const Accessor *operator-> () const;
200 
205  bool operator == (const const_iterator &) const;
209  bool operator != (const const_iterator &) const;
210 
216  bool operator < (const const_iterator &) const;
217 
222  int, int,
223  << "Attempt to access element " << arg2
224  << " of row " << arg1
225  << " which doesn't have that many elements.");
226 
227  private:
232  };
233 
234  }
235 
236 
269  class MatrixBase : public Subscriptor
270  {
271  public:
276 
281 
285  typedef PetscScalar value_type;
286 
290  MatrixBase ();
291 
297  MatrixBase(const MatrixBase &) = delete;
298 
304  MatrixBase &operator=(const MatrixBase &) = delete;
305 
309  virtual ~MatrixBase ();
310 
320  MatrixBase &
321  operator = (const value_type d);
326  void clear ();
327 
337  void set (const size_type i,
338  const size_type j,
339  const PetscScalar value);
340 
360  void set (const std::vector<size_type> &indices,
361  const FullMatrix<PetscScalar> &full_matrix,
362  const bool elide_zero_values = false);
363 
369  void set (const std::vector<size_type> &row_indices,
370  const std::vector<size_type> &col_indices,
371  const FullMatrix<PetscScalar> &full_matrix,
372  const bool elide_zero_values = false);
373 
388  void set (const size_type row,
389  const std::vector<size_type > &col_indices,
390  const std::vector<PetscScalar> &values,
391  const bool elide_zero_values = false);
392 
407  void set (const size_type row,
408  const size_type n_cols,
409  const size_type *col_indices,
410  const PetscScalar *values,
411  const bool elide_zero_values = false);
412 
422  void add (const size_type i,
423  const size_type j,
424  const PetscScalar value);
425 
445  void add (const std::vector<size_type> &indices,
446  const FullMatrix<PetscScalar> &full_matrix,
447  const bool elide_zero_values = true);
448 
454  void add (const std::vector<size_type> &row_indices,
455  const std::vector<size_type> &col_indices,
456  const FullMatrix<PetscScalar> &full_matrix,
457  const bool elide_zero_values = true);
458 
473  void add (const size_type row,
474  const std::vector<size_type> &col_indices,
475  const std::vector<PetscScalar> &values,
476  const bool elide_zero_values = true);
477 
492  void add (const size_type row,
493  const size_type n_cols,
494  const size_type *col_indices,
495  const PetscScalar *values,
496  const bool elide_zero_values = true,
497  const bool col_indices_are_sorted = false);
498 
515  void clear_row (const size_type row,
516  const PetscScalar new_diag_value = 0);
517 
526  void clear_rows (const std::vector<size_type> &rows,
527  const PetscScalar new_diag_value = 0);
528 
540  void compress (const VectorOperation::values operation);
541 
553  PetscScalar operator () (const size_type i,
554  const size_type j) const;
555 
563  PetscScalar el (const size_type i,
564  const size_type j) const;
565 
575  PetscScalar diag_element (const size_type i) const;
576 
580  size_type m () const;
581 
585  size_type n () const;
586 
595  size_type local_size () const;
596 
605  std::pair<size_type, size_type>
606  local_range () const;
607 
612  bool in_local_range (const size_type index) const;
613 
618  virtual const MPI_Comm &get_mpi_communicator () const = 0;
619 
625  size_type n_nonzero_elements () const;
626 
630  size_type row_length (const size_type row) const;
631 
639  PetscReal l1_norm () const;
640 
648  PetscReal linfty_norm () const;
649 
654  PetscReal frobenius_norm () const;
655 
656 
676  PetscScalar matrix_norm_square (const VectorBase &v) const;
677 
678 
692  PetscScalar matrix_scalar_product (const VectorBase &u,
693  const VectorBase &v) const;
694 
699  PetscScalar trace () const;
700 
704  MatrixBase &operator *= (const PetscScalar factor);
705 
709  MatrixBase &operator /= (const PetscScalar factor);
710 
711 
716  MatrixBase &add (const PetscScalar factor,
717  const MatrixBase &other);
718 
719 
725  DEAL_II_DEPRECATED
726  MatrixBase &add (const MatrixBase &other,
727  const PetscScalar factor);
728 
740  void vmult (VectorBase &dst,
741  const VectorBase &src) const;
742 
755  void Tvmult (VectorBase &dst,
756  const VectorBase &src) const;
757 
769  void vmult_add (VectorBase &dst,
770  const VectorBase &src) const;
771 
784  void Tvmult_add (VectorBase &dst,
785  const VectorBase &src) const;
786 
799  PetscScalar residual (VectorBase &dst,
800  const VectorBase &x,
801  const VectorBase &b) const;
802 
806  const_iterator begin () const;
807 
811  const_iterator end () const;
812 
821  const_iterator begin (const size_type r) const;
822 
831  const_iterator end (const size_type r) const;
832 
840  operator Mat () const;
841 
847  Mat &petsc_matrix ();
848 
852  void transpose ();
853 
858  PetscBool
859  is_symmetric (const double tolerance = 1.e-12);
860 
866  PetscBool
867  is_hermitian (const double tolerance = 1.e-12);
868 
875  void write_ascii (const PetscViewerFormat format = PETSC_VIEWER_DEFAULT);
876 
884  void print (std::ostream &out,
885  const bool alternative_output = false) const;
886 
890  std::size_t memory_consumption() const;
891 
896  "You are attempting an operation on two matrices that "
897  "are the same object, but the operation requires that the "
898  "two objects are in fact different.");
899 
904  int, int,
905  << "You tried to do a "
906  << (arg1 == 1 ?
907  "'set'" :
908  (arg1 == 2 ?
909  "'add'" : "???"))
910  << " operation but the matrix is currently in "
911  << (arg2 == 1 ?
912  "'set'" :
913  (arg2 == 2 ?
914  "'add'" : "???"))
915  << " mode. You first have to call 'compress()'.");
916 
917  protected:
922  Mat matrix;
923 
928 
934  void prepare_action(const VectorOperation::values new_action);
935 
941  void assert_is_compressed();
942 
953  void prepare_add();
959  void prepare_set();
960 
976  void mmult (MatrixBase &C,
977  const MatrixBase &B,
978  const VectorBase &V) const;
979 
996  void Tmmult (MatrixBase &C,
997  const MatrixBase &B,
998  const VectorBase &V) const;
999 
1000  private:
1001 
1016  mutable std::vector<PetscInt> column_indices;
1017 
1026  mutable std::vector<PetscScalar> column_values;
1027 
1028 
1032  template <class> friend class ::BlockMatrixBase;
1033  };
1034 
1035 
1036 
1037 #ifndef DOXYGEN
1038 // -------------------------- inline and template functions ----------------------
1039 
1040 
1041  namespace MatrixIterators
1042  {
1043 
1044  inline
1046  Accessor (const MatrixBase *matrix,
1047  const size_type row,
1048  const size_type index)
1049  :
1050  matrix(const_cast<MatrixBase *>(matrix)),
1051  a_row(row),
1052  a_index(index)
1053  {
1054  visit_present_row ();
1055  }
1056 
1057 
1058 
1059  inline
1062  {
1063  Assert (a_row < matrix->m(), ExcBeyondEndOfMatrix());
1064  return a_row;
1065  }
1066 
1067 
1068  inline
1071  {
1072  Assert (a_row < matrix->m(), ExcBeyondEndOfMatrix());
1073  return (*colnum_cache)[a_index];
1074  }
1075 
1076 
1077  inline
1080  {
1081  Assert (a_row < matrix->m(), ExcBeyondEndOfMatrix());
1082  return a_index;
1083  }
1084 
1085 
1086  inline
1087  PetscScalar
1089  {
1090  Assert (a_row < matrix->m(), ExcBeyondEndOfMatrix());
1091  return (*value_cache)[a_index];
1092  }
1093 
1094 
1095  inline
1097  const_iterator(const MatrixBase *matrix,
1098  const size_type row,
1099  const size_type index)
1100  :
1101  accessor(matrix, row, index)
1102  {}
1103 
1104 
1105 
1106  inline
1107  const_iterator &
1108  const_iterator::operator++ ()
1109  {
1110  Assert (accessor.a_row < accessor.matrix->m(), ExcIteratorPastEnd());
1111 
1112  ++accessor.a_index;
1113 
1114  // if at end of line: do one step, then cycle until we find a
1115  // row with a nonzero number of entries
1116  if (accessor.a_index >= accessor.colnum_cache->size())
1117  {
1118  accessor.a_index = 0;
1119  ++accessor.a_row;
1120 
1121  while ((accessor.a_row < accessor.matrix->m())
1122  &&
1123  (accessor.a_row < accessor.matrix->local_range().second)
1124  &&
1125  (accessor.matrix->row_length(accessor.a_row) == 0))
1126  ++accessor.a_row;
1127 
1128  accessor.visit_present_row();
1129  }
1130  return *this;
1131  }
1132 
1133 
1134  inline
1135  const_iterator
1136  const_iterator::operator++ (int)
1137  {
1138  const const_iterator old_state = *this;
1139  ++(*this);
1140  return old_state;
1141  }
1142 
1143 
1144  inline
1145  const const_iterator::Accessor &
1147  {
1148  return accessor;
1149  }
1150 
1151 
1152  inline
1153  const const_iterator::Accessor *
1154  const_iterator::operator-> () const
1155  {
1156  return &accessor;
1157  }
1158 
1159 
1160  inline
1161  bool
1162  const_iterator::
1163  operator == (const const_iterator &other) const
1164  {
1165  return (accessor.a_row == other.accessor.a_row &&
1166  accessor.a_index == other.accessor.a_index);
1167  }
1168 
1169 
1170  inline
1171  bool
1172  const_iterator::
1173  operator != (const const_iterator &other) const
1174  {
1175  return ! (*this == other);
1176  }
1177 
1178 
1179  inline
1180  bool
1181  const_iterator::
1182  operator < (const const_iterator &other) const
1183  {
1184  return (accessor.row() < other.accessor.row() ||
1185  (accessor.row() == other.accessor.row() &&
1186  accessor.index() < other.accessor.index()));
1187  }
1188 
1189  }
1190 
1191 
1192 
1193  // Inline the set() and add()
1194  // functions, since they will be
1195  // called frequently, and the
1196  // compiler can optimize away
1197  // some unnecessary loops when
1198  // the sizes are given at
1199  // compile time.
1200  inline
1201  void
1202  MatrixBase::set (const size_type i,
1203  const size_type j,
1204  const PetscScalar value)
1205  {
1206  AssertIsFinite(value);
1207 
1208  set (i, 1, &j, &value, false);
1209  }
1210 
1211 
1212 
1213  inline
1214  void
1215  MatrixBase::set (const std::vector<size_type> &indices,
1216  const FullMatrix<PetscScalar> &values,
1217  const bool elide_zero_values)
1218  {
1219  Assert (indices.size() == values.m(),
1220  ExcDimensionMismatch(indices.size(), values.m()));
1221  Assert (values.m() == values.n(), ExcNotQuadratic());
1222 
1223  for (size_type i=0; i<indices.size(); ++i)
1224  set (indices[i], indices.size(), indices.data(), &values(i,0),
1225  elide_zero_values);
1226  }
1227 
1228 
1229 
1230  inline
1231  void
1232  MatrixBase::set (const std::vector<size_type> &row_indices,
1233  const std::vector<size_type> &col_indices,
1234  const FullMatrix<PetscScalar> &values,
1235  const bool elide_zero_values)
1236  {
1237  Assert (row_indices.size() == values.m(),
1238  ExcDimensionMismatch(row_indices.size(), values.m()));
1239  Assert (col_indices.size() == values.n(),
1240  ExcDimensionMismatch(col_indices.size(), values.n()));
1241 
1242  for (size_type i=0; i<row_indices.size(); ++i)
1243  set (row_indices[i], col_indices.size(), col_indices.data(), &values(i,0),
1244  elide_zero_values);
1245  }
1246 
1247 
1248 
1249  inline
1250  void
1251  MatrixBase::set (const size_type row,
1252  const std::vector<size_type> &col_indices,
1253  const std::vector<PetscScalar> &values,
1254  const bool elide_zero_values)
1255  {
1256  Assert (col_indices.size() == values.size(),
1257  ExcDimensionMismatch(col_indices.size(), values.size()));
1258 
1259  set (row, col_indices.size(), col_indices.data(), values.data(),
1260  elide_zero_values);
1261  }
1262 
1263 
1264 
1265  inline
1266  void
1267  MatrixBase::set (const size_type row,
1268  const size_type n_cols,
1269  const size_type *col_indices,
1270  const PetscScalar *values,
1271  const bool elide_zero_values)
1272  {
1273  prepare_action(VectorOperation::insert);
1274 
1275  const PetscInt petsc_i = row;
1276  PetscInt const *col_index_ptr;
1277 
1278  PetscScalar const *col_value_ptr;
1279  int n_columns;
1280 
1281  // If we don't elide zeros, the pointers are already available...
1282  if (elide_zero_values == false)
1283  {
1284  col_index_ptr = reinterpret_cast<const PetscInt *>(col_indices);
1285  col_value_ptr = values;
1286  n_columns = n_cols;
1287  }
1288  else
1289  {
1290  // Otherwise, extract nonzero values in each row and get the
1291  // respective index.
1292  if (column_indices.size() < n_cols)
1293  {
1294  column_indices.resize(n_cols);
1295  column_values.resize(n_cols);
1296  }
1297 
1298  n_columns = 0;
1299  for (size_type j=0; j<n_cols; ++j)
1300  {
1301  const PetscScalar value = values[j];
1302  AssertIsFinite(value);
1303  if (value != PetscScalar())
1304  {
1305  column_indices[n_columns] = col_indices[j];
1306  column_values[n_columns] = value;
1307  n_columns++;
1308  }
1309  }
1310  Assert(n_columns <= (int)n_cols, ExcInternalError());
1311 
1312  col_index_ptr = column_indices.data();
1313  col_value_ptr = column_values.data();
1314  }
1315 
1316  const PetscErrorCode ierr = MatSetValues (matrix, 1, &petsc_i, n_columns,
1317  col_index_ptr,
1318  col_value_ptr, INSERT_VALUES);
1319  AssertThrow (ierr == 0, ExcPETScError(ierr));
1320  }
1321 
1322 
1323 
1324  inline
1325  void
1326  MatrixBase::add (const size_type i,
1327  const size_type j,
1328  const PetscScalar value)
1329  {
1330 
1331  AssertIsFinite(value);
1332 
1333  if (value == PetscScalar())
1334  {
1335  // we have to check after using Insert/Add in any case to be
1336  // consistent with the MPI communication model, but we can save
1337  // some work if the addend is zero. However, these actions are done
1338  // in case we pass on to the other function.
1339  prepare_action(VectorOperation::add);
1340 
1341  return;
1342  }
1343  else
1344  add (i, 1, &j, &value, false);
1345  }
1346 
1347 
1348 
1349  inline
1350  void
1351  MatrixBase::add (const std::vector<size_type> &indices,
1352  const FullMatrix<PetscScalar> &values,
1353  const bool elide_zero_values)
1354  {
1355  Assert (indices.size() == values.m(),
1356  ExcDimensionMismatch(indices.size(), values.m()));
1357  Assert (values.m() == values.n(), ExcNotQuadratic());
1358 
1359  for (size_type i=0; i<indices.size(); ++i)
1360  add (indices[i], indices.size(), indices.data(), &values(i,0),
1361  elide_zero_values);
1362  }
1363 
1364 
1365 
1366  inline
1367  void
1368  MatrixBase::add (const std::vector<size_type> &row_indices,
1369  const std::vector<size_type> &col_indices,
1370  const FullMatrix<PetscScalar> &values,
1371  const bool elide_zero_values)
1372  {
1373  Assert (row_indices.size() == values.m(),
1374  ExcDimensionMismatch(row_indices.size(), values.m()));
1375  Assert (col_indices.size() == values.n(),
1376  ExcDimensionMismatch(col_indices.size(), values.n()));
1377 
1378  for (size_type i=0; i<row_indices.size(); ++i)
1379  add (row_indices[i], col_indices.size(), col_indices.data(), &values(i,0),
1380  elide_zero_values);
1381  }
1382 
1383 
1384 
1385  inline
1386  void
1387  MatrixBase::add (const size_type row,
1388  const std::vector<size_type> &col_indices,
1389  const std::vector<PetscScalar> &values,
1390  const bool elide_zero_values)
1391  {
1392  Assert (col_indices.size() == values.size(),
1393  ExcDimensionMismatch(col_indices.size(), values.size()));
1394 
1395  add (row, col_indices.size(), col_indices.data(), values.data(),
1396  elide_zero_values);
1397  }
1398 
1399 
1400 
1401  inline
1402  void
1403  MatrixBase::add (const size_type row,
1404  const size_type n_cols,
1405  const size_type *col_indices,
1406  const PetscScalar *values,
1407  const bool elide_zero_values,
1408  const bool /*col_indices_are_sorted*/)
1409  {
1410  (void)elide_zero_values;
1411 
1412  prepare_action(VectorOperation::add);
1413 
1414  const PetscInt petsc_i = row;
1415  PetscInt const *col_index_ptr;
1416 
1417  PetscScalar const *col_value_ptr;
1418  int n_columns;
1419 
1420  // If we don't elide zeros, the pointers are already available...
1421  if (elide_zero_values == false)
1422  {
1423  col_index_ptr = reinterpret_cast<const PetscInt *>(col_indices);
1424  col_value_ptr = values;
1425  n_columns = n_cols;
1426  }
1427  else
1428  {
1429  // Otherwise, extract nonzero values in each row and get the
1430  // respective index.
1431  if (column_indices.size() < n_cols)
1432  {
1433  column_indices.resize(n_cols);
1434  column_values.resize(n_cols);
1435  }
1436 
1437  n_columns = 0;
1438  for (size_type j=0; j<n_cols; ++j)
1439  {
1440  const PetscScalar value = values[j];
1441  AssertIsFinite(value);
1442  if (value != PetscScalar())
1443  {
1444  column_indices[n_columns] = col_indices[j];
1445  column_values[n_columns] = value;
1446  n_columns++;
1447  }
1448  }
1449  Assert(n_columns <= (int)n_cols, ExcInternalError());
1450 
1451  col_index_ptr = column_indices.data();
1452  col_value_ptr = column_values.data();
1453  }
1454 
1455  const PetscErrorCode ierr = MatSetValues (matrix, 1, &petsc_i, n_columns,
1456  col_index_ptr, col_value_ptr,
1457  ADD_VALUES);
1458  AssertThrow (ierr == 0, ExcPETScError(ierr));
1459  }
1460 
1461 
1462 
1463 
1464 
1465 
1466  inline
1467  PetscScalar
1468  MatrixBase::operator() (const size_type i,
1469  const size_type j) const
1470  {
1471  return el(i,j);
1472  }
1473 
1474 
1475 
1476  inline
1477  MatrixBase::const_iterator
1478  MatrixBase::begin() const
1479  {
1480  return const_iterator(this, 0, 0);
1481  }
1482 
1483 
1484  inline
1485  MatrixBase::const_iterator
1486  MatrixBase::end() const
1487  {
1488  return const_iterator(this, m(), 0);
1489  }
1490 
1491 
1492  inline
1493  MatrixBase::const_iterator
1494  MatrixBase::begin(const size_type r) const
1495  {
1496  Assert (in_local_range(r),
1497  ExcIndexRange(r, local_range().first, local_range().second));
1498 
1499  if (row_length(r) > 0)
1500  return const_iterator(this, r, 0);
1501  else
1502  return end (r);
1503  }
1504 
1505 
1506  inline
1507  MatrixBase::const_iterator
1508  MatrixBase::end(const size_type r) const
1509  {
1510  Assert (in_local_range(r),
1511  ExcIndexRange(r, local_range().first, local_range().second));
1512 
1513  // place the iterator on the first entry past this line, or at the
1514  // end of the matrix
1515  //
1516  // in the parallel case, we need to put it on the first entry of
1517  // the first row after the locally owned range. this of course
1518  // doesn't exist, but we can nevertheless create such an
1519  // iterator. we need to check whether 'i' is past the locally
1520  // owned range of rows first, before we ask for the length of the
1521  // row since the latter query leads to an exception in case we ask
1522  // for a row that is not locally owned
1523  for (size_type i=r+1; i<m(); ++i)
1524  if (i == local_range().second || (row_length(i) > 0))
1525  return const_iterator(this, i, 0);
1526 
1527  // if there is no such line, then take the
1528  // end iterator of the matrix
1529  return end();
1530  }
1531 
1532 
1533 
1534  inline
1535  bool
1536  MatrixBase::in_local_range (const size_type index) const
1537  {
1538  PetscInt begin, end;
1539 
1540  const PetscErrorCode ierr = MatGetOwnershipRange (static_cast<const Mat &>(matrix),
1541  &begin, &end);
1542  AssertThrow (ierr == 0, ExcPETScError(ierr));
1543 
1544  return ((index >= static_cast<size_type>(begin)) &&
1545  (index < static_cast<size_type>(end)));
1546  }
1547 
1548 
1549 
1550  inline
1551  void
1552  MatrixBase::prepare_action(const VectorOperation::values new_action)
1553  {
1554  if (last_action == VectorOperation::unknown)
1555  last_action = new_action;
1556 
1557  Assert (last_action == new_action, ExcWrongMode (last_action, new_action));
1558  }
1559 
1560 
1561 
1562  inline
1563  void
1564  MatrixBase::assert_is_compressed ()
1565  {
1566  // compress() sets the last action to none, which allows us to check if there
1567  // are pending add/insert operations:
1568  AssertThrow (last_action == VectorOperation::unknown,
1569  ExcMessage("Error: missing compress() call."));
1570  }
1571 
1572 
1573 
1574  inline
1575  void
1576  MatrixBase::prepare_add()
1577  {
1578  prepare_action(VectorOperation::add);
1579  }
1580 
1581 
1582 
1583  inline
1584  void
1585  MatrixBase::prepare_set()
1586  {
1587  prepare_action(VectorOperation::insert);
1588  }
1589 
1590 #endif // DOXYGEN
1591 }
1592 
1593 
1594 DEAL_II_NAMESPACE_CLOSE
1595 
1596 
1597 #endif // DEAL_II_WITH_PETSC
1598 
1599 
1600 /*---------------------------- petsc_matrix_base.h ---------------------------*/
1601 
1602 #endif
1603 /*---------------------------- petsc_matrix_base.h ---------------------------*/
size_type m() const
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:358
bool operator==(const const_iterator &) const
void Tmmult(MatrixBase &C, const MatrixBase &B, const VectorBase &V) const
Contents is actually a matrix.
PetscScalar matrix_scalar_product(const VectorBase &u, const VectorBase &v) const
static ::ExceptionBase & ExcBeyondEndOfMatrix()
void add(const size_type i, const size_type j, const PetscScalar value)
void vmult(VectorBase &dst, const VectorBase &src) const
const_iterator begin() const
PetscReal frobenius_norm() const
static ::ExceptionBase & ExcInvalidIndexWithinRow(int arg1, int arg2)
std::shared_ptr< const std::vector< PetscScalar > > value_cache
size_type row_length(const size_type row) const
#define AssertThrow(cond, exc)
Definition: exceptions.h:1221
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
SymmetricTensor< rank_, dim, Number > operator*(const SymmetricTensor< rank_, dim, Number > &t, const Number &factor)
PetscBool is_symmetric(const double tolerance=1.e-12)
PetscBool is_hermitian(const double tolerance=1.e-12)
void clear_rows(const std::vector< size_type > &rows, const PetscScalar new_diag_value=0)
std::vector< PetscInt > column_indices
const_iterator(const MatrixBase *matrix, const size_type row, const size_type index)
void compress(const VectorOperation::values operation)
std::vector< PetscScalar > column_values
MatrixIterators::const_iterator const_iterator
size_type n_nonzero_elements() const
MatrixBase & operator=(const MatrixBase &)=delete
static ::ExceptionBase & ExcMessage(std::string arg1)
size_type n() const
unsigned int global_dof_index
Definition: types.h:88
Accessor(const MatrixBase *matrix, const size_type row, const size_type index)
bool operator<(const const_iterator &) const
#define Assert(cond, exc)
Definition: exceptions.h:1142
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
#define DeclExceptionMsg(Exception, defaulttext)
Definition: exceptions.h:335
#define DeclException0(Exception0)
Definition: exceptions.h:323
void vmult_add(VectorBase &dst, const VectorBase &src) const
PetscScalar residual(VectorBase &dst, const VectorBase &x, const VectorBase &b) const
void mmult(MatrixBase &C, const MatrixBase &B, const VectorBase &V) const
types::global_dof_index size_type
PetscScalar diag_element(const size_type i) const
void Tvmult(VectorBase &dst, const VectorBase &src) const
PetscScalar el(const size_type i, const size_type j) const
void Tvmult_add(VectorBase &dst, const VectorBase &src) const
const_iterator end() const
PetscScalar operator()(const size_type i, const size_type j) const
std::shared_ptr< const std::vector< size_type > > colnum_cache
static ::ExceptionBase & ExcIteratorPastEnd()
void print(std::ostream &out, const bool alternative_output=false) const
static ::ExceptionBase & ExcNotQuadratic()
void write_ascii(const PetscViewerFormat format=PETSC_VIEWER_DEFAULT)
VectorOperation::values last_action
void prepare_action(const VectorOperation::values new_action)
bool in_local_range(const size_type index) const
MatrixBase & operator*=(const PetscScalar factor)
std::pair< size_type, size_type > local_range() const
static ::ExceptionBase & ExcAccessToNonlocalRow(int arg1, int arg2, int arg3)
PetscScalar matrix_norm_square(const VectorBase &v) const
MatrixBase & operator/=(const PetscScalar factor)
static ::ExceptionBase & ExcSourceEqualsDestination()
static ::ExceptionBase & ExcWrongMode(int arg1, int arg2)
#define DeclException3(Exception3, type1, type2, type3, outsequence)
Definition: exceptions.h:370
bool operator!=(const const_iterator &) const
virtual const MPI_Comm & get_mpi_communicator() const =0
#define AssertIsFinite(number)
Definition: exceptions.h:1299
void clear_row(const size_type row, const PetscScalar new_diag_value=0)
std::size_t memory_consumption() const
static ::ExceptionBase & ExcInternalError()