From 50288d311a61253be0b7b51a83fd2d568fb76361 Mon Sep 17 00:00:00 2001 From: David Wells Date: Tue, 20 Apr 2021 17:00:48 -0400 Subject: [PATCH] Improve the scalar assignment exception message. --- include/deal.II/base/exceptions.h | 13 ++++++++++--- include/deal.II/base/tensor.h | 3 +-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/include/deal.II/base/exceptions.h b/include/deal.II/base/exceptions.h index 73d7f8b139..de5d349bf5 100644 --- a/include/deal.II/base/exceptions.h +++ b/include/deal.II/base/exceptions.h @@ -1082,9 +1082,16 @@ namespace StandardExceptions * argument zero. In other cases, this exception is thrown. */ DeclExceptionMsg(ExcScalarAssignmentOnlyForZeroValue, - "You are trying an operation of the form 'vector=s' with " - "a nonzero scalar value 's'. However, such assignments " - "are only allowed if the right hand side is zero."); + "You are trying an operation of the form 'vector = C', " + "'matrix = C', or 'tensor = C' with a nonzero scalar value " + "'C'. However, such assignments are only allowed if the " + "C is zero, since the semantics for assigning any other " + "value are not clear. For example: one could interpret " + "assigning a matrix a value of 1 to mean the matrix has a " + "norm of 1, the matrix is the identity matrix, or the " + "matrix contains only 1s. Similar problems exist with " + "vectors and tensors. Hence, to avoid this ambiguity, such " + "assignments are not permitted."); /** * This function requires support for the LAPACK library. diff --git a/include/deal.II/base/tensor.h b/include/deal.II/base/tensor.h index c5e1e57166..dfbbd3c510 100644 --- a/include/deal.II/base/tensor.h +++ b/include/deal.II/base/tensor.h @@ -1381,8 +1381,7 @@ template DEAL_II_CONSTEXPR inline DEAL_II_ALWAYS_INLINE Tensor & Tensor::operator=(const Number &d) { - Assert(numbers::value_is_zero(d), - ExcMessage("Only assignment with zero is allowed")); + Assert(numbers::value_is_zero(d), ExcScalarAssignmentOnlyForZeroValue()); (void)d; for (unsigned int i = 0; i < dim; ++i) -- 2.39.5