From: Daniel Arndt Date: Tue, 20 Feb 2024 14:30:15 +0000 (-0500) Subject: Tpetra: Fix compiling with complex values X-Git-Tag: relicensing~13^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F16679%2Fhead;p=dealii.git Tpetra: Fix compiling with complex values --- 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; }