From: David Wells Date: Sat, 11 Nov 2023 17:10:03 +0000 (-0500) Subject: SymmetricTensor: move up component_to_unrolled_index(). X-Git-Tag: relicensing~304^2~4 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7b961ea2ca90ed0acce002aa9b492de2621b9636;p=dealii.git SymmetricTensor: move up component_to_unrolled_index(). --- diff --git a/include/deal.II/base/symmetric_tensor.h b/include/deal.II/base/symmetric_tensor.h index 89ad3b399a..401eb5996e 100644 --- a/include/deal.II/base/symmetric_tensor.h +++ b/include/deal.II/base/symmetric_tensor.h @@ -2005,6 +2005,87 @@ DEAL_II_HOST DEAL_II_CONSTEXPR inline // into a separate namespace namespace internal { + namespace SymmetricTensorImplementation + { + // a function to do the unrolling from a set of indices to a + // scalar index into the array in which we store the elements of + // a symmetric tensor + // + // this function is for rank-2 tensors + template + constexpr inline DEAL_II_ALWAYS_INLINE unsigned int + component_to_unrolled_index(const TableIndices<2> &indices) + { + AssertIndexRange(indices[0], dim); + AssertIndexRange(indices[1], dim); + + switch (dim) + { + case 1: + { + return 0; + } + + case 2: + { + constexpr unsigned int table[2][2] = {{0, 2}, {2, 1}}; + return table[indices[0]][indices[1]]; + } + + case 3: + { + constexpr unsigned int table[3][3] = {{0, 3, 4}, + {3, 1, 5}, + {4, 5, 2}}; + return table[indices[0]][indices[1]]; + } + + case 4: + { + constexpr unsigned int table[4][4] = {{0, 4, 5, 6}, + {4, 1, 7, 8}, + {5, 7, 2, 9}, + {6, 8, 9, 3}}; + return table[indices[0]][indices[1]]; + } + + default: + // for the remainder, manually figure out the numbering + { + if (indices[0] == indices[1]) + return indices[0]; + + TableIndices<2> sorted_indices(indices); + sorted_indices.sort(); + + for (unsigned int d = 0, c = 0; d < dim; ++d) + for (unsigned int e = d + 1; e < dim; ++e, ++c) + if ((sorted_indices[0] == d) && (sorted_indices[1] == e)) + return dim + c; + + // should never get here: + Assert(false, ExcInternalError()); + return 0; + } + } + } + + // a function to do the unrolling from a set of indices to a + // scalar index into the array in which we store the elements of + // a symmetric tensor + // + // this function is for tensors of ranks not already handled + // above + template + constexpr inline unsigned int + component_to_unrolled_index(const TableIndices &indices) + { + (void)indices; + Assert(false, ExcNotImplemented()); + return numbers::invalid_unsigned_int; + } + } // namespace SymmetricTensorImplementation + template constexpr inline DEAL_II_ALWAYS_INLINE Number & symmetric_tensor_access(const TableIndices<2> &indices, @@ -2460,91 +2541,6 @@ SymmetricTensor::norm() const -namespace internal -{ - namespace SymmetricTensorImplementation - { - // a function to do the unrolling from a set of indices to a - // scalar index into the array in which we store the elements of - // a symmetric tensor - // - // this function is for rank-2 tensors - template - constexpr inline DEAL_II_ALWAYS_INLINE unsigned int - component_to_unrolled_index(const TableIndices<2> &indices) - { - AssertIndexRange(indices[0], dim); - AssertIndexRange(indices[1], dim); - - switch (dim) - { - case 1: - { - return 0; - } - - case 2: - { - constexpr unsigned int table[2][2] = {{0, 2}, {2, 1}}; - return table[indices[0]][indices[1]]; - } - - case 3: - { - constexpr unsigned int table[3][3] = {{0, 3, 4}, - {3, 1, 5}, - {4, 5, 2}}; - return table[indices[0]][indices[1]]; - } - - case 4: - { - constexpr unsigned int table[4][4] = {{0, 4, 5, 6}, - {4, 1, 7, 8}, - {5, 7, 2, 9}, - {6, 8, 9, 3}}; - return table[indices[0]][indices[1]]; - } - - default: - // for the remainder, manually figure out the numbering - { - if (indices[0] == indices[1]) - return indices[0]; - - TableIndices<2> sorted_indices(indices); - sorted_indices.sort(); - - for (unsigned int d = 0, c = 0; d < dim; ++d) - for (unsigned int e = d + 1; e < dim; ++e, ++c) - if ((sorted_indices[0] == d) && (sorted_indices[1] == e)) - return dim + c; - - // should never get here: - Assert(false, ExcInternalError()); - return 0; - } - } - } - - // a function to do the unrolling from a set of indices to a - // scalar index into the array in which we store the elements of - // a symmetric tensor - // - // this function is for tensors of ranks not already handled - // above - template - constexpr inline unsigned int - component_to_unrolled_index(const TableIndices &indices) - { - (void)indices; - Assert(false, ExcNotImplemented()); - return numbers::invalid_unsigned_int; - } - } // namespace SymmetricTensorImplementation -} // namespace internal - - template DEAL_II_HOST constexpr unsigned int SymmetricTensor::component_to_unrolled_index(