From: Wolfgang Bangerth Date: Sun, 14 Jan 2024 04:12:02 +0000 (-0700) Subject: Peel off first element of the sequence. X-Git-Tag: relicensing~163^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7fcdb8ba1da8068b3944bcc2199b729d0de88740;p=dealii.git Peel off first element of the sequence. --- diff --git a/include/deal.II/base/tensor.h b/include/deal.II/base/tensor.h index c375d0c5a8..259215e74d 100644 --- a/include/deal.II/base/tensor.h +++ b/include/deal.II/base/tensor.h @@ -1698,14 +1698,16 @@ constexpr DEAL_II_HOST_DEVICE_ALWAYS_INLINE typename numbers::NumberTraits::real_type Tensor::norm_square() const { - if constexpr (rank_ == 1) + if constexpr (dim == 0) + return internal::NumberType< + typename numbers::NumberTraits::real_type>::value(0.0); + else if constexpr (rank_ == 1) { // For rank-1 tensors, the square of the norm is simply the sum of // squares of the elements: typename numbers::NumberTraits::real_type s = - internal::NumberType< - typename numbers::NumberTraits::real_type>::value(0.0); - for (unsigned int i = 0; i < dim; ++i) + numbers::NumberTraits::abs_square(values[0]); + for (unsigned int i = 1; i < dim; ++i) s += numbers::NumberTraits::abs_square(values[i]); return s; @@ -1715,9 +1717,8 @@ constexpr DEAL_II_HOST_DEVICE_ALWAYS_INLINE // For higher-rank tensors, the square of the norm is the sum // of squares of sub-tensors typename numbers::NumberTraits::real_type s = - internal::NumberType< - typename numbers::NumberTraits::real_type>::value(0.0); - for (unsigned int i = 0; i < dim; ++i) + values[0].norm_square(); + for (unsigned int i = 1; i < dim; ++i) s += values[i].norm_square(); return s;