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 Aug 26, 2021
1 parent 4c95111 commit 2819e98
Showing 1 changed file with 58 additions and 4 deletions.
62 changes: 58 additions & 4 deletions include/deal.II/base/tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,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 tenso 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 @@ -774,11 +785,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. As usual in C++, the rightmost index of the tensor marches
* fastest.
*
* 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 @@ -1029,6 +1057,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 @@ -1201,6 +1230,7 @@ constexpr DEAL_II_CUDA_HOST_DEV inline DEAL_II_ALWAYS_INLINE
}



template <int dim, typename Number>
template <typename Iterator>
Iterator
Expand All @@ -1215,6 +1245,7 @@ Tensor<0, dim, Number>::unroll_recursion(const Iterator current,
}



template <int dim, typename Number>
constexpr inline void
Tensor<0, dim, Number>::clear()
Expand All @@ -1225,6 +1256,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 @@ -1694,18 +1737,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 2819e98

Please sign in to comment.