13#ifndef dealii_trilinos_tpetra_sparse_matrix_h
14#define dealii_trilinos_tpetra_sparse_matrix_h
18#ifdef DEAL_II_TRILINOS_WITH_TPETRA
31# include <Tpetra_Core.hpp>
32# include <Tpetra_CrsMatrix.hpp>
34# include <type_traits>
40#ifdef DEAL_II_TRILINOS_WITH_TPETRA
43template <
typename Number>
47template <
typename MatrixType>
54 template <
typename MemorySpace>
59 template <
typename Number,
typename MemorySpace,
bool Constness>
109 template <
typename Number,
typename MemorySpace = ::MemorySpace::Host>
123 <<
"You tried to access row " << arg1
124 <<
" of a non-contiguous locally owned row set."
125 <<
" The row " << arg1
126 <<
" is not stored locally and can't be accessed.");
185 const unsigned int n_max_entries_per_row);
196 const std::vector<unsigned int> &n_entries_per_row);
242 template <
typename SparsityPatternType>
244 reinit(
const SparsityPatternType &sparsity_pattern);
290 const unsigned int n_max_entries_per_row);
302 const std::vector<unsigned int> &n_entries_per_row);
319 const IndexSet &col_parallel_partitioning,
332 const IndexSet &col_parallel_partitioning,
334 const std::vector<unsigned int> &n_entries_per_row);
355 template <
typename SparsityPatternType>
357 !std::is_same_v<SparsityPatternType, ::SparseMatrix<double>>>
359 const SparsityPatternType &sparsity_pattern,
360 const MPI_Comm communicator = MPI_COMM_WORLD,
361 const bool exchange_data =
false);
375 template <
typename SparsityPatternType>
377 !std::is_same_v<SparsityPatternType, ::SparseMatrix<double>>>
379 const IndexSet &col_parallel_partitioning,
380 const SparsityPatternType &sparsity_pattern,
381 const MPI_Comm communicator = MPI_COMM_WORLD,
382 const bool exchange_data =
false);
402 const IndexSet &col_parallel_partitioning,
403 const ::SparseMatrix<Number> &dealii_sparse_matrix,
404 const MPI_Comm communicator = MPI_COMM_WORLD,
405 const double drop_tolerance = 1e-13,
406 const bool copy_values =
true,
407 const ::SparsityPattern *use_this_sparsity =
nullptr);
447 std::pair<size_type, size_type>
557 const Number *values,
558 const bool elide_zero_values =
true,
559 const bool col_indices_are_sorted =
false);
628 set(
const std::vector<size_type> &indices,
630 const bool elide_zero_values =
false);
638 set(
const std::vector<size_type> &row_indices,
639 const std::vector<size_type> &col_indices,
641 const bool elide_zero_values =
false);
672 const std::vector<size_type> &col_indices,
673 const std::vector<Number> &values,
674 const bool elide_zero_values =
false);
703 template <
typename OtherNumber>
708 const OtherNumber *values,
709 const bool elide_zero_values =
false);
762 const Number new_diag_value = 0);
834 template <
typename InputVectorType>
836 vmult(InputVectorType &dst,
const InputVectorType &src)
const;
845 template <
typename InputVectorType>
847 Tvmult(InputVectorType &dst,
const InputVectorType &src)
const;
855 template <
typename InputVectorType>
857 vmult_add(InputVectorType &dst,
const InputVectorType &src)
const;
866 template <
typename InputVectorType>
868 Tvmult_add(InputVectorType &dst,
const InputVectorType &src)
const;
988 const bool print_detailed_trilinos_information =
false)
const;
1060 Teuchos::RCP<const TpetraTypes::MatrixType<Number, MemorySpace>>
1072 Teuchos::RCP<TpetraTypes::MatrixType<Number, MemorySpace>>
1214 "You are attempting an operation on two vectors that "
1215 "are the same object, but the operation requires that the "
1216 "two objects are in fact different.");
1222 "The column partitioning of a matrix does not match "
1223 "the partitioning of a vector you are trying to "
1224 "multiply it with. Are you multiplying the "
1225 "matrix with a vector that has ghost elements?");
1231 "The row partitioning of a matrix does not match "
1232 "the partitioning of a vector you are trying to "
1233 "put the result of a matrix-vector product in. "
1234 "Are you trying to put the product of the "
1235 "matrix with a vector into a vector that has "
1244 <<
"The entry with index <" << arg1 <<
',' << arg2
1245 <<
"> does not exist.");
1255 <<
"You tried to access element (" << arg1 <<
'/' << arg2
1257 <<
" of a distributed matrix, but only rows in range ["
1258 << arg3 <<
',' << arg4
1259 <<
"] are stored locally and can be accessed.");
1286 Teuchos::RCP<TpetraTypes::MatrixType<Number, MemorySpace>>
matrix;
1340 template <
typename Number,
typename MemorySpace>
1412 std::shared_ptr<std::vector<::types::signed_global_dof_index>>
1435 template <
typename Number,
typename MemorySpace,
bool Constness>
1454 template <
typename Number,
typename MemorySpace>
1482 template <
bool Other>
1495 template <
typename Number,
typename MemorySpace>
1510 operator Number()
const;
1594 template <
typename Number,
typename MemorySpace,
bool Constness>
1633 template <
bool Other>
1664 template <
bool OtherConstness>
1671 template <
bool OtherConstness>
1680 template <
bool OtherConstness>
1687 template <
bool OtherConstness>
1697 <<
"Attempt to access element " << arg2 <<
" of row "
1698 << arg1 <<
" which doesn't have that many elements.");
1720 template <
typename Number,
typename MemorySpace,
bool Constness>
1723 Iterator<Number, MemorySpace, Constness>>
1727 typename ::LinearAlgebra::TpetraWrappers::SparseMatrixIterators::
1728 Iterator<Number, MemorySpace, Constness>::value_type;
1730 typename ::LinearAlgebra::TpetraWrappers::SparseMatrixIterators::
1731 Iterator<Number, MemorySpace, Constness>::difference_type;
1742 namespace TpetraWrappers
1744 template <
typename Number,
typename MemorySpace>
1755 template <
typename Number,
typename MemorySpace>
1766 template <
typename Number,
typename MemorySpace>
1782 template <
typename Number,
typename MemorySpace>
1786 return matrix->getRowMap()->getGlobalNumElements();
1791 template <
typename Number,
typename MemorySpace>
1804 template <
typename Number,
typename MemorySpace>
1809 sizeof(*this) +
sizeof(*matrix) +
sizeof(
matrix->getGraph().get());
1812 matrix->getLocalNumEntries() +
1814 matrix->getNodeNumEntries() +
1821 template <
typename Number,
typename MemorySpace>
1830 template <
typename Number,
typename MemorySpace>
1839 template <
typename Number,
typename MemorySpace>
1848 template <
typename Number,
typename MemorySpace>
1860 template <
typename Number,
typename MemorySpace>
1880 template <
typename Number,
typename MemorySpace>
1889 template <
typename Number,
typename MemorySpace>
1898 template <
typename Number,
typename MemorySpace>
1911 template <
typename Number,
typename MemorySpace>
1931 template <
typename Number,
typename MemorySpace>
1939 return ((index >=
begin) && (index <
end));
1944 template <
typename Number,
typename MemorySpace>
1948 auto n_entries =
matrix->getNumEntriesInGlobalRow(row);
1950 Teuchos::OrdinalTraits<
decltype(n_entries)>::invalid(),
1958 template <
typename Number,
typename MemorySpace>
1967 template <
typename Number,
typename MemorySpace>
1976 template <
typename Number,
typename MemorySpace>
1985 template <
typename Number,
typename MemorySpace>
1994 template <
typename Number,
typename MemorySpace>
1995 inline Teuchos::RCP<const TpetraTypes::MatrixType<Number, MemorySpace>>
1998 return matrix.getConst();
2003 template <
typename Number,
typename MemorySpace>
2004 inline Teuchos::RCP<TpetraTypes::MatrixType<Number, MemorySpace>>
2012 template <
typename Number,
typename MemorySpace>
2021 template <
typename Number,
typename MemorySpace>
2031 template <
typename Number,
typename MemorySpace>
2044 template <
typename Number,
typename MemorySpace>
2053 template <
typename Number,
typename MemorySpace>
2062 template <
typename Number,
typename MemorySpace>
2072 template <
typename Number,
typename MemorySpace>
2083 (
matrix->in_local_range(this->a_row) ==
false))
2097 value_cache = std::make_shared<std::vector<Number>>(colnums);
2099 std::vector<::types::signed_global_dof_index>>(colnums);
2108 nonconst_global_inds_host_view_type col_indices(
colnum_cache->data(),
2111 nonconst_values_host_view_type values(
value_cache->data(), colnums);
2113 matrix->trilinos_matrix().getGlobalRowCopy(this->
a_row,
2130 template <
typename Number,
typename MemorySpace>
2143 template <
typename Number,
typename MemorySpace>
2144 template <
bool Other>
2152 template <
typename Number,
typename MemorySpace>
2165 template <
typename Number,
typename MemorySpace>
2173 template <
typename Number,
typename MemorySpace>
2182 template <
typename Number,
typename MemorySpace>
2185 const Number n)
const
2190 static_cast<Number
>(*
this));
2196 template <
typename Number,
typename MemorySpace>
2199 const Number n)
const
2204 static_cast<Number
>(*
this));
2210 template <
typename Number,
typename MemorySpace>
2213 const Number n)
const
2218 static_cast<Number
>(*
this));
2223 template <
typename Number,
typename MemorySpace>
2226 const Number n)
const
2231 static_cast<Number
>(*
this));
2236 template <
typename Number,
typename MemorySpace>
2239 const Number n)
const
2244 static_cast<Number
>(*
this));
2249 template <
typename Number,
typename MemorySpace>
2258 template <
typename Number,
typename MemorySpace>
2270 template <
typename Number,
typename MemorySpace,
bool Constness>
2279 template <
typename Number,
typename MemorySpace,
bool Constness>
2280 template <
bool Other>
2288 template <
typename Number,
typename MemorySpace,
bool Constness>
2317 template <
typename Number,
typename MemorySpace,
bool Constness>
2328 template <
typename Number,
typename MemorySpace,
bool Constness>
2337 template <
typename Number,
typename MemorySpace,
bool Constness>
2346 template <
typename Number,
typename MemorySpace,
bool Constness>
2347 template <
bool OtherConstness>
2358 template <
typename Number,
typename MemorySpace,
bool Constness>
2359 template <
bool OtherConstness>
2364 return !(*
this == other);
2369 template <
typename Number,
typename MemorySpace,
bool Constness>
2370 template <
bool OtherConstness>
2381 template <
typename Number,
typename MemorySpace,
bool Constness>
2382 template <
bool OtherConstness>
2387 return (other < *
this);
*Â *Â const_iterator()=default
*Â x_component_mask set(0, true)
SparseMatrix< Number, MemorySpace > * matrix
std::shared_ptr< std::vector< Number > > value_cache
std::shared_ptr< std::vector<::types::signed_global_dof_index > > colnum_cache
AccessorBase(SparseMatrix< Number, MemorySpace > *matrix, const size_type row, const size_type index)
::types::global_dof_index size_type
const Reference & operator=(const Number n) const
const Reference & operator+=(const Number n) const
Reference(const Accessor< Number, MemorySpace, false > &accessor)
const Reference & operator*=(const Number n) const
const Reference & operator/=(const Number n) const
const Reference & operator-=(const Number n) const
SparseMatrix< Number, MemorySpace > MatrixType
Accessor(MatrixType *matrix, const size_type row, const size_type index)
typename AccessorBase< Number, MemorySpace >::size_type size_type
typename AccessorBase< Number, MemorySpace >::size_type size_type
Accessor(MatrixType *matrix, const size_type row, const size_type index)
const SparseMatrix< Number, MemorySpace > MatrixType
Iterator< Number, MemorySpace, Constness > operator++(int)
bool operator!=(const Iterator< Number, MemorySpace, OtherConstness > &) const
bool operator<(const Iterator< Number, MemorySpace, OtherConstness > &) const
bool operator>(const Iterator< Number, MemorySpace, OtherConstness > &) const
::types::global_dof_index size_type
Iterator(MatrixType *matrix, const size_type row, const size_type index)
Accessor< Number, MemorySpace, Constness > accessor
typename Accessor< Number, MemorySpace, Constness >::MatrixType MatrixType
const Accessor< Number, MemorySpace, Constness > * operator->() const
Iterator< Number, MemorySpace, Constness > & operator++()
const Accessor< Number, MemorySpace, Constness > & operator*() const
bool operator==(const Iterator< Number, MemorySpace, OtherConstness > &) const
::types::global_dof_index difference_type
Iterator(const Iterator< Number, MemorySpace, Other > &other)
virtual ~SparseMatrix() override=default
unsigned int row_length(const size_type row) const
SparseMatrix(const SparseMatrix< Number, MemorySpace > &)=delete
void clear_row(const size_type row, const Number new_diag_value=0)
void print(std::ostream &out, const bool print_detailed_trilinos_information=false) const
IndexSet locally_owned_domain_indices() const
::types::global_dof_index size_type
iterator begin(const size_type r)
SparseMatrix< Number, MemorySpace > & operator=(SparseMatrix< Number, MemorySpace > &&other) noexcept
TpetraTypes::MatrixType< Number, MemorySpace > & trilinos_matrix()
void add(const size_type i, const size_type j, const Number value)
void set(const std::vector< size_type > &row_indices, const std::vector< size_type > &col_indices, const FullMatrix< Number > &full_matrix, const bool elide_zero_values=false)
SparseMatrix(SparseMatrix< Number, MemorySpace > &&other) noexcept
void clear_rows(const ArrayView< const size_type > &rows, const Number new_diag_value=0)
const_iterator end() const
void set(const std::vector< size_type > &indices, const FullMatrix< Number > &full_matrix, const bool elide_zero_values=false)
Number residual(Vector< Number, MemorySpace > &dst, const Vector< Number, MemorySpace > &x, const Vector< Number, MemorySpace > &b) const
Number linfty_norm() const
std::pair< size_type, size_type > local_range() const
void set(const size_type row, const std::vector< size_type > &col_indices, const std::vector< Number > &values, const bool elide_zero_values=false)
Number frobenius_norm() const
void Tvmult(InputVectorType &dst, const InputVectorType &src) const
Number matrix_scalar_product(const Vector< Number, MemorySpace > &u, const Vector< Number, MemorySpace > &v) const
Teuchos::RCP< const TpetraTypes::MatrixType< Number, MemorySpace > > trilinos_rcp() const
Teuchos::RCP< TpetraTypes::MatrixType< Number, MemorySpace > > matrix
void reinit(const SparsityPatternType &sparsity_pattern)
SparseMatrix & operator=(const double d)
Number element(const size_type i, const size_type j, const bool no_error) const
SparseMatrix(const size_type m, const size_type n, const unsigned int n_max_entries_per_row)
SparseMatrix & operator/=(const Number factor)
Teuchos::RCP< TpetraTypes::MapType< MemorySpace > > column_space_map
SparseMatrix & operator*=(const Number factor)
bool in_local_range(const size_type index) const
MPI_Comm get_mpi_communicator() const
void add(const size_type row, const size_type n_cols, const size_type *col_indices, const Number *values, const bool elide_zero_values=true, const bool col_indices_are_sorted=false)
const_iterator begin(const size_type r) const
const_iterator begin() const
void set(const size_type row, const size_type n_cols, const size_type *col_indices, const OtherNumber *values, const bool elide_zero_values=false)
SparseMatrix(const IndexSet &row_parallel_partitioning, const IndexSet &col_parallel_partitioning, const MPI_Comm communicator, const std::vector< unsigned int > &n_entries_per_row)
SparseMatrix(const IndexSet ¶llel_partitioning, const MPI_Comm communicator, const unsigned int n_max_entries_per_row)
SparseMatrix(const SparsityPattern< MemorySpace > &sparsity_pattern)
Number diag_element(const size_type i) const
const_iterator end(const size_type r) const
Number operator()(const size_type i, const size_type j) const
void vmult(InputVectorType &dst, const InputVectorType &src) const
SparseMatrix(const size_type m, const size_type n, const std::vector< unsigned int > &n_entries_per_row)
void set(const size_type i, const size_type j, const Number value)
void copy_from(const SparseMatrix< Number, MemorySpace > &source)
iterator end(const size_type r)
SparseMatrix(const IndexSet ¶llel_partitioning, const MPI_Comm communicator, const std::vector< unsigned int > &n_entries_per_row)
std::enable_if_t< !std::is_same_v< SparsityPatternType, ::SparseMatrix< double > > > reinit(const IndexSet &row_parallel_partitioning, const IndexSet &col_parallel_partitioning, const SparsityPatternType &sparsity_pattern, const MPI_Comm communicator=MPI_COMM_WORLD, const bool exchange_data=false)
SparseMatrix(const IndexSet &row_parallel_partitioning, const IndexSet &col_parallel_partitioning, const MPI_Comm communicator, const size_type n_max_entries_per_row)
size_type memory_consumption() const
SparseMatrix< Number, MemorySpace > & operator=(const SparseMatrix< Number, MemorySpace > &)=delete
IndexSet locally_owned_range_indices() const
Teuchos::RCP< TpetraTypes::MatrixType< Number, MemorySpace > > trilinos_rcp()
size_t n_nonzero_elements() const
void Tvmult_add(InputVectorType &dst, const InputVectorType &src) const
void reinit(const SparsityPattern< MemorySpace > &sparsity_pattern)
Number el(const size_type i, const size_type j) const
void vmult_add(InputVectorType &dst, const InputVectorType &src) const
const TpetraTypes::MatrixType< Number, MemorySpace > & trilinos_matrix() const
void compress(VectorOperation::values operation)
std::enable_if_t< !std::is_same_v< SparsityPatternType, ::SparseMatrix< double > > > reinit(const IndexSet ¶llel_partitioning, const SparsityPatternType &sparsity_pattern, const MPI_Comm communicator=MPI_COMM_WORLD, const bool exchange_data=false)
void add(const Number factor, const SparseMatrix< Number, MemorySpace > &matrix)
void reinit(const SparseMatrix< Number, MemorySpace > &matrix)
SparseMatrixIterators::Iterator< Number, MemorySpace, false > iterator
SparseMatrixIterators::Iterator< Number, MemorySpace, true > const_iterator
void reinit(const IndexSet &row_parallel_partitioning, const IndexSet &col_parallel_partitioning, const ::SparseMatrix< Number > &dealii_sparse_matrix, const MPI_Comm communicator=MPI_COMM_WORLD, const double drop_tolerance=1e-13, const bool copy_values=true, const ::SparsityPattern *use_this_sparsity=nullptr)
bool is_compressed() const
Number matrix_norm_square(const Vector< Number, MemorySpace > &v) const
unsigned int local_size() const
real_type l2_norm() const
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_TRILINOS_VERSION_GTE(major, minor, subminor)
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcDomainMapMismatch()
static ::ExceptionBase & ExcColMapMismatch()
#define DeclException0(Exception0)
static ::ExceptionBase & ExcAccessToNonLocalElement(size_type arg1, size_type arg2, size_type arg3, size_type arg4)
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
#define Assert(cond, exc)
static ::ExceptionBase & ExcMatrixNotCompressed()
static ::ExceptionBase & ExcIteratorPastEnd()
static ::ExceptionBase & ExcAccessToNonlocalRow(std::size_t arg1)
#define DeclException2(Exception2, type1, type2, outsequence)
static ::ExceptionBase & ExcBeyondEndOfMatrix()
#define AssertDimension(dim1, dim2)
#define AssertIndexRange(index, range)
#define DeclExceptionMsg(Exception, defaulttext)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcInvalidIndex(size_type arg1, size_type arg2)
#define DeclException1(Exception1, type1, outsequence)
static ::ExceptionBase & ExcInvalidIndexWithinRow(size_type arg1, size_type arg2)
static ::ExceptionBase & ExcSourceEqualsDestination()
const bool IsBlockVector< VectorType >::value
Tpetra::CrsMatrix< Number, LO, GO, NodeType< MemorySpace > > MatrixType
unsigned int global_dof_index
static const bool zero_addition_can_be_elided
forward_iterator_tag iterator_category
typename ::LinearAlgebra::TpetraWrappers::SparseMatrixIterators:: Iterator< Number, MemorySpace, Constness >::value_type value_type
typename ::LinearAlgebra::TpetraWrappers::SparseMatrixIterators:: Iterator< Number, MemorySpace, Constness >::difference_type difference_type