OpenFPM_data  0.1.0
Project that contain the implementation and interfaces for basic structure like vectors, grids, graph ... .
 All Data Structures Namespaces Functions Variables Typedefs Friends
CellList< dim, T, FAST, transform, base > Class Template Reference

Class for FAST cell list implementation. More...

Detailed Description

template<unsigned int dim, typename T, typename transform, typename base>
class CellList< dim, T, FAST, transform, base >

Class for FAST cell list implementation.

This class implement the FAST cell list, fast but memory expensive. The memory allocation is (M * N_cell_max)*sizeof(ele) + M*8

  • M = number of cells
  • N_cell_max = maximum number of elements in a cell
  • ele = element the structure is storing
Note
Because N_cell_max >= N/M then M * N_cell_max >= O(N)
Warning
Not not use for high asymmetric distribution

Example of a 2D Cell list 6x6 structure with padding 1 without shift, cell indicated with p are padding cell the origin of the cell or point (0,0) is marked with cell number 9

* +-----------------------+
* |p |p |p |p |p |p |p |p |
* +-----------------------+
* |p |  |  |  |  |  |  |p |
* +-----------------------+
* |p |  |  |  |  |  |  |p |
* +-----------------------+
* |p |  |  |  |  |  |  |p |
* +-----------------------+
* |p |9 |  |  |  |  |  |p |
* +-----------------------+
* |p |p |p |p |p |p |p |p |
* +-----------------------+
* 
Template Parameters
dimDimansionality of the space
Ttype of the space float, double, complex
baseBase structure that store the information

Declaration of a cell list

//Space where is living the Cell list
SpaceBox<dim,T> box({0.0f,0.0f,0.0f},{1.0f,1.0f,1.0f});
// Subdivisions
size_t div[dim] = {16,16,16};
// Origin
Point<dim,T> org({0.0,0.0,0.0});
// id Cell list
CellS cl2(box,div,org);

Usage of cell list [CellS == CellList<3,double,FAST>]

// id Cell list
CellS cl1(box,div,org);
// Create a grid iterator
// Iterate through each element
// Add 1 element for each cell
// Usefull definition of points
Point<dim,T> end = box.getP2();
Point<dim,T> middle = end / div / 2.0;
Point<dim,T> spacing = end / div;
Point<dim,T> offset[dim] = {middle,middle,middle};
// Create offset shift vectors
for (size_t i = 0 ; i < dim ; i++)
{
offset[i].get(i) += (1.0 / div[i]) / 8.0;
}
size_t id = 0;
while (g_it.isNext())
{
// Add 2 particles on each cell
Point<dim,T> key = Point<dim,T>(g_it.get().toPoint());
key = key * spacing + offset[0];
cl1.add(key,id);
++id;
key = Point<dim,T>(g_it.get().toPoint());
key = key * spacing + offset[1];
cl1.add(key,id);
++id;
++g_it;
}

Remove one particle from each cell

while (g_it.isNext())
{
// remove 1 particle on each cell
Point<dim,T> key = Point<dim,T>(g_it.get().toPoint());
key = key * spacing + offset[0];
auto cell = cl1.getCell(key);
// Remove the first particle in the cell
cl1.remove(cell,0);
++g_it;
}

Usage of the neighborhood iterator

Point<dim,T> key = Point<dim,T>(g_it_s.get().toPoint());
key = key * spacing + offset[0];
auto NN = cl1.template getNNIterator<NO_CHECK>(cl1.getCell(key));
size_t total = 0;
while(NN.isNext())
{
// total
total++;
++NN;
}

Definition at line 67 of file CellListFast.hpp.

#include <CellListFast.hpp>

+ Inheritance diagram for CellList< dim, T, FAST, transform, base >:

Public Types

typedef T value_type
 

Public Member Functions

const grid_sm< dim, void > & getGrid ()
 Return the underlying grid information of the cell list. More...
 
void Initialize (const Box< dim, T > &box, const size_t(&div)[dim], const Point< dim, T > &orig, const size_t pad=1, size_t slot=16)
 
void Initialize (SpaceBox< dim, T > &box, const size_t(&div)[dim], const Point< dim, T > &orig, const size_t pad=1, size_t slot=16)
 
 CellList ()
 Default Constructor.
 
 CellList (const CellList< dim, T, FAST, transform, base > &cell)
 Copy constructor.
 
 CellList (CellList< dim, T, FAST, transform, base > &&cell)
 Copy constructor.
 
CellList< dim, T, FAST,
transform, base > & 
operator= (CellList< dim, T, FAST, transform, base > &&cell)
 Constructor from a temporal object. More...
 
CellList< dim, T, FAST,
transform, base > & 
operator= (const CellList< dim, T, FAST, transform, base > &cell)
 Constructor from a temporal object. More...
 
 CellList (Box< dim, T > &box, const size_t(&div)[dim], Matrix< dim, T > mat, Point< dim, T > &orig, const size_t pad=1, size_t slot=16)
 Cell list constructor. More...
 
 CellList (Box< dim, T > &box, const size_t(&div)[dim], Point< dim, T > &orig, const size_t pad=1, size_t slot=16)
 Cell list constructor. More...
 
 CellList (SpaceBox< dim, T > &box, const size_t(&div)[dim], Point< dim, T > &orig, const size_t pad=1, size_t slot=16)
 Cell list constructor. More...
 
void addCell (size_t cell_id, typename base::value_type ele)
 Add to the cell. More...
 
void add (const T(&pos)[dim], typename base::value_type ele)
 Add an element in the cell list. More...
 
void add (const Point< dim, T > &pos, typename base::value_type ele)
 Add an element in the cell list. More...
 
void remove (size_t cell, size_t ele)
 remove an element from the cell More...
 
size_t getNelements (const size_t cell_id) const
 Return the number of element in the cell. More...
 
auto get (size_t cell, size_t ele) -> decltype(cl_base.get(cell *slot+ele))
 Get an element in the cell. More...
 
template<unsigned int i>
auto get (size_t cell, size_t ele) -> decltype(cl_base.get(cell *slot+ele))
 Get an element in the cell. More...
 
void swap (CellList< dim, T, FAST, transform, base > &cl)
 Swap the memory. More...
 
CellIterator< CellList< dim, T,
FAST, transform, base > > 
getIterator (size_t cell)
 Get the Cell iterator. More...
 
template<unsigned int impl>
CellNNIterator< dim, CellList
< dim, T, FAST, transform,
base >, FULL, impl > 
getNNIterator (size_t cell)
 Get the Neighborhood iterator. More...
 
template<unsigned int impl>
CellNNIterator< dim, CellList
< dim, T, FAST, transform,
base >, SYM, impl > 
getNNIteratorSym (size_t cell)
 Get the Neighborhood iterator. More...
 
template<unsigned int impl>
CellNNIterator< dim, CellList
< dim, T, FAST, transform,
base >, CRS, impl > 
getNNIteratorCross (size_t cell)
 Get the Neighborhood iterator. More...
 

Private Member Functions

void realloc ()
 

Private Attributes

long int NNc_full [openfpm::math::pow(3, dim)]
 
long int NNc_sym [openfpm::math::pow(3, dim)/2+1]
 
long int NNc_cr [openfpm::math::pow(2, dim)]
 
size_t slot
 
openfpm::vector< size_t > cl_n
 
base cl_base
 
Point< dim, T > orig
 

Constructor & Destructor Documentation

template<unsigned int dim, typename T , typename transform , typename base >
CellList< dim, T, FAST, transform, base >::CellList ( Box< dim, T > &  box,
const size_t(&)  div[dim],
Matrix< dim, T >  mat,
Point< dim, T > &  orig,
const size_t  pad = 1,
size_t  slot = 16 
)
inline

Cell list constructor.

Parameters
boxDomain where this cell list is living
divgrid size on each dimension
matMatrix transformation
origorigin of the Cell list
padCell padding
slotmaximum number of slot

Definition at line 318 of file CellListFast.hpp.

template<unsigned int dim, typename T , typename transform , typename base >
CellList< dim, T, FAST, transform, base >::CellList ( Box< dim, T > &  box,
const size_t(&)  div[dim],
Point< dim, T > &  orig,
const size_t  pad = 1,
size_t  slot = 16 
)
inline

Cell list constructor.

Parameters
boxDomain where this cell list is living
origorigin of the Cell list
divgrid size on each dimension
padCell padding
slotmaximum number of slot

Definition at line 334 of file CellListFast.hpp.

template<unsigned int dim, typename T , typename transform , typename base >
CellList< dim, T, FAST, transform, base >::CellList ( SpaceBox< dim, T > &  box,
const size_t(&)  div[dim],
Point< dim, T > &  orig,
const size_t  pad = 1,
size_t  slot = 16 
)
inline

Cell list constructor.

Parameters
boxDomain where this cell list is living
origorigin of the Cell list
divgrid size on each dimension
padCell padding
slotmaximum number of slot

Definition at line 349 of file CellListFast.hpp.

Member Function Documentation

template<unsigned int dim, typename T , typename transform , typename base >
void CellList< dim, T, FAST, transform, base >::add ( const T(&)  pos[dim],
typename base::value_type  ele 
)
inline

Add an element in the cell list.

Parameters
posarray that contain the coordinate
eleelement to store

Definition at line 384 of file CellListFast.hpp.

template<unsigned int dim, typename T , typename transform , typename base >
void CellList< dim, T, FAST, transform, base >::add ( const Point< dim, T > &  pos,
typename base::value_type  ele 
)
inline

Add an element in the cell list.

Parameters
posarray that contain the coordinate
eleelement to store

Definition at line 401 of file CellListFast.hpp.

template<unsigned int dim, typename T , typename transform , typename base >
void CellList< dim, T, FAST, transform, base >::addCell ( size_t  cell_id,
typename base::value_type  ele 
)
inline

Add to the cell.

Parameters
cell_idCell id where to add
eleelement to add

Definition at line 361 of file CellListFast.hpp.

template<unsigned int dim, typename T , typename transform , typename base >
auto CellList< dim, T, FAST, transform, base >::get ( size_t  cell,
size_t  ele 
) -> decltype(cl_base.get(cell * slot + ele))
inline

Get an element in the cell.

Template Parameters
iproperty to get
Parameters
cellcell id
eleelement id
Returns
The element value

Definition at line 445 of file CellListFast.hpp.

template<unsigned int dim, typename T , typename transform , typename base >
template<unsigned int i>
auto CellList< dim, T, FAST, transform, base >::get ( size_t  cell,
size_t  ele 
) -> decltype(cl_base.get(cell * slot + ele))
inline

Get an element in the cell.

Template Parameters
iproperty to get
Parameters
cellcell id
eleelement id
Returns
The element value

Definition at line 460 of file CellListFast.hpp.

template<unsigned int dim, typename T , typename transform , typename base >
const grid_sm<dim,void>& CellList< dim, T, FAST, transform, base >::getGrid ( )
inline

Return the underlying grid information of the cell list.

Returns
the grid infos

Definition at line 134 of file CellListFast.hpp.

template<unsigned int dim, typename T , typename transform , typename base >
CellIterator<CellList<dim,T,FAST,transform,base> > CellList< dim, T, FAST, transform, base >::getIterator ( size_t  cell)
inline

Get the Cell iterator.

Parameters
cell
Returns
the iterator to the elements inside cell

Definition at line 483 of file CellListFast.hpp.

template<unsigned int dim, typename T , typename transform , typename base >
size_t CellList< dim, T, FAST, transform, base >::getNelements ( const size_t  cell_id) const
inline

Return the number of element in the cell.

Parameters
cell_idid of the cell
Returns
number of elements in the cell

Definition at line 430 of file CellListFast.hpp.

template<unsigned int dim, typename T , typename transform , typename base >
template<unsigned int impl>
CellNNIterator<dim,CellList<dim,T,FAST,transform,base>,FULL,impl> CellList< dim, T, FAST, transform, base >::getNNIterator ( size_t  cell)
inline

Get the Neighborhood iterator.

It iterate across all the element of the selected cell and the near cells

  * * *
  * x *
  * * *
  • x is the selected cell
  • * are the near cell
Parameters
cellcell id

Definition at line 506 of file CellListFast.hpp.

template<unsigned int dim, typename T , typename transform , typename base >
template<unsigned int impl>
CellNNIterator<dim,CellList<dim,T,FAST,transform,base>,CRS,impl> CellList< dim, T, FAST, transform, base >::getNNIteratorCross ( size_t  cell)
inline

Get the Neighborhood iterator.

It iterate across all the element of the selected cell and the near cells

* *
x *
  • x is the selected cell
  • * are the near cell
Parameters
cellcell id

Definition at line 556 of file CellListFast.hpp.

template<unsigned int dim, typename T , typename transform , typename base >
template<unsigned int impl>
CellNNIterator<dim,CellList<dim,T,FAST,transform,base>,SYM,impl> CellList< dim, T, FAST, transform, base >::getNNIteratorSym ( size_t  cell)
inline

Get the Neighborhood iterator.

It iterate across all the element of the selected cell and the near cells

* * *
  x *
  • x is the selected cell
  • * are the near cell
Parameters
cellcell id

Definition at line 531 of file CellListFast.hpp.

template<unsigned int dim, typename T , typename transform , typename base >
void CellList< dim, T, FAST, transform, base >::Initialize ( const Box< dim, T > &  box,
const size_t(&)  div[dim],
const Point< dim, T > &  orig,
const size_t  pad = 1,
size_t  slot = 16 
)
inline

Initialize the cell list

Parameters
boxDomain where this cell list is living
divgrid size on each dimension
origorigin of the Cell list
padpadding cell
slotmaximum number of slot

Definition at line 148 of file CellListFast.hpp.

template<unsigned int dim, typename T , typename transform , typename base >
void CellList< dim, T, FAST, transform, base >::Initialize ( SpaceBox< dim, T > &  box,
const size_t(&)  div[dim],
const Point< dim, T > &  orig,
const size_t  pad = 1,
size_t  slot = 16 
)
inline

Initialize the cell list constructor

Parameters
boxDomain where this cell list is living
divgrid size on each dimension
padpadding cell
slotmaximum number of slot

Definition at line 165 of file CellListFast.hpp.

template<unsigned int dim, typename T , typename transform , typename base >
CellList<dim,T,FAST,transform,base>& CellList< dim, T, FAST, transform, base >::operator= ( CellList< dim, T, FAST, transform, base > &&  cell)
inline

Constructor from a temporal object.

Parameters
cellCell list structure

Definition at line 267 of file CellListFast.hpp.

template<unsigned int dim, typename T , typename transform , typename base >
CellList<dim,T,FAST,transform,base>& CellList< dim, T, FAST, transform, base >::operator= ( const CellList< dim, T, FAST, transform, base > &  cell)
inline

Constructor from a temporal object.

Parameters
cellCell list structure

Definition at line 292 of file CellListFast.hpp.

template<unsigned int dim, typename T , typename transform , typename base >
void CellList< dim, T, FAST, transform, base >::remove ( size_t  cell,
size_t  ele 
)
inline

remove an element from the cell

Parameters
cellcell id
eleelement id

Definition at line 418 of file CellListFast.hpp.

template<unsigned int dim, typename T , typename transform , typename base >
void CellList< dim, T, FAST, transform, base >::swap ( CellList< dim, T, FAST, transform, base > &  cl)
inline

Swap the memory.

Parameters
clCell list with witch you swap the memory

Definition at line 470 of file CellListFast.hpp.


The documentation for this class was generated from the following file: