35 #include <type_traits>
79 typename std::enable_if<!std::is_pointer<U>::value, U*>::type
86 typename std::enable_if<std::is_pointer<U>::value, U>::type
96 typename std::enable_if<!std::is_pointer<U>::value, U*>::type
106 typename std::enable_if<std::is_pointer<U>::value, U>::type
207 void resize(
const unsigned int N,
const T& obj);
212 const typename std::vector<T*>::const_iterator
begin()
const;
217 const typename std::vector<T*>::iterator
begin();
222 const typename std::vector<T*>::const_iterator
end()
const;
227 const typename std::vector<T*>::iterator
end();
238 void setId(T*
object,
unsigned int id)
339 logger(
DEBUG,
"BaseHandler<T>::BaseHandler() finished");
354 copyContentsFromOtherHandler(BH);
355 logger(
DEBUG,
"BaseHandler<T>::BaseHandler(const BaseHandler &BH) finished");
362 logger(
DEBUG,
"BaseHandler<T>::~BaseHandler() finished");
369 for (
const T*
const obj : BH.
objects_)
378 typename std::enable_if<!std::is_pointer<U>::value, U*>::type
381 U* oCopy =
object.copy();
389 typename std::enable_if<std::is_pointer<U>::value, U>::type
392 return copyAndAddObject(*
object);
398 typename std::enable_if<!std::is_pointer<U>::value, U*>::type
401 U* oCopy =
object.copy();
402 addGhostObject(oCopy);
409 typename std::enable_if<std::is_pointer<U>::value, U>::type
412 return copyAndAddGhostObject(*
object);
419 objects_.push_back(
O);
421 getLastObject()->setIndex(getSize() - 1);
423 if (
O->getId() + 1 > nextId_)
425 nextId_ =
O->getId() + 1;
433 objects_.push_back(
object);
435 getLastObject()->setIndex(getSize() - 1);
437 getLastObject()->setId(nextId_);
446 objects_.push_back(
O);
448 getLastObject()->setIndex(getSize() - 1);
455 for (
int i = 0;
i < objects_.size(); ++
i) {
456 if (cond(objects_[
i]))
474 logger.assert_debug(index < getSize(),
475 "In: void %::removeObject(const unsigned int index) const, "
476 "no object exists with index %, number of objects is %",
481 const unsigned int lastIndex = objects_.size() - 1;
483 T*
const objectToDelete = objects_[index];
486 if (index != lastIndex)
489 T*
const objectToMove = objects_[lastIndex];
491 objects_[index] = objectToMove;
492 objects_[lastIndex] = objectToDelete;
495 objects_[index]->moveInHandler(index);
498 objects_[lastIndex]->moveInHandler(lastIndex);
506 delete objectToDelete;
515 logger(
WARN,
"In: void %::removeLastObject, no Object exists in this BaseHandler.",
getName());
518 T*
const object = objects_.back();
531 for (T*
const obj : objects_)
549 std::stringstream line;
553 setStorageCapacity(N);
554 for (
unsigned int i = 0;
i < N;
i++)
556 readAndAddObject(is);
570 if (
id < objects_.size() && objects_[
id]->getId() ==
id)
575 for (T* obj : objects_)
577 if (obj->getId() ==
id)
580 #ifndef MERCURYDPM_USE_MPI
581 logger(
ERROR,
"[BaseHandler::getObjectById()] in Object* %: Object with ID % could not be found.",
getName(),
id);
595 std::vector<T*> list;
596 for (T* obj : objects_)
598 if (obj->getId() ==
id)
603 #ifndef MERCURYDPM_USE_MPI
604 logger(
ERROR,
"[BaseHandler::getObjectById()] in Object* %: Object with ID % could not be found.",
getName(),
id);
615 logger.assert_debug(index < getSize(),
616 "[%::getObject()] Object couldn't be found because index (%) is higher than number of objects (%).",
618 return objects_[index];
626 logger.assert_debug(index < getSize(),
627 "[%::getObject() const] Object couldn't be found because index (%) is higher than number of objects (%).",
629 return objects_[index];
636 return objects_.back();
643 return objects_.back();
650 return objects_.size();
657 return objects_.size();
664 return objects_.capacity();
682 while (getSize() < N)
683 copyAndAddObject(obj);
684 while (getSize() > N)
692 return objects_.begin();
699 return objects_.begin();
706 return objects_.end();
713 return objects_.end();
std::string getName(int argc, char *argv[])
Definition: CombineParallelDataFiles.cpp:12
LL< Log::VERBOSE > VERBOSE
Verbose information.
Definition: Logger.cc:57
LL< Log::DEBUG > DEBUG
Debug information.
Definition: Logger.cc:58
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
LL< Log::ERROR > ERROR
Error log level.
Definition: Logger.cc:53
LL< Log::WARN > WARN
Warning log level.
Definition: Logger.cc:54
void addObject(CGHandler &cg, std::string coordinate)
Definition: MercuryCG.cpp:40
Container to store the pointers to all objects that one creates in a simulation.
Definition: BaseHandler.h:51
virtual void removeObject(unsigned const int index)
Removes an Object from the BaseHandler.
Definition: BaseHandler.h:472
DPMBase * DPMBase_
A pointer back to the DPMBase class.
Definition: BaseHandler.h:328
BaseHandler()
Default BaseHandler constructor, it creates an empty BaseHandler and assigns DPMBase_ to a null point...
Definition: BaseHandler.h:335
void setDPMBase(DPMBase *DPMBase)
Sets the problem that is solved using this handler.
Definition: BaseHandler.h:718
void read(std::istream &is)
Reads all objects from restart data.
Definition: BaseHandler.h:543
const std::vector< T * >::iterator end()
Gets the end of the iterator over all BaseBoundary in this BaseHandler.
Definition: BaseHandler.h:711
const T * getObject(const unsigned int id) const
Gets a constant pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:624
const T * getLastObject() const
Gets a constant pointer to the last Object in this BaseHandler.
Definition: BaseHandler.h:641
unsigned nextGroupId_
value of the next BaseObject::groupId_. Value increased by one each time a groupId is assigned....
Definition: BaseHandler.h:320
virtual unsigned int getNumberOfObjects() const
Gets the number of real Object in this BaseHandler. (i.e. no mpi or periodic particles)
Definition: BaseHandler.h:648
virtual std::string getName() const =0
Gets the name of this handler.
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
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:390
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
virtual void writeVTK() const
now empty function for writing VTK files.
Definition: BaseHandler.h:286
unsigned getNextGroupId()
Should be called each time you assign a groupId. Returns the value of nextGroupId_ and increases next...
Definition: BaseHandler.h:293
DPMBase * getDPMBase() const
Gets the problem that is solved using this handler and does not change the class.
Definition: BaseHandler.h:732
virtual void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0.
Definition: BaseHandler.h:528
virtual void readAndAddObject(std::istream &is)=0
Reads Object into the BaseHandler from restart data.
void setStorageCapacity(const unsigned int N)
Sets the storage capacity of this BaseHandler.
Definition: BaseHandler.h:669
virtual void addObject(T *object)
Adds a new Object to the BaseHandler.
Definition: BaseHandler.h:431
unsigned int getNextId()
Definition: BaseHandler.h:256
const std::vector< T * >::const_iterator begin() const
Gets the begin of the const_iterator over all Object in this BaseHandler.
Definition: BaseHandler.h:690
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
unsigned int getStorageCapacity() const
Gets the storage capacity of this BaseHandler.
Definition: BaseHandler.h:662
const std::vector< T * >::const_iterator end() const
Gets the end of the const_iterator over all BaseBoundary in this BaseHandler.
Definition: BaseHandler.h:704
void setId(T *object, unsigned int id)
Definition: BaseHandler.h:238
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Definition: BaseHandler.h:655
void resize(const unsigned int N, const T &obj)
Resizes the container to contain N elements.
Definition: BaseHandler.h:679
void setNextId(unsigned int id)
Definition: BaseHandler.h:261
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:725
void removeIf(const std::function< bool(T *)> cond)
Definition: BaseHandler.h:453
BaseHandler(const BaseHandler< T > &BH)
Constructor that copies the objects of the given handler into itself and sets other variables to 0/nu...
Definition: BaseHandler.h:350
const std::vector< T * >::iterator begin()
Gets the begin of the iterator over all BaseBoundary in this BaseHandler.
Definition: BaseHandler.h:697
unsigned int maxObjects_
An integer to keep track of the largest number of objects ever stored in this BaseHandler.
Definition: BaseHandler.h:308
std::vector< T * > getObjectsById(const unsigned int id)
Gets a vector of pointers to the objects with the specific id.
Definition: BaseHandler.h:593
virtual void addGhostObject(T *O)
Adds a new Object to the BaseHandler. called by the to avoid increasing the id.
Definition: BaseHandler.h:444
void copyContentsFromOtherHandler(const BaseHandler< T > &BH)
Function that copies the contents (vector of pointers, maxObject_, nextId_, DPMBase_) from one handle...
Definition: BaseHandler.h:367
void increaseId()
Definition: BaseHandler.h:251
unsigned int nextId_
identifier for next object created
Definition: BaseHandler.h:313
T * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:613
virtual ~BaseHandler()
Destructor, it destructs the BaseHandler and all Object it contains.
Definition: BaseHandler.h:359
T * getObjectById(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:565
void removeLastObject()
Removes the last Object from the BaseHandler.
Definition: BaseHandler.h:511
virtual void addExistingObject(T *O)
Adds an existing object to the BaseHandler without changing the id of the object.
Definition: BaseHandler.h:417
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:410
T * getLastObject()
Gets a pointer to the last Object in this BaseHandler.
Definition: BaseHandler.h:634
The DPMBase header includes quite a few header files, defining all the handlers, which are essential....
Definition: DPMBase.h:77
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
void getLineFromStringStream(std::istream &in, std::stringstream &out)
Reads a line from one stringstream into another, and prepares the latter for reading in.
Definition: StringHelpers.cc:62