1/*
2 * grid_zm.hpp
3 *
4 * Created on: Mar 25, 2020
5 * Author: i-bird
6 */
7
8#ifndef GRID_ZM_HPP_
9#define GRID_ZM_HPP_
10
11#include "util/zmorton.hpp"
12
13/*! \brief class that store the information of the grid like number of point on each direction and
14 * define the index linearization by stride
15 *
16 * \param N dimensionality
17 * \param T type of object is going to store the grid
18 *
19 */
20template<unsigned int N, typename T>
21class grid_zm : private grid_sm<N,T>
22{
23
24public:
25
26
27 /*! \brief Reset the dimension of the grid
28 *
29 * \param dims store on each dimension the size of the grid
30 *
31 */
32 inline void setDimensions(const size_t (& dims)[N])
33 {
34 ((grid_sm<N,T> *)this)->setDimensions(dims);
35 }
36
37 grid_zm(){};
38
39 /*! \brief construct a grid from another grid
40 *
41 * \param g grid info
42 *
43 * construct a grid from another grid, type can be different
44 *
45 */
46
47 template<typename S> inline grid_zm(const grid_zm<N,S> & g)
48 {
49 this->setDimensions(this->getSize());
50 }
51
52
53 /*! \brief Construct a grid of a specified size
54 *
55 * Construct a grid of a specified size
56 *
57 * \param sz is an array that contain the size of the grid on each dimension
58 *
59 */
60
61 inline grid_zm(const size_t & sz)
62 :grid_sm<N,T>(sz)
63 {}
64
65 /*! \brief Construct a grid of a specified size
66 *
67 * Construct a grid of a specified size
68 *
69 * \param sz is an array that contain the size of the grid on each dimension
70 *
71 */
72
73 inline grid_zm(const size_t (& sz)[N])
74 {
75 this->setDimensions(sz);
76 }
77
78 //! Destructor
79 ~grid_zm() {};
80
81 /*! \brief Linearization of the grid_key_dx
82 *
83 * Linearization of the grid_key_dx given a key, it spit out a number that is just the 1D linearization
84 * of the key. In this case is the linearization of N index
85 *
86 * \param gk grid key to access the element of the grid
87 *
88 */
89 template<typename ids_type> __device__ __host__ inline mem_id LinId(const grid_key_dx<N,ids_type> & gk) const
90 {
91 return lin_zid(gk);
92 }
93
94
95 /*! \brief Copy the grid from another grid
96 *
97 * \param g grid from witch to copy
98 *
99 */
100
101 __device__ __host__ inline grid_zm<N,T> & operator=(const grid_zm<N,T> & g)
102 {
103 ((grid_sm<N,T> *)this)->operator=(g);
104
105 return *this;
106 }
107
108 /*! \brief Check if the two grid_sm are the same
109 *
110 * \param g element to check
111 *
112 * \return true if they are the same
113 *
114 */
115
116 inline bool operator==(const grid_zm<N,T> & g)
117 {
118 return ((grid_sm<N,T> *)this)->operator==(g);
119 }
120
121 /*! \brief Check if the two grid_sm are the same
122 *
123 * \param g element to check
124 *
125 */
126
127 inline bool operator!=(const grid_zm<N,T> & g)
128 {
129 return ((grid_sm<N,T> *)this)->operator!=(g);
130 }
131
132 /*! \brief swap the grid_sm informations
133 *
134 * \param g grid to swap
135 *
136 */
137 inline void swap(grid_zm<N,T> & g)
138 {
139 ((grid_sm<N,T> *)this)->swap(g);
140 }
141
142 /**
143 *
144 * Get the size of the grid on the direction i
145 *
146 * \param i direction
147 * \return the size on the direction i
148 *
149 */
150 inline size_t size(unsigned int i) const
151 {
152 return ((grid_sm<N,T> *)this)->size(i);
153 }
154
155 /**
156 *
157 * Get the total size of the grid
158 *
159 * \return the total size on the grid
160 *
161 */
162 inline size_t size() const
163 {
164 return ((grid_sm<N,T> *)this)->size();
165 }
166
167 //! It simply mean that all the classes grid are friend of all its specialization
168 template <unsigned int,typename> friend class grid_zm;
169};
170
171
172#endif /* GRID_ZM_HPP_ */
173