diff --git a/src/NN/CellList/CellList.hpp b/src/NN/CellList/CellList.hpp index dc7cfebfc5db787345675a8ab4181b7eab3e3567..ddfe278b3c3d86041fbf60580dbc47231b2e7c79 100644 --- a/src/NN/CellList/CellList.hpp +++ b/src/NN/CellList/CellList.hpp @@ -1193,6 +1193,9 @@ public: spacing_c, div_c, off, + this->gr_cell, + this->cell_shift, + this->box_unit, CellDecomposer_sm<dim,T,transform>::getTransform()); return cl; diff --git a/src/NN/CellList/cuda/CellList_cpu_ker.cuh b/src/NN/CellList/cuda/CellList_cpu_ker.cuh index f6d726a987e577a66aec53d13861863bf1727eec..58e7604cf981767bc8ad810235cfa08623bb3b5a 100644 --- a/src/NN/CellList/cuda/CellList_cpu_ker.cuh +++ b/src/NN/CellList/cuda/CellList_cpu_ker.cuh @@ -29,14 +29,26 @@ class CellList_cpu_ker: Mem_type //! transformation transform t; + //! Grid structure of the Cell list + grid_sm<dim,void> gr_cell; + + //! cell_shift + Point<dim,long int> cell_shift; + + //! Unit box of the Cell list + Box<dim,T> box_unit; + public: CellList_cpu_ker(const Mem_type & mt, openfpm::array<T,dim,cnt_type> & spacing_c, openfpm::array<ids_type,dim,cnt_type> & div_c, openfpm::array<ids_type,dim,cnt_type> & off, + grid_sm<dim,void> & gr_cell, + Point<dim,long int> & cell_shift, + Box<dim,T> & box_unit, const transform & t) - :Mem_type(mt),spacing_c(spacing_c),div_c(div_c),off(off),t(t) + :Mem_type(mt),spacing_c(spacing_c),div_c(div_c),off(off),t(t),gr_cell(gr_cell),cell_shift(cell_shift),box_unit(box_unit) {} inline __device__ unsigned int getCell(const Point<dim,T> & xp) const @@ -44,6 +56,86 @@ public: return cid_<dim,cnt_type,ids_type,transform>::get_cid(div_c,spacing_c,off,t,xp); } + /*! \brief Return the underlying grid information of the cell list + * + * \return the grid infos + * + */ + const __device__ grid_sm<dim,void> & getGrid() const + { + return gr_cell; + } + + /*! \brief Get the cell-ids + * + * Convert the point coordinates into the cell ids (Careful it include padding) + * + * \param pos Point position + * + * \return the cell-ids ad a grid_key_dx<dim> + * + */ + inline __device__ grid_key_dx<dim> getCellGrid(const Point<dim,T> & pos) const + { + grid_key_dx<dim> key; + key.set_d(0,ConvertToID(pos,0)); + + for (size_t s = 1 ; s < dim ; s++) + { + key.set_d(s,ConvertToID(pos,s)); + } + + return key; + } + + /*! \brief Get the cell-ids + * + * Convert the point coordinates into the cell ids + * + * \param pos Point position + * + * \return the cell-ids ad a grid_key_dx<dim> + * + */ + inline __device__ grid_key_dx<dim> getCellGrid(const T (& pos)[dim]) const + { + grid_key_dx<dim> key; + key.set_d(0,ConvertToID(pos,0)); + + for (size_t s = 1 ; s < dim ; s++) + { + key.set_d(s,ConvertToID(pos,s)); + } + + return key; + } + + /*! \brief Convert the coordinates into id + * + * \param x coordinate + * \param s dimension + * + */ + inline __device__ size_t ConvertToID(const T (&x)[dim], size_t s) const + { + size_t id = openfpm::math::size_t_floor(t.transform(x,s) / box_unit.getHigh(s)) + off[s]; + id = (id >= gr_cell.size(s))?(gr_cell.size(s)-1-cell_shift.get(s)):id-cell_shift.get(s); + return id; + } + + /*! \brief Convert the coordinates into id + * + * \param x point + * \param s dimension + * + */ + inline __device__ size_t ConvertToID(const Point<dim,T> & x, size_t s, size_t sc = 0) const + { + size_t id = openfpm::math::size_t_floor(t.transform(x,s) / box_unit.getHigh(s)) + off[s]; + id = (id >= gr_cell.size(s))?(gr_cell.size(s)-1-cell_shift.get(s)):id-cell_shift.get(s); + return id; + } + /*! \brief Return the number of elements in the cell * * \param cell_id id of the cell