From f4eb8987aa27c0b1ac394c014fcdfbf198ba5bb7 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Mon, 12 Jun 2023 09:47:36 -0400 Subject: [PATCH] PETSc: Convert PetscScalar* iterators when calling IndexSet::add_indices --- source/lac/petsc_vector_base.cc | 58 +++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/source/lac/petsc_vector_base.cc b/source/lac/petsc_vector_base.cc index 5bf541cda3..a3280a8b24 100644 --- a/source/lac/petsc_vector_base.cc +++ b/source/lac/petsc_vector_base.cc @@ -183,6 +183,55 @@ namespace PETScWrappers + namespace + { + template + class ConvertingIterator + { + Iterator m_iterator; + + public: + ConvertingIterator(const Iterator &iterator) + : m_iterator(iterator) + {} + + OutType + operator*() const + { + return static_cast(*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 start( + &array[end_index - ghost_start_index]); + ConvertingIterator end( + &array[n_elements_stored_locally]); + ghost_indices.add_indices(start, end); + } else { std::vector sorted_indices( -- 2.39.5