From: Doug Shi-Dong Date: Wed, 1 Apr 2020 16:29:20 +0000 (-0400) Subject: Allow vector_adaptor to work on ghosted vectors. X-Git-Tag: v9.2.0-rc1~286^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3e9b42ea60d13e95d8b70a5239e9e4b2a1e47b48;p=dealii.git Allow vector_adaptor to work on ghosted vectors. 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. --- diff --git a/include/deal.II/lac/vector.h b/include/deal.II/lac/vector.h index 19e0151112..3f7a5bfb7a 100644 --- a/include/deal.II/lac/vector.h +++ b/include/deal.II/lac/vector.h @@ -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::compress(::dealii::VectorOperation::values) const {} +template +inline bool +Vector::has_ghost_elements() const +{ + return false; +} template inline void diff --git a/include/deal.II/optimization/rol/vector_adaptor.h b/include/deal.II/optimization/rol/vector_adaptor.h index 2ce0fd15d0..284c80c9fe 100644 --- a/include/deal.II/optimization/rol/vector_adaptor.h +++ b/include/deal.II/optimization/rol/vector_adaptor.h @@ -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 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); + } } diff --git a/tests/rol/vector_adaptor_with_ghost_01.cc b/tests/rol/vector_adaptor_with_ghost_01.cc index 71cae61468..ce327cbf69 100644 --- a/tests/rol/vector_adaptor_with_ghost_01.cc +++ b/tests/rol/vector_adaptor_with_ghost_01.cc @@ -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 a_rcp(new VectorType(a)); Teuchos::RCP b_rcp(new VectorType(b)); Teuchos::RCP 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 a_rol(a_rcp); Rol::VectorAdaptor b_rol(b_rcp);