Gyselalib++
multipatch_field_mem.hpp
1 // SPDX-License-Identifier: MIT
2 #pragma once
3 
4 #include "multipatch_field.hpp"
5 #include "multipatch_type.hpp"
6 
7 template <class T>
8 inline constexpr bool enable_multipatch_field_mem = false;
9 
10 template <class T>
11 inline constexpr bool is_multipatch_field_mem_v
12  = enable_multipatch_field_mem<std::remove_const_t<std::remove_reference_t<T>>>;
13 
28 template <template <typename P> typename T, class... Patches>
29 class MultipatchFieldMem : public MultipatchType<T, Patches...>
30 {
31  static_assert(
32  (has_data_access_methods_v<T<Patches>> && ...),
33  "The MultipatchFieldMem type should only contain instances of objects that can be "
34  "manipulated like fields.");
35  static_assert(
36  (is_mem_type_v<T<Patches>> && ...),
37  "The MultipatchFieldMem type should only contain instances of objects that allocate "
38  "memory.");
39 
40 public:
42  using base_type = MultipatchType<T, Patches...>;
43 
45  using typename base_type::PatchOrdering;
46 
48  template <class Patch>
50 
52  template <class Patch>
54 
56  template <class Patch>
58 
59  template <template <typename P> typename OT, class... OPatches>
60  friend class MultipatchFieldMem;
61 
62 public:
70  using memory_space = typename base_type::example_element::memory_space;
72  using element_type = typename base_type::example_element::element_type;
73 
74 public:
80  explicit MultipatchFieldMem(T<Patches>... args) : base_type(args...) {}
81 
92  template <class MultipatchObj>
93  explicit MultipatchFieldMem(MultipatchObj& other)
94  : base_type(std::move(T<Patches>(other.template get<Patches>()))...)
95  {
96  static_assert(is_multipatch_type_v<MultipatchObj>);
97  }
98 
105  template <template <typename P> typename OT, class... OPatches>
107  {
108  static_assert(
109  std::is_same_v<ddc::detail::TypeSeq<Patches...>, ddc::detail::TypeSeq<OPatches...>>,
110  "Cannot create a MultipatchFieldMem from a temporary MultipatchFieldMem with a "
111  "different "
112  "ordering");
113  static_assert(
114  std::is_same_v<std::tuple<T<Patches>...>, std::tuple<OT<OPatches>...>>,
115  "MultipatchFieldMems are not equivalent");
116  }
117 
118  ~MultipatchFieldMem() {}
119 
126  template <class Patch>
127  auto get() const
128  {
129  return ::get_const_field(std::get<T<Patch>>(base_type::m_tuple));
130  }
131 
138  template <class Patch>
139  auto get()
140  {
141  return ::get_field(std::get<T<Patch>>(base_type::m_tuple));
142  }
143 
149  auto idx_range() const
150  {
151  return MultipatchType<InternalIdxRangeOnPatch, Patches...>(
152  get_idx_range(std::get<T<Patches>>(base_type::m_tuple))...);
153  }
154 
160  auto get_field()
161  {
162  return MultipatchField<InternalFieldOnPatch, Patches...>(
163  ::get_field(std::get<T<Patches>>(base_type::m_tuple))...);
164  }
165 
172  auto span_view()
173  {
174  return get_field();
175  }
176 
182  auto get_const_field() const
183  {
184  return MultipatchField<InternalConstFieldOnPatch, Patches...>(
186  }
187 
194  auto span_cview() const
195  {
196  return get_const_field();
197  }
198 };
199 
200 template <template <typename P> typename T, class... Patches>
201 inline constexpr bool enable_multipatch_type<MultipatchFieldMem<T, Patches...>> = true;
202 
203 template <template <typename P> typename T, class... Patches>
204 inline constexpr bool enable_multipatch_field_mem<MultipatchFieldMem<T, Patches...>> = true;
205 
206 template <template <typename P> typename T, class... Patches>
207 inline constexpr bool enable_mem_type<MultipatchFieldMem<T, Patches...>> = true;
208 
209 template <template <typename P> typename T, class... Patches>
210 inline constexpr bool enable_data_access_methods<MultipatchFieldMem<T, Patches...>> = true;
A class to store field memory block objects on patches.
Definition: multipatch_field_mem.hpp:30
typename T< Patch >::span_type InternalFieldOnPatch
An internal type alias that is only instantiated if the get_const_field method is called.
Definition: multipatch_field_mem.hpp:53
auto get_const_field() const
Get a MultipatchConstField containing constant fields so the values cannot be modified.
Definition: multipatch_field_mem.hpp:182
auto idx_range() const
Get a MultipatchType containing the index ranges on which the fields are defined.
Definition: multipatch_field_mem.hpp:149
MultipatchFieldMem(MultipatchObj &other)
Create a MultipatchFieldMem class by copying an instance of another compatible MultipatchFieldMem.
Definition: multipatch_field_mem.hpp:93
typename T< Patch >::view_type InternalConstFieldOnPatch
An internal type alias that is only instantiated if the get_const_field method is called.
Definition: multipatch_field_mem.hpp:57
MultipatchFieldMem(T< Patches >... args)
Instantiate the MultipatchFieldMem class from an arbitrary number of objects.
Definition: multipatch_field_mem.hpp:80
auto get() const
Retrieve an object from the patch that it is defined on.
Definition: multipatch_field_mem.hpp:127
MultipatchFieldMem(MultipatchFieldMem< OT, OPatches... > &&other)
Create a MultipatchFieldMem class from an r-value (temporary) instance of another MultipatchFieldMem ...
Definition: multipatch_field_mem.hpp:106
auto get()
Retrieve an object from the patch that it is defined on.
Definition: multipatch_field_mem.hpp:139
typename base_type::example_element::element_type element_type
The type of the elements inside the field.
Definition: multipatch_field_mem.hpp:72
auto span_view()
Get a MultipatchField containing modifiable fields.
Definition: multipatch_field_mem.hpp:172
auto get_field()
Get a MultipatchField containing modifiable fields.
Definition: multipatch_field_mem.hpp:160
typename base_type::example_element::memory_space memory_space
The memory space (CPU/GPU) where the data is saved.
Definition: multipatch_field_mem.hpp:70
auto span_cview() const
Get a MultipatchField containing constant fields so the values cannot be modified.
Definition: multipatch_field_mem.hpp:194
typename T< Patch >::discrete_domain_type InternalIdxRangeOnPatch
An internal type alias that is only instantiated if the idx_range method is called.
Definition: multipatch_field_mem.hpp:49
A class to store field objects on patches.
Definition: multipatch_field.hpp:30
A class to store several objects that are of a type which is templated by the patch.
Definition: multipatch_type.hpp:32
ddc::detail::TypeSeq< Patches... > PatchOrdering
A tag storing the order of Patches in this MultipatchType.
Definition: multipatch_type.hpp:35
std::tuple< T< Patches >... > m_tuple
The internal tuple containing the data.
Definition: multipatch_type.hpp:45
A class which describes the real space in the temporal direction.
Definition: geometry.hpp:45