From 2914cb200644f78e102619dea2445fc137d4dcc9 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Tue, 13 Jun 2023 12:58:18 -0400 Subject: [PATCH] Fix compiling deal.II with PETSc and complex scalar type --- .../vector_tools_mean_value.templates.h | 4 +++- source/lac/petsc_vector_base.cc | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/include/deal.II/numerics/vector_tools_mean_value.templates.h b/include/deal.II/numerics/vector_tools_mean_value.templates.h index 94de319928..6a96f58718 100644 --- a/include/deal.II/numerics/vector_tools_mean_value.templates.h +++ b/include/deal.II/numerics/vector_tools_mean_value.templates.h @@ -209,7 +209,9 @@ namespace VectorTools continue; // Then adjust its value: - solution(idx) = copy(idx) + constant_adjustment; + solution(idx) = + typename VectorType::value_type(copy(idx)) + + constant_adjustment; } } } diff --git a/source/lac/petsc_vector_base.cc b/source/lac/petsc_vector_base.cc index a3280a8b24..8e1429a399 100644 --- a/source/lac/petsc_vector_base.cc +++ b/source/lac/petsc_vector_base.cc @@ -198,7 +198,7 @@ namespace PETScWrappers OutType operator*() const { - return static_cast(*m_iterator); + return static_cast(std::real(*m_iterator)); } ConvertingIterator & @@ -284,7 +284,10 @@ namespace PETScWrappers ghost_indices.set_size(this->size()); if (std::is_sorted(&array[end_index - ghost_start_index], - &array[n_elements_stored_locally])) + &array[n_elements_stored_locally], + [](PetscScalar left, PetscScalar right) { + return std::real(left) < std::real(right); + })) { ConvertingIterator start( &array[end_index - ghost_start_index]); @@ -294,9 +297,14 @@ namespace PETScWrappers } else { - std::vector sorted_indices( - &array[end_index - ghost_start_index], - &array[n_elements_stored_locally]); + std::vector sorted_indices; + sorted_indices.reserve(n_elements_stored_locally - + (end_index - ghost_start_index)); + for (PetscInt i = end_index - ghost_start_index; + i < n_elements_stored_locally; + ++i) + sorted_indices.push_back( + static_cast(std::real(array[i]))); std::sort(sorted_indices.begin(), sorted_indices.end()); ghost_indices.add_indices(sorted_indices.begin(), sorted_indices.end()); -- 2.39.5