MercuryDPM  Beta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HGrid Class Reference

In the HGrid class, here all information about the HGrid is stored. More...

#include <HGrid.h>

Public Member Functions

 HGrid ()
 Default constructor, it sets the parameters to some sensible defaults. More...
 
 HGrid (unsigned int num_buckets, double cellOverSizeRatio, std::vector< double > &cellSizes)
 Constructor: initialises parameters and allocates space for internal variables. More...
 
 ~HGrid ()
 Destructor. More...
 
void Initialize_inv_size ()
 
void insertParticleToHgrid (BaseParticle *obj)
 Inserts the given BaseParticle in to the HGrid. More...
 
unsigned int computeHashBucketIndex (int x, int y, int z, unsigned int l) const
 Computes hash bucket index in range [0, NUM_BUCKETS-1] for a 3D domain. More...
 
unsigned int computeHashBucketIndex (int x, int y, unsigned int l) const
 Computes hash bucket index in range [0, NUM_BUCKETS-1] for a 2D domain. More...
 
void clearBucketIsChecked ()
 Sets all buckets to not-checked. More...
 
void clearFirstBaseParticleInBucket ()
 For all buckets, it removes the pointer to the first BaseParticle in it, practically emptying the buckets. More...
 
void setFirstBaseParticleInBucket (unsigned int i, BaseParticle *p)
 Sets the first particle in bucket i to be the given BaseParticle. More...
 
void setBucketIsChecked (unsigned int i)
 Sets that the bucket with the given index is checked to true. More...
 
bool getBucketIsChecked (unsigned int i) const
 Gets whether or not the bucket with index i is checked. More...
 
Mdouble getCellOverSizeRatio () const
 Gets the maximum ratio of the cell to a particle it contains. More...
 
double getCellSize (unsigned int i) const
 Gets the size of the cells at the given level. More...
 
const std::vector< double > & getCellSizes () const
 Gets the sizes of the cells at all levels as a vector. More...
 
const BaseParticlegetFirstBaseParticleInBucket (unsigned int i) const
 Gets the first BaseParticle in the given bucket, const version. More...
 
BaseParticlegetFirstBaseParticleInBucket (unsigned int i)
 Gets the first BaseParticle in the given bucket. More...
 
double getInvCellSize (unsigned int i) const
 Gets 1/cellSize for the cells on level i. More...
 
const std::vector< double > & getInvCellSizes () const
 Gets all the inverse cell sizes (1/cellSize) for all levels as a vector. More...
 
bool getNeedsRebuilding () const
 Gets whether or not the grid needs to be rebuilt before something else is done with it. More...
 
unsigned int getNumberOfBuckets () const
 Gets the number of buckets of this HGrid. More...
 
unsigned int getNumberOfLevels () const
 Gets the number of levels of this HGrid. More...
 
int getOccupiedLevelsMask () const
 Gets the integer that represents which levels are occupied. More...
 
void info () const
 Displays the member variables of the hGrid object. This function is intended for debugging the hGrid, therefore the variables are displayed next to the variable names instead of putting it in a user-friendly format. More...
 

Private Attributes

bool needsRebuilding_
 Flag sets if the HGrid needs to be rebuilt. More...
 
unsigned int numberOfBuckets_
 The number of buckets in the current HGrid. More...
 
Mdouble cellOverSizeRatio_
 The maximum ratio between the size of the cell and the size of a particle it contains. More...
 
int occupiedLevelsMask_
 Marks if there are particles at certain levels. More...
 
std::vector< double > cellSizes_
 The sizes of the cells in the different grids. More...
 
std::vector< double > invCellSizes_
 The inverse sizes of the cells in the different grids, where the inverse is defined as 1/cellSizes_. More...
 
std::vector< BaseParticle * > firstBaseParticleInBucket_
 Stores a pointer to first element in hash bucket b. More...
 
std::vector< bool > bucketIsChecked_
 BucketIsChecked stores if hash bucket b is checked already; initially all false. More...
 

Detailed Description

In the HGrid class, here all information about the HGrid is stored.

In particular, the hashing the grid is done in this class, the cell sizes of the different levels are stored, it is stored whether or not there are BaseParticle on each level and there is a flag to see if the HGrid needs to be rebuilt.

Definition at line 41 of file HGrid.h.

Constructor & Destructor Documentation

HGrid::HGrid ( )

Default constructor, it sets the parameters to some sensible defaults.

Definition at line 30 of file HGrid.cc.

References cellOverSizeRatio_, DEBUG, logger, needsRebuilding_, numberOfBuckets_, and occupiedLevelsMask_.

31 {
32  needsRebuilding_ = true;
33  numberOfBuckets_ = 10;
34  cellOverSizeRatio_ = 1.0;
36  logger(DEBUG, "HGrid::HGrid() finished");
37 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Mdouble cellOverSizeRatio_
The maximum ratio between the size of the cell and the size of a particle it contains.
Definition: HGrid.h:183
unsigned int numberOfBuckets_
The number of buckets in the current HGrid.
Definition: HGrid.h:178
int occupiedLevelsMask_
Marks if there are particles at certain levels.
Definition: HGrid.h:190
bool needsRebuilding_
Flag sets if the HGrid needs to be rebuilt.
Definition: HGrid.h:171
HGrid::HGrid ( unsigned int  num_buckets,
double  cellOverSizeRatio,
std::vector< double > &  cellSizes 
)

Constructor: initialises parameters and allocates space for internal variables.

Parameters
[in]num_bucketsThe number of buckets that are used by this HGrid.
[in]cellOverSizeRatioThe maximum ratio between the size of the cell over the size of the particle.
[in]cellSizesThe sizes of the cells we want to set.

Constructor: initialises parameters and allocates space for internal variables.

Definition at line 47 of file HGrid.cc.

References bucketIsChecked_, cellOverSizeRatio_, cellSizes_, DEBUG, firstBaseParticleInBucket_, invCellSizes_, logger, needsRebuilding_, numberOfBuckets_, and occupiedLevelsMask_.

48 {
49  needsRebuilding_ = false;
50  numberOfBuckets_ = num_buckets;
51  cellOverSizeRatio_ = cellOverSizeRatio;
53 
55  bucketIsChecked_.resize(numberOfBuckets_, false);
56 
57  //std::cout<<"Creating HGrid "<<cellSizes.size()<<" levels:"<<std::endl;
58  for (unsigned int i = 0; i < cellSizes.size(); i++)
59  {
60  //std::cout<<"Level="<<i<<" size="<<cellSizes[i]<<std::endl;
61  cellSizes_.push_back(cellSizes[i]);
62  invCellSizes_.push_back(1.0 / cellSizes[i]);
63  }
64  logger(DEBUG, "HGrid::HGrid(unsigned int, double, vector<double>&) constructor finished.");
65  /* std::cout << "HGrid::HGrid(" << num_buckets << ", " << cellOverSizeRatio << ", [";
66  for (auto p: cellSizes) std::cout << p << " ";
67  std::cout << "]) finished" << std::endl;*/
68 }
std::vector< bool > bucketIsChecked_
BucketIsChecked stores if hash bucket b is checked already; initially all false.
Definition: HGrid.h:216
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Mdouble cellOverSizeRatio_
The maximum ratio between the size of the cell and the size of a particle it contains.
Definition: HGrid.h:183
std::vector< BaseParticle * > firstBaseParticleInBucket_
Stores a pointer to first element in hash bucket b.
Definition: HGrid.h:211
std::vector< double > invCellSizes_
The inverse sizes of the cells in the different grids, where the inverse is defined as 1/cellSizes_...
Definition: HGrid.h:203
std::vector< double > cellSizes_
The sizes of the cells in the different grids.
Definition: HGrid.h:198
unsigned int numberOfBuckets_
The number of buckets in the current HGrid.
Definition: HGrid.h:178
int occupiedLevelsMask_
Marks if there are particles at certain levels.
Definition: HGrid.h:190
bool needsRebuilding_
Flag sets if the HGrid needs to be rebuilt.
Definition: HGrid.h:171
HGrid::~HGrid ( )

Destructor.

Definition at line 70 of file HGrid.cc.

References DEBUG, and logger.

71 {
72  logger(DEBUG, "HGrid::~HGrid() destructor finished");
73 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")

Member Function Documentation

void HGrid::clearBucketIsChecked ( )

Sets all buckets to not-checked.

Definition at line 164 of file HGrid.cc.

References bucketIsChecked_.

Referenced by MercuryBase::hGridActionsBeforeTimeStep().

165 {
166  for (std::vector<bool>::iterator it = bucketIsChecked_.begin(); it != bucketIsChecked_.end(); ++it)
167  {
168  (*it) = false;
169  }
170 }
std::vector< bool > bucketIsChecked_
BucketIsChecked stores if hash bucket b is checked already; initially all false.
Definition: HGrid.h:216
void HGrid::clearFirstBaseParticleInBucket ( )

For all buckets, it removes the pointer to the first BaseParticle in it, practically emptying the buckets.

Definition at line 188 of file HGrid.cc.

References firstBaseParticleInBucket_.

Referenced by MercuryBase::hGridActionsBeforeTimeStep().

189 {
190  for (std::vector<BaseParticle*>::iterator it = firstBaseParticleInBucket_.begin(); it != firstBaseParticleInBucket_.end(); ++it)
191  {
192  (*it) = nullptr;
193  }
194 }
std::vector< BaseParticle * > firstBaseParticleInBucket_
Stores a pointer to first element in hash bucket b.
Definition: HGrid.h:211
unsigned int HGrid::computeHashBucketIndex ( int  x,
int  y,
int  z,
unsigned int  l 
) const

Computes hash bucket index in range [0, NUM_BUCKETS-1] for a 3D domain.

Computes a hash from parameters, the result is in range [0, numberOfBuckets_-1].

Parameters
[in]xThe coordinate of the cell in x direction for which the hash must be computed.
[in]yThe coordinate of the cell in y direction for which the hash must be computed.
[in]zThe coordinate of the cell in z direction for which the hash must be computed.
[in]lThe level in the HGrid of the cell for which the hash must be computed.
Returns
The hash value for the given cell (x,y,z,l), which is in the range [0,numberOfBuckets_-1].

Definition at line 124 of file HGrid.cc.

References numberOfBuckets_.

Referenced by Mercury2D::hGridFindContactsWithinTargetCell(), Mercury3D::hGridFindContactsWithinTargetCell(), Mercury2D::hGridFindContactsWithTargetCell(), Mercury3D::hGridFindContactsWithTargetCell(), Mercury3D::hGridHasContactsInTargetCell(), Mercury2D::hGridRemoveParticle(), Mercury3D::hGridRemoveParticle(), Mercury3D::hGridUpdateParticle(), and Mercury2D::hGridUpdateParticle().

125 {
126  const unsigned int h1 = 0x8da6b343u; // Large multiplicative constants;
127  const unsigned int h2 = 0xd8163841u; // here arbitrarily chosen primes
128  const unsigned int h3 = 0xcb1ab31fu;
129  const unsigned int h4 = 0x165667b1u;
130 
131  unsigned long int n = h1 * x + h2 * y + h3 * z + h4 * l;
132  n = n % numberOfBuckets_;
133 
134  return static_cast<unsigned int>(n);
135 }
unsigned int numberOfBuckets_
The number of buckets in the current HGrid.
Definition: HGrid.h:178
unsigned int HGrid::computeHashBucketIndex ( int  x,
int  y,
unsigned int  l 
) const

Computes hash bucket index in range [0, NUM_BUCKETS-1] for a 2D domain.

Computes a hash from parameters, the result is in range [0, numberOfBuckets_-1].

Parameters
[in]xThe coordinate of the cell in x direction for which the hash must be computed.
[in]yThe coordinate of the cell in y direction for which the hash must be computed.
[in]lThe level in the HGrid of the cell for which the hash must be computed.
Returns
The hash value for the given cell (x,y,l), which is in the range [0,numberOfBuckets_-1].

Definition at line 144 of file HGrid.cc.

References numberOfBuckets_.

145 {
146  const unsigned int h1 = 0x8da6b343u; // Large multiplicative constants;
147  const unsigned int h2 = 0xd8163841u; // here arbitrarily chosen primes
148  const unsigned int h4 = 0x165667b1u;
149 
150  unsigned long int n = h1 * x + h2 * y + h4 * l;
151  n = n % numberOfBuckets_;
152 
153  return static_cast<unsigned int>(n);
154 }
unsigned int numberOfBuckets_
The number of buckets in the current HGrid.
Definition: HGrid.h:178
bool HGrid::getBucketIsChecked ( unsigned int  i) const

Gets whether or not the bucket with index i is checked.

Parameters
[in]iThe ordinal number of the bucket we want to know for whether or not it has been checked.
Returns
A boolean which is true if the bucket is checked and false otherwise.

Definition at line 200 of file HGrid.cc.

References bucketIsChecked_.

Referenced by Mercury2D::hGridFindContactsWithinTargetCell(), and Mercury3D::hGridFindContactsWithinTargetCell().

201 {
202  return bucketIsChecked_[i];
203 }
std::vector< bool > bucketIsChecked_
BucketIsChecked stores if hash bucket b is checked already; initially all false.
Definition: HGrid.h:216
Mdouble HGrid::getCellOverSizeRatio ( ) const

Gets the maximum ratio of the cell to a particle it contains.

Returns
The ratio between the size of the smallest cell and the smallest BaseParticle.

Definition at line 277 of file HGrid.cc.

References cellOverSizeRatio_.

Referenced by MercuryBase::hGridNeedsRebuilding().

278 {
279  return cellOverSizeRatio_;
280 }
Mdouble cellOverSizeRatio_
The maximum ratio between the size of the cell and the size of a particle it contains.
Definition: HGrid.h:183
double HGrid::getCellSize ( unsigned int  i) const

Gets the size of the cells at the given level.

Parameters
[in]iThe level we want to know the cell size of.
Returns
The size of the cells at the given level.

Definition at line 252 of file HGrid.cc.

References cellSizes_.

Referenced by MercuryBase::hGridUpdateMove().

253 {
254  return cellSizes_[i];
255 }
std::vector< double > cellSizes_
The sizes of the cells in the different grids.
Definition: HGrid.h:198
const std::vector< double > & HGrid::getCellSizes ( ) const

Gets the sizes of the cells at all levels as a vector.

Returns
A vector with the sizes of the cells of different levels.

Definition at line 175 of file HGrid.cc.

References cellSizes_.

Referenced by MercuryBase::hGridNeedsRebuilding().

176 {
177  return cellSizes_;
178 }
std::vector< double > cellSizes_
The sizes of the cells in the different grids.
Definition: HGrid.h:198
const BaseParticle * HGrid::getFirstBaseParticleInBucket ( unsigned int  i) const

Gets the first BaseParticle in the given bucket, const version.

Parameters
[in]iThe ordinal number of the bucket for which we want to get the first particle of.
Returns
A pointer to the (constant) BaseParticle which is the first Baseparticle in the given bucket.

Definition at line 209 of file HGrid.cc.

References firstBaseParticleInBucket_.

Referenced by Mercury2D::hGridFindContactsWithinTargetCell(), Mercury3D::hGridFindContactsWithinTargetCell(), Mercury2D::hGridFindContactsWithTargetCell(), Mercury3D::hGridFindContactsWithTargetCell(), Mercury3D::hGridHasContactsInTargetCell(), Mercury2D::hGridRemoveParticle(), Mercury3D::hGridRemoveParticle(), Mercury3D::hGridUpdateParticle(), and Mercury2D::hGridUpdateParticle().

210 {
211  return firstBaseParticleInBucket_[i];
212 }
std::vector< BaseParticle * > firstBaseParticleInBucket_
Stores a pointer to first element in hash bucket b.
Definition: HGrid.h:211
BaseParticle * HGrid::getFirstBaseParticleInBucket ( unsigned int  i)

Gets the first BaseParticle in the given bucket.

Parameters
[in]iThe ordinal number of the bucket for which we want to get the first particle of.
Returns
A pointer to the BaseParticle which is the first Baseparticle in the given bucket.

Definition at line 218 of file HGrid.cc.

References firstBaseParticleInBucket_.

219 {
220  return firstBaseParticleInBucket_[i];
221 }
std::vector< BaseParticle * > firstBaseParticleInBucket_
Stores a pointer to first element in hash bucket b.
Definition: HGrid.h:211
double HGrid::getInvCellSize ( unsigned int  i) const

Gets 1/cellSize for the cells on level i.

Parameters
[in]iThe level we want to know the inverse cell size of.
Returns
The inverse size, i.e. 1/size, of the cells at the given level.

Definition at line 261 of file HGrid.cc.

References invCellSizes_.

Referenced by Mercury2D::hGridFindOneSidedContacts(), Mercury3D::hGridFindOneSidedContacts(), Mercury2D::hGridHasParticleContacts(), Mercury2D::hGridUpdateParticle(), and Mercury3D::hGridUpdateParticle().

262 {
263  return invCellSizes_[i];
264 }
std::vector< double > invCellSizes_
The inverse sizes of the cells in the different grids, where the inverse is defined as 1/cellSizes_...
Definition: HGrid.h:203
const std::vector< double > & HGrid::getInvCellSizes ( ) const

Gets all the inverse cell sizes (1/cellSize) for all levels as a vector.

Returns
A vector with the inverse sizes (1/size) of the cells of different levels.

Definition at line 183 of file HGrid.cc.

References invCellSizes_.

184 {
185  return invCellSizes_;
186 }
std::vector< double > invCellSizes_
The inverse sizes of the cells in the different grids, where the inverse is defined as 1/cellSizes_...
Definition: HGrid.h:203
bool HGrid::getNeedsRebuilding ( ) const

Gets whether or not the grid needs to be rebuilt before something else is done with it.

Returns
A boolean which indicates whether or not the HGrid needs rebuilding.

Definition at line 269 of file HGrid.cc.

References needsRebuilding_.

Referenced by MercuryBase::hGridNeedsRebuilding().

270 {
271  return needsRebuilding_;
272 }
bool needsRebuilding_
Flag sets if the HGrid needs to be rebuilt.
Definition: HGrid.h:171
unsigned int HGrid::getNumberOfBuckets ( ) const

Gets the number of buckets of this HGrid.

Returns
The number of buckets in this HGrid.

Definition at line 159 of file HGrid.cc.

References numberOfBuckets_.

Referenced by MercuryBase::hGridNeedsRebuilding(), and MercuryBase::write().

160 {
161  return numberOfBuckets_;
162 }
unsigned int numberOfBuckets_
The number of buckets in the current HGrid.
Definition: HGrid.h:178
unsigned int HGrid::getNumberOfLevels ( ) const

Gets the number of levels of this HGrid.

Returns
The number of levels in this HGrid.

Definition at line 234 of file HGrid.cc.

References cellSizes_.

Referenced by Mercury2D::hGridFindOneSidedContacts(), Mercury3D::hGridFindOneSidedContacts(), and Mercury2D::hGridHasParticleContacts().

235 {
236  return cellSizes_.size();
237 }
std::vector< double > cellSizes_
The sizes of the cells in the different grids.
Definition: HGrid.h:198
int HGrid::getOccupiedLevelsMask ( ) const

Gets the integer that represents which levels are occupied.

Returns
The integer that represents the bit-vector that indicates which levels have at least one particle.

Definition at line 285 of file HGrid.cc.

References occupiedLevelsMask_.

Referenced by Mercury2D::hGridFindOneSidedContacts(), Mercury3D::hGridFindOneSidedContacts(), and Mercury2D::hGridHasParticleContacts().

286 {
287  return occupiedLevelsMask_;
288 }
int occupiedLevelsMask_
Marks if there are particles at certain levels.
Definition: HGrid.h:190
void HGrid::info ( ) const

Displays the member variables of the hGrid object. This function is intended for debugging the hGrid, therefore the variables are displayed next to the variable names instead of putting it in a user-friendly format.

Definition at line 290 of file HGrid.cc.

References bucketIsChecked_, cellOverSizeRatio_, cellSizes_, firstBaseParticleInBucket_, invCellSizes_, needsRebuilding_, numberOfBuckets_, and occupiedLevelsMask_.

Referenced by MercuryBase::hGridInfo().

291 {
292  std::cout << "Current status of hGrid parameters:" << std::endl;
293  std::cout << "bool needsRebuilding_=" << needsRebuilding_ << std::endl;
294  std::cout << "unsigned int numberOfBuckets_=" << numberOfBuckets_ << std::endl;
295  std::cout << "Mdouble cellOverSizeRatio_=" << cellOverSizeRatio_ << std::endl;
296  std::cout << "int occupiedLevelsMask_=" << occupiedLevelsMask_ << std::endl;
297  std::cout << "std::vector<double> cellSizes_[" << cellSizes_.size() << "]=";
298  for (auto p: cellSizes_) std::cout << p << " ";
299  std::cout << std::endl;
300  std::cout << "std::vector<double> invCellSizes_[" << invCellSizes_.size() << "]=";
301  for (auto p: invCellSizes_) std::cout << p << " ";
302  std::cout << std::endl;
303  std::cout << "std::vector<BaseParticle> firstBaseParticleInBucket_[" << firstBaseParticleInBucket_.size() << "]=... (not shown)";
304  //for (auto p: firstBaseParticleInBucket_) std::cout << p << " ";
305  std::cout << std::endl;
306  std::cout << "std::vector<bool> bucketIsChecked_[" << bucketIsChecked_.size() << "]=... (not shown)";
307  //for (auto p: bucketIsChecked_) std::cout << p << " ";
308  std::cout << std::endl;
309 }
std::vector< bool > bucketIsChecked_
BucketIsChecked stores if hash bucket b is checked already; initially all false.
Definition: HGrid.h:216
Mdouble cellOverSizeRatio_
The maximum ratio between the size of the cell and the size of a particle it contains.
Definition: HGrid.h:183
std::vector< BaseParticle * > firstBaseParticleInBucket_
Stores a pointer to first element in hash bucket b.
Definition: HGrid.h:211
std::vector< double > invCellSizes_
The inverse sizes of the cells in the different grids, where the inverse is defined as 1/cellSizes_...
Definition: HGrid.h:203
std::vector< double > cellSizes_
The sizes of the cells in the different grids.
Definition: HGrid.h:198
unsigned int numberOfBuckets_
The number of buckets in the current HGrid.
Definition: HGrid.h:178
int occupiedLevelsMask_
Marks if there are particles at certain levels.
Definition: HGrid.h:190
bool needsRebuilding_
Flag sets if the HGrid needs to be rebuilt.
Definition: HGrid.h:171
void HGrid::Initialize_inv_size ( )
Todo:
TW: Where is this function defined??
void HGrid::insertParticleToHgrid ( BaseParticle obj)

Inserts the given BaseParticle in to the HGrid.

Parameters
[in]objA pointer to the BaseParticle we want to add to the HGrid.

Inserts the given BaseParticle into the HGrid, i.e. it sets up the particle grid properties and updates the level information on the grid. First find which level is big enough to fit the BaseParticle in, then add the BaseParticle to that level and set that level as occupied in the occupiedLevelsMask_.

Bug:
What happens if the particle is too big for the biggest cell? It just says that it needs to rebuild the HGrid, but the particle is not inserted and there seems to be no indication to the rest of the code that it has not been inserted. For now giving a warning, since code of users may rely on it that nothing happens.

Definition at line 88 of file HGrid.cc.

References cellOverSizeRatio_, cellSizes_, BaseObject::getId(), BaseObject::getIndex(), BaseParticle::getInteractionRadius(), logger, needsRebuilding_, occupiedLevelsMask_, BaseParticle::setHGridLevel(), and WARN.

Referenced by MercuryBase::hGridInsertParticle().

89 {
90  if(!needsRebuilding_)
91  {
92  // Find lowest level where object fully fits inside cell, taking cellOverSizeRatio_ into account
93  Mdouble diameter = obj->getInteractionRadius() * 2.0;
94  unsigned int level = 0;
95  while (level < cellSizes_.size() && cellSizes_[level] <= diameter * cellOverSizeRatio_)
96  {
97  level++;
98  }
99 
100  if (level >= cellSizes_.size())
101  {
102  logger(WARN, "WARNING: object (id = %, index = %) is larger (d = %, cellOverSizeRatio = %) than largest grid cell (%) allows.", obj->getId(), obj->getIndex(), diameter, cellOverSizeRatio_, cellSizes_.back());
103  needsRebuilding_ = true;
104  }
105 
106  obj->setHGridLevel(level);
107  // indicate level is in use - not levels with no particles no collision detection is performed
108  this->occupiedLevelsMask_ |= (1 << level);
109  }
110  else
111  {
112  logger(WARN, "WARNING: the HGrid needs to be rebuild before insertParticleToHgrid may be called!");
113  }
114 }
unsigned int getId() const
Returns the unique identifier of any particular object.
Definition: BaseObject.cc:113
unsigned int getIndex() const
Returns the index of the object in the handler.
Definition: BaseObject.cc:106
void setHGridLevel(const unsigned int level)
Sets the particle's HGrid level.
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
Mdouble cellOverSizeRatio_
The maximum ratio between the size of the cell and the size of a particle it contains.
Definition: HGrid.h:183
std::vector< double > cellSizes_
The sizes of the cells in the different grids.
Definition: HGrid.h:198
int occupiedLevelsMask_
Marks if there are particles at certain levels.
Definition: HGrid.h:190
bool needsRebuilding_
Flag sets if the HGrid needs to be rebuilt.
Definition: HGrid.h:171
Mdouble getInteractionRadius() const
Returns the particle's interaction radius, which might be different from radius_ (e.g., when dealing with wet particles)
void HGrid::setBucketIsChecked ( unsigned int  i)

Sets that the bucket with the given index is checked to true.

Parameters
[in]iThe ordinal number of the bucket we want to mark as checked.

Definition at line 226 of file HGrid.cc.

References bucketIsChecked_.

Referenced by Mercury2D::hGridFindContactsWithinTargetCell(), and Mercury3D::hGridFindContactsWithinTargetCell().

227 {
228  bucketIsChecked_[i] = true;
229 }
std::vector< bool > bucketIsChecked_
BucketIsChecked stores if hash bucket b is checked already; initially all false.
Definition: HGrid.h:216
void HGrid::setFirstBaseParticleInBucket ( unsigned int  i,
BaseParticle p 
)

Sets the first particle in bucket i to be the given BaseParticle.

Parameters
[in]iThe ordinal number of the bucket we want to set the first BaseParticle for.
[in]pA pointer to the BaseParticle we want to place in the given bucket.

Definition at line 243 of file HGrid.cc.

References firstBaseParticleInBucket_.

Referenced by Mercury2D::hGridRemoveParticle(), Mercury3D::hGridRemoveParticle(), Mercury3D::hGridUpdateParticle(), and Mercury2D::hGridUpdateParticle().

244 {
246 }
std::vector< BaseParticle * > firstBaseParticleInBucket_
Stores a pointer to first element in hash bucket b.
Definition: HGrid.h:211

Member Data Documentation

std::vector<bool> HGrid::bucketIsChecked_
private

BucketIsChecked stores if hash bucket b is checked already; initially all false.

Definition at line 216 of file HGrid.h.

Referenced by clearBucketIsChecked(), getBucketIsChecked(), HGrid(), info(), and setBucketIsChecked().

Mdouble HGrid::cellOverSizeRatio_
private

The maximum ratio between the size of the cell and the size of a particle it contains.

Definition at line 183 of file HGrid.h.

Referenced by getCellOverSizeRatio(), HGrid(), info(), and insertParticleToHgrid().

std::vector<double> HGrid::cellSizes_
private

The sizes of the cells in the different grids.

The sizes of the cells in the different grids are saved in a vector of double. The smaller the index in the vector, the smaller the cells.

Definition at line 198 of file HGrid.h.

Referenced by getCellSize(), getCellSizes(), getNumberOfLevels(), HGrid(), info(), and insertParticleToHgrid().

std::vector<BaseParticle*> HGrid::firstBaseParticleInBucket_
private

Stores a pointer to first element in hash bucket b.

The pointer to the first element in a certain bucket, initially a nullptr, is the pointer to the first BaseParticle in the first cell in the bucket.

Definition at line 211 of file HGrid.h.

Referenced by clearFirstBaseParticleInBucket(), getFirstBaseParticleInBucket(), HGrid(), info(), and setFirstBaseParticleInBucket().

std::vector<double> HGrid::invCellSizes_
private

The inverse sizes of the cells in the different grids, where the inverse is defined as 1/cellSizes_.

Definition at line 203 of file HGrid.h.

Referenced by getInvCellSize(), getInvCellSizes(), HGrid(), and info().

bool HGrid::needsRebuilding_
private

Flag sets if the HGrid needs to be rebuilt.

Definition at line 171 of file HGrid.h.

Referenced by getNeedsRebuilding(), HGrid(), info(), and insertParticleToHgrid().

unsigned int HGrid::numberOfBuckets_
private

The number of buckets in the current HGrid.

The number of buckets is the number of possible "results" of the hash function for the grid.

Definition at line 178 of file HGrid.h.

Referenced by computeHashBucketIndex(), getNumberOfBuckets(), HGrid(), and info().

int HGrid::occupiedLevelsMask_
private

Marks if there are particles at certain levels.

The l-th bit of occupiedLevelsMask_ is 1 if level l is contains particles (Implies max 32 hgrid levels) and 0 if it contains none.

Definition at line 190 of file HGrid.h.

Referenced by getOccupiedLevelsMask(), HGrid(), info(), and insertParticleToHgrid().


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