From: David Wells Date: Fri, 20 Aug 2021 21:08:09 +0000 (-0400) Subject: Change Tensor::unroll() to take iterator pairs. X-Git-Tag: v9.4.0-rc1~990^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=07f4702562ae00a861b026130603713a744a92b6;p=dealii.git Change Tensor::unroll() to take iterator pairs. --- diff --git a/include/deal.II/base/tensor.h b/include/deal.II/base/tensor.h index 2f687d5d0b..874b71c4db 100644 --- a/include/deal.II/base/tensor.h +++ b/include/deal.II/base/tensor.h @@ -383,6 +383,17 @@ public: constexpr DEAL_II_CUDA_HOST_DEV real_type norm_square() const; + /** + * Fill a range with all tensor elements. Since this type of Tensor only has + * one entry this just copies the value of this tensor into *begin. + * + * The template type Number must be convertible to the type of + * *begin. + */ + template + void + unroll(const Iterator begin, const Iterator end) const; + /** * Read or write the data of this object to or from a stream for the purpose * of serialization using the [BOOST serialization @@ -792,11 +803,28 @@ public: * This function unrolls all tensor entries into a single, linearly numbered * vector. As usual in C++, the rightmost index of the tensor marches * fastest. + * + * @deprecated Use the more general function that takes a pair of iterators + * instead. */ template - void + DEAL_II_DEPRECATED_EARLY void unroll(Vector &result) const; + /** + * Fill a range with all tensor elements. + * + * This function unrolls all tensor entries into a single, linearly numbered + * sequence. The order of the elements is the one given by + * component_to_unrolled_index(). + * + * The template type Number must be convertible to the type of + * *begin. + */ + template + void + unroll(const Iterator begin, const Iterator end) const; + /** * Return an unrolled index in the range $[0,\text{dim}^{\text{rank}}-1]$ * for the element of the tensor indexed by the argument to the function. @@ -1038,6 +1066,7 @@ constexpr inline DEAL_II_ALWAYS_INLINE } + template template constexpr inline DEAL_II_ALWAYS_INLINE @@ -1210,6 +1239,7 @@ constexpr DEAL_II_CUDA_HOST_DEV inline DEAL_II_ALWAYS_INLINE } + template template Iterator @@ -1218,12 +1248,15 @@ Tensor<0, dim, Number>::unroll_recursion(const Iterator current, { Assert(dim != 0, ExcMessage("Cannot unroll an object of type Tensor<0,0,Number>")); - Assert(current != end, ExcMessage("Cannot put value in end iterator")); + Assert(std::distance(current, end) >= 1, + ExcMessage("The provided iterator range must contain at least one " + "element.")); *current = value; - return current + 1; + return std::next(current); } + template constexpr inline void Tensor<0, dim, Number>::clear() @@ -1234,6 +1267,18 @@ Tensor<0, dim, Number>::clear() } + +template +template +inline void +Tensor<0, dim, Number>::unroll(const Iterator begin, const Iterator end) const +{ + AssertDimension(std::distance(begin, end), n_independent_components); + unroll_recursion(begin, end); +} + + + template template inline void @@ -1703,18 +1748,29 @@ constexpr inline DEAL_II_ALWAYS_INLINE DEAL_II_CUDA_HOST_DEV } + template template inline void Tensor::unroll(Vector &result) const { - AssertDimension(result.size(), - (Utilities::fixed_power(dim))); + unroll(result.begin(), result.end()); +} + + - unroll_recursion(result.begin(), result.end()); +template +template +inline void +Tensor::unroll(const Iterator begin, + const Iterator end) const +{ + AssertDimension(std::distance(begin, end), n_independent_components); + unroll_recursion(begin, end); } + template template Iterator