15#ifndef dealii_trilinos_tpetra_sparsity_pattern_h
16#define dealii_trilinos_tpetra_sparsity_pattern_h
24#ifdef DEAL_II_TRILINOS_WITH_TPETRA
33# include <Tpetra_CrsGraph.hpp>
48 namespace TpetraWrappers
50 template <
typename MemorySpace>
53 template <
typename Number,
typename MemorySpace>
58 template <
typename MemorySpace>
67 namespace TpetraWrappers
82 template <
typename MemorySpace = ::MemorySpace::Host>
128 <<
"You tried to access row " << arg1
129 <<
" of a distributed sparsity pattern, "
130 <<
" but only rows " << arg2 <<
" through " << arg3
131 <<
" are stored locally and can be accessed.");
161 std::shared_ptr<std::vector<::types::signed_global_dof_index>>
181 template <
typename MemorySpace = ::MemorySpace::Host>
254 <<
"Attempt to access element " << arg2 <<
" of row "
255 << arg1 <<
" which doesn't have that many elements.");
286 template <
typename MemorySpace = ::MemorySpace::Host>
336 const std::vector<size_type> &n_entries_per_row);
383 const std::vector<size_type> &n_entries_per_row);
397 template <
typename SparsityPatternType>
399 copy_from(
const SparsityPatternType &nontrilinos_sparsity_pattern);
450 const MPI_Comm communicator = MPI_COMM_WORLD,
465 const std::vector<size_type> &n_entries_per_row);
482 const IndexSet &col_parallel_partitioning,
483 const MPI_Comm communicator = MPI_COMM_WORLD,
498 const IndexSet &col_parallel_partitioning,
500 const std::vector<size_type> &n_entries_per_row);
529 const IndexSet &col_parallel_partitioning,
531 const MPI_Comm communicator = MPI_COMM_WORLD,
551 const MPI_Comm communicator = MPI_COMM_WORLD,
567 const std::vector<size_type> &n_entries_per_row);
587 const IndexSet &col_parallel_partitioning,
588 const MPI_Comm communicator = MPI_COMM_WORLD,
618 const IndexSet &col_parallel_partitioning,
620 const MPI_Comm communicator = MPI_COMM_WORLD,
629 const IndexSet &col_parallel_partitioning,
631 const std::vector<size_type> &n_entries_per_row);
642 template <
typename SparsityPatternType>
645 const IndexSet &col_parallel_partitioning,
646 const SparsityPatternType &nontrilinos_sparsity_pattern,
647 const MPI_Comm communicator = MPI_COMM_WORLD,
648 const bool exchange_data =
false);
658 template <
typename SparsityPatternType>
661 const SparsityPatternType &nontrilinos_sparsity_pattern,
662 const MPI_Comm communicator = MPI_COMM_WORLD,
663 const bool exchange_data =
false);
703 std::pair<size_type, size_type>
782 template <
typename ForwardIterator>
785 ForwardIterator
begin,
787 const bool indices_are_sorted =
false);
791 const ::types::global_dof_index &row,
793 const bool indices_are_sorted =
false)
override;
807 Teuchos::RCP<TpetraTypes::GraphType<MemorySpace>>
816 Teuchos::RCP<const TpetraTypes::MapType<MemorySpace>>
825 Teuchos::RCP<const TpetraTypes::MapType<MemorySpace>>
837 Teuchos::RCP<const Teuchos::Comm<int>>
918 print(std::ostream &out,
919 const bool write_extended_trilinos_info =
false)
const;
948 <<
"An error with error number " << arg1
949 <<
" occurred while calling a Trilinos function");
957 <<
"The entry with index <" << arg1 <<
',' << arg2
958 <<
"> does not exist.");
968 <<
"You tried to access element (" << arg1 <<
'/' << arg2
970 <<
" of a distributed matrix, but only rows in range ["
971 << arg3 <<
',' << arg4
972 <<
"] are stored locally and can be accessed.");
980 <<
"You tried to access element (" << arg1 <<
'/' << arg2
981 <<
')' <<
" of a sparse matrix, but it appears to not"
982 <<
" exist in the Trilinos sparsity pattern.");
996 Teuchos::RCP<TpetraTypes::GraphType<MemorySpace>>
graph;
1021 template <
typename MemorySpace>
1024 const size_type row,
1025 const size_type index)
1030 visit_present_row();
1035 template <
typename MemorySpace>
1036 inline typename Accessor<MemorySpace>::size_type
1037 Accessor<MemorySpace>::row()
const
1039 Assert(a_row < sparsity_pattern->n_rows(),
1040 ExcBeyondEndOfSparsityPattern());
1046 template <
typename MemorySpace>
1047 inline typename Accessor<MemorySpace>::size_type
1048 Accessor<MemorySpace>::column()
const
1050 Assert(a_row < sparsity_pattern->n_rows(),
1051 ExcBeyondEndOfSparsityPattern());
1052 return (*colnum_cache)[a_index];
1057 template <
typename MemorySpace>
1058 inline typename Accessor<MemorySpace>::size_type
1059 Accessor<MemorySpace>::index()
const
1061 Assert(a_row < sparsity_pattern->n_rows(),
1062 ExcBeyondEndOfSparsityPattern());
1068 template <
typename MemorySpace>
1069 inline Iterator<MemorySpace>::Iterator(
1071 const size_type row,
1072 const size_type index)
1073 : accessor(sp, row,
index)
1078 template <
typename MemorySpace>
1079 inline Iterator<MemorySpace>::Iterator(
const Iterator<MemorySpace> &) =
1084 template <
typename MemorySpace>
1085 inline Iterator<MemorySpace> &
1086 Iterator<MemorySpace>::operator++()
1088 Assert(accessor.a_row < accessor.sparsity_pattern->n_rows(),
1095 if (accessor.a_index >=
1097 accessor.colnum_cache->size()))
1099 accessor.a_index = 0;
1102 while (accessor.a_row <
1104 accessor.sparsity_pattern->n_rows()))
1106 const auto row_length =
1107 accessor.sparsity_pattern->row_length(accessor.a_row);
1108 if (row_length == 0 ||
1109 !accessor.sparsity_pattern->row_is_stored_locally(
1116 accessor.visit_present_row();
1123 template <
typename MemorySpace>
1124 inline Iterator<MemorySpace>
1125 Iterator<MemorySpace>::operator++(
int)
1127 const Iterator<MemorySpace> old_state = *
this;
1134 template <
typename MemorySpace>
1135 inline const Accessor<MemorySpace> &
1136 Iterator<MemorySpace>::operator*()
const
1143 template <
typename MemorySpace>
1144 inline const Accessor<MemorySpace> *
1145 Iterator<MemorySpace>::operator->()
const
1152 template <
typename MemorySpace>
1154 Iterator<MemorySpace>::operator==(
1155 const Iterator<MemorySpace> &other)
const
1157 return (accessor.a_row == other.accessor.a_row &&
1158 accessor.a_index == other.accessor.a_index);
1163 template <
typename MemorySpace>
1165 Iterator<MemorySpace>::operator!=(
1166 const Iterator<MemorySpace> &other)
const
1168 return !(*
this == other);
1173 template <
typename MemorySpace>
1175 Iterator<MemorySpace>::operator<(
const Iterator<MemorySpace> &other)
const
1177 return (accessor.row() < other.accessor.row() ||
1178 (accessor.row() == other.accessor.row() &&
1179 accessor.index() < other.accessor.index()));
1186 template <
typename MemorySpace>
1191 return const_iterator(
this, first_valid_row, 0);
1196 template <
typename MemorySpace>
1200 return const_iterator(
this, n_rows(), 0);
1205 template <
typename MemorySpace>
1210 if (row_length(r) > 0)
1211 return const_iterator(
this, r, 0);
1218 template <
typename MemorySpace>
1227 for (size_type i = r + 1; i < n_rows(); ++i)
1228 if (row_length(i) > 0)
1229 return const_iterator(
this, i, 0);
1238 template <
typename MemorySpace>
1243 graph->getRowMap()->getMinGlobalIndex();
1245 graph->getRowMap()->getMaxGlobalIndex() + 1;
1247 return ((index >=
static_cast<size_type>(begin)) &&
1253 template <
typename MemorySpace>
1257 return graph->isFillComplete();
1262 template <
typename MemorySpace>
1266 return ((n_rows() == 0) && (n_cols() == 0));
1271 template <
typename MemorySpace>
1275 add_entries(i, &j, &j + 1);
1280 template <
typename MemorySpace>
1281 template <
typename ForwardIterator>
1284 ForwardIterator begin,
1285 ForwardIterator end,
1304 const_cast<std::decay_t<decltype(*
begin)
> *>(&*
begin));
1308 const_cast<std::decay_t<decltype(*
end)
> *>(&*
end));
1318 Teuchos::Array<TrilinosWrappers::types::int_type> array(
1319 col_index_ptr_begin, col_index_ptr_end);
1321 if (row_is_stored_locally(row))
1322 graph->insertGlobalIndices(trilinos_row_index, array());
1323 else if (nonlocal_graph.get() !=
nullptr)
1328 Assert(nonlocal_graph->getRowMap()->getLocalElement(row) !=
1329 Teuchos::OrdinalTraits<
1331 ExcMessage(
"Attempted to write into off-processor matrix row "
1332 "that has not be specified as being writable upon "
1334 nonlocal_graph->insertGlobalIndices(trilinos_row_index, array);
1337 graph->insertGlobalIndices(trilinos_row_index, array);
1342 template <
typename MemorySpace>
1343 inline Teuchos::RCP<Tpetra::CrsGraph<
int,
1345 TpetraTypes::NodeType<MemorySpace>>>
1353 template <
typename MemorySpace>
1357 return IndexSet(graph->getDomainMap().getConst());
1362 template <
typename MemorySpace>
1366 return IndexSet(graph->getRangeMap().getConst());
Accessor(const SparsityPattern< MemorySpace > *sparsity_pattern, const size_type row, const size_type index)
std::shared_ptr< std::vector<::types::signed_global_dof_index > > colnum_cache
SparsityPattern< MemorySpace > * sparsity_pattern
Iterator< MemorySpace > & operator++()
Iterator(const Iterator< MemorySpace > &i)
Iterator(const SparsityPattern< MemorySpace > *sparsity_pattern, const size_type row, const size_type index)
const Accessor< MemorySpace > * operator->() const
Accessor< MemorySpace > accessor
bool operator!=(const Iterator< MemorySpace > &) const
bool operator<(const Iterator< MemorySpace > &) const
bool operator==(const Iterator< MemorySpace > &) const
const Accessor< MemorySpace > & operator*() const
Teuchos::RCP< TpetraTypes::GraphType< MemorySpace > > graph
Teuchos::RCP< const Teuchos::Comm< int > > get_teuchos_mpi_communicator() const
std::pair< size_type, size_type > local_range() const
Teuchos::RCP< const TpetraTypes::MapType< MemorySpace > > range_partitioner() const
IndexSet locally_owned_range_indices() const
Teuchos::RCP< TpetraTypes::GraphType< MemorySpace > > trilinos_sparsity_pattern() const
void copy_from(const SparsityPattern< MemorySpace > &input_sparsity_pattern)
SparsityPattern< MemorySpace > & operator=(const SparsityPattern< MemorySpace > &input_sparsity_pattern)
void print(std::ostream &out, const bool write_extended_trilinos_info=false) const
unsigned int max_entries_per_row() const
Teuchos::RCP< TpetraTypes::GraphType< MemorySpace > > nonlocal_graph
const_iterator end() const
void print_gnuplot(std::ostream &out) const
IndexSet locally_owned_domain_indices() const
bool is_compressed() const
MPI_Comm get_mpi_communicator() const
Teuchos::RCP< const TpetraTypes::MapType< MemorySpace > > domain_partitioner() const
std::uint64_t n_nonzero_elements() const
const_iterator end(const size_type r) const
size_type bandwidth() const
bool exists(const size_type i, const size_type j) const
void add_entries(const size_type row, ForwardIterator begin, ForwardIterator end, const bool indices_are_sorted=false)
Teuchos::RCP< TpetraTypes::MapType< MemorySpace > > column_space_map
unsigned int local_size() const
virtual void add_row_entries(const ::types::global_dof_index &row, const ArrayView< const ::types::global_dof_index > &columns, const bool indices_are_sorted=false) override
void add(const size_type i, const size_type j)
const_iterator begin() const
const_iterator begin(const size_type r) const
virtual ~SparsityPattern() override=default
size_type row_length(const size_type row) const
bool in_local_range(const size_type index) const
std::size_t memory_consumption() const
bool row_is_stored_locally(const size_type i) const
void reinit(const size_type m, const size_type n, const size_type n_entries_per_row=0)
virtual void add_entries(const ArrayView< const std::pair< size_type, size_type > > &entries)
void add_entries(const size_type row, ForwardIterator begin, ForwardIterator end, const bool indices_are_sorted=false)
bool is_compressed() const
void add(const size_type i, const size_type j)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcTrilinosError(int arg1)
#define DeclException0(Exception0)
static ::ExceptionBase & ExcAccessToNonPresentElement(size_type arg1, size_type arg2)
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
static ::ExceptionBase & ExcAccessToNonLocalElement(size_type arg1, size_type arg2, size_type arg3, size_type arg4)
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
static ::ExceptionBase & ExcIteratorPastEnd()
#define DeclException2(Exception2, type1, type2, outsequence)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcBeyondEndOfSparsityPattern()
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcAccessToNonlocalRow(size_type arg1, size_type arg2, size_type arg3)
#define DeclException3(Exception3, type1, type2, type3, outsequence)
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 & ExcMessage(std::string arg1)
std::pair< types::global_dof_index, types::global_dof_index > local_range
types::global_dof_index size_type
VectorType::value_type * end(VectorType &V)
VectorType::value_type * begin(VectorType &V)
int signed_global_dof_index
unsigned int global_dof_index