From b47ccc391e18808d161407299d7576657ba827eb Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Tue, 20 Feb 2024 09:30:15 -0500 Subject: [PATCH] Tpetra: Fix compiling with complex values --- .../deal.II/lac/read_write_vector.templates.h | 14 +++---- .../lac/trilinos_tpetra_vector.templates.h | 40 +++++++++++-------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/include/deal.II/lac/read_write_vector.templates.h b/include/deal.II/lac/read_write_vector.templates.h index c72a04c8c7..f5ec41ac66 100644 --- a/include/deal.II/lac/read_write_vector.templates.h +++ b/include/deal.II/lac/read_write_vector.templates.h @@ -593,12 +593,12 @@ namespace LinearAlgebra { case VectorOperation::insert: for (size_type i = 0; i < size; ++i) - values[i] = new_values(i); + values[i] = Number(new_values(i)); break; case VectorOperation::add: for (size_type i = 0; i < size; ++i) - values[i] += new_values(i); + values[i] += Number(new_values(i)); break; case VectorOperation::min: @@ -609,14 +609,14 @@ namespace LinearAlgebra for (size_type i = 0; i < size; ++i) { Assert( - std::imag(new_values(i)) == 0., + std::imag(Number(new_values(i))) == 0., ExcMessage( "VectorOperation::min is not defined if there is an imaginary part!)")); Assert( std::imag(values[i]) == 0., ExcMessage( "VectorOperation::min is not defined if there is an imaginary part!)")); - if (std::real(new_values(i)) - std::real(values[i]) < 0.0) + if (std::real(Number(new_values(i))) - std::real(values[i]) < 0.0) values[i] = new_values(i); } break; @@ -625,15 +625,15 @@ namespace LinearAlgebra for (size_type i = 0; i < size; ++i) { Assert( - std::imag(new_values(i)) == 0., + std::imag(Number(new_values(i))) == 0., ExcMessage( "VectorOperation::max is not defined if there is an imaginary part!)")); Assert( std::imag(values[i]) == 0., ExcMessage( "VectorOperation::max is not defined if there is an imaginary part!)")); - if (std::real(new_values(i)) - std::real(values[i]) > 0.0) - values[i] = new_values(i); + if (std::real(Number(new_values(i))) - std::real(values[i]) > 0.0) + values[i] = Number(new_values(i)); } break; diff --git a/include/deal.II/lac/trilinos_tpetra_vector.templates.h b/include/deal.II/lac/trilinos_tpetra_vector.templates.h index 04fd620478..548c36e1a8 100644 --- a/include/deal.II/lac/trilinos_tpetra_vector.templates.h +++ b/include/deal.II/lac/trilinos_tpetra_vector.templates.h @@ -835,26 +835,34 @@ namespace LinearAlgebra bool Vector::is_non_negative() const { - // get a representation of the vector and - // loop over all the elements - Teuchos::ArrayRCP data = vector->getData(); - const size_type n_elements = vector->getLocalLength(); - unsigned int flag = 0; - for (size_type i = 0; i < n_elements; ++i) + if constexpr (!std::is_same_v> && + !std::is_same_v>) { - if (data[i] < Number(0)) + // get a representation of the vector and + // loop over all the elements + Teuchos::ArrayRCP data = vector->getData(); + const size_type n_elements = vector->getLocalLength(); + unsigned int flag = 0; + for (size_type i = 0; i < n_elements; ++i) { - flag = 1; - break; + if (data[i] < Number(0)) + { + flag = 1; + break; + } } - } - // Check that the vector is non-negative on _all_ processors. - unsigned int num_negative = - Utilities::MPI::sum(flag, - Utilities::Trilinos::teuchos_comm_to_mpi_comm( - vector->getMap()->getComm())); - return num_negative == 0; + // Check that the vector is non-negative on _all_ processors. + unsigned int num_negative = + Utilities::MPI::sum(flag, + Utilities::Trilinos::teuchos_comm_to_mpi_comm( + vector->getMap()->getComm())); + return num_negative == 0; + } + Assert(false, + ExcMessage("You can't ask a complex value " + "whether it is non-negative.")); + return true; } -- 2.39.5