OpenFPM  5.2.0
Project that contain the implementation of distributed structures
CellDecomposer_gpu_ker.cuh
1 /*
2  * CellDecomposer_gpu_ker.hpp
3  *
4  * Created on: Apr 28, 2019
5  * Author: i-bird
6  */
7 
8 #ifndef CELLDECOMPOSER_GPU_KER_HPP_
9 #define CELLDECOMPOSER_GPU_KER_HPP_
10 
11 #include "util/cuda_util.hpp"
12 #include "util/multi_array_openfpm/array_openfpm.hpp"
13 #include "Grid/grid_sm.hpp"
14 #include "NN/CellList/cuda/Cuda_cell_list_util_func.hpp"
15 #include "NN/CellList/CellDecomposer.hpp"
16 
17 template <unsigned int dim, typename T, typename ids_type, typename transform_type>
19 {
22 
25 
28 
30  transform_type pointTransform;
31 
34 
37 
40 public:
41 
42  __device__ __host__ CellDecomposer_gpu_ker()
43  {}
44 
45  __device__ __host__ CellDecomposer_gpu_ker(
49  const transform_type & pointTransform)
54  {}
55 
56  __device__ __host__ CellDecomposer_gpu_ker(
60  const transform_type & pointTransform,
71  {}
72 
73  __device__ __host__ grid_sm<dim,void> getGrid()
74  {
75  size_t sz[dim];
76 
77  for (size_t i = 0 ; i < dim ; i++)
78  sz[i] = numCellDiv[i];
79 
80  return grid_sm<dim,void> (sz);
81  }
82 
83  __device__ __host__ void getGridSize(size_t (& sz)[dim]) const
84  {
85  for (size_t i = 0 ; i < dim ; i++)
86  sz[i] = numCellDiv[i] + 2*cellPadDim[i];
87  }
88 
89  template<typename ids_type2>
90  __device__ __host__ mem_id getGridLinId(const grid_key_dx<dim,ids_type2> & gk) const
91  {
92  mem_id lid = gk.get(0);
93  for (mem_id i = 1 ; i < dim ; i++)
94  lid += gk.get(i) * (numCellDiv[i-1] + 2*cellPadDim[i-1]);
95 
96  return lid;
97  }
98 
99  __device__ __host__ inline grid_key_dx<dim,ids_type> getCell(const Point<dim,T> & xp) const
100  {
102  }
103 
104  __device__ __host__ inline unsigned int LinId(const grid_key_dx<dim,ids_type> & k) const
105  {
107  }
108 
109  __device__ inline const openfpm::array<T,dim> & get_spacing_c() const
110  {
111  return unitCellP2;
112  }
113 
114  __device__ __host__ inline const openfpm::array<ids_type,dim> & get_div_c() const
115  {
116  return numCellDiv;
117  }
118 
119  __device__ __host__ inline const openfpm::array<ids_type,dim> & get_off() const
120  {
121  return cellPadDim;
122  }
123 
124  __device__ __host__ inline const transform_type & get_t() const
125  {
126  return pointTransform;
127  }
128 
129  __device__ __host__ inline grid_key_dx<dim> getCellGrid(const T (& pos)[dim]) const
130  {
131  grid_key_dx<dim> key;
132  key.set_d(0,ConvertToID(pos,0));
133 
134  for (size_t s = 1 ; s < dim ; s++)
135  key.set_d(s,ConvertToID(pos,s));
136 
137  return key;
138  }
139 
140  __device__ __host__ inline grid_key_dx<dim> getCellGrid(const Point<dim,T> & pos) const
141  {
142  grid_key_dx<dim> key;
143  key.set_d(0,ConvertToID(pos,0));
144 
145  for (size_t s = 1 ; s < dim ; s++)
146  key.set_d(s,ConvertToID(pos,s));
147 
148  return key;
149  }
150 
151  __device__ __host__ inline size_t ConvertToID(const T (&x)[dim] ,size_t s) const
152  {
153  size_t id = openfpm::math::size_t_floor(pointTransform.transform(x,s) / cellListSpaceBox.getHigh(s)) + cellPadDim[s];
154  id = (id >= cellListGrid.size(s))?(cellListGrid.size(s)-1-cellShift.get(s)):id-cellShift.get(s);
155  return id;
156  }
157 
158  __device__ __host__ inline size_t ConvertToID(const Point<dim,T> & x ,size_t s, size_t sc = 0) const
159  {
160  size_t id = openfpm::math::size_t_floor(pointTransform.transform(x,s) / cellListSpaceBox.getHigh(s)) + cellPadDim[s];
161  id = (id >= cellListGrid.size(s))?(cellListGrid.size(s)-1-cellShift.get(s)):id-cellShift.get(s);
162  return id;
163  }
164 };
165 
166 #endif /* CELLDECOMPOSER_GPU_KER_HPP_ */
This class represent an N-dimensional box.
Definition: Box.hpp:60
Box< dim, T > cellListSpaceBox
Unit box of the Cell list.
openfpm::array< ids_type, dim > cellPadDim
cell offset
openfpm::array< T, dim > unitCellP2
Spacing.
transform_type pointTransform
transformation
openfpm::array< ids_type, dim > numCellDiv
number of sub-divisions in each direction
Point< dim, long int > cellShift
cellShift
grid_sm< dim, void > cellListGrid
Grid structure of the Cell list.
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
Definition: Point.hpp:172
grid_key_dx is the key to access any element in the grid
Definition: grid_key.hpp:19
__device__ __host__ void set_d(index_type i, index_type id)
Set the i index.
Definition: grid_key.hpp:516
__device__ __host__ index_type get(index_type i) const
Get the i index.
Definition: grid_key.hpp:503
__device__ __host__ size_t size() const
Return the size of the grid.
Definition: grid_sm.hpp:657
Definition: ids.hpp:169