MercuryDPM
Beta
|
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 BaseParticle * | getFirstBaseParticleInBucket (unsigned int i) const |
Gets the first BaseParticle in the given bucket, const version. More... | |
BaseParticle * | getFirstBaseParticleInBucket (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... | |
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.
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_.
HGrid::HGrid | ( | unsigned int | num_buckets, |
double | cellOverSizeRatio, | ||
std::vector< double > & | cellSizes | ||
) |
Constructor: initialises parameters and allocates space for internal variables.
[in] | num_buckets | The number of buckets that are used by this HGrid. |
[in] | cellOverSizeRatio | The maximum ratio between the size of the cell over the size of the particle. |
[in] | cellSizes | The 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_.
HGrid::~HGrid | ( | ) |
void HGrid::clearBucketIsChecked | ( | ) |
Sets all buckets to not-checked.
Definition at line 164 of file HGrid.cc.
References bucketIsChecked_.
Referenced by MercuryBase::hGridActionsBeforeTimeStep().
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().
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].
[in] | x | The coordinate of the cell in x direction for which the hash must be computed. |
[in] | y | The coordinate of the cell in y direction for which the hash must be computed. |
[in] | z | The coordinate of the cell in z direction for which the hash must be computed. |
[in] | l | The level in the HGrid of the cell for which the hash must be computed. |
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().
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].
[in] | x | The coordinate of the cell in x direction for which the hash must be computed. |
[in] | y | The coordinate of the cell in y direction for which the hash must be computed. |
[in] | l | The level in the HGrid of the cell for which the hash must be computed. |
Definition at line 144 of file HGrid.cc.
References numberOfBuckets_.
bool HGrid::getBucketIsChecked | ( | unsigned int | i | ) | const |
Gets whether or not the bucket with index i is checked.
[in] | i | The ordinal number of the bucket we want to know for whether or not it has been checked. |
Definition at line 200 of file HGrid.cc.
References bucketIsChecked_.
Referenced by Mercury2D::hGridFindContactsWithinTargetCell(), and Mercury3D::hGridFindContactsWithinTargetCell().
Mdouble HGrid::getCellOverSizeRatio | ( | ) | const |
Gets the maximum ratio of the cell to a particle it contains.
Definition at line 277 of file HGrid.cc.
References cellOverSizeRatio_.
Referenced by MercuryBase::hGridNeedsRebuilding().
double HGrid::getCellSize | ( | unsigned int | i | ) | const |
Gets the size of the cells at the given level.
[in] | i | The level we want to know the cell size of. |
Definition at line 252 of file HGrid.cc.
References cellSizes_.
Referenced by MercuryBase::hGridUpdateMove().
const std::vector< double > & HGrid::getCellSizes | ( | ) | const |
Gets the sizes of the cells at all levels as a vector.
Definition at line 175 of file HGrid.cc.
References cellSizes_.
Referenced by MercuryBase::hGridNeedsRebuilding().
const BaseParticle * HGrid::getFirstBaseParticleInBucket | ( | unsigned int | i | ) | const |
Gets the first BaseParticle in the given bucket, const version.
[in] | i | The ordinal number of the bucket for which we want to get the first particle of. |
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().
BaseParticle * HGrid::getFirstBaseParticleInBucket | ( | unsigned int | i | ) |
Gets the first BaseParticle in the given bucket.
[in] | i | The ordinal number of the bucket for which we want to get the first particle of. |
Definition at line 218 of file HGrid.cc.
References firstBaseParticleInBucket_.
double HGrid::getInvCellSize | ( | unsigned int | i | ) | const |
Gets 1/cellSize for the cells on level i.
[in] | i | The level we want to know the inverse cell size of. |
Definition at line 261 of file HGrid.cc.
References invCellSizes_.
Referenced by Mercury2D::hGridFindOneSidedContacts(), Mercury3D::hGridFindOneSidedContacts(), Mercury2D::hGridHasParticleContacts(), Mercury2D::hGridUpdateParticle(), and Mercury3D::hGridUpdateParticle().
const std::vector< double > & HGrid::getInvCellSizes | ( | ) | const |
Gets all the inverse cell sizes (1/cellSize) for all levels as a vector.
Definition at line 183 of file HGrid.cc.
References invCellSizes_.
bool HGrid::getNeedsRebuilding | ( | ) | const |
Gets whether or not the grid needs to be rebuilt before something else is done with it.
Definition at line 269 of file HGrid.cc.
References needsRebuilding_.
Referenced by MercuryBase::hGridNeedsRebuilding().
unsigned int HGrid::getNumberOfBuckets | ( | ) | const |
Gets the number of buckets of this HGrid.
Definition at line 159 of file HGrid.cc.
References numberOfBuckets_.
Referenced by MercuryBase::hGridNeedsRebuilding(), and MercuryBase::write().
unsigned int HGrid::getNumberOfLevels | ( | ) | const |
Gets the number of levels of this HGrid.
Definition at line 234 of file HGrid.cc.
References cellSizes_.
Referenced by Mercury2D::hGridFindOneSidedContacts(), Mercury3D::hGridFindOneSidedContacts(), and Mercury2D::hGridHasParticleContacts().
int HGrid::getOccupiedLevelsMask | ( | ) | const |
Gets the integer that represents which levels are occupied.
Definition at line 285 of file HGrid.cc.
References occupiedLevelsMask_.
Referenced by Mercury2D::hGridFindOneSidedContacts(), Mercury3D::hGridFindOneSidedContacts(), and Mercury2D::hGridHasParticleContacts().
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().
void HGrid::Initialize_inv_size | ( | ) |
void HGrid::insertParticleToHgrid | ( | BaseParticle * | obj | ) |
Inserts the given BaseParticle in to the HGrid.
[in] | obj | A 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_.
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().
void HGrid::setBucketIsChecked | ( | unsigned int | i | ) |
Sets that the bucket with the given index is checked to true.
[in] | i | The 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().
void HGrid::setFirstBaseParticleInBucket | ( | unsigned int | i, |
BaseParticle * | p | ||
) |
Sets the first particle in bucket i to be the given BaseParticle.
[in] | i | The ordinal number of the bucket we want to set the first BaseParticle for. |
[in] | p | A 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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().
|
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().