Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tpetra: Fix compiling with complex values #16679

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions include/deal.II/lac/read_write_vector.templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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;
Expand All @@ -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;

Expand Down
40 changes: 24 additions & 16 deletions include/deal.II/lac/trilinos_tpetra_vector.templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -835,26 +835,34 @@ namespace LinearAlgebra
bool
Vector<Number, MemorySpace>::is_non_negative() const
{
// get a representation of the vector and
// loop over all the elements
Teuchos::ArrayRCP<const Number> 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<Number, std::complex<double>> &&
!std::is_same_v<Number, std::complex<float>>)
{
if (data[i] < Number(0))
// get a representation of the vector and
// loop over all the elements
Teuchos::ArrayRCP<const Number> 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;
}


Expand Down