]> https://gitweb.dealii.org/ - dealii.git/commitdiff
LinearAlgebra::ReadWriteVector accept serial vectors 11938/head
authorPeter Munch <peterrmuench@gmail.com>
Thu, 18 Mar 2021 09:02:53 +0000 (10:02 +0100)
committerPeter Munch <peterrmuench@gmail.com>
Thu, 18 Mar 2021 09:02:53 +0000 (10:02 +0100)
doc/news/changes/minor/20210318Munch [new file with mode: 0644]
include/deal.II/lac/read_write_vector.h
include/deal.II/lac/read_write_vector.templates.h

diff --git a/doc/news/changes/minor/20210318Munch b/doc/news/changes/minor/20210318Munch
new file mode 100644 (file)
index 0000000..32227fe
--- /dev/null
@@ -0,0 +1,5 @@
+Improved: The class LinearAlgebra::ReadWriteVector now also can import
+from Vector and LinearAlgebra::Vector.
+<br>
+(Peter Munch, 2021/03/18)
+
index 8f799efd4c4b4c145b7df4c9ae6ba962a7954c45..87cf1ada46f93efe5001b42be289087baff2b977 100644 (file)
@@ -47,6 +47,8 @@ DEAL_II_NAMESPACE_OPEN
 #ifndef DOXYGEN
 namespace LinearAlgebra
 {
+  template <typename>
+  class Vector;
   namespace distributed
   {
     template <typename, typename>
@@ -283,6 +285,36 @@ namespace LinearAlgebra
     ReadWriteVector<Number> &
     operator=(const Number s);
 
+    /**
+     * Imports all the elements present in the vector's IndexSet from the
+     * input vector @p vec. VectorOperation::values @p operation
+     * is used to decide if the elements in @p V should be added to the
+     * current vector or replace the current elements.
+     *
+     * @note The parameter @p communication_pattern is ignored since we are
+     *   dealing with a serial vector here.
+     */
+    void
+    import(const dealii::Vector<Number> &vec,
+           VectorOperation::values       operation,
+           const std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
+             &communication_pattern = {});
+
+    /**
+     * Imports all the elements present in the vector's IndexSet from the
+     * input vector @p vec. VectorOperation::values @p operation
+     * is used to decide if the elements in @p V should be added to the
+     * current vector or replace the current elements.
+     *
+     * @note The parameter @p communication_pattern is ignored since we are
+     *   dealing with a serial vector here.
+     */
+    void
+    import(const LinearAlgebra::Vector<Number> &vec,
+           VectorOperation::values              operation,
+           const std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
+             &communication_pattern = {});
+
     /**
      * Imports all the elements present in the vector's IndexSet from the
      * input vector @p vec. VectorOperation::values @p operation
index 3d87efef2343fb36e7b6c3d1920c5da378526eac..3ddfaca6f8e5cd95e06413a9086321f17a5d3d42 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <deal.II/lac/exceptions.h>
 #include <deal.II/lac/la_parallel_vector.h>
+#include <deal.II/lac/la_vector.h>
 #include <deal.II/lac/read_write_vector.h>
 #include <deal.II/lac/vector_operations_internal.h>
 
@@ -409,6 +410,68 @@ namespace LinearAlgebra
 
 
 
+  namespace internal
+  {
+    template <typename VectorType, typename Number>
+    void
+    import_serial_vector(const VectorType &       values,
+                         VectorOperation::values  operation,
+                         ReadWriteVector<Number> &rw_vector)
+    {
+      using size_type = types::global_dof_index;
+
+      const IndexSet &stored = rw_vector.get_stored_elements();
+      if (operation == VectorOperation::add)
+        for (size_type i = 0; i < stored.n_elements(); ++i)
+          rw_vector.local_element(i) += values(stored.nth_index_in_set(i));
+      else if (operation == VectorOperation::min)
+        for (size_type i = 0; i < stored.n_elements(); ++i)
+          rw_vector.local_element(i) =
+            get_min(values(stored.nth_index_in_set(i)),
+                    rw_vector.local_element(i));
+      else if (operation == VectorOperation::max)
+        for (size_type i = 0; i < stored.n_elements(); ++i)
+          rw_vector.local_element(i) =
+            get_max(values(stored.nth_index_in_set(i)),
+                    rw_vector.local_element(i));
+      else
+        for (size_type i = 0; i < stored.n_elements(); ++i)
+          rw_vector.local_element(i) = values(stored.nth_index_in_set(i));
+    }
+  } // namespace internal
+
+
+
+  template <typename Number>
+  void
+  ReadWriteVector<Number>::import(
+    const dealii::Vector<Number> &vec,
+    VectorOperation::values       operation,
+    const std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
+      &communication_pattern)
+  {
+    (void)communication_pattern;
+
+    internal::import_serial_vector(vec, operation, *this);
+  }
+
+
+
+  template <typename Number>
+  void
+  ReadWriteVector<Number>::import(
+    const LinearAlgebra::Vector<Number> &vec,
+    VectorOperation::values              operation,
+    const std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
+      &communication_pattern)
+  {
+    (void)communication_pattern;
+
+    internal::import_serial_vector(vec, operation, *this);
+  }
+
+
+
   template <typename Number>
   template <typename MemorySpace>
   void

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.