Skip to content

Commit

Permalink
Change Tensor::unroll() to take iterator pairs.
Browse files Browse the repository at this point in the history
  • Loading branch information
drwells committed Sep 7, 2021
1 parent 3042d03 commit c2162af
Showing 1 changed file with 62 additions and 6 deletions.
68 changes: 62 additions & 6 deletions include/deal.II/base/tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,17 @@ class Tensor<0, dim, Number>
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 <tt>*begin</tt>.
*
* The template type Number must be convertible to the type of
* <tt>*begin</tt>.
*/
template <class Iterator>
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
Expand Down Expand Up @@ -792,11 +803,28 @@ class Tensor
* 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 <typename OtherNumber>
void
DEAL_II_DEPRECATED_EARLY void
unroll(Vector<OtherNumber> &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
* <tt>*begin</tt>.
*/
template <class Iterator>
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.
Expand Down Expand Up @@ -1038,6 +1066,7 @@ constexpr inline DEAL_II_ALWAYS_INLINE
}



template <int dim, typename Number>
template <typename OtherNumber>
constexpr inline DEAL_II_ALWAYS_INLINE
Expand Down Expand Up @@ -1210,6 +1239,7 @@ constexpr DEAL_II_CUDA_HOST_DEV inline DEAL_II_ALWAYS_INLINE
}



template <int dim, typename Number>
template <typename Iterator>
Iterator
Expand All @@ -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 exactly one "
"element."));
*current = value;
return current + 1;
return std::next(current);
}



template <int dim, typename Number>
constexpr inline void
Tensor<0, dim, Number>::clear()
Expand All @@ -1234,6 +1267,18 @@ Tensor<0, dim, Number>::clear()
}



template <int dim, typename Number>
template <class Iterator>
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 <int dim, typename Number>
template <class Archive>
inline void
Expand Down Expand Up @@ -1703,18 +1748,29 @@ constexpr inline DEAL_II_ALWAYS_INLINE DEAL_II_CUDA_HOST_DEV
}



template <int rank_, int dim, typename Number>
template <typename OtherNumber>
inline void
Tensor<rank_, dim, Number>::unroll(Vector<OtherNumber> &result) const
{
AssertDimension(result.size(),
(Utilities::fixed_power<rank_, unsigned int>(dim)));
unroll(result.begin(), result.end());
}



unroll_recursion(result.begin(), result.end());
template <int rank_, int dim, typename Number>
template <class Iterator>
inline void
Tensor<rank_, dim, Number>::unroll(const Iterator begin,
const Iterator end) const
{
AssertDimension(std::distance(begin, end), n_independent_components);
unroll_recursion(begin, end);
}



template <int rank_, int dim, typename Number>
template <typename Iterator>
Iterator
Expand Down

0 comments on commit c2162af

Please sign in to comment.