walberla::mesa_pd::data::HashGrids::HashGrid Class Reference

Detailed Description

Implementation of the hash grid data structure.

Classes

struct  Cell
 Data structure for representing a cell in the hash grid (used by the 'Hierarchical Hash Grids' coarse collision detection algorithm). More...
 

Public Member Functions

 HashGrid (real_t cellSpan)
 
 ~HashGrid ()
 
real_t getCellSpan () const
 
template<typename Accessor >
void addParticle (size_t p_idx, Accessor &ac)
 Adds a particle to this hash grid. More...
 
template<typename Selector , typename Accessor , typename Func , typename... Args>
void checkEachParticlePairHalfAndStore (ParticleIdxVector &particlesOnGrid, const bool openmp, const Selector &selector, Accessor &ac, Func &&func, Args &&... args) const
 Processes this hash grid for colliding particles. More...
 
template<typename Selector , typename Accessor , typename Func , typename... Args>
void checkAgainstVectorEachParticlePairHalf (const ParticleIdxVector &particlesOnGrid, const bool openmp, const Selector &selector, Accessor &ac, Func &&func, Args &&... args) const
 Checks all the particles that are stored in particles for collisions with the particles that are stored in this grid. More...
 
void clear ()
 

Public Attributes

size_t xyzCellCount_
 Total number of allocated cells. More...
 
size_t enlargementThreshold_
 The enlargement threshold - the moment the number of assigned particles exceeds this threshold, the size of this hash grid is increased. More...
 
real_t cellSpan_
 The grid's cell size (edge length of the underlying cubic grid cells). More...
 
real_t inverseCellSpan_
 The inverse cell size. More...
 
CellVector occupiedCells_
 A grid-global list that keeps track of all particle-occupied cells. More...
 
size_t particleCount_
 Number of particles assigned to this hash grid. More...
 
offset_t stdNeighborOffset_ [27]
 Array of offsets to the neighboring cells (valid for all the inner cells of the hash grid). More...
 

Private Types

using offset_t = long
 The signed integer type that is used for storing offsets to neighboring cells. More...
 
using CellVector = std::vector< Cell * >
 Vector for storing pointers to (particle-occupied) cells. More...
 

Private Member Functions

void initializeNeighborOffsets ()
 Sets up the neighborhood relationships for all grid cells. More...
 
template<typename Accessor >
size_t hashOfParticle (size_t p_idx, Accessor &ac) const
 Computes the hash value (= cell association) of a given particle. More...
 
size_t hashPoint (real_t x, real_t y, real_t z) const
 Computes the hash for a given point. More...
 
void addParticleToCell (size_t p_idx, Cell *cell)
 Adds a particle to a specific cell in this hash grid. More...
 
template<typename Accessor >
void enlarge (Accessor &ac)
 Increases the number of cells used by this hash grid. More...
 

Private Attributes

Cellcell_
 Linear array of cells representing the three-dimensional hash grid. More...
 
size_t xCellCount_
 Number of cells allocated in x-axis direction. More...
 
size_t yCellCount_
 Number of cells allocated in y-axis direction. More...
 
size_t zCellCount_
 Number of cells allocated in z-axis direction. More...
 
size_t xHashMask_
 Bit-mask required for the hash calculation in x-axis direction (xCellCount_ - 1). More...
 
size_t yHashMask_
 Bit-mask required for the hash calculation in y-axis direction (yCellCount_ - 1). More...
 
size_t zHashMask_
 Bit-mask required for the hash calculation in z-axis direction (zCellCount_ - 1). More...
 
size_t xyCellCount_
 Number of cells allocated in x-axis direction multiplied by the number of cells allocated in y-axis direction. More...
 

Member Typedef Documentation

◆ CellVector

Vector for storing pointers to (particle-occupied) cells.

◆ offset_t

The signed integer type that is used for storing offsets to neighboring cells.

Constructor & Destructor Documentation

◆ HashGrid()

walberla::mesa_pd::data::HashGrids::HashGrid::HashGrid ( real_t  cellSpan)
explicit

◆ ~HashGrid()

walberla::mesa_pd::data::HashGrids::HashGrid::~HashGrid ( )

Member Function Documentation

◆ addParticle()

template<typename Accessor >
void walberla::mesa_pd::data::HashGrids::HashGrid::addParticle ( size_t  p_idx,
Accessor &  ac 
)
inline

Adds a particle to this hash grid.

This function is called every time a new rigid particle is added to this grid. If adding the particle will cause the total number of particles assigned to this grid to exceed the enlargement threshold, the size of this hash grid is increased in order to maintain a fixed minimal grid density (= ratio of cells to particles). This function may also be called during the update phase.

◆ addParticleToCell()

void walberla::mesa_pd::data::HashGrids::HashGrid::addParticleToCell ( size_t  p_idx,
Cell cell 
)
private

Adds a particle to a specific cell in this hash grid.

◆ checkAgainstVectorEachParticlePairHalf()

template<typename Selector , typename Accessor , typename Func , typename... Args>
void walberla::mesa_pd::data::HashGrids::HashGrid::checkAgainstVectorEachParticlePairHalf ( const ParticleIdxVector particlesOnGrid,
const bool  openmp,
const Selector &  selector,
Accessor &  ac,
Func &&  func,
Args &&...  args 
) const

Checks all the particles that are stored in particles for collisions with the particles that are stored in this grid.

This function generates all contacts between the rigid particles that are stored in particles and all the rigid particles that are assigned to this grid. The contacts are added to the contact container contacts.

◆ checkEachParticlePairHalfAndStore()

template<typename Selector , typename Accessor , typename Func , typename... Args>
void walberla::mesa_pd::data::HashGrids::HashGrid::checkEachParticlePairHalfAndStore ( ParticleIdxVector particlesOnGrid,
const bool  openmp,
const Selector &  selector,
Accessor &  ac,
Func &&  func,
Args &&...  args 
) const

Processes this hash grid for colliding particles.

This function generates all contacts between all rigid particles that are assigned to this grid. Moreover, a linear array that contains (handles to) all particles that are stored in this grid is returned in order to being able to check these particles against other particles that are stored in grids with larger sized cells.

◆ clear()

void walberla::mesa_pd::data::HashGrids::HashGrid::clear ( )

◆ enlarge()

template<typename Accessor >
void walberla::mesa_pd::data::HashGrids::HashGrid::enlarge ( Accessor &  ac)
private

Increases the number of cells used by this hash grid.

In order to handle an initially unknown and ultimately arbitrary number of particles, the hash grid, starting with a rather small number of cells at the time of its creation, must have the ability to grow as new particles are inserted. Therefore, if by inserting a particle into this hash grid the associated grid density - that is the ratio of cells to particles - drops below the threshold specified by minimalGridDensity, or in other words, if the number of particles grows larger than specified by enlargementThreshold_, the number of cells in each coordinate direction is doubled (thus the total number of grid cells is increased by a factor of 8).

◆ getCellSpan()

real_t walberla::mesa_pd::data::HashGrids::HashGrid::getCellSpan ( ) const
inline

◆ hashOfParticle()

template<typename Accessor >
size_t walberla::mesa_pd::data::HashGrids::HashGrid::hashOfParticle ( size_t  p_idx,
Accessor &  ac 
) const
private

Computes the hash value (= cell association) of a given particle.

◆ hashPoint()

size_t walberla::mesa_pd::data::HashGrids::HashGrid::hashPoint ( real_t  x,
real_t  y,
real_t  z 
) const
private

Computes the hash for a given point.

The hash calculation uses modulo operations in order to spatially map entire blocks of connected cells to the origin of the coordinate system. This block of cells at the origin of the coordinate system that is filled with all the particles of the simulation is referred to as the hash grid. The key feature, and ultimately the advantage, of hash grids is the fact that two adjacent cells that are located anywhere in the simulation space are mapped to two cells that are still adjacent in the hashed storage structure.

Note that the modulo calculations are replaced with fast bitwise AND operations - hence, the spatial dimensions of the hash grid must be restricted to powers of two!

◆ initializeNeighborOffsets()

void walberla::mesa_pd::data::HashGrids::HashGrid::initializeNeighborOffsets ( )
private

Sets up the neighborhood relationships for all grid cells.

This function is used to initialize the offset arrays of all grid cells. The offsets are required for ensuring fast direct access to all directly adjacent cells for each cell in the hash grid.

Member Data Documentation

◆ cell_

Cell* walberla::mesa_pd::data::HashGrids::HashGrid::cell_
private

Linear array of cells representing the three-dimensional hash grid.

◆ cellSpan_

real_t walberla::mesa_pd::data::HashGrids::HashGrid::cellSpan_

The grid's cell size (edge length of the underlying cubic grid cells).

◆ enlargementThreshold_

size_t walberla::mesa_pd::data::HashGrids::HashGrid::enlargementThreshold_

The enlargement threshold - the moment the number of assigned particles exceeds this threshold, the size of this hash grid is increased.

◆ inverseCellSpan_

real_t walberla::mesa_pd::data::HashGrids::HashGrid::inverseCellSpan_

The inverse cell size.

Required for replacing floating point divisions with multiplications during the hash computation.

◆ occupiedCells_

CellVector walberla::mesa_pd::data::HashGrids::HashGrid::occupiedCells_

A grid-global list that keeps track of all particle-occupied cells.

The list is required in order to avoid iterating through all grid cells whenever all particles that are stored in the grid need to be addressed.

◆ particleCount_

size_t walberla::mesa_pd::data::HashGrids::HashGrid::particleCount_

Number of particles assigned to this hash grid.

◆ stdNeighborOffset_

offset_t walberla::mesa_pd::data::HashGrids::HashGrid::stdNeighborOffset_[27]

Array of offsets to the neighboring cells (valid for all the inner cells of the hash grid).

◆ xCellCount_

size_t walberla::mesa_pd::data::HashGrids::HashGrid::xCellCount_
private

Number of cells allocated in x-axis direction.

◆ xHashMask_

size_t walberla::mesa_pd::data::HashGrids::HashGrid::xHashMask_
private

Bit-mask required for the hash calculation in x-axis direction (xCellCount_ - 1).

◆ xyCellCount_

size_t walberla::mesa_pd::data::HashGrids::HashGrid::xyCellCount_
private

Number of cells allocated in x-axis direction multiplied by the number of cells allocated in y-axis direction.

◆ xyzCellCount_

size_t walberla::mesa_pd::data::HashGrids::HashGrid::xyzCellCount_

Total number of allocated cells.

◆ yCellCount_

size_t walberla::mesa_pd::data::HashGrids::HashGrid::yCellCount_
private

Number of cells allocated in y-axis direction.

◆ yHashMask_

size_t walberla::mesa_pd::data::HashGrids::HashGrid::yHashMask_
private

Bit-mask required for the hash calculation in y-axis direction (yCellCount_ - 1).

◆ zCellCount_

size_t walberla::mesa_pd::data::HashGrids::HashGrid::zCellCount_
private

Number of cells allocated in z-axis direction.

◆ zHashMask_

size_t walberla::mesa_pd::data::HashGrids::HashGrid::zHashMask_
private

Bit-mask required for the hash calculation in z-axis direction (zCellCount_ - 1).


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