From edcd7bd51ca2ef0234207124615cc095fe3bd1d7 Mon Sep 17 00:00:00 2001 From: David Wells Date: Thu, 3 Nov 2022 12:40:14 -0400 Subject: [PATCH] TrilinosWrappers::SparsityPattern: inherit from SparsityPatternBase. --- .../deal.II/lac/trilinos_sparsity_pattern.h | 24 +++--- source/lac/trilinos_sparsity_pattern.cc | 77 +++++++++++++------ 2 files changed, 63 insertions(+), 38 deletions(-) diff --git a/include/deal.II/lac/trilinos_sparsity_pattern.h b/include/deal.II/lac/trilinos_sparsity_pattern.h index a6435c0a31..4c6e575106 100644 --- a/include/deal.II/lac/trilinos_sparsity_pattern.h +++ b/include/deal.II/lac/trilinos_sparsity_pattern.h @@ -271,7 +271,7 @@ namespace TrilinosWrappers * @ingroup TrilinosWrappers * @ingroup Sparsity */ - class SparsityPattern : public Subscriptor + class SparsityPattern : public SparsityPatternBase { public: /** @@ -667,18 +667,6 @@ namespace TrilinosWrappers unsigned int max_entries_per_row() const; - /** - * Return the number of rows in this sparsity pattern. - */ - size_type - n_rows() const; - - /** - * Return the number of columns in this sparsity pattern. - */ - size_type - n_cols() const; - /** * Return the local dimension of the sparsity pattern, i.e. the number of * rows stored on the present MPI process. In the sequential case, this @@ -784,6 +772,16 @@ namespace TrilinosWrappers ForwardIterator begin, ForwardIterator end, const bool indices_are_sorted = false); + + virtual void + add_row_entries(const size_type & row, + const ArrayView &columns, + const bool indices_are_sorted = false) override; + + virtual void + add_entries(const ArrayView &rows, + const ArrayView &columns) override; + /** @} */ /** * @name Access of underlying Trilinos data diff --git a/source/lac/trilinos_sparsity_pattern.cc b/source/lac/trilinos_sparsity_pattern.cc index 4fe3d22770..fe31d1da8c 100644 --- a/source/lac/trilinos_sparsity_pattern.cc +++ b/source/lac/trilinos_sparsity_pattern.cc @@ -117,7 +117,7 @@ namespace TrilinosWrappers SparsityPattern::SparsityPattern(SparsityPattern &&other) noexcept - : Subscriptor(std::move(other)) + : SparsityPatternBase(other) , column_space_map(std::move(other.column_space_map)) , graph(std::move(other.graph)) , nonlocal_graph(std::move(other.nonlocal_graph)) @@ -128,7 +128,7 @@ namespace TrilinosWrappers // Copy function only works if the // sparsity pattern is empty. SparsityPattern::SparsityPattern(const SparsityPattern &input_sparsity) - : Subscriptor() + : SparsityPatternBase(input_sparsity) , column_space_map(new Epetra_Map(TrilinosWrappers::types::int_type(0), TrilinosWrappers::types::int_type(0), Utilities::Trilinos::comm_self())) @@ -483,6 +483,8 @@ namespace TrilinosWrappers const MPI_Comm &communicator, const size_type n_entries_per_row) { + SparsityPatternBase::resize(parallel_partitioning.size(), + parallel_partitioning.size()); Epetra_Map map = parallel_partitioning.make_trilinos_map(communicator, false); reinit_sp( @@ -496,6 +498,8 @@ namespace TrilinosWrappers const MPI_Comm & communicator, const std::vector &n_entries_per_row) { + SparsityPatternBase::resize(parallel_partitioning.size(), + parallel_partitioning.size()); Epetra_Map map = parallel_partitioning.make_trilinos_map(communicator, false); reinit_sp( @@ -510,6 +514,8 @@ namespace TrilinosWrappers const MPI_Comm &communicator, const size_type n_entries_per_row) { + SparsityPatternBase::resize(row_parallel_partitioning.size(), + col_parallel_partitioning.size()); Epetra_Map row_map = row_parallel_partitioning.make_trilinos_map(communicator, false); Epetra_Map col_map = @@ -530,6 +536,8 @@ namespace TrilinosWrappers const MPI_Comm &communicator, const std::vector &n_entries_per_row) { + SparsityPatternBase::resize(row_parallel_partitioning.size(), + col_parallel_partitioning.size()); Epetra_Map row_map = row_parallel_partitioning.make_trilinos_map(communicator, false); Epetra_Map col_map = @@ -551,6 +559,8 @@ namespace TrilinosWrappers const MPI_Comm &communicator, const size_type n_entries_per_row) { + SparsityPatternBase::resize(row_parallel_partitioning.size(), + col_parallel_partitioning.size()); Epetra_Map row_map = row_parallel_partitioning.make_trilinos_map(communicator, false); Epetra_Map col_map = @@ -597,6 +607,8 @@ namespace TrilinosWrappers const MPI_Comm & communicator, const bool exchange_data) { + SparsityPatternBase::resize(row_parallel_partitioning.size(), + col_parallel_partitioning.size()); Epetra_Map row_map = row_parallel_partitioning.make_trilinos_map(communicator, false); Epetra_Map col_map = @@ -620,6 +632,12 @@ namespace TrilinosWrappers const MPI_Comm & communicator, const bool exchange_data) { + AssertDimension(nontrilinos_sparsity_pattern.n_rows(), + parallel_partitioning.size()); + AssertDimension(nontrilinos_sparsity_pattern.n_cols(), + parallel_partitioning.size()); + SparsityPatternBase::resize(parallel_partitioning.size(), + parallel_partitioning.size()); Epetra_Map map = parallel_partitioning.make_trilinos_map(communicator, false); reinit_sp(map, @@ -645,6 +663,7 @@ namespace TrilinosWrappers void SparsityPattern::copy_from(const SparsityPattern &sp) { + SparsityPatternBase::resize(sp.n_rows(), sp.n_cols()); column_space_map = std::make_unique(*sp.column_space_map); graph = std::make_unique(*sp.graph); @@ -660,6 +679,7 @@ namespace TrilinosWrappers void SparsityPattern::copy_from(const SparsityPatternType &sp) { + SparsityPatternBase::resize(sp.n_rows(), sp.n_cols()); const Epetra_Map rows(TrilinosWrappers::types::int_type(sp.n_rows()), 0, Utilities::Trilinos::comm_self()); @@ -676,6 +696,7 @@ namespace TrilinosWrappers void SparsityPattern::clear() { + SparsityPatternBase::resize(0, 0); // When we clear the matrix, reset // the pointer and generate an // empty sparsity pattern. @@ -769,6 +790,14 @@ namespace TrilinosWrappers "Epetra indexes entries with a simple 'signed int'.")); } AssertThrow(ierr == 0, ExcTrilinosError(ierr)); + + // Check consistency between the sizes set at the beginning and what + // Trilinos stores: + using namespace deal_II_exceptions::internals; + Assert(compare_for_equality(n_rows(), n_global_rows(*graph)), + ExcInternalError()); + Assert(compare_for_equality(n_cols(), n_global_cols(*graph)), + ExcInternalError()); } @@ -889,29 +918,6 @@ namespace TrilinosWrappers - SparsityPattern::size_type - SparsityPattern::n_rows() const - { - const TrilinosWrappers::types::int_type n_rows = n_global_rows(*graph); - return n_rows; - } - - - - SparsityPattern::size_type - SparsityPattern::n_cols() const - { - TrilinosWrappers::types::int_type n_cols; - if (graph->Filled() == true) - n_cols = n_global_cols(*graph); - else - n_cols = TrilinosWrappers::n_global_elements(*column_space_map); - - return n_cols; - } - - - unsigned int SparsityPattern::local_size() const { @@ -974,6 +980,27 @@ namespace TrilinosWrappers + void + SparsityPattern::add_row_entries(const size_type & row, + const ArrayView &columns, + const bool indices_are_sorted) + { + add_entries(row, columns.begin(), columns.end(), indices_are_sorted); + } + + + + void + SparsityPattern::add_entries(const ArrayView &rows, + const ArrayView &columns) + { + AssertDimension(rows.size(), columns.size()); + for (std::size_t i = 0; i < rows.size(); ++i) + add(rows[i], columns[i]); + } + + + const Epetra_Map & SparsityPattern::domain_partitioner() const { -- 2.39.5