HG-MD
1
|
This is the base class for both HGRID_2D and HGRID_3D. More...
#include <HGRID_base.h>
Public Member Functions | |
HGRID_base () | |
This is the default constructor. All it does is set senible defaults. | |
~HGRID_base () | |
HGRID_base (MD &other) | |
Copy-constructor for creates an HGRID problem from an existing MD problem. | |
void | constructor () |
This is the actually constructor it is called do both constructors above. | |
void | HGRID_actions_before_time_loop () |
This sets up the broad phase information, has to be done at this stage becuase it requires the partcle size. | |
void | HGRID_actions_before_time_step () |
This resets all the bucket information. | |
void | set_HGRID_num_buckets (unsigned int new_num_buckets) |
This sets the number of buckets for the HGRID. | |
void | set_HGRID_num_buckets_to_power () |
set number of buckets to the smallest power of two bigger than the number of particles | |
void | set_HGRID_num_buckets_to_power (unsigned int N) |
set number of buckets to the smallest power of two bigger than N | |
void | set_HGRID_max_levels (int new_max_levels) |
This sets the maximum number of levels for the HGRID. | |
void | set_HGRID_sphere_to_cell_ratio (Mdouble new_ratio) |
This sets the sphere to cell ratio for the HGRID. This raised to the power of dimension is the number of particles of cell size which could be in this cell. | |
void | set_HGRID_cell_to_cell_ratio (Mdouble new_ratio) |
This sets the ratio of the size of cells for the HGRID, note this is real NOT an integer. | |
void | read (std::istream &is) |
This function reads all HGRID data. | |
void | write (std::ostream &os) |
This function writes all HGRID data. | |
void | print (std::ostream &os, bool print_all=false) |
This function outputs all HGRID data. | |
Mdouble | get_CurrentMaxRelativeDisplacement () |
Mdouble | get_TotalCurrentMaxRelativeDisplacement () |
void | set_UpdateEachTimeStep (bool _new) |
bool | get_HGRID_UpdateEachTimeStep () |
Protected Member Functions | |
void | InitBroadPhase () |
This sets up the parameters required for the contact model. | |
void | HGRID_InsertParticleToHgrid (Particle *obj) |
Inserts a single Particle to current grid. | |
void | broad_phase (Particle *i) |
This makes the board_phase of contact point at the HGRID code. | |
virtual void | CheckObjAgainstGrid (HGrid *grid, Particle *obj)=0 |
This is a purly virtual function that checks if an object is in the grid, this code is again dim dependent so purly virtual at this stage. | |
virtual bool | TestObject (Particle *pI, Particle *pJ) |
criterium for inserting a particle (returns false, if particles overlap;) | |
void | HGRID_update_move (Particle *iP, Mdouble move) |
void | HGRID_actions_before_integration () |
void | HGRID_actions_after_integration () |
void | fix_hgrid () |
Protected Attributes | |
HGrid * | grid |
Private Member Functions | |
void | set_HGRID_min_cell_size (Mdouble new_min_cell_size) |
This sets the minimum cell size for the HGRID. No point having this smaller than the smallest particle. | |
void | set_CELL_TO_CELL_RATIO (Mdouble new_CELL_TO_CELL_RATIO) |
Private Attributes | |
Mdouble | currentMaxRelativeDisplacement |
Mdouble | totalCurrentMaxRelativeDisplacement |
bool | updateEachTimeStep |
int | NUM_BUCKETS |
int | HGRID_MAX_LEVELS |
Mdouble | MIN_CELL_SIZE |
Mdouble | SPHERE_TO_CELL_RATIO |
Mdouble | CELL_TO_CELL_RATIO |
This is the base class for both HGRID_2D and HGRID_3D.
Note the actually abstrate grid is defined in the case Grid defined below
HGRID_base::HGRID_base | ( | ) | [inline] |
This is the default constructor. All it does is set senible defaults.
References constructor().
{ constructor(); #ifdef CONSTUCTOR_OUTPUT cerr << "HGRID_base() finished"<<endl; #endif }
HGRID_base::~HGRID_base | ( | ) | [inline] |
HGRID_base::HGRID_base | ( | MD & | other | ) | [inline] |
Copy-constructor for creates an HGRID problem from an existing MD problem.
References constructor().
: MD(other) { constructor(); #ifdef CONSTUCTOR_OUTPUT cerr << "HGRID_base(MD& other) finished " << endl; #endif }
void HGRID_base::broad_phase | ( | Particle * | i | ) | [inline, protected, virtual] |
This makes the board_phase of contact point at the HGRID code.
Reimplemented from MD.
References CheckObjAgainstGrid(), and grid.
{CheckObjAgainstGrid(grid, i);}
virtual void HGRID_base::CheckObjAgainstGrid | ( | HGrid * | grid, |
Particle * | obj | ||
) | [protected, pure virtual] |
This is a purly virtual function that checks if an object is in the grid, this code is again dim dependent so purly virtual at this stage.
Implemented in HGRID_3D, and HGRID_2D.
Referenced by broad_phase().
void HGRID_base::constructor | ( | ) |
This is the actually constructor it is called do both constructors above.
This is the actually constructor for this problem.
It is defined here because it is called by both the copy constructor and normal constructor
Set senible default values for all the required parameters
Reimplemented from MD.
Reimplemented in ChuteWithHopper, Chute, HGRID_3D, HGRID_2D, and ChuteBottom.
References CELL_TO_CELL_RATIO, grid, HGRID_MAX_LEVELS, MIN_CELL_SIZE, NUM_BUCKETS, SPHERE_TO_CELL_RATIO, and updateEachTimeStep.
Referenced by HGRID_base().
{ NUM_BUCKETS=250000; HGRID_MAX_LEVELS=3; MIN_CELL_SIZE=0.1e-3; SPHERE_TO_CELL_RATIO=1.0; CELL_TO_CELL_RATIO=2.0; grid = NULL; updateEachTimeStep=true; }
void HGRID_base::fix_hgrid | ( | ) | [inline, protected] |
References MD::get_LargestParticle(), MD::get_ParticleHandler(), MD::get_SmallestParticle(), set_CELL_TO_CELL_RATIO(), set_HGRID_max_levels(), set_HGRID_min_cell_size(), and set_HGRID_num_buckets_to_power().
{ set_HGRID_min_cell_size(2.00001*get_SmallestParticle()->get_Radius()); set_HGRID_max_levels(2); set_CELL_TO_CELL_RATIO(get_LargestParticle()->get_Radius()/get_SmallestParticle()->get_Radius()); set_HGRID_num_buckets_to_power(get_ParticleHandler().get_NumberOfParticles()); }
Mdouble HGRID_base::get_CurrentMaxRelativeDisplacement | ( | ) | [inline] |
References currentMaxRelativeDisplacement.
{return currentMaxRelativeDisplacement;}
bool HGRID_base::get_HGRID_UpdateEachTimeStep | ( | ) | [inline, virtual] |
References totalCurrentMaxRelativeDisplacement.
{return totalCurrentMaxRelativeDisplacement;}
void HGRID_base::HGRID_actions_after_integration | ( | ) | [inline, protected, virtual] |
Reimplemented from MD.
References currentMaxRelativeDisplacement, and totalCurrentMaxRelativeDisplacement.
void HGRID_base::HGRID_actions_before_integration | ( | ) | [inline, protected, virtual] |
Reimplemented from MD.
References currentMaxRelativeDisplacement.
void HGRID_base::HGRID_actions_before_time_loop | ( | ) | [inline, virtual] |
This sets up the broad phase information, has to be done at this stage becuase it requires the partcle size.
Reimplemented from MD.
References InitBroadPhase().
Referenced by Chute::create_bottom(), and ChuteBottom::setup_particles_initial_conditions().
{InitBroadPhase();}
void HGRID_base::HGRID_actions_before_time_step | ( | ) | [virtual] |
This resets all the bucket information.
This is the actions before the time step, it basically compute which cell each particle is in.
Reimplemented from MD.
References HGrid::bucketIsChecked, ParticleHandler::end(), MD::get_ParticleHandler(), grid, MD::HGRID_UpdateParticleInHgrid(), HGrid::NUM_BUCKETS, HGrid::objectBucket, SPHERE_TO_CELL_RATIO, totalCurrentMaxRelativeDisplacement, and updateEachTimeStep.
Referenced by Chute::create_bottom().
{ static int stepsBeforeUpdate=0; for (int i=0; i<grid->NUM_BUCKETS; i++) { grid->bucketIsChecked[i] = false; } if(updateEachTimeStep||totalCurrentMaxRelativeDisplacement>=SPHERE_TO_CELL_RATIO-1) { for (int i=0; i<grid->NUM_BUCKETS; i++) { grid->objectBucket[i] = NULL; } totalCurrentMaxRelativeDisplacement=0; for (vector<Particle*>::iterator it = get_ParticleHandler().begin(); it!=get_ParticleHandler().end(); ++it) { //(*it)->set_HGRID_NextObject(NULL); HGRID_UpdateParticleInHgrid(*it); } //if(!updateEachTimeStep) cout<<"New HGRID Update after: "<<stepsBeforeUpdate<<" timesteps"<<endl; stepsBeforeUpdate=0; } else { stepsBeforeUpdate++; //cout<<endl<<"No grid update"<<endl; } }
void HGRID_base::HGRID_InsertParticleToHgrid | ( | Particle * | obj | ) | [protected] |
Inserts a single Particle to current grid.
References grid, and HGrid::InsertParticleToHgrid().
{ grid->InsertParticleToHgrid(obj); }
void HGRID_base::HGRID_update_move | ( | Particle * | iP, |
Mdouble | move | ||
) | [inline, protected, virtual] |
Reimplemented from MD.
References HGrid::CELL_TO_CELL_RATIO, currentMaxRelativeDisplacement, Particle::get_HGRID_Level(), grid, and HGrid::MIN_CELL_SIZE.
{ Mdouble currentRelativeDisplacement=move/(grid->MIN_CELL_SIZE*pow(grid->CELL_TO_CELL_RATIO,iP->get_HGRID_Level())); if(currentRelativeDisplacement>currentMaxRelativeDisplacement) currentMaxRelativeDisplacement=currentRelativeDisplacement; };
void HGRID_base::InitBroadPhase | ( | ) | [protected, virtual] |
This sets up the parameters required for the contact model.
This set up the Broad grid.
Reimplemented from MD.
References HGrid::bucketIsChecked, CELL_TO_CELL_RATIO, ParticleHandler::end(), MD::get_ParticleHandler(), MD::get_SmallestParticle(), grid, HGRID_MAX_LEVELS, MD::HGRID_UpdateParticleInHgrid(), HGrid::Initialize_inv_size(), HGrid::InsertParticleToHgrid(), MIN_CELL_SIZE, HGrid::NUM_BUCKETS, NUM_BUCKETS, HGrid::objectBucket, HGrid::occupiedLevelsMask, set_HGRID_min_cell_size(), and SPHERE_TO_CELL_RATIO.
Referenced by HGRID_actions_before_time_loop().
{ //Set the smallest Hgrid size based on the smallest particle set_HGRID_min_cell_size(2.0*get_SmallestParticle()->get_Radius()*SPHERE_TO_CELL_RATIO); //cout << "Smallest particle size is : "<< get_radius_of_smallest_particle() <<endl; //cout << "Largest particle size is : " << get_radius_of_largest_particle() << endl; //Create grid object if (grid!=NULL) delete grid; grid = new HGrid(NUM_BUCKETS, HGRID_MAX_LEVELS, MIN_CELL_SIZE, SPHERE_TO_CELL_RATIO, CELL_TO_CELL_RATIO); grid->occupiedLevelsMask = 0; grid->Initialize_inv_size(); //grid->InitializeMaxMinCellPos(get_xmin(), get_ymin(), get_zmin(), get_xmax(), get_ymax(), get_zmax()); //New steps in initbroad_phase is to not only Insert the Particles in the grid but also update them for (int i=0; i<grid->NUM_BUCKETS; i++) { grid->objectBucket[i] = NULL; grid->bucketIsChecked[i] = false; } for (vector<Particle*>::iterator it = get_ParticleHandler().begin(); it!=get_ParticleHandler().end(); ++it) { grid->InsertParticleToHgrid(*it); HGRID_UpdateParticleInHgrid(*it); } }
void HGRID_base::print | ( | std::ostream & | os, |
bool | print_all = false |
||
) | [inline, virtual] |
This function outputs all HGRID data.
Reimplemented from MD.
Reimplemented in Chute.
References CELL_TO_CELL_RATIO, HGRID_MAX_LEVELS, MIN_CELL_SIZE, NUM_BUCKETS, and SPHERE_TO_CELL_RATIO.
{ MD::print(os,print_all); os << " NUM_BUCKETS:" << NUM_BUCKETS << ", HGRID_MAX_LEVELS:" << HGRID_MAX_LEVELS << ", MIN_CELL_SIZE:" << MIN_CELL_SIZE << ", " << endl << " SPHERE_TO_CELL_RATIO:" << SPHERE_TO_CELL_RATIO << ", CELL_TO_CELL_RATIO:" << CELL_TO_CELL_RATIO << endl; }
void HGRID_base::read | ( | std::istream & | is | ) | [inline, virtual] |
This function reads all HGRID data.
Reimplemented from MD.
Reimplemented in ChuteWithHopper, and Chute.
References CELL_TO_CELL_RATIO, MD::get_restart_version(), HGRID_MAX_LEVELS, MIN_CELL_SIZE, NUM_BUCKETS, and SPHERE_TO_CELL_RATIO.
{ MD::read(is); //read out the full line first, so if there is an error it does not affect the read of the next line string line_string; getline(is,line_string); stringstream line (stringstream::in | stringstream::out); line << line_string; if (get_restart_version()==1) { line >> NUM_BUCKETS >> HGRID_MAX_LEVELS >> MIN_CELL_SIZE >> SPHERE_TO_CELL_RATIO >> CELL_TO_CELL_RATIO; } else { string dummy; line>> dummy >> NUM_BUCKETS >> dummy >> HGRID_MAX_LEVELS >> dummy >> MIN_CELL_SIZE >> dummy >> SPHERE_TO_CELL_RATIO >> dummy >> CELL_TO_CELL_RATIO; } }
void HGRID_base::set_CELL_TO_CELL_RATIO | ( | Mdouble | new_CELL_TO_CELL_RATIO | ) | [inline, private] |
References CELL_TO_CELL_RATIO.
Referenced by fix_hgrid().
{if (new_CELL_TO_CELL_RATIO>0){CELL_TO_CELL_RATIO=new_CELL_TO_CELL_RATIO;}}
void HGRID_base::set_HGRID_cell_to_cell_ratio | ( | Mdouble | new_ratio | ) | [inline] |
This sets the ratio of the size of cells for the HGRID, note this is real NOT an integer.
References CELL_TO_CELL_RATIO.
Referenced by ChuteBottom::setup_particles_initial_conditions().
{if (new_ratio>0){CELL_TO_CELL_RATIO=new_ratio;}}
void HGRID_base::set_HGRID_max_levels | ( | int | new_max_levels | ) | [inline] |
This sets the maximum number of levels for the HGRID.
References HGRID_MAX_LEVELS.
Referenced by fix_hgrid(), and ChuteBottom::setup_particles_initial_conditions().
{if (new_max_levels>0){HGRID_MAX_LEVELS=new_max_levels;}}
void HGRID_base::set_HGRID_min_cell_size | ( | Mdouble | new_min_cell_size | ) | [inline, private] |
This sets the minimum cell size for the HGRID. No point having this smaller than the smallest particle.
References MIN_CELL_SIZE.
Referenced by fix_hgrid(), and InitBroadPhase().
{if (new_min_cell_size>0){MIN_CELL_SIZE=new_min_cell_size;}}
void HGRID_base::set_HGRID_num_buckets | ( | unsigned int | new_num_buckets | ) | [inline] |
This sets the number of buckets for the HGRID.
References NUM_BUCKETS.
Referenced by set_HGRID_num_buckets_to_power().
{if (new_num_buckets>0) NUM_BUCKETS=new_num_buckets; else {cerr << "Error in set_HGRID_num_buckets" << endl; exit(-1);}}
void HGRID_base::set_HGRID_num_buckets_to_power | ( | ) | [inline] |
set number of buckets to the smallest power of two bigger than the number of particles
References MD::get_ParticleHandler(), and set_HGRID_num_buckets_to_power().
Referenced by fix_hgrid(), set_HGRID_num_buckets_to_power(), and ChuteBottom::setup_particles_initial_conditions().
{ set_HGRID_num_buckets_to_power(get_ParticleHandler().get_NumberOfParticles()); }
void HGRID_base::set_HGRID_num_buckets_to_power | ( | unsigned int | N | ) | [inline] |
set number of buckets to the smallest power of two bigger than N
References NUM_BUCKETS, and set_HGRID_num_buckets().
{ unsigned int NUM_BUCKETS = 32; while (NUM_BUCKETS<2*N) NUM_BUCKETS *= 2; set_HGRID_num_buckets(NUM_BUCKETS); }
void HGRID_base::set_HGRID_sphere_to_cell_ratio | ( | Mdouble | new_ratio | ) | [inline] |
This sets the sphere to cell ratio for the HGRID. This raised to the power of dimension is the number of particles of cell size which could be in this cell.
References SPHERE_TO_CELL_RATIO.
{if (new_ratio>0){SPHERE_TO_CELL_RATIO=new_ratio;}}
void HGRID_base::set_UpdateEachTimeStep | ( | bool | _new | ) | [inline] |
References updateEachTimeStep.
{updateEachTimeStep=_new;}
virtual bool HGRID_base::TestObject | ( | Particle * | pI, |
Particle * | pJ | ||
) | [inline, protected, virtual] |
criterium for inserting a particle (returns false, if particles overlap;)
References Particle::get_Index(), Particle::get_Position(), Particle::get_Radius(), and sqr.
Referenced by HGRID_2D::TestCell(), and HGRID_3D::TestCell().
{ //PI==PJ check is required because this function is called for all possible close Particle combination (even itself) return pI->get_Index()==pJ->get_Index() || GetDistance2(pI->get_Position(),pJ->get_Position())>=sqr(pI->get_Radius()+pJ->get_Radius()); }
void HGRID_base::write | ( | std::ostream & | os | ) | [inline, virtual] |
This function writes all HGRID data.
Reimplemented from MD.
Reimplemented in ChuteWithHopper, and Chute.
References CELL_TO_CELL_RATIO, HGRID_MAX_LEVELS, MIN_CELL_SIZE, NUM_BUCKETS, and SPHERE_TO_CELL_RATIO.
{ MD::write(os); os << "NUM_BUCKETS " << NUM_BUCKETS << " " << "HGRID_MAX_LEVELS " << HGRID_MAX_LEVELS << " " << "MIN_CELL_SIZE " << MIN_CELL_SIZE << " " << "SPHERE_TO_CELL_RATIO " << SPHERE_TO_CELL_RATIO << " " << "CELL_TO_CELL_RATIO " << CELL_TO_CELL_RATIO << endl; }
Mdouble HGRID_base::CELL_TO_CELL_RATIO [private] |
Referenced by constructor(), InitBroadPhase(), print(), read(), set_CELL_TO_CELL_RATIO(), set_HGRID_cell_to_cell_ratio(), and write().
HGrid* HGRID_base::grid [protected] |
Referenced by Chute::add_particle(), broad_phase(), constructor(), HGRID_actions_before_time_step(), HGRID_InsertParticleToHgrid(), HGRID_2D::HGRID_RemoveParticleFromHgrid(), HGRID_3D::HGRID_RemoveParticleFromHgrid(), HGRID_update_move(), HGRID_2D::HGRID_UpdateParticleInHgrid(), HGRID_3D::HGRID_UpdateParticleInHgrid(), InitBroadPhase(), Chute::IsInsertable(), and ~HGRID_base().
int HGRID_base::HGRID_MAX_LEVELS [private] |
Referenced by constructor(), InitBroadPhase(), print(), read(), set_HGRID_max_levels(), and write().
Mdouble HGRID_base::MIN_CELL_SIZE [private] |
Referenced by constructor(), InitBroadPhase(), print(), read(), set_HGRID_min_cell_size(), and write().
int HGRID_base::NUM_BUCKETS [private] |
Referenced by constructor(), InitBroadPhase(), print(), read(), set_HGRID_num_buckets(), set_HGRID_num_buckets_to_power(), and write().
Mdouble HGRID_base::SPHERE_TO_CELL_RATIO [private] |
Referenced by constructor(), HGRID_actions_before_time_step(), InitBroadPhase(), print(), read(), set_HGRID_sphere_to_cell_ratio(), and write().
bool HGRID_base::updateEachTimeStep [private] |
Referenced by constructor(), get_HGRID_UpdateEachTimeStep(), HGRID_actions_before_time_step(), and set_UpdateEachTimeStep().