]> https://gitweb.dealii.org/ - dealii.git/commitdiff
PETSc: Convert PetscScalar* iterators when calling IndexSet::add_indices 15344/head
authorDaniel Arndt <arndtd@ornl.gov>
Mon, 12 Jun 2023 13:47:36 +0000 (09:47 -0400)
committerDaniel Arndt <arndtd@ornl.gov>
Mon, 12 Jun 2023 13:48:02 +0000 (09:48 -0400)
source/lac/petsc_vector_base.cc

index 5bf541cda30a987ffe448c720291abae491a952e..a3280a8b247402b1b32d407e08861fd944641ca9 100644 (file)
@@ -183,6 +183,55 @@ namespace PETScWrappers
 
 
 
+  namespace
+  {
+    template <typename Iterator, typename OutType>
+    class ConvertingIterator
+    {
+      Iterator m_iterator;
+
+    public:
+      ConvertingIterator(const Iterator &iterator)
+        : m_iterator(iterator)
+      {}
+
+      OutType
+      operator*() const
+      {
+        return static_cast<OutType>(*m_iterator);
+      }
+
+      ConvertingIterator &
+      operator++()
+      {
+        ++m_iterator;
+        return *this;
+      }
+
+      ConvertingIterator
+      operator++(int)
+      {
+        ConvertingIterator old = *this;
+        ++m_iterator;
+        return old;
+      }
+
+      bool
+      operator==(const ConvertingIterator &other) const
+      {
+        return this->m_iterator == other.m_iterator;
+      }
+
+      bool
+      operator!=(const ConvertingIterator &other) const
+      {
+        return this->m_iterator != other.m_iterator;
+      }
+    };
+  } // namespace
+
+
+
   void
   VectorBase::determine_ghost_indices()
   {
@@ -236,8 +285,13 @@ namespace PETScWrappers
 
         if (std::is_sorted(&array[end_index - ghost_start_index],
                            &array[n_elements_stored_locally]))
-          ghost_indices.add_indices(&array[end_index - ghost_start_index],
-                                    &array[n_elements_stored_locally]);
+          {
+            ConvertingIterator<PetscScalar *, types::global_dof_index> start(
+              &array[end_index - ghost_start_index]);
+            ConvertingIterator<PetscScalar *, types::global_dof_index> end(
+              &array[n_elements_stored_locally]);
+            ghost_indices.add_indices(start, end);
+          }
         else
           {
             std::vector<PetscInt> sorted_indices(

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.