Reference documentation for deal.II version 9.0.0
trilinos_sparse_matrix.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2008 - 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_trilinos_sparse_matrix_h
17 #define dealii_trilinos_sparse_matrix_h
18 
19 
20 #include <deal.II/base/config.h>
21 
22 #ifdef DEAL_II_WITH_TRILINOS
23 
24 # include <deal.II/base/subscriptor.h>
25 # include <deal.II/base/index_set.h>
26 # include <deal.II/lac/full_matrix.h>
27 # include <deal.II/lac/exceptions.h>
28 # include <deal.II/lac/trilinos_vector.h>
29 # include <deal.II/lac/trilinos_epetra_vector.h>
30 # include <deal.II/lac/vector_memory.h>
31 #include <deal.II/lac/vector_operation.h>
32 
33 # include <type_traits>
34 # include <vector>
35 # include <cmath>
36 # include <memory>
37 
38 # include <Epetra_FECrsMatrix.h>
39 # include <Epetra_Export.h>
40 # include <Epetra_Map.h>
41 # include <Epetra_CrsGraph.h>
42 # include <Epetra_MultiVector.h>
43 # include <Epetra_Operator.h>
44 # include <Epetra_Comm.h>
45 # ifdef DEAL_II_WITH_MPI
46 # include <Epetra_MpiComm.h>
47 # include <mpi.h>
48 # else
49 # include <Epetra_SerialComm.h>
50 # endif
51 
52 DEAL_II_NAMESPACE_OPEN
53 
54 // forward declarations
55 template <typename MatrixType> class BlockMatrixBase;
56 
57 template <typename number> class SparseMatrix;
58 class SparsityPattern;
60 
61 
62 
63 namespace TrilinosWrappers
64 {
65  // forward declarations
66  class SparseMatrix;
67  class SparsityPattern;
68 
73  {
74  // forward declaration
75  template <bool Constness> class Iterator;
76 
81 
86  std::size_t, std::size_t, std::size_t,
87  << "You tried to access row " << arg1
88  << " of a distributed sparsity pattern, "
89  << " but only rows " << arg2 << " through " << arg3
90  << " are stored locally and can be accessed.");
91 
103  {
104  public:
108  typedef ::types::global_dof_index size_type;
109 
114  const size_type row,
115  const size_type index);
116 
120  size_type row() const;
121 
125  size_type index() const;
126 
130  size_type column() const;
131 
132  protected:
144 
149 
155  void visit_present_row ();
156 
169  std::shared_ptr<std::vector<size_type> > colnum_cache;
170 
174  std::shared_ptr<std::vector<TrilinosScalar> > value_cache;
175  };
176 
187  template <bool Constess>
188  class Accessor : public AccessorBase
189  {
193  TrilinosScalar value() const;
194 
198  TrilinosScalar &value();
199  };
200 
204  template <>
205  class Accessor<true> : public AccessorBase
206  {
207  public:
212  typedef const SparseMatrix MatrixType;
213 
219  const size_type row,
220  const size_type index);
221 
226  template <bool Other>
227  Accessor (const Accessor<Other> &a);
228 
232  TrilinosScalar value() const;
233 
234  private:
238  template <bool> friend class Iterator;
239  };
240 
244  template <>
245  class Accessor<false> : public AccessorBase
246  {
247  class Reference
248  {
249  public:
253  Reference (const Accessor<false> &accessor);
254 
258  operator TrilinosScalar () const;
259 
263  const Reference &operator = (const TrilinosScalar n) const;
264 
268  const Reference &operator += (const TrilinosScalar n) const;
269 
273  const Reference &operator -= (const TrilinosScalar n) const;
274 
278  const Reference &operator *= (const TrilinosScalar n) const;
279 
283  const Reference &operator /= (const TrilinosScalar n) const;
284 
285  private:
290  Accessor &accessor;
291  };
292 
293  public:
299 
305  const size_type row,
306  const size_type index);
307 
311  Reference value() const;
312 
313  private:
317  template <bool> friend class Iterator;
321  friend class Reference;
322  };
323 
338  template <bool Constness>
339  class Iterator
340  {
341  public:
345  typedef ::types::global_dof_index size_type;
346 
352 
357  Iterator (MatrixType *matrix,
358  const size_type row,
359  const size_type index);
360 
364  template <bool Other>
365  Iterator(const Iterator<Other> &other);
366 
371 
376 
380  const Accessor<Constness> &operator* () const;
381 
385  const Accessor<Constness> *operator-> () const;
386 
391  bool operator == (const Iterator<Constness> &) const;
392 
396  bool operator != (const Iterator<Constness> &) const;
397 
403  bool operator < (const Iterator<Constness> &) const;
404 
408  bool operator > (const Iterator<Constness> &) const;
409 
415  << "Attempt to access element " << arg2
416  << " of row " << arg1
417  << " which doesn't have that many elements.");
418 
419  private:
424 
425  template <bool Other> friend class Iterator;
426  };
427 
428  }
429 
430 
492  class SparseMatrix : public Subscriptor
493  {
494  public:
498  typedef ::types::global_dof_index size_type;
499 
507  struct Traits
508  {
513  static const bool zero_addition_can_be_elided = true;
514  };
515 
520 
525 
529  typedef TrilinosScalar value_type;
530 
538  SparseMatrix ();
539 
547  SparseMatrix (const size_type m,
548  const size_type n,
549  const unsigned int n_max_entries_per_row);
550 
558  SparseMatrix (const size_type m,
559  const size_type n,
560  const std::vector<unsigned int> &n_entries_per_row);
561 
565  SparseMatrix (const SparsityPattern &InputSparsityPattern);
566 
571  SparseMatrix (SparseMatrix &&other) noexcept;
572 
576  SparseMatrix (const SparseMatrix &) = delete;
577 
581  SparseMatrix &operator = (const SparseMatrix &) = delete;
582 
586  virtual ~SparseMatrix () = default;
587 
603  template <typename SparsityPatternType>
604  void reinit (const SparsityPatternType &sparsity_pattern);
605 
618  void reinit (const SparsityPattern &sparsity_pattern);
619 
628  void reinit (const SparseMatrix &sparse_matrix);
629 
650  template <typename number>
651  void reinit (const ::SparseMatrix<number> &dealii_sparse_matrix,
652  const double drop_tolerance=1e-13,
653  const bool copy_values=true,
654  const ::SparsityPattern *use_this_sparsity=nullptr);
655 
661  void reinit (const Epetra_CrsMatrix &input_matrix,
662  const bool copy_values = true);
664 
682  DEAL_II_DEPRECATED
683  SparseMatrix (const Epetra_Map &parallel_partitioning,
684  const size_type n_max_entries_per_row = 0);
685 
695  DEAL_II_DEPRECATED
696  SparseMatrix (const Epetra_Map &parallel_partitioning,
697  const std::vector<unsigned int> &n_entries_per_row);
698 
717  DEAL_II_DEPRECATED
718  SparseMatrix (const Epetra_Map &row_parallel_partitioning,
719  const Epetra_Map &col_parallel_partitioning,
720  const size_type n_max_entries_per_row = 0);
721 
738  DEAL_II_DEPRECATED
739  SparseMatrix (const Epetra_Map &row_parallel_partitioning,
740  const Epetra_Map &col_parallel_partitioning,
741  const std::vector<unsigned int> &n_entries_per_row);
742 
769  template <typename SparsityPatternType>
770  DEAL_II_DEPRECATED
771  void reinit (const Epetra_Map &parallel_partitioning,
772  const SparsityPatternType &sparsity_pattern,
773  const bool exchange_data = false);
774 
789  template <typename SparsityPatternType>
790  DEAL_II_DEPRECATED
791  void reinit (const Epetra_Map &row_parallel_partitioning,
792  const Epetra_Map &col_parallel_partitioning,
793  const SparsityPatternType &sparsity_pattern,
794  const bool exchange_data = false);
795 
814  template <typename number>
815  DEAL_II_DEPRECATED
816  void reinit (const Epetra_Map &parallel_partitioning,
817  const ::SparseMatrix<number> &dealii_sparse_matrix,
818  const double drop_tolerance=1e-13,
819  const bool copy_values=true,
820  const ::SparsityPattern *use_this_sparsity=nullptr);
821 
837  template <typename number>
838  DEAL_II_DEPRECATED
839  void reinit (const Epetra_Map &row_parallel_partitioning,
840  const Epetra_Map &col_parallel_partitioning,
841  const ::SparseMatrix<number> &dealii_sparse_matrix,
842  const double drop_tolerance=1e-13,
843  const bool copy_values=true,
844  const ::SparsityPattern *use_this_sparsity=nullptr);
846 
862  SparseMatrix (const IndexSet &parallel_partitioning,
863  const MPI_Comm &communicator = MPI_COMM_WORLD,
864  const unsigned int n_max_entries_per_row = 0);
865 
873  SparseMatrix (const IndexSet &parallel_partitioning,
874  const MPI_Comm &communicator,
875  const std::vector<unsigned int> &n_entries_per_row);
876 
891  SparseMatrix (const IndexSet &row_parallel_partitioning,
892  const IndexSet &col_parallel_partitioning,
893  const MPI_Comm &communicator = MPI_COMM_WORLD,
894  const size_type n_max_entries_per_row = 0);
895 
910  SparseMatrix (const IndexSet &row_parallel_partitioning,
911  const IndexSet &col_parallel_partitioning,
912  const MPI_Comm &communicator,
913  const std::vector<unsigned int> &n_entries_per_row);
914 
935  template <typename SparsityPatternType>
936  void reinit (const IndexSet &parallel_partitioning,
937  const SparsityPatternType &sparsity_pattern,
938  const MPI_Comm &communicator = MPI_COMM_WORLD,
939  const bool exchange_data = false);
940 
953  template <typename SparsityPatternType>
954  void reinit (const IndexSet &row_parallel_partitioning,
955  const IndexSet &col_parallel_partitioning,
956  const SparsityPatternType &sparsity_pattern,
957  const MPI_Comm &communicator = MPI_COMM_WORLD,
958  const bool exchange_data = false);
959 
976  template <typename number>
977  void reinit (const IndexSet &parallel_partitioning,
978  const ::SparseMatrix<number> &dealii_sparse_matrix,
979  const MPI_Comm &communicator = MPI_COMM_WORLD,
980  const double drop_tolerance=1e-13,
981  const bool copy_values=true,
982  const ::SparsityPattern *use_this_sparsity=nullptr);
983 
997  template <typename number>
998  void reinit (const IndexSet &row_parallel_partitioning,
999  const IndexSet &col_parallel_partitioning,
1000  const ::SparseMatrix<number> &dealii_sparse_matrix,
1001  const MPI_Comm &communicator = MPI_COMM_WORLD,
1002  const double drop_tolerance=1e-13,
1003  const bool copy_values=true,
1004  const ::SparsityPattern *use_this_sparsity=nullptr);
1006 
1010 
1014  size_type m () const;
1015 
1019  size_type n () const;
1020 
1029  unsigned int local_size () const;
1030 
1039  std::pair<size_type, size_type>
1040  local_range () const;
1041 
1046  bool in_local_range (const size_type index) const;
1047 
1052  size_type n_nonzero_elements () const;
1053 
1057  unsigned int row_length (const size_type row) const;
1058 
1065  bool is_compressed () const;
1066 
1072  size_type memory_consumption () const;
1073 
1077  MPI_Comm get_mpi_communicator () const;
1078 
1080 
1084 
1094  SparseMatrix &
1095  operator = (const double d);
1096 
1104  void clear ();
1105 
1133  void compress (::VectorOperation::values operation);
1134 
1156  void set (const size_type i,
1157  const size_type j,
1158  const TrilinosScalar value);
1159 
1192  void set (const std::vector<size_type> &indices,
1193  const FullMatrix<TrilinosScalar> &full_matrix,
1194  const bool elide_zero_values = false);
1195 
1201  void set (const std::vector<size_type> &row_indices,
1202  const std::vector<size_type> &col_indices,
1203  const FullMatrix<TrilinosScalar> &full_matrix,
1204  const bool elide_zero_values = false);
1205 
1233  void set (const size_type row,
1234  const std::vector<size_type> &col_indices,
1235  const std::vector<TrilinosScalar> &values,
1236  const bool elide_zero_values = false);
1237 
1265  void set (const size_type row,
1266  const size_type n_cols,
1267  const size_type *col_indices,
1268  const TrilinosScalar *values,
1269  const bool elide_zero_values = false);
1270 
1280  void add (const size_type i,
1281  const size_type j,
1282  const TrilinosScalar value);
1283 
1302  void add (const std::vector<size_type> &indices,
1303  const FullMatrix<TrilinosScalar> &full_matrix,
1304  const bool elide_zero_values = true);
1305 
1311  void add (const std::vector<size_type> &row_indices,
1312  const std::vector<size_type> &col_indices,
1313  const FullMatrix<TrilinosScalar> &full_matrix,
1314  const bool elide_zero_values = true);
1315 
1329  void add (const size_type row,
1330  const std::vector<size_type> &col_indices,
1331  const std::vector<TrilinosScalar> &values,
1332  const bool elide_zero_values = true);
1333 
1347  void add (const size_type row,
1348  const size_type n_cols,
1349  const size_type *col_indices,
1350  const TrilinosScalar *values,
1351  const bool elide_zero_values = true,
1352  const bool col_indices_are_sorted = false);
1353 
1357  SparseMatrix &operator *= (const TrilinosScalar factor);
1358 
1362  SparseMatrix &operator /= (const TrilinosScalar factor);
1363 
1367  void copy_from (const SparseMatrix &source);
1368 
1376  void add (const TrilinosScalar factor,
1377  const SparseMatrix &matrix);
1378 
1405  void clear_row (const size_type row,
1406  const TrilinosScalar new_diag_value = 0);
1407 
1428  void clear_rows (const std::vector<size_type> &rows,
1429  const TrilinosScalar new_diag_value = 0);
1430 
1440  void transpose ();
1441 
1443 
1447 
1456  TrilinosScalar operator () (const size_type i,
1457  const size_type j) const;
1458 
1475  TrilinosScalar el (const size_type i,
1476  const size_type j) const;
1477 
1484  TrilinosScalar diag_element (const size_type i) const;
1485 
1487 
1491 
1512  template <typename VectorType>
1513  void vmult (VectorType &dst,
1514  const VectorType &src) const;
1515 
1537  template <typename VectorType>
1538  void Tvmult (VectorType &dst,
1539  const VectorType &src) const;
1540 
1562  template <typename VectorType>
1563  void vmult_add (VectorType &dst,
1564  const VectorType &src) const;
1565 
1587  template <typename VectorType>
1588  void Tvmult_add (VectorType &dst,
1589  const VectorType &src) const;
1590 
1612  TrilinosScalar matrix_norm_square (const MPI::Vector &v) const;
1613 
1633  TrilinosScalar matrix_scalar_product (const MPI::Vector &u,
1634  const MPI::Vector &v) const;
1635 
1652  TrilinosScalar residual (MPI::Vector &dst,
1653  const MPI::Vector &x,
1654  const MPI::Vector &b) const;
1655 
1670  void mmult (SparseMatrix &C,
1671  const SparseMatrix &B,
1672  const MPI::Vector &V = MPI::Vector()) const;
1673 
1674 
1691  void Tmmult (SparseMatrix &C,
1692  const SparseMatrix &B,
1693  const MPI::Vector &V = MPI::Vector()) const;
1694 
1696 
1700 
1708  TrilinosScalar l1_norm () const;
1709 
1718  TrilinosScalar linfty_norm () const;
1719 
1724  TrilinosScalar frobenius_norm () const;
1725 
1727 
1731 
1736  const Epetra_CrsMatrix &trilinos_matrix () const;
1737 
1742  const Epetra_CrsGraph &trilinos_sparsity_pattern () const;
1743 
1751  DEAL_II_DEPRECATED
1752  const Epetra_Map &domain_partitioner () const;
1753 
1762  DEAL_II_DEPRECATED
1763  const Epetra_Map &range_partitioner () const;
1764 
1772  DEAL_II_DEPRECATED
1773  const Epetra_Map &row_partitioner () const;
1774 
1784  DEAL_II_DEPRECATED
1785  const Epetra_Map &col_partitioner () const;
1787 
1792 
1798 
1805 
1807 
1812 
1831  const_iterator begin () const;
1832 
1836  iterator begin ();
1837 
1842  const_iterator end () const;
1843 
1847  iterator end ();
1848 
1877  const_iterator begin (const size_type r) const;
1878 
1882  iterator begin (const size_type r);
1883 
1893  const_iterator end (const size_type r) const;
1894 
1898  iterator end (const size_type r);
1899 
1901 
1905 
1911  void write_ascii ();
1912 
1920  void print (std::ostream &out,
1921  const bool write_extended_trilinos_info = false) const;
1922 
1924 
1933  int,
1934  << "An error with error number " << arg1
1935  << " occurred while calling a Trilinos function");
1936 
1942  << "The entry with index <" << arg1 << ',' << arg2
1943  << "> does not exist.");
1944 
1949  "You are attempting an operation on two matrices that "
1950  "are the same object, but the operation requires that the "
1951  "two objects are in fact different.");
1952 
1957 
1963  << "You tried to access element (" << arg1
1964  << "/" << arg2 << ")"
1965  << " of a distributed matrix, but only rows "
1966  << arg3 << " through " << arg4
1967  << " are stored locally and can be accessed.");
1968 
1974  << "You tried to access element (" << arg1
1975  << "/" << arg2 << ")"
1976  << " of a sparse matrix, but it appears to not"
1977  << " exist in the Trilinos sparsity pattern.");
1979 
1980 
1981 
1982  protected:
1983 
1994  void prepare_add();
1995 
2001  void prepare_set();
2002 
2003 
2004 
2005  private:
2010  std::unique_ptr<Epetra_Map> column_space_map;
2011 
2017  std::unique_ptr<Epetra_FECrsMatrix> matrix;
2018 
2024  std::unique_ptr<Epetra_CrsMatrix> nonlocal_matrix;
2025 
2029  std::unique_ptr<Epetra_Export> nonlocal_matrix_exporter;
2030 
2042  Epetra_CombineMode last_action;
2043 
2049 
2054  };
2055 
2056 
2057 
2058  // forwards declarations
2059  class SolverBase;
2060  class PreconditionBase;
2061 
2062  namespace internal
2063  {
2064  namespace
2065  {
2066  inline
2067  void check_vector_map_equality(const Epetra_CrsMatrix &mtrx,
2068  const Epetra_MultiVector &src,
2069  const Epetra_MultiVector &dst,
2070  const bool transpose)
2071  {
2072  if (transpose == false)
2073  {
2074  Assert (src.Map().SameAs(mtrx.DomainMap()) == true,
2075  ExcMessage ("Column map of matrix does not fit with vector map!"));
2076  Assert (dst.Map().SameAs(mtrx.RangeMap()) == true,
2077  ExcMessage ("Row map of matrix does not fit with vector map!"));
2078  }
2079  else
2080  {
2081  Assert (src.Map().SameAs(mtrx.RangeMap()) == true,
2082  ExcMessage ("Column map of matrix does not fit with vector map!"));
2083  Assert (dst.Map().SameAs(mtrx.DomainMap()) == true,
2084  ExcMessage ("Row map of matrix does not fit with vector map!"));
2085  }
2086  (void)mtrx; // removes -Wunused-variable in optimized mode
2087  (void)src;
2088  (void)dst;
2089  }
2090 
2091  inline
2092  void check_vector_map_equality(const Epetra_Operator &op,
2093  const Epetra_MultiVector &src,
2094  const Epetra_MultiVector &dst,
2095  const bool transpose)
2096  {
2097  if (transpose == false)
2098  {
2099  Assert (src.Map().SameAs(op.OperatorDomainMap()) == true,
2100  ExcMessage ("Column map of operator does not fit with vector map!"));
2101  Assert (dst.Map().SameAs(op.OperatorRangeMap()) == true,
2102  ExcMessage ("Row map of operator does not fit with vector map!"));
2103  }
2104  else
2105  {
2106  Assert (src.Map().SameAs(op.OperatorRangeMap()) == true,
2107  ExcMessage ("Column map of operator does not fit with vector map!"));
2108  Assert (dst.Map().SameAs(op.OperatorDomainMap()) == true,
2109  ExcMessage ("Row map of operator does not fit with vector map!"));
2110  }
2111  (void)op; // removes -Wunused-variable in optimized mode
2112  (void)src;
2113  (void)dst;
2114  }
2115  }
2116 
2117  namespace LinearOperatorImplementation
2118  {
2119 
2140  : public Epetra_Operator
2141  {
2142  public:
2143 
2147  typedef Epetra_MultiVector VectorType;
2148 
2153 
2158 
2163 
2171  TrilinosPayload ();
2172 
2176  TrilinosPayload (const TrilinosWrappers::SparseMatrix &matrix_exemplar,
2177  const TrilinosWrappers::SparseMatrix &matrix);
2178 
2182  TrilinosPayload (const TrilinosWrappers::SparseMatrix &matrix_exemplar,
2183  const TrilinosWrappers::PreconditionBase &preconditioner);
2184 
2188  TrilinosPayload (const TrilinosWrappers::PreconditionBase &preconditioner_exemplar,
2189  const TrilinosWrappers::PreconditionBase &preconditioner);
2190 
2194  TrilinosPayload (const TrilinosPayload &payload);
2195 
2203  TrilinosPayload (const TrilinosPayload &first_op,
2204  const TrilinosPayload &second_op);
2205 
2209  virtual ~TrilinosPayload() = default;
2210 
2215 
2219  TrilinosPayload null_payload () const;
2220 
2225 
2242  template <typename Solver, typename Preconditioner>
2243  typename std::enable_if<
2244  std::is_base_of<TrilinosWrappers::SolverBase,Solver>::value &&
2245  std::is_base_of<TrilinosWrappers::PreconditionBase,Preconditioner>::value,
2246  TrilinosPayload>::type
2247  inverse_payload (Solver &, const Preconditioner &) const;
2248 
2265  template <typename Solver, typename Preconditioner>
2266  typename std::enable_if<
2267  !(std::is_base_of<TrilinosWrappers::SolverBase,Solver>::value &&
2268  std::is_base_of<TrilinosWrappers::PreconditionBase,Preconditioner>::value),
2269  TrilinosPayload>::type
2270  inverse_payload (Solver &, const Preconditioner &) const;
2271 
2273 
2278 
2284  IndexSet
2286 
2292  IndexSet
2293  locally_owned_range_indices () const;
2294 
2298  MPI_Comm
2299  get_mpi_communicator () const;
2300 
2307  void
2308  transpose ();
2309 
2317  std::function<void(VectorType &, const VectorType &)> vmult;
2318 
2326  std::function<void(VectorType &, const VectorType &)> Tvmult;
2327 
2335  std::function<void(VectorType &, const VectorType &)> inv_vmult;
2336 
2344  std::function<void(VectorType &, const VectorType &)> inv_Tvmult;
2345 
2347 
2352 
2359  virtual bool
2360  UseTranspose () const;
2361 
2377  virtual int
2379 
2391  virtual int
2392  Apply(const VectorType &X,
2393  VectorType &Y) const;
2394 
2412  virtual int
2413  ApplyInverse(const VectorType &Y,
2414  VectorType &X) const;
2416 
2421 
2428  virtual const char *
2429  Label () const;
2430 
2438  virtual const Epetra_Comm &
2439  Comm () const;
2440 
2448  virtual const Epetra_Map &
2449  OperatorDomainMap () const;
2450 
2459  virtual const Epetra_Map &
2460  OperatorRangeMap () const;
2462 
2463  private:
2464 
2470 
2475 #ifdef DEAL_II_WITH_MPI
2476  Epetra_MpiComm communicator;
2477 #else
2478  Epetra_SerialComm communicator;
2479 #endif
2480 
2485  Epetra_Map domain_map;
2486 
2491  Epetra_Map range_map;
2492 
2501  virtual bool
2502  HasNormInf () const;
2503 
2511  virtual double
2512  NormInf () const;
2513  };
2514 
2519  TrilinosPayload operator+(const TrilinosPayload &first_op,
2520  const TrilinosPayload &second_op);
2521 
2526  TrilinosPayload operator*(const TrilinosPayload &first_op,
2527  const TrilinosPayload &second_op);
2528 
2529  } /* namespace LinearOperator */
2530  } /* namespace internal */
2531 
2532 
2533 
2534 // -------------------------- inline and template functions ----------------------
2535 
2536 #ifndef DOXYGEN
2537 
2538  namespace SparseMatrixIterators
2539  {
2540  inline
2541  AccessorBase::AccessorBase(SparseMatrix *matrix, size_type row, size_type index)
2542  :
2543  matrix(matrix),
2544  a_row(row),
2545  a_index(index)
2546  {
2547  visit_present_row ();
2548  }
2549 
2550 
2551  inline
2552  AccessorBase::size_type
2553  AccessorBase::row() const
2554  {
2555  Assert (a_row < matrix->m(), ExcBeyondEndOfMatrix());
2556  return a_row;
2557  }
2558 
2559 
2560  inline
2561  AccessorBase::size_type
2562  AccessorBase::column() const
2563  {
2564  Assert (a_row < matrix->m(), ExcBeyondEndOfMatrix());
2565  return (*colnum_cache)[a_index];
2566  }
2567 
2568 
2569  inline
2570  AccessorBase::size_type
2571  AccessorBase::index() const
2572  {
2573  Assert (a_row < matrix->m(), ExcBeyondEndOfMatrix());
2574  return a_index;
2575  }
2576 
2577 
2578  inline
2579  Accessor<true>::Accessor (MatrixType *matrix,
2580  const size_type row,
2581  const size_type index)
2582  :
2583  AccessorBase(const_cast<SparseMatrix *>(matrix), row, index)
2584  {}
2585 
2586 
2587  template <bool Other>
2588  inline
2589  Accessor<true>::Accessor(const Accessor<Other> &other)
2590  :
2591  AccessorBase(other)
2592  {}
2593 
2594 
2595  inline
2596  TrilinosScalar
2597  Accessor<true>::value() const
2598  {
2599  Assert (a_row < matrix->m(), ExcBeyondEndOfMatrix());
2600  return (*value_cache)[a_index];
2601  }
2602 
2603 
2604  inline
2605  Accessor<false>::Reference::Reference (
2606  const Accessor<false> &acc)
2607  :
2608  accessor(const_cast<Accessor<false>&>(acc))
2609  {}
2610 
2611 
2612  inline
2613  Accessor<false>::Reference::operator TrilinosScalar () const
2614  {
2615  return (*accessor.value_cache)[accessor.a_index];
2616  }
2617 
2618  inline
2619  const Accessor<false>::Reference &
2620  Accessor<false>::Reference::operator = (const TrilinosScalar n) const
2621  {
2622  (*accessor.value_cache)[accessor.a_index] = n;
2623  accessor.matrix->set(accessor.row(), accessor.column(),
2624  static_cast<TrilinosScalar>(*this));
2625  return *this;
2626  }
2627 
2628 
2629  inline
2630  const Accessor<false>::Reference &
2631  Accessor<false>::Reference::operator += (const TrilinosScalar n) const
2632  {
2633  (*accessor.value_cache)[accessor.a_index] += n;
2634  accessor.matrix->set(accessor.row(), accessor.column(),
2635  static_cast<TrilinosScalar>(*this));
2636  return *this;
2637  }
2638 
2639 
2640  inline
2641  const Accessor<false>::Reference &
2642  Accessor<false>::Reference::operator -= (const TrilinosScalar n) const
2643  {
2644  (*accessor.value_cache)[accessor.a_index] -= n;
2645  accessor.matrix->set(accessor.row(), accessor.column(),
2646  static_cast<TrilinosScalar>(*this));
2647  return *this;
2648  }
2649 
2650 
2651  inline
2652  const Accessor<false>::Reference &
2653  Accessor<false>::Reference::operator *= (const TrilinosScalar n) const
2654  {
2655  (*accessor.value_cache)[accessor.a_index] *= n;
2656  accessor.matrix->set(accessor.row(), accessor.column(),
2657  static_cast<TrilinosScalar>(*this));
2658  return *this;
2659  }
2660 
2661 
2662  inline
2663  const Accessor<false>::Reference &
2664  Accessor<false>::Reference::operator /= (const TrilinosScalar n) const
2665  {
2666  (*accessor.value_cache)[accessor.a_index] /= n;
2667  accessor.matrix->set(accessor.row(), accessor.column(),
2668  static_cast<TrilinosScalar>(*this));
2669  return *this;
2670  }
2671 
2672 
2673  inline
2674  Accessor<false>::Accessor (MatrixType *matrix,
2675  const size_type row,
2676  const size_type index)
2677  :
2678  AccessorBase(matrix, row, index)
2679  {}
2680 
2681 
2682  inline
2683  Accessor<false>::Reference
2684  Accessor<false>::value() const
2685  {
2686  Assert (a_row < matrix->m(), ExcBeyondEndOfMatrix());
2687  return Reference(*this);
2688  }
2689 
2690 
2691 
2692  template <bool Constness>
2693  inline
2694  Iterator<Constness>::Iterator(MatrixType *matrix,
2695  const size_type row,
2696  const size_type index)
2697  :
2698  accessor(matrix, row, index)
2699  {}
2700 
2701 
2702  template <bool Constness>
2703  template <bool Other>
2704  inline
2705  Iterator<Constness>::Iterator(const Iterator<Other> &other)
2706  :
2707  accessor(other.accessor)
2708  {}
2709 
2710 
2711  template <bool Constness>
2712  inline
2713  Iterator<Constness> &
2714  Iterator<Constness>::operator++ ()
2715  {
2716  Assert (accessor.a_row < accessor.matrix->m(), ExcIteratorPastEnd());
2717 
2718  ++accessor.a_index;
2719 
2720  // If at end of line: do one
2721  // step, then cycle until we
2722  // find a row with a nonzero
2723  // number of entries.
2724  if (accessor.a_index >= accessor.colnum_cache->size())
2725  {
2726  accessor.a_index = 0;
2727  ++accessor.a_row;
2728 
2729  while ((accessor.a_row < accessor.matrix->m())
2730  &&
2731  ((accessor.matrix->in_local_range (accessor.a_row) == false)
2732  ||
2733  (accessor.matrix->row_length(accessor.a_row) == 0)))
2734  ++accessor.a_row;
2735 
2736  accessor.visit_present_row();
2737  }
2738  return *this;
2739  }
2740 
2741 
2742  template <bool Constness>
2743  inline
2744  Iterator<Constness>
2745  Iterator<Constness>::operator++ (int)
2746  {
2747  const Iterator<Constness> old_state = *this;
2748  ++(*this);
2749  return old_state;
2750  }
2751 
2752 
2753 
2754  template <bool Constness>
2755  inline
2756  const Accessor<Constness> &
2758  {
2759  return accessor;
2760  }
2761 
2762 
2763 
2764  template <bool Constness>
2765  inline
2766  const Accessor<Constness> *
2767  Iterator<Constness>::operator-> () const
2768  {
2769  return &accessor;
2770  }
2771 
2772 
2773 
2774  template <bool Constness>
2775  inline
2776  bool
2777  Iterator<Constness>::operator == (const Iterator<Constness> &other) const
2778  {
2779  return (accessor.a_row == other.accessor.a_row &&
2780  accessor.a_index == other.accessor.a_index);
2781  }
2782 
2783 
2784 
2785  template <bool Constness>
2786  inline
2787  bool
2788  Iterator<Constness>::operator != (const Iterator<Constness> &other) const
2789  {
2790  return ! (*this == other);
2791  }
2792 
2793 
2794 
2795  template <bool Constness>
2796  inline
2797  bool
2798  Iterator<Constness>::operator < (const Iterator<Constness> &other) const
2799  {
2800  return (accessor.row() < other.accessor.row() ||
2801  (accessor.row() == other.accessor.row() &&
2802  accessor.index() < other.accessor.index()));
2803  }
2804 
2805 
2806  template <bool Constness>
2807  inline
2808  bool
2809  Iterator<Constness>::operator > (const Iterator<Constness> &other) const
2810  {
2811  return (other < *this);
2812  }
2813 
2814  }
2815 
2816 
2817 
2818  inline
2820  SparseMatrix::begin() const
2821  {
2822  return begin(0);
2823  }
2824 
2825 
2826 
2827  inline
2829  SparseMatrix::end() const
2830  {
2831  return const_iterator(this, m(), 0);
2832  }
2833 
2834 
2835 
2836  inline
2838  SparseMatrix::begin(const size_type r) const
2839  {
2840  Assert (r < m(), ExcIndexRange(r, 0, m()));
2841  if (in_local_range (r)
2842  &&
2843  (row_length(r) > 0))
2844  return const_iterator(this, r, 0);
2845  else
2846  return end (r);
2847  }
2848 
2849 
2850 
2851  inline
2853  SparseMatrix::end(const size_type r) const
2854  {
2855  Assert (r < m(), ExcIndexRange(r, 0, m()));
2856 
2857  // place the iterator on the first entry
2858  // past this line, or at the end of the
2859  // matrix
2860  for (size_type i=r+1; i<m(); ++i)
2861  if (in_local_range (i)
2862  &&
2863  (row_length(i) > 0))
2864  return const_iterator(this, i, 0);
2865 
2866  // if there is no such line, then take the
2867  // end iterator of the matrix
2868  return end();
2869  }
2870 
2871 
2872 
2873  inline
2876  {
2877  return begin(0);
2878  }
2879 
2880 
2881 
2882  inline
2885  {
2886  return iterator(this, m(), 0);
2887  }
2888 
2889 
2890 
2891  inline
2893  SparseMatrix::begin(const size_type r)
2894  {
2895  Assert (r < m(), ExcIndexRange(r, 0, m()));
2896  if (in_local_range (r)
2897  &&
2898  (row_length(r) > 0))
2899  return iterator(this, r, 0);
2900  else
2901  return end (r);
2902  }
2903 
2904 
2905 
2906  inline
2908  SparseMatrix::end(const size_type r)
2909  {
2910  Assert (r < m(), ExcIndexRange(r, 0, m()));
2911 
2912  // place the iterator on the first entry
2913  // past this line, or at the end of the
2914  // matrix
2915  for (size_type i=r+1; i<m(); ++i)
2916  if (in_local_range (i)
2917  &&
2918  (row_length(i) > 0))
2919  return iterator(this, i, 0);
2920 
2921  // if there is no such line, then take the
2922  // end iterator of the matrix
2923  return end();
2924  }
2925 
2926 
2927 
2928  inline
2929  bool
2930  SparseMatrix::in_local_range (const size_type index) const
2931  {
2932  TrilinosWrappers::types::int_type begin, end;
2933 #ifndef DEAL_II_WITH_64BIT_INDICES
2934  begin = matrix->RowMap().MinMyGID();
2935  end = matrix->RowMap().MaxMyGID()+1;
2936 #else
2937  begin = matrix->RowMap().MinMyGID64();
2938  end = matrix->RowMap().MaxMyGID64()+1;
2939 #endif
2940 
2941  return ((index >= static_cast<size_type>(begin)) &&
2942  (index < static_cast<size_type>(end)));
2943  }
2944 
2945 
2946 
2947  inline
2948  bool
2950  {
2951  return compressed;
2952  }
2953 
2954 
2955 
2956  // Inline the set() and add() functions, since they will be called
2957  // frequently, and the compiler can optimize away some unnecessary loops
2958  // when the sizes are given at compile time.
2959  inline
2960  void
2961  SparseMatrix::set (const size_type i,
2962  const size_type j,
2963  const TrilinosScalar value)
2964  {
2965 
2966  AssertIsFinite(value);
2967 
2968  set (i, 1, &j, &value, false);
2969  }
2970 
2971 
2972 
2973  inline
2974  void
2975  SparseMatrix::set (const std::vector<size_type> &indices,
2976  const FullMatrix<TrilinosScalar> &values,
2977  const bool elide_zero_values)
2978  {
2979  Assert (indices.size() == values.m(),
2980  ExcDimensionMismatch(indices.size(), values.m()));
2981  Assert (values.m() == values.n(), ExcNotQuadratic());
2982 
2983  for (size_type i=0; i<indices.size(); ++i)
2984  set (indices[i], indices.size(), indices.data(), &values(i,0),
2985  elide_zero_values);
2986  }
2987 
2988 
2989 
2990  inline
2991  void
2992  SparseMatrix::add (const size_type i,
2993  const size_type j,
2994  const TrilinosScalar value)
2995  {
2996  AssertIsFinite(value);
2997 
2998  if (value == 0)
2999  {
3000  // we have to check after Insert/Add in any case to be consistent
3001  // with the MPI communication model, but we can save some
3002  // work if the addend is zero. However, these actions are done in case
3003  // we pass on to the other function.
3004 
3005  // TODO: fix this (do not run compress here, but fail)
3006  if (last_action == Insert)
3007  {
3008  int ierr;
3009  ierr = matrix->GlobalAssemble(*column_space_map,
3010  matrix->RowMap(), false);
3011 
3012  Assert (ierr == 0, ExcTrilinosError(ierr));
3013  (void)ierr; // removes -Wunused-but-set-variable in optimized mode
3014  }
3015 
3016  last_action = Add;
3017 
3018  return;
3019  }
3020  else
3021  add (i, 1, &j, &value, false);
3022  }
3023 
3024 
3025 
3026  // inline "simple" functions that are called frequently and do only involve
3027  // a call to some Trilinos function.
3028  inline
3030  SparseMatrix::m () const
3031  {
3032 #ifndef DEAL_II_WITH_64BIT_INDICES
3033  return matrix->NumGlobalRows();
3034 #else
3035  return matrix->NumGlobalRows64();
3036 #endif
3037  }
3038 
3039 
3040 
3041  inline
3043  SparseMatrix::n () const
3044  {
3045  // If the matrix structure has not been fixed (i.e., we did not have a
3046  // sparsity pattern), it does not know about the number of columns so we
3047  // must always take this from the additional column space map
3048  Assert(column_space_map.get() != nullptr, ExcInternalError());
3049 #ifndef DEAL_II_WITH_64BIT_INDICES
3050  return column_space_map->NumGlobalElements();
3051 #else
3052  return column_space_map->NumGlobalElements64();
3053 #endif
3054  }
3055 
3056 
3057 
3058  inline
3059  unsigned int
3060  SparseMatrix::local_size () const
3061  {
3062  return matrix -> NumMyRows();
3063  }
3064 
3065 
3066 
3067  inline
3068  std::pair<SparseMatrix::size_type, SparseMatrix::size_type>
3069  SparseMatrix::local_range () const
3070  {
3071  size_type begin, end;
3072 #ifndef DEAL_II_WITH_64BIT_INDICES
3073  begin = matrix->RowMap().MinMyGID();
3074  end = matrix->RowMap().MaxMyGID()+1;
3075 #else
3076  begin = matrix->RowMap().MinMyGID64();
3077  end = matrix->RowMap().MaxMyGID64()+1;
3078 #endif
3079 
3080  return std::make_pair (begin, end);
3081  }
3082 
3083 
3084 
3085  inline
3088  {
3089 #ifndef DEAL_II_WITH_64BIT_INDICES
3090  return matrix->NumGlobalNonzeros();
3091 #else
3092  return matrix->NumGlobalNonzeros64();
3093 #endif
3094  }
3095 
3096 
3097 
3098  template <typename SparsityPatternType>
3099  inline
3100  void SparseMatrix::reinit (const IndexSet &parallel_partitioning,
3101  const SparsityPatternType &sparsity_pattern,
3102  const MPI_Comm &communicator,
3103  const bool exchange_data)
3104  {
3105  reinit (parallel_partitioning, parallel_partitioning,
3106  sparsity_pattern, communicator, exchange_data);
3107  }
3108 
3109 
3110 
3111  template <typename number>
3112  inline
3113  void SparseMatrix::reinit (const IndexSet &parallel_partitioning,
3114  const ::SparseMatrix<number> &sparse_matrix,
3115  const MPI_Comm &communicator,
3116  const double drop_tolerance,
3117  const bool copy_values,
3118  const ::SparsityPattern *use_this_sparsity)
3119  {
3120  Epetra_Map map = parallel_partitioning.make_trilinos_map (communicator, false);
3121  reinit (parallel_partitioning, parallel_partitioning, sparse_matrix,
3122  drop_tolerance, copy_values, use_this_sparsity);
3123  }
3124 
3125 
3126 
3127  inline
3128  const Epetra_CrsMatrix &
3130  {
3131  return static_cast<const Epetra_CrsMatrix &>(*matrix);
3132  }
3133 
3134 
3135 
3136  inline
3137  const Epetra_CrsGraph &
3139  {
3140  return matrix->Graph();
3141  }
3142 
3143 
3144 
3145  inline
3146  IndexSet
3148  {
3149  return IndexSet(matrix->DomainMap());
3150  }
3151 
3152 
3153 
3154  inline
3155  IndexSet
3157  {
3158  return IndexSet(matrix->RangeMap());
3159  }
3160 
3161 
3162 
3163  inline
3164  void
3166  {
3167  //nothing to do here
3168  }
3169 
3170 
3171 
3172  inline
3173  void
3175  {
3176  //nothing to do here
3177  }
3178 
3179 
3180  namespace internal
3181  {
3182  namespace LinearOperatorImplementation
3183  {
3184  template <typename Solver, typename Preconditioner>
3185  typename std::enable_if<
3186  std::is_base_of<TrilinosWrappers::SolverBase,Solver>::value &&
3187  std::is_base_of<TrilinosWrappers::PreconditionBase,Preconditioner>::value,
3188  TrilinosPayload>::type
3189  TrilinosPayload::inverse_payload (
3190  Solver &solver,
3191  const Preconditioner &preconditioner) const
3192  {
3193  const auto &payload = *this;
3194 
3195  TrilinosPayload return_op(payload);
3196 
3197  // Capture by copy so the payloads are always valid
3198 
3199  return_op.inv_vmult = [payload,&solver,&preconditioner](
3200  TrilinosPayload::Domain &tril_dst, const TrilinosPayload::Range &tril_src
3201  )
3202  {
3203  // Duplicated from TrilinosWrappers::PreconditionBase::vmult
3204  // as well as from TrilinosWrappers::SparseMatrix::Tvmult
3206  internal::check_vector_map_equality(payload,
3207  tril_src, tril_dst,
3208  !payload.UseTranspose());
3209  solver.solve(payload, tril_dst, tril_src, preconditioner);
3210  };
3211 
3212  return_op.inv_Tvmult = [payload,&solver,&preconditioner](
3213  TrilinosPayload::Range &tril_dst, const TrilinosPayload::Domain &tril_src
3214  )
3215  {
3216  // Duplicated from TrilinosWrappers::PreconditionBase::vmult
3217  // as well as from TrilinosWrappers::SparseMatrix::Tvmult
3219  internal::check_vector_map_equality(payload,
3220  tril_src, tril_dst,
3221  payload.UseTranspose());
3222 
3223  const_cast<TrilinosPayload &>(payload).transpose();
3224  solver.solve(payload, tril_dst, tril_src, preconditioner);
3225  const_cast<TrilinosPayload &>(payload).transpose();
3226  };
3227 
3228  // If the input operator is already setup for transpose operations, then
3229  // we must do similar with its inverse.
3230  if (return_op.UseTranspose() == true)
3231  std::swap(return_op.inv_vmult,
3232  return_op.inv_Tvmult);
3233 
3234  return return_op;
3235  }
3236 
3237  template <typename Solver, typename Preconditioner>
3238  typename std::enable_if<
3239  !(std::is_base_of<TrilinosWrappers::SolverBase,Solver>::value &&
3240  std::is_base_of<TrilinosWrappers::PreconditionBase,Preconditioner>::value),
3241  TrilinosPayload>::type
3242  TrilinosPayload::inverse_payload (
3243  Solver &,
3244  const Preconditioner &) const
3245  {
3246  TrilinosPayload return_op(*this);
3247 
3248  return_op.inv_vmult = [](TrilinosPayload::Domain &,
3249  const TrilinosPayload::Range &)
3250  {
3251  AssertThrow(false,
3252  ExcMessage("Payload inv_vmult disabled because of "
3253  "incompatible solver/preconditioner choice."));
3254  };
3255 
3256  return_op.inv_Tvmult = [](TrilinosPayload::Range &,
3257  const TrilinosPayload::Domain &)
3258  {
3259  AssertThrow(false,
3260  ExcMessage("Payload inv_vmult disabled because of "
3261  "incompatible solver/preconditioner choice."));
3262  };
3263 
3264  return return_op;
3265  }
3266  } // namespace LinearOperator
3267  } // namespace internal
3268 
3269 #endif // DOXYGEN
3270 
3271 } /* namespace TrilinosWrappers */
3272 
3273 
3274 DEAL_II_NAMESPACE_CLOSE
3275 
3276 
3277 #endif // DEAL_II_WITH_TRILINOS
3278 
3279 
3280 /*----------------------- trilinos_sparse_matrix.h --------------------*/
3281 
3282 #endif
3283 /*----------------------- trilinos_sparse_matrix.h --------------------*/
TrilinosScalar diag_element(const size_type i) const
static ::ExceptionBase & ExcTrilinosError(int arg1)
TrilinosScalar el(const size_type i, const size_type j) const
size_type m() const
const_iterator end() const
const Epetra_Map & col_partitioner() const
bool operator>(const Iterator< Constness > &) const
void mmult(SparseMatrix &C, const SparseMatrix &B, const MPI::Vector &V=MPI::Vector()) const
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:358
SparseMatrixIterators::Iterator< false > iterator
Contents is actually a matrix.
static ::ExceptionBase & ExcSourceEqualsDestination()
static ::ExceptionBase & ExcBeyondEndOfMatrix()
bool operator==(const Iterator< Constness > &) const
void clear_row(const size_type row, const TrilinosScalar new_diag_value=0)
const Epetra_Map & range_partitioner() const
void vmult_add(VectorType &dst, const VectorType &src) const
std::function< void(VectorType &, const VectorType &)> inv_Tvmult
std::enable_if< std::is_base_of< TrilinosWrappers::SolverBase, Solver >::value &&std::is_base_of< TrilinosWrappers::PreconditionBase, Preconditioner >::value, TrilinosPayload >::type inverse_payload(Solver &, const Preconditioner &) const
::types::global_dof_index size_type
TrilinosScalar operator()(const size_type i, const size_type j) const
virtual int ApplyInverse(const VectorType &Y, VectorType &X) const
static ::ExceptionBase & ExcInvalidIndex(size_type arg1, size_type arg2)
static ::ExceptionBase & ExcAccessToNonlocalRow(std::size_t arg1, std::size_t arg2, std::size_t arg3)
const Epetra_Map & row_partitioner() const
#define AssertThrow(cond, exc)
Definition: exceptions.h:1221
static ::ExceptionBase & ExcAccessToNonPresentElement(size_type arg1, size_type arg2)
SymmetricTensor< rank_, dim, typename ProductType< Number, OtherNumber >::type > operator+(const SymmetricTensor< rank_, dim, Number > &left, const SymmetricTensor< rank_, dim, OtherNumber > &right)
TrilinosScalar residual(MPI::Vector &dst, const MPI::Vector &x, const MPI::Vector &b) const
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
static ::ExceptionBase & ExcTrilinosError(int arg1)
SymmetricTensor< rank_, dim, Number > operator*(const SymmetricTensor< rank_, dim, Number > &t, const Number &factor)
TrilinosScalar matrix_scalar_product(const MPI::Vector &u, const MPI::Vector &v) const
void clear_rows(const std::vector< size_type > &rows, const TrilinosScalar new_diag_value=0)
void Tvmult(VectorType &dst, const VectorType &src) const
Epetra_Map make_trilinos_map(const MPI_Comm &communicator=MPI_COMM_WORLD, const bool overlapping=false) const
Definition: index_set.cc:549
std::shared_ptr< std::vector< size_type > > colnum_cache
SparseMatrix & operator*=(const TrilinosScalar factor)
std::unique_ptr< Epetra_FECrsMatrix > matrix
SparseMatrix & operator=(const SparseMatrix &)=delete
bool in_local_range(const size_type index) const
static ::ExceptionBase & ExcMessage(std::string arg1)
const Accessor< Constness > & operator*() const
size_type n() const
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:346
void add(const size_type i, const size_type j, const TrilinosScalar value)
#define Assert(cond, exc)
Definition: exceptions.h:1142
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
std::unique_ptr< Epetra_Export > nonlocal_matrix_exporter
#define DeclExceptionMsg(Exception, defaulttext)
Definition: exceptions.h:335
void print(std::ostream &out, const bool write_extended_trilinos_info=false) const
bool operator!=(const Iterator< Constness > &) const
#define DeclException0(Exception0)
Definition: exceptions.h:323
std::function< void(VectorType &, const VectorType &)> inv_vmult
virtual ~SparseMatrix()=default
TrilinosScalar matrix_norm_square(const MPI::Vector &v) const
const Accessor< Constness > * operator->() const
const Epetra_CrsMatrix & trilinos_matrix() const
SymmetricTensor< rank_, dim, Number > transpose(const SymmetricTensor< rank_, dim, Number > &t)
AccessorBase(SparseMatrix *matrix, const size_type row, const size_type index)
static ::ExceptionBase & ExcInvalidIndexWithinRow(size_type arg1, size_type arg2)
void vmult(VectorType &dst, const VectorType &src) const
IndexSet locally_owned_range_indices() const
size_type n_nonzero_elements() const
static ::ExceptionBase & ExcIteratorPastEnd()
const_iterator begin() const
static ::ExceptionBase & ExcNotQuadratic()
void swap(Vector< Number > &u, Vector< Number > &v)
Definition: vector.h:1312
unsigned int row_length(const size_type row) const
void Tvmult_add(VectorType &dst, const VectorType &src) const
SparseMatrixIterators::Iterator< true > const_iterator
Definition: solver.h:322
types::global_dof_index size_type
void reinit(const SparsityPatternType &sparsity_pattern)
void copy_from(const SparseMatrix &source)
const Epetra_Map & domain_partitioner() const
SparseMatrix & operator/=(const TrilinosScalar factor)
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
Definition: exceptions.h:382
std::pair< size_type, size_type > local_range() const
static ::ExceptionBase & ExcMatrixNotCompressed()
IndexSet locally_owned_domain_indices() const
const Epetra_CrsGraph & trilinos_sparsity_pattern() const
void Tmmult(SparseMatrix &C, const SparseMatrix &B, const MPI::Vector &V=MPI::Vector()) const
#define DeclException3(Exception3, type1, type2, type3, outsequence)
Definition: exceptions.h:370
std::unique_ptr< Epetra_Map > column_space_map
void compress(::VectorOperation::values operation)
static ::ExceptionBase & ExcAccessToNonLocalElement(size_type arg1, size_type arg2, size_type arg3, size_type arg4)
std::unique_ptr< Epetra_CrsMatrix > nonlocal_matrix
void set(const size_type i, const size_type j, const TrilinosScalar value)
#define AssertIsFinite(number)
Definition: exceptions.h:1299
unsigned int local_size() const
static ::ExceptionBase & ExcInternalError()
std::shared_ptr< std::vector< TrilinosScalar > > value_cache