MercuryDPM  0.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HGrid Class Reference

This is the HGRID class - This is the actually HGRID code. More...

#include <HGRID.h>

Public Member Functions

 HGrid ()
 
 HGrid (int num_buckets, double cellOverSizeRatio, std::vector< double > &cellSizes)
 constructor: initializes parameters and allocates space for internal variables More...
 
 ~HGrid ()
 constructor: initializes parameters and allocates space for internal variables More...
 
void Initialize_inv_size ()
 
void InsertParticleToHgrid (BaseParticle *obj)
 This insert a particle given by CParticle in to the HGrid (i.e. it sets up the particle grid properts updates the level information on the grid) More...
 
int ComputeHashBucketIndex (int x, int y, int z, int l)
 Computes hash bucket index in range [0, NUM_BUCKETS-1]. More...
 
int ComputeHashBucketIndex (int x, int y, int l)
 Computes hash bucket index in range [0, NUM_BUCKETS-1]. More...
 
void reset_num_buckets (int new_num_buckets)
 

Public Attributes

int NUM_BUCKETS
 Number of buckets used for hashing. More...
 
std::vector< double > cellSizes_
 
std::vector< double > invCellSizes_
 
int occupiedLevelsMask
 l-th bit of occupiedLevelsMask is 1 if level l is contains particles; initially zero (Implies max 32 hgrid levels) More...
 
BaseParticle ** objectBucket
 objectBucket[b] stores pointer to first element in hash bucket b; initially all NULL More...
 
bool * bucketIsChecked
 bucketIsChecked[b] stores if hash bucket b is checked already; initially all zero More...
 
Mdouble cellOverSizeRatio_
 

Detailed Description

This is the HGRID class - This is the actually HGRID code.

Definition at line 39 of file HGRID.h.

Constructor & Destructor Documentation

HGrid::HGrid ( )

Definition at line 29 of file HGRID.cc.

References bucketIsChecked, and objectBucket.

30 {
31  objectBucket = 0;
32  bucketIsChecked = 0;
33 }
bool * bucketIsChecked
bucketIsChecked[b] stores if hash bucket b is checked already; initially all zero ...
Definition: HGRID.h:61
BaseParticle ** objectBucket
objectBucket[b] stores pointer to first element in hash bucket b; initially all NULL ...
Definition: HGRID.h:58
HGrid::HGrid ( int  num_buckets,
double  cellOverSizeRatio,
std::vector< double > &  cellSizes 
)

constructor: initializes parameters and allocates space for internal variables

Definition at line 36 of file HGRID.cc.

References bucketIsChecked, cellOverSizeRatio_, cellSizes_, NUM_BUCKETS, and objectBucket.

37 {
38  NUM_BUCKETS = num_buckets;
39  cellOverSizeRatio_=cellOverSizeRatio;
40 
42  bucketIsChecked = new bool[NUM_BUCKETS];
43 
44  for(int i=0;i<cellSizes.size();i++)
45  {
46  cellSizes_.push_back(cellSizes[i]);
47  std::cout<<"Level="<<i<<" Grid size="<<cellSizes_.back()<<std::endl;
48  }
49 }
Mdouble cellOverSizeRatio_
Definition: HGRID.h:84
int NUM_BUCKETS
Number of buckets used for hashing.
Definition: HGRID.h:47
std::vector< double > cellSizes_
Definition: HGRID.h:50
bool * bucketIsChecked
bucketIsChecked[b] stores if hash bucket b is checked already; initially all zero ...
Definition: HGRID.h:61
BaseParticle ** objectBucket
objectBucket[b] stores pointer to first element in hash bucket b; initially all NULL ...
Definition: HGRID.h:58
HGrid::~HGrid ( )

constructor: initializes parameters and allocates space for internal variables

Definition at line 52 of file HGRID.cc.

References bucketIsChecked, and objectBucket.

52  {
53  if (objectBucket) { delete [] objectBucket; objectBucket=0; }
54  if (bucketIsChecked) { delete [] bucketIsChecked; bucketIsChecked=0; }
55 }
bool * bucketIsChecked
bucketIsChecked[b] stores if hash bucket b is checked already; initially all zero ...
Definition: HGRID.h:61
BaseParticle ** objectBucket
objectBucket[b] stores pointer to first element in hash bucket b; initially all NULL ...
Definition: HGRID.h:58

Member Function Documentation

int HGrid::ComputeHashBucketIndex ( int  x,
int  y,
int  z,
int  l 
)

Computes hash bucket index in range [0, NUM_BUCKETS-1].

Definition at line 93 of file HGRID.cc.

References NUM_BUCKETS.

Referenced by HGRID_2D::CheckCell(), HGRID_3D::CheckCell(), HGRID_2D::CheckCell_current(), HGRID_3D::CheckCell_current(), HGRID_2D::HGRID_RemoveParticleFromHgrid(), HGRID_3D::HGRID_RemoveParticleFromHgrid(), HGRID_2D::HGRID_UpdateParticleInHgrid(), HGRID_3D::HGRID_UpdateParticleInHgrid(), Chute::IsInsertable(), HGRID_2D::TestCell(), and HGRID_3D::TestCell().

94 {
95  const int h1 = 0x8da6b343; // Large multiplicative constants;
96  const int h2 = 0xd8163841; // here arbitrarily chosen primes
97  const int h3 = 0xcb1ab31f;
98  const int h4 = 0x165667b1;
99 
100  int n = h1 * x + h2 * y + h3 * z + h4 * l;
101  n = n % NUM_BUCKETS;
102 
103  if (n < 0) n += NUM_BUCKETS;
104 
105  return n;
106 }
int NUM_BUCKETS
Number of buckets used for hashing.
Definition: HGRID.h:47
int HGrid::ComputeHashBucketIndex ( int  x,
int  y,
int  l 
)

Computes hash bucket index in range [0, NUM_BUCKETS-1].

Definition at line 108 of file HGRID.cc.

References NUM_BUCKETS.

109 {
110  const int h1 = 0x8da6b343; // Large multiplicative constants;
111  const int h2 = 0xd8163841; // here arbitrarily chosen primes
112  const int h4 = 0x165667b1;
113 
114  int n = h1 * x + h2 * y + h4 * l;
115  n = n % NUM_BUCKETS;
116 
117  if (n < 0) n += NUM_BUCKETS;
118 
119  return n;
120 }
int NUM_BUCKETS
Number of buckets used for hashing.
Definition: HGRID.h:47
void HGrid::Initialize_inv_size ( )

Definition at line 57 of file HGRID.cc.

References cellSizes_, and invCellSizes_.

Referenced by HGRID_base::InitBroadPhase().

58 {
59  invCellSizes_.clear();
60  for (unsigned int level = 0; level<cellSizes_.size(); level++)
61  {
62  invCellSizes_.push_back(1.0/cellSizes_[level]);
63  }
64 }
std::vector< double > invCellSizes_
Definition: HGRID.h:51
std::vector< double > cellSizes_
Definition: HGRID.h:50
void HGrid::InsertParticleToHgrid ( BaseParticle obj)

This insert a particle given by CParticle in to the HGrid (i.e. it sets up the particle grid properts updates the level information on the grid)

Definition at line 69 of file HGRID.cc.

References cellOverSizeRatio_, cellSizes_, BaseParticle::get_InteractionRadius(), occupiedLevelsMask, and BaseParticle::set_HGRID_Level().

Referenced by Chute::add_particle(), HGRID_base::HGRID_InsertParticleToHgrid(), and HGRID_base::InitBroadPhase().

70 {
71  // Find lowest level where object fully fits inside cell, taking RATIO into account
72  Mdouble diameter = obj->get_InteractionRadius() * 2.0 ;
73  unsigned int level=0;
74  while(level<cellSizes_.size()&&cellSizes_[level]<=diameter * cellOverSizeRatio_)
75  {
76  level++;
77  }
78 
79  if (level >= cellSizes_.size())
80  {
81  std::cerr << "ATTENTION !!! Object is larger (d=" << diameter << ", cellOverSizeRatio=" << cellOverSizeRatio_ << ") than largest grid cell allows (" << cellSizes_.back() << ")!" << std::endl;
82  exit(-1);
83  }
84 
85  obj->set_HGRID_Level(level);
86  // indicate level is in use - not levels with no particles no collision detection is performed
87  this->occupiedLevelsMask |= (1 << level);
88 }
Mdouble get_InteractionRadius() const
Mdouble cellOverSizeRatio_
Definition: HGRID.h:84
std::vector< double > cellSizes_
Definition: HGRID.h:50
double Mdouble
Definition: ExtendedMath.h:33
void set_HGRID_Level(const int _new)
int occupiedLevelsMask
l-th bit of occupiedLevelsMask is 1 if level l is contains particles; initially zero (Implies max 32 ...
Definition: HGRID.h:55
void HGrid::reset_num_buckets ( int  new_num_buckets)
Bug:
{I don't know if this function still works since we do not use (m/c)alloc anymore}
Bug:
{I don't know if this function still works since we do not use (m/c)alloc anymore}

Definition at line 124 of file HGRID.cc.

References bucketIsChecked, NUM_BUCKETS, and objectBucket.

124  {
125  NUM_BUCKETS=new_num_buckets;
127  bucketIsChecked = (bool*)realloc(bucketIsChecked, NUM_BUCKETS*sizeof(bool));
128 }
int NUM_BUCKETS
Number of buckets used for hashing.
Definition: HGRID.h:47
bool * bucketIsChecked
bucketIsChecked[b] stores if hash bucket b is checked already; initially all zero ...
Definition: HGRID.h:61
BaseParticle ** objectBucket
objectBucket[b] stores pointer to first element in hash bucket b; initially all NULL ...
Definition: HGRID.h:58

Member Data Documentation

bool* HGrid::bucketIsChecked

bucketIsChecked[b] stores if hash bucket b is checked already; initially all zero

Definition at line 61 of file HGRID.h.

Referenced by HGRID_2D::CheckCell_current(), HGRID_3D::CheckCell_current(), HGrid(), HGRID_base::HGRID_actions_before_time_step(), HGRID_base::InitBroadPhase(), reset_num_buckets(), and ~HGrid().

Mdouble HGrid::cellOverSizeRatio_

Definition at line 84 of file HGRID.h.

Referenced by HGrid(), and InsertParticleToHgrid().

int HGrid::NUM_BUCKETS

Number of buckets used for hashing.

Definition at line 47 of file HGRID.h.

Referenced by ComputeHashBucketIndex(), HGrid(), HGRID_base::HGRID_actions_before_time_step(), HGRID_base::InitBroadPhase(), and reset_num_buckets().

int HGrid::occupiedLevelsMask

l-th bit of occupiedLevelsMask is 1 if level l is contains particles; initially zero (Implies max 32 hgrid levels)

Definition at line 55 of file HGRID.h.

Referenced by HGRID_2D::CheckObjAgainstGrid(), HGRID_3D::CheckObjAgainstGrid(), HGRID_base::InitBroadPhase(), InsertParticleToHgrid(), HGRID_2D::TestObjAgainstGrid(), and HGRID_3D::TestObjAgainstGrid().


The documentation for this class was generated from the following files: