OpenFPM  5.2.0
Project that contain the implementation of distributed structures
CellList_cpu_ker.cuh
1 /*
2  * CellList_gpu_ker.cuh
3  *
4  * Created on: Jul 30, 2018
5  * Author: i-bird
6  */
7 
8 #ifndef CELLLIST_CPU_KER_CUH_
9 #define CELLLIST_CPU_KER_CUH_
10 
11 #include "Cuda_cell_list_util_func.hpp"
12 
13 template<unsigned int dim, typename T, typename Mem_type, typename transform_type>
14 class CellList_cpu_ker: Mem_type
15 {
16  typedef typename Mem_type::local_index_type ids_type;
17 
20 
23 
26 
28  transform_type pointTransform;
29 
32 
35 
38 
39 public:
40 
41  CellList_cpu_ker(const Mem_type & mt,
48  const transform_type & pointTransform)
49  : Mem_type(mt),
51  div_c(div_c),
52  off(off),
57  {}
58 
59  inline __device__ unsigned int getCell(const Point<dim,T> & xp) const
60  {
62  }
63 
69  const __device__ grid_sm<dim,void> & getGrid() const
70  {
71  return cellListGrid;
72  }
73 
83  inline __device__ grid_key_dx<dim> getCellGrid(const Point<dim,T> & pos) const
84  {
85  grid_key_dx<dim> key;
86  key.set_d(0,ConvertToID(pos,0));
87 
88  for (size_t s = 1 ; s < dim ; s++)
89  {
90  key.set_d(s,ConvertToID(pos,s));
91  }
92 
93  return key;
94  }
95 
105  inline __device__ grid_key_dx<dim> getCellGrid(const T (& pos)[dim]) const
106  {
107  grid_key_dx<dim> key;
108  key.set_d(0,ConvertToID(pos,0));
109 
110  for (size_t s = 1 ; s < dim ; s++)
111  {
112  key.set_d(s,ConvertToID(pos,s));
113  }
114 
115  return key;
116  }
117 
124  inline __device__ size_t ConvertToID(const T (&x)[dim], size_t s) const
125  {
126  size_t id = openfpm::math::size_t_floor(pointTransform.transform(x,s) / cellListSpaceBox.getHigh(s)) + off[s];
127  id = (id >= cellListGrid.size(s))?(cellListGrid.size(s)-1-cellShift.get(s)):id-cellShift.get(s);
128  return id;
129  }
130 
137  inline __device__ size_t ConvertToID(const Point<dim,T> & x, size_t s, size_t sc = 0) const
138  {
139  size_t id = openfpm::math::size_t_floor(pointTransform.transform(x,s) / cellListSpaceBox.getHigh(s)) + off[s];
140  id = (id >= cellListGrid.size(s))?(cellListGrid.size(s)-1-cellShift.get(s)):id-cellShift.get(s);
141  return id;
142  }
143 
151  inline __device__ int getNelements(unsigned int cell) const
152  {
153  return Mem_type::getNelements(cell);
154  }
155 
166  inline __device__ unsigned int get(unsigned int cell, unsigned int ele)
167  {
168  return Mem_type::get(cell,ele);
169  }
170 
171 };
172 
173 
174 #endif /* CELLLIST_GPU_KER_CUH_ */
This class represent an N-dimensional box.
Definition: Box.hpp:60
Box< dim, T > cellListSpaceBox
Unit box of the Cell list.
__device__ size_t ConvertToID(const Point< dim, T > &x, size_t s, size_t sc=0) const
Convert the coordinates into id.
__device__ size_t ConvertToID(const T(&x)[dim], size_t s) const
Convert the coordinates into id.
const __device__ grid_sm< dim, void > & getGrid() const
Return the underlying grid information of the cell list.
openfpm::array< T, dim > spacing_c
Spacing.
__device__ int getNelements(unsigned int cell) const
Return the number of elements in the cell.
__device__ unsigned int get(unsigned int cell, unsigned int ele)
Get an element in the cell.
transform_type pointTransform
transformation
__device__ grid_key_dx< dim > getCellGrid(const T(&pos)[dim]) const
Get the cell-ids.
__device__ grid_key_dx< dim > getCellGrid(const Point< dim, T > &pos) const
Get the cell-ids.
grid_sm< dim, void > cellListGrid
Grid structure of the Cell list.
openfpm::array< ids_type, dim > off
cell padding
Point< dim, long int > cellShift
cellShift
openfpm::array< ids_type, dim > div_c
number of sub-divisions in each direction
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
Definition: Point.hpp:172
__device__ __host__ void set_d(index_type i, index_type id)
Set the i index.
Definition: grid_key.hpp:516
__device__ __host__ size_t size() const
Return the size of the grid.
Definition: grid_sm.hpp:657