version GIT relicensing-7278-g091132d5eb 2026-12-02 03:10: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::
2560 operator TrilinosScalar() const
2561 {
2562 return (*accessor.value_cache)[accessor.a_index];
2563 }
2564
2565 inline const Accessor<false>::Reference &
2566 Accessor<false>::Reference::operator=(const TrilinosScalar n) const
2567 {
2568 (*accessor.value_cache)[accessor.a_index] = n;
2569 accessor.matrix->set(accessor.row(),
2570 accessor.column(),
2571 static_cast<TrilinosScalar>(*this));
2572 return *this;
2573 }
2574
2575
2576 inline const Accessor<false>::Reference &
2577 Accessor<false>::Reference::operator+=(const TrilinosScalar n) const
2578 {
2579 (*accessor.value_cache)[accessor.a_index] += n;
2580 accessor.matrix->set(accessor.row(),
2581 accessor.column(),
2582 static_cast<TrilinosScalar>(*this));
2583 return *this;
2584 }
2585
2586
2587 inline const Accessor<false>::Reference &
2588 Accessor<false>::Reference::operator-=(const TrilinosScalar n) const
2589 {
2590 (*accessor.value_cache)[accessor.a_index] -= n;
2591 accessor.matrix->set(accessor.row(),
2592 accessor.column(),
2593 static_cast<TrilinosScalar>(*this));
2594 return *this;
2595 }
2596
2597
2598 inline const Accessor<false>::Reference &
2599 Accessor<false>::Reference::operator*=(const TrilinosScalar n) const
2600 {
2601 (*accessor.value_cache)[accessor.a_index] *= n;
2602 accessor.matrix->set(accessor.row(),
2603 accessor.column(),
2604 static_cast<TrilinosScalar>(*this));
2605 return *this;
2606 }
2607
2608
2609 inline const Accessor<false>::Reference &
2610 Accessor<false>::Reference::operator/=(const TrilinosScalar n) const
2611 {
2612 (*accessor.value_cache)[accessor.a_index] /= n;
2613 accessor.matrix->set(accessor.row(),
2614 accessor.column(),
2615 static_cast<TrilinosScalar>(*this));
2616 return *this;
2617 }
2618
2619
2620 inline Accessor<false>::Accessor(MatrixType *matrix,
2621 const size_type row,
2622 const size_type index)
2623 : AccessorBase(matrix, row, index)
2624 {}
2625
2626
2627 inline Accessor<false>::Reference
2628 Accessor<false>::value() const
2629 {
2630 Assert(a_row < matrix->m(), ExcBeyondEndOfMatrix());
2631 return {*this};
2632 }
2633
2634
2635
2636 template <bool Constness>
2637 inline Iterator<Constness>::Iterator(MatrixType *matrix,
2638 const size_type row,
2639 const size_type index)
2640 : accessor(matrix, row, index)
2641 {}
2642
2643
2644 template <bool Constness>
2645 template <bool Other>
2646 inline Iterator<Constness>::Iterator(const Iterator<Other> &other)
2647 : accessor(other.accessor)
2648 {}
2649
2650
2651 template <bool Constness>
2652 inline Iterator<Constness> &
2653 Iterator<Constness>::operator++()
2654 {
2655 Assert(accessor.a_row < accessor.matrix->m(), ExcIteratorPastEnd());
2656
2657 ++accessor.a_index;
2658
2659 // If at end of line: do one
2660 // step, then cycle until we
2661 // find a row with a nonzero
2662 // number of entries.
2663 if (accessor.a_index >= accessor.colnum_cache->size())
2664 {
2665 accessor.a_index = 0;
2666 ++accessor.a_row;
2667
2668 while ((accessor.a_row < accessor.matrix->m()) &&
2669 ((accessor.matrix->in_local_range(accessor.a_row) == false) ||
2670 (accessor.matrix->row_length(accessor.a_row) == 0)))
2671 ++accessor.a_row;
2672
2673 accessor.visit_present_row();
2674 }
2675 return *this;
2676 }
2677
2678
2679 template <bool Constness>
2680 inline Iterator<Constness>
2681 Iterator<Constness>::operator++(int)
2682 {
2683 const Iterator<Constness> old_state = *this;
2684 ++(*this);
2685 return old_state;
2686 }
2687
2688
2689
2690 template <bool Constness>
2691 inline const Accessor<Constness> &
2692 Iterator<Constness>::operator*() const
2693 {
2694 return accessor;
2695 }
2696
2697
2698
2699 template <bool Constness>
2700 inline const Accessor<Constness> *
2701 Iterator<Constness>::operator->() const
2702 {
2703 return &accessor;
2704 }
2705
2706
2707
2708 template <bool Constness>
2709 template <bool OtherConstness>
2710 inline bool
2711 Iterator<Constness>::operator==(const Iterator<OtherConstness> &other) const
2712 {
2713 return (accessor.a_row == other.accessor.a_row &&
2714 accessor.a_index == other.accessor.a_index);
2715 }
2716
2717
2718
2719 template <bool Constness>
2720 template <bool OtherConstness>
2721 inline bool
2722 Iterator<Constness>::operator!=(const Iterator<OtherConstness> &other) const
2723 {
2724 return !(*this == other);
2725 }
2726
2727
2728
2729 template <bool Constness>
2730 template <bool OtherConstness>
2731 inline bool
2732 Iterator<Constness>::operator<(const Iterator<OtherConstness> &other) const
2733 {
2734 return (accessor.row() < other.accessor.row() ||
2735 (accessor.row() == other.accessor.row() &&
2736 accessor.index() < other.accessor.index()));
2737 }
2738
2739
2740 template <bool Constness>
2741 template <bool OtherConstness>
2742 inline bool
2743 Iterator<Constness>::operator>(const Iterator<OtherConstness> &other) const
2744 {
2745 return (other < *this);
2746 }
2747
2748 } // namespace SparseMatrixIterators
2749
2750
2751
2753 {
2754 return begin(0);
2755 }
2756
2757
2758
2760 {
2761 return const_iterator(this, m(), 0);
2762 }
2763
2764
2765
2766 inline SparseMatrix::const_iterator SparseMatrix::begin(const size_type r)
2767 const
2768 {
2769 AssertIndexRange(r, m());
2770 if (in_local_range(r) && (row_length(r) > 0))
2771 return const_iterator(this, r, 0);
2772 else
2773 return end(r);
2774 }
2775
2776
2777
2778 inline SparseMatrix::const_iterator SparseMatrix::end(const size_type r) const
2779 {
2780 AssertIndexRange(r, m());
2781
2782 // place the iterator on the first entry
2783 // past this line, or at the end of the
2784 // matrix
2785 for (size_type i = r + 1; i < m(); ++i)
2786 if (in_local_range(i) && (row_length(i) > 0))
2787 return const_iterator(this, i, 0);
2788
2789 // if there is no such line, then take the
2790 // end iterator of the matrix
2791 return end();
2792 }
2793
2794
2795
2797 {
2798 return begin(0);
2799 }
2800
2801
2802
2804 {
2805 return iterator(this, m(), 0);
2806 }
2807
2808
2809
2810 inline SparseMatrix::iterator SparseMatrix::begin(const size_type r)
2811 {
2812 AssertIndexRange(r, m());
2813 if (in_local_range(r) && (row_length(r) > 0))
2814 return iterator(this, r, 0);
2815 else
2816 return end(r);
2817 }
2818
2819
2820
2821 inline SparseMatrix::iterator SparseMatrix::end(const size_type r)
2822 {
2823 AssertIndexRange(r, m());
2824
2825 // place the iterator on the first entry
2826 // past this line, or at the end of the
2827 // matrix
2828 for (size_type i = r + 1; i < m(); ++i)
2829 if (in_local_range(i) && (row_length(i) > 0))
2830 return iterator(this, i, 0);
2831
2832 // if there is no such line, then take the
2833 // end iterator of the matrix
2834 return end();
2835 }
2836
2837
2838
2839 inline bool SparseMatrix::in_local_range(const size_type index) const
2840 {
2842# ifndef DEAL_II_WITH_64BIT_INDICES
2843 begin = matrix->RowMap().MinMyGID();
2844 end = matrix->RowMap().MaxMyGID() + 1;
2845# else
2846 begin = matrix->RowMap().MinMyGID64();
2847 end = matrix->RowMap().MaxMyGID64() + 1;
2848# endif
2849
2850 return ((index >= static_cast<size_type>(begin)) &&
2851 (index < static_cast<size_type>(end)));
2852 }
2853
2854
2855
2856 inline bool SparseMatrix::is_compressed() const
2857 {
2858 return compressed;
2859 }
2860
2861
2862
2863 // Inline the set() and add() functions, since they will be called
2864 // frequently, and the compiler can optimize away some unnecessary loops
2865 // when the sizes are given at compile time.
2866 template <>
2867 void SparseMatrix::set<TrilinosScalar>(const size_type row,
2868 const size_type n_cols,
2869 const size_type *col_indices,
2870 const TrilinosScalar *values,
2871 const bool elide_zero_values);
2872
2873
2874
2875 template <typename Number>
2876 void SparseMatrix::set(const size_type row,
2877 const size_type n_cols,
2878 const size_type *col_indices,
2879 const Number *values,
2880 const bool elide_zero_values)
2881 {
2882 std::vector<TrilinosScalar> trilinos_values(n_cols);
2883 std::copy(values, values + n_cols, trilinos_values.begin());
2884 this->set(
2885 row, n_cols, col_indices, trilinos_values.data(), elide_zero_values);
2886 }
2887
2888
2889
2890 inline void SparseMatrix::set(const size_type i,
2891 const size_type j,
2892 const TrilinosScalar value)
2893 {
2894 AssertIsFinite(value);
2895
2896 set(i, 1, &j, &value, false);
2897 }
2898
2899
2900
2901 inline void SparseMatrix::set(const std::vector<size_type> &indices,
2902 const FullMatrix<TrilinosScalar> &values,
2903 const bool elide_zero_values)
2904 {
2905 Assert(indices.size() == values.m(),
2906 ExcDimensionMismatch(indices.size(), values.m()));
2907 Assert(values.m() == values.n(), ExcNotQuadratic());
2908
2909 for (size_type i = 0; i < indices.size(); ++i)
2910 set(indices[i],
2911 indices.size(),
2912 indices.data(),
2913 &values(i, 0),
2914 elide_zero_values);
2915 }
2916
2917
2918
2919 inline void SparseMatrix::add(const size_type i,
2920 const size_type j,
2921 const TrilinosScalar value)
2922 {
2923 AssertIsFinite(value);
2924
2925 if (value == 0)
2926 {
2927 // we have to check after Insert/Add in any case to be consistent
2928 // with the MPI communication model, but we can save some
2929 // work if the addend is zero. However, these actions are done in case
2930 // we pass on to the other function.
2931
2932 // TODO: fix this (do not run compress here, but fail)
2933 if (last_action == Insert)
2934 {
2935 const int ierr = matrix->GlobalAssemble(*column_space_map,
2936 matrix->RowMap(),
2937 false);
2938
2939 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
2940 }
2941
2942 last_action = Add;
2943
2944 return;
2945 }
2946 else
2947 add(i, 1, &j, &value, false);
2948 }
2949
2950
2951
2952 // inline "simple" functions that are called frequently and do only involve
2953 // a call to some Trilinos function.
2955 {
2956# ifndef DEAL_II_WITH_64BIT_INDICES
2957 return matrix->NumGlobalRows();
2958# else
2959 return matrix->NumGlobalRows64();
2960# endif
2961 }
2962
2963
2964
2966 {
2967 // If the matrix structure has not been fixed (i.e., we did not have a
2968 // sparsity pattern), it does not know about the number of columns so we
2969 // must always take this from the additional column space map
2970 Assert(column_space_map.get() != nullptr, ExcInternalError());
2971 return n_global_elements(*column_space_map);
2972 }
2973
2974
2975
2976 inline unsigned int SparseMatrix::local_size() const
2977 {
2978 return matrix->NumMyRows();
2979 }
2980
2981
2982
2983 inline std::pair<SparseMatrix::size_type, SparseMatrix::size_type>
2985 {
2987# ifndef DEAL_II_WITH_64BIT_INDICES
2988 begin = matrix->RowMap().MinMyGID();
2989 end = matrix->RowMap().MaxMyGID() + 1;
2990# else
2991 begin = matrix->RowMap().MinMyGID64();
2992 end = matrix->RowMap().MaxMyGID64() + 1;
2993# endif
2994
2995 return std::make_pair(begin, end);
2996 }
2997
2998
2999
3000 inline std::uint64_t SparseMatrix::n_nonzero_elements() const
3001 {
3002 // Trilinos uses 64bit functions internally for attribute access, which
3003 // return `long long`. They also offer 32bit variants that return `int`,
3004 // however those call the 64bit version and convert the values to 32bit.
3005 // There is no necessity in using the 32bit versions at all.
3006 return static_cast<std::uint64_t>(matrix->NumGlobalNonzeros64());
3007 }
3008
3009
3010
3011 template <typename SparsityPatternType>
3012 inline void SparseMatrix::reinit(const IndexSet &parallel_partitioning,
3013 const SparsityPatternType &sparsity_pattern,
3014 const MPI_Comm communicator,
3015 const bool exchange_data)
3016 {
3017 reinit(parallel_partitioning,
3018 parallel_partitioning,
3019 sparsity_pattern,
3020 communicator,
3021 exchange_data);
3022 }
3023
3024
3025
3026 template <typename number>
3027 inline void SparseMatrix::reinit(
3028 const IndexSet &parallel_partitioning,
3029 const ::SparseMatrix<number> &sparse_matrix,
3030 const MPI_Comm communicator,
3031 const double drop_tolerance,
3032 const bool copy_values,
3033 const ::SparsityPattern *use_this_sparsity)
3034 {
3035 Epetra_Map map =
3036 parallel_partitioning.make_trilinos_map(communicator, false);
3037 reinit(parallel_partitioning,
3038 parallel_partitioning,
3039 sparse_matrix,
3040 drop_tolerance,
3041 copy_values,
3042 use_this_sparsity);
3043 }
3044
3045
3046
3047 inline const Epetra_CrsMatrix &SparseMatrix::trilinos_matrix() const
3048 {
3049 return static_cast<const Epetra_CrsMatrix &>(*matrix);
3050 }
3051
3052
3053
3054 inline const Epetra_CrsGraph &SparseMatrix::trilinos_sparsity_pattern() const
3055 {
3056 return matrix->Graph();
3057 }
3058
3059
3060
3062 {
3063 return IndexSet(matrix->DomainMap());
3064 }
3065
3066
3067
3069 {
3070 return IndexSet(matrix->RangeMap());
3071 }
3072
3073
3074
3075 inline void SparseMatrix::prepare_add()
3076 {
3077 // nothing to do here
3078 }
3079
3080
3081
3082 inline void SparseMatrix::prepare_set()
3083 {
3084 // nothing to do here
3085 }
3086
3087
3088
3089 template <typename VectorType>
3090 inline TrilinosScalar SparseMatrix::residual(VectorType & dst,
3091 const VectorType &x,
3092 const VectorType &b) const
3093 {
3094 vmult(dst, x);
3095 dst -= b;
3096 dst *= -1.;
3097
3098 return dst.l2_norm();
3099 }
3100
3101
3102 namespace internal
3103 {
3104 namespace LinearOperatorImplementation
3105 {
3106 template <typename EpetraOpType>
3107 TrilinosPayload::TrilinosPayload(
3108 EpetraOpType &op,
3109 const bool supports_inverse_operations,
3110 const bool use_transpose,
3111 const MPI_Comm mpi_communicator,
3112 const IndexSet &locally_owned_domain_indices,
3113 const IndexSet &locally_owned_range_indices)
3114 : use_transpose(use_transpose)
3115 , communicator(mpi_communicator)
3116 , domain_map(
3117 locally_owned_domain_indices.make_trilinos_map(communicator.Comm()))
3118 , range_map(
3119 locally_owned_range_indices.make_trilinos_map(communicator.Comm()))
3120 {
3121 vmult = [&op](Range &tril_dst, const Domain &tril_src) {
3122 // Duplicated from TrilinosWrappers::PreconditionBase::vmult
3123 // as well as from TrilinosWrappers::SparseMatrix::Tvmult
3124 Assert(&tril_src != &tril_dst,
3127 tril_src,
3128 tril_dst,
3129 op.UseTranspose());
3130
3131 const int ierr = op.Apply(tril_src, tril_dst);
3132 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
3133 };
3134
3135 Tvmult = [&op](Domain &tril_dst, const Range &tril_src) {
3136 // Duplicated from TrilinosWrappers::PreconditionBase::vmult
3137 // as well as from TrilinosWrappers::SparseMatrix::Tvmult
3138 Assert(&tril_src != &tril_dst,
3141 tril_src,
3142 tril_dst,
3143 !op.UseTranspose());
3144
3145 op.SetUseTranspose(!op.UseTranspose());
3146 const int ierr = op.Apply(tril_src, tril_dst);
3147 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
3148 op.SetUseTranspose(!op.UseTranspose());
3149 };
3150
3151 if (supports_inverse_operations)
3152 {
3153 inv_vmult = [&op](Domain &tril_dst, const Range &tril_src) {
3154 // Duplicated from TrilinosWrappers::PreconditionBase::vmult
3155 // as well as from TrilinosWrappers::SparseMatrix::Tvmult
3156 Assert(
3157 &tril_src != &tril_dst,
3160 tril_src,
3161 tril_dst,
3162 !op.UseTranspose());
3163
3164 const int ierr = op.ApplyInverse(tril_src, tril_dst);
3165 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
3166 };
3167
3168 inv_Tvmult = [&op](Range &tril_dst, const Domain &tril_src) {
3169 // Duplicated from TrilinosWrappers::PreconditionBase::vmult
3170 // as well as from TrilinosWrappers::SparseMatrix::Tvmult
3171 Assert(
3172 &tril_src != &tril_dst,
3175 tril_src,
3176 tril_dst,
3177 op.UseTranspose());
3178
3179 op.SetUseTranspose(!op.UseTranspose());
3180 const int ierr = op.ApplyInverse(tril_src, tril_dst);
3181 AssertThrow(ierr == 0, ExcTrilinosError(ierr));
3182 op.SetUseTranspose(!op.UseTranspose());
3183 };
3184 }
3185 else
3186 {
3187 inv_vmult = [](Domain &, const Range &) {
3188 Assert(false,
3189 ExcMessage(
3190 "Uninitialized TrilinosPayload::inv_vmult called. "
3191 "The operator does not support inverse operations."));
3192 };
3193
3194 inv_Tvmult = [](Range &, const Domain &) {
3195 Assert(false,
3196 ExcMessage(
3197 "Uninitialized TrilinosPayload::inv_Tvmult called. "
3198 "The operator does not support inverse operations."));
3199 };
3200 }
3201 }
3202
3203
3204 template <typename Solver, typename Preconditioner>
3205 std::enable_if_t<
3206 std::is_base_of_v<TrilinosWrappers::SolverBase, Solver> &&
3207 std::is_base_of_v<TrilinosWrappers::PreconditionBase, Preconditioner>,
3208 TrilinosPayload>
3210 Solver &solver,
3211 const Preconditioner &preconditioner) const
3212 {
3213 const auto &payload = *this;
3214
3215 TrilinosPayload return_op(payload);
3216
3217 // Capture by copy so the payloads are always valid
3218
3219 return_op.inv_vmult = [payload, &solver, &preconditioner](
3220 TrilinosPayload::Domain &tril_dst,
3221 const TrilinosPayload::Range &tril_src) {
3222 // Duplicated from TrilinosWrappers::PreconditionBase::vmult
3223 // as well as from TrilinosWrappers::SparseMatrix::Tvmult
3224 Assert(&tril_src != &tril_dst,
3227 tril_src,
3228 tril_dst,
3229 !payload.UseTranspose());
3230 solver.solve(payload, tril_dst, tril_src, preconditioner);
3231 };
3232
3233 return_op.inv_Tvmult = [payload, &solver, &preconditioner](
3234 TrilinosPayload::Range &tril_dst,
3235 const TrilinosPayload::Domain &tril_src) {
3236 // Duplicated from TrilinosWrappers::PreconditionBase::vmult
3237 // as well as from TrilinosWrappers::SparseMatrix::Tvmult
3238 Assert(&tril_src != &tril_dst,
3241 tril_src,
3242 tril_dst,
3243 payload.UseTranspose());
3244
3245 const_cast<TrilinosPayload &>(payload).transpose();
3246 solver.solve(payload, tril_dst, tril_src, preconditioner);
3247 const_cast<TrilinosPayload &>(payload).transpose();
3248 };
3249
3250 // If the input operator is already setup for transpose operations, then
3251 // we must do similar with its inverse.
3252 if (return_op.UseTranspose() == true)
3253 std::swap(return_op.inv_vmult, return_op.inv_Tvmult);
3254
3255 return return_op;
3256 }
3257
3258 template <typename Solver, typename Preconditioner>
3259 std::enable_if_t<
3260 !(std::is_base_of_v<TrilinosWrappers::SolverBase, Solver> &&
3261 std::is_base_of_v<TrilinosWrappers::PreconditionBase,
3262 Preconditioner>),
3263 TrilinosPayload>
3264 TrilinosPayload::inverse_payload(Solver &, const Preconditioner &) const
3265 {
3266 TrilinosPayload return_op(*this);
3267
3268 return_op.inv_vmult = [](TrilinosPayload::Domain &,
3269 const TrilinosPayload::Range &) {
3270 AssertThrow(false,
3271 ExcMessage("Payload inv_vmult disabled because of "
3272 "incompatible solver/preconditioner choice."));
3273 };
3274
3275 return_op.inv_Tvmult = [](TrilinosPayload::Range &,
3276 const TrilinosPayload::Domain &) {
3277 AssertThrow(false,
3278 ExcMessage("Payload inv_vmult disabled because of "
3279 "incompatible solver/preconditioner choice."));
3280 };
3281
3282 return return_op;
3283 }
3284 } // namespace LinearOperatorImplementation
3285 } // namespace internal
3286
3287 template <>
3288 void SparseMatrix::set<TrilinosScalar>(const size_type row,
3289 const size_type n_cols,
3290 const size_type *col_indices,
3291 const TrilinosScalar *values,
3292 const bool elide_zero_values);
3293# endif // DOXYGEN
3294
3295} /* namespace TrilinosWrappers */
3296
3297#endif
3298
3300
3301#endif
3302/*----------------------- 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