Loading...
Searching...
No Matches
ParticleHandler Class Reference

Container to store pointers to all particles. More...

#include <ParticleHandler.h>

+ Inheritance diagram for ParticleHandler:

Public Member Functions

 ParticleHandler ()
 Default constructor, it creates an empty ParticleHandler.
 
 ParticleHandler (const ParticleHandler &PH)
 Constructor that copies all BaseParticle it contains and then sets the smallest and largest particle.
 
ParticleHandler & operator= (const ParticleHandler &rhs)
 Assignment operator.
 
 ~ParticleHandler () override
 Destructor, it destructs the ParticleHandler and all BaseParticle it contains.
 
void addExistingObject (BaseParticle *P) override
 Adds a BaseParticle to the ParticleHandler.
 
void addObject (BaseParticle *P) override
 Adds a BaseParticle to the ParticleHandler.
 
void addObject (int fromProcessor, BaseParticle *P)
 Adds a BaseParticle located at processor fromProcessor to toProcessor.
 
void addGhostObject (int fromProcessor, int toProcessor, BaseParticle *p)
 Adds a ghost particle located at fromProcessor to toProcessor.
 
void addGhostObject (BaseParticle *P) override
 Adds a BaseParticle to the ParticleHandler.
 
void removeObject (unsigned int index) override
 Removes a BaseParticle from the ParticleHandler.
 
void removeGhostObject (unsigned int index)
 Removes a BaseParticle from the ParticleHandler without a global check, this is only to be done for mpi routines.
 
void removeLastObject ()
 Removes the last BaseParticle from the 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_.
 
BaseParticle * getSmallestParticleLocal () const
 Gets a pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler of the local domain.
 
BaseParticle * 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.
 
BaseParticle * getLargestParticleLocal () const
 Gets a pointer to the largest BaseParticle (by interactionRadius) in the ParticleHandler of the local domain.
 
BaseParticle * 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.
 
Mdouble getSmallestInteractionRadiusLocal () const
 Returns the smallest interaction radius of the current domain.
 
Mdouble getSmallestInteractionRadius () const
 Returns the smallest interaction radius.
 
Mdouble getLargestInteractionRadiusLocal () const
 Returns the largest interaction radius of the current domain.
 
Mdouble getLargestInteractionRadius () const
 Returns the largest interaction radius.
 
BaseParticle * getFastestParticleLocal () const
 Gets a pointer to the fastest BaseParticle in this ParticleHandler.
 
BaseParticle * getFastestParticle () 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
 
BaseParticle * getLowestPositionComponentParticleLocal (int i) const
 Gets a pointer to the particle with the lowest coordinates in direction i in this ParticleHandler.
 
BaseParticle * getLowestPositionComponentParticle (int i) const
 Gets a pointer to the particle with the lowest coordinates in direction i in this ParticleHandler.
 
BaseParticle * getHighestPositionComponentParticleLocal (int i) const
 Gets a pointer to the particle with the highest coordinates in direction i in this ParticleHandler.
 
BaseParticle * getHighestPositionComponentParticle (int i) const
 Gets a pointer to the particle with the highest coordinates in direction i in this ParticleHandler.
 
BaseParticle * getLowestVelocityComponentParticleLocal (int i) const
 Gets a pointer to the particle with the lowest velocity in direction i in this ParticleHandler.
 
BaseParticle * getLowestVelocityComponentParticle (int i) const
 Gets a pointer to the particle with the lowest velocity in direction i in this ParticleHandler.
 
BaseParticle * getHighestVelocityComponentParticleLocal (int i) const
 Gets a pointer to the particle with the highest velocity in direction i in this ParticleHandler.
 
BaseParticle * getHighestVelocityComponentParticle (int i) const
 Gets a pointer to the particle with the highest velocity in direction i in this ParticleHandler.
 
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.
 
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.
 
Mdouble getHighestPositionX () const
 Function returns the highest position in the x-direction.
 
void clear () override
 Empties the whole ParticleHandler by removing all BaseParticle.
 
unsigned int getNumberOfFixedParticles () const
 Gets the number of particles that are fixed.
 
unsigned int getNumberOfUnfixedParticles () const
 Gets the number of particles that are not fixed.
 
BaseParticle * readAndCreateObject (std::istream &is)
 Create a new particle, based on the information provided in a restart file.
 
void readAndAddObject (std::istream &is) override
 
void write (std::ostream &os) const
 
void checkExtrema (BaseParticle *P)
 Checks if the extrema of this ParticleHandler needs updating.
 
void checkExtremaOnDelete (BaseParticle *P)
 Checks if the extrema of this ParticleHandler needs updating when a particle is deleted.
 
void computeAllMasses (unsigned int indSpecies)
 Computes the mass for all BaseParticle of the given species in this ParticleHandler.
 
void computeAllMasses ()
 Computes the mass for all BaseParticle in this ParticleHandler.
 
void addedFixedParticle ()
 Increment of the number of fixed particles.
 
void removedFixedParticle ()
 Decrement of the number of fixed particles.
 
std::string getName () const override
 Returns the name of the handler, namely the string "ParticleHandler".
 
unsigned int getNumberOfRealObjects () const
 Returns the number of real objects (on all processors)
 
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()
 
unsigned int getNumberOfFixedObjectsLocal () const
 Computes the number of Fixed particles on a local domain.
 
unsigned int getNumberOfFixedObjects () const
 Computes the number of fixed particles in the whole simulation.
 
unsigned int getNumberOfRealObjectsLocal () const
 Returns the number of real objects on a local domain. MPI particles and periodic particles are neglected.
 
void actionsBeforeTimeStep ()
 
void actionsAfterTimeStep ()
 
double getLiquidFilmVolume () const
 
void saveNumberPSDtoCSV (std::string csvFileName, std::vector< double > diameterBins={}) const
 Writes the PSD of the particles currently in the handler to a CSV file, with type PROBABILITYDENSITY_NUMBER_DISTRIBUTION.
 
PSD getPSD (std::vector< Mdouble > bins={}, Mdouble scaleFactor=1.0) const
 Gets the PSD from the particles currently in the handler.
 
void setWriteVTK (bool)
 Sets whether particles are written into a VTK file.
 
FileType getWriteVTK () const
 Returns whether particles are written in a VTK file.
 
- Public Member Functions inherited from BaseHandler< BaseParticle >
 BaseHandler ()
 Default BaseHandler constructor, it creates an empty BaseHandler and assigns DPMBase_ to a null pointer.
 
 BaseHandler (const BaseHandler< BaseParticle > &BH)
 Constructor that copies the objects of the given handler into itself and sets other variables to 0/nullptr.
 
virtual ~BaseHandler ()
 Destructor, it destructs the BaseHandler and all Object it contains.
 
void copyContentsFromOtherHandler (const BaseHandler< BaseParticle > &BH)
 Function that copies the contents (vector of pointers, maxObject_, nextId_, DPMBase_) from one handler (container) to the other.
 
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.
 
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.
 
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.
 
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.
 
virtual void addExistingObject (BaseParticle *O)
 Adds an existing object to the BaseHandler without changing the id of the object.
 
virtual void addObject (BaseParticle *object)
 Adds a new Object to the BaseHandler.
 
virtual void addGhostObject (BaseParticle *O)
 Adds a new Object to the BaseHandler. called by the to avoid increasing the id.
 
void removeIf (const std::function< bool(BaseParticle *)> cond)
 
virtual void removeObjects (std::vector< unsigned int > indices)
 
void removeLastObject ()
 Removes the last Object from the BaseHandler.
 
void read (std::istream &is)
 Reads all objects from restart data.
 
BaseParticle * getObjectById (const unsigned int id)
 Gets a pointer to the Object at the specified index in the BaseHandler.
 
std::vector< BaseParticle * > getObjectsById (const unsigned int id)
 Gets a vector of pointers to the objects with the specific id.
 
BaseParticle * getObject (const unsigned int id)
 Gets a pointer to the Object at the specified index in the BaseHandler.

 
const BaseParticle * getObject (const unsigned int id) const
 Gets a constant pointer to the Object at the specified index in the BaseHandler.
 
BaseParticle * getLastObject ()
 Gets a pointer to the last Object in this BaseHandler.
 
const BaseParticle * getLastObject () const
 Gets a constant pointer to the last Object in this BaseHandler.
 
unsigned int getSize () const
 Gets the size of the particleHandler (including mpi and periodic particles)
 
unsigned int getStorageCapacity () const
 Gets the storage capacity of this BaseHandler.
 
void setStorageCapacity (const unsigned int N)
 Sets the storage capacity of this BaseHandler.
 
void resize (const unsigned int N, const BaseParticle &obj)
 Resizes the container to contain N elements.
 
const std::vector< BaseParticle * >::const_iterator begin () const
 Gets the begin of the const_iterator over all Object in this BaseHandler.
 
const std::vector< BaseParticle * >::iterator begin ()
 Gets the begin of the iterator over all BaseBoundary in this BaseHandler.
 
const std::vector< BaseParticle * >::const_iterator end () const
 Gets the end of the const_iterator over all BaseBoundary in this BaseHandler.
 
const std::vector< BaseParticle * >::iterator end ()
 Gets the end of the iterator over all BaseBoundary in this BaseHandler.
 
void setDPMBase (DPMBase *DPMBase)
 Sets the problem that is solved using this handler.
 
void setId (BaseParticle *object, unsigned int id)
 
void increaseId ()
 
unsigned int getNextId ()
 
void setNextId (unsigned int id)
 
DPMBase * getDPMBase ()
 Gets the problem that is solved using this handler.
 
DPMBase * getDPMBase () const
 Gets the problem that is solved using this handler and does not change the class.
 
virtual void writeVTK () const
 now empty function for writing VTK files.
 
unsigned getNextGroupId ()
 Should be called each time you assign a groupId. Returns the value of nextGroupId_ and increases nextGroupId_ by one.
 

Static Public Member Functions

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

Private Member Functions

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

Private Attributes

BaseParticle * largestParticle_
 A pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.
 
BaseParticle * smallestParticle_
 A pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler.
 
unsigned int NFixedParticles_
 Number of fixed particles.
 
FileType writeVTK_
 

Additional Inherited Members

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

Detailed Description

Container to store pointers to all particles.

The ParticleHandler is a container that stores pointers to all particles belonging to a simulation. It is implemented as a vector of pointers of type BaseParticle*.

Constructor & Destructor Documentation

◆ ParticleHandler() [1/2]

ParticleHandler::ParticleHandler ( )

Default constructor, it creates an empty ParticleHandler.

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

32{
33 largestParticle_ = nullptr;
34 smallestParticle_ = nullptr;
36 logger(DEBUG, "ParticleHandler::ParticleHandler() finished");
37}
@ NO_FILE
file will not be created/read
LL< Log::DEBUG > DEBUG
Debug information.
Definition Logger.cc:37
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
BaseParticle * smallestParticle_
A pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler.
Definition ParticleHandler.h:472
FileType writeVTK_
Definition ParticleHandler.h:479
BaseParticle * largestParticle_
A pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.
Definition ParticleHandler.h:467

References DEBUG, largestParticle_, logger, NO_FILE, smallestParticle_, and writeVTK_.

◆ ParticleHandler() [2/2]

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.

47{
48 clear();
50 largestParticle_ = nullptr;
51 smallestParticle_ = nullptr;
53 if (!objects_.empty())
54 {
57 }
59 logger(DEBUG, "ParticleHandler::ParticleHandler(const ParticleHandler &PH) finished");
60}
Container to store the pointers to all objects that one creates in a simulation.
Definition BaseHandler.h:30
void setDPMBase(DPMBase *DPMBase)
Sets the problem that is solved using this handler.
Definition BaseHandler.h:726
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Definition BaseHandler.h:283
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition BaseHandler.h:733
void copyContentsFromOtherHandler(const BaseHandler< BaseParticle > &BH)
Function that copies the contents (vector of pointers, maxObject_, nextId_, DPMBase_) from one handle...
Definition BaseHandler.h:348
void clear() override
Empties the whole ParticleHandler by removing all BaseParticle.
Definition ParticleHandler.cc:995
void computeSmallestParticle()
Computes the smallest particle (by interaction radius) and sets it in smallestParticle_.
Definition ParticleHandler.cc:469
void computeLargestParticle()
Computes the largest particle (by interaction radius) and sets it in largestParticle_.
Definition ParticleHandler.cc:493

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

◆ ~ParticleHandler()

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.

92{
93 //First reset the pointers, such that they are not checked twice when removing particles
94 largestParticle_ = nullptr;
95 smallestParticle_ = nullptr;
96 logger(DEBUG, "ParticleHandler::~ParticleHandler() finished");
97}

References DEBUG, largestParticle_, logger, and smallestParticle_.

Member Function Documentation

◆ actionsAfterTimeStep()

void ParticleHandler::actionsAfterTimeStep ( )
1411{
1412 for (auto i: *this)
1413 {
1414 i->actionsAfterTimeStep();
1415 }
1416}
const std::complex< Mdouble > i
Definition ExtendedMath.h:31

Referenced by DPMBase::computeOneTimeStep().

◆ actionsBeforeTimeStep()

void ParticleHandler::actionsBeforeTimeStep ( )
1403{
1404 for (auto i: *this)
1405 {
1406 i->actionsBeforeTimeStep();
1407 }
1408}

Referenced by DPMBase::computeOneTimeStep().

◆ addedFixedParticle()

void ParticleHandler::addedFixedParticle ( )

Increment of the number of fixed particles.

Todo:
MX: For Jonny, is this still required, keeping the parallel code in mind?
1265{
1267}
unsigned int NFixedParticles_
Number of fixed particles.
Definition ParticleHandler.h:477

References NFixedParticles_.

Referenced by BaseParticle::fixParticle().

◆ addExistingObject()

void ParticleHandler::addExistingObject ( BaseParticle *  P)
override

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.

116{
117 if (P->getSpecies() == nullptr)
118 {
119 logger(WARN, "WARNING: The particle with ID % that is added in ParticleHandler::addObject does not have a "
120 "species yet. Please make sure that you have "
121 "set the species somewhere in the driver code.", P->getId());
122 }
123
124 //Puts the particle in the Particle list
126
127 //NOTE:Must set extrema before rebuilding grid
128 //set the particleHandler pointer
129 P->setHandler(this);
130 //compute mass of the particle
131 P->getSpecies()->computeMass(P);
132 //Check if this particle has new extrema
133 checkExtrema(P);
134
135 //Add particle to hgrid
136 if (getDPMBase() != nullptr)
137 {
138 //Rebuild grid if necessary
140 //This places the particle in this grid
142 //This computes where the particle currently is in the grid
144 }
145}
LL< Log::WARN > WARN
Warning log level.
Definition Logger.cc:33
virtual void addExistingObject(T *O)
Adds an existing object to the BaseHandler without changing the id of the object.
Definition BaseHandler.h:398
virtual void hGridUpdateParticle(BaseParticle *obj UNUSED)
Definition DPMBase.cc:1666
virtual void hGridRebuildIfNecessary()
Rebuilds the hgrid if necessary.
Definition DPMBase.h:1036
virtual void hGridInsertParticle(BaseParticle *obj UNUSED)
Definition DPMBase.cc:1659
void checkExtrema(BaseParticle *P)
Checks if the extrema of this ParticleHandler needs updating.
Definition ParticleHandler.cc:1203
double P
Uniform pressure.
Definition TwenteMeshGluing.cpp:77

References BaseHandler< T >::addExistingObject(), checkExtrema(), BaseHandler< BaseParticle >::getDPMBase(), DPMBase::hGridInsertParticle(), DPMBase::hGridRebuildIfNecessary(), DPMBase::hGridUpdateParticle(), logger, and WARN.

Referenced by readAndAddObject().

◆ addGhostObject() [1/2]

void ParticleHandler::addGhostObject ( BaseParticle *  P)
override

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.
355{
356#ifdef MERCURYDPM_USE_MPI
357 if (P->getSpecies() == nullptr)
358 {
359 logger(WARN, "[ParticleHandler::adGhostObject(BaseParticle*)] "
360 "WARNING: The particle with ID % that is added in "
361 "ParticleHandler::addObject does not have a species yet."
362 " Please make sure that you have "
363 "set the species somewhere in the driver code.", P->getId());
364 }
365
366 MPIContainer& communicator = MPIContainer::Instance();
367 //Puts the particle in the Particle list
369
370 //NOTE:Must set extrema before rebuilding grid
371 //set the particleHandler pointer
372 P->setHandler(this);
373 //compute mass of the particle
374 P->getSpecies()->computeMass(P);
375 //Check if this particle has new extrema
376 checkExtrema(P);
377
378 //Add particle to hgrid
379 if (getDPMBase() != nullptr)
380 {
381 //Rebuild grid if necessary
383 //This places the particle in this grid
385 //This computes where the particle currently is in the grid
387
388 // broadcast particle addition
389 getDPMBase()->handleParticleAddition(P->getId(), P);
390 }
391
392 if (getDPMBase() != nullptr)
393 {
394 // Broadcasts the existence of a new particle
395 getDPMBase()->handleParticleAddition(P->getId(), P);
396 }
397#else
398 logger(INFO,
399 "Function ParticleHandler::mpiAddObject(BaseParticle* P) should only be called when compiling with parallel build on");
400#endif
401}
LL< Log::INFO > INFO
Info log level.
Definition Logger.cc:34
virtual void addGhostObject(T *O)
Adds a new Object to the BaseHandler. called by the to avoid increasing the id.
Definition BaseHandler.h:425
virtual void handleParticleAddition(unsigned int id, BaseParticle *p)
Handles the addition of particles to the particleHandler.
Definition DPMBase.cc:5543
This class contains all information and functions required for communication between processors.
Definition MpiContainer.h:109
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition MpiContainer.h:113

References BaseHandler< T >::addGhostObject(), checkExtrema(), BaseHandler< BaseParticle >::getDPMBase(), DPMBase::handleParticleAddition(), DPMBase::hGridInsertParticle(), DPMBase::hGridRebuildIfNecessary(), DPMBase::hGridUpdateParticle(), INFO, MPIContainer::Instance(), logger, and WARN.

◆ addGhostObject() [2/2]

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
294{
295#ifdef MERCURYDPM_USE_MPI
296 MPIContainer& communicator = MPIContainer::Instance();
297 if (fromProcessor == toProcessor)
298 {
299 if (communicator.getProcessorID() == fromProcessor)
300 {
302 }
303
304 return;
305 }
306
307 //Create communication information object
309 MPIParticle pInfo;
310 int tag;
311 if (communicator.getProcessorID() == fromProcessor)
312 {
314 tag = fromProcessor*MAX_PROC*10 + toProcessor*10 + MercuryMPITag::PARTICLE_DATA;
315 communicator.send(&pInfo, MercuryMPIType::PARTICLE, 1, toProcessor, tag);
316 }
317
318 if (communicator.getProcessorID() == toProcessor)
319 {
320 tag = fromProcessor*MAX_PROC*10 + toProcessor*10 + MercuryMPITag::PARTICLE_DATA;
321 communicator.receive(&pInfo, MercuryMPIType::PARTICLE, 1, fromProcessor, tag);
322 }
323
324 //Sync the communication
325 communicator.sync();
326
327 //Add the data to the new particle
328 if (communicator.getProcessorID() == toProcessor)
329 {
330 copyDataFromMPIParticleToParticle(&pInfo, p, this);
331 }
332
333
334 //Only toProcessor adds the particle, quietly without any check with other processors
335 //IMPORTANT NOTE: When adding a periodic particle in parallel, this is performed just before
336 //finding new particles. For that reason we dont have to add a ghostparticle to the mpi communication lists
337 if (communicator.getProcessorID() == toProcessor)
338 {
340 }
341#else
342 logger(WARN,
343 "Function addGhostObject(int fromProcessor, int toProcessor, BaseParticle* p) should not be used in serial code");
344#endif
345}
#define MAX_PROC
Definition GeneralDefine.h:30
@ PARTICLE_DATA
Definition MpiContainer.h:58
@ PARTICLE
Definition MpiContainer.h:46
void copyDataFromMPIParticleToParticle(MPIParticle *bP, BaseParticle *p, ParticleHandler *particleHandler)
Copies data from an MPIParticle class to a BaseParticle and sets the particleHandler and species.
Definition MpiDataClass.cc:84
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:200
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:150
void sync()
Process all pending asynchronous communication requests before continuing.
Definition MpiContainer.h:131
std::size_t getProcessorID()
Reduces a scalar on all processors to one scalar on a target processor.
Definition MpiContainer.cc:92
Data class to send a particle over MPI.
Definition MpiDataClass.h:60
void copyDataFromParticleToMPIParticle(BaseParticle *p)
Definition MpiDataClass.cc:110
void addGhostObject(int fromProcessor, int toProcessor, BaseParticle *p)
Adds a ghost particle located at fromProcessor to toProcessor.
Definition ParticleHandler.cc:293

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

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

◆ addObject() [1/2]

void ParticleHandler::addObject ( BaseParticle *  P)
override

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.

162{
163 if (P->getSpecies() == nullptr)
164 {
165 logger(WARN, "WARNING: The particle with ID % that is added in "
166 "ParticleHandler::addObject does not have a species yet. "
167 "Please make sure that you have "
168 "set the species somewhere in the driver code.", P->getId());
169 }
170#ifdef MERCURYDPM_USE_MPI
171 bool insertParticle;
172 //Check if the particle P should be added to the current domain
173 if (NUMBER_OF_PROCESSORS == 1)
174 {
175 insertParticle = true;
176 }
177 else
178 {
179 insertParticle = getDPMBase()->mpiInsertParticleCheck(P);
180 }
181
182 //Add the particle if it is in the mpi domain or if the domain is not yet defined
183 if(insertParticle)
184 {
185#endif
186 //Puts the particle in the Particle list
188
189 //NOTE:Must set extrema before rebuilding grid
190 //set the particleHandler pointer
191 P->setHandler(this);
192 //compute mass of the particle
193 P->getSpecies()->computeMass(P);
194 //Check if this particle has new extrema
195 checkExtrema(P);
196
197 //Add particle to hgrid
198 if (getDPMBase() != nullptr)
199 {
200 //Rebuild grid if necessary
202 //This places the particle in this grid
204 //This computes where the particle currently is in the grid
206
207 // Broadcasts the existance of a new particle
208 getDPMBase()->handleParticleAddition(P->getId(), P);
209
210 // Store the time stamp of creation.
211 P->setTimeStamp(getDPMBase()->getNumberOfTimeSteps());
212 }
213
214 if (!P->isSphericalParticle())
215 {
216 getDPMBase()->setRotation(true);
217 }
218
219 P->actionsAfterAddObject();
220
221 if (getDPMBase() != nullptr)
222 {
223 // Broadcasts the existence of a new particle
224 getDPMBase()->handleParticleAddition(P->getId(), P);
225 }
226
227#ifdef MERCURYDPM_USE_MPI
228 P->setPeriodicComplexity(std::vector<int>(0));
229 }
230 else
231 {
232 logger.assert_debug(!P->isMPIParticle(),"Can't add mpi particle as it does not exist");
233 logger.assert_debug(!P->isPeriodicGhostParticle(),"Can't add mpi particle as it does not exist");
234 //Somehwere a really new particle has been added, so to keep the ID's globally unique, we also update
235 //the unique value on all other processors
237 }
238
239 //Add the particle to the ghost particle lists
241 //Check if this new particle requires an update in the mpi grid (interactionDistance).
243
244 //Delete the particle that was supposed to be added (but was not)
245 if(!insertParticle)
246 {
247 delete P;
248 }
249#endif
250}
#define NUMBER_OF_PROCESSORS
For the MPI communication routines this quantity is often required. defining this macro makes the cod...
Definition GeneralDefine.h:41
virtual void addObject(T *object)
Adds a new Object to the BaseHandler.
Definition BaseHandler.h:412
void increaseId()
Definition BaseHandler.h:232
void setRotation(bool rotation)
Sets whether particle rotation is enabled or disabled.
Definition DPMBase.h:547
void insertGhostParticle(BaseParticle *P)
This function inserts a particle in the mpi communication boundaries.
Definition DPMBase.cc:1773
void updateGhostGrid(BaseParticle *P)
Checks if the Domain/periodic interaction distance needs to be updated and updates it accordingly.
Definition DPMBase.cc:1799
bool mpiInsertParticleCheck(BaseParticle *P)
Function that checks if the mpi particle should really be inserted by the current domain.
Definition DPMBase.cc:1694

References BaseHandler< T >::addObject(), checkExtrema(), BaseHandler< BaseParticle >::getDPMBase(), DPMBase::handleParticleAddition(), DPMBase::hGridInsertParticle(), DPMBase::hGridRebuildIfNecessary(), DPMBase::hGridUpdateParticle(), BaseHandler< T >::increaseId(), DPMBase::insertGhostParticle(), logger, DPMBase::mpiInsertParticleCheck(), NUMBER_OF_PROCESSORS, DPMBase::setRotation(), DPMBase::updateGhostGrid(), and WARN.

Referenced by ChuteWithPeriodicInflow::AddContinuingBottom(), addObject(), CircularPeriodicBoundary::checkBoundaryAfterParticleMoved(), ConstantMassFlowMaserBoundary::checkBoundaryAfterParticleMoved(), SubcriticalMaserBoundary::checkBoundaryAfterParticleMoved(), SubcriticalMaserBoundaryTEST::checkBoundaryAfterParticleMoved(), ChuteWithContraction::ChuteWithContraction(), ChuteWithPeriodicInflowAndContinuingBottom::ChuteWithPeriodicInflowAndContinuingBottom(), ChuteWithPeriodicInflowAndContraction::ChuteWithPeriodicInflowAndContraction(), ChuteWithPeriodicInflowAndVariableBottom::ChuteWithPeriodicInflowAndVariableBottom(), ContractionWithPeriodicInflow::ContractionWithPeriodicInflow(), SubcriticalMaserBoundaryTEST::copyExtraParticles(), CurvyChute::createBottom(), PeriodicBoundary::createGhostParticle(), TimeDependentPeriodicBoundary::createGhostParticle(), LeesEdwardsBoundary::createHorizontalPeriodicParticle(), ShearBoxBoundary::createHorizontalPeriodicParticle(), AngledPeriodicBoundary::createPeriodicParticle(), CircularPeriodicBoundary::createPeriodicParticle(), ConstantMassFlowMaserBoundary::createPeriodicParticle(), SubcriticalMaserBoundary::createPeriodicParticle(), LeesEdwardsBoundary::createVerticalPeriodicParticle(), ShearBoxBoundary::createVerticalPeriodicParticle(), SubcriticalMaserBoundaryTEST::extendBottom(), ChuteWithPeriodicInflow::ExtendInWidth(), ChuteWithPeriodicInflow::integrateBeforeForceComputation(), and ContactDetectionTester::setupParticles().

◆ addObject() [2/2]

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
261{
262#ifdef MERCURYDPM_USE_MPI
263 MPIContainer& communicator = MPIContainer::Instance();
264
265 //The processor that contains the particle that needs to be copied needs to identify the target, and communicate this
266 MPIParticle pInfo;
267 if (communicator.getProcessorID() == fromProcessor)
268 {
270 }
271
272 //Broadcast from processor i
273 communicator.broadcast(&pInfo,MercuryMPIType::PARTICLE,fromProcessor);
274 copyDataFromMPIParticleToParticle(&pInfo, p, this);
275
276 //All processors now know have the same information and we can proceed with the collective add
277 addObject(p);
278#else
279 logger(WARN, "Function addObject(int fromProcessor, BaseParticle* p) should not be used in serial code");
280#endif
281}
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:420
void addObject(BaseParticle *P) override
Adds a BaseParticle to the ParticleHandler.
Definition ParticleHandler.cc:161

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

◆ checkExtrema()

void ParticleHandler::checkExtrema ( BaseParticle *  P)

Checks if the extrema of this ParticleHandler needs updating.

 \param[in] type The first value of the position.
 \param[in] is The input stream from which the information is read.
 \details 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.
&zwj;/

void ParticleHandler::readAndCreateOldObject(std::istream& is, const std::string& type) { //read in next line std::stringstream line; helpers::getLineFromStringStream(is, line); logger(VERBOSE, line.str()); //stdcout << line.str() << std::endl;

BaseParticle particle;

//Declare all properties of the particle unsigned int indSpecies; Mdouble radius, inverseMass, inverseInertia; Vec3D position, velocity, euler, angularVelocity;

//Read all values position.X = atof(type.c_str());

line >> position.Y >> position.Z >> velocity >> radius >> euler >> angularVelocity >> inverseMass >> inverseInertia >> indSpecies;

//Put the values in the particle particle.setSpecies(getDPMBase()->speciesHandler.getObject(indSpecies)); particle.setPosition(position); particle.setVelocity(velocity); particle.setRadius(radius); Quaternion q; q.setEuler(euler); particle.setOrientation(q); particle.setAngularVelocity(angularVelocity); if (inverseMass == 0.0) particle.fixParticle(); else { particle.setInverseInertia(MatrixSymmetric3D(1,0,0,1,0,1)*inverseInertia); }

//Put the particle in the handler copyAndAddObject(particle); }

void ParticleHandler::write(std::ostream& os) const {

os << "Particles " << getSize() << '\n';
for (BaseParticle* it : *this)
{
    os << (*it) << '\n';
}

os.flush(); }

/*!

Parameters
[in]PA pointer to the particle, which properties have to be checked against the ParticleHandlers extrema.
1204{
1205 if (P == largestParticle_)
1206 {
1207 //if the properties of the largest particle changes
1209 }
1210 else if (!largestParticle_ || P->getMaxInteractionRadius() > largestParticle_->getMaxInteractionRadius())
1211 {
1213 }
1214
1215 if (P == smallestParticle_)
1216 {
1217 //if the properties of the smallest particle changes
1219 }
1220 else if (!smallestParticle_ || P->getMaxInteractionRadius() < smallestParticle_->getMaxInteractionRadius())
1221 {
1223 }
1224}
virtual Mdouble getMaxInteractionRadius() const
Returns the particle's interaction radius, which might be different from radius_ (e....
Definition BaseParticle.h:353

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

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

◆ checkExtremaOnDelete()

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.
1230{
1231 if (P == largestParticle_)
1232 {
1234 }
1235 if (P == smallestParticle_)
1236 {
1238 }
1239}

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

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

◆ clear()

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 >.

996{
997 smallestParticle_ = nullptr;
998 largestParticle_ = nullptr;
999
1000 for (auto p0: *this)
1001 {
1002 getDPMBase()->handleParticleRemoval(p0->getId());
1003 }
1004
1006}
virtual void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0.
Definition BaseHandler.h:536
virtual void handleParticleRemoval(unsigned int id)
Handles the removal of particles from the particleHandler.
Definition DPMBase.cc:5528

References BaseHandler< T >::clear(), BaseHandler< BaseParticle >::getDPMBase(), DPMBase::handleParticleRemoval(), largestParticle_, and smallestParticle_.

Referenced by NautaMixer::addParticles(), NautaMixer::addParticlesAtWall(), CGExactOverlapUnitTest::clear(), CGHandler::evaluateRestartFiles(), HorizontalMixer::introduceParticlesAtWall(), HorizontalMixer::introduceParticlesInDomain(), HorizontalMixer::introduceSingleParticle(), operator=(), ParticleHandler(), FileReader::read(), DPMBase::read(), DPMBase::readNextDataFile(), HorizontalMixerWalls::setupInitialConditions(), FreeCooling2DinWallsDemo::setupInitialConditions(), FreeCooling3DDemoProblem::setupInitialConditions(), FreeCooling3DinWallsDemo::setupInitialConditions(), FreeCoolingDemoProblem::setupInitialConditions(), CoilSelfTest::setupInitialConditions(), ParticleParticleInteraction::setupInitialConditions(), ParticleParticleInteractionWithPlasticForces::setupInitialConditions(), ParticleWallInteraction::setupInitialConditions(), EnergyUnitTest::setupInitialConditions(), HertzianSinterForceUnitTest::setupInitialConditions(), MD_demo::setupInitialConditions(), PlasticForceUnitTest::setupInitialConditions(), SeparateFilesSelfTest::setupInitialConditions(), SinterForceUnitTest::setupInitialConditions(), and BaseCluster::setupInitialConditions().

◆ computeAllMasses() [1/2]

void ParticleHandler::computeAllMasses ( )

Computes the mass for all BaseParticle in this ParticleHandler.

1257{
1258 for (BaseParticle* particle : objects_)
1259 {
1260 particle->getSpecies()->computeMass(particle);
1261 }
1262}
Definition BaseParticle.h:35

References BaseHandler< BaseParticle >::objects_.

◆ computeAllMasses() [2/2]

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.
1246{
1247 for (BaseParticle* particle : objects_)
1248 {
1249 if (particle->getIndSpecies() == indSpecies)
1250 {
1251 particle->getSpecies()->computeMass(particle);
1252 }
1253 }
1254}

References BaseHandler< BaseParticle >::objects_.

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

◆ computeLargestParticle()

void ParticleHandler::computeLargestParticle ( )

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

494{
495 if (getSize() == 0)
496 {
497 logger(DEBUG, "No particles, so cannot compute the largest particle.");
498 largestParticle_ = nullptr;
499 return;
500 }
501 Mdouble max = -std::numeric_limits<Mdouble>::max();
502 largestParticle_ = nullptr;
503 for (BaseParticle* const particle : objects_)
504 {
505 //if (!(particle->isMPIParticle() || particle->isPeriodicGhostParticle()))
506 {
507 if (particle->getMaxInteractionRadius() > max)
508 {
509 max = particle->getMaxInteractionRadius();
510 largestParticle_ = particle;
511 }
512 }
513 }
514}
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Definition BaseHandler.h:663

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

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

◆ computeSmallestParticle()

void ParticleHandler::computeSmallestParticle ( )

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

470{
471 if (getSize() == 0)
472 {
473 logger(DEBUG, "No particles, so cannot compute the smallest particle.");
474
475 smallestParticle_ = nullptr;
476 return;
477 }
478 Mdouble min = std::numeric_limits<Mdouble>::max();
479 smallestParticle_ = nullptr;
480 for (BaseParticle* const particle : objects_)
481 {
482 //if (!(particle->isMPIParticle() || particle->isPeriodicGhostParticle()))
483 {
484 if (particle->getMaxInteractionRadius() < min)
485 {
486 min = particle->getMaxInteractionRadius();
487 smallestParticle_ = particle;
488 }
489 }
490 }
491}

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

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

◆ createObject()

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.
1044{
1045 if (type == "BaseParticle") {
1046 //for backwards compatibility
1047 return new SphericalParticle;
1048 }
1049 else if (type == "SphericalParticle")
1050 {
1051 return new SphericalParticle;
1052 }
1053 else if (type == "SPHBaseParticle")
1054 {
1055 return new SPHParticle;
1056 }
1057 else if (type == "GhostSPHBaseParticle")
1058 {
1059 return new GhostSPHParticle;
1060 }
1061 else if (type == "LiquidFilmBaseParticle" || type == "LiquidFilmParticle")
1062 {
1063 return new LiquidFilmParticle;
1064 }
1065 else if (type == "SuperQuadricParticle")
1066 {
1067 return new SuperQuadricParticle;
1068 }
1069 else if (type == "ThermalParticle")
1070 {
1071 return new ThermalParticle;
1072 }
1073 else if (type == "MeltableParticle")
1074 {
1075 return new MeltableParticle;
1076 }
1077 else if (type == "HeatFluidCoupledBaseParticle")
1078 {
1079 return new HeatFluidCoupledParticle;
1080 }
1081 else if (type == "Clump")
1082 {
1083 return new ClumpParticle;
1084 }
1085 else
1086 {
1087 logger(WARN, "Particle type % not understood in restart file. Particle will not be read.", type);
1088 return nullptr;
1089 }
1090}
HeatFluidCoupled< SphericalParticle > HeatFluidCoupledParticle
Template specialisation of HeatFluidCoupled<Particle> for spherical particles.
Definition HeatFluidCoupledParticle.h:111
LiquidFilm< SphericalParticle > LiquidFilmParticle
Definition LiquidMigrationLSInteraction.h:23
SPH< SphericalParticle > SPHParticle
Definition SPHInteraction.h:19
Thermal< SphericalParticle > ThermalParticle
Definition ThermalParticle.h:165
Definition ClumpParticle.h:30
Definition GhostSPHParticle.h:33
Definition MeltableParticle.h:15
A spherical particle is the most simple particle used in MercuryDPM.
Definition SphericalParticle.h:16
Definition SuperQuadricParticle.h:36

References logger, and WARN.

Referenced by readAndCreateObject().

◆ getAngularMomentum()

Vec3D ParticleHandler::getAngularMomentum ( ) const
694{
695 Vec3D momentum = {0, 0, 0};
696 for (auto p : *this)
697 if (!(p->isFixed() || p->isMPIParticle() || p->isPeriodicGhostParticle()))
698 momentum += p->getAngularMomentum();
699 return getMPISum(momentum);
700}
Vec3D getMPISum(Vec3D &val)
Definition MpiDataClass.cc:178
Vec3D getAngularMomentum() const
Definition ParticleHandler.cc:693
Definition Vector.h:30

References getMPISum().

Referenced by main().

◆ getCentreOfMass()

Vec3D ParticleHandler::getCentreOfMass ( ) const
673{
674 Mdouble m = getMass();
675 if (m == 0)
676 {
678 return nanvec;
679 }
680 else
681 return getMassTimesPosition() / m;
682}
Vec3D getMassTimesPosition() const
Definition ParticleHandler.cc:654
Mdouble getMass() const
Definition ParticleHandler.cc:629
const Mdouble NaN
Definition GeneralDefine.h:22

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

Referenced by DPMBase::getCentreOfMass(), RotatingDrumWet::printTime(), and RayleighKothe::printTime().

◆ getFastestParticle()

BaseParticle * ParticleHandler::getFastestParticle ( ) const
729{
730#ifdef MERCURYDPM_USE_MPI
731 logger(ERROR,"This function should not be used in parallel");
732#endif
734}
LL< Log::ERROR > ERROR
Error log level.
Definition Logger.cc:32
BaseParticle * getFastestParticleLocal() const
Gets a pointer to the fastest BaseParticle in this ParticleHandler.
Definition ParticleHandler.cc:705

References ERROR, getFastestParticleLocal(), and logger.

◆ getFastestParticleLocal()

BaseParticle * ParticleHandler::getFastestParticleLocal ( ) const

Gets a pointer to the fastest BaseParticle in this ParticleHandler.

Returns
A pointer to the fastest BaseParticle in this ParticleHandler.
706{
707 if (getSize() == 0)
708 {
709 logger(WARN, "No particles to set getFastestParticle()");
710 return nullptr;
711 }
712 BaseParticle* p = nullptr;
713 Mdouble maxSpeed = -std::numeric_limits<Mdouble>::max();
714 for (BaseParticle* const pLoop : objects_)
715 {
716 if (!(pLoop->isMPIParticle() || pLoop->isPeriodicGhostParticle()))
717 {
718 if ((pLoop->getVelocity().getLength()) > maxSpeed)
719 {
720 maxSpeed = pLoop->getVelocity().getLength();
721 p = pLoop;
722 }
723 }
724 }
725 return p;
726}

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

Referenced by getFastestParticle().

◆ getHighestPositionComponentParticle()

BaseParticle * ParticleHandler::getHighestPositionComponentParticle ( int  i) const

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

911{
912#ifdef MERCURYDPM_USE_MPI
913 logger(ERROR,"This function should not be used in parallel");
914#endif
916}
BaseParticle * getHighestPositionComponentParticleLocal(int i) const
Gets a pointer to the particle with the highest coordinates in direction i in this ParticleHandler.
Definition ParticleHandler.cc:886

References ERROR, getHighestPositionComponentParticleLocal(), and logger.

◆ getHighestPositionComponentParticleLocal()

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.
887{
888 if (getSize() == 0)
889 {
890 logger(WARN, "No getHighestPositionComponentParticle(const int i) since there are no particles.");
891 return nullptr;
892 }
893 BaseParticle* p = nullptr;
894 Mdouble max = -std::numeric_limits<Mdouble>::max();
895 for (BaseParticle* const pLoop : objects_)
896 {
897 if (!(pLoop->isMPIParticle() || pLoop->isPeriodicGhostParticle()))
898 {
899 if (pLoop->getPosition().getComponent(i) > max)
900 {
901 max = pLoop->getPosition().getComponent(i);
902 p = pLoop;
903 }
904 }
905 }
906
907 return p;
908}

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

Referenced by getHighestPositionComponentParticle().

◆ getHighestPositionX()

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
1014{
1015 //Define the attribute function
1016 std::function<Mdouble(BaseParticle*)> particleAttribute = [](BaseParticle* p) { return p->getPosition().X; };
1017
1018 //Obtain the MAX attribute
1019 Mdouble positionXGlobal = getParticleAttribute<Mdouble>(particleAttribute, AttributeType::MAX);
1020
1021 return positionXGlobal;
1022}
double Mdouble
Definition GeneralDefine.h:13
@ MAX
Definition ParticleHandler.h:19

References MAX.

◆ getHighestVelocityComponentParticle()

BaseParticle * ParticleHandler::getHighestVelocityComponentParticle ( int  i) const

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

983{
984#ifdef MERCURYDPM_USE_MPI
985 logger(ERROR,"This function should not be used in parallel");
986#endif
988}
BaseParticle * getHighestVelocityComponentParticleLocal(int i) const
Gets a pointer to the particle with the highest velocity in direction i in this ParticleHandler.
Definition ParticleHandler.cc:959

References ERROR, getHighestVelocityComponentParticleLocal(), and logger.

◆ getHighestVelocityComponentParticleLocal()

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.
960{
961 if (!getSize())
962 {
963 logger(WARN, "No getHighestVelocityComponentParticle(const int i) since there are no particles");
964 return nullptr;
965 }
966 BaseParticle* p = nullptr;
967 Mdouble max = -std::numeric_limits<Mdouble>::max();
968 for (BaseParticle* const pLoop : objects_)
969 {
970 if (!(pLoop->isMPIParticle() || pLoop->isPeriodicGhostParticle()))
971 {
972 if (pLoop->getVelocity().getComponent(i) > max)
973 {
974 max = pLoop->getVelocity().getComponent(i);
975 p = pLoop;
976 }
977 }
978 }
979 return p;
980}

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

Referenced by getHighestVelocityComponentParticle().

◆ getKineticEnergy()

Mdouble ParticleHandler::getKineticEnergy ( ) const
576{
577#ifdef MERCURYDPM_USE_MPI
578 Mdouble kineticEnergyLocal = getKineticEnergyLocal();
579 Mdouble kineticEnergyGlobal = 0.0;
580
581 //sum up over all domains
582 MPIContainer& communicator = MPIContainer::Instance();
583 communicator.allReduce(kineticEnergyLocal, kineticEnergyGlobal, MPI_SUM);
584
585 return kineticEnergyGlobal;
586#else
587 return getKineticEnergyLocal();
588#endif
589}
Mdouble getKineticEnergyLocal() const
Definition ParticleHandler.cc:562

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

Referenced by main(), DPMBase::writeEneTimeStep(), and LawinenBox::writeEneTimeStep().

◆ getKineticEnergyLocal()

Mdouble ParticleHandler::getKineticEnergyLocal ( ) const
private
563{
564 Mdouble ene = 0;
565 for (auto p : *this)
566 {
567 if (!(p->isMPIParticle() || p->isPeriodicGhostParticle()))
568 {
569 ene += p->getKineticEnergy();
570 }
571 }
572 return ene;
573}

Referenced by getKineticEnergy().

◆ getLargestInteractionRadius()

Mdouble ParticleHandler::getLargestInteractionRadius ( ) const

Returns the largest interaction radius.

791{
792#ifdef MERCURYDPM_USE_MPI
793 Mdouble largestInteractionRadiusLocal = getLargestInteractionRadiusLocal();
794 Mdouble largestInteractionRadiusGlobal = 0.0;
795
796 //Obtain the global value
797 MPIContainer& communicator = MPIContainer::Instance();
798 communicator.allReduce(largestInteractionRadiusLocal, largestInteractionRadiusGlobal, MPI_MAX);
799
800 return largestInteractionRadiusGlobal;
801#else
803#endif
804}
Mdouble getLargestInteractionRadiusLocal() const
Returns the largest interaction radius of the current domain.
Definition ParticleHandler.cc:775

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

Referenced by Contact::actionsAfterSolve(), getPSD(), and DPMBase::read().

◆ getLargestInteractionRadiusLocal()

Mdouble ParticleHandler::getLargestInteractionRadiusLocal ( ) const

Returns the largest interaction radius of the current domain.

776{
777 if (!(getLargestParticleLocal() == nullptr))
778 {
780 }
781 else
782 {
783 return 0.0;
784 }
785}
BaseParticle * getLargestParticleLocal() const
Gets a pointer to the largest BaseParticle (by interactionRadius) in the ParticleHandler of the local...
Definition ParticleHandler.cc:544
BaseParticle * getLargestParticle() const
Returns the pointer of the largest particle in the particle handler. When mercury is running in paral...
Definition ParticleHandler.cc:552

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

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

◆ getLargestParticle()

BaseParticle * ParticleHandler::getLargestParticle ( ) const

◆ getLargestParticleLocal()

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.
545{
546 return largestParticle_;
547}

References largestParticle_.

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

◆ getLiquidFilmVolume()

double ParticleHandler::getLiquidFilmVolume ( ) const
1419{
1420 double liquidVolume = 0;
1421 for (auto i : objects_) {
1422 auto j = dynamic_cast<LiquidFilmParticle*>(i);
1423 if (j and !j->isMPIParticle()) liquidVolume += j->getLiquidVolume();
1424 }
1425 return getMPISum(liquidVolume);
1426};
Definition LiquidFilmParticle.h:15
Mdouble getLiquidVolume() const
Definition LiquidFilmParticle.h:84

References getMPISum(), and BaseHandler< BaseParticle >::objects_.

Referenced by LiquidMigrationMPI2Test::printTime().

◆ getLowestPositionComponentParticle()

BaseParticle * ParticleHandler::getLowestPositionComponentParticle ( int  i) const

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

874{
875#ifdef MERCURYDPM_USE_MPI
876 logger(ERROR,"This function should not be used in parallel");
877#endif
879}
BaseParticle * getLowestPositionComponentParticleLocal(int i) const
Gets a pointer to the particle with the lowest coordinates in direction i in this ParticleHandler.
Definition ParticleHandler.cc:847

References ERROR, getLowestPositionComponentParticleLocal(), and logger.

◆ getLowestPositionComponentParticleLocal()

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.
848{
849#ifdef MERCURYDPM_USE_MPI
850 logger(ERROR,"getLowestPositionComponentParticle() not implemented yet in parallel");
851#endif
852 if (getSize() == 0)
853 {
854 logger(WARN, "No getLowestPositionComponentParticle(const int i) since there are no particles.");
855 return nullptr;
856 }
857 BaseParticle* p = nullptr;
858 Mdouble min = std::numeric_limits<Mdouble>::max();
859 for (BaseParticle* const pLoop : objects_)
860 {
861 if (!(pLoop->isMPIParticle() || pLoop->isPeriodicGhostParticle()))
862 {
863 if (pLoop->getPosition().getComponent(i) < min)
864 {
865 min = pLoop->getPosition().getComponent(i);
866 p = pLoop;
867 }
868 }
869 }
870 return p;
871}

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

Referenced by getLowestPositionComponentParticle().

◆ getLowestVelocityComponentParticle()

BaseParticle * ParticleHandler::getLowestVelocityComponentParticle ( int  i) const

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

947{
948#ifdef MERCURYDPM_USE_MPI
949 logger(ERROR,"This function should not be used in parallel");
950#endif
952}
BaseParticle * getLowestVelocityComponentParticleLocal(int i) const
Gets a pointer to the particle with the lowest velocity in direction i in this ParticleHandler.
Definition ParticleHandler.cc:923

References ERROR, getLowestVelocityComponentParticleLocal(), and logger.

◆ getLowestVelocityComponentParticleLocal()

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.
924{
925 if (getSize() == 0)
926 {
927 logger(WARN, "No getLowestVelocityComponentParticle(const int i) since there are no particles");
928 return nullptr;
929 }
930 BaseParticle* p = nullptr;
931 Mdouble min = std::numeric_limits<Mdouble>::max();
932 for (BaseParticle* const pLoop : objects_)
933 {
934 if (!(pLoop->isMPIParticle() || pLoop->isPeriodicGhostParticle()))
935 {
936 if (pLoop->getVelocity().getComponent(i) < min)
937 {
938 min = pLoop->getVelocity().getComponent(i);
939 p = pLoop;
940 }
941 }
942 }
943 return p;
944}

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

Referenced by getLowestVelocityComponentParticle().

◆ getMass()

Mdouble ParticleHandler::getMass ( ) const
630{
631#ifdef MERCURYDPM_USE_MPI
632 Mdouble massLocal = getMassLocal();
633 Mdouble massGlobal = 0.0;
634
635 //Sum up over all domains
636 MPIContainer& communicator = MPIContainer::Instance();
637 communicator.allReduce(massLocal, massGlobal, MPI_SUM);
638
639 return massGlobal;
640#else
641 return getMassLocal();
642#endif
643}
Mdouble getMassLocal() const
Definition ParticleHandler.cc:620

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

Referenced by BoundariesSelfTest::actionsAfterTimeStep(), FluxAndPeriodicBoundarySelfTest::actionsAfterTimeStep(), FluxBoundarySelfTest::actionsAfterTimeStep(), FixedClusterInsertionBoundary::checkBoundaryBeforeTimeStep(), RandomClusterInsertionBoundary::checkBoundaryBeforeTimeStep(), getCentreOfMass(), DPMBase::getTotalMass(), HeaterBoundaryTest::setupInitialConditions(), DPMBase::writeEneTimeStep(), and LawinenBox::writeEneTimeStep().

◆ getMassLocal()

Mdouble ParticleHandler::getMassLocal ( ) const
private
621{
622 Mdouble m = 0;
623 for (auto p : *this)
624 if (!(p->isFixed() || p->isMPIParticle() || p->isPeriodicGhostParticle()))
625 m += p->getMass();
626 return m;
627}

Referenced by getMass().

◆ getMassTimesPosition()

Vec3D ParticleHandler::getMassTimesPosition ( ) const
655{
656#ifdef MERCURYDPM_USE_MPI
657 Vec3D massTimesPositionLocal = getMassTimesPositionLocal();
658 Vec3D massTimesPositionGlobal = {0.0, 0.0, 0.0};
659
660 // Sum up over all domains
661 MPIContainer& communicator = MPIContainer::Instance();
662 communicator.allReduce(massTimesPositionLocal.X, massTimesPositionGlobal.X, MPI_SUM);
663 communicator.allReduce(massTimesPositionLocal.Y, massTimesPositionGlobal.Y, MPI_SUM);
664 communicator.allReduce(massTimesPositionLocal.Z, massTimesPositionGlobal.Z, MPI_SUM);
665
666 return massTimesPositionGlobal;
667#else
669#endif
670}
Vec3D getMassTimesPositionLocal() const
Definition ParticleHandler.cc:645
Mdouble Y
Definition Vector.h:45
Mdouble Z
Definition Vector.h:45
Mdouble X
the vector components
Definition Vector.h:45

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

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

◆ getMassTimesPositionLocal()

Vec3D ParticleHandler::getMassTimesPositionLocal ( ) const
private
646{
647 Vec3D com = {0, 0, 0};
648 for (auto p : *this)
649 if (!(p->isFixed() || p->isMPIParticle() || p->isPeriodicGhostParticle()))
650 com += p->getMass() * p->getPosition();
651 return com;
652}

Referenced by getMassTimesPosition().

◆ getMeanRadius()

Mdouble ParticleHandler::getMeanRadius ( ) const
823{
824#ifdef MERCURYDPM_USE_MPI
825 Mdouble sumRadiusLocal = getSumRadiusLocal();
826 unsigned numberOfRealParticlesLocal = getNumberOfRealObjectsLocal();
827
828 Mdouble sumRadiusGlobal = 0.0;
829 unsigned numberOfRealParticlesGlobal = 0;
830
831 //Sum up over all domains
832 MPIContainer& communicator = MPIContainer::Instance();
833 communicator.allReduce(sumRadiusLocal, sumRadiusGlobal, MPI_SUM);
834 communicator.allReduce(numberOfRealParticlesLocal, numberOfRealParticlesGlobal, MPI_SUM);
835
836 return sumRadiusGlobal/numberOfRealParticlesGlobal;
837#else
838 return getSumRadiusLocal() / getSize();
839#endif
840}
unsigned int getNumberOfRealObjectsLocal() const
Returns the number of real objects on a local domain. MPI particles and periodic particles are neglec...
Definition ParticleHandler.cc:1313
Mdouble getSumRadiusLocal() const
Definition ParticleHandler.cc:809

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

Referenced by InitialConditions< SpeciesType >::getMeanRelativeContactRadius(), Sintering::getMeanRelativeContactRadius(), regimeForceUnitTest::getMeanRelativeContactRadius(), LaserOnLayer::LaserOnLayer(), main(), main(), GranuDrum::printTime(), Drum::printTime(), RotatingDrumWet::printTime(), RotatingDrumBidisperse::printTime(), regimeForceUnitTest::printTime(), and SingleParticle< SpeciesType >::writeEneTimeStep().

◆ getMomentum()

Vec3D ParticleHandler::getMomentum ( ) const
685{
686 Vec3D momentum = {0, 0, 0};
687 for (auto p : *this)
688 if (!(p->isFixed() || p->isMPIParticle() || p->isPeriodicGhostParticle()))
689 momentum += p->getMomentum();
690 return getMPISum(momentum);
691}
Vec3D getMomentum() const
Definition ParticleHandler.cc:684

References getMPISum().

Referenced by DPMBase::getTotalMomentum(), main(), ParticleBeam::printTime(), and LawinenBox::writeEneTimeStep().

◆ getName()

std::string ParticleHandler::getName ( ) const
overridevirtual

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

Returns
The string "ParticleHandler".

Implements BaseHandler< BaseParticle >.

1278{
1279 return "ParticleHandler";
1280}

◆ getNumberOfFixedObjects()

unsigned int ParticleHandler::getNumberOfFixedObjects ( ) const

Computes the number of fixed particles in the whole simulation.

1389{
1390#ifdef MERCURYDPM_USE_MPI
1391 unsigned int numberOfFixedParticlesLocal = getNumberOfFixedObjectsLocal();
1392 unsigned int numberOfFixedParticles = 0;
1393
1394 MPIContainer& communicator = MPIContainer::Instance();
1395 communicator.allReduce(numberOfFixedParticlesLocal, numberOfFixedParticles, MPI_SUM);
1396 return numberOfFixedParticles;
1397#else
1399#endif
1400}
unsigned int getNumberOfFixedObjectsLocal() const
Computes the number of Fixed particles on a local domain.
Definition ParticleHandler.cc:1372

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

Referenced by LawinenBox::setupInitialConditions().

◆ getNumberOfFixedObjectsLocal()

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
1373{
1374 unsigned int numberOfFixedParticles = 0;
1375 for (BaseParticle* particle : *this)
1376 {
1377 if (particle->isFixed())
1378 {
1379 numberOfFixedParticles++;
1380 }
1381 }
1382 return numberOfFixedParticles;
1383}

Referenced by getNumberOfFixedObjects().

◆ getNumberOfFixedParticles()

unsigned int ParticleHandler::getNumberOfFixedParticles ( ) const

Gets the number of particles that are fixed.

1028{
1029 return NFixedParticles_;
1030}

References NFixedParticles_.

◆ getNumberOfObjects()

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 >.

1356{
1357//#ifdef MERCURYDPM_USE_MPI
1358// MPIContainer& communicator = MPIContainer::Instance();
1359// if (communicator.getNumberOfProcessors() > 1)
1360// {
1361// logger(WARN,"When compiling with MPI please do not use getNumberOfObjects(). Instead use: getNumberOfRealObjectsLocal(), getNumberOfRealObjects() or getSize()");
1362// }
1363//#endif
1364 return getSize();
1365}

References BaseHandler< BaseParticle >::getSize().

Referenced by Contact::actionsAfterSolve(), TwoByTwoMPIDomainMPI4Test::actionsAfterTimeStep(), VFunnel::actionsAfterTimeStep(), GranularCollapse::actionsAfterTimeStep(), MercuryProblem::actionsAfterTimeStep(), AngleOfRepose::actionsBeforeTimeStep(), LawinenBox::actionsBeforeTimeStep(), SmoothChute::actionsBeforeTimeStep(), AngleOfRepose::actionsBeforeTimeStep(), Chutebelt::actionsBeforeTimeStep(), ChutePeriodic::add_flow_particles(), SilbertPeriodic::add_flow_particles(), ChuteWithPeriodicInflow::AddContinuingBottom(), BulbousHead::addFlowParticlesCompactly(), Chute::addFlowParticlesCompactly(), NautaMixer::addParticles(), statistics_while_running< T >::auto_set_domain(), statistics_while_running< T >::auto_set_z(), Mercury3DSPH::buildLookupTable(), Mercury3Dclump::checkClumpForInteractionPeriodic(), DPMBase::checkParticleForInteractionLocalPeriodic(), ChuteWithContraction::ChuteWithContraction(), ChuteWithPeriodicInflowAndContinuingBottom::ChuteWithPeriodicInflowAndContinuingBottom(), ChuteWithPeriodicInflowAndContraction::ChuteWithPeriodicInflowAndContraction(), ChuteWithPeriodicInflowAndVariableBottom::ChuteWithPeriodicInflowAndVariableBottom(), AxisymmetricHopper::cleanChute(), ChuteWithPeriodicInflow::cleanChute(), ChuteWithContraction::cleanChute(), Funnel::cleanChute(), Chute::cleanChute(), ClosedCSCRestart::ClosedCSCRestart(), ClosedCSCRun::ClosedCSCRun(), ContractionWithPeriodicInflow::ContractionWithPeriodicInflow(), Slide::create_rough_wall(), AngleOfRepose::createBaseSpecies(), SilbertPeriodic::createBaseSpecies(), FlowRule::createBottom(), CSCInit::CSCInit(), ChuteWithPeriodicInflow::ExtendInWidth(), SphericalIndenter::getBedHeight(), getNumberOfUnfixedParticles(), getPSD(), InitialConditions< SpeciesType >::InitialConditions(), ChuteWithPeriodicInflow::integrateBeforeForceComputation(), ContactDetectionIntersectionOfWallsTest::introduceParticlesAtWall(), LawinenBox::LawinenBox(), main(), main(), ChuteBottom::makeRoughBottom(), LiquidMigrationSelfTest::outputXBallsData(), SphericalIndenter::outputXBallsData(), SilbertPeriodic::printTime(), LawinenBox::printTime(), GranuDrum::printTime(), GranuHeap::printTime(), ChuteWithPeriodicInflow::printTime(), Drum::printTime(), RotatingDrumWet::printTime(), VerticalMixer::printTime(), SilbertPeriodic::printTime(), vibratedBed::printTime(), RotatingDrumBidisperse::printTime(), Chute::printTime(), statistics_while_running< T >::processStatistics(), readAndCreateObject(), RotatingDrumBidisperse::RotatingDrumBidisperse(), CSCInit::save(), RotatingDrumBidisperseInitialise::save(), save(), ClosedCSCWalls::saveWalls(), CSCWalls::saveWalls(), VFunnel::seedOutletExtensionFluidHCP(), MeshTriangle::setHandler(), LawinenBox::setupInitialConditions(), ClosedCSCWalls::setupInitialConditions(), CSCRun::setupInitialConditions(), CSCWalls::setupInitialConditions(), Binary::setupInitialConditions(), FreeCooling2DinWalls::setupInitialConditions(), FreeCooling2DinWallsDemo::setupInitialConditions(), FreeCooling3DDemoProblem::setupInitialConditions(), FreeCooling3DinWallsDemo::setupInitialConditions(), FreeCoolingDemoProblem::setupInitialConditions(), HourGlass2D::setupInitialConditions(), HourGlass::setupInitialConditions(), Cstatic2d::setupInitialConditions(), Cstatic3D::setupInitialConditions(), AngleOfRepose::setupInitialConditions(), SilbertPeriodic::setupInitialConditions(), InitialBed::setupInitialConditions(), RayleighKothe::setupInitialConditions(), Chutebelt::setupInitialConditions(), ParticleCreation::setupInitialConditions(), TriangulatedScrewSelfTest::setupInitialConditions(), TriangulatedStepWallSelfTest::setupInitialConditions(), TriangulatedWallSelfTest::setupInitialConditions(), SphericalIndenter::setupInitialConditions(), ScalingTestRun::setupInitialConditions(), SPHParallelPlateRheometer::setupInitialConditions(), GranularCollapse::setupInitialConditions(), Tutorial11::setupInitialConditions(), MD_demo::setupInitialConditions(), ChuteBottom::setupInitialConditions(), SingleParticleIndenter::SingleParticleIndenter(), and SilbertHstop::writeToEne().

◆ getNumberOfRealObjects()

unsigned int ParticleHandler::getNumberOfRealObjects ( ) const

Returns the number of real objects (on all processors)

1335{
1336#ifdef MERCURYDPM_USE_MPI
1337 MPIContainer& communicator = MPIContainer::Instance();
1338 unsigned int numberOfRealParticles = getNumberOfRealObjectsLocal();
1339
1340 // \todo MX: use an allreduce here
1341 //Combine the total number of Particles into one number on processor 0
1342 communicator.reduce(numberOfRealParticles, MPI_SUM);
1343
1344 //Broadcast new number to all the processorsi
1345 communicator.broadcast(numberOfRealParticles);
1346 return numberOfRealParticles;
1347#else
1348 return getSize();
1349#endif
1350}

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

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

◆ getNumberOfRealObjectsLocal()

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
1314{
1315#ifdef MERCURYDPM_USE_MPI
1316 const MPIContainer& communicator = MPIContainer::Instance();
1317 if (communicator.getNumberOfProcessors() > 1)
1318 {
1319 unsigned int numberOfFakeParticles = 0;
1322 logger.assert_debug(numberOfFakeParticles <= getSize(), "More fake particles than getSize()");
1323 return (getSize() - numberOfFakeParticles);
1324 }
1325 else
1326 {
1327 return getSize();
1328 }
1329#else
1330 return getSize();
1331#endif
1332}
PeriodicBoundaryHandler periodicBoundaryHandler
Internal handler that deals with periodic boundaries, especially in a parallel build.
Definition DPMBase.h:1472
DomainHandler domainHandler
An object of the class DomainHandler which deals with parallel code.
Definition DPMBase.h:1477
Domain * getCurrentDomain()
Gets the domain assigned to the processor.
Definition DomainHandler.cc:228
unsigned int getNumberOfTrueMPIParticles()
Obtains the number of particles in the particleHandler that are MPIParticles, but NOT periodic partic...
Definition Domain.cc:1665
std::size_t getNumberOfProcessors() const
Get the total number of processors participating in this simulation.
Definition MpiContainer.cc:83
unsigned int getNumberOfPeriodicGhostParticles()
Returns the number of particles that are flagged is periodicGhostParticle.
Definition PeriodicBoundaryHandler.cc:335

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 MaserRepeatedOutInMPI2Test::actionsAfterSolve(), TwoByTwoMPIDomainMPI4Test::actionsAfterTimeStep(), getMeanRadius(), getNumberOfRealObjects(), and DPMBase::outputXBallsData().

◆ getNumberOfUnfixedParticles()

unsigned int ParticleHandler::getNumberOfUnfixedParticles ( ) const

Gets the number of particles that are not fixed.

1036{
1038}
unsigned int getNumberOfObjects() const override
Returns the number of objects in the container. In parallel code this practice is forbidden to avoid ...
Definition ParticleHandler.cc:1355

References getNumberOfObjects(), and NFixedParticles_.

◆ getParticleAttribute()

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 useful 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 AttributeType 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 attribute such as radius
287 {
288#ifdef MERCURYDPM_USE_MPI
289 T particleAttributeLocal = getParticleAttributeLocal(attribute, type);
290 T particleAttributeGlobal;
291
292 //Communicate local to global using the approriate rule
293 MPIContainer& communicator = MPIContainer::Instance();
294 switch(type)
295 {
296 case AttributeType::MIN :
297 communicator.allReduce(particleAttributeLocal,particleAttributeGlobal,MPI_MIN);
298 break;
299 case AttributeType::MAX :
300 communicator.allReduce(particleAttributeLocal,particleAttributeGlobal,MPI_MAX);
301 break;
302 default :
303 logger(ERROR,"Attribute type is not recognised");
304 break;
305 }
306 return particleAttributeGlobal;
307#else
308 return getParticleAttributeLocal(attribute, type);
309#endif
310 }
Eigen::Triplet< double > T
Definition EigenUnitTest.cpp:11
@ MIN
Definition ParticleHandler.h:19
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...
Definition ParticleHandler.h:225
default
Definition calibrate.py:45

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

◆ getParticleAttributeLocal()

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 useful 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 AttributeType 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 attribute such as radius
226 {
227 T attributeParticle;
228 T attributeFinal;
229
230 if ((*this).getSize() == 0)
231 {
232 logger(WARN, "ParticleHandler is empty: returning 0.0");
233 attributeFinal = 0;
234 return 0.0;
235 }
236 else
237 {
238 //Initialise with the first particle found
239 attributeParticle = attribute(objects_[0]);
240 attributeFinal = attributeParticle;
241
242 //Find the final attribute
243 for (BaseParticle* particle : (*this))
244 {
245 //Obtain the attribute
246 if (!(particle->isMPIParticle() || particle->isPeriodicGhostParticle() || particle->isFixed()))
247 {
248 attributeParticle = attribute(particle);
249 }
250
251 //Decide what to do with the magnitude of the attribute
252 switch (type)
253 {
254 case AttributeType::MIN :
255 if (attributeParticle < attributeFinal)
256 {
257 attributeFinal = attributeParticle;
258 }
259 break;
260 case AttributeType::MAX :
261 if (attributeParticle > attributeFinal)
262 {
263 attributeFinal = attributeParticle;
264 }
265 break;
266 default :
267 logger(ERROR, "Attribute type is not recognised");
268 break;
269 }
270 }
271 return attributeFinal;
272 }
273 }

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

Referenced by getParticleAttribute().

◆ getPSD()

PSD ParticleHandler::getPSD ( std::vector< Mdouble >  bins = {},
Mdouble  scaleFactor = 1.0 
) const

Gets the PSD from the particles currently in the handler.

When no bins are provided, they will be created linearly between the smallest and largest particle radius in the handler. When bins are provided and don't include the smallest/largest particle size currently in the handler, they will be added. For the largest particle size this is a necessity, otherwise there is no way to account for larger particles. For the smallest particle size this isn't strictly necessary, however it is preferred to have the PSD start with zero probability.

Parameters
binsOptionally, the bins of interest.
scaleFactorOptionally, value to scale the bins by, to convert them to radii. E.g. 0.5 when diameters are provided.
Returns
1460{
1461 // check that there is at least one particle in the handler
1462 if (getNumberOfObjects()==0) {
1463 logger(WARN, "getPSD: Empty PSD is returned, as particleHandler is empty.");
1464 return PSD();
1465 }
1466
1467 // check that the bins vector is set
1468#ifdef MERCURYDPM_USE_MPI
1469 double rMin = getSmallestInteractionRadius();
1470 double rMax = getLargestInteractionRadius();
1471#else
1472 double rMin = getSmallestParticle()->getRadius();
1473 double rMax = getLargestParticle()->getRadius();
1474#endif
1475 if (bins.empty()) {
1476 // Number of bins needed with average of 20 particles in each bin.
1477 int n = (int)std::ceil(getNumberOfObjects()/20);
1478 // Limit number of bins to a certain maximum and minimum.
1479 n = std::min(100, n);
1480 n = std::max(5, n);
1481 bins.reserve(n);
1482 double dr = (rMax-rMin)/(n-1);
1483 for (int i = 0; i<n-1; i++) {
1484 bins.push_back(rMin + i * dr);
1485 }
1486 } else {
1487 // make sure values are in increasing order
1488 std::sort(bins.begin(), bins.end());
1489 // and convert to radius
1490 for (auto& b : bins) {
1491 b *= scaleFactor;
1492 }
1493 }
1494
1495 // set the first/last bin to include the smallest/largest particle (first bin to make PSD start with zero probability)
1496 if (bins.front() > rMin) {
1497 bins.insert(bins.begin(), rMin);
1498 }
1499 if (bins.back() < rMax) {
1500 bins.push_back(rMax);
1501 }
1502
1503 // PSD vector, all probabilities initialised to 0
1504 std::vector<DistributionElements> des;
1505 des.reserve(bins.size());
1506 for (const Mdouble bin : bins) {
1507 des.push_back({ bin, 0.0 });
1508 }
1509
1510 // calculate the probabilities
1511 for (const auto& p : *this) {
1512 if (p->isFixed() || p->isMPIParticle() || p->isPeriodicGhostParticle()) {
1513 continue;
1514 }
1515 // the first "bin"/radius is skipped, since the probabilities for each bin are assigned to its upper radius
1516 // i.e. the PSD should start with zero probability
1517 for (auto bin = des.begin() + 1; bin != des.end(); bin++) {
1518 if (p->getRadius() <= bin->internalVariable) {
1519 bin->probability += 1.0 / getNumberOfRealObjects();
1520 break;
1521 }
1522 }
1523 }
1524
1525 // create and return PSD
1526 PSD psd;
1528 return psd;
1529}
const unsigned n
Definition CG3DPackingUnitTest.cpp:11
Mdouble getRadius() const
Returns the particle's radius.
Definition BaseParticle.h:339
Contains a vector with radii and probabilities of a user defined particle size distribution (PSD)
Definition PSD.h:47
@ PROBABILITYDENSITY_NUMBER_DISTRIBUTION
void setPSDFromVector(std::vector< DistributionElements > psd, TYPE PSDType)
Sets the PSD from a vector with DistributionElements.
Definition PSD.cc:513
Mdouble getLargestInteractionRadius() const
Returns the largest interaction radius.
Definition ParticleHandler.cc:790
Mdouble getSmallestInteractionRadius() const
Returns the smallest interaction radius.
Definition ParticleHandler.cc:754
unsigned int getNumberOfRealObjects() const
Returns the number of real objects (on all processors)
Definition ParticleHandler.cc:1334
BaseParticle * getSmallestParticle() const
Gets a pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler of the loc...
Definition ParticleHandler.cc:529
bins
Definition UniformPSDSelfTest.py:19

References getLargestInteractionRadius(), getLargestParticle(), getNumberOfObjects(), getNumberOfRealObjects(), BaseParticle::getRadius(), getSmallestInteractionRadius(), getSmallestParticle(), logger, n, PSD::PROBABILITYDENSITY_NUMBER_DISTRIBUTION, PSD::setPSDFromVector(), and WARN.

Referenced by saveNumberPSDtoCSV().

◆ getRotationalEnergy()

Mdouble ParticleHandler::getRotationalEnergy ( ) const
605{
606#ifdef MERCURYDPM_USE_MPI
607 Mdouble rotationalEnergyLocal = getRotationalEnergyLocal();
608 Mdouble rotationalEnergyGlobal = 0.0;
609
610 //sum up over all domains
611 MPIContainer& communicator = MPIContainer::Instance();
612 communicator.allReduce(rotationalEnergyLocal, rotationalEnergyGlobal, MPI_SUM);
613
614 return rotationalEnergyGlobal;
615#else
617#endif
618}
Mdouble getRotationalEnergyLocal() const
Definition ParticleHandler.cc:591

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

Referenced by main(), DPMBase::writeEneTimeStep(), and LawinenBox::writeEneTimeStep().

◆ getRotationalEnergyLocal()

Mdouble ParticleHandler::getRotationalEnergyLocal ( ) const
private
592{
593 Mdouble ene = 0;
594 for (auto p : *this)
595 {
596 if (!(p->isMPIParticle() || p->isPeriodicGhostParticle()))
597 {
598 ene += p->getRotationalEnergy();
599 }
600 }
601 return ene;
602}

Referenced by getRotationalEnergy().

◆ getSmallestInteractionRadius()

Mdouble ParticleHandler::getSmallestInteractionRadius ( ) const

Returns the smallest interaction radius.

755{
756#ifdef MERCURYDPM_USE_MPI
757 //Compute the local value
758 Mdouble smallestInteractionRadiusLocal = getSmallestInteractionRadiusLocal();
759 Mdouble smallestInteractionRadiusGlobal = 0.0;
760
761 //Obtain the global value
762 MPIContainer& communicator = MPIContainer::Instance();
763 communicator.allReduce(smallestInteractionRadiusLocal, smallestInteractionRadiusGlobal, MPI_MIN);
764
765 return smallestInteractionRadiusGlobal;
766
767#else
769#endif
770}
Mdouble getSmallestInteractionRadiusLocal() const
Returns the smallest interaction radius of the current domain.
Definition ParticleHandler.cc:739

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

Referenced by Contact::actionsAfterSolve(), getPSD(), and main().

◆ getSmallestInteractionRadiusLocal()

Mdouble ParticleHandler::getSmallestInteractionRadiusLocal ( ) const

Returns the smallest interaction radius of the current domain.

740{
741 if (!(getSmallestParticleLocal() == nullptr))
742 {
744 }
745 else
746 {
747 return 0.0;
748 }
749}
BaseParticle * getSmallestParticleLocal() const
Gets a pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler of the loc...
Definition ParticleHandler.cc:520

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

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

◆ getSmallestParticle()

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.
530{
531#ifdef MERCURYDPM_USE_MPI
532 logger(WARN,"getSmallestParticle should not be used in parallel; use getSmallestInteractionRadius or "
533 "ParticleSpecies::getSmallestParticleMass instead");
534 return nullptr;
535#else
537#endif
538}

References getSmallestParticleLocal(), logger, and WARN.

Referenced by RotatingDrumBidisperseInitialise::actionsAfterTimeStep(), getPSD(), HGridOptimiser::initialise(), and CFDDEMCoupleTest::setupInitialConditions().

◆ getSmallestParticleLocal()

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.
521{
522 return smallestParticle_;
523}

References smallestParticle_.

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

◆ getSumRadiusLocal()

Mdouble ParticleHandler::getSumRadiusLocal ( ) const
private
Returns
The sum of all particle radii
810{
811 Mdouble sumRadius = 0;
812 for (BaseParticle* const p : objects_)
813 {
814 if (!(p->isMPIParticle() || p->isPeriodicGhostParticle()))
815 {
816 sumRadius += p->getRadius();
817 }
818 }
819 return sumRadius;
820}

References BaseHandler< BaseParticle >::objects_.

Referenced by getMeanRadius().

◆ getVolume()

◆ getVolumeLocal()

Mdouble ParticleHandler::getVolumeLocal ( ) const
private
1283{
1284 Mdouble volume = 0;
1285 for (auto p : *this)
1286 {
1287 if (!(p->isFixed() || p->isPeriodicGhostParticle() || p->isMPIParticle()))
1288 volume += p->getVolume();
1289 }
1290 return volume;
1291}

Referenced by getVolume().

◆ getWriteVTK()

FileType ParticleHandler::getWriteVTK ( ) const

Returns whether particles are written in a VTK file.

Returns
The file type used for VTK output.
1543{
1544 return writeVTK_;
1545}

References writeVTK_.

Referenced by DPMBase::getParticlesWriteVTK(), DPMBase::getSuperquadricParticlesWriteVTK(), DPMBase::initialiseVTK(), DPMBase::write(), DPMBase::writePythonFileForVTKVisualisation(), and DPMBase::writeVTKFiles().

◆ operator=()

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.

69{
70 if (this != &rhs)
71 {
72 clear();
73 largestParticle_ = nullptr;
74 smallestParticle_ = nullptr;
76 if (!objects_.empty())
77 {
80 }
81 writeVTK_ = rhs.writeVTK_;
82 }
83 logger(DEBUG, "ParticleHandler::operator = (const ParticleHandler& rhs) finished");
84 return *this;
85}

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

◆ readAndAddObject()

void ParticleHandler::readAndAddObject ( std::istream &  is)
overridevirtual
     \brief Create a new particle, based on the information from old-style restart data.
    &zwj;/

void readAndCreateOldObject(std::istream &is, const std::string& type);

/*!
   \brief 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 >.

1125{
1128}
void addExistingObject(BaseParticle *P) override
Adds a BaseParticle to the ParticleHandler.
Definition ParticleHandler.cc:115
BaseParticle * readAndCreateObject(std::istream &is)
Create a new particle, based on the information provided in a restart file.
Definition ParticleHandler.cc:1095

References addExistingObject(), and readAndCreateObject().

Referenced by DPMBase::read().

◆ readAndCreateObject()

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.
Todo:
check what is special about this case
1096{
1097 std::string type;
1098 BaseParticle* particle = nullptr;
1099 if (getNumberOfObjects()>0) logger(DEBUG,"size % % %",getNumberOfObjects(),getLastObject()->getVelocity(),getLastObject()->getRadius());
1100 if (getStorageCapacity() > 0)
1101 {
1102 is >> type;
1103 logger(DEBUG, "ParticleHandler::readAndCreateObject(is): type %", type);
1104 particle = createObject(type);
1105 particle->setHandler(this);
1106 particle->read(is);
1107 }
1108 else //for insertion boundaries
1109 {
1111 is >> type;
1112 logger(DEBUG, "ParticleHandler::readAndCreateObject(is): type %", type);
1113 particle = createObject(type);
1114 particle->setHandler(this);
1115 particle->read(is);
1116 }
1117 particle->setSpecies(getDPMBase()->speciesHandler.getObject(particle->getIndSpecies()));
1118 return particle;
1119}
unsigned int getStorageCapacity() const
Gets the storage capacity of this BaseHandler.
Definition BaseHandler.h:670
BaseParticle * getLastObject()
Gets a pointer to the last Object in this BaseHandler.
Definition BaseHandler.h:642
unsigned int getIndSpecies() const
Returns the index of the species associated with the interactable object.
Definition BaseInteractable.h:67
void setHandler(ParticleHandler *handler)
Sets the pointer to the particle's ParticleHandler.
Definition BaseParticle.cc:640
void read(std::istream &is) override
Particle read function, which accepts an std::istream as input.
Definition BaseParticle.cc:368
virtual void setSpecies(const ParticleSpecies *species)
Definition BaseParticle.cc:798
static BaseParticle * createObject(const std::string &type)
Reads BaseParticle into the ParticleHandler from restart data.
Definition ParticleHandler.cc:1043
type
Definition compute_granudrum_aor.py:141

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

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

◆ removedFixedParticle()

void ParticleHandler::removedFixedParticle ( )

Decrement of the number of fixed particles.

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

References NFixedParticles_.

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

◆ removeGhostObject()

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.

441{
442#ifdef MERCURYDPM_USE_MPI
443#ifdef CONTACT_LIST_HGRID
444 getDPMBase()->getPossibleContactList().remove_ParticlePosibleContacts(getObject(id));
445#endif
447 // broadcast the particle removal
448 getDPMBase()->handleParticleRemoval(getObject(index)->getId());
450#else
451 logger(ERROR, "This function should only be used interally for mpi routines");
452#endif
453}
virtual void removeObject(unsigned const int index)
Removes an Object from the BaseHandler.
Definition BaseHandler.h:453
BaseParticle * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition BaseHandler.h:621
virtual void hGridRemoveParticle(BaseParticle *obj UNUSED)
Definition DPMBase.cc:1673

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

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

◆ removeLastObject()

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.

460{
461#ifdef CONTACT_LIST_HGRID
462 getDPMBase()->getPossibleContactList().remove_ParticlePosibleContacts(getLastObject());
463#endif
467}
void removeLastObject()
Removes the last Object from the BaseHandler.
Definition BaseHandler.h:519

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

Referenced by Penetration::setupInitialConditions().

◆ removeObject()

void ParticleHandler::removeObject ( unsigned int  index)
overridevirtual

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

Reimplemented from BaseHandler< BaseParticle >.

413{
414#ifdef MERCURYDPM_USE_MPI
415 MPIContainer& communicator = MPIContainer::Instance();
416 if (communicator.getNumberOfProcessors() > 1 )
417 {
418 logger(WARN, "[ParticleHandler::removeObject(const unsigned int)] Using the function removeObject in parallel could lead to out-of-sync communication, Instead use deletion boundaries");
419 }
420#endif
421#ifdef CONTACT_LIST_HGRID
422 getDPMBase()->getPossibleContactList().remove_ParticlePosibleContacts(getObject(id));
423#endif
425 // broadcast the particle removal
426 getDPMBase()->handleParticleRemoval(getObject(index)->getId());
428}

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

Referenced by VFunnel::actionsAfterTimeStep(), AngleOfRepose::actionsBeforeTimeStep(), AngleOfRepose::actionsBeforeTimeStep(), PeriodicWallsWithSlidingFrictionUnitTest::actionsBeforeTimeStep(), SilbertPeriodic::add_flow_particles(), CircularPeriodicBoundary::checkBoundaryAfterParticleMoved(), ConstantMassFlowMaserBoundary::checkBoundaryAfterParticleMoved(), DeletionBoundary::checkBoundaryAfterParticleMoved(), ChuteWithContraction::ChuteWithContraction(), ChuteWithPeriodicInflowAndContraction::ChuteWithPeriodicInflowAndContraction(), VariableBottom::cleanChute(), AxisymmetricHopper::cleanChute(), ChuteWithPeriodicInflow::cleanChute(), ChuteWithContraction::cleanChute(), Funnel::cleanChute(), Chute::cleanChute(), ContactDetectionTester::cleanup(), ContractionWithPeriodicInflow::ContractionWithPeriodicInflow(), ChuteBottom::makeRoughBottom(), CurvyChute::recreateBottom(), DPMBase::removeDuplicatePeriodicParticles(), CSCWalls::saveWalls(), and AngleOfRepose::setupInitialConditions().

◆ saveNumberPSDtoCSV()

void ParticleHandler::saveNumberPSDtoCSV ( std::string  csvFileName,
std::vector< double >  diameterBins = {} 
) const

Writes the PSD of the particles currently in the handler to a CSV file, with type PROBABILITYDENSITY_NUMBER_DISTRIBUTION.

Parameters
csvFileNameThe filename to write to.
diameterBinsOptionally, the bins of interest.
1433{
1434 // get the PSD, with scale factor 0.5 to scale diameter to radius
1435 PSD psd = getPSD(diameterBins, 0.5);
1436 // get the PSD vector by the required type, with scale factor 2 to scale radius to diameter
1437 std::vector<DistributionElements> psdVector = psd.getParticleSizeDistributionByType(PSD::TYPE::PROBABILITYDENSITY_NUMBER_DISTRIBUTION, 2.0);
1438
1439 logger(INFO,"Writing PSD to %",csvFileName);
1440 std::ofstream csv(csvFileName);
1441 logger.assert_always(csv.is_open(),"File % could not be opened",csvFileName);
1442 csv << "Diameter" << ',' << "Probability Number Distribution" << '\n';
1443 for (const auto& bin : psdVector) {
1444 csv << bin.internalVariable << ',' << bin.probability << '\n';
1445 }
1446 csv.close();
1447}
std::vector< DistributionElements > getParticleSizeDistributionByType(TYPE psdType, Mdouble scalingFactor=1.0) const
Gets the PSD vector, converted to the preferred type.
Definition PSD.cc:1067
PSD getPSD(std::vector< Mdouble > bins={}, Mdouble scaleFactor=1.0) const
Gets the PSD from the particles currently in the handler.
Definition ParticleHandler.cc:1459

References PSD::getParticleSizeDistributionByType(), getPSD(), INFO, logger, and PSD::PROBABILITYDENSITY_NUMBER_DISTRIBUTION.

Referenced by main(), and main().

◆ setWriteVTK()

void ParticleHandler::setWriteVTK ( bool  writeVTK)

Sets whether particles are written into a VTK file.

Parameters
[in]writeVTKtrue if VTK output should be enabled (MULTIPLE_FILES).
1535{
1537}
@ MULTIPLE_FILES
each time-step will be written into/read from separate files numbered consecutively: name_....
virtual void writeVTK() const
now empty function for writing VTK files.
Definition BaseHandler.h:267

References MULTIPLE_FILES, NO_FILE, BaseHandler< BaseParticle >::writeVTK(), and writeVTK_.

Referenced by Chutebelt::actionsAfterTimeStep(), BaseCluster::actionsOnRestart(), AxisymmetricWallSelfTest::AxisymmetricWallSelfTest(), HorizontalMixer::HorizontalMixer(), LaserOnLayer::LaserOnLayer(), main(), main(), main(), main(), MaserRepeatedOutInMPI2Test::MaserRepeatedOutInMPI2Test(), ParticleBeam::ParticleBeam(), protectiveWall::protectiveWall(), DPMBase::read(), RotatingDrumBidisperse::RotatingDrumBidisperse(), DPMBase::setParticlesWriteVTK(), DPMBase::setSuperquadricParticlesWriteVTK(), ChutePeriodicDemo::setupInitialConditions(), MaserDemo::setupInitialConditions(), ChangingTOIParticle::setupInitialConditions(), NautaMixer::setupInitialConditions(), NozzleDemo::setupInitialConditions(), Drum::setupInitialConditions(), RotatingDrumWet::setupInitialConditions(), MarbleRun::setupInitialConditions(), BulbousHead::setupInitialConditions(), InitialBed::setupInitialConditions(), MeltableForceLaw2SelfTest::setupInitialConditions(), MeltableForceLawSelfTest::setupInitialConditions(), ThermalConductionSelfTest::setupInitialConditions(), Penetration::setupInitialConditions(), Silo::setupInitialConditions(), RayleighKothe::setupInitialConditions(), SegregationPeriodic::setupInitialConditions(), SingleParticleSegregation::setupInitialConditions(), NozzleSelfTest::setupInitialConditions(), SubcriticalMaserBoundarySelfTest::setupInitialConditions(), TwoParticleBagheriCollision::setupInitialConditions(), TwoParticleClassicalWilletCollision::setupInitialConditions(), RollingOverTriangleWalls::setupInitialConditions(), PSDSelfTest::setupInitialConditions(), MovingWalls::setupInitialConditions(), AreaVTK::setupInitialConditions(), BaseCluster::setupInitialConditions(), MercuryProblem::setupMercuryProblem(), SinterPair::SinterPair(), SubcriticalMaserBoundaryTESTMPI2Test::SubcriticalMaserBoundaryTESTMPI2Test(), T_protectiveWall::T_protectiveWall(), TangentialSpringEnergyConservationUnitTest::TangentialSpringEnergyConservationUnitTest(), BouncingSuperQuadric::test(), and Tutorial11::Tutorial11().

◆ write()

Member Data Documentation

◆ largestParticle_

BaseParticle* ParticleHandler::largestParticle_
private

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

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

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

◆ NFixedParticles_

unsigned int ParticleHandler::NFixedParticles_
private

◆ smallestParticle_

BaseParticle* ParticleHandler::smallestParticle_
private

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

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

◆ writeVTK_

FileType ParticleHandler::writeVTK_
private

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