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

Container to store all BaseParticle. More...

#include <ParticleHandler.h>

+ Inheritance diagram for ParticleHandler:

Public Member Functions

 ParticleHandler ()
 Default constructor, it creates an empty ParticleHandler. More...
 
 ParticleHandler (const ParticleHandler &PH)
 Constructor that copies all BaseParticle it contains and then sets the smallest and largest particle. More...
 
ParticleHandleroperator= (const ParticleHandler &rhs)
 Assignment operator. More...
 
 ~ParticleHandler () override
 Destructor, it destructs the ParticleHandler and all BaseParticle it contains. More...
 
void addExistingObject (BaseParticle *P) override
 Adds a BaseParticle to the ParticleHandler. More...
 
void addObject (BaseParticle *P) override
 Adds a BaseParticle to the ParticleHandler. More...
 
void addObject (int fromProcessor, BaseParticle *P)
 Adds a BaseParticle located at processor fromProcessor to toProcessor. More...
 
void addGhostObject (int fromPrcessor, int toProcessor, BaseParticle *p)
 Adds a ghost particle located at fromProcessor to toProcessor. More...
 
void addGhostObject (BaseParticle *P) override
 Adds a BaseParticle to the ParticleHandler. More...
 
void removeObject (unsigned int index) override
 Removes a BaseParticle from the ParticleHandler. More...
 
void removeGhostObject (unsigned int index)
 Removes a BaseParticle from the ParticleHandler without a global check, this is only to be done for mpi routines. More...
 
void removeLastObject ()
 Removes the last BaseParticle from the ParticleHandler. More...
 
void computeSmallestParticle ()
 Computes the smallest particle (by interaction radius) and sets it in smallestParticle_. More...
 
void computeLargestParticle ()
 Computes the largest particle (by interaction radius) and sets it in largestParticle_. More...
 
BaseParticlegetSmallestParticleLocal () const
 Gets a pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler of the local domain. More...
 
BaseParticlegetSmallestParticle () const
 Gets a pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler of the local domain. When mercury is running in parallel this function throws an error since a pointer to another domain is useless. More...
 
BaseParticlegetLargestParticleLocal () const
 Gets a pointer to the largest BaseParticle (by interactionRadius) in the ParticleHandler of the local domain. More...
 
BaseParticlegetLargestParticle () const
 Returns the pointer of the largest particle in the particle handler. When mercury is running in parallel this function throws an error since a pointer to another domain is useless. More...
 
Mdouble getSmallestInteractionRadiusLocal () const
 Returns the smallest interaction radius of the current domain. More...
 
Mdouble getSmallestInteractionRadius () const
 Returns the smallest interaction radius. More...
 
Mdouble getLargestInteractionRadiusLocal () const
 Returns the largest interaction radius of the current domain. More...
 
Mdouble getLargestInteractionRadius () const
 Returns the largest interaction radius. More...
 
BaseParticlegetFastestParticleLocal () const
 Gets a pointer to the fastest BaseParticle in this ParticleHandler. More...
 
BaseParticlegetFastestParticle () const
 
Mdouble getKineticEnergy () const
 
Mdouble getRotationalEnergy () const
 
Mdouble getMass () const
 
Vec3D getMassTimesPosition () const
 
Vec3D getCentreOfMass () const
 
Vec3D getMomentum () const
 
Vec3D getAngularMomentum () const
 
Mdouble getVolume () const
 
Mdouble getMeanRadius () const
 
BaseParticlegetLowestPositionComponentParticleLocal (int i) const
 Gets a pointer to the particle with the lowest coordinates in direction i in this ParticleHandler. More...
 
BaseParticlegetLowestPositionComponentParticle (int i) const
 Gets a pointer to the particle with the lowest coordinates in direction i in this ParticleHandler. More...
 
BaseParticlegetHighestPositionComponentParticleLocal (int i) const
 Gets a pointer to the particle with the highest coordinates in direction i in this ParticleHandler. More...
 
BaseParticlegetHighestPositionComponentParticle (int i) const
 Gets a pointer to the particle with the highest coordinates in direction i in this ParticleHandler. More...
 
BaseParticlegetLowestVelocityComponentParticleLocal (int i) const
 Gets a pointer to the particle with the lowest velocity in direction i in this ParticleHandler. More...
 
BaseParticlegetLowestVelocityComponentParticle (int i) const
 Gets a pointer to the particle with the lowest velocity in direction i in this ParticleHandler. More...
 
BaseParticlegetHighestVelocityComponentParticleLocal (int i) const
 Gets a pointer to the particle with the highest velocity in direction i in this ParticleHandler. More...
 
BaseParticlegetHighestVelocityComponentParticle (int i) const
 Gets a pointer to the particle with the highest velocity in direction i in this ParticleHandler. More...
 
template<typename T >
std::enable_if< std::is_scalar
< T >::value, T >::type 
getParticleAttributeLocal (std::function< T(BaseParticle *)> attribute, AttributeType type) const
 Computes an attribute type (min/max/..) of a particle attribute (position/velocity) in a local domain. More...
 
template<typename T >
std::enable_if< std::is_scalar
< T >::value, T >::type 
getParticleAttribute (std::function< T(BaseParticle *)> attribute, AttributeType type) const
 Computes an attribute type (min/max/..) of a particle attribute(position/velocity) in the global domain. More...
 
Mdouble getHighestPositionX () const
 Function returns the highest position in the x-direction. More...
 
void clear () override
 Empties the whole ParticleHandler by removing all BaseParticle. More...
 
unsigned int getNumberOfFixedParticles () const
 Gets the number of particles that are fixed. More...
 
unsigned int getNumberOfUnfixedParticles () const
 Gets the number of particles that are not fixed. More...
 
BaseParticlereadAndCreateObject (std::istream &is)
 Create a new particle, based on the information provided in a restart file. More...
 
void readAndAddObject (std::istream &is) override
 Create a new particle, based on the information from old-style restart data. More...
 
void write (std::ostream &os) const
 
void checkExtrema (BaseParticle *P)
 Checks if the extrema of this ParticleHandler needs updating. More...
 
void checkExtremaOnDelete (BaseParticle *P)
 Checks if the extrema of this ParticleHandler needs updating when a particle is deleted. More...
 
void computeAllMasses (unsigned int indSpecies)
 Computes the mass for all BaseParticle of the given species in this ParticleHandler. More...
 
void computeAllMasses ()
 Computes the mass for all BaseParticle in this ParticleHandler. More...
 
void addedFixedParticle ()
 Increment of the number of fixed particles. More...
 
void removedFixedParticle ()
 Decrement of the number of fixed particles. More...
 
std::string getName () const override
 Returns the name of the handler, namely the string "ParticleHandler". More...
 
unsigned int getNumberOfRealObjects () const
 Returns the number of real objects (on all processors) More...
 
unsigned int getNumberOfObjects () const override
 Returns the number of objects in the container. In parallel code this practice is forbidden to avoid confusion with real and fake particles. If the size of the container is wished, call size() More...
 
unsigned int getNumberOfFixedObjectsLocal () const
 Computes the number of Fixed particles on a local domain. More...
 
unsigned int getNumberOfFixedObjects () const
 Computes the number of fixed particles in the whole simulation. More...
 
unsigned int getNumberOfRealObjectsLocal () const
 Returns the number of real objects on a local domain. MPI particles and periodic particles are neglected. More...
 
void actionsAfterTimeStep ()
 
double getLiquidFilmVolume () const
 
- Public Member Functions inherited from BaseHandler< BaseParticle >
 BaseHandler ()
 Default BaseHandler constructor, it creates an empty BaseHandler and assigns DPMBase_ to a null pointer. More...
 
 BaseHandler (const BaseHandler< BaseParticle > &BH)
 Constructor that copies the objects of the given handler into itself and sets other variables to 0/nullptr. More...
 
virtual ~BaseHandler ()
 Destructor, it destructs the BaseHandler and all Object it contains. More...
 
void copyContentsFromOtherHandler (const BaseHandler< BaseParticle > &BH)
 Function that copies the contents (vector of pointers, maxObject_, nextId_, DPMBase_) from one handler (container) to the other. More...
 
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...
 
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...
 
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...
 
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...
 
void removeIf (const std::function< bool(BaseParticle *)> 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...
 
void read (std::istream &is)
 Reads all objects from restart data. More...
 
BaseParticlegetObjectById (const unsigned int id)
 Gets a pointer to the Object at the specified index in the BaseHandler. More...
 
std::vector< BaseParticle * > getObjectsById (const unsigned int id)
 Gets a vector of pointers to the objects with the specific id. More...
 
BaseParticlegetObject (const unsigned int id)
 Gets a pointer to the Object at the specified index in the BaseHandler. More...
 
const BaseParticlegetObject (const unsigned int id) const
 Gets a constant pointer to the Object at the specified index in the BaseHandler. More...
 
BaseParticlegetLastObject ()
 Gets a pointer to the last Object in this BaseHandler. More...
 
const BaseParticlegetLastObject () const
 Gets a constant pointer to the last Object in this BaseHandler. More...
 
unsigned int 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 BaseParticle &obj)
 Resizes the container to contain N elements. More...
 
const std::vector
< BaseParticle * >
::const_iterator 
begin () const
 Gets the begin of the const_iterator over all Object in this BaseHandler. More...
 
const std::vector
< BaseParticle * >::iterator 
begin ()
 Gets the begin of the iterator over all BaseBoundary in this BaseHandler. More...
 
const std::vector
< BaseParticle * >
::const_iterator 
end () const
 Gets the end of the const_iterator over all BaseBoundary in this BaseHandler. More...
 
const std::vector
< BaseParticle * >::iterator 
end ()
 Gets the end of the iterator over all BaseBoundary in this BaseHandler. More...
 
void setDPMBase (DPMBase *DPMBase)
 Sets the problem that is solved using this handler. More...
 
void setId (BaseParticle *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 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...
 

Static Public Member Functions

static BaseParticlecreateObject (const std::string &type)
 Reads BaseParticle into the ParticleHandler from restart data. More...
 

Private Member Functions

Mdouble getKineticEnergyLocal () const
 
Mdouble getRotationalEnergyLocal () const
 
Mdouble getMassLocal () const
 
Mdouble getVolumeLocal () const
 
Vec3D getMassTimesPositionLocal () const
 
Mdouble getSumRadiusLocal () const
 

Private Attributes

BaseParticlelargestParticle_
 A pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler. More...
 
BaseParticlesmallestParticle_
 A pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler. More...
 
unsigned int NFixedParticles_
 Number of fixed particles. More...
 

Additional Inherited Members

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

Detailed Description

Container to store all BaseParticle.

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

Definition at line 47 of file ParticleHandler.h.

Constructor & Destructor Documentation

ParticleHandler::ParticleHandler ( )

Default constructor, it creates an empty ParticleHandler.

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

Definition at line 49 of file ParticleHandler.cc.

References DEBUG, largestParticle_, logger, and smallestParticle_.

50 {
51  largestParticle_ = nullptr;
52  smallestParticle_ = nullptr;
53  logger(DEBUG, "ParticleHandler::ParticleHandler() finished");
54 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
BaseParticle * smallestParticle_
A pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler.
BaseParticle * largestParticle_
A pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.
ParticleHandler::ParticleHandler ( const ParticleHandler PH)

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

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

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

Definition at line 62 of file ParticleHandler.cc.

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

64 {
65  clear();
66  setDPMBase(PH.getDPMBase());
67  largestParticle_ = nullptr;
68  smallestParticle_ = nullptr;
70  if (!objects_.empty())
71  {
74  }
75  logger(DEBUG, "ParticleHandler::ParticleHandler(const ParticleHandler &PH) finished");
76 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
void setDPMBase(DPMBase *DPMBase)
Sets the problem that is solved using this handler.
void clear() override
Empties the whole ParticleHandler by removing all BaseParticle.
BaseParticle * smallestParticle_
A pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler.
BaseParticle * largestParticle_
A pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
void computeSmallestParticle()
Computes the smallest particle (by interaction radius) and sets it in smallestParticle_.
void computeLargestParticle()
Computes the largest particle (by interaction radius) and sets it in largestParticle_.
void copyContentsFromOtherHandler(const BaseHandler< BaseParticle > &BH)
Function that copies the contents (vector of pointers, maxObject_, nextId_, DPMBase_) from one handle...
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:725
ParticleHandler::~ParticleHandler ( )
override

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

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

Definition at line 106 of file ParticleHandler.cc.

References DEBUG, largestParticle_, logger, and smallestParticle_.

107 {
108  //First reset the pointers, such that they are not checked twice when removing particles
109  largestParticle_ = nullptr;
110  smallestParticle_ = nullptr;
111  logger(DEBUG, "ParticleHandler::~ParticleHandler() finished");
112 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
BaseParticle * smallestParticle_
A pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler.
BaseParticle * largestParticle_
A pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.

Member Function Documentation

void ParticleHandler::actionsAfterTimeStep ( )

Definition at line 1355 of file ParticleHandler.cc.

References constants::i.

Referenced by DPMBase::computeOneTimeStep().

1356 {
1357  for (auto i: *this)
1358  {
1359  i->actionsAfterTimeStep();
1360  }
1361 }
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
void ParticleHandler::addedFixedParticle ( )

Increment of the number of fixed particles.

Todo:
MX: For Jonny, is this still required, keeping the parallel code in mind?

Definition at line 1217 of file ParticleHandler.cc.

References NFixedParticles_.

Referenced by BaseParticle::fixParticle().

1218 {
1219  NFixedParticles_++;
1220 }
unsigned int NFixedParticles_
Number of fixed particles.
void ParticleHandler::addExistingObject ( BaseParticle P)
overridevirtual

Adds a BaseParticle to the ParticleHandler.

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

To add a BaseParticle to the ParticleHandler, first check if it has a species, since it is as common bug to use a BaseParticle without species, which leads to a segmentation fault. To help the user with debugging, a warning is given if a particle without species is added. After that, the actions for adding the particle to the BaseHandler are taken, which include adding it to the vector of pointers to all BaseParticle and assigning the correct id and index. Then the particle is added to the HGrid, the particle is told that this is its handler, its mass is computed and finally it is checked if this is the smallest or largest particle in this ParticleHandler. The particle exists, in other words: it has been made before. This implies it already got an id Attached to it and hence we don't want to assign a new ID to it.

Reimplemented from BaseHandler< BaseParticle >.

Definition at line 130 of file ParticleHandler.cc.

References BaseHandler< T >::addExistingObject(), checkExtrema(), ParticleSpecies::computeMass(), BaseHandler< BaseParticle >::getDPMBase(), BaseObject::getId(), BaseInteractable::getSpecies(), DPMBase::hGridInsertParticle(), DPMBase::hGridUpdateParticle(), logger, BaseParticle::setHandler(), and WARN.

Referenced by readAndAddObject().

131 {
132  if (P->getSpecies() == nullptr)
133  {
134  logger(WARN, "WARNING: The particle with ID % that is added in ParticleHandler::addObject does not have a "
135  "species yet. Please make sure that you have "
136  "set the species somewhere in the driver code.", P->getId());
137  }
138 
139  //Puts the particle in the Particle list
141  if (getDPMBase() != nullptr)
142  {
143  //This places the particle in this grid
145  //This computes where the particle currently is in the grid
147  }
148  //set the particleHandler pointer
149  P->setHandler(this);
150  //compute mass of the particle
151  P->getSpecies()->computeMass(P);
152  //Check if this particle has new extrema
153  checkExtrema(P);
154 }
unsigned int getId() const
Returns the unique identifier of any particular object.
Definition: BaseObject.h:125
virtual void hGridUpdateParticle(BaseParticle *obj UNUSED)
Definition: DPMBase.cc:1695
virtual void hGridInsertParticle(BaseParticle *obj UNUSED)
Definition: DPMBase.cc:1688
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
const ParticleSpecies * getSpecies() const
Returns a pointer to the species of this BaseInteractable.
void checkExtrema(BaseParticle *P)
Checks if the extrema of this ParticleHandler needs updating.
void setHandler(ParticleHandler *handler)
Sets the pointer to the particle's ParticleHandler.
void computeMass(BaseParticle *p) const
Compute Particle mass function, which required a reference to the Species vector. It computes the Par...
virtual void addExistingObject(T *O)
Adds an existing object to the BaseHandler without changing the id of the object. ...
Definition: BaseHandler.h:417
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
void ParticleHandler::addGhostObject ( int  fromProcessor,
int  toProcessor,
BaseParticle p 
)

Adds a ghost particle located at fromProcessor to toProcessor.

This function adds a ghost particle from one processor to another processor.

When a periodic ghost particle or a mpi ghost particle is created, the ID should not be updated and hence the addGhostObject needs to be called. Adding a ghost keeps the ID constant. Additionally this function copies the particle information given on processor fromProcessor to all other processors. The target processor then adds the particle.

Parameters
[in]fromProcessorprocessor containing the particle data
[in]toProcessorprocessor that needs to add the particle
[in,out]particlethat contains the data and receives the data

Definition at line 283 of file ParticleHandler.cc.

References copyDataFromMPIParticleToParticle(), MPISphericalParticle::copyDataFromParticleToMPIParticle(), MPIContainer::getProcessorID(), MPIContainer::Instance(), logger, MAX_PROC, PARTICLE, PARTICLE_DATA, MPIContainer::receive(), MPIContainer::send(), MPIContainer::sync(), and WARN.

Referenced by PeriodicBoundaryHandler::processLocalGhostParticles(), Domain::processReceivedBoundaryParticleData(), and PeriodicBoundaryHandler::processReceivedGhostParticleData().

284 {
285 #ifdef MERCURY_USE_MPI
286  MPIContainer& communicator = MPIContainer::Instance();
287  if (fromProcessor == toProcessor)
288  {
289  if (communicator.getProcessorID() == fromProcessor)
290  {
291  addGhostObject(p);
292  }
293 
294  return;
295  }
296 
297  //Create communication information object
299  MPIParticle pInfo;
300  int tag;
301  if (communicator.getProcessorID() == fromProcessor)
302  {
304  tag = fromProcessor*MAX_PROC*10 + toProcessor*10 + MercuryMPITag::PARTICLE_DATA;
305  communicator.send(&pInfo, MercuryMPIType::PARTICLE, 1, toProcessor, tag);
306  }
307 
308  if (communicator.getProcessorID() == toProcessor)
309  {
310  tag = fromProcessor*MAX_PROC*10 + toProcessor*10 + MercuryMPITag::PARTICLE_DATA;
311  communicator.receive(&pInfo, MercuryMPIType::PARTICLE, 1, fromProcessor, tag);
312  }
313 
314  //Sync the communication
315  communicator.sync();
316 
317  //Add the data to the new particle
318  if (communicator.getProcessorID() == toProcessor)
319  {
320  copyDataFromMPIParticleToParticle(&pInfo, p, this);
321  }
322 
323 
324  //Only toProcessor adds the particle, quietly without any check with other processors
325  //IMPORTANT NOTE: When adding a periodic particle in parallel, this is performed just before
326  //finding new particles. For that reason we dont have to add a ghostparticle to the mpi communication lists
327  if (communicator.getProcessorID() == toProcessor)
328  {
329  addGhostObject(p);
330  }
331 #else
332  logger(WARN,
333  "Function addGhostObject(int fromProcessor, int toProcessor, BaseParticle* p) should not be used in serial code");
334 #endif
335 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:129
void copyDataFromParticleToMPIParticle(BaseParticle *p)
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:134
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
std::enable_if< std::is_scalar< T >::value, void >::type receive(T &t, int from, int tag)
asynchronously receive a scalar from some other processor.
Definition: MpiContainer.h:221
void addGhostObject(int fromPrcessor, int toProcessor, BaseParticle *p)
Adds a ghost particle located at fromProcessor to toProcessor.
void copyDataFromMPIParticleToParticle(MPIParticle *bP, BaseParticle *p, ParticleHandler *particleHandler)
Copies data from an MPIParticle class to a BaseParticle and sets the particleHandler and species...
std::size_t getProcessorID()
Reduces a scalar on all processors to one scalar on a target processor.
#define MAX_PROC
Definition: GeneralDefine.h:51
Data class to send a particle over MPI.
Definition: MpiDataClass.h:81
void sync()
Process all pending asynchronous communication requests before continuing.
Definition: MpiContainer.h:152
std::enable_if< std::is_scalar< T >::value, void >::type send(T &t, int to, int tag)
Asynchronously send a scalar to some other processor.
Definition: MpiContainer.h:171
void ParticleHandler::addGhostObject ( BaseParticle P)
overridevirtual

Adds a BaseParticle to the ParticleHandler.

This is a special function that is used in the parallel code. The functions differs from the standard parallel implementation as this function does not check if the particle is an mpi particle and the mpi domain is not updated. When the domain adds mpi particles to the simulation these checks are not required. It also doesnt increase the id of the particle

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

Reimplemented from BaseHandler< BaseParticle >.

Definition at line 344 of file ParticleHandler.cc.

References BaseHandler< T >::addGhostObject(), checkExtrema(), ParticleSpecies::computeMass(), BaseHandler< BaseParticle >::getDPMBase(), BaseObject::getId(), BaseInteractable::getSpecies(), DPMBase::handleParticleAddition(), DPMBase::hGridInsertParticle(), DPMBase::hGridUpdateParticle(), INFO, MPIContainer::Instance(), logger, BaseParticle::setHandler(), and WARN.

345 {
346 #ifdef MERCURY_USE_MPI
347  if (P->getSpecies() == nullptr)
348  {
349  logger(WARN, "[ParticleHandler::adGhostObject(BaseParticle*)] "
350  "WARNING: The particle with ID % that is added in "
351  "ParticleHandler::addObject does not have a species yet."
352  " Please make sure that you have "
353  "set the species somewhere in the driver code.", P->getId());
354  }
355 
356  MPIContainer& communicator = MPIContainer::Instance();
357  //Puts the particle in the Particle list
359  if (getDPMBase() != nullptr)
360  {
361  //This places the particle in this grid
363  //This computes where the particle currently is in the grid
365 
366  // broadcast particle addition
368  }
369  //set the particleHandler pointer
370  P->setHandler(this);
371  //compute mass of the particle
372  P->getSpecies()->computeMass(P) ;
373  //Check if this particle has new extrema
374  checkExtrema(P);
375 #else
376  logger(INFO,
377  "Function ParticleHandler::mpiAddObject(BaseParticle* P) should only be called when compiling with parallel build on");
378 #endif
379 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:129
unsigned int getId() const
Returns the unique identifier of any particular object.
Definition: BaseObject.h:125
virtual void hGridUpdateParticle(BaseParticle *obj UNUSED)
Definition: DPMBase.cc:1695
virtual void hGridInsertParticle(BaseParticle *obj UNUSED)
Definition: DPMBase.cc:1688
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:134
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
const ParticleSpecies * getSpecies() const
Returns a pointer to the species of this BaseInteractable.
void checkExtrema(BaseParticle *P)
Checks if the extrema of this ParticleHandler needs updating.
void setHandler(ParticleHandler *handler)
Sets the pointer to the particle's ParticleHandler.
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 computeMass(BaseParticle *p) const
Compute Particle mass function, which required a reference to the Species vector. It computes the Par...
virtual void handleParticleAddition(unsigned int id, BaseParticle *p)
Definition: DPMBase.cc:5312
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
void ParticleHandler::addObject ( BaseParticle P)
overridevirtual

Adds a BaseParticle to the ParticleHandler.

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

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

Reimplemented from BaseHandler< BaseParticle >.

Definition at line 170 of file ParticleHandler.cc.

References BaseHandler< T >::addObject(), checkExtrema(), ParticleSpecies::computeMass(), BaseHandler< BaseParticle >::getDPMBase(), BaseObject::getId(), BaseInteractable::getSpecies(), DPMBase::handleParticleAddition(), DPMBase::hGridInsertParticle(), DPMBase::hGridUpdateParticle(), BaseHandler< T >::increaseId(), DPMBase::insertGhostParticle(), BaseParticle::isMPIParticle(), BaseParticle::isPeriodicGhostParticle(), BaseParticle::isSphericalParticle(), logger, DPMBase::mpiInsertParticleCheck(), NUMBER_OF_PROCESSORS, BaseParticle::setHandler(), BaseParticle::setPeriodicComplexity(), DPMBase::setRotation(), DPMBase::updateGhostGrid(), and WARN.

Referenced by addObject(), CircularPeriodicBoundary::checkBoundaryAfterParticleMoved(), SubcriticalMaserBoundaryTEST::checkBoundaryAfterParticleMoved(), SubcriticalMaserBoundary::checkBoundaryAfterParticleMoved(), ConstantMassFlowMaserBoundary::checkBoundaryAfterParticleMoved(), SubcriticalMaserBoundaryTEST::copyExtraParticles(), CurvyChute::createBottom(), PeriodicBoundary::createGhostParticle(), TimeDependentPeriodicBoundary::createGhostParticle(), ShearBoxBoundary::createHorizontalPeriodicParticles(), LeesEdwardsBoundary::createHorizontalPeriodicParticles(), CircularPeriodicBoundary::createPeriodicParticle(), AngledPeriodicBoundary::createPeriodicParticle(), SubcriticalMaserBoundary::createPeriodicParticle(), ConstantMassFlowMaserBoundary::createPeriodicParticle(), ShearBoxBoundary::createVerticalPeriodicParticles(), LeesEdwardsBoundary::createVerticalPeriodicParticles(), and SubcriticalMaserBoundaryTEST::extendBottom().

171 {
172  if (P->getSpecies() == nullptr)
173  {
174  logger(WARN, "WARNING: The particle with ID % that is added in "
175  "ParticleHandler::addObject does not have a species yet. "
176  "Please make sure that you have "
177  "set the species somewhere in the driver code.", P->getId());
178  }
179 #ifdef MERCURY_USE_MPI
180  bool insertParticle;
181  //Check if the particle P should be added to the current domain
182  if (NUMBER_OF_PROCESSORS == 1)
183  {
184  insertParticle = true;
185  }
186  else
187  {
188  insertParticle = getDPMBase()->mpiInsertParticleCheck(P);
189  }
190 
191  //Add the particle if it is in the mpi domain or if the domain is not yet defined
192  if(insertParticle)
193  {
194 #endif
195  //Puts the particle in the Particle list
197  if (getDPMBase() != nullptr)
198  {
199  //This places the particle in this grid
201  //This computes where the particle currently is in the grid
203 
204  // Broadcasts the existance of a new particle
206  }
207  //set the particleHandler pointer
208  P->setHandler(this);
209  //compute mass of the particle
210  P->getSpecies()->computeMass(P);
211  //Check if this particle has new extrema
212  checkExtrema(P);
213  if (!P->isSphericalParticle())
214  {
215  getDPMBase()->setRotation(true);
216  }
217 #ifdef MERCURY_USE_MPI
218  P->setPeriodicComplexity(std::vector<int>(0));
219  }
220  else
221  {
222  logger.assert_debug(!P->isMPIParticle(),"Can't add mpi particle as it does not exist");
223  logger.assert_debug(!P->isPeriodicGhostParticle(),"Can't add mpi particle as it does not exist");
224  //Somehwere a really new particle has been added, so to keep the ID's globally unique, we also update
225  //the unique value on all other processors
227  }
228 
229  //Add the particle to the ghost particle lists
231  //Check if this new particle requires an update in the mpi grid (interactionDistance).
233 
234  //Delete the particle that was supposed to be added (but was not)
235  if(!insertParticle)
236  {
237  delete P;
238  }
239 #endif
240 }
unsigned int getId() const
Returns the unique identifier of any particular object.
Definition: BaseObject.h:125
virtual void hGridUpdateParticle(BaseParticle *obj UNUSED)
Definition: DPMBase.cc:1695
virtual void hGridInsertParticle(BaseParticle *obj UNUSED)
Definition: DPMBase.cc:1688
void increaseId()
Definition: BaseHandler.h:251
virtual bool isSphericalParticle() const
Definition: BaseParticle.h:645
bool mpiInsertParticleCheck(BaseParticle *P)
Function that checks if the mpi particle should really be inserted by the current domain...
Definition: DPMBase.cc:1723
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
const ParticleSpecies * getSpecies() const
Returns a pointer to the species of this BaseInteractable.
void checkExtrema(BaseParticle *P)
Checks if the extrema of this ParticleHandler needs updating.
void setHandler(ParticleHandler *handler)
Sets the pointer to the particle's ParticleHandler.
void computeMass(BaseParticle *p) const
Compute Particle mass function, which required a reference to the Species vector. It computes the Par...
virtual void handleParticleAddition(unsigned int id, BaseParticle *p)
Definition: DPMBase.cc:5312
void updateGhostGrid(BaseParticle *P)
Checks if the Domain/periodic interaction distance needs to be updated and updates it accordingly...
Definition: DPMBase.cc:1828
bool isPeriodicGhostParticle() const
Indicates if this particle is a ghost in the periodic boundary.
#define NUMBER_OF_PROCESSORS
For the MPI communication routines this quantity is often required. defining this macro makes the cod...
Definition: GeneralDefine.h:62
void setPeriodicComplexity(std::vector< int > complexity)
Set the periodic communication complexity of the particle.
void insertGhostParticle(BaseParticle *P)
This function inserts a particle in the mpi communication boundaries.
Definition: DPMBase.cc:1802
bool isMPIParticle() const
Indicates if this particle is a ghost in the MPI domain.
virtual void addObject(T *object)
Adds a new Object to the BaseHandler.
Definition: BaseHandler.h:431
void setRotation(bool rotation)
Sets whether particle rotation is enabled or disabled.
Definition: DPMBase.h:552
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
void ParticleHandler::addObject ( int  fromProcessor,
BaseParticle p 
)

Adds a BaseParticle located at processor fromProcessor to toProcessor.

This function adds a particle to the simulation where the information of the particle is not available by the target processor.

When a certain processor generates a particle which needs to be inserted in a domain of another processor, this information needs to be transfered before the particle can be actually added

Parameters
[in]fromProcessorprocessor containing the particle data
[in,out]particlethat contains the data and receives the data

Definition at line 250 of file ParticleHandler.cc.

References addObject(), MPIContainer::broadcast(), copyDataFromMPIParticleToParticle(), MPISphericalParticle::copyDataFromParticleToMPIParticle(), MPIContainer::getProcessorID(), MPIContainer::Instance(), logger, PARTICLE, and WARN.

251 {
252 #ifdef MERCURY_USE_MPI
253  MPIContainer& communicator = MPIContainer::Instance();
254 
255  //The processor that contains the particle that needs to be copied needs to identify the target, and communicate this
256  MPIParticle pInfo;
257  if (communicator.getProcessorID() == fromProcessor)
258  {
260  }
261 
262  //Broadcast from processor i
263  communicator.broadcast(&pInfo,MercuryMPIType::PARTICLE,fromProcessor);
264  copyDataFromMPIParticleToParticle(&pInfo, p, this);
265 
266  //All processors now know have the same information and we can proceed with the collective add
267  addObject(p);
268 #else
269  logger(WARN, "Function addObject(int fromProcessor, BaseParticle* p) should not be used in serial code");
270 #endif
271 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:129
void copyDataFromParticleToMPIParticle(BaseParticle *p)
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:134
void addObject(BaseParticle *P) override
Adds a BaseParticle to the ParticleHandler.
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
void copyDataFromMPIParticleToParticle(MPIParticle *bP, BaseParticle *p, ParticleHandler *particleHandler)
Copies data from an MPIParticle class to a BaseParticle and sets the particleHandler and species...
std::size_t getProcessorID()
Reduces a scalar on all processors to one scalar on a target processor.
Data class to send a particle over MPI.
Definition: MpiDataClass.h:81
std::enable_if< std::is_scalar< T >::value, void >::type broadcast(T &t, int fromProcessor=0)
Broadcasts a scalar from the root to all other processors.
Definition: MpiContainer.h:441
void ParticleHandler::checkExtrema ( BaseParticle P)

Checks if the extrema of this ParticleHandler needs updating.

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

Definition at line 1156 of file ParticleHandler.cc.

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

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

1157 {
1158  if (P == largestParticle_)
1159  {
1160  //if the properties of the largest particle changes
1162  }
1164  {
1165  largestParticle_ = P;
1166  }
1167 
1168  if (P == smallestParticle_)
1169  {
1170  //if the properties of the smallest particle changes
1172  }
1174  {
1175  smallestParticle_ = P;
1176  }
1177 }
Mdouble getMaxInteractionRadius() const
Returns the particle's interaction radius, which might be different from radius_ (e.g., when dealing with wet particles)
Definition: BaseParticle.h:362
BaseParticle * smallestParticle_
A pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler.
BaseParticle * largestParticle_
A pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.
void computeSmallestParticle()
Computes the smallest particle (by interaction radius) and sets it in smallestParticle_.
void computeLargestParticle()
Computes the largest particle (by interaction radius) and sets it in largestParticle_.
void ParticleHandler::checkExtremaOnDelete ( BaseParticle P)

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

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

Definition at line 1182 of file ParticleHandler.cc.

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

Referenced by BaseParticle::~BaseParticle(), and SuperQuadricParticle::~SuperQuadricParticle().

1183 {
1184  if (P == largestParticle_)
1185  {
1187  }
1188  if (P == smallestParticle_)
1189  {
1191  }
1192 }
BaseParticle * smallestParticle_
A pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler.
BaseParticle * largestParticle_
A pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.
void computeSmallestParticle()
Computes the smallest particle (by interaction radius) and sets it in smallestParticle_.
void computeLargestParticle()
Computes the largest particle (by interaction radius) and sets it in largestParticle_.
void ParticleHandler::clear ( )
overridevirtual

Empties the whole ParticleHandler by removing all BaseParticle.

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

Reimplemented from BaseHandler< BaseParticle >.

Definition at line 972 of file ParticleHandler.cc.

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

Referenced by CGHandler::evaluateRestartFiles(), operator=(), ParticleHandler(), FileReader::read(), DPMBase::read(), DPMBase::readNextDataFile(), and BaseCluster::setupInitialConditions().

973 {
974  smallestParticle_ = nullptr;
975  largestParticle_ = nullptr;
977 }
BaseParticle * smallestParticle_
A pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler.
BaseParticle * largestParticle_
A pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.
virtual void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
Definition: BaseHandler.h:528
void ParticleHandler::computeAllMasses ( unsigned int  indSpecies)

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

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

Definition at line 1198 of file ParticleHandler.cc.

References BaseHandler< BaseParticle >::objects_.

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

1199 {
1200  for (BaseParticle* particle : objects_)
1201  {
1202  if (particle->getIndSpecies() == indSpecies)
1203  {
1204  particle->getSpecies()->computeMass(particle);
1205  }
1206  }
1207 }
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
void ParticleHandler::computeAllMasses ( )

Computes the mass for all BaseParticle in this ParticleHandler.

Definition at line 1209 of file ParticleHandler.cc.

References BaseHandler< BaseParticle >::objects_.

1210 {
1211  for (BaseParticle* particle : objects_)
1212  {
1213  particle->getSpecies()->computeMass(particle);
1214  }
1215 }
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
void ParticleHandler::computeLargestParticle ( )

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

Definition at line 470 of file ParticleHandler.cc.

References DEBUG, BaseParticle::getMaxInteractionRadius(), BaseHandler< BaseParticle >::getSize(), largestParticle_, logger, and BaseHandler< BaseParticle >::objects_.

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

471 {
472  if (getSize() == 0)
473  {
474  logger(DEBUG, "No particles, so cannot compute the largest particle.");
475  largestParticle_ = nullptr;
476  return;
477  }
478  Mdouble max = -std::numeric_limits<Mdouble>::max();
479  largestParticle_ = nullptr;
480  for (BaseParticle* const particle : objects_)
481  {
482  //if (!(particle->isMPIParticle() || particle->isPeriodicGhostParticle()))
483  {
484  if (particle->getMaxInteractionRadius() > max)
485  {
486  max = particle->getMaxInteractionRadius();
487  largestParticle_ = particle;
488  }
489  }
490  }
491 }
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
double Mdouble
Definition: GeneralDefine.h:34
Mdouble getMaxInteractionRadius() const
Returns the particle's interaction radius, which might be different from radius_ (e.g., when dealing with wet particles)
Definition: BaseParticle.h:362
BaseParticle * largestParticle_
A pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
void ParticleHandler::computeSmallestParticle ( )

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

Definition at line 446 of file ParticleHandler.cc.

References DEBUG, BaseParticle::getMaxInteractionRadius(), BaseHandler< BaseParticle >::getSize(), logger, BaseHandler< BaseParticle >::objects_, and smallestParticle_.

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

447 {
448  if (getSize() == 0)
449  {
450  logger(DEBUG, "No particles, so cannot compute the smallest particle.");
451 
452  smallestParticle_ = nullptr;
453  return;
454  }
455  Mdouble min = std::numeric_limits<Mdouble>::max();
456  smallestParticle_ = nullptr;
457  for (BaseParticle* const particle : objects_)
458  {
459  //if (!(particle->isMPIParticle() || particle->isPeriodicGhostParticle()))
460  {
461  if (particle->getMaxInteractionRadius() < min)
462  {
463  min = particle->getMaxInteractionRadius();
464  smallestParticle_ = particle;
465  }
466  }
467  }
468 }
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
double Mdouble
Definition: GeneralDefine.h:34
Mdouble getMaxInteractionRadius() const
Returns the particle's interaction radius, which might be different from radius_ (e.g., when dealing with wet particles)
Definition: BaseParticle.h:362
BaseParticle * smallestParticle_
A pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler.
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
BaseParticle * ParticleHandler::createObject ( const std::string &  type)
static

Reads BaseParticle into the ParticleHandler from restart data.

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

Definition at line 1014 of file ParticleHandler.cc.

References logger, and WARN.

Referenced by readAndCreateObject().

1015 {
1016  if (type == "BaseParticle") {
1017  //for backwards compatibility
1018  return new SphericalParticle;
1019  }
1020  else if (type == "SphericalParticle")
1021  {
1022  return new SphericalParticle;
1023  }
1024  else if (type == "LiquidFilmParticle")
1025  {
1026  return new LiquidFilmParticle;
1027  }
1028  else if (type == "SuperQuadricParticle")
1029  {
1030  return new SuperQuadricParticle;
1031  }
1032  else if (type == "ThermalParticle")
1033  {
1034  return new ThermalParticle;
1035  }
1036  else if (type == "HeatFluidCoupledParticle")
1037  {
1038  return new HeatFluidCoupledParticle;
1039  }
1040  else
1041  {
1042  logger(WARN, "Particle type % not understood in restart file. Particle will not be read.", type);
1043  return nullptr;
1044  }
1045 }
A spherical particle is the most simple particle used in MercuryDPM.
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
Class that implements particles which store both temperature/heat capacity and liquid content which i...
Vec3D ParticleHandler::getAngularMomentum ( ) const

Definition at line 670 of file ParticleHandler.cc.

References getMPISum().

671 {
672  Vec3D momentum = {0, 0, 0};
673  for (auto p : *this)
674  if (!(p->isFixed() || p->isMPIParticle() || p->isPeriodicGhostParticle()))
675  momentum += p->getAngularMomentum();
676  return getMPISum(momentum);
677 }
Vec3D getMPISum(Vec3D &val)
Sums the values over all processors using MPI_reduce.
Definition: Vector.h:49
Vec3D ParticleHandler::getCentreOfMass ( ) const

Definition at line 649 of file ParticleHandler.cc.

References getMass(), getMassTimesPosition(), and constants::NaN.

Referenced by DPMBase::getCentreOfMass().

650 {
651  Mdouble m = getMass();
652  if (m == 0)
653  {
654  Vec3D nanvec = {constants::NaN, constants::NaN, constants::NaN};
655  return nanvec;
656  }
657  else
658  return getMassTimesPosition() / m;
659 }
const Mdouble NaN
Definition: GeneralDefine.h:43
double Mdouble
Definition: GeneralDefine.h:34
Mdouble getMass() const
Vec3D getMassTimesPosition() const
Definition: Vector.h:49
BaseParticle * ParticleHandler::getFastestParticle ( ) const

Definition at line 705 of file ParticleHandler.cc.

References ERROR, getFastestParticleLocal(), and logger.

706 {
707 #ifdef MERCURY_USE_MPI
708  logger(ERROR,"This function should not be used in parallel");
709 #endif
710  return getFastestParticleLocal();
711 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
BaseParticle * getFastestParticleLocal() const
Gets a pointer to the fastest BaseParticle in this ParticleHandler.
BaseParticle * ParticleHandler::getFastestParticleLocal ( ) const

Gets a pointer to the fastest BaseParticle in this ParticleHandler.

Returns
A pointer to the fastest BaseParticle in this ParticleHandler.

Definition at line 682 of file ParticleHandler.cc.

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

Referenced by getFastestParticle().

683 {
684  if (getSize() == 0)
685  {
686  logger(WARN, "No particles to set getFastestParticle()");
687  return nullptr;
688  }
689  BaseParticle* p = nullptr;
690  Mdouble maxSpeed = -std::numeric_limits<Mdouble>::max();
691  for (BaseParticle* const pLoop : objects_)
692  {
693  if (!(pLoop->isMPIParticle() || pLoop->isPeriodicGhostParticle()))
694  {
695  if ((pLoop->getVelocity().getLength()) > maxSpeed)
696  {
697  maxSpeed = pLoop->getVelocity().getLength();
698  p = pLoop;
699  }
700  }
701  }
702  return p;
703 }
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
double Mdouble
Definition: GeneralDefine.h:34
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
BaseParticle * ParticleHandler::getHighestPositionComponentParticle ( int  i) const

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

Definition at line 887 of file ParticleHandler.cc.

References ERROR, getHighestPositionComponentParticleLocal(), and logger.

888 {
889 #ifdef MERCURY_USE_MPI
890  logger(ERROR,"This function should not be used in parallel");
891 #endif
893 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
BaseParticle * getHighestPositionComponentParticleLocal(int i) const
Gets a pointer to the particle with the highest coordinates in direction i in this ParticleHandler...
BaseParticle * ParticleHandler::getHighestPositionComponentParticleLocal ( int  i) const

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

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

Definition at line 863 of file ParticleHandler.cc.

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

Referenced by getHighestPositionComponentParticle().

864 {
865  if (getSize() == 0)
866  {
867  logger(WARN, "No getHighestPositionComponentParticle(const int i) since there are no particles.");
868  return nullptr;
869  }
870  BaseParticle* p = nullptr;
871  Mdouble max = -std::numeric_limits<Mdouble>::max();
872  for (BaseParticle* const pLoop : objects_)
873  {
874  if (!(pLoop->isMPIParticle() || pLoop->isPeriodicGhostParticle()))
875  {
876  if (pLoop->getPosition().getComponent(i) > max)
877  {
878  max = pLoop->getPosition().getComponent(i);
879  p = pLoop;
880  }
881  }
882  }
883 
884  return p;
885 }
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
double Mdouble
Definition: GeneralDefine.h:34
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
Mdouble ParticleHandler::getHighestPositionX ( ) const

Function returns the highest position in the x-direction.

This is a prototype example of how to obtain global particle attributes in the parallel code

Returns
Returns the highest x-position value of all particles

Definition at line 984 of file ParticleHandler.cc.

References MAX.

985 {
986  //Define the attribute function
987  std::function<Mdouble(BaseParticle*)> particleAttribute = [](BaseParticle* p) { return p->getPosition().X; };
988 
989  //Obtain the MAX attribute
990  Mdouble positionXGlobal = getParticleAttribute<Mdouble>(particleAttribute, AttributeType::MAX);
991 
992  return positionXGlobal;
993 }
double Mdouble
Definition: GeneralDefine.h:34
BaseParticle * ParticleHandler::getHighestVelocityComponentParticle ( int  i) const

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

Definition at line 959 of file ParticleHandler.cc.

References ERROR, getHighestVelocityComponentParticleLocal(), and logger.

960 {
961 #ifdef MERCURY_USE_MPI
962  logger(ERROR,"This function should not be used in parallel");
963 #endif
965 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
BaseParticle * getHighestVelocityComponentParticleLocal(int i) const
Gets a pointer to the particle with the highest velocity in direction i in this ParticleHandler.
BaseParticle * ParticleHandler::getHighestVelocityComponentParticleLocal ( int  i) const

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

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

Definition at line 936 of file ParticleHandler.cc.

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

Referenced by getHighestVelocityComponentParticle().

937 {
938  if (!getSize())
939  {
940  logger(WARN, "No getHighestVelocityComponentParticle(const int i) since there are no particles");
941  return nullptr;
942  }
943  BaseParticle* p = nullptr;
944  Mdouble max = -std::numeric_limits<Mdouble>::max();
945  for (BaseParticle* const pLoop : objects_)
946  {
947  if (!(pLoop->isMPIParticle() || pLoop->isPeriodicGhostParticle()))
948  {
949  if (pLoop->getVelocity().getComponent(i) > max)
950  {
951  max = pLoop->getVelocity().getComponent(i);
952  p = pLoop;
953  }
954  }
955  }
956  return p;
957 }
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
double Mdouble
Definition: GeneralDefine.h:34
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
Mdouble ParticleHandler::getKineticEnergy ( ) const

Definition at line 552 of file ParticleHandler.cc.

References getKineticEnergyLocal(), and MPIContainer::Instance().

Referenced by DPMBase::writeEneTimeStep().

553 {
554 #ifdef MERCURY_USE_MPI
555  Mdouble kineticEnergyLocal = getKineticEnergyLocal();
556  Mdouble kineticEnergyGlobal = 0.0;
557 
558  //sum up over all domains
559  MPIContainer& communicator = MPIContainer::Instance();
560  communicator.allReduce(kineticEnergyLocal, kineticEnergyGlobal, MPI_SUM);
561 
562  return kineticEnergyGlobal;
563 #else
564  return getKineticEnergyLocal();
565 #endif
566 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:129
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:134
double Mdouble
Definition: GeneralDefine.h:34
Mdouble getKineticEnergyLocal() const
Mdouble ParticleHandler::getKineticEnergyLocal ( ) const
private

Definition at line 539 of file ParticleHandler.cc.

Referenced by getKineticEnergy().

540 {
541  Mdouble ene = 0;
542  for (auto p : *this)
543  {
544  if (!(p->isMPIParticle() || p->isPeriodicGhostParticle()))
545  {
546  ene += p->getKineticEnergy();
547  }
548  }
549  return ene;
550 }
double Mdouble
Definition: GeneralDefine.h:34
Mdouble ParticleHandler::getLargestInteractionRadius ( ) const

Returns the largest interaction radius.

Definition at line 767 of file ParticleHandler.cc.

References getLargestInteractionRadiusLocal(), and MPIContainer::Instance().

Referenced by DPMBase::read().

768 {
769 #ifdef MERCURY_USE_MPI
770  Mdouble largestInteractionRadiusLocal = getLargestInteractionRadiusLocal();
771  Mdouble largestInteractionRadiusGlobal = 0.0;
772 
773  //Obtain the global value
774  MPIContainer& communicator = MPIContainer::Instance();
775  communicator.allReduce(largestInteractionRadiusLocal, largestInteractionRadiusGlobal, MPI_MAX);
776 
777  return largestInteractionRadiusGlobal;
778 #else
780 #endif
781 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:129
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:134
double Mdouble
Definition: GeneralDefine.h:34
Mdouble getLargestInteractionRadiusLocal() const
Returns the largest interaction radius of the current domain.
Mdouble ParticleHandler::getLargestInteractionRadiusLocal ( ) const

Returns the largest interaction radius of the current domain.

Definition at line 752 of file ParticleHandler.cc.

References getLargestParticle(), getLargestParticleLocal(), and BaseParticle::getMaxInteractionRadius().

Referenced by MercuryBase::getHGridTargetMaxInteractionRadius(), and getLargestInteractionRadius().

753 {
754  if (!(getLargestParticleLocal() == nullptr))
755  {
757  }
758  else
759  {
760  return 0.0;
761  }
762 }
BaseParticle * getLargestParticle() const
Returns the pointer of the largest particle in the particle handler. When mercury is running in paral...
Mdouble getMaxInteractionRadius() const
Returns the particle's interaction radius, which might be different from radius_ (e.g., when dealing with wet particles)
Definition: BaseParticle.h:362
BaseParticle * getLargestParticleLocal() const
Gets a pointer to the largest BaseParticle (by interactionRadius) in the ParticleHandler of the local...
BaseParticle * ParticleHandler::getLargestParticle ( ) const

Returns the pointer of the largest particle in the particle handler. When mercury is running in parallel this function throws an error since a pointer to another domain is useless.

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

Definition at line 529 of file ParticleHandler.cc.

References getLargestParticleLocal(), logger, and WARN.

Referenced by DPMBase::checkParticleForInteractionLocalPeriodic(), ShearBoxBoundary::createHorizontalPeriodicParticles(), LeesEdwardsBoundary::createHorizontalPeriodicParticles(), CircularPeriodicBoundary::createPeriodicParticle(), SubcriticalMaserBoundaryTEST::createPeriodicParticle(), AngledPeriodicBoundary::createPeriodicParticle(), SubcriticalMaserBoundary::createPeriodicParticle(), PeriodicBoundary::createPeriodicParticle(), TimeDependentPeriodicBoundary::createPeriodicParticle(), ShearBoxBoundary::createVerticalPeriodicParticles(), LeesEdwardsBoundary::createVerticalPeriodicParticles(), getLargestInteractionRadiusLocal(), MercuryBase::hGridNeedsRebuilding(), HGridOptimiser::initialise(), and BaseCluster::setupInitialConditions().

530 {
531 #ifdef MERCURY_USE_MPIO
532  logger(WARN,"getLargestParticle() should not be used in parallel; use getLargestInteractionRadius instead");
533  return nullptr;
534 #else
535  return getLargestParticleLocal();
536 #endif
537 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
BaseParticle * getLargestParticleLocal() const
Gets a pointer to the largest BaseParticle (by interactionRadius) in the ParticleHandler of the local...
BaseParticle * ParticleHandler::getLargestParticleLocal ( ) const

Gets a pointer to the largest BaseParticle (by interactionRadius) in the ParticleHandler of the local domain.

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

Definition at line 521 of file ParticleHandler.cc.

References largestParticle_.

Referenced by ConstantMassFlowMaserBoundary::activateMaser(), ConstantMassFlowMaserBoundary::createPeriodicParticle(), getLargestInteractionRadiusLocal(), getLargestParticle(), and DPMBase::writeFstatHeader().

522 {
523  return largestParticle_;
524 }
BaseParticle * largestParticle_
A pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.
double ParticleHandler::getLiquidFilmVolume ( ) const

Definition at line 1363 of file ParticleHandler.cc.

References LiquidFilmParticle::getLiquidVolume(), getMPISum(), constants::i, and BaseHandler< BaseParticle >::objects_.

1363  {
1364  double liquidVolume = 0;
1365  for (auto i : objects_) {
1366  auto j = dynamic_cast<LiquidFilmParticle*>(i);
1367  if (j and !j->isMPIParticle()) liquidVolume += j->getLiquidVolume();
1368  }
1369  return getMPISum(liquidVolume);
1370 };
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
Vec3D getMPISum(Vec3D &val)
Sums the values over all processors using MPI_reduce.
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
Mdouble getLiquidVolume() const
BaseParticle * ParticleHandler::getLowestPositionComponentParticle ( int  i) const

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

Definition at line 850 of file ParticleHandler.cc.

References ERROR, getLowestPositionComponentParticleLocal(), and logger.

851 {
852 #ifdef MERCURY_USE_MPI
853  logger(ERROR,"This function should not be used in parallel");
854 #endif
856 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
BaseParticle * getLowestPositionComponentParticleLocal(int i) const
Gets a pointer to the particle with the lowest coordinates in direction i in this ParticleHandler...
BaseParticle * ParticleHandler::getLowestPositionComponentParticleLocal ( int  i) const

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

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

Definition at line 824 of file ParticleHandler.cc.

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

Referenced by getLowestPositionComponentParticle().

825 {
826 #ifdef MERCURY_USE_MPI
827  logger(ERROR,"getLowestPositionComponentParticle() not implemented yet in parallel");
828 #endif
829  if (getSize() == 0)
830  {
831  logger(WARN, "No getLowestPositionComponentParticle(const int i) since there are no particles.");
832  return nullptr;
833  }
834  BaseParticle* p = nullptr;
835  Mdouble min = std::numeric_limits<Mdouble>::max();
836  for (BaseParticle* const pLoop : objects_)
837  {
838  if (!(pLoop->isMPIParticle() || pLoop->isPeriodicGhostParticle()))
839  {
840  if (pLoop->getPosition().getComponent(i) < min)
841  {
842  min = pLoop->getPosition().getComponent(i);
843  p = pLoop;
844  }
845  }
846  }
847  return p;
848 }
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
double Mdouble
Definition: GeneralDefine.h:34
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
BaseParticle * ParticleHandler::getLowestVelocityComponentParticle ( int  i) const

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

Definition at line 923 of file ParticleHandler.cc.

References ERROR, getLowestVelocityComponentParticleLocal(), and logger.

924 {
925 #ifdef MERCURY_USE_MPI
926  logger(ERROR,"This function should not be used in parallel");
927 #endif
929 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
BaseParticle * getLowestVelocityComponentParticleLocal(int i) const
Gets a pointer to the particle with the lowest velocity in direction i in this ParticleHandler.
BaseParticle * ParticleHandler::getLowestVelocityComponentParticleLocal ( int  i) const

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

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

Definition at line 900 of file ParticleHandler.cc.

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

Referenced by getLowestVelocityComponentParticle().

901 {
902  if (getSize() == 0)
903  {
904  logger(WARN, "No getLowestVelocityComponentParticle(const int i) since there are no particles");
905  return nullptr;
906  }
907  BaseParticle* p = nullptr;
908  Mdouble min = std::numeric_limits<Mdouble>::max();
909  for (BaseParticle* const pLoop : objects_)
910  {
911  if (!(pLoop->isMPIParticle() || pLoop->isPeriodicGhostParticle()))
912  {
913  if (pLoop->getVelocity().getComponent(i) < min)
914  {
915  min = pLoop->getVelocity().getComponent(i);
916  p = pLoop;
917  }
918  }
919  }
920  return p;
921 }
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
double Mdouble
Definition: GeneralDefine.h:34
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
Mdouble ParticleHandler::getMass ( ) const

Definition at line 606 of file ParticleHandler.cc.

References getMassLocal(), and MPIContainer::Instance().

Referenced by FixedClusterInsertionBoundary::checkBoundaryBeforeTimeStep(), RandomClusterInsertionBoundary::checkBoundaryBeforeTimeStep(), getCentreOfMass(), DPMBase::getTotalMass(), and DPMBase::writeEneTimeStep().

607 {
608 #ifdef MERCURY_USE_MPI
609  Mdouble massLocal = getMassLocal();
610  Mdouble massGlobal = 0.0;
611 
612  //Sum up over all domains
613  MPIContainer& communicator = MPIContainer::Instance();
614  communicator.allReduce(massLocal, massGlobal, MPI_SUM);
615 
616  return massGlobal;
617 #else
618  return getMassLocal();
619 #endif
620 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:129
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:134
double Mdouble
Definition: GeneralDefine.h:34
Mdouble getMassLocal() const
Mdouble ParticleHandler::getMassLocal ( ) const
private

Definition at line 597 of file ParticleHandler.cc.

Referenced by getMass().

598 {
599  Mdouble m = 0;
600  for (auto p : *this)
601  if (!(p->isFixed() || p->isMPIParticle() || p->isPeriodicGhostParticle()))
602  m += p->getMass();
603  return m;
604 }
double Mdouble
Definition: GeneralDefine.h:34
Vec3D ParticleHandler::getMassTimesPosition ( ) const

Definition at line 631 of file ParticleHandler.cc.

References getMassTimesPositionLocal(), MPIContainer::Instance(), Vec3D::X, Vec3D::Y, and Vec3D::Z.

Referenced by getCentreOfMass(), and DPMBase::writeEneTimeStep().

632 {
633 #ifdef MERCURY_USE_MPI
634  Vec3D massTimesPositionLocal = getMassTimesPositionLocal();
635  Vec3D massTimesPositionGlobal = {0.0, 0.0, 0.0};
636 
637  // Sum up over all domains
638  MPIContainer& communicator = MPIContainer::Instance();
639  communicator.allReduce(massTimesPositionLocal.X, massTimesPositionGlobal.X, MPI_SUM);
640  communicator.allReduce(massTimesPositionLocal.Y, massTimesPositionGlobal.Y, MPI_SUM);
641  communicator.allReduce(massTimesPositionLocal.Z, massTimesPositionGlobal.Z, MPI_SUM);
642 
643  return massTimesPositionGlobal;
644 #else
645  return getMassTimesPositionLocal();
646 #endif
647 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:129
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:134
Mdouble X
the vector components
Definition: Vector.h:65
Mdouble Y
Definition: Vector.h:65
Vec3D getMassTimesPositionLocal() const
Definition: Vector.h:49
Mdouble Z
Definition: Vector.h:65
Vec3D ParticleHandler::getMassTimesPositionLocal ( ) const
private

Definition at line 622 of file ParticleHandler.cc.

Referenced by getMassTimesPosition().

623 {
624  Vec3D com = {0, 0, 0};
625  for (auto p : *this)
626  if (!(p->isFixed() || p->isMPIParticle() || p->isPeriodicGhostParticle()))
627  com += p->getMass() * p->getPosition();
628  return com;
629 }
Definition: Vector.h:49
Mdouble ParticleHandler::getMeanRadius ( ) const

Definition at line 799 of file ParticleHandler.cc.

References getNumberOfRealObjectsLocal(), BaseHandler< BaseParticle >::getSize(), getSumRadiusLocal(), and MPIContainer::Instance().

800 {
801 #ifdef MERCURY_USE_MPI
802  Mdouble sumRadiusLocal = getSumRadiusLocal();
803  unsigned numberOfRealParticlesLocal = getNumberOfRealObjectsLocal();
804 
805  Mdouble sumRadiusGlobal = 0.0;
806  unsigned numberOfRealParticlesGlobal = 0;
807 
808  //Sum up over all domains
809  MPIContainer& communicator = MPIContainer::Instance();
810  communicator.allReduce(sumRadiusLocal, sumRadiusGlobal, MPI_SUM);
811  communicator.allReduce(numberOfRealParticlesLocal, numberOfRealParticlesGlobal, MPI_SUM);
812 
813  return sumRadiusGlobal/numberOfRealParticlesGlobal;
814 #else
815  return getSumRadiusLocal() / getSize();
816 #endif
817 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:129
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:134
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
double Mdouble
Definition: GeneralDefine.h:34
Mdouble getSumRadiusLocal() const
unsigned int getNumberOfRealObjectsLocal() const
Returns the number of real objects on a local domain. MPI particles and periodic particles are neglec...
Vec3D ParticleHandler::getMomentum ( ) const

Definition at line 661 of file ParticleHandler.cc.

References getMPISum().

Referenced by DPMBase::getTotalMomentum().

662 {
663  Vec3D momentum = {0, 0, 0};
664  for (auto p : *this)
665  if (!(p->isFixed() || p->isMPIParticle() || p->isPeriodicGhostParticle()))
666  momentum += p->getMomentum();
667  return getMPISum(momentum);
668 }
Vec3D getMPISum(Vec3D &val)
Sums the values over all processors using MPI_reduce.
Definition: Vector.h:49
std::string ParticleHandler::getName ( ) const
overridevirtual

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

Returns
The string "ParticleHandler".

Implements BaseHandler< BaseParticle >.

Definition at line 1230 of file ParticleHandler.cc.

1231 {
1232  return "ParticleHandler";
1233 }
unsigned int ParticleHandler::getNumberOfFixedObjects ( ) const

Computes the number of fixed particles in the whole simulation.

Definition at line 1341 of file ParticleHandler.cc.

References getNumberOfFixedObjectsLocal(), and MPIContainer::Instance().

1342 {
1343 #ifdef MERCURY_USE_MPI
1344  unsigned int numberOfFixedParticlesLocal = getNumberOfFixedObjectsLocal();
1345  unsigned int numberOfFixedParticles = 0;
1346 
1347  MPIContainer& communicator = MPIContainer::Instance();
1348  communicator.allReduce(numberOfFixedParticlesLocal, numberOfFixedParticles, MPI_SUM);
1349  return numberOfFixedParticles;
1350 #else
1352 #endif
1353 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:129
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:134
unsigned int getNumberOfFixedObjectsLocal() const
Computes the number of Fixed particles on a local domain.
unsigned int ParticleHandler::getNumberOfFixedObjectsLocal ( ) const

Computes the number of Fixed particles on a local domain.

Loops over all particles to check if the particle is fixed or not, in a local domain.

Returns
the number of fixed particles in a local domain

Definition at line 1325 of file ParticleHandler.cc.

References BaseParticle::isFixed().

Referenced by getNumberOfFixedObjects().

1326 {
1327  unsigned int numberOfFixedParticles = 0;
1328  for (BaseParticle* particle : *this)
1329  {
1330  if (particle->isFixed())
1331  {
1332  numberOfFixedParticles++;
1333  }
1334  }
1335  return numberOfFixedParticles;
1336 }
bool isFixed() const override
Is fixed Particle function. It returns whether a Particle is fixed or not, by checking its inverse Ma...
Definition: BaseParticle.h:93
unsigned int ParticleHandler::getNumberOfFixedParticles ( ) const

Gets the number of particles that are fixed.

Definition at line 998 of file ParticleHandler.cc.

References NFixedParticles_.

999 {
1000  return NFixedParticles_;
1001 }
unsigned int NFixedParticles_
Number of fixed particles.
unsigned int ParticleHandler::getNumberOfObjects ( ) const
overridevirtual

Returns the number of objects in the container. In parallel code this practice is forbidden to avoid confusion with real and fake particles. If the size of the container is wished, call size()

Reimplemented from BaseHandler< BaseParticle >.

Definition at line 1308 of file ParticleHandler.cc.

References BaseHandler< BaseParticle >::getSize().

Referenced by Chute::addFlowParticlesCompactly(), DPMBase::checkParticleForInteractionLocalPeriodic(), Chute::cleanChute(), getNumberOfUnfixedParticles(), Chute::printTime(), MeshTriangle::setHandler(), and ChuteBottom::setupInitialConditions().

1309 {
1310 //#ifdef MERCURY_USE_MPI
1311 // MPIContainer& communicator = MPIContainer::Instance();
1312 // if (communicator.getNumberOfProcessors() > 1)
1313 // {
1314 // logger(WARN,"When compiling with MPI please do not use getNumberOfObjects(). Instead use: getNumberOfRealObjectsLocal(), getNumberOfRealObjects() or getSize()");
1315 // }
1316 //#endif
1317  return getSize();
1318 }
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
unsigned int ParticleHandler::getNumberOfRealObjects ( ) const

Returns the number of real objects (on all processors)

Definition at line 1287 of file ParticleHandler.cc.

References MPIContainer::broadcast(), getNumberOfRealObjectsLocal(), BaseHandler< BaseParticle >::getSize(), and MPIContainer::Instance().

Referenced by Membrane::createVertexParticles(), and DPMBase::decompose().

1288 {
1289 #ifdef MERCURY_USE_MPI
1290  MPIContainer& communicator = MPIContainer::Instance();
1291  unsigned int numberOfRealParticles = getNumberOfRealObjectsLocal();
1292 
1293  // \todo MX: use an allreduce here
1294  //Combine the total number of Particles into one number on processor 0
1295  communicator.reduce(numberOfRealParticles, MPI_SUM);
1296 
1297  //Broadcast new number to all the processorsi
1298  communicator.broadcast(numberOfRealParticles);
1299  return numberOfRealParticles;
1300 #else
1301  return getSize();
1302 #endif
1303 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:129
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:134
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
unsigned int getNumberOfRealObjectsLocal() const
Returns the number of real objects on a local domain. MPI particles and periodic particles are neglec...
std::enable_if< std::is_scalar< T >::value, void >::type broadcast(T &t, int fromProcessor=0)
Broadcasts a scalar from the root to all other processors.
Definition: MpiContainer.h:441
unsigned int ParticleHandler::getNumberOfRealObjectsLocal ( ) const

Returns the number of real objects on a local domain. MPI particles and periodic particles are neglected.

Returns
the number of real particles (neglecting MPI and periodic) on a local domain
Todo:
MX: in future also add the periodic mpi particles

Definition at line 1266 of file ParticleHandler.cc.

References DPMBase::domainHandler, DomainHandler::getCurrentDomain(), BaseHandler< BaseParticle >::getDPMBase(), PeriodicBoundaryHandler::getNumberOfPeriodicGhostParticles(), MPIContainer::getNumberOfProcessors(), Domain::getNumberOfTrueMPIParticles(), BaseHandler< BaseParticle >::getSize(), MPIContainer::Instance(), logger, and DPMBase::periodicBoundaryHandler.

Referenced by getMeanRadius(), getNumberOfRealObjects(), DPMBase::outputXBallsData(), and write().

1267 {
1268 #ifdef MERCURY_USE_MPI
1269  const MPIContainer& communicator = MPIContainer::Instance();
1270  if (communicator.getNumberOfProcessors() > 1)
1271  {
1272  unsigned int numberOfFakeParticles = 0;
1273  numberOfFakeParticles += getDPMBase()->domainHandler.getCurrentDomain()->getNumberOfTrueMPIParticles();
1275  logger.assert_debug(numberOfFakeParticles <= getSize(), "More fake particles than getSize()");
1276  return (getSize() - numberOfFakeParticles);
1277  }
1278  else
1279  {
1280  return getSize();
1281  }
1282 #else
1283  return getSize();
1284 #endif
1285 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:129
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:134
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
std::size_t getNumberOfProcessors() const
Get the total number of processors participating in this simulation.
DomainHandler domainHandler
An object of the class DomainHandler which deals with parallel code.
Definition: DPMBase.h:1420
unsigned int getNumberOfTrueMPIParticles()
Obtains the number of particles in the particleHandler that are MPIParticles, but NOT periodic partic...
Definition: Domain.cc:1679
PeriodicBoundaryHandler periodicBoundaryHandler
Internal handler that deals with periodic boundaries, especially in a parallel build.
Definition: DPMBase.h:1415
unsigned int getNumberOfPeriodicGhostParticles()
Returns the number of particles that are flagged is periodicGhostParticle.
Domain * getCurrentDomain()
Gets the domain assigned to the processor.
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
unsigned int ParticleHandler::getNumberOfUnfixedParticles ( ) const

Gets the number of particles that are not fixed.

Definition at line 1006 of file ParticleHandler.cc.

References getNumberOfObjects(), and NFixedParticles_.

1007 {
1009 }
unsigned int getNumberOfObjects() const override
Returns the number of objects in the container. In parallel code this practice is forbidden to avoid ...
unsigned int NFixedParticles_
Number of fixed particles.
template<typename T >
std::enable_if<std::is_scalar<T>::value, T>::type ParticleHandler::getParticleAttribute ( std::function< T(BaseParticle *)>  attribute,
AttributeType  type 
) const
inline

Computes an attribute type (min/max/..) of a particle attribute(position/velocity) in the global domain.

Many functions the particleHandler return a pointer to a BaseParticle, i.e. the fastest particle, however in parallel this is not usefull as pointers can't be send across processes. This function gives the flexibility to find a global particle extremum such as the fastest particle Velocity or lowest particle position.

Parameters
[in]attributeA function that obtains a scalar from a particle. i.e. position or radius
[in]typeAn AttribyteType tells this function what to do with the attribute, take the maximum or the minimum
Returns
Returns a scalar value representing the AttributeType of the Attribute: In easier terms returns the max/min/... of a particle atribute such as radius

Definition at line 305 of file ParticleHandler.h.

References ERROR, getParticleAttributeLocal(), MPIContainer::Instance(), logger, MAX, and MIN.

306  {
307 #ifdef MERCURY_USE_MPI
308  T particleAttributeLocal = getParticleAttributeLocal(attribute, type);
309  T particleAttributeGlobal;
310 
311  //Communicate local to global using the approriate rule
312  MPIContainer& communicator = MPIContainer::Instance();
313  switch(type)
314  {
315  case AttributeType::MIN :
316  communicator.allReduce(particleAttributeLocal,particleAttributeGlobal,MPI_MIN);
317  break;
318  case AttributeType::MAX :
319  communicator.allReduce(particleAttributeLocal,particleAttributeGlobal,MPI_MAX);
320  break;
321  default :
322  logger(ERROR,"Attribute type is not recognised");
323  break;
324  }
325  return particleAttributeGlobal;
326 #else
327  return getParticleAttributeLocal(attribute, type);
328 #endif
329  }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:129
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:134
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
std::enable_if< std::is_scalar< T >::value, T >::type getParticleAttributeLocal(std::function< T(BaseParticle *)> attribute, AttributeType type) const
Computes an attribute type (min/max/..) of a particle attribute (position/velocity) in a local domain...
template<typename T >
std::enable_if<std::is_scalar<T>::value, T>::type ParticleHandler::getParticleAttributeLocal ( std::function< T(BaseParticle *)>  attribute,
AttributeType  type 
) const
inline

Computes an attribute type (min/max/..) of a particle attribute (position/velocity) in a local domain.

Computes an attribute type (min/max/..) of a particle attribute (position/velocity) in a local domain

Many functions the particleHandler return a pointer to a BaseParticle, i.e. the fastest particle, however in parallel this is not usefull as pointers can't be send across processes. This function gives the flexibility to find a global particle extremum such as the fastest particle Velocity or lowest particle position.

Parameters
[in]attributeA function that obtains a scalar from a particle. i.e. position or radius
[in]typeAn AttribyteType tells this function what to do with the attribute, take the maximum or the minimum
Returns
Returns a scalar value representing the AttributeType of the Attribute: In easier terms returns the max/min/... of a particle atribute such as radius

Definition at line 244 of file ParticleHandler.h.

References ERROR, logger, MAX, MIN, BaseHandler< BaseParticle >::objects_, and WARN.

Referenced by getParticleAttribute().

245  {
246  T attributeParticle;
247  T attributeFinal;
248 
249  if ((*this).getSize() == 0)
250  {
251  logger(WARN, "ParticleHandler is empty: returning 0.0");
252  attributeFinal = 0;
253  return 0.0;
254  }
255  else
256  {
257  //Initialise with the first particle found
258  attributeParticle = attribute(objects_[0]);
259  attributeFinal = attributeParticle;
260 
261  //Findn the final attribute
262  for (BaseParticle* particle : (*this))
263  {
264  //Obtain the attribute
265  if (!(particle->isMPIParticle() || particle->isPeriodicGhostParticle() || particle->isFixed()))
266  {
267  attributeParticle = attribute(particle);
268  }
269 
270  //Decide what to do with the magnitude of the attribute
271  switch (type)
272  {
273  case AttributeType::MIN :
274  if (attributeParticle < attributeFinal)
275  {
276  attributeFinal = attributeParticle;
277  }
278  break;
279  case AttributeType::MAX :
280  if (attributeParticle > attributeFinal)
281  {
282  attributeFinal = attributeParticle;
283  }
284  break;
285  default :
286  logger(ERROR, "Attribute type is not recognised");
287  break;
288  }
289  }
290  return attributeFinal;
291  }
292  }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
Mdouble ParticleHandler::getRotationalEnergy ( ) const

Definition at line 581 of file ParticleHandler.cc.

References getRotationalEnergyLocal(), and MPIContainer::Instance().

Referenced by DPMBase::writeEneTimeStep().

582 {
583 #ifdef MERCURY_USE_MPI
584  Mdouble rotationalEnergyLocal = getRotationalEnergyLocal();
585  Mdouble rotationalEnergyGlobal = 0.0;
586 
587  //sum up over all domains
588  MPIContainer& communicator = MPIContainer::Instance();
589  communicator.allReduce(rotationalEnergyLocal, rotationalEnergyGlobal, MPI_SUM);
590 
591  return rotationalEnergyGlobal;
592 #else
593  return getRotationalEnergyLocal();
594 #endif
595 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:129
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:134
double Mdouble
Definition: GeneralDefine.h:34
Mdouble getRotationalEnergyLocal() const
Mdouble ParticleHandler::getRotationalEnergyLocal ( ) const
private

Definition at line 568 of file ParticleHandler.cc.

Referenced by getRotationalEnergy().

569 {
570  Mdouble ene = 0;
571  for (auto p : *this)
572  {
573  if (!(p->isMPIParticle() || p->isPeriodicGhostParticle()))
574  {
575  ene += p->getRotationalEnergy();
576  }
577  }
578  return ene;
579 }
double Mdouble
Definition: GeneralDefine.h:34
Mdouble ParticleHandler::getSmallestInteractionRadius ( ) const

Returns the smallest interaction radius.

Definition at line 731 of file ParticleHandler.cc.

References getSmallestInteractionRadiusLocal(), and MPIContainer::Instance().

732 {
733 #ifdef MERCURY_USE_MPI
734  //Compute the local value
735  Mdouble smallestInteractionRadiusLocal = getSmallestInteractionRadiusLocal();
736  Mdouble smallestInteractionRadiusGlobal = 0.0;
737 
738  //Obtain the global value
739  MPIContainer& communicator = MPIContainer::Instance();
740  communicator.allReduce(smallestInteractionRadiusLocal, smallestInteractionRadiusGlobal, MPI_MIN);
741 
742  return smallestInteractionRadiusGlobal;
743 
744 #else
746 #endif
747 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:129
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:134
double Mdouble
Definition: GeneralDefine.h:34
Mdouble getSmallestInteractionRadiusLocal() const
Returns the smallest interaction radius of the current domain.
Mdouble ParticleHandler::getSmallestInteractionRadiusLocal ( ) const

Returns the smallest interaction radius of the current domain.

Definition at line 716 of file ParticleHandler.cc.

References BaseParticle::getMaxInteractionRadius(), and getSmallestParticleLocal().

Referenced by MercuryBase::getHGridTargetMinInteractionRadius(), and getSmallestInteractionRadius().

717 {
718  if (!(getSmallestParticleLocal() == nullptr))
719  {
721  }
722  else
723  {
724  return 0.0;
725  }
726 }
Mdouble getMaxInteractionRadius() const
Returns the particle's interaction radius, which might be different from radius_ (e.g., when dealing with wet particles)
Definition: BaseParticle.h:362
BaseParticle * getSmallestParticleLocal() const
Gets a pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler of the loc...
BaseParticle * ParticleHandler::getSmallestParticle ( ) const

Gets a pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler of the local domain. When mercury is running in parallel this function throws an error since a pointer to another domain is useless.

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

Definition at line 506 of file ParticleHandler.cc.

References getSmallestParticleLocal(), logger, and WARN.

Referenced by HGridOptimiser::initialise().

507 {
508 #ifdef MERCURY_USE_MPI
509  logger(WARN,"getSmallestParticle should not be used in parallel; use getSmallestInteractionRadius or "
510  "ParticleSpecies::getSmallestParticleMass instead");
511  return nullptr;
512 #else
513  return getSmallestParticleLocal();
514 #endif
515 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
BaseParticle * getSmallestParticleLocal() const
Gets a pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler of the loc...
BaseParticle * ParticleHandler::getSmallestParticleLocal ( ) const

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

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

Definition at line 497 of file ParticleHandler.cc.

References smallestParticle_.

Referenced by getSmallestInteractionRadiusLocal(), getSmallestParticle(), and DPMBase::writeFstatHeader().

498 {
499  return smallestParticle_;
500 }
BaseParticle * smallestParticle_
A pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler.
Mdouble ParticleHandler::getSumRadiusLocal ( ) const
private
Returns
The sum of all particle radii

Definition at line 786 of file ParticleHandler.cc.

References BaseHandler< BaseParticle >::objects_.

Referenced by getMeanRadius().

787 {
788  Mdouble sumRadius = 0;
789  for (BaseParticle* const p : objects_)
790  {
791  if (!(p->isMPIParticle() || p->isPeriodicGhostParticle()))
792  {
793  sumRadius += p->getRadius();
794  }
795  }
796  return sumRadius;
797 }
double Mdouble
Definition: GeneralDefine.h:34
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
Mdouble ParticleHandler::getVolume ( ) const

Definition at line 1246 of file ParticleHandler.cc.

References getVolumeLocal(), and MPIContainer::Instance().

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

1247 {
1248 #ifdef MERCURY_USE_MPI
1249  Mdouble volumeLocal = getVolumeLocal();
1250  Mdouble volumeGlobal = 0.0;
1251 
1252  // sum up over all domains
1253  MPIContainer& communicator = MPIContainer::Instance();
1254  communicator.allReduce(volumeLocal, volumeGlobal, MPI_SUM);
1255 
1256  return volumeGlobal;
1257 #else
1258  return getVolumeLocal();
1259 #endif
1260 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:129
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:134
double Mdouble
Definition: GeneralDefine.h:34
Mdouble getVolumeLocal() const
Mdouble ParticleHandler::getVolumeLocal ( ) const
private

Definition at line 1235 of file ParticleHandler.cc.

Referenced by getVolume().

1236 {
1237  Mdouble volume = 0;
1238  for (auto p : *this)
1239  {
1240  if (!(p->isFixed() || p->isPeriodicGhostParticle() || p->isMPIParticle()))
1241  volume += p->getVolume();
1242  }
1243  return volume;
1244 }
double Mdouble
Definition: GeneralDefine.h:34
ParticleHandler & ParticleHandler::operator= ( const ParticleHandler rhs)

Assignment operator.

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

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

Definition at line 84 of file ParticleHandler.cc.

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

85 {
86  if (this != &rhs)
87  {
88  clear();
89  largestParticle_ = nullptr;
90  smallestParticle_ = nullptr;
92  if (!objects_.empty())
93  {
96  }
97  }
98  logger(DEBUG, "ParticleHandler::operator = (const ParticleHandler& rhs) finished");
99  return *this;
100 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
void clear() override
Empties the whole ParticleHandler by removing all BaseParticle.
BaseParticle * smallestParticle_
A pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler.
BaseParticle * largestParticle_
A pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
void computeSmallestParticle()
Computes the smallest particle (by interaction radius) and sets it in smallestParticle_.
void computeLargestParticle()
Computes the largest particle (by interaction radius) and sets it in largestParticle_.
void copyContentsFromOtherHandler(const BaseHandler< BaseParticle > &BH)
Function that copies the contents (vector of pointers, maxObject_, nextId_, DPMBase_) from one handle...
void ParticleHandler::readAndAddObject ( std::istream &  is)
overridevirtual

Create a new particle, based on the information from old-style restart data.

Create a new particle in the WallHandler, based on the information provided in a restart file.

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

Implements BaseHandler< BaseParticle >.

Definition at line 1077 of file ParticleHandler.cc.

References addExistingObject(), and readAndCreateObject().

Referenced by DPMBase::read().

1078 {
1080  addExistingObject(o);
1081 }
void addExistingObject(BaseParticle *P) override
Adds a BaseParticle to the ParticleHandler.
BaseParticle * readAndCreateObject(std::istream &is)
Create a new particle, based on the information provided in a restart file.
BaseParticle * ParticleHandler::readAndCreateObject ( std::istream &  is)

Create a new particle, based on the information provided in a restart file.

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

Definition at line 1050 of file ParticleHandler.cc.

References createObject(), DEBUG, BaseHandler< BaseParticle >::getDPMBase(), BaseInteractable::getIndSpecies(), BaseHandler< BaseParticle >::getStorageCapacity(), logger, BaseParticle::read(), BaseParticle::setHandler(), and BaseParticle::setSpecies().

Referenced by InsertionBoundary::read(), and readAndAddObject().

1051 {
1052  std::string type;
1053  BaseParticle* particle = nullptr;
1054  if (getStorageCapacity() > 0)
1055  {
1056  is >> type;
1057  logger(DEBUG, "ParticleHandler::readAndCreateObject(is): type %", type);
1058  particle = createObject(type);
1059  particle->setHandler(this);
1060  particle->read(is);
1061  }
1062  else //for insertion boundaries
1063  {
1064  is >> type;
1065  logger(DEBUG, "ParticleHandler::readAndCreateObject(is): type %", type);
1066  particle = createObject(type);
1067  particle->setHandler(this);
1068  particle->read(is);
1069  }
1070  particle->setSpecies(getDPMBase()->speciesHandler.getObject(particle->getIndSpecies()));
1071  return particle;
1072 }
void read(std::istream &is) override
Particle read function, which accepts an std::istream as input.
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
void setHandler(ParticleHandler *handler)
Sets the pointer to the particle's ParticleHandler.
void setSpecies(const ParticleSpecies *species)
unsigned int getIndSpecies() const
Returns the index of the species associated with the interactable object.
static BaseParticle * createObject(const std::string &type)
Reads BaseParticle into the ParticleHandler from restart data.
unsigned int getStorageCapacity() const
Gets the storage capacity of this BaseHandler.
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
void ParticleHandler::removedFixedParticle ( )

Decrement of the number of fixed particles.

Todo:
MX: For Jonny, is this still required, keeping the parallel code in mind?

Definition at line 1222 of file ParticleHandler.cc.

References NFixedParticles_.

Referenced by BaseParticle::unfix(), and BaseParticle::~BaseParticle().

1223 {
1224  NFixedParticles_--;
1225 }
unsigned int NFixedParticles_
Number of fixed particles.
void ParticleHandler::removeGhostObject ( unsigned int  index)

Removes a BaseParticle from the ParticleHandler without a global check, this is only to be done for mpi routines.

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

The BaseParticle with index is removed and the last BaseParticle in the vector is moved to its position. It also removes the BaseParticle from the HGrid. This function is only called by the parallel routines where we are sure the particles have been flushed out of the communication boundaries.

Definition at line 418 of file ParticleHandler.cc.

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

Referenced by DeletionBoundary::checkBoundaryAfterParticleMoved(), DPMBase::checkInteractionWithBoundaries(), and DPMBase::deleteGhostParticles().

419 {
420 #ifdef MERCURY_USE_MPI
421 #ifdef CONTACT_LIST_HGRID
422  getDPMBase()->getPossibleContactList().remove_ParticlePosibleContacts(getObject(id));
423 #endif
425  // broadcast the particle removal
426  getDPMBase()->handleParticleRemoval(getObject(index)->getId());
428 #else
429  logger(ERROR, "This function should only be used interally for mpi routines");
430 #endif
431 }
virtual void handleParticleRemoval(unsigned int id)
Handles the removal of particles from the particleHandler.
Definition: DPMBase.cc:5297
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
virtual void removeObject(unsigned const int index)
Removes an Object from the BaseHandler.
Definition: BaseHandler.h:472
BaseParticle * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
virtual void hGridRemoveParticle(BaseParticle *obj UNUSED)
Definition: DPMBase.cc:1702
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
void ParticleHandler::removeLastObject ( )

Removes the last BaseParticle from the ParticleHandler.

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

Definition at line 437 of file ParticleHandler.cc.

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

438 {
439 #ifdef CONTACT_LIST_HGRID
440  getDPMBase()->getPossibleContactList().remove_ParticlePosibleContacts(getLastObject());
441 #endif
444 }
void removeLastObject()
Removes the last Object from the BaseHandler.
Definition: BaseHandler.h:511
virtual void hGridRemoveParticle(BaseParticle *obj UNUSED)
Definition: DPMBase.cc:1702
BaseParticle * getLastObject()
Gets a pointer to the last Object in this BaseHandler.
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
void ParticleHandler::removeObject ( unsigned int  index)
override

Removes a BaseParticle from the ParticleHandler.

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

The BaseParticle with index is removed and the last BaseParticle in the vector is moved to its position. It also removes the BaseParticle from the HGrid. When running this in parallel a warning is thrown that deleting particles might cause havoc in the communication between boundaries, as the deleted particle might still be in one of the boundary lists

Definition at line 390 of file ParticleHandler.cc.

References BaseHandler< BaseParticle >::getDPMBase(), MPIContainer::getNumberOfProcessors(), BaseHandler< BaseParticle >::getObject(), DPMBase::handleParticleRemoval(), DPMBase::hGridRemoveParticle(), MPIContainer::Instance(), logger, BaseHandler< T >::removeObject(), and WARN.

Referenced by CircularPeriodicBoundary::checkBoundaryAfterParticleMoved(), DeletionBoundary::checkBoundaryAfterParticleMoved(), ConstantMassFlowMaserBoundary::checkBoundaryAfterParticleMoved(), Chute::cleanChute(), CurvyChute::recreateBottom(), and DPMBase::removeDuplicatePeriodicParticles().

391 {
392 #ifdef MERCURY_USE_MPI
393  MPIContainer& communicator = MPIContainer::Instance();
394  if (communicator.getNumberOfProcessors() > 1 )
395  {
396  logger(WARN, "[ParticleHandler::removeObject(const unsigned int)] Using the function removeObject in parallel could lead to out-of-sync communication, Instead use deletion boundaries");
397  }
398 #endif
399 #ifdef CONTACT_LIST_HGRID
400  getDPMBase()->getPossibleContactList().remove_ParticlePosibleContacts(getObject(id));
401 #endif
403  // broadcast the particle removal
404  getDPMBase()->handleParticleRemoval(getObject(index)->getId());
406 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:129
virtual void handleParticleRemoval(unsigned int id)
Handles the removal of particles from the particleHandler.
Definition: DPMBase.cc:5297
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:134
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
std::size_t getNumberOfProcessors() const
Get the total number of processors participating in this simulation.
virtual void removeObject(unsigned const int index)
Removes an Object from the BaseHandler.
Definition: BaseHandler.h:472
BaseParticle * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
virtual void hGridRemoveParticle(BaseParticle *obj UNUSED)
Definition: DPMBase.cc:1702
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
void ParticleHandler::write ( std::ostream &  os) const
Parameters
[in]typeThe first value of the position.
[in]isThe input stream from which the information is read.

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

Definition at line 1131 of file ParticleHandler.cc.

References getNumberOfRealObjectsLocal(), BaseHandler< BaseParticle >::getSize(), BaseParticle::isMPIParticle(), and BaseParticle::isPeriodicGhostParticle().

Referenced by DPMBase::write().

1132 {
1133 #ifdef MERCURY_USE_MPI
1134  os << "Particles " << getNumberOfRealObjectsLocal() << std::endl;
1135  for (BaseParticle* it : *this)
1136  {
1137  if (!it->isPeriodicGhostParticle() && !it->isMPIParticle())
1138  {
1139  os << (*it) << '\n';
1140  }
1141  }
1142 #else
1143  os << "Particles " << getSize() << '\n';
1144  for (BaseParticle* it : *this)
1145  {
1146  os << (*it) << '\n';
1147  }
1148 #endif
1149  //os.flush();
1150 }
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
unsigned int getNumberOfRealObjectsLocal() const
Returns the number of real objects on a local domain. MPI particles and periodic particles are neglec...
bool isPeriodicGhostParticle() const
Indicates if this particle is a ghost in the periodic boundary.
bool isMPIParticle() const
Indicates if this particle is a ghost in the MPI domain.

Member Data Documentation

BaseParticle* ParticleHandler::largestParticle_
private

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

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

Definition at line 465 of file ParticleHandler.h.

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

unsigned int ParticleHandler::NFixedParticles_
private

Number of fixed particles.

Definition at line 475 of file ParticleHandler.h.

Referenced by addedFixedParticle(), getNumberOfFixedParticles(), getNumberOfUnfixedParticles(), and removedFixedParticle().

BaseParticle* ParticleHandler::smallestParticle_
private

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

Definition at line 470 of file ParticleHandler.h.

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


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