Gyselalib++
vector_field_mem.hpp
1 // SPDX-License-Identifier: MIT
2 
3 #pragma once
4 #include <ddc/ddc.hpp>
5 
6 #include "ddc_alias_inline_functions.hpp"
7 #include "ddc_aliases.hpp"
8 #include "vector_field_common.hpp"
9 
13 template <
14  class ElementType,
15  class IdxRangeType,
16  class NDTag,
17  class MemSpace = Kokkos::DefaultExecutionSpace::memory_space>
18 class VectorFieldMem;
19 
20 
21 template <class ElementType, class IdxRangeType, class DimSeq, class MemSpace>
22 inline constexpr bool
23  enable_vector_field<VectorFieldMem<ElementType, IdxRangeType, DimSeq, MemSpace>> = true;
24 
25 template <class ElementType, class IdxRangeType, class DimSeq, class Allocator>
26 inline constexpr bool enable_data_access_methods<
28 
29 template <class ElementType, class IdxRangeType, class DimSeq, class Allocator>
30 inline constexpr bool
31  enable_mem_type<VectorFieldMem<ElementType, IdxRangeType, DimSeq, Allocator>> = true;
32 
36 template <class, class, class, class, class>
37 class VectorField;
38 
51 template <class ElementType, class IdxRangeType, class NDTag, class MemSpace>
53  : public VectorFieldCommon<FieldMem<ElementType, IdxRangeType, MemSpace>, NDTag>
54 {
55 public:
63  using chunk_type = FieldMem<ElementType, IdxRangeType, MemSpace>;
64 
65 private:
67 
68 public:
70  using typename base_type::element_type;
71 
72  using typename base_type::NDTypeTag;
73 
74  using typename base_type::chunk_span_type;
75  using typename base_type::chunk_view_type;
76 
78  using Allocator = ddc::KokkosAllocator<ElementType, MemSpace>;
79 
80 public:
87  ElementType,
88  IdxRangeType,
89  NDTag,
90  MemSpace,
91  std::experimental::layout_right>;
92 
99  const ElementType,
100  IdxRangeType,
101  NDTag,
102  MemSpace,
103  std::experimental::layout_right>;
104 
110  using discrete_domain_type = typename base_type::discrete_domain_type;
113 
117  using memory_space = typename chunk_type::memory_space;
118 
119 private:
121  template <std::size_t... Is>
122  explicit VectorFieldMem(
123  index_range_type const& idx_range,
124  Allocator allocator,
125  std::index_sequence<Is...> const&)
126  : base_type(((void)Is, chunk_type(idx_range, allocator))...)
127  {
128  }
129 
134  template <class... ODDims, typename T, T... ints>
135  element_type operator()(Idx<ODDims...> const& delems, std::integer_sequence<T, ints...>)
136  const noexcept
137  {
138  return element_type((base_type::m_values[ints](delems))...);
139  }
140 
141 public:
143  VectorFieldMem() = default;
144 
151  explicit VectorFieldMem(index_range_type const& idx_range, Allocator allocator = Allocator())
152  : VectorFieldMem(idx_range, allocator, std::make_index_sequence<base_type::NDims> {})
153  {
154  }
155 
157  VectorFieldMem(VectorFieldMem const& other) = delete;
158 
163  VectorFieldMem(VectorFieldMem&& other) = default;
164 
166  VectorFieldMem& operator=(VectorFieldMem const& other) = delete;
167 
174 
175  ~VectorFieldMem() = default;
176 
186  {
187  return view_type(*this);
188  }
189 
199  {
200  return view_type(*this);
201  }
202 
212  {
213  return span_type(*this);
214  }
215 
220  template <class... ODDims>
221  element_type operator()(Idx<ODDims> const&... delems) const noexcept
222  {
223  Idx<ODDims...> delem_idx(delems...);
224  return this->
225  operator()(delem_idx, std::make_integer_sequence<int, element_type::size()> {});
226  }
227 
232  template <class... ODDims, class = std::enable_if_t<sizeof...(ODDims) != 1>>
233  element_type operator()(Idx<ODDims...> const& delems) const noexcept
234  {
235  return this->operator()(delems, std::make_integer_sequence<int, element_type::size()> {});
236  }
237 
238 
249  template <class... QueryDDims>
250  auto operator[](Idx<QueryDDims...> const& slice_spec) const
251  {
252  return span_cview()[slice_spec];
253  }
254 
265  template <class... QueryDDims>
266  auto operator[](Idx<QueryDDims...> const& slice_spec)
267  {
268  return span_view()[slice_spec];
269  }
270 
280  template <class... QueryDDims>
281  auto operator[](IdxRange<QueryDDims...> const& oidx_range) const
282  {
283  return span_cview()[oidx_range];
284  }
285 
295  template <class... QueryDDims>
296  auto operator[](IdxRange<QueryDDims...> const& oidx_range)
297  {
298  return span_view()[oidx_range];
299  }
300 
306  template <class QueryTag>
307  inline constexpr chunk_span_type get() noexcept
308  {
309  static_assert(
310  ddc::in_tags_v<QueryTag, NDTypeTag>,
311  "requested Tag absent from TaggedVector");
312  return base_type::m_values[ddc::type_seq_rank_v<QueryTag, NDTypeTag>].span_view();
313  }
314 
320  template <class QueryTag>
321  inline constexpr chunk_view_type get() const noexcept
322  {
323  static_assert(
324  ddc::in_tags_v<QueryTag, NDTypeTag>,
325  "requested Tag absent from TaggedVector");
326  return base_type::m_values[ddc::type_seq_rank_v<QueryTag, NDTypeTag>].span_cview();
327  }
328 };
Definition: vector_field_common.hpp:9
Pre-declaration of VectorFieldMem.
Definition: vector_field_mem.hpp:54
view_type span_view() const
Get a constant reference to this vector field.
Definition: vector_field_mem.hpp:198
element_type operator()(Idx< ODDims > const &... delems) const noexcept
Element access using a list of Idxs.
Definition: vector_field_mem.hpp:221
VectorFieldMem(VectorFieldMem const &other)=delete
Deleted: use deepcopy instead.
auto operator[](Idx< QueryDDims... > const &slice_spec)
Slice out some dimensions.
Definition: vector_field_mem.hpp:266
constexpr chunk_span_type get() noexcept
Get the Field describing the component in the QueryTag direction.
Definition: vector_field_mem.hpp:307
auto operator[](IdxRange< QueryDDims... > const &oidx_range) const
Slice out some dimensions.
Definition: vector_field_mem.hpp:281
VectorField< const ElementType, IdxRangeType, NDTag, MemSpace, std::experimental::layout_right > view_type
A type which can hold a constant reference to this VectorFieldMem.
Definition: vector_field_mem.hpp:103
VectorFieldMem(VectorFieldMem &&other)=default
Constructs a new VectorFieldMem by move.
auto operator[](Idx< QueryDDims... > const &slice_spec) const
Slice out some dimensions.
Definition: vector_field_mem.hpp:250
VectorField< ElementType, IdxRangeType, NDTag, MemSpace, std::experimental::layout_right > span_type
A type which can hold a reference to this VectorFieldMem.
Definition: vector_field_mem.hpp:91
FieldMem< ElementType, IdxRangeType, MemSpace > chunk_type
Type describing the object which can be extracted from this VectorFieldMem using the get<> function.
Definition: vector_field_mem.hpp:63
VectorFieldMem & operator=(VectorFieldMem &&other)=default
Move-assigns a new value to this VectorField.
VectorFieldMem(index_range_type const &idx_range, Allocator allocator=Allocator())
Construct a VectorFieldMem on an index range with uninitialized values.
Definition: vector_field_mem.hpp:151
auto operator[](IdxRange< QueryDDims... > const &oidx_range)
Slice out some dimensions.
Definition: vector_field_mem.hpp:296
typename chunk_type::memory_space memory_space
The type of the memory space where the field is saved (CPU vs GPU).
Definition: vector_field_mem.hpp:117
view_type span_cview() const
Get a constant reference to this vector field.
Definition: vector_field_mem.hpp:185
ddc::KokkosAllocator< ElementType, MemSpace > Allocator
The type of allocator that will be used to allocate the data.
Definition: vector_field_mem.hpp:78
discrete_domain_type index_range_type
The IdxRange on which the fields in this object are defined.
Definition: vector_field_mem.hpp:112
VectorFieldMem()=default
Empty VectorFieldMem.
typename base_type::discrete_domain_type discrete_domain_type
The type of the index range on which the field is defined.
Definition: vector_field_mem.hpp:110
span_type span_view()
Get a modifiable reference to this vector field.
Definition: vector_field_mem.hpp:211
constexpr chunk_view_type get() const noexcept
Get the Field describing the component in the QueryTag direction.
Definition: vector_field_mem.hpp:321
VectorFieldMem & operator=(VectorFieldMem const &other)=delete
Deleted: use deepcopy instead.
A class which holds multiple (scalar) fields in order to represent a vector field.
Definition: vector_field.hpp:64
A class which describes the real space in the temporal direction.
Definition: geometry.hpp:45