From 17c8567e29193182e7294c07cc73c10d6d9ed6aa Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Tue, 6 Aug 2019 16:55:33 -0600 Subject: [PATCH] Simplify SymmetricTensor constructor --- include/deal.II/base/symmetric_tensor.h | 43 ++++++------------------- 1 file changed, 9 insertions(+), 34 deletions(-) diff --git a/include/deal.II/base/symmetric_tensor.h b/include/deal.II/base/symmetric_tensor.h index b9a7adc703..57fff3af70 100644 --- a/include/deal.II/base/symmetric_tensor.h +++ b/include/deal.II/base/symmetric_tensor.h @@ -1026,42 +1026,17 @@ DEAL_II_CONSTEXPR inline DEAL_II_ALWAYS_INLINE SymmetricTensor::SymmetricTensor( const Tensor<2, dim, OtherNumber> &t) { - Assert(rank == 2, ExcNotImplemented()); - switch (dim) - { - case 2: - Assert(t[0][1] == t[1][0], ExcInternalError()); - - data[0] = t[0][0]; - data[1] = t[1][1]; - data[2] = t[0][1]; - - break; - case 3: - Assert(t[0][1] == t[1][0], ExcInternalError()); - Assert(t[0][2] == t[2][0], ExcInternalError()); - Assert(t[1][2] == t[2][1], ExcInternalError()); - - data[0] = t[0][0]; - data[1] = t[1][1]; - data[2] = t[2][2]; - data[3] = t[0][1]; - data[4] = t[0][2]; - data[5] = t[1][2]; - - break; - default: - for (unsigned int d = 0; d < dim; ++d) - for (unsigned int e = 0; e < d; ++e) - Assert(t[d][e] == t[e][d], ExcInternalError()); + static_assert(rank == 2, "This function is only implemented for rank==2"); + for (unsigned int d = 0; d < dim; ++d) + for (unsigned int e = 0; e < d; ++e) + Assert(t[d][e] == t[e][d], ExcInternalError()); - for (unsigned int d = 0; d < dim; ++d) - data[d] = t[d][d]; + for (unsigned int d = 0; d < dim; ++d) + data[d] = t[d][d]; - for (unsigned int d = 0, c = 0; d < dim; ++d) - for (unsigned int e = d + 1; e < dim; ++e, ++c) - data[dim + c] = t[d][e]; - } + for (unsigned int d = 0, c = 0; d < dim; ++d) + for (unsigned int e = d + 1; e < dim; ++e, ++c) + data[dim + c] = t[d][e]; } -- 2.39.5