From: Daniel Arndt Date: Mon, 12 Jun 2023 13:47:36 +0000 (-0400) Subject: PETSc: Convert PetscScalar* iterators when calling IndexSet::add_indices X-Git-Tag: v9.5.0-rc1~127^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f4eb8987aa27c0b1ac394c014fcdfbf198ba5bb7;p=dealii.git PETSc: Convert PetscScalar* iterators when calling IndexSet::add_indices --- 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(