HGrid.h
Go to the documentation of this file.
1 // This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2 // Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3 // License: BSD 3-Clause License; see the LICENSE file in the root directory.
4 
5 #ifndef HGRID_H
6 #define HGRID_H
7 
8 #include <vector>
9 #include "Math/ExtendedMath.h"
10 #include "Particles/HGridCell.h"
11 
12 class BaseParticle;
13 
21 class HGrid
22 {
23 public:
27  HGrid();
28 
32  HGrid(unsigned int num_buckets, double cellOverSizeRatio, std::vector<double>& cellSizes);
33 
37  ~HGrid();
38 
43 
55  inline unsigned int computeHashBucketIndex(int x, int y, int z, unsigned int l) const
56  {
57  static const unsigned int h1 = 0x8da6b343u; // Large multiplicative constants;
58  static const unsigned int h2 = 0xd8163841u; // here arbitrarily chosen primes
59  static const unsigned int h3 = 0xcb1ab31fu;
60  static const unsigned int h4 = 0x165667b1u;
61 
62  return (h1 * x + h2 * y + h3 * z + h4 * l) % numberOfBuckets_;
63  }
64 
68  inline unsigned int computeHashBucketIndex(HGridCell hGridCell) const
69  {
70  return computeHashBucketIndex(hGridCell.getHGridX(),
71  hGridCell.getHGridY(),
72  hGridCell.getHGridZ(),
73  hGridCell.getHGridLevel());
74  }
75 
79  unsigned int computeHashBucketIndex(int x, int y, unsigned int l) const;
80 
84  void clearBucketIsChecked();
85 
90 
98 
103  void setBucketIsChecked(unsigned int i)
104  { bucketIsChecked_[i] = true; }
105 
111  bool getBucketIsChecked(unsigned int i) const
112  { return bucketIsChecked_[i]; }
113 
119  { return cellOverSizeRatio_; }
120 
126  double getCellSize(unsigned int i) const
127  { return cellSizes_[i]; }
128 
133  const std::vector<double>& getCellSizes() const
134  { return cellSizes_; }
135 
141  const BaseParticle* getFirstBaseParticleInBucket(unsigned int i) const
142  { return firstBaseParticleInBucket_[i]; }
143 
150  { return firstBaseParticleInBucket_[i]; }
151 
157  double getInvCellSize(unsigned int i) const
158  {
159  logger.assert_debug(i<invCellSizes_.size(),"Error in getInvCellSize %<%", i, invCellSizes_.size());
160  return invCellSizes_[i];
161  }
162 
167  const std::vector<double>& getInvCellSizes() const
168  { return invCellSizes_; }
169 
174  bool getNeedsRebuilding() const
175  { return needsRebuilding_; }
176 
181  unsigned int getNumberOfBuckets() const
182  { return numberOfBuckets_; }
183 
188  unsigned long getNumberOfLevels() const
189  { return cellSizes_.size(); }
190 
196  { return occupiedLevelsMask_; }
197 
204  void info() const;
205 
206 private:
211 
217  unsigned int numberOfBuckets_;
218 
223 
230 
237  std::vector<double> cellSizes_;
238 
242  std::vector<double> invCellSizes_;
243 
250  std::vector<BaseParticle*> firstBaseParticleInBucket_;
251 
255  std::vector<bool> bucketIsChecked_;
256 };
257 
258 #endif
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
float * p
Definition: Tutorial_Map_using.cpp:9
Definition: BaseParticle.h:33
Definition: HGridCell.h:12
unsigned int getHGridLevel() const
Definition: HGridCell.h:65
int getHGridX() const
Definition: HGridCell.h:35
int getHGridZ() const
Definition: HGridCell.h:55
int getHGridY() const
Definition: HGridCell.h:45
In the HGrid class, here all information about the HGrid is stored.
Definition: HGrid.h:22
bool needsRebuilding_
Flag sets if the HGrid needs to be rebuilt.
Definition: HGrid.h:210
~HGrid()
Destructor.
Definition: HGrid.cc:49
std::vector< bool > bucketIsChecked_
BucketIsChecked stores if hash bucket b is checked already; initially all false.
Definition: HGrid.h:255
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:242
bool getBucketIsChecked(unsigned int i) const
Gets whether or not the bucket with index i is checked.
Definition: HGrid.h:111
Mdouble cellOverSizeRatio_
The maximum ratio between the size of the cell and the size of a particle it contains.
Definition: HGrid.h:222
void setFirstBaseParticleInBucket(unsigned int i, BaseParticle *p)
Sets the first particle in bucket i to be the given BaseParticle.
Definition: HGrid.h:96
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.
Definition: HGrid.h:55
unsigned int numberOfBuckets_
The number of buckets in the current HGrid.
Definition: HGrid.h:217
unsigned long getNumberOfLevels() const
Gets the number of levels of this HGrid.
Definition: HGrid.h:188
const std::vector< double > & getCellSizes() const
Gets the sizes of the cells at all levels as a vector.
Definition: HGrid.h:133
bool getNeedsRebuilding() const
Gets whether or not the grid needs to be rebuilt before something else is done with it.
Definition: HGrid.h:174
std::vector< double > cellSizes_
The sizes of the cells in the different grids.
Definition: HGrid.h:237
double getInvCellSize(unsigned int i) const
Gets 1/cellSize for the cells on level i.
Definition: HGrid.h:157
void info() const
Displays the member variables of the hGrid object. This function is intended for debugging the hGrid,...
Definition: HGrid.cc:130
void setBucketIsChecked(unsigned int i)
Sets that the bucket with the given index is checked to true.
Definition: HGrid.h:103
const BaseParticle * getFirstBaseParticleInBucket(unsigned int i) const
Gets the first BaseParticle in the given bucket, const version.
Definition: HGrid.h:141
unsigned int computeHashBucketIndex(HGridCell hGridCell) const
Computes hash bucket index in range [0, NUM_BUCKETS-1] for a 3D domain.
Definition: HGrid.h:68
std::vector< BaseParticle * > firstBaseParticleInBucket_
Stores a pointer to first element in hash bucket b.
Definition: HGrid.h:250
const std::vector< double > & getInvCellSizes() const
Gets all the inverse cell sizes (1/cellSize) for all levels as a vector.
Definition: HGrid.h:167
HGrid()
Default constructor, it sets the parameters to some sensible defaults.
Definition: HGrid.cc:9
BaseParticle * getFirstBaseParticleInBucket(unsigned int i)
Gets the first BaseParticle in the given bucket.
Definition: HGrid.h:149
void insertParticleToHgrid(BaseParticle *obj)
Inserts the given BaseParticle in to the HGrid.
Definition: HGrid.cc:67
void clearFirstBaseParticleInBucket()
For all buckets, it removes the pointer to the first BaseParticle in it, practically emptying the buc...
Definition: HGrid.cc:124
void clearBucketIsChecked()
Sets all buckets to not-checked.
Definition: HGrid.cc:119
int occupiedLevelsMask_
Marks if there are particles at certain levels.
Definition: HGrid.h:229
int getOccupiedLevelsMask() const
Gets the integer that represents which levels are occupied.
Definition: HGrid.h:195
unsigned int getNumberOfBuckets() const
Gets the number of buckets of this HGrid.
Definition: HGrid.h:181
double getCellSize(unsigned int i) const
Gets the size of the cells at the given level.
Definition: HGrid.h:126
Mdouble getCellOverSizeRatio() const
Gets the maximum ratio of the cell to a particle it contains.
Definition: HGrid.h:118
Scalar * y
Definition: level1_cplx_impl.h:128
list x
Definition: plotDoE.py:28