From: Daniel Arndt Date: Tue, 13 Jun 2023 16:58:18 +0000 (-0400) Subject: Fix compiling deal.II with PETSc and complex scalar type X-Git-Tag: v9.5.0-rc1~111^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2914cb200644f78e102619dea2445fc137d4dcc9;p=dealii.git Fix compiling deal.II with PETSc and complex scalar type --- 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());