]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Allow vector_adaptor to work on ghosted vectors. 9792/head
authorDoug Shi-Dong <doug.shidong@gmail.com>
Wed, 1 Apr 2020 16:29:20 +0000 (12:29 -0400)
committerDoug Shi-Dong <doug.shidong@gmail.com>
Thu, 2 Apr 2020 00:34:30 +0000 (20:34 -0400)
Previous implementation did not work on ghosted vectors since it used
compress().

The test on ghosted vectors did not truly test for ghosted vectors
since it used the copy constructor of LA::distributed::Vector,
which does not fill the ghosted entries.

include/deal.II/lac/vector.h
include/deal.II/optimization/rol/vector_adaptor.h
tests/rol/vector_adaptor_with_ghost_01.cc

index 19e0151112ea52f976dc2c55a057e6ef94b5fdd4..3f7a5bfb7ae557de741b0b93bb65c274f1f700df 100644 (file)
@@ -1007,6 +1007,14 @@ public:
    */
   std::size_t
   memory_consumption() const;
+
+  /**
+   * This function exists for compatibility with the @p
+   * parallel vector classes (e.g., LinearAlgebra::distributed::Vector class).
+   * Always returns false since this implementation is serial.
+   */
+  bool
+  has_ghost_elements() const;
   //@}
 
 private:
@@ -1311,6 +1319,12 @@ inline void Vector<Number>::compress(::dealii::VectorOperation::values) const
 {}
 
 
+template <typename Number>
+inline bool
+Vector<Number>::has_ghost_elements() const
+{
+  return false;
+}
 
 template <typename Number>
 inline void
index 2ce0fd15d0d8435e6aec6bd96e114752a50328c9..284c80c9fe8b07dfc708d42622509bd6b18131cb 100644 (file)
@@ -396,7 +396,14 @@ namespace Rol
     if (vector_ptr->locally_owned_elements().is_element(i))
       vec_ptr->operator[](i) = 1.;
 
-    vec_ptr->compress(VectorOperation::insert);
+    if (vec_ptr->has_ghost_elements())
+      {
+        vec_ptr->update_ghost_values();
+      }
+    else
+      {
+        vec_ptr->compress(VectorOperation::insert);
+      }
 
     Teuchos::RCP<VectorAdaptor> e = Teuchos::rcp(new VectorAdaptor(vec_ptr));
 
@@ -417,7 +424,14 @@ namespace Rol
          iterator++)
       *iterator = f.apply(*iterator);
 
-    vector_ptr->compress(VectorOperation::insert);
+    if (vector_ptr->has_ghost_elements())
+      {
+        vector_ptr->update_ghost_values();
+      }
+    else
+      {
+        vector_ptr->compress(VectorOperation::insert);
+      }
   }
 
 
@@ -445,7 +459,14 @@ namespace Rol
          l_iterator++, r_iterator++)
       *l_iterator = f.apply(*l_iterator, *r_iterator);
 
-    vector_ptr->compress(VectorOperation::insert);
+    if (vector_ptr->has_ghost_elements())
+      {
+        vector_ptr->update_ghost_values();
+      }
+    else
+      {
+        vector_ptr->compress(VectorOperation::insert);
+      }
   }
 
 
index 71cae61468437e3f2cbe6df654e34f753720dfe9..ce327cbf690f78f668f600532a65547c8f643ac6 100644 (file)
@@ -92,10 +92,18 @@ test()
   b.compress(VectorOperation::insert);
   c.compress(VectorOperation::insert);
 
+  a.update_ghost_values();
+  b.update_ghost_values();
+  c.update_ghost_values();
+
   Teuchos::RCP<VectorType> a_rcp(new VectorType(a));
   Teuchos::RCP<VectorType> b_rcp(new VectorType(b));
   Teuchos::RCP<VectorType> c_rcp(new VectorType(c));
 
+  a_rcp->update_ghost_values();
+  b_rcp->update_ghost_values();
+  c_rcp->update_ghost_values();
+
   // --- Testing the constructor
   Rol::VectorAdaptor<VectorType> a_rol(a_rcp);
   Rol::VectorAdaptor<VectorType> b_rol(b_rcp);

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.