]> https://gitweb.dealii.org/ - dealii.git/commitdiff
TrilinosWrappers::SparsityPattern: inherit from SparsityPatternBase. 14418/head
authorDavid Wells <drwells@email.unc.edu>
Thu, 3 Nov 2022 16:40:14 +0000 (12:40 -0400)
committerDavid Wells <drwells@email.unc.edu>
Sun, 13 Nov 2022 23:51:52 +0000 (18:51 -0500)
include/deal.II/lac/trilinos_sparsity_pattern.h
source/lac/trilinos_sparsity_pattern.cc

index a6435c0a3197939840eb8f4932b32e3f7ae2ecd0..4c6e575106f19f4dba9c4f56a6f5727c27dc0c48 100644 (file)
@@ -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<const size_type> &columns,
+                    const bool indices_are_sorted = false) override;
+
+    virtual void
+    add_entries(const ArrayView<const size_type> &rows,
+                const ArrayView<const size_type> &columns) override;
+
     /** @} */
     /**
      * @name Access of underlying Trilinos data
index 4fe3d2277097ad2c9aff1af417492bd43cfa0900..fe31d1da8cd79e2387d1206e4cf731206dbde278 100644 (file)
@@ -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<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(
@@ -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<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 =
@@ -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<Epetra_Map>(*sp.column_space_map);
     graph            = std::make_unique<Epetra_FECrsGraph>(*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<const size_type> &columns,
+                                   const bool indices_are_sorted)
+  {
+    add_entries(row, columns.begin(), columns.end(), indices_are_sorted);
+  }
+
+
+
+  void
+  SparsityPattern::add_entries(const ArrayView<const size_type> &rows,
+                               const ArrayView<const size_type> &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
   {

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.