|
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 | 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 (HGridCell hGridCell) 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 long | 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.
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.
References bucketIsChecked_, cellOverSizeRatio_, cellSizes_, DEBUG, firstBaseParticleInBucket_, invCellSizes_, logger, needsRebuilding_, numberOfBuckets_, and occupiedLevelsMask_.
HGrid::~HGrid | ( | ) |
void HGrid::clearBucketIsChecked | ( | ) |
Sets all buckets to not-checked.
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.
References firstBaseParticleInBucket_.
Referenced by MercuryBase::hGridActionsBeforeTimeStep().
|
inline |
Computes hash bucket index in range [0, NUM_BUCKETS-1] for a 3D domain.
References computeHashBucketIndex(), HGridCell::getHGridLevel(), HGridCell::getHGridX(), HGridCell::getHGridY(), and HGridCell::getHGridZ().
|
inline |
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]. Inline for performance reasons: this method is called VERY often.
[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. |
References numberOfBuckets_.
Referenced by computeHashBucketIndex(), DPM::computeLocalCGHGrid(), DPM::computeLocalVolumeFractionHGrid(), Mercury3D::computeWallForces(), Mercury3D::hGridFindContactsWithinTargetCell(), Mercury2D::hGridFindContactsWithinTargetCell(), Mercury3D::hGridFindContactsWithTargetCell(), Mercury2D::hGridFindContactsWithTargetCell(), Mercury2D::hGridFindParticleContacts(), Mercury3D::hGridFindParticleContacts(), Mercury3D::hGridFindParticlesWithTargetCell(), Mercury2D::hGridFindParticlesWithTargetCell(), Mercury3D::hGridHasContactsInTargetCell(), Mercury2D::hGridHasContactsInTargetCell(), Mercury2D::hGridRemoveParticle(), Mercury3D::hGridRemoveParticle(), Mercury2D::hGridUpdateParticle(), and Mercury3D::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. |
References n, and numberOfBuckets_.
|
inline |
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. |
References bucketIsChecked_, and constants::i.
Referenced by Mercury3D::hGridFindContactsWithinTargetCell(), and Mercury2D::hGridFindContactsWithinTargetCell().
|
inline |
Gets the maximum ratio of the cell to a particle it contains.
References cellOverSizeRatio_.
Referenced by MercuryBase::hGridNeedsRebuilding().
|
inline |
Gets the size of the cells at the given level.
[in] | i | The level we want to know the cell size of. |
References cellSizes_, and constants::i.
|
inline |
Gets the sizes of the cells at all levels as a vector.
References cellSizes_.
Referenced by MercuryBase::hGridInfo(), and MercuryBase::hGridNeedsRebuilding().
|
inline |
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. |
References firstBaseParticleInBucket_, and constants::i.
|
inline |
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. |
References firstBaseParticleInBucket_, and constants::i.
Referenced by DPM::computeLocalCGHGrid(), DPM::computeLocalVolumeFractionHGrid(), Mercury3D::computeWallForces(), Mercury3D::hGridFindContactsWithinTargetCell(), Mercury2D::hGridFindContactsWithinTargetCell(), Mercury3D::hGridFindContactsWithTargetCell(), Mercury2D::hGridFindContactsWithTargetCell(), Mercury2D::hGridFindParticleContacts(), Mercury3D::hGridFindParticleContacts(), Mercury3D::hGridFindParticlesWithTargetCell(), Mercury2D::hGridFindParticlesWithTargetCell(), Mercury3D::hGridHasContactsInTargetCell(), Mercury2D::hGridHasContactsInTargetCell(), Mercury3D::hGridRemoveParticle(), Mercury2D::hGridUpdateParticle(), and Mercury3D::hGridUpdateParticle().
|
inline |
Gets 1/cellSize for the cells on level i.
[in] | i | The level we want to know the inverse cell size of. |
References constants::i, and invCellSizes_.
Referenced by Mercury2D::computeInternalForces(), Mercury3D::computeInternalForces(), DPM::computeLocalCGHGrid(), DPM::computeLocalVolumeFractionHGrid(), Mercury3D::computeWallForces(), Mercury2D::hGridFindParticleContacts(), Mercury3D::hGridFindParticleContacts(), Mercury2D::hGridGetInteractingParticleList(), Mercury3D::hGridGetInteractingParticleList(), Mercury2D::hGridHasParticleContacts(), Mercury3D::hGridHasParticleContacts(), Mercury2D::hGridUpdateParticle(), and Mercury3D::hGridUpdateParticle().
|
inline |
Gets all the inverse cell sizes (1/cellSize) for all levels as a vector.
References invCellSizes_.
|
inline |
Gets whether or not the grid needs to be rebuilt before something else is done with it.
References needsRebuilding_.
Referenced by MercuryBase::hGridNeedsRebuilding().
|
inline |
Gets the number of buckets of this HGrid.
References numberOfBuckets_.
Referenced by MercuryBase::hGridInfo(), and MercuryBase::hGridNeedsRebuilding().
|
inline |
Gets the number of levels of this HGrid.
References cellSizes_.
Referenced by Mercury2D::computeInternalForces(), Mercury3D::computeInternalForces(), Mercury3D::computeWallForces(), Mercury2D::hGridFindParticleContacts(), Mercury3D::hGridFindParticleContacts(), Mercury2D::hGridGetInteractingParticleList(), Mercury3D::hGridGetInteractingParticleList(), Mercury2D::hGridHasParticleContacts(), and Mercury3D::hGridHasParticleContacts().
|
inline |
Gets the integer that represents which levels are occupied.
References occupiedLevelsMask_.
Referenced by Mercury2D::computeInternalForces(), Mercury3D::computeInternalForces(), DPM::computeLocalCGHGrid(), DPM::computeLocalVolumeFractionHGrid(), Mercury3D::computeWallForces(), Mercury2D::hGridFindParticleContacts(), Mercury3D::hGridFindParticleContacts(), Mercury2D::hGridGetInteractingParticleList(), Mercury3D::hGridGetInteractingParticleList(), Mercury2D::hGridHasParticleContacts(), and Mercury3D::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.
References cellOverSizeRatio_, cellSizes_, INFO, logger, NO_FLUSH, and numberOfBuckets_.
Referenced by EllipsoidsBouncingOnWallDemo::actionsAfterSolve(), EllipticalSuperQuadricCollision::actionsAfterSolve(), SphericalSuperQuadricCollision::actionsAfterSolve(), and VisualisationTest::actionsAfterSolve().
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_.
References cellOverSizeRatio_, cellSizes_, BaseObject::getId(), BaseObject::getIndex(), BaseParticle::getMaxInteractionRadius(), logger, needsRebuilding_, occupiedLevelsMask_, BaseParticle::setHGridLevel(), and WARN.
Referenced by MercuryBase::hGridInsertParticle().
|
inline |
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. |
References bucketIsChecked_, and constants::i.
Referenced by Mercury3D::hGridFindContactsWithinTargetCell(), and Mercury2D::hGridFindContactsWithinTargetCell().
|
inline |
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. |
References firstBaseParticleInBucket_, and constants::i.
Referenced by Mercury2D::hGridRemoveParticle(), Mercury3D::hGridRemoveParticle(), Mercury2D::hGridUpdateParticle(), and Mercury3D::hGridUpdateParticle().
|
private |
BucketIsChecked stores if hash bucket b is checked already; initially all false.
Referenced by clearBucketIsChecked(), getBucketIsChecked(), HGrid(), and setBucketIsChecked().
|
private |
The maximum ratio between the size of the cell and the size of a particle it contains.
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.
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.
Referenced by clearFirstBaseParticleInBucket(), getFirstBaseParticleInBucket(), HGrid(), and setFirstBaseParticleInBucket().
|
private |
The inverse sizes of the cells in the different grids, where the inverse is defined as 1/cellSizes_.
Referenced by getInvCellSize(), getInvCellSizes(), and HGrid().
|
private |
Flag sets if the HGrid needs to be rebuilt.
Referenced by getNeedsRebuilding(), HGrid(), 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.
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.
Referenced by getOccupiedLevelsMask(), HGrid(), and insertParticleToHgrid().