]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add MGTransferBase::prolongate_and_add 11792/head
authorPeter Munch <peterrmuench@gmail.com>
Mon, 22 Feb 2021 17:31:12 +0000 (18:31 +0100)
committerPeter Munch <peterrmuench@gmail.com>
Tue, 2 Mar 2021 15:31:21 +0000 (16:31 +0100)
doc/news/changes/minor/2020222MartinKronbichler [new file with mode: 0644]
include/deal.II/multigrid/mg_base.h
include/deal.II/multigrid/mg_transfer_matrix_free.h
source/multigrid/mg_base.cc
source/multigrid/mg_transfer_matrix_free.cc

diff --git a/doc/news/changes/minor/2020222MartinKronbichler b/doc/news/changes/minor/2020222MartinKronbichler
new file mode 100644 (file)
index 0000000..f86e2af
--- /dev/null
@@ -0,0 +1,4 @@
+New: The new MGTransferBase::prolongate_and_add() performs a prolongation
+without zeroing out the destination vector.
+<br>
+(Martin Kronbichler, 2020/02/22)
index f688d11b1ef2708e1164b1019dc4e9f5d234764c..2073b33b74bda4e0b8cb27d14de636dc90712151 100644 (file)
@@ -191,6 +191,21 @@ public:
              VectorType &       dst,
              const VectorType & src) const = 0;
 
+  /**
+   * Prolongate a vector from level <tt>to_level-1</tt> to level
+   * <tt>to_level</tt>, summing into the previous content of <tt>dst</tt>.
+   *
+   * @arg src is a vector with as many elements as there are degrees of
+   * freedom on the coarser level involved.
+   *
+   * @arg dst has as many elements as there are degrees of freedom on the
+   * finer level.
+   */
+  virtual void
+  prolongate_and_add(const unsigned int to_level,
+                     VectorType &       dst,
+                     const VectorType & src) const;
+
   /**
    * Restrict a vector from level <tt>from_level</tt> to level
    * <tt>from_level-1</tt> and add this restriction to <tt>dst</tt>. If the
index 8c71361164d04529d2cec4a28c76295fc939152f..210aa36a1bc089da8b49dbd61a9fe662d5d1ce3e 100644 (file)
@@ -125,6 +125,12 @@ public:
     LinearAlgebra::distributed::Vector<Number> &      dst,
     const LinearAlgebra::distributed::Vector<Number> &src) const override;
 
+  virtual void
+  prolongate_and_add(
+    const unsigned int                                to_level,
+    LinearAlgebra::distributed::Vector<Number> &      dst,
+    const LinearAlgebra::distributed::Vector<Number> &src) const override;
+
   /**
    * Restrict a vector from level <tt>from_level</tt> to level
    * <tt>from_level-1</tt> using the transpose operation of the prolongate()
@@ -382,6 +388,12 @@ public:
     LinearAlgebra::distributed::BlockVector<Number> &      dst,
     const LinearAlgebra::distributed::BlockVector<Number> &src) const override;
 
+  virtual void
+  prolongate_and_add(
+    const unsigned int                                     to_level,
+    LinearAlgebra::distributed::BlockVector<Number> &      dst,
+    const LinearAlgebra::distributed::BlockVector<Number> &src) const override;
+
   /**
    * Restrict a vector from level <tt>from_level</tt> to level
    * <tt>from_level-1</tt> using the transpose operation of the prolongate()
index 7ac5d611fb36c82c0af2ba3c61af7bc103f169c8..1750407279f65e20873f2a5efd08b040ab46ea76 100644 (file)
@@ -41,6 +41,22 @@ MGSmootherBase<VectorType>::apply(const unsigned int level,
 }
 
 
+
+template <typename VectorType>
+void
+MGTransferBase<VectorType>::prolongate_and_add(const unsigned int to_level,
+                                               VectorType &       dst,
+                                               const VectorType & src) const
+{
+  VectorType temp;
+  temp.reinit(dst, true);
+
+  this->prolongate(to_level, temp, src);
+
+  dst += temp;
+}
+
+
 // Explicit instantiations
 
 #include "mg_base.inst"
index d1cc31f16d1ba330679cc09661d7cba7d24d2aaf..48a7986303076ff76163d418232f940556eb30df 100644 (file)
@@ -184,6 +184,19 @@ MGTransferMatrixFree<dim, Number>::prolongate(
   const unsigned int                                to_level,
   LinearAlgebra::distributed::Vector<Number> &      dst,
   const LinearAlgebra::distributed::Vector<Number> &src) const
+{
+  dst = 0;
+  prolongate_and_add(to_level, dst, src);
+}
+
+
+
+template <int dim, typename Number>
+void
+MGTransferMatrixFree<dim, Number>::prolongate_and_add(
+  const unsigned int                                to_level,
+  LinearAlgebra::distributed::Vector<Number> &      dst,
+  const LinearAlgebra::distributed::Vector<Number> &src) const
 {
   Assert((to_level >= 1) && (to_level <= level_dof_indices.size()),
          ExcIndexRange(to_level, 1, level_dof_indices.size() + 1));
@@ -210,6 +223,7 @@ MGTransferMatrixFree<dim, Number>::prolongate(
           this->vector_partitioners[to_level]);
       AssertDimension(this->ghosted_level_vector[to_level].locally_owned_size(),
                       dst.locally_owned_size());
+      this->ghosted_level_vector[to_level] = 0.;
     }
 
   const LinearAlgebra::distributed::Vector<Number> &src_vec =
@@ -217,8 +231,6 @@ MGTransferMatrixFree<dim, Number>::prolongate(
   LinearAlgebra::distributed::Vector<Number> &dst_vec =
     dst_inplace ? dst : this->ghosted_level_vector[to_level];
 
-  dst_vec = 0.;
-
   src_vec.update_ghost_values();
   // the implementation in do_prolongate_add is templated in the degree of the
   // element (for efficiency reasons), so we need to find the appropriate
@@ -250,7 +262,7 @@ MGTransferMatrixFree<dim, Number>::prolongate(
 
   dst_vec.compress(VectorOperation::add);
   if (dst_inplace == false)
-    dst.copy_locally_owned_data_from(this->ghosted_level_vector[to_level]);
+    dst += dst_vec;
 
   if (src_inplace == true)
     src.zero_out_ghost_values();
@@ -777,6 +789,30 @@ MGTransferBlockMatrixFree<dim, Number>::prolongate(
 
 
 
+template <int dim, typename Number>
+void
+MGTransferBlockMatrixFree<dim, Number>::prolongate_and_add(
+  const unsigned int                                     to_level,
+  LinearAlgebra::distributed::BlockVector<Number> &      dst,
+  const LinearAlgebra::distributed::BlockVector<Number> &src) const
+{
+  const unsigned int n_blocks = src.n_blocks();
+  AssertDimension(dst.n_blocks(), n_blocks);
+
+  if (!same_for_all)
+    AssertDimension(matrix_free_transfer_vector.size(), n_blocks);
+
+  for (unsigned int b = 0; b < n_blocks; ++b)
+    {
+      const unsigned int data_block = same_for_all ? 0 : b;
+      matrix_free_transfer_vector[data_block].prolongate_and_add(to_level,
+                                                                 dst.block(b),
+                                                                 src.block(b));
+    }
+}
+
+
+
 template <int dim, typename Number>
 void
 MGTransferBlockMatrixFree<dim, Number>::restrict_and_add(

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.