15#ifndef dealii_trilinos_tpetra_sparsity_pattern_h
16#define dealii_trilinos_tpetra_sparsity_pattern_h
24#ifdef DEAL_II_TRILINOS_WITH_TPETRA
34# include <Tpetra_CrsGraph.hpp>
49 namespace TpetraWrappers
51 template <
typename MemorySpace>
54 template <
typename Number,
typename MemorySpace>
59 template <
typename MemorySpace>
68 namespace TpetraWrappers
83 template <
typename MemorySpace = ::MemorySpace::Host>
129 <<
"You tried to access row " << arg1
130 <<
" of a distributed sparsity pattern, "
131 <<
" but only rows " << arg2 <<
" through " << arg3
132 <<
" are stored locally and can be accessed.");
162 std::shared_ptr<std::vector<::types::signed_global_dof_index>>
182 template <
typename MemorySpace = ::MemorySpace::Host>
255 <<
"Attempt to access element " << arg2 <<
" of row "
256 << arg1 <<
" which doesn't have that many elements.");
287 template <
typename MemorySpace = ::MemorySpace::Host>
337 const std::vector<size_type> &n_entries_per_row);
384 const std::vector<size_type> &n_entries_per_row);
398 template <
typename SparsityPatternType>
400 copy_from(
const SparsityPatternType &nontrilinos_sparsity_pattern);
451 const MPI_Comm communicator = MPI_COMM_WORLD,
466 const std::vector<size_type> &n_entries_per_row);
483 const IndexSet &col_parallel_partitioning,
484 const MPI_Comm communicator = MPI_COMM_WORLD,
499 const IndexSet &col_parallel_partitioning,
501 const std::vector<size_type> &n_entries_per_row);
530 const IndexSet &col_parallel_partitioning,
532 const MPI_Comm communicator = MPI_COMM_WORLD,
552 const MPI_Comm communicator = MPI_COMM_WORLD,
568 const std::vector<size_type> &n_entries_per_row);
588 const IndexSet &col_parallel_partitioning,
589 const MPI_Comm communicator = MPI_COMM_WORLD,
619 const IndexSet &col_parallel_partitioning,
621 const MPI_Comm communicator = MPI_COMM_WORLD,
630 const IndexSet &col_parallel_partitioning,
632 const std::vector<size_type> &n_entries_per_row);
643 template <
typename SparsityPatternType>
646 const IndexSet &col_parallel_partitioning,
647 const SparsityPatternType &nontrilinos_sparsity_pattern,
648 const MPI_Comm communicator = MPI_COMM_WORLD,
649 const bool exchange_data =
false);
659 template <
typename SparsityPatternType>
662 const SparsityPatternType &nontrilinos_sparsity_pattern,
663 const MPI_Comm communicator = MPI_COMM_WORLD,
664 const bool exchange_data =
false);
704 std::pair<size_type, size_type>
783 template <
typename ForwardIterator>
786 ForwardIterator
begin,
788 const bool indices_are_sorted =
false);
792 const ::types::global_dof_index &row,
794 const bool indices_are_sorted =
false)
override;
808 Teuchos::RCP<TpetraTypes::GraphType<MemorySpace>>
817 Teuchos::RCP<const TpetraTypes::MapType<MemorySpace>>
826 Teuchos::RCP<const TpetraTypes::MapType<MemorySpace>>
838 Teuchos::RCP<const Teuchos::Comm<int>>
919 print(std::ostream &out,
920 const bool write_extended_trilinos_info =
false)
const;
949 <<
"An error with error number " << arg1
950 <<
" occurred while calling a Trilinos function");
958 <<
"The entry with index <" << arg1 <<
',' << arg2
959 <<
"> does not exist.");
969 <<
"You tried to access element (" << arg1 <<
'/' << arg2
971 <<
" of a distributed matrix, but only rows in range ["
972 << arg3 <<
',' << arg4
973 <<
"] are stored locally and can be accessed.");
981 <<
"You tried to access element (" << arg1 <<
'/' << arg2
982 <<
')' <<
" of a sparse matrix, but it appears to not"
983 <<
" exist in the Trilinos sparsity pattern.");
997 Teuchos::RCP<TpetraTypes::GraphType<MemorySpace>>
graph;
1022 template <
typename MemorySpace>
1025 const size_type row,
1026 const size_type index)
1031 visit_present_row();
1036 template <
typename MemorySpace>
1037 inline typename Accessor<MemorySpace>::size_type
1038 Accessor<MemorySpace>::row()
const
1040 Assert(a_row < sparsity_pattern->n_rows(),
1041 ExcBeyondEndOfSparsityPattern());
1047 template <
typename MemorySpace>
1048 inline typename Accessor<MemorySpace>::size_type
1049 Accessor<MemorySpace>::column()
const
1051 Assert(a_row < sparsity_pattern->n_rows(),
1052 ExcBeyondEndOfSparsityPattern());
1053 return (*colnum_cache)[a_index];
1058 template <
typename MemorySpace>
1059 inline typename Accessor<MemorySpace>::size_type
1060 Accessor<MemorySpace>::index()
const
1062 Assert(a_row < sparsity_pattern->n_rows(),
1063 ExcBeyondEndOfSparsityPattern());
1069 template <
typename MemorySpace>
1070 inline Iterator<MemorySpace>::Iterator(
1072 const size_type row,
1073 const size_type index)
1074 : accessor(sp, row,
index)
1079 template <
typename MemorySpace>
1080 inline Iterator<MemorySpace>::Iterator(
const Iterator<MemorySpace> &) =
1085 template <
typename MemorySpace>
1086 inline Iterator<MemorySpace> &
1087 Iterator<MemorySpace>::operator++()
1089 Assert(accessor.a_row < accessor.sparsity_pattern->n_rows(),
1096 if (accessor.a_index >=
1098 accessor.colnum_cache->size()))
1100 accessor.a_index = 0;
1103 while (accessor.a_row <
1105 accessor.sparsity_pattern->n_rows()))
1107 const auto row_length =
1108 accessor.sparsity_pattern->row_length(accessor.a_row);
1109 if (row_length == 0 ||
1110 !accessor.sparsity_pattern->row_is_stored_locally(
1117 accessor.visit_present_row();
1124 template <
typename MemorySpace>
1125 inline Iterator<MemorySpace>
1126 Iterator<MemorySpace>::operator++(
int)
1128 const Iterator<MemorySpace> old_state = *
this;
1135 template <
typename MemorySpace>
1136 inline const Accessor<MemorySpace> &
1137 Iterator<MemorySpace>::operator*()
const
1144 template <
typename MemorySpace>
1145 inline const Accessor<MemorySpace> *
1146 Iterator<MemorySpace>::operator->()
const
1153 template <
typename MemorySpace>
1155 Iterator<MemorySpace>::operator==(
1156 const Iterator<MemorySpace> &other)
const
1158 return (accessor.a_row == other.accessor.a_row &&
1159 accessor.a_index == other.accessor.a_index);
1164 template <
typename MemorySpace>
1166 Iterator<MemorySpace>::operator!=(
1167 const Iterator<MemorySpace> &other)
const
1169 return !(*
this == other);
1174 template <
typename MemorySpace>
1176 Iterator<MemorySpace>::operator<(
const Iterator<MemorySpace> &other)
const
1178 return (accessor.row() < other.accessor.row() ||
1179 (accessor.row() == other.accessor.row() &&
1180 accessor.index() < other.accessor.index()));
1187 template <
typename MemorySpace>
1191 const size_type first_valid_row = this->local_range().first;
1192 return const_iterator(
this, first_valid_row, 0);
1197 template <
typename MemorySpace>
1201 return const_iterator(
this, n_rows(), 0);
1206 template <
typename MemorySpace>
1211 if (row_length(r) > 0)
1212 return const_iterator(
this, r, 0);
1219 template <
typename MemorySpace>
1228 for (size_type i = r + 1; i < n_rows(); ++i)
1229 if (row_length(i) > 0)
1230 return const_iterator(
this, i, 0);
1239 template <
typename MemorySpace>
1244 graph->getRowMap()->getMinGlobalIndex();
1246 graph->getRowMap()->getMaxGlobalIndex() + 1;
1248 return ((index >=
static_cast<size_type>(begin)) &&
1254 template <
typename MemorySpace>
1258 return graph->isFillComplete();
1263 template <
typename MemorySpace>
1267 return ((n_rows() == 0) && (n_cols() == 0));
1272 template <
typename MemorySpace>
1276 add_entries(i, &j, &j + 1);
1281 template <
typename MemorySpace>
1282 template <
typename ForwardIterator>
1285 ForwardIterator begin,
1286 ForwardIterator end,
1305 const_cast<std::decay_t<decltype(*
begin)
> *>(&*
begin));
1309 const_cast<std::decay_t<decltype(*
end)
> *>(&*
end));
1319 Teuchos::Array<TrilinosWrappers::types::int_type> array(
1320 col_index_ptr_begin, col_index_ptr_end);
1322 if (row_is_stored_locally(row))
1323 graph->insertGlobalIndices(trilinos_row_index, array());
1324 else if (nonlocal_graph.get() !=
nullptr)
1329 Assert(nonlocal_graph->getRowMap()->getLocalElement(row) !=
1330 Teuchos::OrdinalTraits<
1332 ExcMessage(
"Attempted to write into off-processor matrix row "
1333 "that has not be specified as being writable upon "
1335 nonlocal_graph->insertGlobalIndices(trilinos_row_index, array);
1338 graph->insertGlobalIndices(trilinos_row_index, array);
1343 template <
typename MemorySpace>
1344 inline Teuchos::RCP<Tpetra::CrsGraph<
int,
1346 TpetraTypes::NodeType<MemorySpace>>>
1354 template <
typename MemorySpace>
1358 return IndexSet(graph->getDomainMap().getConst());
1363 template <
typename MemorySpace>
1367 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)
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