14 #include <type_traits>
193 const typename std::vector<T*>::const_iterator
begin()
const;
198 const typename std::vector<T*>::iterator
begin();
203 const typename std::vector<T*>::const_iterator
end()
const;
208 const typename std::vector<T*>::iterator
end();
320 logger(
DEBUG,
"BaseHandler<T>::BaseHandler() finished");
335 copyContentsFromOtherHandler(BH);
336 logger(
DEBUG,
"BaseHandler<T>::BaseHandler(const BaseHandler &BH) finished");
343 logger(
DEBUG,
"BaseHandler<T>::~BaseHandler() finished");
362 U* oCopy =
object.copy();
373 return copyAndAddObject(*
object);
382 U* oCopy =
object.copy();
383 addGhostObject(oCopy);
393 return copyAndAddGhostObject(*
object);
400 objects_.push_back(
O);
402 getLastObject()->setIndex(getSize() - 1);
404 if (
O->getId() + 1 > nextId_)
406 nextId_ =
O->getId() + 1;
414 objects_.push_back(
object);
416 getLastObject()->setIndex(getSize() - 1);
418 getLastObject()->setId(nextId_);
427 objects_.push_back(
O);
429 getLastObject()->setIndex(getSize() - 1);
436 for (
int i = 0;
i < objects_.size(); ++
i) {
437 if (cond(objects_[
i]))
455 logger.assert_debug(index < getSize(),
456 "In: void %::removeObject(const unsigned int index) const, "
457 "no object exists with index %, number of objects is %",
462 const unsigned int lastIndex = objects_.size() - 1;
464 T*
const objectToDelete = objects_[index];
467 if (index != lastIndex)
470 T*
const objectToMove = objects_[lastIndex];
472 objects_[index] = objectToMove;
473 objects_[lastIndex] = objectToDelete;
476 objects_[index]->moveInHandler(index);
479 objects_[lastIndex]->moveInHandler(lastIndex);
487 delete objectToDelete;
502 logger(
DEBUG,
"no objects could be removed due to an empty indices vector, please specify the"
503 "indices of objects to delete.");
507 std::sort(indices.begin(), indices.end(), std::greater<unsigned int>());
509 indices.erase(std::unique(indices.begin(), indices.end()), indices.end());
512 for (
unsigned const int index : indices)
523 logger(
WARN,
"In: void %::removeLastObject, no Object exists in this BaseHandler.",
getName());
526 T*
const object = objects_.back();
539 for (
T*
const obj : objects_)
557 std::stringstream
line;
561 setStorageCapacity(
N);
562 for (
unsigned int i = 0;
i <
N;
i++)
564 readAndAddObject(is);
578 if (
id < objects_.size() && objects_[
id]->getId() ==
id)
583 for (
T* obj : objects_)
585 if (obj->getId() ==
id)
588 #ifndef MERCURYDPM_USE_MPI
589 logger(
ERROR,
"[BaseHandler::getObjectById()] in Object* %: Object with ID % could not be found.",
getName(),
id);
603 std::vector<T*> list;
604 for (
T* obj : objects_)
606 if (obj->getId() ==
id)
611 #ifndef MERCURYDPM_USE_MPI
612 logger(
ERROR,
"[BaseHandler::getObjectById()] in Object* %: Object with ID % could not be found.",
getName(),
id);
623 logger.assert_debug(index < getSize(),
624 "[%::getObject()] Object couldn't be found because index (%) is higher than number of objects (%).",
626 return objects_[index];
634 logger.assert_debug(index < getSize(),
635 "[%::getObject() const] Object couldn't be found because index (%) is higher than number of objects (%).",
637 return objects_[index];
644 return objects_.back();
651 return objects_.back();
658 return objects_.size();
665 return objects_.size();
672 return objects_.capacity();
690 while (getSize() <
N)
691 copyAndAddObject(obj);
692 while (getSize() >
N)
700 return objects_.begin();
707 return objects_.begin();
714 return objects_.end();
721 return objects_.end();
int i
Definition: BiCGSTAB_step_by_step.cpp:9
std::string getName(int argc, char *argv[])
Definition: CombineParallelDataFiles.cpp:16
LL< Log::VERBOSE > VERBOSE
Verbose information.
Definition: Logger.cc:36
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:32
LL< Log::WARN > WARN
Warning log level.
Definition: Logger.cc:33
void addObject(CGHandler &cg, std::string coordinate)
Definition: MercuryCG.cpp:22
Container to store the pointers to all objects that one creates in a simulation.
Definition: BaseHandler.h:30
virtual void removeObject(unsigned const int index)
Removes an Object from the BaseHandler.
Definition: BaseHandler.h:453
DPMBase * DPMBase_
A pointer back to the DPMBase class.
Definition: BaseHandler.h:309
BaseHandler()
Default BaseHandler constructor, it creates an empty BaseHandler and assigns DPMBase_ to a null point...
Definition: BaseHandler.h:316
void setDPMBase(DPMBase *DPMBase)
Sets the problem that is solved using this handler.
Definition: BaseHandler.h:726
void read(std::istream &is)
Reads all objects from restart data.
Definition: BaseHandler.h:551
const std::vector< T * >::iterator end()
Gets the end of the iterator over all BaseBoundary in this BaseHandler.
Definition: BaseHandler.h:719
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:632
const T * getLastObject() const
Gets a constant pointer to the last Object in this BaseHandler.
Definition: BaseHandler.h:649
unsigned nextGroupId_
value of the next BaseObject::groupId_. Value increased by one each time a groupId is assigned....
Definition: BaseHandler.h:301
virtual unsigned int getNumberOfObjects() const
Gets the number of real Object in this BaseHandler. (i.e. no mpi or periodic particles)
Definition: BaseHandler.h:656
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:380
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:371
std::vector< T * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:283
virtual void writeVTK() const
now empty function for writing VTK files.
Definition: BaseHandler.h:267
unsigned getNextGroupId()
Should be called each time you assign a groupId. Returns the value of nextGroupId_ and increases next...
Definition: BaseHandler.h:274
DPMBase * getDPMBase() const
Gets the problem that is solved using this handler and does not change the class.
Definition: BaseHandler.h:740
virtual void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0.
Definition: BaseHandler.h:536
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:677
virtual void addObject(T *object)
Adds a new Object to the BaseHandler.
Definition: BaseHandler.h:412
unsigned int getNextId()
Definition: BaseHandler.h:237
const std::vector< T * >::const_iterator begin() const
Gets the begin of the const_iterator over all Object in this BaseHandler.
Definition: BaseHandler.h:698
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:360
unsigned int getStorageCapacity() const
Gets the storage capacity of this BaseHandler.
Definition: BaseHandler.h:670
const std::vector< T * >::const_iterator end() const
Gets the end of the const_iterator over all BaseBoundary in this BaseHandler.
Definition: BaseHandler.h:712
void setId(T *object, unsigned int id)
Definition: BaseHandler.h:219
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Definition: BaseHandler.h:663
void resize(const unsigned int N, const T &obj)
Resizes the container to contain N elements.
Definition: BaseHandler.h:687
void setNextId(unsigned int id)
Definition: BaseHandler.h:242
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:733
void removeIf(const std::function< bool(T *)> cond)
Definition: BaseHandler.h:434
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:331
const std::vector< T * >::iterator begin()
Gets the begin of the iterator over all BaseBoundary in this BaseHandler.
Definition: BaseHandler.h:705
unsigned int maxObjects_
An integer to keep track of the largest number of objects ever stored in this BaseHandler.
Definition: BaseHandler.h:289
std::vector< T * > getObjectsById(const unsigned int id)
Gets a vector of pointers to the objects with the specific id.
Definition: BaseHandler.h:601
virtual void addGhostObject(T *O)
Adds a new Object to the BaseHandler. called by the to avoid increasing the id.
Definition: BaseHandler.h:425
void copyContentsFromOtherHandler(const BaseHandler< T > &BH)
Function that copies the contents (vector of pointers, maxObject_, nextId_, DPMBase_) from one handle...
Definition: BaseHandler.h:348
void increaseId()
Definition: BaseHandler.h:232
unsigned int nextId_
identifier for next object created
Definition: BaseHandler.h:294
T * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:621
virtual ~BaseHandler()
Destructor, it destructs the BaseHandler and all Object it contains.
Definition: BaseHandler.h:340
T * getObjectById(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:573
void removeLastObject()
Removes the last Object from the BaseHandler.
Definition: BaseHandler.h:519
virtual void addExistingObject(T *O)
Adds an existing object to the BaseHandler without changing the id of the object.
Definition: BaseHandler.h:398
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:391
T * getLastObject()
Gets a pointer to the last Object in this BaseHandler.
Definition: BaseHandler.h:642
virtual void removeObjects(std::vector< unsigned int > indices)
Definition: BaseHandler.h:498
The DPMBase header includes quite a few header files, defining all the handlers, which are essential....
Definition: DPMBase.h:56
@ N
Definition: constructor.cpp:22
#define DEBUG
Definition: main.h:181
squared absolute value
Definition: GlobalFunctions.h:87
double U
Swimming speed.
Definition: two_d_variable_diff_adapt.cc:53
line
Definition: calibrate.py:103
type
Definition: compute_granudrum_aor.py:141
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:41
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286