MercuryDPM  Beta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ParticleHandler Class Reference

Container to store all BaseParticle. More...

#include <ParticleHandler.h>

+ Inheritance diagram for ParticleHandler:

Public Member Functions

 ParticleHandler ()
 Default constructor, it creates an empty ParticleHandler. More...
 
 ParticleHandler (const ParticleHandler &PH)
 Constructor that copies all BaseParticle it contains and then sets the smallest and largest particle. More...
 
ParticleHandler operator= (const ParticleHandler &rhs)
 Assignment operator. More...
 
 ~ParticleHandler ()
 Destructor, it destructs the ParticleHandler and all BaseParticle it contains. More...
 
virtual void addObject (BaseParticle *P)
 Adds a BaseParticle to the ParticleHandler. More...
 
virtual void removeObject (unsigned const int id)
 Removes a BaseParticle from the ParticleHandler. More...
 
void removeLastObject ()
 Removes the last BaseParticle from the ParticleHandler. More...
 
void computeSmallestParticle ()
 Computes the smallest particle (by interaction radius) and sets it in smallestParticle_. More...
 
void computeLargestParticle ()
 Computes the largest particle (by interaction radius) and sets it in largestParticle_. More...
 
BaseParticlegetSmallestParticle () const
 Gets a pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler. More...
 
BaseParticlegetLargestParticle () const
 Gets a pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler. More...
 
BaseParticlegetFastestParticle () const
 Gets a pointer to the fastest BaseParticle in this ParticleHandler. More...
 
BaseParticlegetLowestPositionComponentParticle (const int i) const
 Gets a pointer to the particle with the lowest coordinates in direction i in this ParticleHandler. More...
 
BaseParticlegetHighestPositionComponentParticle (const int i) const
 Gets a pointer to the particle with the highest coordinates in direction i in this ParticleHandler. More...
 
BaseParticlegetLowestVelocityComponentParticle (const int i) const
 Gets a pointer to the particle with the lowest velocity in direction i in this ParticleHandler. More...
 
BaseParticlegetHighestVelocityComponentParticle (const int i) const
 Gets a pointer to the particle with the highest velocity in direction i in this ParticleHandler. More...
 
BaseParticlegetLightestParticle () const
 Gets a pointer to the lightest BaseParticle (by mass) in this ParticleHandler. More...
 
void clear ()
 Empties the whole ParticleHandler by removing all BaseParticle. More...
 
void readObject (std::istream &is)
 Reads BaseParticle into the ParticleHandler from restart data. More...
 
void readOldObject (std::string type, std::istream &is)
 Reads BaseParticle into the ParticleHandler from old-style restart data. More...
 
void write (std::ostream &os) const
 
void checkExtrema (BaseParticle *P)
 Checks if the extrema of this ParticleHandler needs updating. More...
 
void checkExtremaOnDelete (BaseParticle *P)
 Checks if the extrema of this ParticleHandler needs updating when a particle is deleted. More...
 
void computeAllMasses (unsigned int indSpecies)
 Computes the mass for all BaseParticle of the given species in this ParticleHandler. More...
 
void computeAllMasses ()
 Computes the mass for all BaseParticle in this ParticleHandler. More...
 
std::string getName () const
 Returns the name of the handler, namely the string "ParticleHandler". More...
 
- Public Member Functions inherited from BaseHandler< BaseParticle >
 BaseHandler ()
 Default BaseHandler constructor, it creates an empty BaseHandler and assigns DPMBase_ to a null pointer. More...
 
 BaseHandler (const BaseHandler< BaseParticle > &BH)
 Constructor that copies the objects of the given handler into itself and sets other variables to 0/nullptr. More...
 
virtual ~BaseHandler ()
 Destructor, it destructs the BaseHandler and all Object it contains. More...
 
void copyContentsFromOtherHandler (const BaseHandler< BaseParticle > &BH)
 Function that copies the contents (vector of pointers, maxObject_, nextId_, DPMBase_) from one handler (container) to the other. More...
 
U * copyAndAddObject (const U &O)
 Creates a copy of a Object and adds it to the BaseHandler. More...
 
U * copyAndAddObject (U *O)
 Creates a copy of a Object and adds it to the BaseHandler. More...
 
void removeLastObject ()
 Removes the last Object from the BaseHandler. More...
 
void clear ()
 Empties the whole BaseHandler by removing all Objects and setting all other variables to 0. More...
 
void read (std::istream &is)
 Reads all objects from restart data. More...
 
BaseParticlegetObjectById (const unsigned int id)
 Gets a pointer to the Object at the specified index in the BaseHandler. More...
 
BaseParticlegetObject (const unsigned int id)
 Gets a pointer to the Object at the specified index in the BaseHandler. More...
 
const BaseParticlegetObject (const unsigned int id) const
 Gets a constant pointer to the Object at the specified index in the BaseHandler. More...
 
BaseParticlegetLastObject ()
 Gets a pointer to the last Object in this BaseHandler. More...
 
const BaseParticlegetLastObject () const
 Gets a constant pointer to the last Object in this BaseHandler. More...
 
unsigned int getNumberOfObjects () const
 Gets the number of Object in this BaseHandler. More...
 
unsigned int getStorageCapacity () const
 Gets the storage capacity of this BaseHandler. More...
 
void setStorageCapacity (const unsigned int N)
 Sets the storage capacity of this BaseHandler. More...
 
const std::vector
< BaseParticle * >
::const_iterator 
begin () const
 Gets the begin of the const_iterator over all Object in this BaseHandler. More...
 
const std::vector
< BaseParticle * >::iterator 
begin ()
 Gets the begin of the iterator over all BaseBoundary in this BaseHandler. More...
 
const std::vector
< BaseParticle * >
::const_iterator 
end () const
 Gets the end of the const_iterator over all BaseBoundary in this BaseHandler. More...
 
const std::vector
< BaseParticle * >::iterator 
end ()
 Gets the end of the iterator over all BaseBoundary in this BaseHandler. More...
 
void setDPMBase (DPMBase *DPMBase)
 Sets the problem that is solved using this handler. More...
 
DPMBasegetDPMBase ()
 Gets the problem that is solved using this handler. More...
 
DPMBasegetDPMBase () const
 Gets the problem that is solved using this handler and does not change the class. More...
 

Private Attributes

BaseParticlelargestParticle_
 A pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler. More...
 
BaseParticlesmallestParticle_
 A pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler. More...
 

Additional Inherited Members

- Protected Attributes inherited from BaseHandler< BaseParticle >
std::vector< BaseParticle * > objects_
 The actual list of Object pointers. More...
 

Detailed Description

Container to store all BaseParticle.

The ParticleHandler is a container to store all BaseParticle. It is implemented by a vector of pointers to BaseParticle.

Definition at line 41 of file ParticleHandler.h.

Constructor & Destructor Documentation

ParticleHandler::ParticleHandler ( )

Default constructor, it creates an empty ParticleHandler.

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

Definition at line 39 of file ParticleHandler.cc.

References DEBUG, largestParticle_, logger, and smallestParticle_.

40 {
41  largestParticle_ = nullptr;
42  smallestParticle_ = nullptr;
43  logger(DEBUG, "ParticleHandler::ParticleHandler() finished");
44 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
BaseParticle * smallestParticle_
A pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler.
BaseParticle * largestParticle_
A pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.
ParticleHandler::ParticleHandler ( const ParticleHandler PH)

Constructor that copies all BaseParticle it contains and then sets the smallest and largest particle.

Parameters
[in]PHThe ParticleHandler that has to be copied.

This is not a copy constructor! It copies the DPMBase and all BaseParticle, and sets the other variables to 0. After that, it computes the smallest and largest particle in this handler.

Definition at line 52 of file ParticleHandler.cc.

References clear(), computeLargestParticle(), computeSmallestParticle(), BaseHandler< BaseParticle >::copyContentsFromOtherHandler(), DEBUG, BaseHandler< T >::getDPMBase(), largestParticle_, logger, BaseHandler< BaseParticle >::objects_, BaseHandler< BaseParticle >::setDPMBase(), and smallestParticle_.

54 {
55  clear();
56  setDPMBase(PH.getDPMBase());
57  largestParticle_ = nullptr;
58  smallestParticle_ = nullptr;
60  if (objects_.size() != 0)
61  {
64  }
65  logger(DEBUG, "ParticleHandler::ParticleHandler(const ParticleHandler &PH) finished");
66 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
void setDPMBase(DPMBase *DPMBase)
Sets the problem that is solved using this handler.
BaseParticle * smallestParticle_
A pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler.
void clear()
Empties the whole ParticleHandler by removing all BaseParticle.
BaseParticle * largestParticle_
A pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:205
void computeSmallestParticle()
Computes the smallest particle (by interaction radius) and sets it in smallestParticle_.
void computeLargestParticle()
Computes the largest particle (by interaction radius) and sets it in largestParticle_.
void copyContentsFromOtherHandler(const BaseHandler< BaseParticle > &BH)
Function that copies the contents (vector of pointers, maxObject_, nextId_, DPMBase_) from one handle...
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:512
ParticleHandler::~ParticleHandler ( )

Destructor, it destructs the ParticleHandler and all BaseParticle it contains.

Set the pointers to largestParticle_ and smallestParticle_ to nullptr, all BaseParticle are destroyed by the BaseHandler afterwards.

Definition at line 96 of file ParticleHandler.cc.

References DEBUG, largestParticle_, logger, and smallestParticle_.

97 {
98  //First reset the pointers, such that they are not checked twice when removing particles
99  largestParticle_ = nullptr;
100  smallestParticle_ = nullptr;
101  logger(DEBUG, "ParticleHandler::~ParticleHandler() finished");
102 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
BaseParticle * smallestParticle_
A pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler.
BaseParticle * largestParticle_
A pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.

Member Function Documentation

void ParticleHandler::addObject ( BaseParticle P)
virtual

Adds a BaseParticle to the ParticleHandler.

Parameters
[in]PA pointer to the BaseParticle that has to be added.

To add a BaseParticle to the ParticleHandler, first check if it has a species, since it is as common bug to use a BaseParticle without species, which leads to a segmentation fault. To help the user with debugging, a warning is given if a particle without species is added. After that, the actions for adding the particle to the BaseHandler are taken, which include adding it to the vector of pointers to all BaseParticle and assigning the correct id and index. Then the particle is added to the HGrid, the particle is told that this is its handler, its mass is computed and finally it is checked if this is the smallest or largest particle in this ParticleHandler.

Reimplemented from BaseHandler< BaseParticle >.

Definition at line 117 of file ParticleHandler.cc.

References BaseHandler< T >::addObject(), checkExtrema(), ParticleSpecies::computeMass(), BaseHandler< BaseParticle >::getDPMBase(), BaseInteractable::getSpecies(), DPMBase::hGridInsertParticle(), DPMBase::hGridUpdateParticle(), and BaseParticle::setHandler().

Referenced by CircularPeriodicBoundary::checkBoundaryAfterParticleMoved(), LeesEdwardsBoundary::createHorizontalPeriodicParticles(), CircularPeriodicBoundary::createPeriodicParticles(), MaserBoundary::createPeriodicParticles(), AngledPeriodicBoundary::createPeriodicParticles(), PeriodicBoundary::createPeriodicParticles(), and LeesEdwardsBoundary::createVerticalPeriodicParticles().

118 {
119  //\todo I diasbled the MERCURY_DEPRECATED attribute until we actually fixed the deprecation issue. This will scare users away.
120  // if (P->getSpecies() == nullptr)
121  // {
122  // logger(WARN, "WARNING: The particle with ID % that is added in "
123  // "ParticleHandler::addObject does not have a species yet. "
124  // "Please make sure that you have "
125  // "set the species somewhere in the driver code.", P->getId());
126  // }
127  //Puts the particle in the Particle list
129  if (getDPMBase() != nullptr)
130  {
131  //This places the particle in this grid
133  //This computes where the particle currently is in the grid
135  }
136  //set the particleHandler pointer
137  P->setHandler(this);
138  //compute mass of the particle
139  P->getSpecies()->computeMass(P) ;
140  //Check if this particle has new extrema
141  checkExtrema(P);
142 }
virtual void hGridUpdateParticle(BaseParticle *obj UNUSED)
no implementation but can be overidden in its derived classes.
Definition: DPMBase.cc:633
virtual void hGridInsertParticle(BaseParticle *obj UNUSED)
no implementation but can be overidden in its derived classes.
Definition: DPMBase.cc:626
void checkExtrema(BaseParticle *P)
Checks if the extrema of this ParticleHandler needs updating.
const ParticleSpecies * getSpecies() const
Returns a pointer to the species of this BaseInteractable.
void setHandler(ParticleHandler *handler)
Sets the pointer to the particle's ParticleHandler.
virtual void computeMass(BaseParticle *p) const
Compute Particle mass function, which required a reference to the Species vector. It computes the Par...
virtual void addObject(T *O)
Adds a new Object to the BaseHandler.
Definition: BaseHandler.h:284
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
void ParticleHandler::checkExtrema ( BaseParticle P)

Checks if the extrema of this ParticleHandler needs updating.

Parameters
[in]PA pointer to the particle, which properties have to be checked against the ParticleHandlers extrema.

Definition at line 488 of file ParticleHandler.cc.

References computeLargestParticle(), computeSmallestParticle(), BaseParticle::getInteractionRadius(), largestParticle_, and smallestParticle_.

Referenced by addObject(), and BaseParticle::setRadius().

489 {
490  if (P == largestParticle_)
491  {
492  //if the properties of the largest particle changes
494  }
496  {
497  largestParticle_ = P;
498  }
499 
500  if (P == smallestParticle_)
501  {
502  //if the properties of the smallest particle changes
504  }
506  {
507  smallestParticle_ = P;
508  }
509 }
BaseParticle * smallestParticle_
A pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler.
BaseParticle * largestParticle_
A pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.
void computeSmallestParticle()
Computes the smallest particle (by interaction radius) and sets it in smallestParticle_.
void computeLargestParticle()
Computes the largest particle (by interaction radius) and sets it in largestParticle_.
Mdouble getInteractionRadius() const
Returns the particle's interaction radius, which might be different from radius_ (e.g., when dealing with wet particles)
void ParticleHandler::checkExtremaOnDelete ( BaseParticle P)

Checks if the extrema of this ParticleHandler needs updating when a particle is deleted.

Parameters
[in]PA pointer to the particle, which is going to get deleted.

Definition at line 514 of file ParticleHandler.cc.

References computeLargestParticle(), computeSmallestParticle(), largestParticle_, and smallestParticle_.

Referenced by BaseParticle::~BaseParticle().

515 {
516  if (P == largestParticle_)
517  {
519  }
520  if (P == smallestParticle_)
521  {
523  }
524 }
BaseParticle * smallestParticle_
A pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler.
BaseParticle * largestParticle_
A pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.
void computeSmallestParticle()
Computes the smallest particle (by interaction radius) and sets it in smallestParticle_.
void computeLargestParticle()
Computes the largest particle (by interaction radius) and sets it in largestParticle_.
void ParticleHandler::clear ( )

Empties the whole ParticleHandler by removing all BaseParticle.

Note that the pointers to smallestParticle_ and largestParticle_ are set to nullptr since these particles don't exist anymore after calling this function.

Definition at line 389 of file ParticleHandler.cc.

References BaseHandler< T >::clear(), largestParticle_, and smallestParticle_.

Referenced by operator=(), ParticleHandler(), and DPMBase::read().

390 {
391  smallestParticle_ = nullptr;
392  largestParticle_ = nullptr;
394 }
BaseParticle * smallestParticle_
A pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler.
BaseParticle * largestParticle_
A pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.
void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
Definition: BaseHandler.h:360
void ParticleHandler::computeAllMasses ( unsigned int  indSpecies)

Computes the mass for all BaseParticle of the given species in this ParticleHandler.

Parameters
[in]indSpeciesUnsigned integer with the index of the species for which the masses must be computed.

Definition at line 530 of file ParticleHandler.cc.

References BaseHandler< BaseParticle >::objects_.

Referenced by SpeciesHandler::addObject(), DPMBase::readNextDataFile(), ParticleSpecies::setDensity(), DPMBase::setParticleDimensions(), and DPMBase::solve().

531 {
532  for (BaseParticle* particle : objects_)
533  {
534  if (particle->getIndSpecies() == indSpecies)
535  {
536  particle->getSpecies()->computeMass(particle);
537  }
538  }
539 }
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:205
void ParticleHandler::computeAllMasses ( )

Computes the mass for all BaseParticle in this ParticleHandler.

Definition at line 541 of file ParticleHandler.cc.

References BaseHandler< BaseParticle >::objects_.

542 {
543  for (BaseParticle* particle : objects_)
544  {
545  particle->getSpecies()->computeMass(particle);
546  }
547 }
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:205
void ParticleHandler::computeLargestParticle ( )

Computes the largest particle (by interaction radius) and sets it in largestParticle_.

Definition at line 192 of file ParticleHandler.cc.

References BaseParticle::getInteractionRadius(), BaseHandler< BaseParticle >::getNumberOfObjects(), largestParticle_, logger, BaseHandler< BaseParticle >::objects_, and WARN.

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

193 {
194  if (getNumberOfObjects() == 0)
195  {
196  logger(WARN, "No particles, so cannot compute the largest particle.");
197  return;
198  }
199  Mdouble max = -std::numeric_limits<Mdouble>::max();
200  largestParticle_ = nullptr;
201  for (BaseParticle* const particle : objects_)
202  {
203  if (particle->getInteractionRadius() > max)
204  {
205  max = particle->getInteractionRadius();
206  largestParticle_ = particle;
207  }
208  }
209 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
BaseParticle * largestParticle_
A pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:205
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
Mdouble getInteractionRadius() const
Returns the particle's interaction radius, which might be different from radius_ (e.g., when dealing with wet particles)
void ParticleHandler::computeSmallestParticle ( )

Computes the smallest particle (by interaction radius) and sets it in smallestParticle_.

Definition at line 173 of file ParticleHandler.cc.

References BaseParticle::getInteractionRadius(), BaseHandler< BaseParticle >::getNumberOfObjects(), logger, BaseHandler< BaseParticle >::objects_, smallestParticle_, and WARN.

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

174 {
175  if (getNumberOfObjects() == 0)
176  {
177  logger(WARN, "No particles, so cannot compute the smallest particle.");
178  return;
179  }
180  Mdouble min = std::numeric_limits<Mdouble>::max();
181  smallestParticle_ = nullptr;
182  for (BaseParticle* const particle : objects_)
183  {
184  if (particle->getInteractionRadius() < min)
185  {
186  min = particle->getInteractionRadius();
187  smallestParticle_ = particle;
188  }
189  }
190 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
BaseParticle * smallestParticle_
A pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler.
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:205
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
Mdouble getInteractionRadius() const
Returns the particle's interaction radius, which might be different from radius_ (e.g., when dealing with wet particles)
BaseParticle * ParticleHandler::getFastestParticle ( ) const

Gets a pointer to the fastest BaseParticle in this ParticleHandler.

Returns
A pointer to the fastest BaseParticle in this ParticleHandler.

Definition at line 240 of file ParticleHandler.cc.

References BaseHandler< BaseParticle >::getNumberOfObjects(), logger, BaseHandler< BaseParticle >::objects_, and WARN.

241 {
242  if (getNumberOfObjects() == 0)
243  {
244  logger(WARN, "No particles to set getFastestParticle()" );
245  return nullptr;
246  }
247  BaseParticle* p = nullptr;
248  Mdouble maxSpeed = -std::numeric_limits<Mdouble>::max();
249  for (BaseParticle* const pLoop : objects_)
250  {
251  if ((pLoop->getVelocity().getLength()) > maxSpeed)
252  {
253  maxSpeed = pLoop->getVelocity().getLength();
254  p = pLoop;
255  }
256  }
257  return p;
258 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:205
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
BaseParticle * ParticleHandler::getHighestPositionComponentParticle ( const int  i) const

Gets a pointer to the particle with the highest coordinates in direction i in this ParticleHandler.

Parameters
[in]iDirection for which one wants the particle with highest coordinates.
Returns
A pointer to the particle with the highest coordinates in direction i in this ParticleHandler.

Definition at line 290 of file ParticleHandler.cc.

References BaseHandler< BaseParticle >::getNumberOfObjects(), logger, BaseHandler< BaseParticle >::objects_, and WARN.

291 {
292  if (getNumberOfObjects() == 0)
293  {
294  logger(WARN, "No getHighestPositionComponentParticle(const int i) since there are no particles.");
295  return nullptr;
296  }
297  BaseParticle* p = nullptr;
298  Mdouble max = -std::numeric_limits<Mdouble>::max();
299  for (BaseParticle* const pLoop : objects_)
300  {
301  if (pLoop->getPosition().getComponent(i) > max)
302  {
303  max = pLoop->getPosition().getComponent(i);
304  p = pLoop;
305  }
306  }
307 
308  return p;
309 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:205
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
BaseParticle * ParticleHandler::getHighestVelocityComponentParticle ( const int  i) const

Gets a pointer to the particle with the highest velocity in direction i in this ParticleHandler.

Parameters
[in]iDirection for which you want the particle with highest velocity.
Returns
A pointer to the particle with the highest velocity in direction i in this ParticleHandler.

Definition at line 341 of file ParticleHandler.cc.

References BaseHandler< BaseParticle >::getNumberOfObjects(), logger, BaseHandler< BaseParticle >::objects_, and WARN.

342 {
343  if (!getNumberOfObjects())
344  {
345  logger(WARN, "No getHighestVelocityComponentParticle(const int i) since there are no particles");
346  return nullptr;
347  }
348  BaseParticle* p = nullptr;
349  Mdouble max = -std::numeric_limits<Mdouble>::max();
350  for (BaseParticle* const pLoop : objects_)
351  {
352  if (pLoop->getVelocity().getComponent(i) > max)
353  {
354  max = pLoop->getVelocity().getComponent(i);
355  p = pLoop;
356  }
357  }
358  return p;
359 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:205
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
BaseParticle * ParticleHandler::getLargestParticle ( ) const

Gets a pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.

Returns
A pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.

Definition at line 228 of file ParticleHandler.cc.

References largestParticle_, logger, and WARN.

Referenced by LeesEdwardsBoundary::createHorizontalPeriodicParticles(), CircularPeriodicBoundary::createPeriodicParticles(), MaserBoundary::createPeriodicParticles(), AngledPeriodicBoundary::createPeriodicParticles(), PeriodicBoundary::createPeriodicParticles(), LeesEdwardsBoundary::createVerticalPeriodicParticles(), MercuryBase::getHGridTargetMaxInteractionRadius(), MercuryBase::hGridNeedsRebuilding(), HGridOptimiser::initialise(), and DPMBase::writeFstatHeader().

229 {
230  if (largestParticle_ == nullptr)
231  {
232  logger(WARN, "No particles to set get_LargestParticle()");
233  }
234  return largestParticle_;
235 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
BaseParticle * largestParticle_
A pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.
BaseParticle * ParticleHandler::getLightestParticle ( ) const

Gets a pointer to the lightest BaseParticle (by mass) in this ParticleHandler.

Returns
A pointer to the to the lightest BaseParticle (by mass) in this ParticleHandler.

Definition at line 364 of file ParticleHandler.cc.

References BaseHandler< BaseParticle >::getNumberOfObjects(), logger, BaseHandler< BaseParticle >::objects_, and WARN.

365 {
366  if (getNumberOfObjects() == 0)
367  {
368  logger(WARN, "No particles to set getLightestParticle()");
369  return nullptr;
370  }
371  BaseParticle* p = nullptr;
372  Mdouble minMass = std::numeric_limits<Mdouble>::max();
373  for (BaseParticle* const pLoop : objects_)
374  {
375  if (pLoop->getMass() < minMass)
376  {
377  minMass = pLoop->getMass();
378  p = pLoop;
379  }
380  }
381  return p;
382 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:205
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
BaseParticle * ParticleHandler::getLowestPositionComponentParticle ( const int  i) const

Gets a pointer to the particle with the lowest coordinates in direction i in this ParticleHandler.

Parameters
[in]iDirection for which you want the particle with lowest coordinates.
Returns
A pointer to the particle with the lowest coordinates in the given direction in this ParticleHandler.

Definition at line 265 of file ParticleHandler.cc.

References BaseHandler< BaseParticle >::getNumberOfObjects(), logger, BaseHandler< BaseParticle >::objects_, and WARN.

266 {
267  if (getNumberOfObjects() == 0)
268  {
269  logger(WARN, "No getLowestPositionComponentParticle(const int i) since there are no particles.");
270  return nullptr;
271  }
272  BaseParticle* p = nullptr;
273  Mdouble min = std::numeric_limits<Mdouble>::max();
274  for (BaseParticle* const pLoop : objects_)
275  {
276  if (pLoop->getPosition().getComponent(i) < min)
277  {
278  min = pLoop->getPosition().getComponent(i);
279  p = pLoop;
280  }
281  }
282  return p;
283 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:205
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
BaseParticle * ParticleHandler::getLowestVelocityComponentParticle ( const int  i) const

Gets a pointer to the particle with the lowest velocity in direction i in this ParticleHandler.

Parameters
[in]iDirection for which you want the particle with lowest velocity.
Returns
A pointer to the particle with the lowest velocity in direction i in this ParticleHandler.

Definition at line 316 of file ParticleHandler.cc.

References BaseHandler< BaseParticle >::getNumberOfObjects(), logger, BaseHandler< BaseParticle >::objects_, and WARN.

317 {
318  if (getNumberOfObjects() == 0)
319  {
320  logger(WARN, "No getLowestVelocityComponentParticle(const int i) since there are no particles");
321  return nullptr;
322  }
323  BaseParticle* p = nullptr;
324  Mdouble min = std::numeric_limits<Mdouble>::max();
325  for (BaseParticle* const pLoop : objects_)
326  {
327  if (pLoop->getVelocity().getComponent(i) < min)
328  {
329  min = pLoop->getVelocity().getComponent(i);
330  p = pLoop;
331  }
332  }
333  return p;
334 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:205
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
std::string ParticleHandler::getName ( ) const
virtual

Returns the name of the handler, namely the string "ParticleHandler".

Returns
The string "ParticleHandler".

Implements BaseHandler< BaseParticle >.

Definition at line 552 of file ParticleHandler.cc.

553 {
554  return "ParticleHandler";
555 }
BaseParticle * ParticleHandler::getSmallestParticle ( ) const

Gets a pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler.

Returns
A pointer to the to the smallest BaseParticle (by interactionRadius) in this ParticleHandler.

Definition at line 215 of file ParticleHandler.cc.

References logger, smallestParticle_, and WARN.

Referenced by MercuryBase::getHGridTargetMinInteractionRadius(), HGridOptimiser::initialise(), and DPMBase::writeFstatHeader().

216 {
217  if (smallestParticle_ == nullptr)
218  {
219  logger(WARN, "No particles to return in getSmallestParticle()");
220  }
221  return smallestParticle_;
222 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
BaseParticle * smallestParticle_
A pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler.
ParticleHandler ParticleHandler::operator= ( const ParticleHandler rhs)

Assignment operator.

Parameters
[in]rhsThe ParticleHandler on the right hand side of the assignment.

This is not a copy assignment operator! It copies the DPMBase and all BaseParticle, and sets the other variables to 0. After that, it computes the smallest and largest particle in this handler.

Definition at line 74 of file ParticleHandler.cc.

References clear(), computeLargestParticle(), computeSmallestParticle(), BaseHandler< BaseParticle >::copyContentsFromOtherHandler(), DEBUG, largestParticle_, logger, BaseHandler< BaseParticle >::objects_, and smallestParticle_.

75 {
76  if (this != &rhs)
77  {
78  clear();
79  largestParticle_ = nullptr;
80  smallestParticle_ = nullptr;
82  if (objects_.size() != 0)
83  {
86  }
87  }
88  logger(DEBUG, "ParticleHandler::operator = (const ParticleHandler& rhs) finished");
89  return *this;
90 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
BaseParticle * smallestParticle_
A pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler.
void clear()
Empties the whole ParticleHandler by removing all BaseParticle.
BaseParticle * largestParticle_
A pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:205
void computeSmallestParticle()
Computes the smallest particle (by interaction radius) and sets it in smallestParticle_.
void computeLargestParticle()
Computes the largest particle (by interaction radius) and sets it in largestParticle_.
void copyContentsFromOtherHandler(const BaseHandler< BaseParticle > &BH)
Function that copies the contents (vector of pointers, maxObject_, nextId_, DPMBase_) from one handle...
void ParticleHandler::readObject ( std::istream &  is)
virtual

Reads BaseParticle into the ParticleHandler from restart data.

Parameters
[in]isThe input stream from which the information is read.
Todo:
make sure setting the id doesn't break the id setter :)
Todo:
{Remove for final version}

Implements BaseHandler< BaseParticle >.

Definition at line 399 of file ParticleHandler.cc.

References BaseHandler< BaseParticle >::copyAndAddObject(), ERROR, BaseObject::getId(), BaseHandler< BaseParticle >::getLastObject(), logger, BaseParticle::oldRead(), readOldObject(), and BaseObject::setId().

Referenced by DPMBase::read().

400 {
401  std::string type;
402  is >> type;
403  if (type == "BaseParticle")
404  {
405  BaseParticle baseParticle;
406  is >> baseParticle;
407  copyAndAddObject(baseParticle);
408  getLastObject()->setId(baseParticle.getId()); //to ensure old id
410  }
412  else if (type == "BP")
413  {
414  BaseParticle baseParticle;
415  baseParticle.oldRead(is);
416  copyAndAddObject(baseParticle);
417  getLastObject()->setId(baseParticle.getId()); //to ensure old id
418  }
419  else if (isdigit(type[0]))
420  {
421  readOldObject(type, is);
422  }
423  else
424  {
425  logger(ERROR, "Particle type % not understood in restart file. Particle has not been read.", type);
426  return;
427  }
428 }
unsigned int getId() const
Returns the unique identifier of any particular object.
Definition: BaseObject.cc:113
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
void setId(const unsigned int id)
Assigns a unique identifier to each object in the handler (container) which remains constant even aft...
Definition: BaseObject.cc:98
U * copyAndAddObject(const U &O)
Creates a copy of a Object and adds it to the BaseHandler.
void readOldObject(std::string type, std::istream &is)
Reads BaseParticle into the ParticleHandler from old-style restart data.
virtual MERCURY_DEPRECATED void oldRead(std::istream &is)
deprecated version of the read function.
BaseParticle * getLastObject()
Gets a pointer to the last Object in this BaseHandler.
void ParticleHandler::readOldObject ( std::string  type,
std::istream &  is 
)

Reads BaseParticle into the ParticleHandler from old-style restart data.

Parameters
[in]typeThe first value of the position.
[in]isThe input stream from which the information is read.

The old objects did not have their type in the beginning of the line. Instead, the first string of the file was the position in x-direction. Since we already read the first string of the file, we need to give it to this function and convert it to the position in x-direction. The rest of the stream is then read in the usual way.

Definition at line 439 of file ParticleHandler.cc.

References BaseHandler< BaseParticle >::copyAndAddObject(), helpers::getLineFromStringStream(), logger, VERBOSE, Vec3D::X, Vec3D::Y, and Vec3D::Z.

Referenced by readObject().

440 {
441  //read in next line
442  std::stringstream line(std::stringstream::in | std::stringstream::out);
444  logger(VERBOSE, line.str());
445  //std::cout << line.str() << std::endl;
446 
447  BaseParticle particle;
448 
449  //Declare all properties of the particle
450  unsigned int indSpecies;
451  Mdouble radius, inverseMass, inverseInertia;
452  Vec3D position, velocity, orientation, angularVelocity;
453 
454  //Read all values
455  position.X = atof(type.c_str());
456 
457  line >> position.Y >> position.Z >> velocity >> radius >> orientation >> angularVelocity >> inverseMass >> inverseInertia >> indSpecies;
458 
459  //Put the values in the particle
460  particle.setIndSpecies(indSpecies);
461  particle.setPosition(position);
462  particle.setVelocity(velocity);
463  particle.setRadius(radius);
464  particle.setOrientation(orientation);
465  particle.setAngularVelocity(angularVelocity);
466  if (inverseMass == 0.0)
467  particle.fixParticle();
468  else
469  {
470  particle.setInertia(1./inverseInertia);
471  }
472 
473  //Put the particle in the handler
474  copyAndAddObject(particle);
475 }
Mdouble X
the vector components
Definition: Vector.h:52
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
U * copyAndAddObject(const U &O)
Creates a copy of a Object and adds it to the BaseHandler.
void getLineFromStringStream(std::istream &in, std::stringstream &out)
Reads a line from one stringstream into another, and prepares the latter for reading in...
Definition: Helpers.cc:389
Mdouble Y
Definition: Vector.h:52
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
Mdouble Z
Definition: Vector.h:52
void ParticleHandler::removeLastObject ( )

Removes the last BaseParticle from the ParticleHandler.

Function that removes the last object from this ParticleHandler. It also removes the particle from the HGrid.

Definition at line 164 of file ParticleHandler.cc.

References BaseHandler< BaseParticle >::getDPMBase(), BaseHandler< BaseParticle >::getLastObject(), DPMBase::hGridRemoveParticle(), and BaseHandler< T >::removeLastObject().

Referenced by DPMBase::readNextDataFile().

165 {
166 #ifdef CONTACT_LIST_HGRID
167  getDPMBase()->getPossibleContactList().remove_ParticlePosibleContacts(getLastObject());
168 #endif
171 }
void removeLastObject()
Removes the last Object from the BaseHandler.
Definition: BaseHandler.h:345
virtual void hGridRemoveParticle(BaseParticle *obj UNUSED)
no implementation but can be overidden in its derived classes.
Definition: DPMBase.cc:640
BaseParticle * getLastObject()
Gets a pointer to the last Object in this BaseHandler.
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
void ParticleHandler::removeObject ( unsigned const int  id)
virtual

Removes a BaseParticle from the ParticleHandler.

Parameters
[in]idThe index of which BaseParticle has to be removed from this ParticleHandler.

The BaseParticle at position id is removed by moving the last BaseParticle in the vector to the position of id. It also removes the BaseParticle from the HGrid.

Reimplemented from BaseHandler< BaseParticle >.

Definition at line 151 of file ParticleHandler.cc.

References BaseHandler< BaseParticle >::getDPMBase(), BaseHandler< BaseParticle >::getObject(), DPMBase::hGridRemoveParticle(), and BaseHandler< T >::removeObject().

Referenced by DeletionBoundary::checkBoundaryAfterParticleMoved(), CircularPeriodicBoundary::checkBoundaryAfterParticleMoved(), Chute::cleanChute(), ChuteBottom::makeRoughBottom(), and DPMBase::removeDuplicatePeriodicParticles().

152 {
153 #ifdef CONTACT_LIST_HGRID
154  getDPMBase()->getPossibleContactList().remove_ParticlePosibleContacts(getObject(id));
155 #endif
158 }
virtual void removeObject(unsigned const int id)
Removes an Object from the BaseHandler.
Definition: BaseHandler.h:303
BaseParticle * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
virtual void hGridRemoveParticle(BaseParticle *obj UNUSED)
no implementation but can be overidden in its derived classes.
Definition: DPMBase.cc:640
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
void ParticleHandler::write ( std::ostream &  os) const

Definition at line 477 of file ParticleHandler.cc.

References BaseHandler< BaseParticle >::getNumberOfObjects().

Referenced by DPMBase::write().

478 {
479  os << "Particles " << getNumberOfObjects() << std::endl;
480  for (BaseParticle* it : *this)
481  os << (*it) << std::endl;
482 }
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.

Member Data Documentation

BaseParticle* ParticleHandler::largestParticle_
private

A pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.

Todo:
TW: note that checkExtrema gets called if a particle gets created and its Species and Radius gets set, even if it's not yet included in the particleHandler! This is necessary to check a not included particle for overlaps before inserting it into the handler. Not sure if this is a sensible structure; to be discussed.

Definition at line 180 of file ParticleHandler.h.

Referenced by checkExtrema(), checkExtremaOnDelete(), clear(), computeLargestParticle(), getLargestParticle(), operator=(), ParticleHandler(), and ~ParticleHandler().

BaseParticle* ParticleHandler::smallestParticle_
private

A pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler.

Definition at line 185 of file ParticleHandler.h.

Referenced by checkExtrema(), checkExtremaOnDelete(), clear(), computeSmallestParticle(), getSmallestParticle(), operator=(), ParticleHandler(), and ~ParticleHandler().


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