17#ifdef DEAL_II_TRILINOS_WITH_TPETRA
34 namespace TpetraWrappers
38 template <
typename MemorySpace>
44 if (
static_cast<size_t>(this->a_row) == sparsity_pattern->n_rows())
51 if (!sparsity_pattern->is_compressed())
52 sparsity_pattern->compress();
55 std::make_shared<std::vector<::types::signed_global_dof_index>>(
56 sparsity_pattern->row_length(this->a_row));
58 if (colnum_cache->size() > 0)
62# if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
70 sparsity_pattern->graph->getGlobalRowCopy(this->a_row,
84 template <
typename MemorySpace>
96 graph->fillComplete();
101 template <
typename MemorySpace>
112 template <
typename MemorySpace>
123 template <
typename MemorySpace>
127 , column_space_map(std::move(
other.column_space_map))
128 , graph(std::move(
other.graph))
129 , nonlocal_graph(std::move(
other.nonlocal_graph))
135 template <
typename MemorySpace>
143 Utilities::Trilinos::tpetra_comm_self()))
145 TpetraTypes::GraphType<
MemorySpace>>(column_space_map,
152 "Copy constructor only works for empty sparsity patterns."));
157 template <
typename MemorySpace>
171 template <
typename MemorySpace>
185 template <
typename MemorySpace>
200 template <
typename MemorySpace>
215 template <
typename MemorySpace>
232 template <
typename MemorySpace>
246 template <
typename MemorySpace>
261 namespace SparsityPatternImpl
263 template <
typename MemorySpace>
266 template <
typename MemorySpace>
277 ExcMessage(
"Row map must be 1-to-1, i.e., no overlap between "
278 "the maps of different processors."));
280 ExcMessage(
"Column map must be 1-to-1, i.e., no overlap between "
281 "the maps of different processors."));
283 nonlocal_graph.reset();
303 template <
typename MemorySpace>
314 ExcMessage(
"Row map must be 1-to-1, i.e., no overlap between "
315 "the maps of different processors."));
317 ExcMessage(
"Column map must be 1-to-1, i.e., no overlap between "
318 "the maps of different processors."));
321 nonlocal_graph.reset();
324 row_map->getGlobalNumElements());
330 Kokkos::DualView<size_t *, typename MemorySpace::kokkos_space>
339 std::uint64_t total_size = 0;
352 total_size <
static_cast<std::uint64_t
>(
356 "You are requesting to store more elements than global ordinal type allows."));
366 template <
typename SparsityPatternType,
typename MemorySpace>
377 nonlocal_graph.reset();
388 "This function only works if the row map is contiguous."));
392 row_map->getMaxGlobalIndex() + 1;
402 static_cast<std::uint64_t
>(std::numeric_limits<int>::max()),
404 "The TrilinosWrappers use Tpetra internally, and "
405 "Trilinos/Tpetra was compiled with 'local ordinate = int'. "
406 "Therefore, 'signed int' is used to represent local indices, "
407 "and only 2,147,483,647 nonzero matrix entries can be stored "
408 "on a single process, but you are requesting more than "
409 "that. Either use more MPI processes or recompile Trilinos "
410 "with 'local ordinate = long long' "));
412# if DEAL_II_TRILINOS_VERSION_GTE(12, 16, 0)
413 if (
row_map->getComm()->getSize() > 1)
422 if (
row_map->getComm()->getSize() > 1)
436 std::vector<TrilinosWrappers::types::int_type> row_indices;
445 row_indices.resize(row_length, -1);
447 typename SparsityPatternType::iterator p =
sp.begin(row);
450 for (
int col = 0; col < row_length;)
452 row_indices[col++] = p->column();
453 if (col < row_length)
457 graph->insertGlobalIndices(row, row_length, row_indices.data());
460 graph->globalAssemble();
465 template <
typename MemorySpace>
476 communicator,
false);
477 SparsityPatternImpl::reinit_sp<MemorySpace>(
483 template <
typename MemorySpace>
495 communicator,
false);
496 SparsityPatternImpl::reinit_sp<MemorySpace>(
502 template <
typename MemorySpace>
515 communicator,
false);
519 communicator,
false);
520 SparsityPatternImpl::reinit_sp<MemorySpace>(
row_map,
530 template <
typename MemorySpace>
543 communicator,
false);
547 communicator,
false);
548 SparsityPatternImpl::reinit_sp<MemorySpace>(
row_map,
558 template <
typename MemorySpace>
572 communicator,
false);
576 communicator,
false);
577 SparsityPatternImpl::reinit_sp<MemorySpace>(
row_map,
592 "The set of writable rows passed to this method does not "
593 "contain the locally owned rows, which is not allowed."));
612 template <
typename MemorySpace>
613 template <
typename SparsityPatternType>
627 communicator,
false);
631 communicator,
false);
632 SparsityPatternImpl::reinit_sp<SparsityPatternType, MemorySpace>(
644 template <
typename MemorySpace>
645 template <
typename SparsityPatternType>
662 communicator,
false);
663 SparsityPatternImpl::reinit_sp<SparsityPatternType, MemorySpace>(
675 template <
typename MemorySpace>
686 template <
typename MemorySpace>
697 if (
sp.nonlocal_graph.get() !=
nullptr)
701 nonlocal_graph.reset();
706 template <
typename MemorySpace>
707 template <
typename SparsityPatternType>
725 SparsityPatternImpl::reinit_sp<SparsityPatternType, MemorySpace>(
726 rows, columns,
sp,
false, column_space_map, graph, nonlocal_graph);
731 template <
typename MemorySpace>
748 graph->fillComplete();
750 nonlocal_graph.reset();
755 template <
typename MemorySpace>
760 if (nonlocal_graph.get() !=
nullptr)
762# if DEAL_II_TRILINOS_VERSION_GTE(14, 0, 0)
763 if (nonlocal_graph->getRowMap()->getLocalNumElements() > 0 &&
764 column_space_map->getGlobalNumElements() > 0)
766 if (nonlocal_graph->getRowMap()->getNodeNumElements() > 0 &&
767 column_space_map->getGlobalNumElements() > 0)
773 nonlocal_graph->getRowMap()->getGlobalElement(0);
778 if (column_space_map->getGlobalNumElements() ==
779 graph->getRangeMap()->getGlobalNumElements())
785# if DEAL_II_TRILINOS_VERSION_GTE(14, 0, 0)
786 else if (column_space_map->getLocalNumElements() > 0)
788 else if (column_space_map->getNodeNumElements() > 0)
790 column = column_space_map->getGlobalElement(0);
791 nonlocal_graph->insertGlobalIndices(row, 1, &column);
793# if DEAL_II_TRILINOS_VERSION_GTE(14, 0, 0)
794 Assert(nonlocal_graph->getRowMap()->getLocalNumElements() == 0 ||
795 column_space_map->getGlobalNumElements() == 0,
798 Assert(nonlocal_graph->getRowMap()->getNodeNumElements() == 0 ||
799 column_space_map->getGlobalNumElements() == 0,
803 nonlocal_graph->fillComplete(column_space_map, graph->getRowMap());
805 graph->fillComplete(column_space_map, graph->getRowMap());
816 template <
typename MemorySpace>
820 return graph->getRowMap()->getLocalElement(i) !=
821 Teuchos::OrdinalTraits<int>::invalid();
826 template <
typename MemorySpace>
831# if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
832 if (!row_is_stored_locally(i))
836 const auto trilinos_i = graph->getRowMap()->getLocalElement(i);
837 const auto trilinos_j = graph->getColMap()->getLocalElement(
j);
863 template <
typename MemorySpace>
870# if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
877 graph->getLocalRowView(i, indices);
896 template <
typename MemorySpace>
900# if DEAL_II_TRILINOS_VERSION_GTE(14, 0, 0)
901 return graph->getLocalNumRows();
903 return graph->getNodeNumRows();
909 template <
typename MemorySpace>
910 std::pair<typename SparsityPattern<MemorySpace>::size_type,
914 const size_type begin = graph->getRowMap()->getMinGlobalIndex();
915 const size_type end = graph->getRowMap()->getMaxGlobalIndex() + 1;
922 template <
typename MemorySpace>
926 return graph->getGlobalNumEntries();
931 template <
typename MemorySpace>
935# if DEAL_II_TRILINOS_VERSION_GTE(14, 0, 0)
936 return graph->getLocalMaxNumRowEntries();
938 return graph->getNodeMaxNumRowEntries();
944 template <
typename MemorySpace>
953 graph->getRowMap()->getLocalElement(row);
958 return graph->getNumEntriesInLocalRow(
local_row);
965 template <
typename MemorySpace>
968 const ::types::global_dof_index &row,
977 template <
typename MemorySpace>
981 return graph->getDomainMap();
986 template <
typename MemorySpace>
990 return graph->getRangeMap();
995 template <
typename MemorySpace>
1000 graph->getRangeMap()->getComm());
1005 template <
typename MemorySpace>
1009 return graph->getRangeMap()->getComm();
1017 template <
typename MemorySpace>
1027# if DEAL_II_TRILINOS_VERSION_GTE(14, 0, 0)
1028 for (
unsigned int i = 0; i < graph->getLocalNumRows(); ++i)
1030 for (
unsigned int i = 0; i < graph->getNodeNumRows(); ++i)
1033# if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1039 graph->getLocalRowView(i, indices);
1042 out <<
"(" << graph->getRowMap()->getGlobalElement(i) <<
","
1043 << graph->getColMap()->getGlobalElement(indices[
j]) <<
") "
1053 template <
typename MemorySpace>
1059 for (
unsigned int row = 0; row < local_size(); ++row)
1061# if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0)
1067 graph->getLocalRowView(row, indices);
1081 out <<
static_cast<int>(
1082 graph->getColMap()->getGlobalElement(indices[
j]))
1084 << -
static_cast<int>(graph->getRowMap()->getGlobalElement(row))
1092 template <
typename MemorySpace>
1107 const ::SparsityPattern &);
1110 const ::DynamicSparsityPattern &);
1115 const ::SparsityPattern &,
1121 const ::DynamicSparsityPattern &,
1130 const ::SparsityPattern &,
1137 const ::DynamicSparsityPattern &,
1146 const ::SparsityPattern &);
1149 const ::DynamicSparsityPattern &);
1154 const ::SparsityPattern &,
1160 const ::DynamicSparsityPattern &,
1169 const ::SparsityPattern &,
1176 const ::DynamicSparsityPattern &,
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
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
void print_gnuplot(std::ostream &out) const
MPI_Comm get_mpi_communicator() const
Teuchos::RCP< const TpetraTypes::MapType< MemorySpace > > domain_partitioner() const
std::uint64_t n_nonzero_elements() const
size_type bandwidth() const
bool exists(const size_type i, const size_type j) const
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
size_type row_length(const size_type row) 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 resize(const size_type rows, const size_type cols)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcIO()
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
#define DEAL_II_NOT_IMPLEMENTED()
IndexSet complete_index_set(const IndexSet::size_type N)
void reinit_sp(const Teuchos::RCP< TpetraTypes::MapType< MemorySpace > > &row_map, const Teuchos::RCP< TpetraTypes::MapType< MemorySpace > > &col_map, const size_type< MemorySpace > n_entries_per_row, Teuchos::RCP< TpetraTypes::MapType< MemorySpace > > &column_space_map, Teuchos::RCP< TpetraTypes::GraphType< MemorySpace > > &graph, Teuchos::RCP< TpetraTypes::GraphType< MemorySpace > > &nonlocal_graph)
typename SparsityPattern< MemorySpace >::size_type size_type
Tpetra::CrsGraph< LO, GO, NodeType< MemorySpace > > GraphType
Tpetra::Map< LO, GO, NodeType< MemorySpace > > MapType
unsigned int n_mpi_processes(const MPI_Comm mpi_communicator)
T max(const T &t, const MPI_Comm mpi_communicator)
Teuchos::RCP< T > make_rcp(Args &&...args)
MPI_Comm teuchos_comm_to_mpi_comm(const Teuchos::RCP< const Teuchos::Comm< int > > &teuchos_comm)
const Teuchos::RCP< const Teuchos::Comm< int > > & tpetra_comm_self()
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)