OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
SparseGridGpu_iterator_sub.hpp
1/*
2 * SparseGridGpu_iterator_sub.hpp
3 *
4 * Created on: Jun 24, 2019
5 * Author: i-bird
6 */
7
8#ifndef SPARSEGRIDGPU_ITERATOR_SUB_HPP_
9#define SPARSEGRIDGPU_ITERATOR_SUB_HPP_
10
11#include "SparseGridGpu_iterator.hpp"
12
13template<unsigned int dim, typename SparseGridType>
15{
17 unsigned int chunk;
18
20 const SparseGridType * sparseGrid;
21
24
26 typedef typename std::remove_reference<decltype(sparseGrid->private_get_index_array())>::type index_array_type;
27
29 typedef typename std::remove_reference<decltype(sparseGrid->private_get_data_array())>::type data_array_type;
30
32 const typename std::remove_reference<decltype(sparseGrid->private_get_index_array())>::type * ids;
33
35 const typename std::remove_reference<decltype(sparseGrid->private_get_data_array())>::type * data;
36
37 //Get the chunk type
38 typedef typename boost::mpl::at<typename data_array_type::value_type::type,boost::mpl::int_<0>>::type chunk_type;
39
40 //Get the chunk type
41 typedef boost::mpl::int_<boost::mpl::size<typename data_array_type::value_type::type>::type::value-1> pMask;
42
43 // subset in grid coordinates
44 Box<dim,int> sub_set;
45
46 // subset in local chunk coordinates
47 Box<dim,int> res;
48
49 // in chunk iterator
51
52 // chunk size
53 grid_sm<dim,void> chunk_sz;
54
60 {
61 if (chunk >= ids->size())
62 {return;}
63
64 // compute if the chunk intersect the start - stop box
65 chunk_coord = sparseGrid->getCoord(ids->template get<0>(chunk)*sparseGrid->getBlockSize());
66
67 Box<dim,int> box;
68
69 for (int i = 0 ; i < dim ; i++)
70 {
71 box.setLow(i,chunk_coord.get(i));
72 box.setHigh(i,chunk_coord.get(i) + sparseGrid->getBlockEdgeSize() - 1);
73 }
74
75
76 if (sub_set.Intersect(box,res) == true)
77 {
78 // remove the offset
79 for (int i = 0 ; i < dim ; i++)
80 {
81 res.setLow(i,res.getLow(i) - chunk_coord.get(i));
82 res.setHigh(i,res.getHigh(i) - chunk_coord.get(i));
83 }
84
85 in_chunk_it.reinitialize(grid_key_dx_iterator_sub<dim>(chunk_sz,res.getKP1(),res.getKP2()));
86
87 while (in_chunk_it.isNext() == true && (data->template get<pMask::value>(chunk)[chunk_sz.LinId(in_chunk_it.get())]&1ul) == 0)
88 {
89 ++in_chunk_it;
90 }
91 }
92 }
93
96 {
97 while (in_chunk_it.isNext() == true && (data->template get<pMask::value>(chunk)[chunk_sz.LinId(in_chunk_it.get())]&1ul) == 0)
98 {
99 ++in_chunk_it;
100 }
101
102 while (in_chunk_it.isNext() == false && chunk < ids->size())
103 {
104 chunk++;
105
107 }
108 }
109
115 {
116 size_t sz[dim];
117
118 for (int i = 0 ; i < dim ; i++)
119 {sz[i] = sparseGrid->getBlockEdgeSize();}
120
121 chunk_sz.setDimensions(sz);
122 }
123
124public:
125
130 :chunk(0),
131 sparseGrid(NULL),
132 ids(NULL),
133 data(NULL)
134 {
136 }
137
145 inline SparseGridGpu_iterator_sub(const SparseGridType & sparseGrid,const grid_key_dx<dim> & start,const grid_key_dx<dim> & stop, int is_to_init)
146 :chunk(0),
148 ids(&sparseGrid.private_get_index_array()),
149 data(&sparseGrid.private_get_data_array())
150 {
151 for (int i = 0; i < dim ; i++)
152 {
153 sub_set.setLow(i,start.get(i));
154 sub_set.setHigh(i,stop.get(i));
155 }
156
158 if (is_to_init == 1)
159 {
160 in_chunk_it.invalidate();
162
163 SelectValid();
164 }
165 }
166
173 {
174 return sub_set.getKP1();
175 }
176
183 {
184 return sub_set.getKP2();
185 }
186
193 {
194 this->operator=(it_sub);
195 }
196
204 bool isNext() const
205 {
206 return chunk < ids->size();
207 }
208
217 {
218 ++in_chunk_it;
219
220 SelectValid();
221
222 return *this;
223 }
224
231 {
232 sparse_grid_gpu_index<SparseGridType> spgi(*sparseGrid,chunk,chunk_sz.LinId(in_chunk_it.get()));
233
234 return spgi;
235 }
236
238 {
239 chunk = it_sub.chunk;
240 sparseGrid = it_sub.sparseGrid;
241 chunk_coord = it_sub.chunk_coord;
242 ids = it_sub.ids;
243 data = it_sub.data;
244 sub_set = it_sub.sub_set;
245 res = it_sub.res;
246 in_chunk_it = it_sub.in_chunk_it;
247 chunk_sz = it_sub.chunk_sz;
248
249 return *this;
250 }
251};
252
253
254#endif /* SPARSEGRIDGPU_ITERATOR_SUB_HPP_ */
This class represent an N-dimensional box.
Definition Box.hpp:61
__device__ __host__ T getLow(int i) const
get the i-coordinate of the low bound interval of the box
Definition Box.hpp:556
__device__ __host__ bool Intersect(const Box< dim, T > &b, Box< dim, T > &b_out) const
Intersect.
Definition Box.hpp:95
__device__ __host__ T getHigh(int i) const
get the high interval of the box
Definition Box.hpp:567
__device__ __host__ void setHigh(int i, T val)
set the high interval of the box
Definition Box.hpp:544
grid_key_dx< dim > getKP2() const
Get the point p12 as grid_key_dx.
Definition Box.hpp:669
__device__ __host__ void setLow(int i, T val)
set the low interval of the box
Definition Box.hpp:533
grid_key_dx< dim > getKP1() const
Get the point p1 as grid_key_dx.
Definition Box.hpp:656
sparse_grid_gpu_index< SparseGridType > get() const
return the actual point
const SparseGridType * sparseGrid
original SparseGrid
void initialize_chunk_it()
initialize the chunk interator
std::remove_reference< decltype(sparseGrid->private_get_data_array())>::type data_array_type
array type for the data
SparseGridGpu_iterator_sub< dim, SparseGridType > & operator++()
Get the next element.
std::remove_reference< decltype(sparseGrid->private_get_index_array())>::type index_array_type
array type for the indexes
const std::remove_reference< decltype(sparseGrid->private_get_data_array())>::type * data
vector containing each chunks datas
grid_key_dx< dim > getStart() const
Return the starting point.
void initialize_chunk_sz()
Initialize chunk_sz member.
void reinitialize(const SparseGridGpu_iterator_sub< dim, SparseGridType > &it_sub)
Reinitialize the iterator.
const std::remove_reference< decltype(sparseGrid->private_get_index_array())>::type * ids
vector of the chunk indexes
void SelectValid()
Select the first valid point chunk.
grid_key_dx< dim > getStop() const
Return the stop point.
bool isNext() const
Check if there is the next element.
SparseGridGpu_iterator_sub(const SparseGridType &sparseGrid, const grid_key_dx< dim > &start, const grid_key_dx< dim > &stop, int is_to_init)
Constructor.
grid_key_dx< dim, int > chunk_coord
chunk coordinates
SparseGridGpu_iterator_sub()
Default constructor.
Declaration grid_key_dx_iterator_sub.
grid_key_dx< dim > get() const
Return the actual grid key iterator.
bool isNext()
Check if there is the next element.
void reinitialize(const grid_key_dx_iterator_sub< dim > &g_s_it)
Reinitialize the iterator.
grid_key_dx is the key to access any element in the grid
Definition grid_key.hpp:19
__device__ __host__ index_type get(index_type i) const
Get the i index.
Definition grid_key.hpp:503
Declaration grid_sm.
Definition grid_sm.hpp:167
void setDimensions(const size_t(&dims)[N])
Reset the dimension of the grid.
Definition grid_sm.hpp:326
mem_id LinId(const grid_key_dx< N, ids_type > &gk, const signed char sum_id[N]) const
Linearization of the grid_key_dx with a specified shift.
Definition grid_sm.hpp:454
Element index contain a data chunk index and a point index.