]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Introduce a new constructor for Tensor.
authorWolfgang Bangerth <bangerth@colostate.edu>
Fri, 26 Jun 2020 23:54:03 +0000 (17:54 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Sat, 27 Jun 2020 12:30:44 +0000 (06:30 -0600)
include/deal.II/base/tensor.h

index 713e08a5d0484df1097b40a982d3e42cc6e6ed4b..a2059c6016fcb51488f1d668e53161e54ddc7eb3 100644 (file)
@@ -39,6 +39,8 @@ DEAL_II_NAMESPACE_OPEN
 
 // Forward declarations:
 #ifndef DOXYGEN
+template <typename ElementType, typename MemorySpace>
+class ArrayView;
 template <int dim, typename Number>
 class Point;
 template <int rank_, int dim, typename Number = double>
@@ -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`<sup>`rank`</sup>. 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 <typename ElementType, typename MemorySpace>
+  constexpr DEAL_II_CUDA_HOST_DEV explicit Tensor(
+    const ArrayView<ElementType, MemorySpace> &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 <int rank_, int dim, typename Number>
+template <typename ElementType, typename MemorySpace>
+constexpr DEAL_II_ALWAYS_INLINE DEAL_II_CUDA_HOST_DEV
+                                Tensor<rank_, dim, Number>::Tensor(
+  const ArrayView<ElementType, MemorySpace> &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 <int rank_, int dim, typename Number>
 template <typename OtherNumber>
 constexpr DEAL_II_ALWAYS_INLINE DEAL_II_CUDA_HOST_DEV

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.