15#ifndef dealii_trilinos_sparsity_pattern_h
16#define dealii_trilinos_sparsity_pattern_h
20#ifdef DEAL_II_WITH_TRILINOS
30# include <Epetra_FECrsGraph.h>
31# include <Epetra_Map.h>
32# include <Epetra_MpiComm.h>
118 <<
"You tried to access row " << arg1
119 <<
" of a distributed sparsity pattern, "
120 <<
" but only rows " << arg2 <<
" through " << arg3
121 <<
" are stored locally and can be accessed.");
242 <<
"Attempt to access element " << arg2 <<
" of row "
243 << arg1 <<
" which doesn't have that many elements.");
324 const std::vector<size_type> &n_entries_per_row);
370 const std::vector<size_type> &n_entries_per_row);
384 template <
typename SparsityPatternType>
386 copy_from(
const SparsityPatternType &nontrilinos_sparsity_pattern);
437 const MPI_Comm communicator = MPI_COMM_WORLD,
452 const std::vector<size_type> &n_entries_per_row);
469 const IndexSet &col_parallel_partitioning,
470 const MPI_Comm communicator = MPI_COMM_WORLD,
485 const IndexSet &col_parallel_partitioning,
487 const std::vector<size_type> &n_entries_per_row);
516 const IndexSet &col_parallel_partitioning,
518 const MPI_Comm communicator = MPI_COMM_WORLD,
538 const MPI_Comm communicator = MPI_COMM_WORLD,
554 const std::vector<size_type> &n_entries_per_row);
574 const IndexSet &col_parallel_partitioning,
575 const MPI_Comm communicator = MPI_COMM_WORLD,
605 const IndexSet &col_parallel_partitioning,
607 const MPI_Comm communicator = MPI_COMM_WORLD,
616 const IndexSet &col_parallel_partitioning,
618 const std::vector<size_type> &n_entries_per_row);
629 template <
typename SparsityPatternType>
632 const IndexSet &col_parallel_partitioning,
633 const SparsityPatternType &nontrilinos_sparsity_pattern,
634 const MPI_Comm communicator = MPI_COMM_WORLD,
635 const bool exchange_data =
false);
645 template <
typename SparsityPatternType>
648 const SparsityPatternType &nontrilinos_sparsity_pattern,
649 const MPI_Comm communicator = MPI_COMM_WORLD,
650 const bool exchange_data =
false);
690 std::pair<size_type, size_type>
769 template <
typename ForwardIterator>
772 ForwardIterator
begin,
774 const bool indices_are_sorted =
false);
779 const bool indices_are_sorted =
false)
override;
793 const Epetra_FECrsGraph &
906 print(std::ostream &out,
907 const bool write_extended_trilinos_info =
false)
const;
936 <<
"An error with error number " << arg1
937 <<
" occurred while calling a Trilinos function");
945 <<
"The entry with index <" << arg1 <<
',' << arg2
946 <<
"> does not exist.");
956 <<
"You tried to access element (" << arg1 <<
'/' << arg2
958 <<
" of a distributed matrix, but only rows in range ["
959 << arg3 <<
',' << arg4
960 <<
"] are stored locally and can be accessed.");
968 <<
"You tried to access element (" << arg1 <<
'/' << arg2
969 <<
')' <<
" of a sparse matrix, but it appears to not"
970 <<
" exist in the Trilinos sparsity pattern.");
984 std::unique_ptr<Epetra_FECrsGraph>
graph;
1009 const size_type row,
1010 const size_type index)
1015 visit_present_row();
1020 inline Accessor::size_type
1021 Accessor::row()
const
1023 Assert(a_row < sparsity_pattern->n_rows(),
1024 ExcBeyondEndOfSparsityPattern());
1030 inline Accessor::size_type
1031 Accessor::column()
const
1033 Assert(a_row < sparsity_pattern->n_rows(),
1034 ExcBeyondEndOfSparsityPattern());
1035 return (*colnum_cache)[a_index];
1040 inline Accessor::size_type
1041 Accessor::index()
const
1043 Assert(a_row < sparsity_pattern->n_rows(),
1044 ExcBeyondEndOfSparsityPattern());
1051 const size_type row,
1052 const size_type index)
1053 : accessor(sp, row,
index)
1058 inline Iterator::Iterator(
const Iterator &) =
default;
1063 Iterator::operator++()
1065 Assert(accessor.a_row < accessor.sparsity_pattern->n_rows(),
1072 if (accessor.a_index >= accessor.colnum_cache->size())
1074 accessor.a_index = 0;
1077 while (accessor.a_row < accessor.sparsity_pattern->n_rows())
1079 const auto row_length =
1080 accessor.sparsity_pattern->row_length(accessor.a_row);
1081 if (row_length == 0 ||
1082 !accessor.sparsity_pattern->row_is_stored_locally(
1089 accessor.visit_present_row();
1097 Iterator::operator++(
int)
1099 const Iterator old_state = *
this;
1106 inline const Accessor &
1107 Iterator::operator*()
const
1114 inline const Accessor *
1115 Iterator::operator->()
const
1123 Iterator::operator==(
const Iterator &other)
const
1125 return (accessor.a_row == other.accessor.a_row &&
1126 accessor.a_index == other.accessor.a_index);
1132 Iterator::operator!=(
const Iterator &other)
const
1134 return !(*
this == other);
1140 Iterator::operator<(
const Iterator &other)
const
1142 return (accessor.row() < other.accessor.row() ||
1143 (accessor.row() == other.accessor.row() &&
1144 accessor.index() < other.accessor.index()));
1200 SparsityPattern::in_local_range(
const size_type index)
const
1203# ifndef DEAL_II_WITH_64BIT_INDICES
1204 begin = graph->RowMap().MinMyGID();
1205 end = graph->RowMap().MaxMyGID() + 1;
1207 begin = graph->RowMap().MinMyGID64();
1208 end = graph->RowMap().MaxMyGID64() + 1;
1220 return graph->Filled();
1241 template <
typename ForwardIterator>
1244 ForwardIterator begin,
1245 ForwardIterator end,
1264 const_cast<std::decay_t<decltype(*
begin)
> *>(&*
begin));
1271 if (row_is_stored_locally(row))
1273 graph->InsertGlobalIndices(trilinos_row_index,
n_cols, col_index_ptr);
1274 else if (nonlocal_graph.get() !=
nullptr)
1279 Assert(nonlocal_graph->RowMap().LID(
1281 ExcMessage(
"Attempted to write into off-processor matrix row " +
1283 " that has not been specified as being writable upon "
1284 "initialization."));
1285 ierr = nonlocal_graph->InsertGlobalIndices(trilinos_row_index,
1290 ierr = graph->InsertGlobalIndices(1,
1291 &trilinos_row_index,
1300 inline const Epetra_FECrsGraph &
1301 SparsityPattern::trilinos_sparsity_pattern()
const
1309 SparsityPattern::locally_owned_domain_indices()
const
1311 return IndexSet(graph->DomainMap());
1317 SparsityPattern::locally_owned_range_indices()
const
1319 return IndexSet(graph->RangeMap());
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)
SparsityPatternIterators::Iterator const_iterator
types::global_dof_index size_type
unsigned int row_length(const size_type row) const
std::shared_ptr< const std::vector< size_type > > colnum_cache
Accessor(const SparsityPattern *sparsity_pattern, const size_type row, const size_type index)
SparsityPattern * sparsity_pattern
bool operator==(const Iterator &) const
const Accessor & operator*() const
bool operator<(const Iterator &) const
Iterator(const SparsityPattern *sparsity_pattern, const size_type row, const size_type index)
bool operator!=(const Iterator &) const
const Accessor * operator->() const
Iterator(const Iterator &i)
IndexSet locally_owned_domain_indices() const
size_type row_length(const size_type row) const
std::unique_ptr< Epetra_FECrsGraph > graph
void add(const size_type i, const size_type j)
void print(std::ostream &out, const bool write_extended_trilinos_info=false) const
unsigned int max_entries_per_row() const
size_type bandwidth() const
void print_gnuplot(std::ostream &out) const
const_iterator end() const
MPI_Comm get_mpi_communicator() const
virtual void add_row_entries(const size_type &row, const ArrayView< const size_type > &columns, const bool indices_are_sorted=false) override
const_iterator begin(const size_type r) const
std::uint64_t n_nonzero_elements() const
std::unique_ptr< Epetra_CrsGraph > nonlocal_graph
bool exists(const size_type i, const size_type j) const
const Epetra_Map & domain_partitioner() const
std::pair< size_type, size_type > local_range() const
const Epetra_FECrsGraph & trilinos_sparsity_pattern() const
void add_entries(const size_type row, ForwardIterator begin, ForwardIterator end, const bool indices_are_sorted=false)
bool is_compressed() const
unsigned int local_size() const
void copy_from(const SparsityPattern &input_sparsity_pattern)
IndexSet locally_owned_range_indices() const
std::unique_ptr< Epetra_Map > column_space_map
const Epetra_Map & range_partitioner() const
const_iterator begin() const
const_iterator end(const size_type r) const
bool in_local_range(const size_type index) const
virtual ~SparsityPattern() override=default
std::size_t memory_consumption() const
SparsityPattern & operator=(const SparsityPattern &input_sparsity_pattern)
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)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcAccessToNonPresentElement(size_type arg1, size_type arg2)
#define DeclException0(Exception0)
static ::ExceptionBase & ExcBeyondEndOfSparsityPattern()
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
static ::ExceptionBase & ExcNotImplemented()
static ::ExceptionBase & ExcInvalidIndexWithinRow(size_type arg1, size_type arg2)
#define Assert(cond, exc)
static ::ExceptionBase & ExcIteratorPastEnd()
static ::ExceptionBase & ExcAccessToNonlocalRow(size_type arg1, size_type arg2, size_type arg3)
#define DeclException2(Exception2, type1, type2, outsequence)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcAccessToNonLocalElement(size_type arg1, size_type arg2, size_type arg3, size_type arg4)
static ::ExceptionBase & ExcInvalidIndex(size_type arg1, size_type arg2)
#define AssertIndexRange(index, range)
#define DeclException3(Exception3, type1, type2, type3, outsequence)
#define DeclException1(Exception1, type1, outsequence)
static ::ExceptionBase & ExcTrilinosError(int arg1)
static ::ExceptionBase & ExcTrilinosError(int arg1)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
std::pair< types::global_dof_index, types::global_dof_index > local_range
std::string to_string(const number value, const unsigned int digits=numbers::invalid_unsigned_int)
unsigned int global_dof_index