@@ -109,6 +109,22 @@ class Tensor
109
109
" Filling the tensor on initialisation is only permitted for 1D vector objects" );
110
110
}
111
111
112
+ /* *
113
+ * @brief Construct a 1D tensor object from a coordinate.
114
+ *
115
+ * @param coord The coordinate.
116
+ */
117
+ template <class ... Dims>
118
+ explicit KOKKOS_FUNCTION Tensor (Coord<Dims...> coord) : m_data(coord.array())
119
+ {
120
+ static_assert (
121
+ rank () == 1 ,
122
+ " Filling the tensor on initialisation is only permitted for 1D vector objects" );
123
+ static_assert (
124
+ std::is_same_v<VectorIndexSet<Dims...>, ddc::type_seq_element_t <0 , index_set>>,
125
+ " The coordinate must have the same memory layout to make a clean conversion." );
126
+ }
127
+
112
128
/* *
113
129
* @brief Construct a tensor object by copying an existing tensor.
114
130
*
@@ -151,6 +167,24 @@ class Tensor
151
167
*/
152
168
KOKKOS_DEFAULTED_FUNCTION Tensor& operator =(Tensor const & other) = default ;
153
169
170
+ /* *
171
+ * @brief A copy operator.
172
+ * @param coord The coordinate to be copied into the vector.
173
+ * @return A reference to the current tensor.
174
+ */
175
+ template <class ... Dims>
176
+ KOKKOS_FUNCTION Tensor& operator =(Coord<Dims...> coord)
177
+ {
178
+ static_assert (
179
+ rank () == 1 ,
180
+ " Copying a coordinate into a tensor is only possible for 1D tensor objects" );
181
+ static_assert (
182
+ std::is_same_v<VectorIndexSet<Dims...>, ddc::type_seq_element_t <0 , index_set>>,
183
+ " The coordinate must have the same memory layout to make a clean conversion." );
184
+ m_data = coord.array ();
185
+ return *this ;
186
+ }
187
+
154
188
/* *
155
189
* @brief An operator to multiply all the element of the current tensor by
156
190
* a value.
@@ -295,9 +329,6 @@ using to_tensor_t = typename detail::ToTensor<ElementType, TypeSeqValidIndexSet>
295
329
template <class ... ValidIndexSet>
296
330
using DTensor = Tensor<double , ValidIndexSet...>;
297
331
298
- // These objects should be extricated from the namespace in a later PR
299
- namespace tensor_tools {
300
-
301
332
/* *
302
333
* @brief A helper type alias to get a 1D tensor (a vector).
303
334
* @tparam ElementType The type of the elements of the tensor (usually double/complex).
@@ -313,8 +344,6 @@ using Vector = Tensor<ElementType, VectorIndexSet<Dims...>>;
313
344
template <class ... Dims>
314
345
using DVector = Vector<double , Dims...>;
315
346
316
- } // namespace tensor_tools
317
-
318
347
// ////////////////////////////////////////////////////////////////////////
319
348
// Operators
320
349
// ////////////////////////////////////////////////////////////////////////
0 commit comments