47 HGrid::HGrid(
unsigned int num_buckets,
double cellOverSizeRatio, std::vector<double>& cellSizes)
58 for (
unsigned int i = 0; i < cellSizes.size(); i++)
64 logger(
DEBUG,
"HGrid::HGrid(unsigned int, double, vector<double>&) constructor finished.");
72 logger(
DEBUG,
"HGrid::~HGrid() destructor finished");
94 unsigned int level = 0;
112 logger(
WARN,
"WARNING: the HGrid needs to be rebuild before insertParticleToHgrid may be called!");
126 const unsigned int h1 = 0x8da6b343u;
127 const unsigned int h2 = 0xd8163841u;
128 const unsigned int h3 = 0xcb1ab31fu;
129 const unsigned int h4 = 0x165667b1u;
131 unsigned long int n = h1 * x + h2 * y + h3 * z + h4 * l;
134 return static_cast<unsigned int>(n);
146 const unsigned int h1 = 0x8da6b343u;
147 const unsigned int h2 = 0xd8163841u;
148 const unsigned int h4 = 0x165667b1u;
150 unsigned long int n = h1 * x + h2 * y + h4 * l;
153 return static_cast<unsigned int>(n);
292 std::cout <<
"Current status of hGrid parameters:" << std::endl;
294 std::cout <<
"unsigned int numberOfBuckets_=" <<
numberOfBuckets_ << 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() <<
"]=";
302 std::cout << std::endl;
303 std::cout <<
"std::vector<BaseParticle> firstBaseParticleInBucket_[" <<
firstBaseParticleInBucket_.size() <<
"]=... (not shown)";
305 std::cout << std::endl;
306 std::cout <<
"std::vector<bool> bucketIsChecked_[" <<
bucketIsChecked_.size() <<
"]=... (not shown)";
308 std::cout << std::endl;
const std::vector< double > & getCellSizes() const
Gets the sizes of the cells at all levels as a vector.
unsigned int getId() const
Returns the unique identifier of any particular object.
unsigned int getIndex() const
Returns the index of the object in the handler.
std::vector< bool > bucketIsChecked_
BucketIsChecked stores if hash bucket b is checked already; initially all false.
void setHGridLevel(const unsigned int level)
Sets the particle's HGrid level.
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
void insertParticleToHgrid(BaseParticle *obj)
Inserts the given BaseParticle in to the HGrid.
void info() const
Displays the member variables of the hGrid object. This function is intended for debugging the hGrid...
void clearFirstBaseParticleInBucket()
For all buckets, it removes the pointer to the first BaseParticle in it, practically emptying the buc...
Mdouble cellOverSizeRatio_
The maximum ratio between the size of the cell and the size of a particle it contains.
Mdouble getCellOverSizeRatio() const
Gets the maximum ratio of the cell to a particle it contains.
std::vector< BaseParticle * > firstBaseParticleInBucket_
Stores a pointer to first element in hash bucket b.
int getOccupiedLevelsMask() const
Gets the integer that represents which levels are occupied.
unsigned int getNumberOfLevels() const
Gets the number of levels of this HGrid.
std::vector< double > invCellSizes_
The inverse sizes of the cells in the different grids, where the inverse is defined as 1/cellSizes_...
std::vector< double > cellSizes_
The sizes of the cells in the different grids.
HGrid()
Default constructor, it sets the parameters to some sensible defaults.
unsigned int numberOfBuckets_
The number of buckets in the current HGrid.
void setFirstBaseParticleInBucket(unsigned int i, BaseParticle *p)
Sets the first particle in bucket i to be the given BaseParticle.
void clearBucketIsChecked()
Sets all buckets to not-checked.
const std::vector< double > & getInvCellSizes() const
Gets all the inverse cell sizes (1/cellSize) for all levels as a vector.
void setBucketIsChecked(unsigned int i)
Sets that the bucket with the given index is checked to true.
const BaseParticle * getFirstBaseParticleInBucket(unsigned int i) const
Gets the first BaseParticle in the given bucket, const version.
double getCellSize(unsigned int i) const
Gets the size of the cells at the given level.
bool getNeedsRebuilding() const
Gets whether or not the grid needs to be rebuilt before something else is done with it...
int occupiedLevelsMask_
Marks if there are particles at certain levels.
bool needsRebuilding_
Flag sets if the HGrid needs to be rebuilt.
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.
Mdouble getInteractionRadius() const
Returns the particle's interaction radius, which might be different from radius_ (e.g., when dealing with wet particles)
bool getBucketIsChecked(unsigned int i) const
Gets whether or not the bucket with index i is checked.
double getInvCellSize(unsigned int i) const
Gets 1/cellSize for the cells on level i.
unsigned int getNumberOfBuckets() const
Gets the number of buckets of this HGrid.