chombo-discharge
CD_TileImplem.H
Go to the documentation of this file.
1 /* chombo-discharge
2  * Copyright © 2023 SINTEF Energy Research.
3  * Please refer to Copyright.txt and LICENSE in the chombo-discharge root directory.
4  */
5 
12 #ifndef CD_TileImplem_H
13 #define CD_TileImplem_H
14 
15 // Std includes
16 #include <utility>
17 
18 // Our includes
19 #include <CD_Tile.H>
20 #include <CD_NamespaceHeader.H>
21 
22 // Utility functions, but std::tuple_cat should work.
23 // template <class T, size_t DIM, size_t... Is>
24 // auto
25 // unpack_impl(const std::array<T, DIM>& arr, std::index_sequence<Is...>) -> decltype(std::make_tuple(arr[Is]...))
26 // {
27 // return std::make_tuple(arr[Is]...);
28 // }
29 
30 // template <class T, size_t DIM>
31 // auto
32 // unpack(const std::array<T, DIM>& arr) -> decltype(unpack_impl(arr, std::make_index_sequence<DIM>{}))
33 // {
34 // return unpack_impl(arr, std::make_index_sequence<DIM>{});
35 // }
36 
37 template <class T, size_t DIM>
39 {
40  for (auto& index : m_indices) {
41  index = 0;
42  }
43 }
44 
45 // template <class T, size_t DIM>
46 // template <typename... Args>
47 // TileI<T, DIM>::TileI(Args... args) noexcept
48 // {}
49 
50 template <class T, size_t DIM>
52 {}
53 
54 template <class T, size_t DIM>
55 inline T&
56 TileI<T, DIM>::operator[](const size_t a_dir) noexcept
57 {
58  return m_indices[a_dir];
59 }
60 
61 template <class T, size_t DIM>
62 inline const T&
63 TileI<T, DIM>::operator[](const size_t a_dir) const noexcept
64 {
65  return m_indices[a_dir];
66 }
67 
68 template <class T, size_t DIM>
69 inline std::array<T, DIM>&
71 {
72  return m_indices;
73 }
74 
75 template <class T, size_t DIM>
76 inline const std::array<T, DIM>&
77 TileI<T, DIM>::getIndices() const noexcept
78 {
79  return m_indices;
80 }
81 
82 template <class T, size_t DIM>
83 inline constexpr bool
84 TileI<T, DIM>::operator<(const TileI& a_otherTile) const noexcept
85 {
86  // const auto& myIndices = unpack<T, DIM>(this->getIndices());
87  // const auto& otherIndices = unpack<T, DIM>(a_otherTile.getIndices());
88 
89  const auto& myIndices = std::tuple_cat(m_indices);
90  const auto& otherIndices = std::tuple_cat(a_otherTile.getIndices());
91 
92  return std::tie(myIndices) < std::tie(otherIndices);
93 }
94 
95 template <class T, size_t DIM>
96 inline constexpr bool
97 TileI<T, DIM>::operator>(const TileI& a_otherTile) const noexcept
98 {
99  // const auto& myIndices = unpack<T, DIM>(this->getIndices());
100  // const auto& otherIndices = unpack<T, DIM>(a_otherTile.getIndices());
101  const auto& myIndices = std::tuple_cat(m_indices);
102  const auto& otherIndices = std::tuple_cat(a_otherTile.getIndices());
103 
104  return std::tie(myIndices) > std::tie(otherIndices);
105 }
106 
107 template <class T, size_t DIM>
108 inline constexpr bool
109 TileI<T, DIM>::operator==(const TileI& a_otherTile) const noexcept
110 {
111  // const auto& myIndices = unpack<T, DIM>(this->getIndices());
112  // const auto& otherIndices = unpack<T, DIM>(a_otherTile.getIndices());
113 
114  const auto& myIndices = std::tuple_cat(m_indices);
115  const auto& otherIndices = std::tuple_cat(a_otherTile.getIndices());
116 
117  return std::tie(myIndices) == std::tie(otherIndices);
118 }
119 
120 #include <CD_NamespaceFooter.H>
121 
122 #endif
Class for representing a tile (used in, e.g., TiledMeshRefine)
Definition: CD_Tile.H:26
constexpr bool operator>(const TileI &a_otherTile) const noexcept
Comparison operator. Uses lexicographical comparison.
Definition: CD_TileImplem.H:97
TileI() noexcept
Default constructor. Sets m_indices = 0.
Definition: CD_TileImplem.H:38
constexpr bool operator<(const TileI &a_otherTile) const noexcept
Comparison operator. Uses lexicographical comparison.
Definition: CD_TileImplem.H:84
virtual ~TileI() noexcept
Destructor.
Definition: CD_TileImplem.H:51
constexpr bool operator==(const TileI &a_otherTile) const noexcept
Comparison operator. Uses lexicographical comparison.
Definition: CD_TileImplem.H:109
T & operator[](const size_t a_dir) noexcept
Get the index in specified coordinate direction.
Definition: CD_TileImplem.H:56
std::array< T, DIM > & getIndices() noexcept
Get the indices.
Definition: CD_TileImplem.H:70