deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
trilinos_sparse_matrix.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2008 - 2026 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_trilinos_sparse_matrix_h
14# define dealii_trilinos_sparse_matrix_h
15
16
17# include <deal.II/base/config.h>
18
19# ifndef DEAL_II_TRILINOS_WITH_EPETRA
22
23# endif
24
25# ifdef DEAL_II_TRILINOS_WITH_EPETRA
29
37
39# include <Epetra_Comm.h>
40# include <Epetra_CrsGraph.h>
41# include <Epetra_Export.h>
42# include <Epetra_FECrsMatrix.h>
43# include <Epetra_Map.h>
44# include <Epetra_MpiComm.h>
45# include <Epetra_MultiVector.h>
46# include <Epetra_Operator.h>
48
49# include <cmath>
50# include <iterator>
51# include <memory>
52# include <type_traits>
53# include <vector>
54
55# endif
56
58
59# ifdef DEAL_II_TRILINOS_WITH_EPETRA
60// forward declarations
61# ifndef DOXYGEN
62template <typename MatrixType>
63class BlockMatrixBase;
64
65template <typename number>
66class SparseMatrix;
67class SparsityPattern;
69
70namespace TrilinosWrappers
71{
72 class SparseMatrix;
73 class SparsityPattern;
74
75 namespace SparseMatrixIterators
76 {
77 template <bool Constness>
78 class Iterator;
79 }
80} // namespace TrilinosWrappers
81# endif
82
83namespace TrilinosWrappers
84{
89 {
94
99 std::size_t,
100 std::size_t,
101 std::size_t,
102 << "You tried to access row " << arg1
103 << " of a distributed sparsity pattern, "
104 << " but only rows " << arg2 << " through " << arg3
105 << " are stored locally and can be accessed.");
106
115 {
116 public:
121
126 const size_type row,
127 const size_type index);
128
133 row() const;
134
139 index() const;
140
145 column() const;
146
147 protected:
159
164
170 void
172
185 std::shared_ptr<std::vector<size_type>> colnum_cache;
186
190 std::shared_ptr<std::vector<TrilinosScalar>> value_cache;
191 };
192
203 template <bool Constess>
204 class Accessor : public AccessorBase
205 {
210 value() const;
211
217 };
218
219
220
224 template <>
225 class Accessor<true> : public AccessorBase
226 {
227 public:
233
239
244 template <bool Other>
246
251 value() const;
252
253 private:
254 // Make iterator class a friend.
255 template <bool>
256 friend class Iterator;
257 };
258
262 template <>
263 class Accessor<false> : public AccessorBase
264 {
265 class Reference
266 {
267 public:
271 Reference(const Accessor<false> &accessor);
272
276 operator TrilinosScalar() const;
277
281 const Reference &
282 operator=(const TrilinosScalar n) const;
283
287 const Reference &
289
293 const Reference &
295
299 const Reference &
301
305 const Reference &
307
308 private:
314 };
315
316 public:
322
328
332 Reference
333 value() const;
334
335 private:
336 // Make iterator class a friend.
337 template <bool>
338 friend class Iterator;
339
340 // Make Reference object a friend.
341 friend class Reference;
342 };
343
357 template <bool Constness>
359 {
360 public:
365
371
377
383
388 Iterator(MatrixType *matrix, const size_type row, const size_type index);
389
393 template <bool Other>
395
401
407
411 const Accessor<Constness> &
412 operator*() const;
413
417 const Accessor<Constness> *
418 operator->() const;
419
424 template <bool OtherConstness>
425 bool
427
431 template <bool OtherConstness>
432 bool
434
440 template <bool OtherConstness>
441 bool
442 operator<(const Iterator<OtherConstness> &) const;
443
447 template <bool OtherConstness>
448 bool
450
455 size_type,
456 size_type,
457 << "Attempt to access element " << arg2 << " of row "
458 << arg1 << " which doesn't have that many elements.");
459
460 private:
465
466 template <bool Other>
467 friend class Iterator;
468 };
469
470 } // namespace SparseMatrixIterators
471} // namespace TrilinosWrappers
472
473DEAL_II_NAMESPACE_CLOSE // Do not convert for module purposes
474
475 namespace std
476{
477 template <bool Constness>
480 {
481 using iterator_category = forward_iterator_tag;
483 typename ::TrilinosWrappers::SparseMatrixIterators::Iterator<
484 Constness>::value_type;
486 typename ::TrilinosWrappers::SparseMatrixIterators::Iterator<
487 Constness>::difference_type;
488 };
489} // namespace std
490
491DEAL_II_NAMESPACE_OPEN // Do not convert for module purposes
492
493
494 namespace TrilinosWrappers
495{
557 {
558 public:
563
568 std::size_t,
569 << "You tried to access row " << arg1
570 << " of a non-contiguous locally owned row set."
571 << " The row " << arg1
572 << " is not stored locally and can't be accessed.");
573
581 struct Traits
582 {
587 static const bool zero_addition_can_be_elided = true;
588 };
589
594
599
604
612 SparseMatrix();
613
622 const size_type n,
623 const unsigned int n_max_entries_per_row);
624
633 const size_type n,
634 const std::vector<unsigned int> &n_entries_per_row);
635
639 SparseMatrix(const SparsityPattern &InputSparsityPattern);
640
645 SparseMatrix(SparseMatrix &&other) noexcept;
646
650 SparseMatrix(const SparseMatrix &) = delete;
651
656 operator=(const SparseMatrix &) = delete;
657
661 virtual ~SparseMatrix() override = default;
662
678 template <typename SparsityPatternType>
679 void
680 reinit(const SparsityPatternType &sparsity_pattern);
681
694 void
695 reinit(const SparsityPattern &sparsity_pattern);
696
705 void
706 reinit(const SparseMatrix &sparse_matrix);
707
728 template <typename number>
729 void
730 reinit(const ::SparseMatrix<number> &dealii_sparse_matrix,
731 const double drop_tolerance = 1e-13,
732 const bool copy_values = true,
733 const ::SparsityPattern *use_this_sparsity = nullptr);
734
740 void
741 reinit(const Epetra_CrsMatrix &input_matrix, const bool copy_values = true);
760 SparseMatrix(const IndexSet &parallel_partitioning,
761 const MPI_Comm communicator,
762 const unsigned int n_max_entries_per_row);
763
765 "Use the overload specifying the number of entries per row!")
766 SparseMatrix(const IndexSet &parallel_partitioning,
767 const MPI_Comm communicator);
768
770 "Use the overload specifying the MPI communicator and the number of entries per row!")
771 SparseMatrix(const IndexSet &parallel_partitioning);
772
780 SparseMatrix(const IndexSet &parallel_partitioning,
781 const MPI_Comm communicator,
782 const std::vector<unsigned int> &n_entries_per_row);
783
798 SparseMatrix(const IndexSet &row_parallel_partitioning,
799 const IndexSet &col_parallel_partitioning,
800 const MPI_Comm communicator,
801 const size_type n_max_entries_per_row);
802
804 "Use the overload specifying the number of entries per row!")
805 SparseMatrix(const IndexSet &row_parallel_partitioning,
806 const IndexSet &col_parallel_partitioning,
807 const MPI_Comm communicator);
808
810 "Use the overload specifying the MPI communicator and the number of entries per row!")
811 SparseMatrix(const IndexSet &row_parallel_partitioning,
812 const IndexSet &col_parallel_partitioning);
813
828 SparseMatrix(const IndexSet &row_parallel_partitioning,
829 const IndexSet &col_parallel_partitioning,
830 const MPI_Comm communicator,
831 const std::vector<unsigned int> &n_entries_per_row);
832
853 template <typename SparsityPatternType>
854 void
855 reinit(const IndexSet &parallel_partitioning,
856 const SparsityPatternType &sparsity_pattern,
857 const MPI_Comm communicator = MPI_COMM_WORLD,
858 const bool exchange_data = false);
859
872 template <typename SparsityPatternType>
873 std::enable_if_t<
874 !std::is_same_v<SparsityPatternType, ::SparseMatrix<double>>>
875 reinit(const IndexSet &row_parallel_partitioning,
876 const IndexSet &col_parallel_partitioning,
877 const SparsityPatternType &sparsity_pattern,
878 const MPI_Comm communicator = MPI_COMM_WORLD,
879 const bool exchange_data = false);
880
897 template <typename number>
898 void
899 reinit(const IndexSet &parallel_partitioning,
900 const ::SparseMatrix<number> &dealii_sparse_matrix,
901 const MPI_Comm communicator = MPI_COMM_WORLD,
902 const double drop_tolerance = 1e-13,
903 const bool copy_values = true,
904 const ::SparsityPattern *use_this_sparsity = nullptr);
905
919 template <typename number>
920 void
921 reinit(const IndexSet &row_parallel_partitioning,
922 const IndexSet &col_parallel_partitioning,
923 const ::SparseMatrix<number> &dealii_sparse_matrix,
924 const MPI_Comm communicator = MPI_COMM_WORLD,
925 const double drop_tolerance = 1e-13,
926 const bool copy_values = true,
927 const ::SparsityPattern *use_this_sparsity = nullptr);
938 m() const;
939
944 n() const;
945
954 unsigned int
955 local_size() const;
956
965 std::pair<size_type, size_type>
966 local_range() const;
967
972 bool
973 in_local_range(const size_type index) const;
974
979 std::uint64_t
981
985 unsigned int
986 row_length(const size_type row) const;
987
994 bool
996
1002 size_type
1003 memory_consumption() const;
1004
1008 MPI_Comm
1009 get_mpi_communicator() const;
1010
1026 SparseMatrix &
1027 operator=(const double d);
1028
1036 void
1037 clear();
1038
1066 void
1067 compress(VectorOperation::values operation);
1068
1090 void
1091 set(const size_type i, const size_type j, const TrilinosScalar value);
1092
1125 void
1126 set(const std::vector<size_type> &indices,
1127 const FullMatrix<TrilinosScalar> &full_matrix,
1128 const bool elide_zero_values = false);
1129
1135 void
1136 set(const std::vector<size_type> &row_indices,
1137 const std::vector<size_type> &col_indices,
1138 const FullMatrix<TrilinosScalar> &full_matrix,
1139 const bool elide_zero_values = false);
1140
1168 void
1169 set(const size_type row,
1170 const std::vector<size_type> &col_indices,
1171 const std::vector<TrilinosScalar> &values,
1172 const bool elide_zero_values = false);
1173
1201 template <typename Number>
1202 void
1203 set(const size_type row,
1204 const size_type n_cols,
1205 const size_type *col_indices,
1206 const Number *values,
1207 const bool elide_zero_values = false);
1208
1218 void
1219 add(const size_type i, const size_type j, const TrilinosScalar value);
1220
1239 void
1240 add(const std::vector<size_type> &indices,
1241 const FullMatrix<TrilinosScalar> &full_matrix,
1242 const bool elide_zero_values = true);
1243
1249 void
1250 add(const std::vector<size_type> &row_indices,
1251 const std::vector<size_type> &col_indices,
1252 const FullMatrix<TrilinosScalar> &full_matrix,
1253 const bool elide_zero_values = true);
1254
1268 void
1269 add(const size_type row,
1270 const std::vector<size_type> &col_indices,
1271 const std::vector<TrilinosScalar> &values,
1272 const bool elide_zero_values = true);
1273
1287 void
1288 add(const size_type row,
1289 const size_type n_cols,
1290 const size_type *col_indices,
1291 const TrilinosScalar *values,
1292 const bool elide_zero_values = true,
1293 const bool col_indices_are_sorted = false);
1294
1298 SparseMatrix &
1299 operator*=(const TrilinosScalar factor);
1300
1304 SparseMatrix &
1305 operator/=(const TrilinosScalar factor);
1306
1310 void
1311 copy_from(const SparseMatrix &source);
1312
1320 void
1321 add(const TrilinosScalar factor, const SparseMatrix &matrix);
1322
1349 void
1350 clear_row(const size_type row, const TrilinosScalar new_diag_value = 0);
1351
1372 void
1373 clear_rows(const ArrayView<const size_type> &rows,
1374 const TrilinosScalar new_diag_value = 0);
1375
1385 void
1386 transpose();
1387
1403 operator()(const size_type i, const size_type j) const;
1404
1422 el(const size_type i, const size_type j) const;
1423
1431 diag_element(const size_type i) const;
1432
1465 template <typename VectorType>
1466 void
1467 vmult(VectorType &dst, const VectorType &src) const;
1468
1479 template <typename VectorType>
1480 void
1481 Tvmult(VectorType &dst, const VectorType &src) const;
1482
1492 template <typename VectorType>
1493 void
1494 vmult_add(VectorType &dst, const VectorType &src) const;
1495
1506 template <typename VectorType>
1507 void
1508 Tvmult_add(VectorType &dst, const VectorType &src) const;
1509
1532 matrix_norm_square(const MPI::Vector &v) const;
1533
1554 matrix_scalar_product(const MPI::Vector &u, const MPI::Vector &v) const;
1555
1572 template <typename VectorType>
1574 residual(VectorType &dst, const VectorType &x, const VectorType &b) const;
1575
1590 void
1592 const SparseMatrix &B,
1593 const MPI::Vector &V = MPI::Vector()) const;
1594
1595
1612 void
1614 const SparseMatrix &B,
1615 const MPI::Vector &V = MPI::Vector()) const;
1616
1631 l1_norm() const;
1632
1642 linfty_norm() const;
1643
1649 frobenius_norm() const;
1650
1661 const Epetra_CrsMatrix &
1663
1668 const Epetra_CrsGraph &
1670
1682 IndexSet
1684
1690 IndexSet
1692
1719 begin() const;
1720
1724 iterator
1726
1732 end() const;
1733
1737 iterator
1739
1769 begin(const size_type r) const;
1770
1774 iterator
1776
1787 end(const size_type r) const;
1788
1792 iterator
1793 end(const size_type r);
1794
1806 void
1807 write_ascii();
1808
1816 void
1817 print(std::ostream &out,
1818 const bool write_extended_trilinos_info = false) const;
1819
1830 int,
1831 << "An error with error number " << arg1
1832 << " occurred while calling a Trilinos function. "
1833 "\n\n"
1834 "For historical reasons, many Trilinos functions express "
1835 "errors by returning specific integer values to indicate "
1836 "certain errors. Unfortunately, different Trilinos functions "
1837 "often use the same integer values for different kinds of "
1838 "errors, and in most cases it is also not documented what "
1839 "each error code actually means. As a consequence, it is often "
1840 "difficult to say what a particular error (in this case, "
1841 "the error with integer code '"
1842 << arg1
1843 << "') represents and how one should fix a code to avoid it. "
1844 "The best one can often do is to look up the call stack to "
1845 "see which deal.II function generated the error, and which "
1846 "Trilinos function the error code had originated from; "
1847 "then look up the Trilinos source code of that function (for "
1848 "example on github) to see what code path set that error "
1849 "code. Short of going through all of that, the only other "
1850 "option is to guess the cause of the error from "
1851 "the context in which the error appeared.");
1852
1853
1858 size_type,
1859 size_type,
1860 << "The entry with index <" << arg1 << ',' << arg2
1861 << "> does not exist.");
1862
1867 "You are attempting an operation on two vectors that "
1868 "are the same object, but the operation requires that the "
1869 "two objects are in fact different.");
1870
1875
1880 size_type,
1881 size_type,
1882 size_type,
1883 size_type,
1884 << "You tried to access element (" << arg1 << '/' << arg2
1885 << ')'
1886 << " of a distributed matrix, but only rows in range ["
1887 << arg3 << ',' << arg4
1888 << "] are stored locally and can be accessed.");
1889
1894 size_type,
1895 size_type,
1896 << "You tried to access element (" << arg1 << '/' << arg2
1897 << ')' << " of a sparse matrix, but it appears to not"
1898 << " exist in the Trilinos sparsity pattern.");
1903 protected:
1904 private:
1909 std::unique_ptr<Epetra_Map> column_space_map;
1910
1916 std::unique_ptr<Epetra_FECrsMatrix> matrix;
1917
1923 std::unique_ptr<Epetra_CrsMatrix> nonlocal_matrix;
1924
1928 std::unique_ptr<Epetra_Export> nonlocal_matrix_exporter;
1929
1941 Epetra_CombineMode last_action;
1942
1948
1961 void
1963
1971 void
1973
1974 // To allow calling protected prepare_add() and prepare_set().
1975 friend class BlockMatrixBase<SparseMatrix>;
1976 };
1977
1978
1979
1980 // forwards declarations
1981 class SolverBase;
1982 class PreconditionBase;
1983
1984 namespace internal
1985 {
1986 inline void
1987 check_vector_map_equality(const Epetra_CrsMatrix &mtrx,
1988 const Epetra_MultiVector &src,
1989 const Epetra_MultiVector &dst,
1990 const bool transpose)
1991 {
1992 if (transpose == false)
1993 {
1994 Assert(src.Map().SameAs(mtrx.DomainMap()) == true,
1995 ExcMessage(
1996 "Column map of matrix does not fit with vector map!"));
1997 Assert(dst.Map().SameAs(mtrx.RangeMap()) == true,
1998 ExcMessage("Row map of matrix does not fit with vector map!"));
1999 }
2000 else
2001 {
2002 Assert(src.Map().SameAs(mtrx.RangeMap()) == true,
2003 ExcMessage(
2004 "Column map of matrix does not fit with vector map!"));
2005 Assert(dst.Map().SameAs(mtrx.DomainMap()) == true,
2006 ExcMessage("Row map of matrix does not fit with vector map!"));
2007 }
2008 }
2009
2010 inline void
2012 const Epetra_MultiVector &src,
2013 const Epetra_MultiVector &dst,
2014 const bool transpose)
2015 {
2016 if (transpose == false)
2017 {
2018 Assert(src.Map().SameAs(op.OperatorDomainMap()) == true,
2019 ExcMessage(
2020 "Column map of operator does not fit with vector map!"));
2021 Assert(dst.Map().SameAs(op.OperatorRangeMap()) == true,
2022 ExcMessage(
2023 "Row map of operator does not fit with vector map!"));
2024 }
2025 else
2026 {
2027 Assert(src.Map().SameAs(op.OperatorRangeMap()) == true,
2028 ExcMessage(
2029 "Column map of operator does not fit with vector map!"));
2030 Assert(dst.Map().SameAs(op.OperatorDomainMap()) == true,
2031 ExcMessage(
2032 "Row map of operator does not fit with vector map!"));
2033 }
2034 }
2035
2036
2037 namespace LinearOperatorImplementation
2038 {
2059 {
2060 public:
2064 using VectorType = Epetra_MultiVector;
2065
2070
2075
2080
2094
2098 TrilinosPayload(const TrilinosWrappers::SparseMatrix &matrix_exemplar,
2099 const TrilinosWrappers::SparseMatrix &matrix);
2100
2104 TrilinosPayload(const TrilinosPayload &payload_exemplar,
2105 const TrilinosWrappers::SparseMatrix &matrix);
2106
2111 const TrilinosWrappers::SparseMatrix &matrix_exemplar,
2112 const TrilinosWrappers::PreconditionBase &preconditioner);
2113
2118 const TrilinosWrappers::PreconditionBase &preconditioner_exemplar,
2119 const TrilinosWrappers::PreconditionBase &preconditioner);
2120
2125 const TrilinosPayload &payload_exemplar,
2126 const TrilinosWrappers::PreconditionBase &preconditioner);
2127
2131 TrilinosPayload(const TrilinosPayload &payload);
2132
2140 TrilinosPayload(const TrilinosPayload &first_op,
2141 const TrilinosPayload &second_op);
2142
2146 virtual ~TrilinosPayload() override = default;
2147
2152 identity_payload() const;
2153
2158 null_payload() const;
2159
2164 transpose_payload() const;
2165
2182 template <typename Solver, typename Preconditioner>
2183 std::enable_if_t<
2184 std::is_base_of_v<TrilinosWrappers::SolverBase, Solver> &&
2185 std::is_base_of_v<TrilinosWrappers::PreconditionBase,
2186 Preconditioner>,
2188 inverse_payload(Solver &, const Preconditioner &) const;
2189
2207 template <typename Solver, typename Preconditioner>
2208 std::enable_if_t<
2209 !(std::is_base_of_v<TrilinosWrappers::SolverBase, Solver> &&
2210 std::is_base_of_v<TrilinosWrappers::PreconditionBase,
2211 Preconditioner>),
2213 inverse_payload(Solver &, const Preconditioner &) const;
2214
2227 IndexSet
2228 locally_owned_domain_indices() const;
2229
2235 IndexSet
2236 locally_owned_range_indices() const;
2237
2241 MPI_Comm
2242 get_mpi_communicator() const;
2243
2250 void
2251 transpose();
2252
2260 std::function<void(VectorType &, const VectorType &)> vmult;
2261
2269 std::function<void(VectorType &, const VectorType &)> Tvmult;
2270
2279 std::function<void(VectorType &, const VectorType &)> inv_vmult;
2280
2289 std::function<void(VectorType &, const VectorType &)> inv_Tvmult;
2290
2304 virtual bool
2305 UseTranspose() const override;
2306
2322 virtual int
2323 SetUseTranspose(bool UseTranspose) override;
2324
2336 virtual int
2337 Apply(const VectorType &X, VectorType &Y) const override;
2338
2357 virtual int
2358 ApplyInverse(const VectorType &Y, VectorType &X) const override;
2372 virtual const char *
2373 Label() const override;
2374
2382 virtual const Epetra_Comm &
2383 Comm() const override;
2384
2392 virtual const Epetra_Map &
2393 OperatorDomainMap() const override;
2394
2403 virtual const Epetra_Map &
2404 OperatorRangeMap() const override;
2407 private:
2417 template <typename EpetraOpType>
2418 TrilinosPayload(EpetraOpType &op,
2419 const bool supports_inverse_operations,
2420 const bool use_transpose,
2421 const MPI_Comm mpi_communicator,
2422 const IndexSet &locally_owned_domain_indices,
2423 const IndexSet &locally_owned_range_indices);
2424
2430
2435 Epetra_MpiComm communicator;
2436
2441 Epetra_Map domain_map;
2442
2447 Epetra_Map range_map;
2448
2457 virtual bool
2458 HasNormInf() const override;
2459
2467 virtual double
2468 NormInf() const override;
2469 };
2470
2476 operator+(const TrilinosPayload &first_op,
2477 const TrilinosPayload &second_op);
2478
2484 operator*(const TrilinosPayload &first_op,
2485 const TrilinosPayload &second_op);
2486
2487 } // namespace LinearOperatorImplementation
2488 } /* namespace internal */
2489
2490
2491
2492 // ----------------------- inline and template functions --------------------
2493
2494# ifndef DOXYGEN
2495
2496 namespace SparseMatrixIterators
2497 {
2498 inline AccessorBase::AccessorBase(SparseMatrix *matrix,
2499 size_type row,
2500 size_type index)
2501 : matrix(matrix)
2502 , a_row(row)
2503 , a_index(index)
2504 {
2505 visit_present_row();
2506 }
2507
2508
2509 inline AccessorBase::size_type
2510 AccessorBase::row() const
2511 {
2512 Assert(a_row < matrix->m(), ExcBeyondEndOfMatrix());
2513 return a_row;
2514 }
2515
2516
2517 inline AccessorBase::size_type
2518 AccessorBase::column() const
2519 {
2520 Assert(a_row < matrix->m(), ExcBeyondEndOfMatrix());
2521 return (*colnum_cache)[a_index];
2522 }
2523
2524
2525 inline AccessorBase::size_type
2526 AccessorBase::index() const
2527 {
2528 Assert(a_row < matrix->m(), ExcBeyondEndOfMatrix());
2529 return a_index;
2530 }
2531
2532
2533 inline Accessor<true>::Accessor(MatrixType *matrix,
2534 const size_type row,
2535 const size_type index)
2536 : AccessorBase(const_cast<SparseMatrix *>(matrix), row, index)
2537 {}
2538
2539
2540 template <bool Other>
2541 inline Accessor<true>::Accessor(const Accessor<Other> &other)
2542 : AccessorBase(other)
2543 {}
2544
2545
2546 inline TrilinosScalar
2547 Accessor<true>::value() const
2548 {
2549 Assert(a_row < matrix->m(), ExcBeyondEndOfMatrix());
2550 return (*value_cache)[a_index];
2551 }
2552
2553
2554 inline Accessor<false>::Reference::Reference(const Accessor<false> &acc)
2555 : accessor(const_cast<Accessor<false> &>(acc))
2556 {}
2557
2558
2559 inline Accessor<false>::Reference::operator TrilinosScalar() const
2560 {
2561 return (*accessor.value_cache)[accessor.a_index];
2562 }
2563
2564 inline const Accessor<false>::Reference &
2565 Accessor<false>::Reference::operator=(const TrilinosScalar n) const
2566 {
2567 (*accessor.value_cache)[accessor.a_index] = n;
2568 accessor.matrix->set(accessor.row(),
2569 accessor.column(),
2570 static_cast<TrilinosScalar>(*this));
2571 return *this;
2572 }
2573
2574
2575 inline const Accessor<false>::Reference &
2576 Accessor<false>::Reference::operator+=(const TrilinosScalar n) const
2577 {
2578 (*accessor.value_cache)[accessor.a_index] += n;
2579 accessor.matrix->set(accessor.row(),
2580 accessor.column(),
2581 static_cast<TrilinosScalar>(*this));
2582 return *this;
2583 }
2584
2585
2586 inline const Accessor<false>::Reference &
2587 Accessor<false>::Reference::operator-=(const TrilinosScalar n) const
2588 {
2589 (*accessor.value_cache)[accessor.a_index] -= n;
2590 accessor.matrix->set(accessor.row(),
2591 accessor.column(),
2592 static_cast<TrilinosScalar>(*this));
2593 return *this;
2594 }
2595
2596
2597 inline const Accessor<false>::Reference &
2598 Accessor<false>::Reference::operator*=(const TrilinosScalar n) const
2599 {
2600 (*accessor.value_cache)[accessor.a_index] *= n;
2601 accessor.matrix->set(accessor.row(),
2602 accessor.column(),
2603 static_cast<TrilinosScalar>(*this));
2604 return *this;
2605 }
2606
2607
2608 inline const Accessor<false>::Reference &
2609 Accessor<false>::Reference::operator/=(const TrilinosScalar n) const
2610 {
2611 (*accessor.value_cache)[accessor.a_index] /= n;
2612 accessor.matrix->set(accessor.row(),
2613 accessor.column(),
2614 static_cast<TrilinosScalar>(*this));
2615 return *this;
2616 }
2617
2618
2619 inline Accessor<false>::Accessor(MatrixType *matrix,
2620 const size_type row,
2621 const size_type index)
2622 : AccessorBase(matrix, row, index)
2623 {}
2624
2625
2626 inline Accessor<false>::Reference
2627 Accessor<false>::value() const
2628 {
2629 Assert(a_row < matrix->m(), ExcBeyondEndOfMatrix());
2630 return {*this};
2631 }
2632
2633
2634
2635 template <bool Constness>
2636 inline Iterator<Constness>::Iterator(MatrixType *matrix,
2637 const size_type row,
2638 const size_type index)
2639 : accessor(matrix, row, index)
2640 {}
2641
2642
2643 template <bool Constness>
2644 template <bool Other>
2645 inline Iterator<Constness>::Iterator(const Iterator<Other> &other)
2646 : accessor(other.accessor)
2647 {}
2648
2649
2650 template <bool Constness>
2651 inline Iterator<Constness> &
2652 Iterator<Constness>::operator++()
2653 {
2654 Assert(accessor.a_row < accessor.matrix->m(), ExcIteratorPastEnd());
2655
2656 ++accessor.a_index;
2657
2658 // If at end of line: do one
2659 // step, then cycle until we
2660 // find a row with a nonzero
2661 // number of entries.
2662 if (accessor.a_index >= accessor.colnum_cache->size())
2663 {
2664 accessor.a_index = 0;
2665 ++accessor.a_row;
2666
2667 while ((accessor.a_row < accessor.matrix->m()) &&
2668 ((accessor.matrix->in_local_range(accessor.a_row) == false) ||
2669 (accessor.matrix->row_length(accessor.a_row) == 0)))
2670 ++accessor.a_row;
2671
2672 accessor.visit_present_row();
2673 }
2674 return *this;
2675 }
2676
2677
2678 template <bool Constness>
2679 inline Iterator<Constness>
2680 Iterator<Constness>::operator++(int)
2681 {
2682 const Iterator<Constness> old_state = *this;
2683 ++(*this);
2684 return old_state;
2685 }
2686
2687
2688
2689 template <bool Constness>
2690 inline const Accessor<Constness> &
2691 Iterator<Constness>::operator*() const
2692 {
2693 return accessor;
2694 }
2695
2696
2697
2698 template <bool Constness>
2699 inline const Accessor<Constness> *
2700 Iterator<Constness>::operator->() const
2701 {
2702 return &accessor;
2703 }
2704
2705
2706
2707 template <bool Constness>
2708 template <bool OtherConstness>
2709 inline bool
2710 Iterator<Constness>::operator==(const Iterator<OtherConstness> &other) const
2711 {
2712 return (accessor.a_row == other.accessor.a_row &&
2713 accessor.a_index == other.accessor.a_index);
2714 }
2715
2716
2717
2718 template <bool Constness>
2719 template <bool OtherConstness>
2720 inline bool
2721 Iterator<Constness>::operator!=(const Iterator<OtherConstness> &other) const
2722 {
2723 return !(*this == other);
2724 }
2725
2726
2727
2728 template <bool Constness>
2729 template <bool OtherConstness>
2730 inline bool
2731 Iterator<Constness>::operator<(const Iterator<OtherConstness> &other) const
2732 {
2733 return (accessor.row() < other.accessor.row() ||
2734 (accessor.row() == other.accessor.row() &&
2735 accessor.index() < other.accessor.index()));
2736 }
2737
2738
2739 template <bool Constness>
2740 template <bool OtherConstness>
2741 inline bool
2742 Iterator<Constness>::operator>(const Iterator<OtherConstness> &other) const
2743 {
2744 return (other < *this);
2745 }
2746
2747 } // namespace SparseMatrixIterators
2748
2749
2750
2752 {
2753 return begin(0);
2754 }
2755
2756
2757
2759 {
2760 return const_iterator(this, m(), 0);
2761 }
2762
2763
2764
2765 inline SparseMatrix::const_iterator SparseMatrix::begin(const size_type r)
2766 const
2767 {
2768 AssertIndexRange(r, m());
2769 if (in_local_range(r) && (row_length(r) > 0))
2770 return const_iterator(this, r, 0);
2771 else
2772 return end(r);
2773 }
2774
2775
2776
2777 inline SparseMatrix::const_iterator SparseMatrix::end(const size_type r) const
2778 {
2779 AssertIndexRange(r, m());
2780
2781 // place the iterator on the first entry
2782 // past this line, or at the end of the
2783 // matrix
2784 for (size_type i = r + 1; i < m(); ++i)
2785 if (in_local_range(i) && (row_length(i) > 0))
2786 return const_iterator(this, i, 0);
2787
2788 // if there is no such line, then take the
2789 // end iterator of the matrix
2790 return end();
2791 }
2792
2793
2794
2796 {
2797 return begin(0);
2798 }
2799
2800
2801
2803 {
2804 return iterator(this, m(), 0);
2805 }
2806
2807
2808
2809 inline SparseMatrix::iterator SparseMatrix::begin(const size_type r)
2810 {
2811 AssertIndexRange(r, m());
2812 if (in_local_range(r) && (row_length(r) > 0))
2813 return iterator(this, r, 0);
2814 else
2815 return end(r);
2816 }
2817
2818
2819
2820 inline SparseMatrix::iterator SparseMatrix::end(const size_type r)
2821 {
2822 AssertIndexRange(r, m());
2823
2824 // place the iterator on the first entry
2825 // past this line, or at the end of the
2826 // matrix
2827 for (size_type i = r + 1; i < m(); ++i)
2828 if (in_local_range(i) && (row_length(i) > 0))
2829 return iterator(this, i, 0);
2830
2831 // if there is no such line, then take the
2832 // end iterator of the matrix
2833 return end();
2834 }
2835
2836
2837
2838 inline bool SparseMatrix::in_local_range(const size_type index) const
2839 {
2841# ifndef DEAL_II_WITH_64BIT_INDICES
2842 begin = matrix->RowMap().MinMyGID();
2843 end = matrix->RowMap().MaxMyGID() + 1;
2844# else
2845 begin = matrix->RowMap().MinMyGID64();
2846 end = matrix->RowMap().MaxMyGID64() + 1;
2847# endif
2848
2849 return ((index >= static_cast<size_type>(begin)) &&
2850 (index < static_cast<size_type>(end)));
2851 }
2852
2853
2854
2855 inline bool SparseMatrix::is_compressed() const
2856 {
2857 return compressed;
2858 }
2859
2860
2861
2862 // Inline the set() and add() functions, since they will be called
2863 // frequently, and the compiler can optimize away some unnecessary loops
2864 // when the sizes are given at compile time.
2865 template <>
2866 void SparseMatrix::set<TrilinosScalar>(const size_type row,
2867 const size_type n_cols,
2868 const size_type *col_indices,
2869 const TrilinosScalar *values,
2870 const bool elide_zero_values);
2871
2872
2873
2874 template <typename Number>
2875 void SparseMatrix::set(const size_type row,
2876 const size_type n_cols,
2877 const size_type *col_indices,
2878 const Number *values,
2879 const bool elide_zero_values)
2880 {
2881 std::vector<TrilinosScalar> trilinos_values(n_cols);
2882 std::copy(values, values + n_cols, trilinos_values.begin());
2883 this->set(
2884 row, n_cols, col_indices, trilinos_values.data(), elide_zero_values);
2885 }
2886
2887
2888
2889 inline void SparseMatrix::set(const size_type i,
2890 const size_type j,
2891 const TrilinosScalar value)
2892 {
2893 AssertIsFinite(value);
2894
2895 set(i, 1, &j, &value, false);
2896 }
2897
2898
2899
2900 inline void SparseMatrix::set(const std::vector<size_type> &indices,
2901 const FullMatrix<TrilinosScalar> &values,
2902 const bool elide_zero_values)
2903 {
2904 Assert(indices.size() == values.m(),
2905 ExcDimensionMismatch(indices.size(), values.m()));
2906 Assert(values.m() == values.n(), ExcNotQuadratic());
2907
2908 for (size_type i = 0; i < indices.size(); ++i)
2909 set(indices[i],
2910 indices.size(),
2911 indices.data(),
2912 &values(i, 0),
2913 elide_zero_values);
2914 }
2915
2916
2917
2918 inline void SparseMatrix::add(const size_type i,
2919 const size_type j,
2920 const TrilinosScalar value)
2921 {
2922 AssertIsFinite(value);
2923
2924 if (value == 0)
2925 {
2926 // we have to check after Insert/Add in any case to be consistent
2927 // with the MPI communication model, but we can save some
2928 // work if the addend is zero. However, these actions are done in case
2929 // we pass on to the other function.
2930
2931 // TODO: fix this (do not run compress here, but fail)
2932 if (last_action == Insert)
2933 {
2934 const int ierr = matrix->GlobalAssemble(*column_space_map,
2935 matrix->RowMap(),
2936 false);
2937
2938 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
2939 }
2940
2941 last_action = Add;
2942
2943 return;
2944 }
2945 else
2946 add(i, 1, &j, &value, false);
2947 }
2948
2949
2950
2951 // inline "simple" functions that are called frequently and do only involve
2952 // a call to some Trilinos function.
2954 {
2955# ifndef DEAL_II_WITH_64BIT_INDICES
2956 return matrix->NumGlobalRows();
2957# else
2958 return matrix->NumGlobalRows64();
2959# endif
2960 }
2961
2962
2963
2965 {
2966 // If the matrix structure has not been fixed (i.e., we did not have a
2967 // sparsity pattern), it does not know about the number of columns so we
2968 // must always take this from the additional column space map
2969 Assert(column_space_map.get() != nullptr, ExcInternalError());
2970 return n_global_elements(*column_space_map);
2971 }
2972
2973
2974
2975 inline unsigned int SparseMatrix::local_size() const
2976 {
2977 return matrix->NumMyRows();
2978 }
2979
2980
2981
2982 inline std::pair<SparseMatrix::size_type, SparseMatrix::size_type>
2984 {
2986# ifndef DEAL_II_WITH_64BIT_INDICES
2987 begin = matrix->RowMap().MinMyGID();
2988 end = matrix->RowMap().MaxMyGID() + 1;
2989# else
2990 begin = matrix->RowMap().MinMyGID64();
2991 end = matrix->RowMap().MaxMyGID64() + 1;
2992# endif
2993
2994 return std::make_pair(begin, end);
2995 }
2996
2997
2998
2999 inline std::uint64_t SparseMatrix::n_nonzero_elements() const
3000 {
3001 // Trilinos uses 64bit functions internally for attribute access, which
3002 // return `long long`. They also offer 32bit variants that return `int`,
3003 // however those call the 64bit version and convert the values to 32bit.
3004 // There is no necessity in using the 32bit versions at all.
3005 return static_cast<std::uint64_t>(matrix->NumGlobalNonzeros64());
3006 }
3007
3008
3009
3010 template <typename SparsityPatternType>
3011 inline void SparseMatrix::reinit(const IndexSet &parallel_partitioning,
3012 const SparsityPatternType &sparsity_pattern,
3013 const MPI_Comm communicator,
3014 const bool exchange_data)
3015 {
3016 reinit(parallel_partitioning,
3017 parallel_partitioning,
3018 sparsity_pattern,
3019 communicator,
3020 exchange_data);
3021 }
3022
3023
3024
3025 template <typename number>
3026 inline void SparseMatrix::reinit(
3027 const IndexSet &parallel_partitioning,
3028 const ::SparseMatrix<number> &sparse_matrix,
3029 const MPI_Comm communicator,
3030 const double drop_tolerance,
3031 const bool copy_values,
3032 const ::SparsityPattern *use_this_sparsity)
3033 {
3034 Epetra_Map map =
3035 parallel_partitioning.make_trilinos_map(communicator, false);
3036 reinit(parallel_partitioning,
3037 parallel_partitioning,
3038 sparse_matrix,
3039 drop_tolerance,
3040 copy_values,
3041 use_this_sparsity);
3042 }
3043
3044
3045
3046 inline const Epetra_CrsMatrix &SparseMatrix::trilinos_matrix() const
3047 {
3048 return static_cast<const Epetra_CrsMatrix &>(*matrix);
3049 }
3050
3051
3052
3053 inline const Epetra_CrsGraph &SparseMatrix::trilinos_sparsity_pattern() const
3054 {
3055 return matrix->Graph();
3056 }
3057
3058
3059
3061 {
3062 return IndexSet(matrix->DomainMap());
3063 }
3064
3065
3066
3068 {
3069 return IndexSet(matrix->RangeMap());
3070 }
3071
3072
3073
3074 inline void SparseMatrix::prepare_add()
3075 {
3076 // nothing to do here
3077 }
3078
3079
3080
3081 inline void SparseMatrix::prepare_set()
3082 {
3083 // nothing to do here
3084 }
3085
3086
3087
3088 template <typename VectorType>
3089 inline TrilinosScalar SparseMatrix::residual(VectorType & dst,
3090 const VectorType &x,
3091 const VectorType &b) const
3092 {
3093 vmult(dst, x);
3094 dst -= b;
3095 dst *= -1.;
3096
3097 return dst.l2_norm();
3098 }
3099
3100
3101 namespace internal
3102 {
3103 namespace LinearOperatorImplementation
3104 {
3105 template <typename EpetraOpType>
3106 TrilinosPayload::TrilinosPayload(
3107 EpetraOpType &op,
3108 const bool supports_inverse_operations,
3109 const bool use_transpose,
3110 const MPI_Comm mpi_communicator,
3111 const IndexSet &locally_owned_domain_indices,
3112 const IndexSet &locally_owned_range_indices)
3113 : use_transpose(use_transpose)
3114 , communicator(mpi_communicator)
3115 , domain_map(
3116 locally_owned_domain_indices.make_trilinos_map(communicator.Comm()))
3117 , range_map(
3118 locally_owned_range_indices.make_trilinos_map(communicator.Comm()))
3119 {
3120 vmult = [&op](Range &tril_dst, const Domain &tril_src) {
3121 // Duplicated from TrilinosWrappers::PreconditionBase::vmult
3122 // as well as from TrilinosWrappers::SparseMatrix::Tvmult
3123 Assert(&tril_src != &tril_dst,
3126 tril_src,
3127 tril_dst,
3128 op.UseTranspose());
3129
3130 const int ierr = op.Apply(tril_src, tril_dst);
3131 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
3132 };
3133
3134 Tvmult = [&op](Domain &tril_dst, const Range &tril_src) {
3135 // Duplicated from TrilinosWrappers::PreconditionBase::vmult
3136 // as well as from TrilinosWrappers::SparseMatrix::Tvmult
3137 Assert(&tril_src != &tril_dst,
3140 tril_src,
3141 tril_dst,
3142 !op.UseTranspose());
3143
3144 op.SetUseTranspose(!op.UseTranspose());
3145 const int ierr = op.Apply(tril_src, tril_dst);
3146 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
3147 op.SetUseTranspose(!op.UseTranspose());
3148 };
3149
3150 if (supports_inverse_operations)
3151 {
3152 inv_vmult = [&op](Domain &tril_dst, const Range &tril_src) {
3153 // Duplicated from TrilinosWrappers::PreconditionBase::vmult
3154 // as well as from TrilinosWrappers::SparseMatrix::Tvmult
3155 Assert(
3156 &tril_src != &tril_dst,
3159 tril_src,
3160 tril_dst,
3161 !op.UseTranspose());
3162
3163 const int ierr = op.ApplyInverse(tril_src, tril_dst);
3164 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
3165 };
3166
3167 inv_Tvmult = [&op](Range &tril_dst, const Domain &tril_src) {
3168 // Duplicated from TrilinosWrappers::PreconditionBase::vmult
3169 // as well as from TrilinosWrappers::SparseMatrix::Tvmult
3170 Assert(
3171 &tril_src != &tril_dst,
3174 tril_src,
3175 tril_dst,
3176 op.UseTranspose());
3177
3178 op.SetUseTranspose(!op.UseTranspose());
3179 const int ierr = op.ApplyInverse(tril_src, tril_dst);
3180 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
3181 op.SetUseTranspose(!op.UseTranspose());
3182 };
3183 }
3184 else
3185 {
3186 inv_vmult = [](Domain &, const Range &) {
3187 Assert(false,
3188 ExcMessage(
3189 "Uninitialized TrilinosPayload::inv_vmult called. "
3190 "The operator does not support inverse operations."));
3191 };
3192
3193 inv_Tvmult = [](Range &, const Domain &) {
3194 Assert(false,
3195 ExcMessage(
3196 "Uninitialized TrilinosPayload::inv_Tvmult called. "
3197 "The operator does not support inverse operations."));
3198 };
3199 }
3200 }
3201
3202
3203 template <typename Solver, typename Preconditioner>
3204 std::enable_if_t<
3205 std::is_base_of_v<TrilinosWrappers::SolverBase, Solver> &&
3206 std::is_base_of_v<TrilinosWrappers::PreconditionBase, Preconditioner>,
3207 TrilinosPayload>
3209 Solver &solver,
3210 const Preconditioner &preconditioner) const
3211 {
3212 const auto &payload = *this;
3213
3214 TrilinosPayload return_op(payload);
3215
3216 // Capture by copy so the payloads are always valid
3217
3218 return_op.inv_vmult = [payload, &solver, &preconditioner](
3219 TrilinosPayload::Domain &tril_dst,
3220 const TrilinosPayload::Range &tril_src) {
3221 // Duplicated from TrilinosWrappers::PreconditionBase::vmult
3222 // as well as from TrilinosWrappers::SparseMatrix::Tvmult
3223 Assert(&tril_src != &tril_dst,
3226 tril_src,
3227 tril_dst,
3228 !payload.UseTranspose());
3229 solver.solve(payload, tril_dst, tril_src, preconditioner);
3230 };
3231
3232 return_op.inv_Tvmult = [payload, &solver, &preconditioner](
3233 TrilinosPayload::Range &tril_dst,
3234 const TrilinosPayload::Domain &tril_src) {
3235 // Duplicated from TrilinosWrappers::PreconditionBase::vmult
3236 // as well as from TrilinosWrappers::SparseMatrix::Tvmult
3237 Assert(&tril_src != &tril_dst,
3240 tril_src,
3241 tril_dst,
3242 payload.UseTranspose());
3243
3244 const_cast<TrilinosPayload &>(payload).transpose();
3245 solver.solve(payload, tril_dst, tril_src, preconditioner);
3246 const_cast<TrilinosPayload &>(payload).transpose();
3247 };
3248
3249 // If the input operator is already setup for transpose operations, then
3250 // we must do similar with its inverse.
3251 if (return_op.UseTranspose() == true)
3252 std::swap(return_op.inv_vmult, return_op.inv_Tvmult);
3253
3254 return return_op;
3255 }
3256
3257 template <typename Solver, typename Preconditioner>
3258 std::enable_if_t<
3259 !(std::is_base_of_v<TrilinosWrappers::SolverBase, Solver> &&
3260 std::is_base_of_v<TrilinosWrappers::PreconditionBase,
3261 Preconditioner>),
3262 TrilinosPayload>
3263 TrilinosPayload::inverse_payload(Solver &, const Preconditioner &) const
3264 {
3265 TrilinosPayload return_op(*this);
3266
3267 return_op.inv_vmult = [](TrilinosPayload::Domain &,
3268 const TrilinosPayload::Range &) {
3269 AssertThrow(false,
3270 ExcMessage("Payload inv_vmult disabled because of "
3271 "incompatible solver/preconditioner choice."));
3272 };
3273
3274 return_op.inv_Tvmult = [](TrilinosPayload::Range &,
3275 const TrilinosPayload::Domain &) {
3276 AssertThrow(false,
3277 ExcMessage("Payload inv_vmult disabled because of "
3278 "incompatible solver/preconditioner choice."));
3279 };
3280
3281 return return_op;
3282 }
3283 } // namespace LinearOperatorImplementation
3284 } // namespace internal
3285
3286 template <>
3287 void SparseMatrix::set<TrilinosScalar>(const size_type row,
3288 const size_type n_cols,
3289 const size_type *col_indices,
3290 const TrilinosScalar *values,
3291 const bool elide_zero_values);
3292# endif // DOXYGEN
3293
3294} /* namespace TrilinosWrappers */
3295
3296# endif
3297
3299
3300#endif
3301/*----------------------- trilinos_sparse_matrix.h --------------------*/
*  iterator end()
*  *  for(const auto &cell :triangulation.active_cell_iterators())
*  *  iterator begin()
*  x_component_mask set(0, true)
*  *  reference operator*() const
std::ptrdiff_t difference_type
*  *  const_iterator()=default
*  *  iterator()=default
Epetra_Map make_trilinos_map(const MPI_Comm communicator=MPI_COMM_WORLD, const bool overlapping=false) const
AccessorBase(SparseMatrix *matrix, const size_type row, const size_type index)
std::shared_ptr< std::vector< TrilinosScalar > > value_cache
std::shared_ptr< std::vector< size_type > > colnum_cache
const Reference & operator-=(const TrilinosScalar n) const
const Reference & operator*=(const TrilinosScalar n) const
const Reference & operator+=(const TrilinosScalar n) const
const Reference & operator/=(const TrilinosScalar n) const
const Reference & operator=(const TrilinosScalar n) const
Accessor(MatrixType *matrix, const size_type row, const size_type index)
Accessor(MatrixType *matrix, const size_type row, const size_type index)
const Accessor< Constness > & operator*() const
const Accessor< Constness > * operator->() const
typename Accessor< Constness >::MatrixType MatrixType
bool operator==(const Iterator< OtherConstness > &) const
bool operator!=(const Iterator< OtherConstness > &) const
bool operator<(const Iterator< OtherConstness > &) const
Iterator(const Iterator< Other > &other)
bool operator>(const Iterator< OtherConstness > &) const
Iterator(MatrixType *matrix, const size_type row, const size_type index)
void set(const size_type i, const size_type j, const TrilinosScalar value)
std::unique_ptr< Epetra_Map > column_space_map
TrilinosScalar residual(VectorType &dst, const VectorType &x, const VectorType &b) const
void mmult(SparseMatrix &C, const SparseMatrix &B, const MPI::Vector &V=MPI::Vector()) const
std::unique_ptr< Epetra_Export > nonlocal_matrix_exporter
void compress(VectorOperation::values operation)
std::unique_ptr< Epetra_FECrsMatrix > matrix
void vmult(VectorType &dst, const VectorType &src) const
const Epetra_CrsMatrix & trilinos_matrix() const
TrilinosScalar matrix_norm_square(const MPI::Vector &v) const
IndexSet locally_owned_range_indices() const
void print(std::ostream &out, const bool write_extended_trilinos_info=false) const
void Tmmult(SparseMatrix &C, const SparseMatrix &B, const MPI::Vector &V=MPI::Vector()) const
void clear_row(const size_type row, const TrilinosScalar new_diag_value=0)
void clear_rows(const ArrayView< const size_type > &rows, const TrilinosScalar new_diag_value=0)
const_iterator begin() const
void reinit(const SparsityPatternType &sparsity_pattern)
void vmult_add(VectorType &dst, const VectorType &src) const
SparseMatrix & operator=(const SparseMatrix &)=delete
void Tvmult_add(VectorType &dst, const VectorType &src) const
TrilinosScalar el(const size_type i, const size_type j) const
IndexSet locally_owned_domain_indices() const
bool in_local_range(const size_type index) const
void copy_from(const SparseMatrix &source)
unsigned int row_length(const size_type row) const
void Tvmult(VectorType &dst, const VectorType &src) const
std::uint64_t n_nonzero_elements() const
const Epetra_CrsGraph & trilinos_sparsity_pattern() const
SparseMatrix(const SparseMatrix &)=delete
TrilinosScalar diag_element(const size_type i) const
void add(const size_type i, const size_type j, const TrilinosScalar value)
unsigned int local_size() const
virtual ~SparseMatrix() override=default
TrilinosScalar matrix_scalar_product(const MPI::Vector &u, const MPI::Vector &v) const
const_iterator end() const
std::pair< size_type, size_type > local_range() const
std::unique_ptr< Epetra_CrsMatrix > nonlocal_matrix
std::function< void(VectorType &, const VectorType &)> inv_Tvmult
std::enable_if_t< std::is_base_of_v< TrilinosWrappers::SolverBase, Solver > &&std::is_base_of_v< TrilinosWrappers::PreconditionBase, Preconditioner >, TrilinosPayload > inverse_payload(Solver &, const Preconditioner &) const
TrilinosPayload(EpetraOpType &op, const bool supports_inverse_operations, const bool use_transpose, const MPI_Comm mpi_communicator, const IndexSet &locally_owned_domain_indices, const IndexSet &locally_owned_range_indices)
std::enable_if_t< !(std::is_base_of_v< TrilinosWrappers::SolverBase, Solver > &&std::is_base_of_v< TrilinosWrappers::PreconditionBase, Preconditioner >), TrilinosPayload > inverse_payload(Solver &, const Preconditioner &) const
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
Definition config.h:636
#define DEAL_II_DEPRECATED_WITH_COMMENT(comment)
Definition config.h:295
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define DEAL_II_ENABLE_EXTRA_DIAGNOSTICS
Definition config.h:680
DerivativeForm< 1, spacedim, dim, Number > transpose(const DerivativeForm< 1, dim, spacedim, Number > &DF)
static ::ExceptionBase & ExcInvalidIndexWithinRow(size_type arg1, size_type arg2)
#define DeclException0(Exception0)
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
static ::ExceptionBase & ExcAccessToNonlocalRow(std::size_t arg1, std::size_t arg2, std::size_t arg3)
static ::ExceptionBase & ExcInvalidIndex(size_type arg1, size_type arg2)
#define Assert(cond, exc)
static ::ExceptionBase & ExcIteratorPastEnd()
static ::ExceptionBase & ExcAccessToNonPresentElement(size_type arg1, size_type arg2)
#define AssertIsFinite(number)
static ::ExceptionBase & ExcAccessToNonlocalRow(std::size_t arg1)
static ::ExceptionBase & ExcBeyondEndOfMatrix()
#define DeclException2(Exception2, type1, type2, outsequence)
#define AssertIndexRange(index, range)
#define DeclExceptionMsg(Exception, defaulttext)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcSourceEqualsDestination()
#define DeclException3(Exception3, type1, type2, type3, outsequence)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcNotQuadratic()
#define DeclException1(Exception1, type1, outsequence)
static ::ExceptionBase & ExcMatrixNotCompressed()
static ::ExceptionBase & ExcTrilinosError(int arg1)
static ::ExceptionBase & ExcAccessToNonLocalElement(size_type arg1, size_type arg2, size_type arg3, size_type arg4)
static ::ExceptionBase & ExcMessage(std::string arg1)
static ::ExceptionBase & ExcTrilinosError(int arg1)
#define AssertThrow(cond, exc)
@ matrix
Contents is actually a matrix.
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
void check_vector_map_equality(const Epetra_CrsMatrix &mtrx, const Epetra_MultiVector &src, const Epetra_MultiVector &dst, const bool transpose)
TrilinosWrappers::types::int64_type n_global_elements(const Epetra_BlockMap &map)
void reinit(MatrixBlock< MatrixType > &v, const BlockSparsityPattern &p)
STL namespace.
unsigned int global_dof_index
Definition types.h:92
BarycentricPolynomial< dim, Number1 > operator+(const Number2 &a, const BarycentricPolynomial< dim, Number1 > &bp)
typename ::TrilinosWrappers::SparseMatrixIterators::Iterator< Constness >::value_type value_type
typename ::TrilinosWrappers::SparseMatrixIterators::Iterator< Constness >::difference_type difference_type
double TrilinosScalar
Definition types.h:188