16 #ifndef dealii_trilinos_sparsity_pattern_h 17 #define dealii_trilinos_sparsity_pattern_h 20 #include <deal.II/base/config.h> 22 #ifdef DEAL_II_WITH_TRILINOS 24 # include <deal.II/base/subscriptor.h> 25 # include <deal.II/base/index_set.h> 26 # include <deal.II/lac/exceptions.h> 33 # include <Epetra_FECrsGraph.h> 34 # include <Epetra_Map.h> 35 # ifdef DEAL_II_WITH_MPI 36 # include <Epetra_MpiComm.h> 39 # include <Epetra_SerialComm.h> 43 DEAL_II_NAMESPACE_OPEN
113 <<
"You tried to access row " << arg1
114 <<
" of a distributed sparsity pattern, " 115 <<
" but only rows " << arg2 <<
" through " << arg3
116 <<
" are stored locally and can be accessed.");
230 <<
"Attempt to access element " << arg2
231 <<
" of row " << arg1
232 <<
" which doesn't have that many elements.");
315 const std::vector<size_type> &n_entries_per_row);
361 const std::vector<size_type> &n_entries_per_row);
375 template <
typename SparsityPatternType>
377 copy_from (
const SparsityPatternType &nontrilinos_sparsity_pattern);
444 const std::vector<size_type> &n_entries_per_row);
466 const Epetra_Map &col_parallel_partitioning,
484 const Epetra_Map &col_parallel_partitioning,
485 const std::vector<size_type> &n_entries_per_row);
505 reinit (
const Epetra_Map ¶llel_partitioning,
522 reinit (
const Epetra_Map ¶llel_partitioning,
523 const std::vector<size_type> &n_entries_per_row);
545 reinit (
const Epetra_Map &row_parallel_partitioning,
546 const Epetra_Map &col_parallel_partitioning,
564 reinit (
const Epetra_Map &row_parallel_partitioning,
565 const Epetra_Map &col_parallel_partitioning,
566 const std::vector<size_type> &n_entries_per_row);
578 template <
typename SparsityPatternType>
581 reinit (
const Epetra_Map &row_parallel_partitioning,
582 const Epetra_Map &col_parallel_partitioning,
583 const SparsityPatternType &nontrilinos_sparsity_pattern,
584 const bool exchange_data =
false);
596 template <
typename SparsityPatternType>
599 reinit (
const Epetra_Map ¶llel_partitioning,
600 const SparsityPatternType &nontrilinos_sparsity_pattern,
601 const bool exchange_data =
false);
620 const MPI_Comm &communicator = MPI_COMM_WORLD,
634 const MPI_Comm &communicator,
635 const std::vector<size_type> &n_entries_per_row);
652 const IndexSet &col_parallel_partitioning,
653 const MPI_Comm &communicator = MPI_COMM_WORLD,
668 const IndexSet &col_parallel_partitioning,
669 const MPI_Comm &communicator,
670 const std::vector<size_type> &n_entries_per_row);
699 const IndexSet &col_parallel_partitioning,
701 const MPI_Comm &communicator = MPI_COMM_WORLD,
721 const MPI_Comm &communicator = MPI_COMM_WORLD,
736 const MPI_Comm &communicator,
737 const std::vector<size_type> &n_entries_per_row);
757 const IndexSet &col_parallel_partitioning,
758 const MPI_Comm &communicator = MPI_COMM_WORLD,
788 const IndexSet &col_parallel_partitioning,
790 const MPI_Comm &communicator = MPI_COMM_WORLD,
799 const IndexSet &col_parallel_partitioning,
800 const MPI_Comm &communicator,
801 const std::vector<size_type> &n_entries_per_row);
812 template <
typename SparsityPatternType>
815 const IndexSet &col_parallel_partitioning,
816 const SparsityPatternType &nontrilinos_sparsity_pattern,
817 const MPI_Comm &communicator = MPI_COMM_WORLD,
818 const bool exchange_data =
false);
828 template <
typename SparsityPatternType>
831 const SparsityPatternType &nontrilinos_sparsity_pattern,
832 const MPI_Comm &communicator = MPI_COMM_WORLD,
833 const bool exchange_data =
false);
880 std::pair<size_type, size_type>
941 template <
typename ForwardIterator>
943 ForwardIterator
begin,
945 const bool indices_are_sorted =
false);
1092 void print (std::ostream &out,
1093 const bool write_extended_trilinos_info =
false)
const;
1121 <<
"An error with error number " << arg1
1122 <<
" occurred while calling a Trilinos function");
1129 <<
"The entry with index <" << arg1 <<
',' << arg2
1130 <<
"> does not exist.");
1136 "You are attempting an operation on two sparsity patterns that " 1137 "are the same object, but the operation requires that the " 1138 "two objects are in fact different.");
1145 <<
"You tried to access element (" << arg1
1146 <<
"/" << arg2 <<
")" 1147 <<
" of a distributed matrix, but only rows " 1148 << arg3 <<
" through " << arg4
1149 <<
" are stored locally and can be accessed.");
1156 <<
"You tried to access element (" << arg1
1157 <<
"/" << arg2 <<
")" 1158 <<
" of a sparse matrix, but it appears to not" 1159 <<
" exist in the Trilinos sparsity pattern.");
1174 std::unique_ptr<Epetra_FECrsGraph>
graph;
1201 const size_type row,
1202 const size_type index)
1208 visit_present_row ();
1215 Accessor::row()
const 1217 Assert (a_row < sparsity_pattern->n_rows(), ExcBeyondEndOfSparsityPattern());
1225 Accessor::column()
const 1227 Assert (a_row < sparsity_pattern->n_rows(), ExcBeyondEndOfSparsityPattern());
1228 return (*colnum_cache)[a_index];
1235 Accessor::index()
const 1237 Assert (a_row < sparsity_pattern->n_rows(), ExcBeyondEndOfSparsityPattern());
1245 const size_type row,
1246 const size_type index)
1248 accessor(sp, row, index)
1253 Iterator::Iterator(
const Iterator &) =
default;
1259 Iterator::operator++ ()
1261 Assert (accessor.a_row < accessor.sparsity_pattern->n_rows(),
1270 if (accessor.a_index >= accessor.colnum_cache->size())
1272 accessor.a_index = 0;
1275 while ((accessor.a_row < accessor.sparsity_pattern->n_rows())
1277 (accessor.sparsity_pattern->row_length(accessor.a_row) == 0))
1280 accessor.visit_present_row();
1289 Iterator::operator++ (
int)
1291 const Iterator old_state = *
this;
1309 Iterator::operator-> ()
const 1318 Iterator::operator == (
const Iterator &other)
const 1320 return (accessor.a_row == other.accessor.a_row &&
1321 accessor.a_index == other.accessor.a_index);
1328 Iterator::operator != (
const Iterator &other)
const 1330 return ! (*
this == other);
1337 Iterator::operator < (
const Iterator &other)
const 1339 return (accessor.row() < other.accessor.row() ||
1340 (accessor.row() == other.accessor.row() &&
1341 accessor.index() < other.accessor.index()));
1401 SparsityPattern::in_local_range (
const size_type index)
const 1403 TrilinosWrappers::types::int_type
begin,
end;
1404 #ifndef DEAL_II_WITH_64BIT_INDICES 1405 begin = graph->RowMap().MinMyGID();
1406 end = graph->RowMap().MaxMyGID()+1;
1408 begin = graph->RowMap().MinMyGID64();
1409 end = graph->RowMap().MaxMyGID64()+1;
1412 return ((index >= static_cast<size_type>(
begin)) &&
1413 (index < static_cast<size_type>(
end)));
1422 return graph->Filled();
1446 template <
typename ForwardIterator>
1450 ForwardIterator begin,
1451 ForwardIterator end,
1465 Assert (
sizeof(TrilinosWrappers::types::int_type) ==
1469 TrilinosWrappers::types::int_type *col_index_ptr =
1470 (TrilinosWrappers::types::int_type *)(&*
begin);
1474 if ( graph->RowMap().LID(static_cast<TrilinosWrappers::types::int_type>(row)) != -1)
1475 ierr = graph->InsertGlobalIndices (row,
n_cols, col_index_ptr);
1476 else if (nonlocal_graph.get() !=
nullptr)
1481 Assert (nonlocal_graph->RowMap().LID(static_cast<TrilinosWrappers::types::int_type>(row)) != -1,
1482 ExcMessage(
"Attempted to write into off-processor matrix row " 1483 "that has not be specified as being writable upon " 1485 ierr = nonlocal_graph->InsertGlobalIndices (row,
n_cols, col_index_ptr);
1488 ierr = graph->InsertGlobalIndices
1489 (1, (TrilinosWrappers::types::int_type *)&row,
n_cols, col_index_ptr);
1497 const Epetra_FECrsGraph &
1498 SparsityPattern::trilinos_sparsity_pattern ()
const 1507 SparsityPattern::locally_owned_domain_indices ()
const 1509 return IndexSet(static_cast<const Epetra_Map &>(graph->DomainMap()));
1516 SparsityPattern::locally_owned_range_indices ()
const 1518 return IndexSet(static_cast<const Epetra_Map &>(graph->RangeMap()));
1525 DEAL_II_NAMESPACE_CLOSE
1528 #endif // DEAL_II_WITH_TRILINOS static ::ExceptionBase & ExcTrilinosError(int arg1)
static ::ExceptionBase & ExcAccessToNonLocalElement(size_type arg1, size_type arg2, size_type arg3, size_type arg4)
const Epetra_Map & domain_partitioner() const
void add_entries(const size_type row, ForwardIterator begin, ForwardIterator end, const bool indices_are_sorted=false)
unsigned int local_size() const
#define DeclException2(Exception2, type1, type2, outsequence)
static ::ExceptionBase & ExcBeyondEndOfSparsityPattern()
::types::global_dof_index size_type
void print(std::ostream &out, const bool write_extended_trilinos_info=false) const
std::shared_ptr< const std::vector< size_type > > colnum_cache
virtual ~SparsityPattern()=default
static ::ExceptionBase & ExcAccessToNonPresentElement(size_type arg1, size_type arg2)
size_type row_length(const size_type row) const
IndexSet locally_owned_range_indices() const
const Epetra_FECrsGraph & trilinos_sparsity_pattern() const
static ::ExceptionBase & ExcSourceEqualsDestination()
const Epetra_Map & row_partitioner() const
bool operator==(const Iterator &) const
size_type n_nonzero_elements() const
const Epetra_Map & col_partitioner() const
#define AssertThrow(cond, exc)
void add(const size_type i, const size_type j)
::types::global_dof_index size_type
void add_entries(const size_type row, ForwardIterator begin, ForwardIterator end, const bool indices_are_sorted=false)
SymmetricTensor< rank_, dim, Number > operator*(const SymmetricTensor< rank_, dim, Number > &t, const Number &factor)
std::unique_ptr< Epetra_CrsGraph > nonlocal_graph
bool is_compressed() const
const_iterator begin() const
bool exists(const size_type i, const size_type j) const
static ::ExceptionBase & ExcTrilinosError(int arg1)
SparsityPattern * sparsity_pattern
static ::ExceptionBase & ExcMessage(std::string arg1)
static ::ExceptionBase & ExcInvalidIndex(size_type arg1, size_type arg2)
#define DeclException1(Exception1, type1, outsequence)
void add(const size_type i, const size_type j)
MPI_Comm get_mpi_communicator() const
std::unique_ptr< Epetra_Map > column_space_map
#define Assert(cond, exc)
const Accessor & operator*() const
#define DeclExceptionMsg(Exception, defaulttext)
static ::ExceptionBase & ExcInvalidIndexWithinRow(size_type arg1, size_type arg2)
#define DeclException0(Exception0)
size_type bandwidth() const
std::size_t memory_consumption() const
::types::global_dof_index size_type
void print_gnuplot(std::ostream &out) const
const_iterator end() const
bool is_compressed() const
SparsityPatternIterators::Iterator const_iterator
SparsityPatternIterators::Iterator const_iterator
unsigned int max_entries_per_row() const
bool operator<(const Iterator &) const
static ::ExceptionBase & ExcIteratorPastEnd()
bool operator!=(const Iterator &) const
SparsityPattern & operator=(const SparsityPattern &input_sparsity_pattern)
types::global_dof_index size_type
void copy_from(const SparsityPattern &input_sparsity_pattern)
Iterator(const SparsityPattern *sparsity_pattern, const size_type row, const size_type index)
static ::ExceptionBase & ExcAccessToNonlocalRow(size_type arg1, size_type arg2, size_type arg3)
#define DeclException4(Exception4, type1, type2, type3, type4, outsequence)
const Accessor * operator->() const
const Epetra_Comm & trilinos_communicator() const
static ::ExceptionBase & ExcNotImplemented()
#define DeclException3(Exception3, type1, type2, type3, outsequence)
bool in_local_range(const size_type index) const
void reinit(const size_type m, const size_type n, const size_type n_entries_per_row=0)
IndexSet locally_owned_domain_indices() const
const Epetra_Map & range_partitioner() const
std::pair< size_type, size_type > local_range() const
std::unique_ptr< Epetra_FECrsGraph > graph
unsigned int row_length(const size_type row) const
Accessor(const SparsityPattern *sparsity_pattern, const size_type row, const size_type index)