HG-MD  1
Public Member Functions | Private Attributes
ParticleHandler Class Reference

#include <ParticleHandler.h>

List of all members.

Public Member Functions

 ParticleHandler ()
 Constructor of the ParticleHandler class. It creates and empty ParticleHandler.
 ParticleHandler (const ParticleHandler &pH)
 Copy constructor of the ParticleHandler class, which accepts as input a reference to a ParticleHandler. It creates a copy this instance and all Particle in this instance.
ParticleHandler operator= (const ParticleHandler right)
 ~ParticleHandler ()
 Destructor of the ParticleHandler class. It destruct the ParticleHandler and also all Particle reffered to by the ParitcleHandler.
void copyAndAddParticle (Particle &P)
 Copy and add Particle functionc, which accpets a reference to a Particle (or derived class).
void addParticle (Particle *P)
 Add Particle function, which accepts a pointer to a Particle (or derived class). It adds the Particle to the ParticleHandler, note that is does not create a copy of this Particle.
void removeParticle (int IP)
 Remove Particle function, which accepts an integer.
void removeLastParticle ()
 Remove last Particle function. It removes the last Particle from the ParticleHandler.
Particleget_SmallestParticle ()
 Get smallest Particle function. It returns a pointer to the smallest (by radius) Particle in this ParticleHandler.
Particleget_LightestParticle ()
 Get lightest Particle function. It returns a pointer to the lightest (by mass) Particle in this ParticleHandler.
Particleget_LargestParticle ()
 Get largest Particle function. It returns a pointer to the largest (by radius) Particle in this ParticleHandler.
void clear ()
 Clears the whole ParticleHandler.
Particleget_Particle (unsigned int p)
 Get Particle function, which accepts an unsigned integer. It returns a pointer to the Particle at that position in the ParticleHandler.
Particleback ()
 Get last Particle function. It returns a pointer to the last Particle in this ParticleHandler.
unsigned int get_NumberOfParticles ()
 Get number of Particle function. It returns the number of Particle in this ParticleHandler.
unsigned int get_StorageCapacity ()
 Get storage capacity function. It returns the current storage capacity of this ParticleHandler.
unsigned int get_MaximumParticles ()
 Get maximum number of Particle function. It returns the largest number of Particle ever stored in this ParticleHandler.
void set_StorageCapacity (unsigned int N)
 Set storage capacity function, which accepts an unsigned integer. It sets the storage capacity of this ParticleHandler to the value provided (use of this function is not neccesary but can increase performance)
vector< Particle * >::iterator begin ()
 Begin iterator helper function. This returns an vector<Particle*>::iterator pointing to the first Particle, used for looping over all Particle in this ParticleHandler.
vector< Particle * >::iterator end ()
 End iterator helper function. This returns an vector<Particle*>::iterator pointing to the last Particle, used for looping over all Particle in this ParticleHandler.

Private Attributes

vector< Particle * > particles
 The actual list of Particle pointers.
unsigned int maxParticles
 An integer to keep track of the largest number of Particle ever stored in this ParticleHandler.

Constructor & Destructor Documentation

Constructor of the ParticleHandler class. It creates and empty ParticleHandler.

        {
                maxParticles=0;
                #ifdef CONSTUCTOR_OUTPUT
                        cerr << "ParticleHandler() finished" << endl;
                #endif                          
        }

Copy constructor of the ParticleHandler class, which accepts as input a reference to a ParticleHandler. It creates a copy this instance and all Particle in this instance.

References particles.

        {
                cout<<"ParticleHandler copy constructor"<<endl;
                for (unsigned int i=0;i<pH.particles.size();i++)
                {
                        addParticle(pH.particles[i]->copy());
                }
                #ifdef CONSTUCTOR_OUTPUT
                        cerr << "ParticleHandler(const ParticleHandler &pH) finished" << endl;
                #endif          
        }

Destructor of the ParticleHandler class. It destruct the ParticleHandler and also all Particle reffered to by the ParitcleHandler.

        {
                for(vector<Particle*>::iterator it = particles.begin(); it!=particles.end();it++)
                {
                        delete *it;
                }
        }

Member Function Documentation

void ParticleHandler::addParticle ( Particle P) [inline]

Add Particle function, which accepts a pointer to a Particle (or derived class). It adds the Particle to the ParticleHandler, note that is does not create a copy of this Particle.

        {
                //Puts the particle in the Particle list
                particles.push_back(P);
                //Set the index of the particle
                particles.back()->set_Index(particles.size()-1);
                //Update the maximum number of Particles
                if(particles.size()>maxParticles) maxParticles=particles.size();
        }       

Get last Particle function. It returns a pointer to the last Particle in this ParticleHandler.

Referenced by MD::Check_and_Duplicate_Periodic_Particle(), copyAndAddParticle(), and Chute::IsInsertable().

{return particles.back();}
vector<Particle*>::iterator ParticleHandler::begin ( ) [inline]

Begin iterator helper function. This returns an vector<Particle*>::iterator pointing to the first Particle, used for looping over all Particle in this ParticleHandler.

Referenced by MD::compute_all_forces(), ChuteBottom::make_rough_bottom(), MD::output_ene(), MD::read_next_from_data_file(), MD::solve(), MD::write(), and MD::write_v1().

{return particles.begin();}
void ParticleHandler::clear ( ) [inline]

Clears the whole ParticleHandler.

        {
                while (particles.size()>0)
                        removeLastParticle();
        }

Copy and add Particle functionc, which accpets a reference to a Particle (or derived class).

It creates a copy of this Particle and adds it to the list of Particle in the ParticleHandler. todo{Should this function also put and update the Particle in the Hgrid? If so then the HGrid must be set before Particle are added, other posibility is to make a check of the Hgrid is initialized and act on that}

References back(), Particle::copy(), and Particle::set_Index().

Referenced by Chute::add_particle(), MD::Check_and_Duplicate_Periodic_Particle(), Chute::create_bottom(), MD::read(), MD::read_next_from_data_file(), MD::read_v1(), and MD::read_v2().

        {
                //Puts the particle in the Particle list
                particles.push_back(P.copy());
                //Set the index of the particle
                particles.back()->set_Index(particles.size()-1); 
                //Update the maximum number of Particles
                if(particles.size()>maxParticles) maxParticles=particles.size();
        }
vector<Particle*>::iterator ParticleHandler::end ( ) [inline]

Get largest Particle function. It returns a pointer to the largest (by radius) Particle in this ParticleHandler.

References Particle::get_Radius().

                                       {
                if (!particles.size()) cerr << "Warning: No particles to set get_LargestParticle()" << endl;
                Particle* p = NULL;
                Mdouble maxRadius = 0;
                for (unsigned int i=0; i<particles.size(); i++) { 
                        if (particles[i]->get_Radius()>maxRadius) {
                                maxRadius=particles[i]->get_Radius(); 
                                p = particles[i]; 
                        }
                }
                return p;
        }

Get lightest Particle function. It returns a pointer to the lightest (by mass) Particle in this ParticleHandler.

                                        {
                if (!particles.size()) cerr << "Warning: No particles to set get_LightestParticle()" << endl;
                Particle* p = NULL;
                Mdouble minMass = numeric_limits<Mdouble>::max();
                for (unsigned int i=0; i<particles.size(); i++) {
                        if (particles[i]->get_Mass()<minMass) {
                                minMass=particles[i]->get_Mass(); 
                                p = particles[i]; 
                        }
                }
                return p;
        }
unsigned int ParticleHandler::get_MaximumParticles ( ) [inline]

Get maximum number of Particle function. It returns the largest number of Particle ever stored in this ParticleHandler.

{return maxParticles;}
unsigned int ParticleHandler::get_NumberOfParticles ( ) [inline]
Particle* ParticleHandler::get_Particle ( unsigned int  p) [inline]

Get Particle function, which accepts an unsigned integer. It returns a pointer to the Particle at that position in the ParticleHandler.

Referenced by MD::Check_and_Duplicate_Periodic_Particles(), Chute::clean_chute(), Chute::get_LargestParticle(), Chute::get_radius_of_smallest_particle(), Chute::get_SmallestParticle(), MD::print(), MD::read_next_from_data_file(), MD::Remove_Duplicate_Periodic_Particles(), and MD::solve().

{if (p<particles.size()) return particles[p]; else {cerr<<"No particle exist with index "<<p<<endl; return NULL;}}

Get smallest Particle function. It returns a pointer to the smallest (by radius) Particle in this ParticleHandler.

                                        {
                if (!particles.size()) cerr << "Warning: No particles to set get_SmallestParticle()" << endl;
                Particle* p = NULL;
                Mdouble minRadius = numeric_limits<Mdouble>::max();
                for (unsigned int i=0; i<particles.size(); i++) {
                        if (particles[i]->get_Radius()<minRadius) {
                                minRadius=particles[i]->get_Radius(); 
                                p = particles[i]; 
                        }
                }               
                return p;
        }
unsigned int ParticleHandler::get_StorageCapacity ( ) [inline]

Get storage capacity function. It returns the current storage capacity of this ParticleHandler.

Referenced by MD::print().

{return particles.capacity();}
ParticleHandler ParticleHandler::operator= ( const ParticleHandler  right) [inline]

References particles.

        {
                cout<<"ParticleHandler assignment opperator"<<endl;
                  if (this != &right) 
                  {
                        for (unsigned int i=0;i<right.particles.size();i++)
                        {
                                addParticle(right.particles[i]->copy());
                        }
                        
                }
                return *this;
        }

Remove last Particle function. It removes the last Particle from the ParticleHandler.

Referenced by Chute::IsInsertable(), and MD::read_next_from_data_file().

        {
                //Physically removes Particle
                delete particles.back();
                //Remove the (now Mdouble) reference to that last Particle
                particles.pop_back();
        }
void ParticleHandler::removeParticle ( int  IP) [inline]

Remove Particle function, which accepts an integer.

It removes the Particle at that position from the ParticleHandler by moving the last Particle in the vector to the position of p. todo{Is it still required to check for tangential spring removal? Also it checks if the moved Particle has any tangentialsspring-information, which needs to be moved to a different Particle, because tangential spring information always needs to be stored in the real Particle with highest Particle index.}

todo{Is a time restriction neccesary here?}

References CTangentialSpring::pParticle.

Referenced by ChuteBottom::make_rough_bottom().

        {
                //Physically remove Particle
                delete particles[IP];
                //Copy the pointer to the last Particle to position p
                particles[IP] = particles.back();
                //Set the correct (new) index
                particles[IP]->set_Index(IP);
                //Remove the (now Mdouble) reference to that last Particle
                particles.pop_back();
                
                for(unsigned int i=0;i<particles[IP]->get_TangentialSprings().size();)
                {
                        if (particles[IP]->get_TangentialSprings()[i].pParticle>IP)
                        {
                                int JP=particles[IP]->get_TangentialSprings()[i].pParticle;
                                
                                //Copy Tangentalspring to new location
                                CTangentialSpring CTS=particles[IP]->get_TangentialSprings()[i];
                                CTS.pParticle=IP;
                                particles[JP]->get_TangentialSprings().push_back(CTS);
                                
                                //Remove now unused tangentialspring
                                particles[IP]->get_TangentialSprings()[i]=particles[IP]->get_TangentialSprings().back();
                                particles[IP]->get_TangentialSprings().pop_back();
                        }       else i++;                               
                }       
        }
void ParticleHandler::set_StorageCapacity ( unsigned int  N) [inline]

Set storage capacity function, which accepts an unsigned integer. It sets the storage capacity of this ParticleHandler to the value provided (use of this function is not neccesary but can increase performance)

Referenced by MD::constructor(), ChuteBottom::make_rough_bottom(), and ChuteBottom::setup_particles_initial_conditions().

{particles.reserve(N);}

Member Data Documentation

unsigned int ParticleHandler::maxParticles [private]

An integer to keep track of the largest number of Particle ever stored in this ParticleHandler.

The actual list of Particle pointers.

Referenced by operator=(), and ParticleHandler().


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines