MercuryDPM  Trunk
 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...
 
template<typename U >
std::enable_if
<!std::is_pointer< U >::value,
U * >::type 
copyAndAddGhostObject (const U &object)
 Creates a copy of a Object and adds it to the BaseHandler. This is one locally for inserting mpi particles, they avoid the global check if the particle can actually be inserted, because the mpi domain already knows that is the case. More...
 
template<typename U >
std::enable_if
< std::is_pointer< U >::value,
U >::type 
copyAndAddGhostObject (const U object)
 Creates a copy of a Object and adds it to the BaseHandler. This is one locally for inserting mpi particles, they avoid the global check if the particle can actually be inserted, because the mpi domain already knows that is the case. More...
 
virtual void addExistingObject (T *O)
 Adds an existing object to the BaseHandler without changing the id of the object. More...
 
virtual void addObject (T *object)
 Adds a new Object to the BaseHandler. More...
 
virtual void addGhostObject (T *O)
 Adds a new Object to the BaseHandler. called by the to avoid increasing the id. More...
 
void removeIf (const std::function< bool(T *)> cond)
 
virtual void removeObject (unsigned const int index)
 Removes an Object from the BaseHandler. More...
 
void removeLastObject ()
 Removes the last Object from the BaseHandler. More...
 
virtual void clear ()
 Empties the whole BaseHandler by removing all Objects and setting all other variables to 0. More...
 
virtual void readAndAddObject (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...
 
std::vector< T * > getObjectsById (const unsigned int id)
 Gets a vector of pointers to the objects with the specific id. 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...
 
virtual unsigned int getNumberOfObjects () const
 Gets the number of real Object in this BaseHandler. (i.e. no mpi or periodic particles) More...
 
unsigned int getSize () const
 Gets the size of the particleHandler (including mpi and periodic particles) 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...
 
void resize (const unsigned int N, const T &obj)
 Resizes the container to contain N elements. 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...
 
void increaseId ()
 
unsigned int getNextId ()
 
void setNextId (unsigned int id)
 
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 () const
 now empty function for writing VTK files. More...
 
unsigned getNextGroupId ()
 Should be called each time you assign a groupId. Returns the value of nextGroupId_ and increases nextGroupId_ by one. 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...
 
unsigned nextGroupId_ = 1
 value of the next BaseObject::groupId_. Value increased by one each time a groupId is assigned. Default group is 0 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 50 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 335 of file BaseHandler.h.

References DEBUG, and logger.

336 {
337  DPMBase_ = nullptr;
338  clear();
339  logger(DEBUG, "BaseHandler<T>::BaseHandler() finished");
340 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
DPMBase * DPMBase_
A pointer back to the DPMBase class.
Definition: BaseHandler.h:328
virtual void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
Definition: BaseHandler.h:528
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 350 of file BaseHandler.h.

References DEBUG, and logger.

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

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

Definition at line 359 of file BaseHandler.h.

References DEBUG, and logger.

360 {
361  clear();
362  logger(DEBUG, "BaseHandler<T>::~BaseHandler() finished");
363 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
virtual void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
Definition: BaseHandler.h:528

Member Function Documentation

template<class T>
void BaseHandler< T >::addExistingObject ( T *  O)
virtual

Adds an existing object to the BaseHandler without changing the id of the object.

Parameters
[in]objectA point to an existing object which already has an id given

Reimplemented in ParticleHandler.

Definition at line 417 of file BaseHandler.h.

Referenced by ParticleHandler::addExistingObject().

418 {
419  objects_.push_back(O);
420  //Set the index of the particle
421  getLastObject()->setIndex(getSize() - 1);
422  //Adjust the nextId_ value
423  if (O->getId() + 1 > nextId_)
424  {
425  nextId_ = O->getId() + 1;
426  }
427 }
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Definition: BaseHandler.h:655
unsigned int nextId_
identifier for next object created
Definition: BaseHandler.h:313
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
T * getLastObject()
Gets a pointer to the last Object in this BaseHandler.
Definition: BaseHandler.h:634
template<class T>
void BaseHandler< T >::addGhostObject ( T *  O)
virtual

Adds a new Object to the BaseHandler. called by the to avoid increasing the id.

Todo:
mx: type the stuff here: keeps the id unique key

Reimplemented in ParticleHandler.

Definition at line 444 of file BaseHandler.h.

Referenced by ParticleHandler::addGhostObject().

445 {
446  objects_.push_back(O);
447  //Set the index of the particle
448  getLastObject()->setIndex(getSize() - 1);
449 }
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Definition: BaseHandler.h:655
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
T * getLastObject()
Gets a pointer to the last Object in this BaseHandler.
Definition: BaseHandler.h:634
template<class 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 CGHandler, DomainHandler, ParticleHandler, PeriodicBoundaryHandler, InteractionHandler, WallHandler, BoundaryHandler, and SpeciesHandler.

Definition at line 431 of file BaseHandler.h.

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

432 {
433  objects_.push_back(object);
434  //Set the index of the particle
435  getLastObject()->setIndex(getSize() - 1);
436  //set the non changing particle identifier
437  getLastObject()->setId(nextId_);
438  //Update Id for next particle
439  nextId_++;
440 }
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Definition: BaseHandler.h:655
unsigned int nextId_
identifier for next object created
Definition: BaseHandler.h:313
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
T * getLastObject()
Gets a pointer to the last Object in this BaseHandler.
Definition: BaseHandler.h:634
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 697 of file BaseHandler.h.

698 {
699  return objects_.begin();
700 }
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
template<typename T >
void BaseHandler< T >::clear ( )
virtual

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.

Reimplemented in ParticleHandler, and SpeciesHandler.

Definition at line 528 of file BaseHandler.h.

Referenced by SpeciesHandler::clear(), ParticleHandler::clear(), CGHandler::evaluateRestartFiles(), FileReader::read(), DPMBase::read(), DPMBase::readNextFStatFile(), and ChuteBottom::setupInitialConditions().

529 {
530 
531  for (T* const obj : objects_)
532  {
533  delete obj;
534  }
535  objects_.clear();
536 
537  nextId_ = 0;
538  maxObjects_ = 0;
539 }
unsigned int nextId_
identifier for next object created
Definition: BaseHandler.h:313
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
unsigned int maxObjects_
An integer to keep track of the largest number of objects ever stored in this BaseHandler.
Definition: BaseHandler.h:308
template<class T >
template<class U >
std::enable_if<!std::is_pointer< U >::value, U * >::type BaseHandler< T >::copyAndAddGhostObject ( const U &  object)

Creates a copy of a Object and adds it to the BaseHandler. This is one locally for inserting mpi particles, they avoid the global check if the particle can actually be inserted, because the mpi domain already knows that is the case.

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

Definition at line 399 of file BaseHandler.h.

400 {
401  U* oCopy = object.copy();
402  addGhostObject(oCopy);
403  return oCopy;
404 }
virtual void addGhostObject(T *O)
Adds a new Object to the BaseHandler. called by the to avoid increasing the id.
Definition: BaseHandler.h:444
template<class T >
template<class U >
std::enable_if< std::is_pointer< U >::value, U >::type BaseHandler< T >::copyAndAddGhostObject ( const U  object)

Creates a copy of a Object and adds it to the BaseHandler. This is one locally for inserting mpi particles, they avoid the global check if the particle can actually be inserted, because the mpi domain already knows that is the case.

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

Definition at line 410 of file BaseHandler.h.

411 {
412  return copyAndAddGhostObject(*object);
413 }
std::enable_if<!std::is_pointer< U >::value, U * >::type copyAndAddGhostObject(const U &object)
Creates a copy of a Object and adds it to the BaseHandler. This is one locally for inserting mpi part...
Definition: BaseHandler.h:399
template<typename T >
template<typename U >
std::enable_if<!std::is_pointer< U >::value, U * >::type BaseHandler< T >::copyAndAddObject ( const U &  object)
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 390 of file BaseHandler.h.

391 {
392  return copyAndAddObject(*object);
393 }
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:379
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 367 of file BaseHandler.h.

References BaseHandler< T >::objects_.

368 {
369  for (const T* const obj : BH.objects_)
370  {
371  addObject(obj->copy());
372  }
373 }
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
virtual void addObject(T *object)
Adds a new Object to the BaseHandler.
Definition: BaseHandler.h:431
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 711 of file BaseHandler.h.

712 {
713  return objects_.end();
714 }
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
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 725 of file BaseHandler.h.

Referenced by SubcriticalMaserBoundaryTEST::activateMaser(), SubcriticalMaserBoundary::activateMaser(), ConstantMassFlowMaserBoundary::activateMaser(), StressStrainControlBoundary::activateStrainRateControl(), BaseWall::addParticlesAtWall(), SubcriticalMaserBoundary::addParticleToMaser(), ConstantMassFlowMaserBoundary::addParticleToMaser(), BaseInteraction::BaseInteraction(), CGHandler::CGHandler(), DeletionBoundary::checkBoundaryAfterParticleMoved(), HeaterBoundary::checkBoundaryAfterParticleMoved(), DropletBoundary::checkBoundaryAfterParticlesMove(), PeriodicBoundary::checkBoundaryAfterParticlesMove(), FrictionInteraction::computeFrictionForce(), MindlinInteraction::computeFrictionForce(), MindlinRollingTorsionInteraction::computeFrictionForce(), SinterInteraction::computeNormalForce(), HertzianSinterInteraction::computeSinterForce(), SlidingFrictionInteraction::computeSlidingSpring(), SlidingFrictionInteraction::computeSlidingSpringSuperQuadric(), StressStrainControlBoundary::computeStrainRate(), copyDataFromMPIParticleToParticle(), SubcriticalMaserBoundaryTEST::copyExtraParticles(), PeriodicBoundary::createGhostParticle(), InfiniteWall::createVTK(), StressStrainControlBoundary::determineLengthAndCentre(), StressStrainControlBoundary::determineStressControlledShearBoundaries(), SubcriticalMaserBoundaryTEST::extendBottom(), Domain::finaliseBoundaryDataTransmission(), BaseInteraction::gatherContactStatistics(), LeesEdwardsBoundary::getCurrentShift(), LeesEdwardsBoundary::getCurrentVelocity(), NurbsWall::getDistanceAndNormal(), Screw::getDistanceAndNormal(), HorizontalBaseScrew::getDistanceAndNormal(), IntersectionOfWalls::getDistanceAndNormal(), BaseWall::getInteractionWith(), BaseParticle::getParticleDimensions(), BaseParticle::getPeriodicComplexity(), ParticleSpecies::getVolumeFromRadius(), BaseParticle::integrateBeforeForceComputation(), WallHandler::operator=(), CGHandler::operator=(), ParticleHandler::ParticleHandler(), Domain::performBoundaryDataTransmission(), Domain::processReceivedBoundaryParticleData(), Domain::processReceivedInteractionData(), SubcriticalMaserBoundary::read(), ConstantMassFlowMaserBoundary::read(), InsertionBoundary::read(), BaseWall::renderWall(), Screw::rotate(), LiquidMigrationWilletInteraction::rupture(), StressStrainControlBoundary::set(), Domain::setBounds(), ParticleSpecies::setDensity(), BaseParticle::setIndSpecies(), BaseParticle::setPeriodicComplexity(), Domain::setRange(), BaseWall::setSpecies(), BaseParticle::setSpecies(), ShearBoxBoundary::shiftHorizontalPosition(), LeesEdwardsBoundary::shiftVerticalPosition(), SpeciesHandler::SpeciesHandler(), StressStrainControlBoundary::updateDomainSize(), Domain::updateParticlePosition(), Domain::updateParticles(), WallHandler::WallHandler(), LeesEdwardsBoundary::write(), BaseInteraction::writeInteraction(), HorizontalBaseScrew::writeVTK(), AxisymmetricIntersectionOfWalls::writeVTK(), ScrewsymmetricIntersectionOfWalls::writeVTK(), IntersectionOfWalls::writeVTK(), and BaseInteraction::~BaseInteraction().

726 {
727  return DPMBase_;
728 }
DPMBase * DPMBase_
A pointer back to the DPMBase class.
Definition: BaseHandler.h:328
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 732 of file BaseHandler.h.

733 {
734  return DPMBase_;
735 }
DPMBase * DPMBase_
A pointer back to the DPMBase class.
Definition: BaseHandler.h:328
template<typename T >
T * BaseHandler< T >::getLastObject ( )
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 641 of file BaseHandler.h.

642 {
643  return objects_.back();
644 }
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
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, DomainHandler, CGHandler, SpeciesHandler, WallHandler, BoundaryHandler, and PeriodicBoundaryHandler.

template<typename T>
unsigned BaseHandler< T >::getNextGroupId ( )
inline

Should be called each time you assign a groupId. Returns the value of nextGroupId_ and increases nextGroupId_ by one.

Definition at line 293 of file BaseHandler.h.

Referenced by FixedClusterInsertionBoundary::checkBoundaryBeforeTimeStep(), and RandomClusterInsertionBoundary::checkBoundaryBeforeTimeStep().

293 { return nextGroupId_++; }
unsigned nextGroupId_
value of the next BaseObject::groupId_. Value increased by one each time a groupId is assigned...
Definition: BaseHandler.h:320
template<typename T>
unsigned int BaseHandler< T >::getNextId ( )
inline

Definition at line 256 of file BaseHandler.h.

Referenced by PeriodicBoundaryHandler::updateMaserParticle(), and PeriodicBoundaryHandler::updateParticleStatus().

257  {
258  return nextId_;
259  }
unsigned int nextId_
identifier for next object created
Definition: BaseHandler.h:313
template<typename T >
unsigned int BaseHandler< T >::getNumberOfObjects ( ) const
virtual

Gets the number of real Object in this BaseHandler. (i.e. no mpi or periodic particles)

Returns
The number of Objects in this BaseHandler.

Reimplemented in ParticleHandler.

Definition at line 648 of file BaseHandler.h.

Referenced by DPMBase::checkSettings(), DPMBase::computeAllForces(), DPMBase::decompose(), CGHandler::evaluateDataFiles(), CGHandler::evaluateRestartFiles(), DPMBase::integrateAfterForceComputation(), DPMBase::integrateBeforeForceComputation(), FileReader::read(), DPMBase::readNextFStatFile(), CGHandler::restart(), Chute::setupInitialConditions(), DPMBase::write(), and InteractionVTKWriter::writeVTK().

649 {
650  return objects_.size();
651 }
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
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 613 of file BaseHandler.h.

References getName(), and logger.

Referenced by ChuteWithHopper::addHopper(), BaseCluster::calculateTimeStep(), DeletionBoundary::checkBoundaryAfterParticlesMove(), FixedClusterInsertionBoundary::checkBoundaryBeforeTimeStep(), RandomClusterInsertionBoundary::checkBoundaryBeforeTimeStep(), Chute::cleanChute(), DPMBase::computeAllForces(), BaseCluster::computeInternalStructure(), copyDataFromMPIParticleToParticle(), Chute::createBottom(), InteractionHandler::createEmptyInteraction(), Chute::createFlowParticle(), CircularPeriodicBoundary::createPeriodicParticles(), SubcriticalMaserBoundary::createPeriodicParticles(), LeesEdwardsBoundary::createPeriodicParticles(), AngledPeriodicBoundary::createPeriodicParticles(), ConstantMassFlowMaserBoundary::createPeriodicParticles(), PeriodicBoundary::createPeriodicParticles(), InteractionHandler::deleteEmptyInteraction(), DPMBase::importParticlesAs(), MPIContainer::initialiseMercuryMPITypes(), DPMBase::integrateAfterForceComputation(), DPMBase::integrateBeforeForceComputation(), BaseCluster::makeDataAnalysis(), ChuteBottom::makeRoughBottom(), DPMBase::outputXBallsData(), BaseCluster::particleInsertionSuccessful(), FileReader::read(), SubcriticalMaserBoundary::read(), ConstantMassFlowMaserBoundary::read(), InsertionBoundary::read(), DPMBase::readNextDataFile(), DPMBase::readNextFStatFile(), DPMBase::readParAndIniFiles(), DPMBase::removeDuplicatePeriodicParticles(), DPMBase::setFixedParticles(), BaseWall::setHandler(), BaseParticle::setHandler(), BaseWall::setIndSpecies(), BaseParticle::setIndSpecies(), BaseSpecies::setInteractionDistance(), BaseInteractable::setSpecies(), BaseCluster::setSpecies(), ChuteBottom::setupInitialConditions(), Chute::setupInitialConditions(), ChuteWithHopper::setupInitialConditions(), Chute::setupSideWalls(), Domain::updateParticles(), DPMBase::write(), and BaseCluster::writeToOverlFile().

614 {
615  logger.assert(index < getSize(),
616  "[%::getObject()] Object couldn't be found because index (%) is higher than number of objects (%).",
617  getName(), index, getSize());
618  return objects_[index];
619 }
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Definition: BaseHandler.h:655
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:302
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 624 of file BaseHandler.h.

References getName(), and logger.

625 {
626  logger.assert(index < getSize(),
627  "[%::getObject() const] Object couldn't be found because index (%) is higher than number of objects (%).",
628  getName(), index, getSize());
629  return objects_[index];
630 }
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Definition: BaseHandler.h:655
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:302
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 565 of file BaseHandler.h.

References ERROR, getName(), and logger.

Referenced by PeriodicBoundaryHandler::processLocalInteractionData(), PeriodicBoundaryHandler::processReceivedInteractionData(), Domain::processReceivedInteractionData(), and FileReader::read().

566 {
567  // Usually, the id and the index into the backing storage matches
568  // So check this position first!
569  // dducks: Can't we guarantee more? That should speed up searches.
570  if (id < objects_.size() && objects_[id]->getId() == id)
571  {
572  return objects_[id]; //There is a hit, return early
573  }
574 
575  for (T* obj : objects_) //Search for the correct id, since it wasn't where
576  { // we expected it. Just use a linear search..
577  if (obj->getId() == id) //Found it, so return!
578  return obj;
579  }
580 #ifndef MERCURY_USE_MPI
581  logger(ERROR, "[BaseHandler::getObjectById()] in Object* %: Object with ID % could not be found.", getName(), id);
582 #endif
583  return nullptr;
584 }
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:302
template<typename T >
std::vector< T * > BaseHandler< T >::getObjectsById ( const unsigned int  id)

Gets a vector of pointers to the objects with the specific id.

Gets all the objects with the id from the handler. This is especially useful in parallel where ghost particles of a real particle have the same id

Parameters
[in]idThe id of the requested objects.
Returns
A list of pointers towards objects with the specified id

Definition at line 593 of file BaseHandler.h.

References ERROR, getName(), and logger.

Referenced by InteractionHandler::readAndAddObject().

594 {
595  std::vector<T*> list;
596  for (T* obj : objects_)
597  {
598  if (obj->getId() == id)
599  {
600  list.push_back(obj);
601  }
602  }
603 #ifndef MERCURY_USE_MPI
604  logger(ERROR, "[BaseHandler::getObjectById()] in Object* %: Object with ID % could not be found.", getName(), id);
605 #endif
606  return list;
607 
608 }
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:302
template<class T >
unsigned int BaseHandler< T >::getSize ( ) const

Gets the size of the particleHandler (including mpi and periodic particles)

Returns
The number of items in this BaseHandler

Definition at line 655 of file BaseHandler.h.

Referenced by Chute::addFlowParticlesCompactly(), BaseWall::addParticlesAtWall(), DeletionBoundary::checkBoundaryAfterParticlesMove(), FixedClusterInsertionBoundary::checkBoundaryBeforeTimeStep(), RandomClusterInsertionBoundary::checkBoundaryBeforeTimeStep(), BaseCluster::createAdjacencyMatrix(), CircularPeriodicBoundary::createPeriodicParticles(), LeesEdwardsBoundary::createPeriodicParticles(), SubcriticalMaserBoundary::createPeriodicParticles(), AngledPeriodicBoundary::createPeriodicParticles(), ConstantMassFlowMaserBoundary::createPeriodicParticles(), PeriodicBoundary::createPeriodicParticles(), DPMBase::decompose(), DPMBase::deleteGhostParticles(), CGHandler::evaluateDataFiles(), CGHandler::evaluateRestartFiles(), DPMBase::fillDomainWithParticles(), MercuryBase::getHGridTargetMaxInteractionRadius(), MercuryBase::getHGridTargetMinInteractionRadius(), MercuryBase::getHGridTargetNumberOfBuckets(), BaseParticle::getPeriodicComplexity(), WallVTKWriter::getVTKData(), MercuryBase::hGridNeedsRebuilding(), DPMBase::importParticlesAs(), HGridOptimiser::initialise(), DPMBase::insertGhostParticle(), BaseCluster::makeDataAnalysis(), BaseCluster::makeGnuplotFile(), DPMBase::mpiInsertParticleCheck(), DPMBase::outputXBallsData(), BaseCluster::printTime(), DPMBase::readNextDataFile(), DPMBase::removeDuplicatePeriodicParticles(), CGHandler::restart(), DPMBase::setFixedParticles(), ParticleSpecies::setMaxInteractionDistance(), BaseParticle::setPeriodicComplexity(), BaseCluster::setupInitialConditions(), DPMBase::write(), BaseCluster::writeAmatFile(), ParticleVtkWriter::writeExtraFields(), and SuperQuadricParticleVtkWriter::writeVTK().

656 {
657  return objects_.size();
658 }
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
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 662 of file BaseHandler.h.

663 {
664  return objects_.capacity();
665 }
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
template<typename T>
void BaseHandler< T >::increaseId ( )
inline

Definition at line 251 of file BaseHandler.h.

Referenced by ParticleHandler::addObject(), and PeriodicBoundaryHandler::updateMaserParticle().

252  {
253  nextId_++;
254  }
unsigned int nextId_
identifier for next object created
Definition: BaseHandler.h:313
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 543 of file BaseHandler.h.

References helpers::getLineFromStringStream(), getName(), constants::i, logger, and VERBOSE.

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

544 {
545  clear();
546  unsigned int N;
547  std::string dummy;
548  is >> dummy;
549  std::stringstream line;
551  line >> N;
552  logger(VERBOSE, "In %::read(is): reading in % objects.", getName(), N);
554  for (unsigned int i = 0; i < N; i++)
555  {
556  readAndAddObject(is);
557  }
558 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
void setStorageCapacity(const unsigned int N)
Sets the storage capacity of this BaseHandler.
Definition: BaseHandler.h:669
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
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:424
virtual std::string getName() const =0
Gets the name of this handler.
virtual void readAndAddObject(std::istream &is)=0
Reads Object into the BaseHandler from restart data.
virtual void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
Definition: BaseHandler.h:528
template<typename T>
virtual void BaseHandler< T >::readAndAddObject ( 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, CGHandler, DomainHandler, WallHandler, InteractionHandler, PeriodicBoundaryHandler, BoundaryHandler, and SpeciesHandler.

template<class T>
void BaseHandler< T >::removeIf ( const std::function< bool(T *)>  cond)

Definition at line 453 of file BaseHandler.h.

References constants::i.

454 {
455  for (int i = 0; i < objects_.size(); ++i) {
456  if (cond(objects_[i]))
457  {
458  //objects_(i)->actionsOnErase();
459  removeObject(i);
460  --i;
461  }
462  }
463 }
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
virtual void removeObject(unsigned const int index)
Removes an Object from the BaseHandler.
Definition: BaseHandler.h:472
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
template<typename T >
void BaseHandler< T >::removeLastObject ( )

Removes the last Object from the BaseHandler.

Definition at line 511 of file BaseHandler.h.

References getName(), logger, and WARN.

Referenced by ParticleHandler::removeLastObject().

512 {
513  if (getSize() == 0)
514  {
515  logger(WARN, "In: void %::removeLastObject, no Object exists in this BaseHandler.", getName());
516  return;
517  }
518  T* const object = objects_.back();
519  //Remove the (now double) reference to that last Object
520  objects_.pop_back();
521  //Physically removes Object
522  delete object;
523 }
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Definition: BaseHandler.h:655
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:302
template<typename T>
void BaseHandler< T >::removeObject ( unsigned const int  index)
virtual

Removes an Object from the BaseHandler.

This methods removes an object. This methods invalidates ANY iterators to objects 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.

Definition at line 472 of file BaseHandler.h.

References getName(), and logger.

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

473 {
474  logger.assert(index < getSize(),
475  "In: void %::removeObject(const unsigned int index) const, "
476  "no object exists with index %, number of objects is %",
477  getName(), index, getSize());
478 
479  //Removing a particle within the list is not efficient.
480  //Swap with last element and then perform the deletion
481  const unsigned int lastIndex = objects_.size() - 1;
482 
483  T* const objectToDelete = objects_[index];
484 
485  //No swapping required if it is the last object
486  if (index != lastIndex)
487  {
488 
489  T* const objectToMove = objects_[lastIndex];
490 
491  objects_[index] = objectToMove; //place it back
492  objects_[lastIndex] = objectToDelete; //Just to make sure.
493 
494  //and notify it of the change.
495  objects_[index]->moveInHandler(index);
496  //Even though we are going to delete this particle,
497  //we still need to keep it consistent.
498  objects_[lastIndex]->moveInHandler(lastIndex);
499  }
500 
501 
502  //And clear it from the backing container.
503  objects_.pop_back();
504  //And _NOW_ we delete it.
505 
506  delete objectToDelete;
507 
508 }
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Definition: BaseHandler.h:655
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:302
template<class T>
void BaseHandler< T >::resize ( const unsigned int  N,
const T &  obj 
)

Resizes the container to contain N elements.

If the current size is greater than count, the container is reduced to its first count elements.

If the current size is less than count, additional elements are appended and initialized with copies of obj.

Parameters
[in]NContainer resized to contain N elements.
[in]objadditional elements are appended and initialized with copies of obj.

Definition at line 679 of file BaseHandler.h.

680 {
681  //objects_.resize(N,obj); //doesn't work because the handler stores pointers only (data needs to be allocated);
682  while (getSize() < N)
683  copyAndAddObject(obj);
684  while (getSize() > N)
686 }
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Definition: BaseHandler.h:655
void removeLastObject()
Removes the last Object from the BaseHandler.
Definition: BaseHandler.h:511
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:379
template<typename T >
void BaseHandler< T >::setDPMBase ( DPMBase DPMBase)

Sets the problem that is solved using this handler.

Todo:
MX: Bad practice to have a function parameter with the exact name of the class
Parameters
[in]DPMBaseA pointer to a DPMBase, which is the superclass for all problem descriptions.

Definition at line 718 of file BaseHandler.h.

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

719 {
720  DPMBase_ = DPMBase;
721 }
DPMBase * DPMBase_
A pointer back to the DPMBase class.
Definition: BaseHandler.h:328
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 238 of file BaseHandler.h.

239  {
240  object->setId(id);
241  if (nextId_ <= id)
242  {
243  nextId_ = id + 1;
244  }
245  }
unsigned int nextId_
identifier for next object created
Definition: BaseHandler.h:313
template<typename T>
void BaseHandler< T >::setNextId ( unsigned int  id)
inline

Definition at line 261 of file BaseHandler.h.

Referenced by PeriodicBoundaryHandler::updateParticleStatus().

262  {
263  nextId_ = id;
264  }
unsigned int nextId_
identifier for next object created
Definition: BaseHandler.h:313
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 669 of file BaseHandler.h.

Referenced by Chute::addFlowParticlesCompactly(), FileReader::read(), DPMBase::read(), DPMBase::readNextDataFile(), and ChuteBottom::setupInitialConditions().

670 {
671  objects_.reserve(N);
672 }
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
template<typename T>
virtual void BaseHandler< T >::writeVTK ( ) const
inlinevirtual

now empty function for writing VTK files.

Deprecated:
Now the VTK-writers have their own classes, and are called from DPMBase.

Definition at line 286 of file BaseHandler.h.

287  {};

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 328 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 308 of file BaseHandler.h.

template<typename T>
unsigned BaseHandler< T >::nextGroupId_ = 1
private

value of the next BaseObject::groupId_. Value increased by one each time a groupId is assigned. Default group is 0

Definition at line 320 of file BaseHandler.h.

Referenced by BaseHandler< BaseCG >::getNextGroupId().

template<typename T>
unsigned int BaseHandler< T >::nextId_
private
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 302 of file BaseHandler.h.

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


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