Gyselalib++
multipatch_type.hpp
1 // SPDX-License-Identifier: MIT
2 
3 #pragma once
4 #include "ddc_alias_inline_functions.hpp"
5 #include "ddc_aliases.hpp"
6 #include "types.hpp"
7 
8 template <class T>
9 inline constexpr bool enable_multipatch_type = false;
10 
11 template <class T>
12 inline constexpr bool is_multipatch_type_v
13  = enable_multipatch_type<std::remove_const_t<std::remove_reference_t<T>>>;
14 
15 
30 template <template <typename P> typename T, class... Patches>
32 {
33 public:
35  using PatchOrdering = ddc::detail::TypeSeq<Patches...>;
36 
42 
43 protected:
45  std::tuple<T<Patches>...> m_tuple;
46 
47  template <template <typename P> typename OT, class... OPatches>
48  friend class MultipatchType;
49 
55  KOKKOS_FUNCTION explicit MultipatchType(std::tuple<T<Patches>...>&& tuple) : m_tuple(tuple) {}
56 
57 public:
63  explicit KOKKOS_FUNCTION MultipatchType(T<Patches>... args)
64  : m_tuple(std::make_tuple(std::move(args)...))
65  {
66  }
67 
82  template <template <typename P> typename OT, class... OPatches>
83  KOKKOS_FUNCTION MultipatchType(MultipatchType<OT, OPatches...> const& other)
84  : m_tuple(std::make_tuple(other.template get<Patches>()...))
85  {
86  static_assert(
87  ddc::type_seq_contains_v<PatchOrdering, ddc::detail::TypeSeq<OPatches...>>,
88  "The type being copied does not contain all the required patches");
89  static_assert(
90  std::is_same_v<std::tuple<T<Patches>...>, std::tuple<OT<Patches>...>>,
91  "MultipatchTypes are not equivalent");
92  }
93 
100  template <template <typename P> typename OT, class... OPatches>
102  : m_tuple(std::make_tuple(std::move(other.template get<Patches>())...))
103  {
104  static_assert(
105  std::is_same_v<ddc::detail::TypeSeq<Patches...>, ddc::detail::TypeSeq<OPatches...>>,
106  "Cannot create a MultipatchType from a temporary MultipatchType with a different "
107  "ordering");
108  static_assert(
109  std::is_same_v<std::tuple<T<Patches>...>, std::tuple<OT<OPatches>...>>,
110  "MultipatchTypes are not equivalent");
111  }
112 
113  KOKKOS_FUNCTION ~MultipatchType() {}
114 
121  template <class Patch, std::enable_if_t<!has_data_access_methods_v<T<Patch>>, bool> = true>
122  KOKKOS_FUNCTION T<Patch> get() const
123  {
124  return std::get<T<Patch>>(m_tuple);
125  }
126 
131  static constexpr std::size_t size()
132  {
133  return sizeof...(Patches);
134  }
135 
141  KOKKOS_FUNCTION std::tuple<T<Patches>...> const& get_tuple() const
142  {
143  return m_tuple;
144  }
145 };
146 
147 template <template <typename P> typename T, class... Patches>
148 inline constexpr bool enable_multipatch_type<MultipatchType<T, Patches...>> = true;
A class to store several objects that are of a type which is templated by the patch.
Definition: multipatch_type.hpp:32
KOKKOS_FUNCTION T< Patch > get() const
Retrieve an object from the patch that it is defined on.
Definition: multipatch_type.hpp:122
KOKKOS_FUNCTION MultipatchType(T< Patches >... args)
Instantiate the MultipatchType class from an arbitrary number of objects.
Definition: multipatch_type.hpp:63
static constexpr std::size_t size()
Get the number of objects stored inside the class.
Definition: multipatch_type.hpp:131
KOKKOS_FUNCTION std::tuple< T< Patches >... > const & get_tuple() const
Get a constant reference to the tuple of objects stored inside this MultipatchType.
Definition: multipatch_type.hpp:141
KOKKOS_FUNCTION MultipatchType(MultipatchType< OT, OPatches... > const &other)
Create a MultipatchType class by copying an instance of another compatible MultipatchType.
Definition: multipatch_type.hpp:83
ddc::detail::TypeSeq< Patches... > PatchOrdering
A tag storing the order of Patches in this MultipatchType.
Definition: multipatch_type.hpp:35
MultipatchType(MultipatchType< OT, OPatches... > &&other)
Create a MultipatchType class from an r-value (temporary) instance of another MultipatchType which us...
Definition: multipatch_type.hpp:101
KOKKOS_FUNCTION MultipatchType(std::tuple< T< Patches >... > &&tuple)
A constructor for sub-classes which can build the necessary tuple directly following their own rules.
Definition: multipatch_type.hpp:55
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