From: Wolfgang Bangerth Date: Fri, 26 Jun 2020 23:54:03 +0000 (-0600) Subject: Introduce a new constructor for Tensor. X-Git-Tag: v9.3.0-rc1~1360^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8f8416a7ed413a04d09b21ac83f21f2348bacb9c;p=dealii.git Introduce a new constructor for Tensor. --- diff --git a/include/deal.II/base/tensor.h b/include/deal.II/base/tensor.h index 713e08a5d0..a2059c6016 100644 --- a/include/deal.II/base/tensor.h +++ b/include/deal.II/base/tensor.h @@ -39,6 +39,8 @@ DEAL_II_NAMESPACE_OPEN // Forward declarations: #ifndef DOXYGEN +template +class ArrayView; template class Point; template @@ -501,13 +503,30 @@ public: #endif /** - * Constructor, where the data is copied from a C-style array. + * A constructor where the data is copied from a C-style array. * * @note This function can also be used in CUDA device code. */ constexpr DEAL_II_CUDA_HOST_DEV explicit Tensor( const array_type &initializer); + /** + * A constructor where the data is copied from an ArrayView object. + * Obviously, the ArrayView object must represent a stretch of + * data of size `dim``rank`. The sequentially ordered elements + * of the argument `initializer` are interpreted as described by + * unrolled_to_component_index(). + * + * This constructor obviously requires that the @p ElementType type is + * either equal to @p Number, or is convertible to @p Number. + * Number. + * + * @note This function can also be used in CUDA device code. + */ + template + constexpr DEAL_II_CUDA_HOST_DEV explicit Tensor( + const ArrayView &initializer); + /** * Constructor from tensors with different underlying scalar type. This * obviously requires that the @p OtherNumber type is convertible to @p @@ -1153,6 +1172,21 @@ constexpr DEAL_II_ALWAYS_INLINE DEAL_II_CUDA_HOST_DEV {} + +template +template +constexpr DEAL_II_ALWAYS_INLINE DEAL_II_CUDA_HOST_DEV + Tensor::Tensor( + const ArrayView &initializer) +{ + AssertDimension(initializer.size(), n_independent_components); + + for (unsigned int i = 0; i < n_independent_components; ++i) + (*this)[unrolled_to_component_indices(i)] = initializer[i]; +} + + + template template constexpr DEAL_II_ALWAYS_INLINE DEAL_II_CUDA_HOST_DEV