MercuryDPM  Alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HGrid.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2014, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 #ifndef HGRID_H
27 #define HGRID_H
28 
29 #include <vector>
30 #include "Math/ExtendedMath.h"
31 
32 class BaseParticle;
33 
41 class HGrid
42 {
43 public:
47  HGrid();
48 
52  HGrid(unsigned int num_buckets, double cellOverSizeRatio, std::vector<double>& cellSizes);
53 
57  ~HGrid();
58 
62  void Initialize_inv_size();
63 
68 
72  unsigned int computeHashBucketIndex(int x, int y, int z, unsigned int l) const;
73 
77  unsigned int computeHashBucketIndex(int x, int y, unsigned int l) const;
78 
82  void clearBucketIsChecked();
83 
88 
92  void setFirstBaseParticleInBucket(unsigned int i, BaseParticle* p);
93 
97  void setBucketIsChecked(unsigned int i);
98 
102  bool getBucketIsChecked(unsigned int i) const;
103 
108 
112  double getCellSize(unsigned int i) const;
113 
117  const std::vector<double>& getCellSizes() const;
118 
122  const BaseParticle* getFirstBaseParticleInBucket(unsigned int i) const;
123 
128 
132  double getInvCellSize(unsigned int i) const;
133 
137  const std::vector<double>& getInvCellSizes() const;
138 
142  bool getNeedsRebuilding() const;
143 
147  unsigned int getNumberOfBuckets() const;
148 
152  unsigned int getNumberOfLevels() const;
153 
157  int getOccupiedLevelsMask() const;
158 
165  void info() const;
166 
167 private:
172 
178  unsigned int numberOfBuckets_;
179 
184 
191 
198  std::vector<double> cellSizes_;
199 
203  std::vector<double> invCellSizes_;
204 
211  std::vector<BaseParticle*> firstBaseParticleInBucket_;
212 
216  std::vector<bool> bucketIsChecked_;
217 };
218 #endif
const std::vector< double > & getCellSizes() const
Gets the sizes of the cells at all levels as a vector.
Definition: HGrid.cc:176
std::vector< bool > bucketIsChecked_
BucketIsChecked stores if hash bucket b is checked already; initially all false.
Definition: HGrid.h:216
void insertParticleToHgrid(BaseParticle *obj)
Inserts the given BaseParticle in to the HGrid.
Definition: HGrid.cc:89
void info() const
Displays the member variables of the hGrid object. This function is intended for debugging the hGrid...
Definition: HGrid.cc:292
void clearFirstBaseParticleInBucket()
For all buckets, it removes the pointer to the first BaseParticle in it, practically emptying the buc...
Definition: HGrid.cc:189
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
Mdouble getCellOverSizeRatio() const
Gets the maximum ratio of the cell to a particle it contains.
Definition: HGrid.cc:278
~HGrid()
Destructor.
Definition: HGrid.cc:71
std::vector< BaseParticle * > firstBaseParticleInBucket_
Stores a pointer to first element in hash bucket b.
Definition: HGrid.h:211
int getOccupiedLevelsMask() const
Gets the integer that represents which levels are occupied.
Definition: HGrid.cc:286
unsigned int getNumberOfLevels() const
Gets the number of levels of this HGrid.
Definition: HGrid.cc:235
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
HGrid()
Default constructor, it sets the parameters to some sensible defaults.
Definition: HGrid.cc:31
In the HGrid class, here all information about the HGrid is stored.
Definition: HGrid.h:41
unsigned int numberOfBuckets_
The number of buckets in the current HGrid.
Definition: HGrid.h:178
void setFirstBaseParticleInBucket(unsigned int i, BaseParticle *p)
Sets the first particle in bucket i to be the given BaseParticle.
Definition: HGrid.cc:244
void clearBucketIsChecked()
Sets all buckets to not-checked.
Definition: HGrid.cc:165
const std::vector< double > & getInvCellSizes() const
Gets all the inverse cell sizes (1/cellSize) for all levels as a vector.
Definition: HGrid.cc:184
void setBucketIsChecked(unsigned int i)
Sets that the bucket with the given index is checked to true.
Definition: HGrid.cc:227
void Initialize_inv_size()
const BaseParticle * getFirstBaseParticleInBucket(unsigned int i) const
Gets the first BaseParticle in the given bucket, const version.
Definition: HGrid.cc:210
double getCellSize(unsigned int i) const
Gets the size of the cells at the given level.
Definition: HGrid.cc:253
bool getNeedsRebuilding() const
Gets whether or not the grid needs to be rebuilt before something else is done with it...
Definition: HGrid.cc:270
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
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.cc:125
bool getBucketIsChecked(unsigned int i) const
Gets whether or not the bucket with index i is checked.
Definition: HGrid.cc:201
double getInvCellSize(unsigned int i) const
Gets 1/cellSize for the cells on level i.
Definition: HGrid.cc:262
unsigned int getNumberOfBuckets() const
Gets the number of buckets of this HGrid.
Definition: HGrid.cc:160