MercuryDPM  Alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BaseHandler< T > Class Template Referenceabstract

Container to store the pointers to all objects that one creates in a simulation. More...

#include <BaseHandler.h>

Public Member Functions

 BaseHandler ()
 Default BaseHandler constructor, it creates an empty BaseHandler and assigns DPMBase_ to a null pointer. More...
 
 BaseHandler (const BaseHandler< T > &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< T > &BH)
 Function that copies the contents (vector of pointers, maxObject_, nextId_, DPMBase_) from one handler (container) to the other. More...
 
template<typename U >
std::enable_if
<!std::is_pointer< U >::value,
U * >::type 
copyAndAddObject (const U &object)
 Creates a copy of a Object and adds it to the BaseHandler. More...
 
template<typename U >
std::enable_if
< std::is_pointer< U >::value,
U >::type 
copyAndAddObject (const U object)
 Creates a copy of a Object and adds it to the BaseHandler. More...
 
virtual void addObject (T *object)
 Adds a new Object to the BaseHandler. More...
 
virtual void removeObject (unsigned const int id)
 Removes an Object from 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...
 
virtual void readObject (std::istream &is)=0
 Reads Object into the BaseHandler from restart data. More...
 
void read (std::istream &is)
 Reads all objects from restart data. More...
 
T * getObjectById (const unsigned int id)
 Gets a pointer to the Object at the specified index in the BaseHandler. More...
 
T * getObject (const unsigned int id)
 Gets a pointer to the Object at the specified index in the BaseHandler. More...
 
const T * getObject (const unsigned int id) const
 Gets a constant pointer to the Object at the specified index in the BaseHandler. More...
 
T * getLastObject ()
 Gets a pointer to the last Object in this BaseHandler. More...
 
const T * getLastObject () 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< T * >
::const_iterator 
begin () const
 Gets the begin of the const_iterator over all Object in this BaseHandler. More...
 
const std::vector< T * >::iterator begin ()
 Gets the begin of the iterator over all BaseBoundary in this BaseHandler. More...
 
const std::vector< T * >
::const_iterator 
end () const
 Gets the end of the const_iterator over all BaseBoundary in this BaseHandler. More...
 
const std::vector< T * >::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...
 
void setId (T *object, unsigned int id)
 This function sets the id and ensures that nextId is a bigger value than id. 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...
 
virtual std::string getName () const =0
 Gets the name of this handler. More...
 
virtual void writeVTK ()
 Over written in WallHandler and ParticleHandler. More...
 

Protected Attributes

std::vector< T * > objects_
 The actual list of Object pointers. More...
 

Private Attributes

unsigned int maxObjects_
 An integer to keep track of the largest number of objects ever stored in this BaseHandler. More...
 
unsigned int nextId_
 identifier for next object created More...
 
DPMBaseDPMBase_
 A pointer back to the DPMBase class. More...
 

Detailed Description

template<typename T>
class BaseHandler< T >

Container to store the pointers to all objects that one creates in a simulation.

The BaseHandler allows one to create a container to store all pointer objects of a templated type T It is implemented by a (protected) vector of pointers to objects of type T. Once the container is created, the BaseHandler also provides the provision to manipulate the pointers i.e. by accessing, adding, deleting and few more operations by using its member methods.

Definition at line 51 of file BaseHandler.h.

Constructor & Destructor Documentation

template<typename T >
BaseHandler< T >::BaseHandler ( )

Default BaseHandler constructor, it creates an empty BaseHandler and assigns DPMBase_ to a null pointer.

Definition at line 251 of file BaseHandler.h.

References DEBUG, and logger.

252 {
253  DPMBase_ = nullptr;
254  clear();
255  logger(DEBUG, "Basehandler<T>::BaseHandler() finished");
256 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
DPMBase * DPMBase_
A pointer back to the DPMBase class.
Definition: BaseHandler.h:244
void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
Definition: BaseHandler.h:392
template<typename T>
BaseHandler< T >::BaseHandler ( const BaseHandler< T > &  BH)

Constructor that copies the objects of the given handler into itself and sets other variables to 0/nullptr.

Parameters
[in]BHA reference to the BaseHandler that has to be copied.

This is not a copy constructor! It only copies the vector objects_ from the given handler, and sets all other variables to 0/nullptr.

Todo:
Should max objects be set to the number of objects after this constructor? Maybe in copyContentsFromOtherHandler?

Definition at line 266 of file BaseHandler.h.

References DEBUG, and logger.

267 {
268  DPMBase_ = nullptr;
269  clear();
271  logger(DEBUG,"BaseHandler<T>::BaseHandler(const BaseHandler &BH) finished");
272 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
DPMBase * DPMBase_
A pointer back to the DPMBase class.
Definition: BaseHandler.h:244
void copyContentsFromOtherHandler(const BaseHandler< T > &BH)
Function that copies the contents (vector of pointers, maxObject_, nextId_, DPMBase_) from one handle...
Definition: BaseHandler.h:283
void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
Definition: BaseHandler.h:392
template<typename T >
BaseHandler< T >::~BaseHandler ( )
virtual

Destructor, it destructs the BaseHandler and all Object it contains.

Definition at line 275 of file BaseHandler.h.

References DEBUG, and logger.

276 {
277  clear();
278  logger(DEBUG, "BaseHandler<T>::~BaseHandler() finished");
279 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
Definition: BaseHandler.h:392

Member Function Documentation

template<typename T>
void BaseHandler< T >::addObject ( T *  object)
virtual

Adds a new Object to the BaseHandler.

Parameters
[in]objectA pointer to the object that must be added.

Reimplemented in WallHandler, ParticleHandler, BoundaryHandler, InteractionHandler, and SpeciesHandler.

Definition at line 313 of file BaseHandler.h.

Referenced by SpeciesHandler::addObject(), InteractionHandler::addObject(), BoundaryHandler::addObject(), ParticleHandler::addObject(), and WallHandler::addObject().

314 {
315  objects_.push_back(object);
316  //Set the index of the particle
317  getLastObject()->setIndex(getNumberOfObjects() - 1);
318  //set the non changing particle identifier
319  getLastObject()->setId(nextId_);
320  //Update Id for next particle
321  nextId_++;
322  //Update the maximum number of Particles
325 }
unsigned int nextId_
identifier for next object created
Definition: BaseHandler.h:236
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:216
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
Definition: BaseHandler.h:487
T * getLastObject()
Gets a pointer to the last Object in this BaseHandler.
Definition: BaseHandler.h:473
unsigned int maxObjects_
An integer to keep track of the largest number of objects ever stored in this BaseHandler.
Definition: BaseHandler.h:231
template<typename T >
const std::vector< T * >::const_iterator BaseHandler< T >::begin ( ) const

Gets the begin of the const_iterator over all Object in this BaseHandler.

Returns
A const_iterator pointing to the first Object.

Definition at line 508 of file BaseHandler.h.

Referenced by DPMBase::broadPhase(), DPMBase::checkInteractionWithBoundaries(), HGridOptimiser::initialise(), DPMBase::integrateAfterForceComputation(), and DPMBase::integrateBeforeForceComputation().

509 {
510  return objects_.begin();
511 }
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:216
template<typename T >
const std::vector< T * >::iterator BaseHandler< T >::begin ( )

Gets the begin of the iterator over all BaseBoundary in this BaseHandler.

Returns
A iterator pointing to the first Object.

Definition at line 515 of file BaseHandler.h.

516 {
517  return objects_.begin();
518 }
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:216
template<typename T >
void BaseHandler< T >::clear ( )

Empties the whole BaseHandler by removing all Objects and setting all other variables to 0.

Delete all objects stored in objects_ and set the maximum number of objects that have been in this container to 0, and set the Id of the next object that will be added to 0.

Definition at line 392 of file BaseHandler.h.

Referenced by ParticleHandler::clear(), main(), FileReader::read(), DPMBase::read(), DPMBase::readParAndIniFiles(), and ChuteBottom::setupInitialConditions().

393 {
394 
395  for (T* const obj : objects_)
396  {
397  delete obj;
398  }
399  objects_.clear();
400 
401  nextId_ = 0;
402  maxObjects_ = 0;
403 }
unsigned int nextId_
identifier for next object created
Definition: BaseHandler.h:236
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:216
unsigned int maxObjects_
An integer to keep track of the largest number of objects ever stored in this BaseHandler.
Definition: BaseHandler.h:231
template<typename T >
template<typename U >
std::enable_if<!std::is_pointer< U >::value, U * >::type BaseHandler< T >::copyAndAddObject ( const U &  object)

Creates a copy of a Object and adds it to the BaseHandler.

Parameters
[in]objectA reference to the BaseHandler of which the objects have to be copied.

Definition at line 295 of file BaseHandler.h.

Referenced by ChuteWithHopper::addHopper(), MaserBoundary::addParticleToMaser(), MaserBoundary::checkBoundaryAfterParticleMoved(), InsertionBoundary::checkBoundaryBeforeTimeStep(), Chute::createBottom(), FileReader::read(), DPMBase::readNextDataFile(), DPMBase::readParAndIniFiles(), ChuteBottom::setupInitialConditions(), Chute::setupInitialConditions(), ChuteWithHopper::setupInitialConditions(), and Chute::setupSideWalls().

296 {
297  U* oCopy = object.copy();
298  addObject(oCopy);
299  return oCopy;
300 }
virtual void addObject(T *object)
Adds a new Object to the BaseHandler.
Definition: BaseHandler.h:313
template<typename T >
template<typename U >
std::enable_if< std::is_pointer< U >::value, U >::type BaseHandler< T >::copyAndAddObject ( const U  object)

Creates a copy of a Object and adds it to the BaseHandler.

Parameters
[in]objectA reference to the Object that has to be copied.

Definition at line 306 of file BaseHandler.h.

307 {
308  return copyAndAddObject(*object);
309 }
std::enable_if<!std::is_pointer< U >::value, U * >::type copyAndAddObject(const U &object)
Creates a copy of a Object and adds it to the BaseHandler.
Definition: BaseHandler.h:295
template<typename T>
void BaseHandler< T >::copyContentsFromOtherHandler ( const BaseHandler< T > &  BH)

Function that copies the contents (vector of pointers, maxObject_, nextId_, DPMBase_) from one handler (container) to the other.

Parameters
[in]BHA reference to the BaseHandler of which the objects have to be copied.

Definition at line 283 of file BaseHandler.h.

References BaseHandler< T >::objects_.

284 {
285  for (const T* const obj : BH.objects_)
286  {
287  addObject(obj->copy());
288  }
289 }
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:216
virtual void addObject(T *object)
Adds a new Object to the BaseHandler.
Definition: BaseHandler.h:313
template<typename T >
const std::vector< T * >::const_iterator BaseHandler< T >::end ( ) const

Gets the end of the const_iterator over all BaseBoundary in this BaseHandler.

Returns
A const_iterator pointing to the last BaseBoundary.

Definition at line 522 of file BaseHandler.h.

Referenced by DPMBase::checkInteractionWithBoundaries(), HGridOptimiser::initialise(), DPMBase::integrateAfterForceComputation(), and DPMBase::integrateBeforeForceComputation().

523 {
524  return objects_.end();
525 }
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:216
template<typename T >
const std::vector< T * >::iterator BaseHandler< T >::end ( )

Gets the end of the iterator over all BaseBoundary in this BaseHandler.

Returns
An iterator pointing to the last BaseBoundary.

Definition at line 529 of file BaseHandler.h.

530 {
531  return objects_.end();
532 }
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:216
template<typename T >
DPMBase * BaseHandler< T >::getDPMBase ( )

Gets the problem that is solved using this handler.

Returns
A pointer to the DPMBase (problem descriptor) that is using this handler.

Definition at line 543 of file BaseHandler.h.

References logger.

Referenced by MaserBoundary::addParticleToMaser(), SlidingFrictionInteraction::computeFrictionForce(), FrictionInteraction::computeFrictionForce(), MindlinInteraction::computeFrictionForce(), MindlinRollingTorsionInteraction::computeFrictionForce(), SinterInteraction::computeNormalForce(), HertzianSinterInteraction::computeSinterForce(), InfiniteWall::createVTK(), BaseInteraction::gatherContactStatistics(), LeesEdwardsBoundary::getCurrentShift(), LeesEdwardsBoundary::getCurrentVelocity(), BaseParticle::getParticleDimensions(), ParticleSpecies::getVolumeFromRadius(), BaseParticle::integrateBeforeForceComputation(), WallHandler::operator=(), ParticleHandler::ParticleHandler(), LiquidMigrationWilletInteraction::rupture(), ParticleSpecies::setDensity(), BaseParticle::setIndSpecies(), BaseWall::setSpecies(), BaseParticle::setSpecies(), ShearBoxBoundary::shiftHorizontalPosition(), LeesEdwardsBoundary::shiftVerticalPosition(), SpeciesHandler::SpeciesHandler(), WallHandler::WallHandler(), LeesEdwardsBoundary::write(), and AxisymmetricIntersectionOfWalls::writeVTK().

544 {
545  logger.assert(DPMBase_!= nullptr,"[BaseHandler::getDPMBase()] in Object* %: pointer to DPMBase class is not set.", getName());
546  return DPMBase_;
547 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
virtual std::string getName() const =0
Gets the name of this handler.
DPMBase * DPMBase_
A pointer back to the DPMBase class.
Definition: BaseHandler.h:244
template<typename T >
DPMBase * BaseHandler< T >::getDPMBase ( ) const

Gets the problem that is solved using this handler and does not change the class.

Returns
A pointer to the DPMBase (problem descriptor) that is using this handler.

Definition at line 551 of file BaseHandler.h.

References logger.

552 {
553  logger.assert(DPMBase_!= nullptr, "[BaseHandler::getDPMBase() const] in Object* %: pointer to DPMBase class is not set.", getName());
554  return DPMBase_;
555 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
virtual std::string getName() const =0
Gets the name of this handler.
DPMBase * DPMBase_
A pointer back to the DPMBase class.
Definition: BaseHandler.h:244
template<typename T >
T * BaseHandler< T >::getLastObject ( )

Gets a pointer to the last Object in this BaseHandler.

Returns
A pointer to the last Object in the BaseHandler.

Definition at line 473 of file BaseHandler.h.

Referenced by LeesEdwardsBoundary::createVerticalPeriodicParticles(), ShearBoxBoundary::createVerticalPeriodicParticles(), DPMBase::readNextDataFile(), and ChuteWithHopper::setupInitialConditions().

474 {
475  return objects_.back();
476 }
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:216
template<typename T >
const T * BaseHandler< T >::getLastObject ( ) const

Gets a constant pointer to the last Object in this BaseHandler.

Returns
A constant pointer to the last Object in the BaseHandler.

Definition at line 480 of file BaseHandler.h.

481 {
482  return objects_.back();
483 }
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:216
template<typename T>
virtual std::string BaseHandler< T >::getName ( ) const
pure virtual

Gets the name of this handler.

Returns
A string that contains the name of the handler.

Implemented in ParticleHandler, InteractionHandler, SpeciesHandler, WallHandler, and BoundaryHandler.

template<typename T >
T * BaseHandler< T >::getObject ( const unsigned int  index)

Gets a pointer to the Object at the specified index in the BaseHandler.

Parameters
[in]indexthe index of the requested Object.
Returns
A pointer to the requested Object.

Definition at line 451 of file BaseHandler.h.

References logger.

Referenced by ChuteWithHopper::addHopper(), DPMBase::checkAndDuplicatePeriodicParticles(), Chute::cleanChute(), Chute::createBottom(), ChuteBottom::makeRoughBottom(), FileReader::read(), DPMBase::readNextDataFile(), WallHandler::readObject(), DPMBase::readParAndIniFiles(), DPMBase::removeDuplicatePeriodicParticles(), DPMBase::setFixedParticles(), BaseWall::setHandler(), BaseParticle::setHandler(), BaseWall::setIndSpecies(), BaseParticle::setIndSpecies(), ChuteBottom::setupInitialConditions(), Chute::setupInitialConditions(), ChuteWithHopper::setupInitialConditions(), Chute::setupSideWalls(), and DPMBase::write().

452 {
453  logger.assert(index < getNumberOfObjects(),
454  "[%::getObject()] Object couldn't be found because index (%) is higher than number of objects (%).",
455  getName(), index, getNumberOfObjects());
456 
457  return objects_[index];
458 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
virtual std::string getName() const =0
Gets the name of this handler.
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:216
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
Definition: BaseHandler.h:487
template<typename T >
const T * BaseHandler< T >::getObject ( const unsigned int  index) const

Gets a constant pointer to the Object at the specified index in the BaseHandler.

Parameters
[in]indexthe index of the requested Object.
Returns
A constant pointer to the requested Object.

Definition at line 463 of file BaseHandler.h.

References logger.

464 {
465  logger.assert(index < getNumberOfObjects(),
466  "[%::getObject() const] Object couldn't be found because index (%) is higher than number of objects (%).",
467  getName(), index, getNumberOfObjects());
468  return objects_[index];
469 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
virtual std::string getName() const =0
Gets the name of this handler.
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:216
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
Definition: BaseHandler.h:487
template<typename T >
T * BaseHandler< T >::getObjectById ( const unsigned int  id)

Gets a pointer to the Object at the specified index in the BaseHandler.

Parameters
[in]idThe id of the requested Object.
Returns
A pointer to the Object with the correct Id. Gets an object with the identity id. Please note that the object with this identity does not have to be at place id in the vector of Object objects_.

Definition at line 429 of file BaseHandler.h.

References ERROR, and logger.

Referenced by FileReader::read(), and InteractionHandler::readObject().

430 {
431  // Usually, the id and the index into the backing storage matches
432  // So check this position first!
433  // dducks: Can't we guarantee more? That should speed up searches.
434  if (id < objects_.size() && objects_[id]->getId() == id)
435  {
436  return objects_[id]; //There is a hit, return early
437  }
438 
439  for (T* obj : objects_ ) //Search for the correct id, since it wasn't where
440  { // we expected it. Just use a linear search..
441  if (obj->getId() == id) //Found it, so return!
442  return obj;
443  }
444  logger(ERROR, "[BaseHandler::getObjectById()] in Object* %: Object with ID % could not be found.", getName(), id);
445  return nullptr;
446 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
virtual std::string getName() const =0
Gets the name of this handler.
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:216
template<typename T >
unsigned int BaseHandler< T >::getStorageCapacity ( ) const

Gets the storage capacity of this BaseHandler.

Returns
The storage capacity of this BaseHandler.

Definition at line 494 of file BaseHandler.h.

495 {
496  return objects_.capacity();
497 }
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:216
template<typename T >
void BaseHandler< T >::read ( std::istream &  is)

Reads all objects from restart data.

Parameters
[in]isThe input stream from which the information is read.

Definition at line 407 of file BaseHandler.h.

References helpers::getLineFromStringStream(), logger, and VERBOSE.

Referenced by DPMBase::read(), and DPMBase::readOld().

408 {
409  clear();
410  unsigned int N;
411  std::string dummy;
412  is >> dummy;
413  std::stringstream line(std::stringstream::in | std::stringstream::out);
415  line >> N;
416  logger(VERBOSE, "In %::read(is): reading in % objects.", getName(), N);
418  for (unsigned int i = 0; i < N; i++)
419  {
420  readObject(is);
421  }
422 }
virtual void readObject(std::istream &is)=0
Reads Object into the BaseHandler from restart data.
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
void setStorageCapacity(const unsigned int N)
Sets the storage capacity of this BaseHandler.
Definition: BaseHandler.h:501
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:396
virtual std::string getName() const =0
Gets the name of this handler.
void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
Definition: BaseHandler.h:392
template<typename T>
virtual void BaseHandler< T >::readObject ( std::istream &  is)
pure virtual

Reads Object into the BaseHandler from restart data.

Parameters
[in]isThe input stream from which the information is read.

Implemented in ParticleHandler, WallHandler, BoundaryHandler, InteractionHandler, and SpeciesHandler.

template<typename T >
void BaseHandler< T >::removeLastObject ( )

Removes the last Object from the BaseHandler.

Definition at line 375 of file BaseHandler.h.

References logger, and WARN.

Referenced by ParticleHandler::removeLastObject().

376 {
377  if (getNumberOfObjects() == 0)
378  {
379  logger(WARN, "In: void %::removeLastObject, no Object exists in this BaseHandler.", getName());
380  return;
381  }
382  T* const object = objects_.back();
383  //Remove the (now double) reference to that last Object
384  objects_.pop_back();
385  //Physically removes Object
386  delete object;
387 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
virtual std::string getName() const =0
Gets the name of this handler.
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:216
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
Definition: BaseHandler.h:487
template<typename T>
void BaseHandler< T >::removeObject ( unsigned const int  id)
virtual

Removes an Object from the BaseHandler.

This methods removes a particle. This methods invalidates ANY iterators to particles in this container. This method may shuffle the order of objects in this container.

Parameters
[in]indexAn unsigned integer that gives the id of the Object that has to be removed.

Reimplemented in ParticleHandler, and SpeciesHandler.

Definition at line 333 of file BaseHandler.h.

References logger.

Referenced by BaseInteraction::removeFromHandler(), SpeciesHandler::removeObject(), ParticleHandler::removeObject(), and InteractionHandler::removeObjectKeepingPeriodics().

334 {
335  logger.assert_always(index < getNumberOfObjects(),
336  "In: void %::removeOject(const unsigned int index) const, "
337  "no object exists with index %, number of objects is %",
338  getName(), index, getNumberOfObjects());
339 
340  //Okay, this function deletes the particle. Now, the problem is that
341  //particles store their position in the handler (@dducks: do they?)
342  //which means that we would absolutely destroy performance if we took
343  //something out in the middle. Now, what we'll do is swap our particle
344  //with the last one (in case it already is, it is invariant); then
345  //remove the last one.
346  //So, we want the last index.
347  const unsigned int lastIndex = objects_.size() - 1;
348 
349  //So, step one, retrieve the pointer
350  T* const objectToDelete = objects_[index];
351 
352  if (index != lastIndex) //Are we not the last object?
353  {
354  //well.. let's swap.
355  T* const objectToMove = objects_[lastIndex];
356 
357  objects_[index] = objectToMove; //place it back
358  objects_[lastIndex] = objectToDelete; //Just to make sure.
359 
360  //and notify it of the change.
361  objects_[index]->moveInHandler(index);
362  //Even though we are going to delete this particle,
363  //we still need to keep it consistent.
364  objects_[lastIndex]->moveInHandler(lastIndex);
365  }
366 
367  //And clear it from the backing container.
368  objects_.pop_back();
369  //And _NOW_ we delete it.
370  delete objectToDelete;
371 
372 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
virtual std::string getName() const =0
Gets the name of this handler.
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:216
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
Definition: BaseHandler.h:487
template<typename T >
void BaseHandler< T >::setDPMBase ( DPMBase DPMBase)

Sets the problem that is solved using this handler.

Parameters
[in]DPMBaseA pointer to a DPMBase, which is the superclass for all problem descriptions.

Definition at line 536 of file BaseHandler.h.

Referenced by DPMBase::constructor(), and DPMBase::DPMBase().

537 {
538  DPMBase_ = DPMBase;
539 }
DPMBase * DPMBase_
A pointer back to the DPMBase class.
Definition: BaseHandler.h:244
template<typename T>
void BaseHandler< T >::setId ( T *  object,
unsigned int  id 
)
inline

This function sets the id and ensures that nextId is a bigger value than id.

Todo:
we should use this function only to set the id of particles, not BaseObject::setId; however, to block BaseObject::setId, I need to make this function a friend of BaseObject, and I don't know how to do that.

Definition at line 189 of file BaseHandler.h.

190  {
191  object->setId(id);
192  if (nextId_<=id)
193  {
194  nextId_ = id+1;
195  }
196  }
unsigned int nextId_
identifier for next object created
Definition: BaseHandler.h:236
template<typename T >
void BaseHandler< T >::setStorageCapacity ( const unsigned int  N)

Sets the storage capacity of this BaseHandler.

Parameters
[in]NThe storage capacity the BaseHandler will have

Definition at line 501 of file BaseHandler.h.

Referenced by DPMBase::constructor(), ChuteBottom::makeRoughBottom(), FileReader::read(), DPMBase::read(), and ChuteBottom::setupInitialConditions().

502 {
503  objects_.reserve(N);
504 }
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:216
template<typename T>
virtual void BaseHandler< T >::writeVTK ( )
inlinevirtual

Over written in WallHandler and ParticleHandler.

Definition at line 216 of file BaseHandler.h.

216 {};

Member Data Documentation

template<typename T>
DPMBase* BaseHandler< T >::DPMBase_
private

A pointer back to the DPMBase class.

Please note that this pointer back to the DPMBase class is a "shared" pointer and should not be deallocated by this class.

Definition at line 244 of file BaseHandler.h.

template<typename T>
unsigned int BaseHandler< T >::maxObjects_
private

An integer to keep track of the largest number of objects ever stored in this BaseHandler.

Definition at line 231 of file BaseHandler.h.

template<typename T>
unsigned int BaseHandler< T >::nextId_
private

identifier for next object created

Definition at line 236 of file BaseHandler.h.

Referenced by BaseHandler< BaseBoundary >::setId().

template<typename T>
std::vector<T*> BaseHandler< T >::objects_
protected

The actual list of Object pointers.

The list of Object pointers. This handler is responsible for the memory-deallocation of these objects.

Definition at line 216 of file BaseHandler.h.

Referenced by BaseHandler< T >::copyContentsFromOtherHandler().


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