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 48 of file ParticleHandler.cc.

References DEBUG, largestParticle_, logger, and smallestParticle_.

49 {
50  largestParticle_ = nullptr;
51  smallestParticle_ = nullptr;
52  logger(DEBUG, "ParticleHandler::ParticleHandler() finished");
53 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
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 61 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_.

63 {
64  clear();
65  setDPMBase(PH.getDPMBase());
66  largestParticle_ = nullptr;
67  smallestParticle_ = nullptr;
69  if (!objects_.empty())
70  {
73  }
74  logger(DEBUG, "ParticleHandler::ParticleHandler(const ParticleHandler &PH) finished");
75 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
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 105 of file ParticleHandler.cc.

References DEBUG, largestParticle_, logger, and smallestParticle_.

106 {
107  //First reset the pointers, such that they are not checked twice when removing particles
108  largestParticle_ = nullptr;
109  smallestParticle_ = nullptr;
110  logger(DEBUG, "ParticleHandler::~ParticleHandler() finished");
111 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
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 1340 of file ParticleHandler.cc.

References constants::i.

Referenced by DPMBase::computeOneTimeStep().

1341 {
1342  for (auto i: *this)
1343  {
1344  i->actionsAfterTimeStep();
1345  }
1346 }
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
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 1202 of file ParticleHandler.cc.

References NFixedParticles_.

Referenced by BaseParticle::fixParticle().

1203 {
1204  NFixedParticles_++;
1205 }
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 129 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().

130 {
131  if (P->getSpecies() == nullptr)
132  {
133  logger(WARN, "WARNING: The particle with ID % that is added in "
134  "ParticleHandler::addObject does not have a species yet."
135  "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:1664
virtual void hGridInsertParticle(BaseParticle *obj UNUSED)
Definition: DPMBase.cc:1657
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
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 280 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().

281 {
282 #ifdef MERCURY_USE_MPI
283  MPIContainer& communicator = MPIContainer::Instance();
284  if (fromProcessor == toProcessor)
285  {
286  if (communicator.getProcessorID() == fromProcessor)
287  {
288  addGhostObject(p);
289  }
290 
291  return;
292  }
293 
294  //Create communication information object
296  MPIParticle pInfo;
297  int tag;
298  if (communicator.getProcessorID() == fromProcessor)
299  {
301  tag = fromProcessor*MAX_PROC*10 + toProcessor*10 + MercuryMPITag::PARTICLE_DATA;
302  communicator.send(&pInfo, MercuryMPIType::PARTICLE, 1, toProcessor, tag);
303  }
304 
305  if (communicator.getProcessorID() == toProcessor)
306  {
307  tag = fromProcessor*MAX_PROC*10 + toProcessor*10 + MercuryMPITag::PARTICLE_DATA;
308  communicator.receive(&pInfo, MercuryMPIType::PARTICLE, 1, fromProcessor, tag);
309  }
310 
311  //Sync the communication
312  communicator.sync();
313 
314  //Add the data to the new particle
315  if (communicator.getProcessorID() == toProcessor)
316  {
317  copyDataFromMPIParticleToParticle(&pInfo, p, this);
318  }
319 
320 
321  //Only toProcessor adds the particle, quietly without any check with other processors
322  //IMPORTANT NOTE: When adding a periodic particle in parallel, this is performed just before
323  //finding new particles. For that reason we dont have to add a ghostparticle to the mpi communication lists
324  if (communicator.getProcessorID() == toProcessor)
325  {
326  addGhostObject(p);
327  }
328 #else
329  logger(WARN,
330  "Function addGhostObject(int fromProcessor, int toProcessor, BaseParticle* p) should not be used in serial code");
331 #endif
332 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:125
void copyDataFromParticleToMPIParticle(BaseParticle *p)
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:130
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
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:213
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:148
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:167
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 341 of file ParticleHandler.cc.

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

342 {
343 #ifdef MERCURY_USE_MPI
344  if (P->getSpecies() == nullptr)
345  {
346  logger(WARN, "[ParticleHandler::adGhostObject(BaseParticle*)] "
347  "WARNING: The particle with ID % that is added in "
348  "ParticleHandler::addObject does not have a species yet."
349  "Please make sure that you have "
350  "set the species somewhere in the driver code.", P->getId());
351  }
352 
353  MPIContainer& communicator = MPIContainer::Instance();
354  //Puts the particle in the Particle list
356  if (getDPMBase() != nullptr)
357  {
358  //This places the particle in this grid
360  //This computes where the particle currently is in the grid
362  }
363  //set the particleHandler pointer
364  P->setHandler(this);
365  //compute mass of the particle
366  P->getSpecies()->computeMass(P) ;
367  //Check if this particle has new extrema
368  checkExtrema(P);
369 #else
370  logger(INFO,
371  "Function ParticleHandler::mpiAddObject(BaseParticle* P) should only be called when compiling with parallel build on");
372 #endif
373 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:125
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:1664
virtual void hGridInsertParticle(BaseParticle *obj UNUSED)
Definition: DPMBase.cc:1657
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:130
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
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...
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::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(), PeriodicBoundary::createGhostParticle(), ShearBoxBoundary::createHorizontalPeriodicParticles(), LeesEdwardsBoundary::createHorizontalPeriodicParticles(), CircularPeriodicBoundary::createPeriodicParticle(), SubcriticalMaserBoundary::createPeriodicParticle(), AngledPeriodicBoundary::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  //set the particleHandler pointer
205  P->setHandler(this);
206  //compute mass of the particle
207  P->getSpecies()->computeMass(P);
208  //Check if this particle has new extrema
209  checkExtrema(P);
210  if (!P->isSphericalParticle())
211  {
212  getDPMBase()->setRotation(true);
213  }
214 #ifdef MERCURY_USE_MPI
215  P->setPeriodicComplexity(std::vector<int>(0));
216  }
217  else
218  {
219  logger.assert(!P->isMPIParticle(),"Can't add mpi particle as it does not exist");
220  logger.assert(!P->isPeriodicGhostParticle(),"Can't add mpi particle as it does not exist");
221  //Somehwere a really new particle has been added, so to keep the ID's globally unique, we also update
222  //the unique value on all other processors
224  }
225 
226  //Add the particle to the ghost particle lists
228  //Check if this new particle requires an update in the mpi grid (interactionDistance).
230 
231  //Delete the particle that was supposed to be added (but was not)
232  if(!insertParticle)
233  {
234  delete P;
235  }
236 #endif
237 }
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:1664
virtual void hGridInsertParticle(BaseParticle *obj UNUSED)
Definition: DPMBase.cc:1657
void increaseId()
Definition: BaseHandler.h:251
virtual bool isSphericalParticle() const
Definition: BaseParticle.h:642
bool mpiInsertParticleCheck(BaseParticle *P)
Function that checks if the mpi particle should really be inserted by the current domain...
Definition: DPMBase.cc:1692
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
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...
void updateGhostGrid(BaseParticle *P)
Checks if the Domain/periodic interaction distance needs to be updated and updates it accordingly...
Definition: DPMBase.cc:1797
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:1771
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:538
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 247 of file ParticleHandler.cc.

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

248 {
249 #ifdef MERCURY_USE_MPI
250  MPIContainer& communicator = MPIContainer::Instance();
251 
252  //The processor that contains the particle that needs to be copied needs to identify the target, and communicate this
253  MPIParticle pInfo;
254  if (communicator.getProcessorID() == fromProcessor)
255  {
257  }
258 
259  //Broadcast from processor i
260  communicator.broadcast(&pInfo,MercuryMPIType::PARTICLE,fromProcessor);
261  copyDataFromMPIParticleToParticle(&pInfo, p, this);
262 
263  //All processors now know have the same information and we can proceed with the collective add
264  addObject(p);
265 #else
266  logger(WARN, "Function addObject(int fromProcessor, BaseParticle* p) should not be used in serial code");
267 #endif
268 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:125
void copyDataFromParticleToMPIParticle(BaseParticle *p)
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:130
void addObject(BaseParticle *P) override
Adds a BaseParticle to the ParticleHandler.
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
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:429
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 1141 of file ParticleHandler.cc.

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

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

1142 {
1143  if (P == largestParticle_)
1144  {
1145  //if the properties of the largest particle changes
1147  }
1149  {
1150  largestParticle_ = P;
1151  }
1152 
1153  if (P == smallestParticle_)
1154  {
1155  //if the properties of the smallest particle changes
1157  }
1159  {
1160  smallestParticle_ = P;
1161  }
1162 }
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:359
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 1167 of file ParticleHandler.cc.

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

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

1168 {
1169  if (P == largestParticle_)
1170  {
1172  }
1173  if (P == smallestParticle_)
1174  {
1176  }
1177 }
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 961 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().

962 {
963  smallestParticle_ = nullptr;
964  largestParticle_ = nullptr;
966 }
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 1183 of file ParticleHandler.cc.

References BaseHandler< BaseParticle >::objects_.

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

1184 {
1185  for (BaseParticle* particle : objects_)
1186  {
1187  if (particle->getIndSpecies() == indSpecies)
1188  {
1189  particle->getSpecies()->computeMass(particle);
1190  }
1191  }
1192 }
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 1194 of file ParticleHandler.cc.

References BaseHandler< BaseParticle >::objects_.

1195 {
1196  for (BaseParticle* particle : objects_)
1197  {
1198  particle->getSpecies()->computeMass(particle);
1199  }
1200 }
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 460 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().

461 {
462  if (getSize() == 0)
463  {
464  logger(DEBUG, "No particles, so cannot compute the largest particle.");
465  largestParticle_ = nullptr;
466  return;
467  }
468  Mdouble max = -std::numeric_limits<Mdouble>::max();
469  largestParticle_ = nullptr;
470  for (BaseParticle* const particle : objects_)
471  {
472  if (!(particle->isMPIParticle() || particle->isPeriodicGhostParticle()))
473  {
474  if (particle->getMaxInteractionRadius() > max)
475  {
476  max = particle->getMaxInteractionRadius();
477  largestParticle_ = particle;
478  }
479  }
480  }
481 }
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
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:359
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 436 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().

437 {
438  if (getSize() == 0)
439  {
440  logger(DEBUG, "No particles, so cannot compute the smallest particle.");
441 
442  smallestParticle_ = nullptr;
443  return;
444  }
445  Mdouble min = std::numeric_limits<Mdouble>::max();
446  smallestParticle_ = nullptr;
447  for (BaseParticle* const particle : objects_)
448  {
449  if (!(particle->isMPIParticle() || particle->isPeriodicGhostParticle()))
450  {
451  if (particle->getMaxInteractionRadius() < min)
452  {
453  min = particle->getMaxInteractionRadius();
454  smallestParticle_ = particle;
455  }
456  }
457  }
458 }
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
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:359
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 1003 of file ParticleHandler.cc.

References ERROR, and logger.

Referenced by readAndCreateObject().

1004 {
1005  if (type == "BaseParticle") {
1006  //for backwards compatibility
1007  return new SphericalParticle;
1008  }
1009  else if (type == "SphericalParticle")
1010  {
1011  return new SphericalParticle;
1012  }
1013  else if (type == "LiquidFilmParticle")
1014  {
1015  return new LiquidFilmParticle;
1016  }
1017  else if (type == "SuperQuadricParticle")
1018  {
1019  return new SuperQuadricParticle;
1020  }
1021  else if (type == "ThermalParticle")
1022  {
1023  return new ThermalParticle;
1024  }
1025  else
1026  {
1027  logger(ERROR, "Particle type % not understood in restart file. Particle will not be read.", type);
1028  return nullptr;
1029  }
1030 }
A basic particle.
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Vec3D ParticleHandler::getAngularMomentum ( ) const

Definition at line 659 of file ParticleHandler.cc.

References getMPISum().

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

Definition at line 638 of file ParticleHandler.cc.

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

Referenced by DPMBase::getCentreOfMass().

639 {
640  Mdouble m = getMass();
641  if (m == 0)
642  {
643  Vec3D nanvec = {constants::NaN, constants::NaN, constants::NaN};
644  return nanvec;
645  }
646  else
647  return getMassTimesPosition() / m;
648 }
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 694 of file ParticleHandler.cc.

References ERROR, getFastestParticleLocal(), and logger.

695 {
696 #ifdef MERCURY_USE_MPI
697  logger(ERROR,"This function should not be used in parallel");
698 #endif
699  return getFastestParticleLocal();
700 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
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 671 of file ParticleHandler.cc.

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

Referenced by getFastestParticle().

672 {
673  if (getSize() == 0)
674  {
675  logger(WARN, "No particles to set getFastestParticle()");
676  return nullptr;
677  }
678  BaseParticle* p = nullptr;
679  Mdouble maxSpeed = -std::numeric_limits<Mdouble>::max();
680  for (BaseParticle* const pLoop : objects_)
681  {
682  if (!(pLoop->isMPIParticle() || pLoop->isPeriodicGhostParticle()))
683  {
684  if ((pLoop->getVelocity().getLength()) > maxSpeed)
685  {
686  maxSpeed = pLoop->getVelocity().getLength();
687  p = pLoop;
688  }
689  }
690  }
691  return p;
692 }
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
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 876 of file ParticleHandler.cc.

References ERROR, getHighestPositionComponentParticleLocal(), and logger.

877 {
878 #ifdef MERCURY_USE_MPI
879  logger(ERROR,"This function should not be used in parallel");
880 #endif
882 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
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 852 of file ParticleHandler.cc.

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

Referenced by getHighestPositionComponentParticle().

853 {
854  if (getSize() == 0)
855  {
856  logger(WARN, "No getHighestPositionComponentParticle(const int i) since there are no particles.");
857  return nullptr;
858  }
859  BaseParticle* p = nullptr;
860  Mdouble max = -std::numeric_limits<Mdouble>::max();
861  for (BaseParticle* const pLoop : objects_)
862  {
863  if (!(pLoop->isMPIParticle() || pLoop->isPeriodicGhostParticle()))
864  {
865  if (pLoop->getPosition().getComponent(i) > max)
866  {
867  max = pLoop->getPosition().getComponent(i);
868  p = pLoop;
869  }
870  }
871  }
872 
873  return p;
874 }
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
Definition: GeneralDefine.h:34
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
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 973 of file ParticleHandler.cc.

References MAX.

974 {
975  //Define the attribute function
976  std::function<Mdouble(BaseParticle*)> particleAttribute = [](BaseParticle* p) { return p->getPosition().X; };
977 
978  //Obtain the MAX attribute
979  Mdouble positionXGlobal = getParticleAttribute<Mdouble>(particleAttribute, AttributeType::MAX);
980 
981  return positionXGlobal;
982 }
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 948 of file ParticleHandler.cc.

References ERROR, getHighestVelocityComponentParticleLocal(), and logger.

949 {
950 #ifdef MERCURY_USE_MPI
951  logger(ERROR,"This function should not be used in parallel");
952 #endif
954 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
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 925 of file ParticleHandler.cc.

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

Referenced by getHighestVelocityComponentParticle().

926 {
927  if (!getSize())
928  {
929  logger(WARN, "No getHighestVelocityComponentParticle(const int i) since there are no particles");
930  return nullptr;
931  }
932  BaseParticle* p = nullptr;
933  Mdouble max = -std::numeric_limits<Mdouble>::max();
934  for (BaseParticle* const pLoop : objects_)
935  {
936  if (!(pLoop->isMPIParticle() || pLoop->isPeriodicGhostParticle()))
937  {
938  if (pLoop->getVelocity().getComponent(i) > max)
939  {
940  max = pLoop->getVelocity().getComponent(i);
941  p = pLoop;
942  }
943  }
944  }
945  return p;
946 }
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
Definition: GeneralDefine.h:34
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
Mdouble ParticleHandler::getKineticEnergy ( ) const

Definition at line 541 of file ParticleHandler.cc.

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

Referenced by DPMBase::writeEneTimeStep().

542 {
543 #ifdef MERCURY_USE_MPI
544  Mdouble kineticEnergyLocal = getKineticEnergyLocal();
545  Mdouble kineticEnergyGlobal = 0.0;
546 
547  //sum up over all domains
548  MPIContainer& communicator = MPIContainer::Instance();
549  communicator.allReduce(kineticEnergyLocal, kineticEnergyGlobal, MPI_SUM);
550 
551  return kineticEnergyGlobal;
552 #else
553  return getKineticEnergyLocal();
554 #endif
555 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:125
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:130
double Mdouble
Definition: GeneralDefine.h:34
Mdouble getKineticEnergyLocal() const
Mdouble ParticleHandler::getKineticEnergyLocal ( ) const
private

Definition at line 528 of file ParticleHandler.cc.

Referenced by getKineticEnergy().

529 {
530  Mdouble ene = 0;
531  for (auto p : *this)
532  {
533  if (!(p->isMPIParticle() || p->isPeriodicGhostParticle()))
534  {
535  ene += p->getKineticEnergy();
536  }
537  }
538  return ene;
539 }
double Mdouble
Definition: GeneralDefine.h:34
Mdouble ParticleHandler::getLargestInteractionRadius ( ) const

Returns the largest interaction radius.

Definition at line 756 of file ParticleHandler.cc.

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

Referenced by DPMBase::read().

757 {
758 #ifdef MERCURY_USE_MPI
759  Mdouble largestInteractionRadiusLocal = getLargestInteractionRadiusLocal();
760  Mdouble largestInteractionRadiusGlobal = 0.0;
761 
762  //Obtain the global value
763  MPIContainer& communicator = MPIContainer::Instance();
764  communicator.allReduce(largestInteractionRadiusLocal, largestInteractionRadiusGlobal, MPI_MAX);
765 
766  return largestInteractionRadiusGlobal;
767 #else
769 #endif
770 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:125
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:130
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 741 of file ParticleHandler.cc.

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

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

742 {
743  if (!(getLargestParticleLocal() == nullptr))
744  {
746  }
747  else
748  {
749  return 0.0;
750  }
751 }
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:359
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 518 of file ParticleHandler.cc.

References ERROR, getLargestParticleLocal(), and logger.

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

519 {
520 #ifdef MERCURY_USE_MPIO
521  logger(ERROR,"getLargestParticle() should not be used in parallel; use getLargestInteractionRadius instead");
522  return nullptr;
523 #else
524  return getLargestParticleLocal();
525 #endif
526 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
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 510 of file ParticleHandler.cc.

References largestParticle_.

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

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

Definition at line 1348 of file ParticleHandler.cc.

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

1348  {
1349  double liquidVolume = 0;
1350  for (auto i : objects_) {
1351  auto j = dynamic_cast<LiquidFilmParticle*>(i);
1352  if (j and !j->isMPIParticle()) liquidVolume += j->getLiquidVolume();
1353  }
1354  return getMPISum(liquidVolume);
1355 };
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
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 839 of file ParticleHandler.cc.

References ERROR, getLowestPositionComponentParticleLocal(), and logger.

840 {
841 #ifdef MERCURY_USE_MPI
842  logger(ERROR,"This function should not be used in parallel");
843 #endif
845 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
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 813 of file ParticleHandler.cc.

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

Referenced by getLowestPositionComponentParticle().

814 {
815 #ifdef MERCURY_USE_MPI
816  logger(ERROR,"getLowestPositionComponentParticle() not implemented yet in parallel");
817 #endif
818  if (getSize() == 0)
819  {
820  logger(WARN, "No getLowestPositionComponentParticle(const int i) since there are no particles.");
821  return nullptr;
822  }
823  BaseParticle* p = nullptr;
824  Mdouble min = std::numeric_limits<Mdouble>::max();
825  for (BaseParticle* const pLoop : objects_)
826  {
827  if (!(pLoop->isMPIParticle() || pLoop->isPeriodicGhostParticle()))
828  {
829  if (pLoop->getPosition().getComponent(i) < min)
830  {
831  min = pLoop->getPosition().getComponent(i);
832  p = pLoop;
833  }
834  }
835  }
836  return p;
837 }
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
Definition: GeneralDefine.h:34
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
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 912 of file ParticleHandler.cc.

References ERROR, getLowestVelocityComponentParticleLocal(), and logger.

913 {
914 #ifdef MERCURY_USE_MPI
915  logger(ERROR,"This function should not be used in parallel");
916 #endif
918 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
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 889 of file ParticleHandler.cc.

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

Referenced by getLowestVelocityComponentParticle().

890 {
891  if (getSize() == 0)
892  {
893  logger(WARN, "No getLowestVelocityComponentParticle(const int i) since there are no particles");
894  return nullptr;
895  }
896  BaseParticle* p = nullptr;
897  Mdouble min = std::numeric_limits<Mdouble>::max();
898  for (BaseParticle* const pLoop : objects_)
899  {
900  if (!(pLoop->isMPIParticle() || pLoop->isPeriodicGhostParticle()))
901  {
902  if (pLoop->getVelocity().getComponent(i) < min)
903  {
904  min = pLoop->getVelocity().getComponent(i);
905  p = pLoop;
906  }
907  }
908  }
909  return p;
910 }
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
Definition: GeneralDefine.h:34
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
Mdouble ParticleHandler::getMass ( ) const

Definition at line 595 of file ParticleHandler.cc.

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

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

596 {
597 #ifdef MERCURY_USE_MPI
598  Mdouble massLocal = getMassLocal();
599  Mdouble massGlobal = 0.0;
600 
601  //Sum up over all domains
602  MPIContainer& communicator = MPIContainer::Instance();
603  communicator.allReduce(massLocal, massGlobal, MPI_SUM);
604 
605  return massGlobal;
606 #else
607  return getMassLocal();
608 #endif
609 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:125
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:130
double Mdouble
Definition: GeneralDefine.h:34
Mdouble getMassLocal() const
Mdouble ParticleHandler::getMassLocal ( ) const
private

Definition at line 586 of file ParticleHandler.cc.

Referenced by getMass().

587 {
588  Mdouble m = 0;
589  for (auto p : *this)
590  if (!(p->isFixed() || p->isMPIParticle() || p->isPeriodicGhostParticle()))
591  m += p->getMass();
592  return m;
593 }
double Mdouble
Definition: GeneralDefine.h:34
Vec3D ParticleHandler::getMassTimesPosition ( ) const

Definition at line 620 of file ParticleHandler.cc.

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

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

621 {
622 #ifdef MERCURY_USE_MPI
623  Vec3D massTimesPositionLocal = getMassTimesPositionLocal();
624  Vec3D massTimesPositionGlobal = {0.0, 0.0, 0.0};
625 
626  // Sum up over all domains
627  MPIContainer& communicator = MPIContainer::Instance();
628  communicator.allReduce(massTimesPositionLocal.X, massTimesPositionGlobal.X, MPI_SUM);
629  communicator.allReduce(massTimesPositionLocal.Y, massTimesPositionGlobal.Y, MPI_SUM);
630  communicator.allReduce(massTimesPositionLocal.Z, massTimesPositionGlobal.Z, MPI_SUM);
631 
632  return massTimesPositionGlobal;
633 #else
634  return getMassTimesPositionLocal();
635 #endif
636 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:125
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:130
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 611 of file ParticleHandler.cc.

Referenced by getMassTimesPosition().

612 {
613  Vec3D com = {0, 0, 0};
614  for (auto p : *this)
615  if (!(p->isFixed() || p->isMPIParticle() || p->isPeriodicGhostParticle()))
616  com += p->getMass() * p->getPosition();
617  return com;
618 }
Definition: Vector.h:49
Mdouble ParticleHandler::getMeanRadius ( ) const

Definition at line 788 of file ParticleHandler.cc.

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

789 {
790 #ifdef MERCURY_USE_MPI
791  Mdouble sumRadiusLocal = getSumRadiusLocal();
792  unsigned numberOfRealParticlesLocal = getNumberOfRealObjectsLocal();
793 
794  Mdouble sumRadiusGlobal = 0.0;
795  unsigned numberOfRealParticlesGlobal = 0;
796 
797  //Sum up over all domains
798  MPIContainer& communicator = MPIContainer::Instance();
799  communicator.allReduce(sumRadiusLocal, sumRadiusGlobal, MPI_SUM);
800  communicator.allReduce(numberOfRealParticlesLocal, numberOfRealParticlesGlobal, MPI_SUM);
801 
802  return sumRadiusGlobal/numberOfRealParticlesGlobal;
803 #else
804  return getSumRadiusLocal() / getSize();
805 #endif
806 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:125
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:130
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 650 of file ParticleHandler.cc.

References getMPISum().

Referenced by DPMBase::getTotalMomentum().

651 {
652  Vec3D momentum = {0, 0, 0};
653  for (auto p : *this)
654  if (!(p->isFixed() || p->isMPIParticle() || p->isPeriodicGhostParticle()))
655  momentum += p->getMomentum();
656  return getMPISum(momentum);
657 }
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 1215 of file ParticleHandler.cc.

1216 {
1217  return "ParticleHandler";
1218 }
unsigned int ParticleHandler::getNumberOfFixedObjects ( ) const

Computes the number of fixed particles in the whole simulation.

Definition at line 1326 of file ParticleHandler.cc.

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

1327 {
1328 #ifdef MERCURY_USE_MPI
1329  unsigned int numberOfFixedParticlesLocal = getNumberOfFixedObjectsLocal();
1330  unsigned int numberOfFixedParticles = 0;
1331 
1332  MPIContainer& communicator = MPIContainer::Instance();
1333  communicator.allReduce(numberOfFixedParticlesLocal, numberOfFixedParticles, MPI_SUM);
1334  return numberOfFixedParticles;
1335 #else
1337 #endif
1338 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:125
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:130
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 1310 of file ParticleHandler.cc.

References BaseParticle::isFixed().

Referenced by getNumberOfFixedObjects().

1311 {
1312  unsigned int numberOfFixedParticles = 0;
1313  for (BaseParticle* particle : *this)
1314  {
1315  if (particle->isFixed())
1316  {
1317  numberOfFixedParticles++;
1318  }
1319  }
1320  return numberOfFixedParticles;
1321 }
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 987 of file ParticleHandler.cc.

References NFixedParticles_.

988 {
989  return NFixedParticles_;
990 }
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 1293 of file ParticleHandler.cc.

References MPIContainer::getNumberOfProcessors(), BaseHandler< BaseParticle >::getSize(), MPIContainer::Instance(), logger, and WARN.

Referenced by Chute::addFlowParticlesCompactly(), DPMBase::checkParticleForInteractionLocalPeriodic(), Chute::cleanChute(), DPMBase::computeAllForces(), getNumberOfUnfixedParticles(), DPMBase::integrateAfterForceComputation(), DPMBase::integrateBeforeForceComputation(), Chute::printTime(), and ChuteBottom::setupInitialConditions().

1294 {
1295 #ifdef MERCURY_USE_MPI
1296  MPIContainer& communicator = MPIContainer::Instance();
1297  if (communicator.getNumberOfProcessors() > 1)
1298  {
1299  logger(WARN,"When compiling with MPI please do not use getNumberOfObjects(). Instead use: getNumberOfRealObjectsLocal(), getNumberOfRealObjects() or getSize()");
1300  }
1301 #endif
1302  return getSize();
1303 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:125
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:130
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
std::size_t getNumberOfProcessors() const
Get the total number of processors participating in this simulation.
unsigned int ParticleHandler::getNumberOfRealObjects ( ) const

Returns the number of real objects (on all processors)

Definition at line 1272 of file ParticleHandler.cc.

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

Referenced by DPMBase::decompose().

1273 {
1274 #ifdef MERCURY_USE_MPI
1275  MPIContainer& communicator = MPIContainer::Instance();
1276  unsigned int numberOfRealParticles = getNumberOfRealObjectsLocal();
1277 
1278  // \todo MX: use an allreduce here
1279  //Combine the total number of Particles into one number on processor 0
1280  communicator.reduce(numberOfRealParticles, MPI::SUM);
1281 
1282  //Broadcast new number to all the processorsi
1283  communicator.broadcast(numberOfRealParticles);
1284  return numberOfRealParticles;
1285 #else
1286  return getSize();
1287 #endif
1288 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:125
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:130
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:429
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 1251 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().

1252 {
1253 #ifdef MERCURY_USE_MPI
1254  const MPIContainer& communicator = MPIContainer::Instance();
1255  if (communicator.getNumberOfProcessors() > 1)
1256  {
1257  unsigned int numberOfFakeParticles = 0;
1258  numberOfFakeParticles += getDPMBase()->domainHandler.getCurrentDomain()->getNumberOfTrueMPIParticles();
1260  logger.assert(numberOfFakeParticles <= getSize(), "More fake particles than getSize()");
1261  return (getSize() - numberOfFakeParticles);
1262  }
1263  else
1264  {
1265  return getSize();
1266  }
1267 #else
1268  return getSize();
1269 #endif
1270 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:125
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:130
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
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:1354
unsigned int getNumberOfTrueMPIParticles()
Obtains the number of particles in the particleHandler that are MPIParticles, but NOT periodic partic...
Definition: Domain.cc:1650
PeriodicBoundaryHandler periodicBoundaryHandler
Internal handler that deals with periodic boundaries, especially in a parallel build.
Definition: DPMBase.h:1349
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 995 of file ParticleHandler.cc.

References getNumberOfObjects(), and NFixedParticles_.

996 {
998 }
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:125
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:130
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
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")
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
Mdouble ParticleHandler::getRotationalEnergy ( ) const

Definition at line 570 of file ParticleHandler.cc.

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

Referenced by DPMBase::writeEneTimeStep().

571 {
572 #ifdef MERCURY_USE_MPI
573  Mdouble rotationalEnergyLocal = getRotationalEnergyLocal();
574  Mdouble rotationalEnergyGlobal = 0.0;
575 
576  //sum up over all domains
577  MPIContainer& communicator = MPIContainer::Instance();
578  communicator.allReduce(rotationalEnergyLocal, rotationalEnergyGlobal, MPI_SUM);
579 
580  return rotationalEnergyGlobal;
581 #else
582  return getRotationalEnergyLocal();
583 #endif
584 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:125
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:130
double Mdouble
Definition: GeneralDefine.h:34
Mdouble getRotationalEnergyLocal() const
Mdouble ParticleHandler::getRotationalEnergyLocal ( ) const
private

Definition at line 557 of file ParticleHandler.cc.

Referenced by getRotationalEnergy().

558 {
559  Mdouble ene = 0;
560  for (auto p : *this)
561  {
562  if (!(p->isMPIParticle() || p->isPeriodicGhostParticle()))
563  {
564  ene += p->getRotationalEnergy();
565  }
566  }
567  return ene;
568 }
double Mdouble
Definition: GeneralDefine.h:34
Mdouble ParticleHandler::getSmallestInteractionRadius ( ) const

Returns the smallest interaction radius.

Definition at line 720 of file ParticleHandler.cc.

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

721 {
722 #ifdef MERCURY_USE_MPI
723  //Compute the local value
724  Mdouble smallestInteractionRadiusLocal = getSmallestInteractionRadiusLocal();
725  Mdouble smallestInteractionRadiusGlobal = 0.0;
726 
727  //Obtain the global value
728  MPIContainer& communicator = MPIContainer::Instance();
729  communicator.allReduce(smallestInteractionRadiusLocal, smallestInteractionRadiusGlobal, MPI_MIN);
730 
731  return smallestInteractionRadiusGlobal;
732 
733 #else
735 #endif
736 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:125
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:130
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 705 of file ParticleHandler.cc.

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

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

706 {
707  if (!(getSmallestParticleLocal() == nullptr))
708  {
710  }
711  else
712  {
713  return 0.0;
714  }
715 }
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:359
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 496 of file ParticleHandler.cc.

References ERROR, getSmallestParticleLocal(), and logger.

Referenced by HGridOptimiser::initialise().

497 {
498 #ifdef MERCURY_USE_MPI
499  logger(ERROR,"getSmallestParticle should not be used in parallel; use getSmallestInteractionRadius or ParticleSpecies::getSmallestParticleMass instead");
500  return nullptr;
501 #else
502  return getSmallestParticleLocal();
503 #endif
504 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
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 487 of file ParticleHandler.cc.

References smallestParticle_.

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

488 {
489  return smallestParticle_;
490 }
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 775 of file ParticleHandler.cc.

References BaseHandler< BaseParticle >::objects_.

Referenced by getMeanRadius().

776 {
777  Mdouble sumRadius = 0;
778  for (BaseParticle* const p : objects_)
779  {
780  if (!(p->isMPIParticle() || p->isPeriodicGhostParticle()))
781  {
782  sumRadius += p->getRadius();
783  }
784  }
785  return sumRadius;
786 }
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 1231 of file ParticleHandler.cc.

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

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

1232 {
1233 #ifdef MERCURY_USE_MPI
1234  Mdouble volumeLocal = getVolumeLocal();
1235  Mdouble volumeGlobal = 0.0;
1236 
1237  // sum up over all domains
1238  MPIContainer& communicator = MPIContainer::Instance();
1239  communicator.allReduce(volumeLocal, volumeGlobal, MPI_SUM);
1240 
1241  return volumeGlobal;
1242 #else
1243  return getVolumeLocal();
1244 #endif
1245 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:125
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:130
double Mdouble
Definition: GeneralDefine.h:34
Mdouble getVolumeLocal() const
Mdouble ParticleHandler::getVolumeLocal ( ) const
private

Definition at line 1220 of file ParticleHandler.cc.

Referenced by getVolume().

1221 {
1222  Mdouble volume = 0;
1223  for (auto p : *this)
1224  {
1225  if (!(p->isFixed() || p->isPeriodicGhostParticle() || p->isMPIParticle()))
1226  volume += p->getVolume();
1227  }
1228  return volume;
1229 }
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 83 of file ParticleHandler.cc.

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

84 {
85  if (this != &rhs)
86  {
87  clear();
88  largestParticle_ = nullptr;
89  smallestParticle_ = nullptr;
91  if (!objects_.empty())
92  {
95  }
96  }
97  logger(DEBUG, "ParticleHandler::operator = (const ParticleHandler& rhs) finished");
98  return *this;
99 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
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 1062 of file ParticleHandler.cc.

References addExistingObject(), and readAndCreateObject().

Referenced by DPMBase::read().

1063 {
1065  addExistingObject(o);
1066 }
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 1035 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().

1036 {
1037  std::string type;
1038  BaseParticle* particle = nullptr;
1039  if (getStorageCapacity() > 0)
1040  {
1041  is >> type;
1042  logger(DEBUG, "ParticleHandler::readAndCreateObject(is): type %", type);
1043  particle = createObject(type);
1044  particle->setHandler(this);
1045  particle->read(is);
1046  }
1047  else //for insertion boundaries
1048  {
1049  is >> type;
1050  logger(DEBUG, "ParticleHandler::readAndCreateObject(is): type %", type);
1051  particle = createObject(type);
1052  particle->setHandler(this);
1053  particle->read(is);
1054  }
1055  particle->setSpecies(getDPMBase()->speciesHandler.getObject(particle->getIndSpecies()));
1056  return particle;
1057 }
void read(std::istream &is) override
Particle read function, which accepts an std::istream as input.
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
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 1207 of file ParticleHandler.cc.

References NFixedParticles_.

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

1208 {
1209  NFixedParticles_--;
1210 }
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 410 of file ParticleHandler.cc.

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

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

411 {
412 #ifdef MERCURY_USE_MPI
413 #ifdef CONTACT_LIST_HGRID
414  getDPMBase()->getPossibleContactList().remove_ParticlePosibleContacts(getObject(id));
415 #endif
418 #else
419  logger(ERROR, "This function should only be used interally for mpi routines");
420 #endif
421 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
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:1671
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 427 of file ParticleHandler.cc.

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

428 {
429 #ifdef CONTACT_LIST_HGRID
430  getDPMBase()->getPossibleContactList().remove_ParticlePosibleContacts(getLastObject());
431 #endif
434 }
void removeLastObject()
Removes the last Object from the BaseHandler.
Definition: BaseHandler.h:511
virtual void hGridRemoveParticle(BaseParticle *obj UNUSED)
Definition: DPMBase.cc:1671
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 384 of file ParticleHandler.cc.

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

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

385 {
386 #ifdef MERCURY_USE_MPI
387  MPIContainer& communicator = MPIContainer::Instance();
388  if (communicator.getNumberOfProcessors() > 1 )
389  {
390  logger(WARN, "[ParticleHandler::removeObject(const unsigned int)] Using the function removeObject in parallel could lead to out-of-sync communication, Instead use deletion boundaries");
391  }
392 #endif
393 #ifdef CONTACT_LIST_HGRID
394  getDPMBase()->getPossibleContactList().remove_ParticlePosibleContacts(getObject(id));
395 #endif
398 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:125
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:130
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
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:1671
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 1116 of file ParticleHandler.cc.

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

Referenced by DPMBase::write().

1117 {
1118 #ifdef MERCURY_USE_MPI
1119  os << "Particles " << getNumberOfRealObjectsLocal() << std::endl;
1120  for (BaseParticle* it : *this)
1121  {
1122  if (!it->isPeriodicGhostParticle() && !it->isMPIParticle())
1123  {
1124  os << (*it) << '\n';
1125  }
1126  }
1127 #else
1128  os << "Particles " << getSize() << '\n';
1129  for (BaseParticle* it : *this)
1130  {
1131  os << (*it) << '\n';
1132  }
1133 #endif
1134  //os.flush();
1135 }
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.

Definition at line 464 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 474 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 469 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: