Domain Class Referencefinal

The simulation can be subdivided into Domain's used in parallel code. More...

#include <Domain.h>

+ Inheritance diagram for Domain:

Public Member Functions

 Domain ()
 Default Domain constructor. More...
 
 Domain (std::vector< unsigned > globalMeshIndex)
 Constructs an empty domain with a globalMeshIndex. More...
 
 Domain (const Domain &d)
 Constructor that copies the domain range and rank from a given domain. More...
 
 ~Domain () override
 Destructor, destroys the domain. More...
 
void constructor ()
 contructor of a domain More...
 
virtual Domaincopy () const
 Function that creates a copy of this current domain, using the copy constructor. More...
 
void read (std::istream &is) override
 This function does nothing. More...
 
void write (std::ostream &os) const override
 This function does nothing. More...
 
std::string getName () const override
 Returns the name of the object. More...
 
void setRange (Direction direction, Mdouble min, Mdouble max)
 Sets the domain range in a given direction. More...
 
void setBounds (std::vector< double > domainLeft, std::vector< double > domainRight, bool computeMiddle)
 Sets the domain bounds. More...
 
std::vector< doublegetDomainMin ()
 Gets the minimum domain bounds. More...
 
std::vector< doublegetDomainMax ()
 Gets the maximum domain bounds. More...
 
int getRank ()
 Gets the rank associated with the assigned processorID. More...
 
void setRank (int rank)
 Sets the rank associated with the assigned processorID. More...
 
void setHandler (DomainHandler *handler)
 Sets the domainHandler. More...
 
DomainHandlergetHandler () const
 Gets the domainHandler. More...
 
int getGlobalIndex ()
 Gets the global index of the domain. More...
 
std::vector< unsigned > getGlobalMeshIndex ()
 Gets the global mesh index of the domain. More...
 
void setGlobalMeshIndex (std::vector< unsigned > globalMeshIndex)
 Sets the global mesh index of theh domain. More...
 
void disableBoundary (unsigned localIndex)
 Disables a boundary of the domain with a neighbouring domain. More...
 
void disableBoundaries ()
 disables all domain boundaries that have no neighbour More...
 
std::vector< boolgetActiveBoundaryList ()
 Returns a list of boundaries that are active in mpi communication. More...
 
bool containsParticle (BaseParticle *particle, Mdouble offset=0.0)
 Check to see if a given particle is within the current domain. More...
 
bool isInGreaterDomain (BaseParticle *particle)
 Check to see if a given particle is in the current domain or in neighbouring communication zones. More...
 
bool isInInnerDomain (BaseParticle *particle)
 Check if the particle is in the current domain but not in the communication zone. More...
 
bool isInCommunicationZone (BaseParticle *particle)
 Check if the particle is in the communication zone of the current domain. More...
 
void createLookUpTable ()
 Create a look up table between local index system to global index system. More...
 
int getLocalIndex (int i, int j, int k)
 return the local index of a domain given local mesh indices i,j and k More...
 
int getLocalIndex (std::vector< int > localMeshIndex)
 return the local index of a doman given the localMeshIndex vector More...
 
std::vector< int > getLocalIndexInverse (int localMeshIndex)
 
BaseParticlefindParticleInList (unsigned int identification, std::vector< BaseParticle * > particleList)
 Searches for a particle with a specific id in a list of particles. More...
 
std::vector< int > findNearbyBoundaries (BaseParticle *particle, Mdouble offset=0)
 This function finds if a given particle is close to a given boundary. More...
 
bool inBoundary (BaseParticle *particle, int localIndex)
 
void addParticlesToLists (BaseParticle *particle, std::vector< std::vector< BaseParticle * > > &list)
 Function that adds the particles to the approriate boundary list. More...
 
void findNewMPIParticles (const ParticleHandler &particleHandler)
 Function that finds new particles in the particle handler that should be added to the communication lists. More...
 
void findNewMPIParticle (BaseParticle *particle)
 Function that check if a given particle should be added to the communication lists. More...
 
bool isInNewBoundaryParticleList (BaseParticle *object, int localIndex) const
 
void findNewMPIInteractions ()
 Finds interactions that have to be send over to another domain. More...
 
void collectBoundaryParticleData (int localIndex)
 collects the data of a particle that has to be communicated to other processors More...
 
void collectInteractionData (int localIndex)
 Collects the data of an interaction that has to be communicated to other processors. More...
 
void processReceivedBoundaryParticleData (unsigned index, std::vector< BaseParticle * > &newParticles)
 Function that copies the mpi data format of a base particle to a real particle and adds it to the particleHandler. More...
 
void processSentBoundaryParticles (unsigned index)
 Bookkeep the newly send particles. More...
 
void processReceivedInteractionData (unsigned index, std::vector< BaseParticle * > &newParticles)
 Processes the received interactions from newly added mpi particles
More...
 
void debugInformation ()
 
void sendAndReceiveCount (MercuryMPITag tag, unsigned &countReceive, unsigned &countSend, unsigned localIndexNeighbour)
 A symmetric communication between two domains exchanging a send/recieve count. More...
 
void prepareBoundaryDataTransmission ()
 Prepares the MPI transmission of particle and interaction data from particles in particleHandler. More...
 
void prepareBoundaryDataTransmission (BaseParticle *particle)
 Prepares the MPI transmission of a single particle and its interactions. More...
 
void performBoundaryDataTransmission ()
 Collects data to be transmitted and then performs the transmission of the data. More...
 
void finaliseBoundaryDataTransmission ()
 This function processes the transmitted data. More...
 
void updateParticles (std::set< BaseParticle * > &ghostParticlesToBeDeleted)
 This step updates all communication lists and particles in the communication zone. More...
 
void updateParticlePosition (int localIndex)
 Updates the position of particles which are flagged as MPIParticles. More...
 
void updateParticleVelocity (int localIndex)
 Updates the velocity of particles which are flagged as MPIParticles. More...
 
void preparePositionAndVelocityUpdate ()
 Function that sends particle position and velocity data for ghost particles to other processors. More...
 
void finalisePositionAndVelocityUpdate (std::set< BaseParticle * > &ghostParticlesToBeDeleted)
 processes position and velocity data for ghost particles More...
 
void prepareVelocityUpdate ()
 Function that sends particle velocity data for ghost particles. More...
 
void finaliseVelocityUpdate ()
 Processes particle velocity data for ghost particles. More...
 
template<typename T >
void sendAndReceiveMPIData (MercuryMPITag tag, MercuryMPIType type, T *receiveData, unsigned receiveCount, T *sendData, unsigned sendCount, unsigned localIndexNeighbour)
 Function that sends transmissionData/positionData/velocityData to other processors. More...
 
void addNewParticles ()
 Initialises the MPIParticles by communicating newly found particles. More...
 
void addParticle (BaseParticle *particle)
 Initialises a single particle which is added during the simulation. More...
 
void updateStatus (std::set< BaseParticle * > &ghostParticlesToBeDeleted)
 Updates particles that are not in the current domain and communicates newly added particles. More...
 
void updateVelocity ()
 Updates MPI particle velocity at the half-time step. More...
 
unsigned int getNumberOfMPIParticles ()
 Obtains the number of particles in the particleHandler that are MPIParticles. More...
 
unsigned int getNumberOfTrueMPIParticles ()
 Obtains the number of particles in the particleHandler that are MPIParticles, but NOT periodic particles. More...
 
void flushParticles (std::set< BaseParticle * > &toBeDeletedList)
 Particles that are going to be deleted from the simulation are flushed out of the communication boundaries. More...
 
void flushParticlesFromList (std::vector< BaseParticle * > &list, std::set< BaseParticle * > &toBeDeletedList)
 Particles that are going to be deleted from the simulation are flushed out of a give communcation boundary. More...
 
Vec3D getMiddle () const
 Gives the middle of the domain. More...
 
void cleanCommunicationLists ()
 Removes nullptrs from boundaryParticleList_ and boundaryParticleListNeighbour_. More...
 
void cleanCommunicationList (std::vector< BaseParticle * > &list)
 Removes nullptr's from a given particle list. More...
 
- Public Member Functions inherited from BaseObject
 BaseObject ()=default
 Default constructor. More...
 
 BaseObject (const BaseObject &p)=default
 Copy constructor, copies all the objects BaseObject contains. More...
 
virtual ~BaseObject ()=default
 virtual destructor More...
 
virtual void moveInHandler (unsigned int index)
 Except that it is virtual, it does the same thing as setIndex() does. More...
 
void setIndex (unsigned int index)
 Allows one to assign an index to an object in the handler/container. More...
 
void setId (unsigned long id)
 Assigns a unique identifier to each object in the handler (container) which remains constant even after the object is deleted from the container/handler. More...
 
unsigned int getIndex () const
 Returns the index of the object in the handler. More...
 
unsigned int getId () const
 Returns the unique identifier of any particular object. More...
 
void setGroupId (unsigned groupId)
 
unsigned getGroupId () const
 

Private Attributes

DomainHandlerdomainHandler_
 Pointer to the domain's DomainHandler container. More...
 
std::vector< doubledomainMin_
 Minimum domain bounds in the x,y and z direction. More...
 
std::vector< doubledomainMax_
 Maximum domain bounds in the x,y and z direction. More...
 
Vec3D middle_
 Middle of the closed domain. More...
 
int globalIndex_
 Global index of the domain in the mesh. More...
 
std::vector< unsigned > globalMeshIndex_
 Vector containing the global mesh indices i,j,k. More...
 
std::vector< int > localIndexToGlobalIndexTable_
 look-up table to get the global index given a local domain index More...
 
std::vector< int > localIndexToProcessorList_
 look-up table to get the processor of the domain given a local domain index More...
 
std::vector< boolactiveBoundaryList_
 A list of flags corresponding to an inactive or active boundary. More...
 
std::vector< int > boundaryList_
 A list of indices of all the active boundaries. More...
 
std::vector< std::vector< BaseParticle * > > boundaryParticleList_
 A list of boundary particles in the communication zone that are ghost particles on other domains. More...
 
std::vector< std::vector< BaseParticle * > > boundaryParticleListNeighbour_
 a list of ghost particles on the current domain, which are real on the neighbour domain More...
 
std::vector< std::vector< BaseParticle * > > newBoundaryParticleList_
 Array that queues particles that need to be transmitted. More...
 
std::vector< std::vector< BaseInteraction * > > newInteractionList_
 Array that queues interactions that need to be transmitted. More...
 
std::vector< unsigned > numberOfParticlesSend_
 Counter that keeps track of the number of particles that are being send to other domains. More...
 
std::vector< unsigned > numberOfParticlesReceive_
 Counter that keeps track of the number of particles that are being received by this domain. More...
 
std::vector< unsigned > numNewInteractionsSend_
 Counter that keeps track of the number of interactions that are being send to other domains. More...
 
std::vector< unsigned > numNewInteractionsReceive_
 Counter that keeps track of the number of interactions that are being received by this domain. More...
 
std::vector< std::vector< MPIParticle > > boundaryParticleDataSend_
 Container that keeps a list of MPIParticles that are being send to other domains. More...
 
std::vector< std::vector< MPIParticle > > boundaryParticleDataReceive_
 Container that keeps a list of MPIParticles that are being received by this domain. More...
 
std::vector< std::vector< MPIParticlePosition > > updatePositionDataSend_
 Container that keeps a list of MPIParticlePositions that are being send to other domains. More...
 
std::vector< std::vector< MPIParticlePosition > > updatePositionDataReceive_
 Container that keeps a list of MPIParticlePositions that are being received by this domain. More...
 
std::vector< std::vector< MPIParticleVelocity > > updateVelocityDataSend_
 Container that keeps a list of MPIParticleVelocities that are being send to other domains. More...
 
std::vector< std::vector< MPIParticleVelocity > > updateVelocityDataReceive_
 Container that keeps a list of MPIParticleVelocities that are being received by this domain. More...
 
std::vector< void * > interactionDataSend_
 Container that keeps a void array of all the interaction data that are being send to other domains, interpretation is done by the interaction handler. More...
 
std::vector< void * > interactionDataReceive_
 Container that keeps a void array of all the interaction data that is being received by this domain, interpretation is done by the interaction handler. More...
 
int rank_
 Rank of the domain which identifies to which processor it belongs. More...
 

Detailed Description

The simulation can be subdivided into Domain's used in parallel code.

The domain class defines a region in the simulation domain, given by a min vector and a max vector. The domain also as a processorID assigned to it. It has a check to see whether a given particle is in the domain or not.

Constructor & Destructor Documentation

◆ Domain() [1/3]

Domain::Domain ( )

Default Domain constructor.

Constructs an empty domain.

Constructor of the domain class. It creates a domain with infinite bounds and no processor or domainHandler assigned to it and initialises all communication lists

49 {
50  constructor();
51 #ifdef DEBUG_CONSTRUCTOR
52  std::cout<<"Domain::Domain() finished"<<std::endl;
53 #endif
54 }
void constructor()
contructor of a domain
Definition: Domain.cc:133

References constructor().

Referenced by copy().

◆ Domain() [2/3]

Domain::Domain ( std::vector< unsigned >  globalMeshIndex)
explicit

Constructs an empty domain with a globalMeshIndex.

Constructor of the domain class. It creates a domain with infinite bounds and no processor or domainHandler assigned to it and initialises all communication lists

62  : globalMeshIndex_(std::move(globalMeshIndex))
63 {
64  constructor();
65 #ifdef DEBUG_CONSTRUCTOR
66  std::cout<<"Domain::Domain() finished"<<std::endl;
67 #endif
68 }
std::vector< unsigned > globalMeshIndex_
Vector containing the global mesh indices i,j,k.
Definition: Domain.h:474

References constructor().

◆ Domain() [3/3]

Domain::Domain ( const Domain b)

Constructor that copies the domain range and rank from a given domain.

Copies a domain.

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

This constructor copies all the private variables of the current domain into the input domain.

77  : BaseObject(b)
78 {
79  rank_ = b.rank_;
84  middle_ = b.middle_;
85 
86  //A cube has 3^3=27 neighbours
87  unsigned long numberOfNeighbours = 27;
88 
89  //Create all lists
90  localIndexToGlobalIndexTable_ = std::vector<int>(numberOfNeighbours);
91  localIndexToProcessorList_ = std::vector<int>(numberOfNeighbours);
92  boundaryParticleList_ = std::vector<std::vector<BaseParticle*> >(numberOfNeighbours, std::vector<BaseParticle*>(0));
93  boundaryParticleListNeighbour_ = std::vector<std::vector<BaseParticle*> >(numberOfNeighbours,
94  std::vector<BaseParticle*>(0));
95  newBoundaryParticleList_ = std::vector<std::vector<BaseParticle*> >(numberOfNeighbours,
96  std::vector<BaseParticle*>(0));
97  newInteractionList_ = std::vector<std::vector<BaseInteraction*> >(numberOfNeighbours,
98  std::vector<BaseInteraction*>(0));
99  numberOfParticlesSend_ = std::vector<unsigned>(numberOfNeighbours);
100  numberOfParticlesReceive_ = std::vector<unsigned>(numberOfNeighbours);
101  numNewInteractionsSend_ = std::vector<unsigned>(numberOfNeighbours);
102  numNewInteractionsReceive_ = std::vector<unsigned>(numberOfNeighbours);
103  boundaryParticleDataSend_ = std::vector<std::vector<MPIParticle> >(numberOfNeighbours);
104  boundaryParticleDataReceive_ = std::vector<std::vector<MPIParticle> >(numberOfNeighbours);
105  updatePositionDataSend_ = std::vector<std::vector<MPIParticlePosition> >(numberOfNeighbours);
106  updatePositionDataReceive_ = std::vector<std::vector<MPIParticlePosition> >(numberOfNeighbours);
107  updateVelocityDataSend_ = std::vector<std::vector<MPIParticleVelocity> >(numberOfNeighbours);
108  updateVelocityDataReceive_ = std::vector<std::vector<MPIParticleVelocity> >(numberOfNeighbours);
109  interactionDataSend_ = std::vector<void*>(numberOfNeighbours);
110  interactionDataReceive_ = std::vector<void*>(numberOfNeighbours);
111  activeBoundaryList_ = std::vector<bool>(numberOfNeighbours, true);
112  boundaryList_ = std::vector<int>(0);
113 #ifdef DEBUG_CONSTRUCTOR
114  std::cout<<"Domain::Domain(const Domain &b) finished"<<std::endl;
115 #endif
116 }
BaseObject()=default
Default constructor.
std::vector< unsigned > numberOfParticlesReceive_
Counter that keeps track of the number of particles that are being received by this domain.
Definition: Domain.h:527
std::vector< void * > interactionDataReceive_
Container that keeps a void array of all the interaction data that is being received by this domain,...
Definition: Domain.h:577
std::vector< unsigned > numNewInteractionsSend_
Counter that keeps track of the number of interactions that are being send to other domains.
Definition: Domain.h:532
std::vector< bool > activeBoundaryList_
A list of flags corresponding to an inactive or active boundary.
Definition: Domain.h:491
DomainHandler * domainHandler_
Pointer to the domain's DomainHandler container.
Definition: Domain.h:448
std::vector< std::vector< MPIParticle > > boundaryParticleDataSend_
Container that keeps a list of MPIParticles that are being send to other domains.
Definition: Domain.h:542
std::vector< std::vector< BaseInteraction * > > newInteractionList_
Array that queues interactions that need to be transmitted.
Definition: Domain.h:517
std::vector< std::vector< MPIParticle > > boundaryParticleDataReceive_
Container that keeps a list of MPIParticles that are being received by this domain.
Definition: Domain.h:547
std::vector< std::vector< BaseParticle * > > boundaryParticleListNeighbour_
a list of ghost particles on the current domain, which are real on the neighbour domain
Definition: Domain.h:507
std::vector< std::vector< BaseParticle * > > boundaryParticleList_
A list of boundary particles in the communication zone that are ghost particles on other domains.
Definition: Domain.h:502
int rank_
Rank of the domain which identifies to which processor it belongs.
Definition: Domain.h:582
std::vector< unsigned > numberOfParticlesSend_
Counter that keeps track of the number of particles that are being send to other domains.
Definition: Domain.h:522
std::vector< double > domainMin_
Minimum domain bounds in the x,y and z direction.
Definition: Domain.h:453
std::vector< int > localIndexToProcessorList_
look-up table to get the processor of the domain given a local domain index
Definition: Domain.h:486
std::vector< std::vector< MPIParticlePosition > > updatePositionDataReceive_
Container that keeps a list of MPIParticlePositions that are being received by this domain.
Definition: Domain.h:557
std::vector< double > domainMax_
Maximum domain bounds in the x,y and z direction.
Definition: Domain.h:458
std::vector< std::vector< MPIParticleVelocity > > updateVelocityDataSend_
Container that keeps a list of MPIParticleVelocities that are being send to other domains.
Definition: Domain.h:562
std::vector< int > localIndexToGlobalIndexTable_
look-up table to get the global index given a local domain index
Definition: Domain.h:480
Vec3D middle_
Middle of the closed domain.
Definition: Domain.h:463
std::vector< unsigned > numNewInteractionsReceive_
Counter that keeps track of the number of interactions that are being received by this domain.
Definition: Domain.h:537
std::vector< void * > interactionDataSend_
Container that keeps a void array of all the interaction data that are being send to other domains,...
Definition: Domain.h:572
std::vector< std::vector< MPIParticleVelocity > > updateVelocityDataReceive_
Container that keeps a list of MPIParticleVelocities that are being received by this domain.
Definition: Domain.h:567
std::vector< std::vector< BaseParticle * > > newBoundaryParticleList_
Array that queues particles that need to be transmitted.
Definition: Domain.h:512
std::vector< std::vector< MPIParticlePosition > > updatePositionDataSend_
Container that keeps a list of MPIParticlePositions that are being send to other domains.
Definition: Domain.h:552
std::vector< int > boundaryList_
A list of indices of all the active boundaries.
Definition: Domain.h:497

References activeBoundaryList_, boundaryList_, boundaryParticleDataReceive_, boundaryParticleDataSend_, boundaryParticleList_, boundaryParticleListNeighbour_, domainHandler_, domainMax_, domainMin_, globalMeshIndex_, interactionDataReceive_, interactionDataSend_, localIndexToGlobalIndexTable_, localIndexToProcessorList_, middle_, newBoundaryParticleList_, newInteractionList_, numberOfParticlesReceive_, numberOfParticlesSend_, numNewInteractionsReceive_, numNewInteractionsSend_, rank_, updatePositionDataReceive_, updatePositionDataSend_, updateVelocityDataReceive_, and updateVelocityDataSend_.

◆ ~Domain()

Domain::~Domain ( )
override

Destructor, destroys the domain.

Destructor

122 {
123 #ifdef DEBUG_DESTRUCTOR
124  std::cout << "Domain::~Domain() finished"<<std::endl;
125 #endif
126 }

Member Function Documentation

◆ addNewParticles()

void Domain::addNewParticles ( )

Initialises the MPIParticles by communicating newly found particles.

Adds new MPI ghost particles to the simulation. This is done in a three stage process where first the particles are located that generate ghosts, secondly their data is transmitted to the correct processor and thirdly that data is then used to create ghost particles.

1589 {
1590  //Step 1: For every MPIDomain boundary, create a list of particles that have to be transmitted
1591  //queue send and receive instructions for the number of particles
1594 
1595  //Step 2: queue send and receive of data
1598 
1599  //Step 3: Add the received particles to the particleHandler of the current domain
1601 }
void performBoundaryDataTransmission()
Collects data to be transmitted and then performs the transmission of the data.
Definition: Domain.cc:1221
void prepareBoundaryDataTransmission()
Prepares the MPI transmission of particle and interaction data from particles in particleHandler.
Definition: Domain.cc:1146
void finaliseBoundaryDataTransmission()
This function processes the transmitted data.
Definition: Domain.cc:1262
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:134
void sync()
Process all pending asynchronous communication requests before continuing.
Definition: MpiContainer.h:152

References finaliseBoundaryDataTransmission(), MPIContainer::Instance(), performBoundaryDataTransmission(), prepareBoundaryDataTransmission(), and MPIContainer::sync().

Referenced by DomainHandler::addNewParticles().

◆ addParticle()

void Domain::addParticle ( BaseParticle particle)

Initialises a single particle which is added during the simulation.

Initialises a single particle which was added by the user after the domain creation.

This function is used when a single particle is added during the simulation In that case it has to be added to the mpi domains manually using this function. Examples are insertion boundaries that occasionally add particles to the domain

Parameters
[in]particleThe single particle that has to be inserted into the domain
1611 {
1612  //Step1: check if the particle has to be sent to other processors
1615 
1616  //Step2: queue send and receive data. Note for an inserted particle, no interactions should be required
1619 
1620  //Step3: Add the received particles to the particleHandler of the current domain
1623 }

References finaliseBoundaryDataTransmission(), MPIContainer::Instance(), performBoundaryDataTransmission(), prepareBoundaryDataTransmission(), and MPIContainer::sync().

Referenced by DPMBase::insertGhostParticle().

◆ addParticlesToLists()

void Domain::addParticlesToLists ( BaseParticle particle,
std::vector< std::vector< BaseParticle * > > &  list 
)

Function that adds the particles to the approriate boundary list.

Function that adds the particles to the approriate boundary lists.

This function computes the complexity of the particle. The complexity is defined by the number of boundaries the particle is close-by. Depending on this complexity value the particle has to be added to different boundary lists.

Parameters
[in]particlepointer to base particle
[in,out]lista list of lists of particles which the particle might be added to
702 {
703  std::vector<int> boundaryIndex = findNearbyBoundaries(particle);
704 
705  //Compute and set complexity of the particle
706  unsigned int complexity = boundaryIndex[0] + 3 * boundaryIndex[1] + 9 * boundaryIndex[2] + 13;
707  unsigned int list_complexity = 0;
708  for (int d = 0; d < 3; d++) //Loop over all directions
709  {
710  list_complexity += std::abs(boundaryIndex[d]);
711  }
712  particle->setCommunicationComplexity(complexity);
713  //particle->setCommunicationComplexity(list_complexity);
714 
715  //Based on the complexity of the particle, add it to the approriate list
716  switch (list_complexity)
717  {
718  //The particle is not close at all
719  case 0:
720  break;
721  //The particle is close to one side
722  // 1 side contribution
723  case 1 :
724  //Add the side contribution
725  list[getLocalIndex(boundaryIndex)].push_back(particle);
726  break;
727  //The particle is close to two neighbouring directions
728  //2 side and 1 rib contrubution
729  case 2 :
730  {
731  //Add the two side contributions
732  for (int d = 0; d < 3; d++)
733  {
734  std::vector<int> localMeshIndex = {0, 0, 0};
735  localMeshIndex[d] = boundaryIndex[d];
736  //Avoid adding the particle in the wrong direction by excluding localMeshIndex[d] = 0
737  if (localMeshIndex[d] != 0)
738  {
739  list[getLocalIndex(localMeshIndex)].push_back(particle);
740  }
741  }
742  }
743  //Add the rib contribution
744  list[getLocalIndex(boundaryIndex)].push_back(particle);
745  break;
746 
747  //The particle is close to three neighbouring directions
748  // 3 side, 3 rib and 1 corner contribution
749  case 3 :
750  {
751  //Add the three side contributions
752  for (int d = 0; d < 3; d++)
753  {
754  std::vector<int> localMeshIndex = {0, 0, 0};
755  //Reset index vector
756  localMeshIndex[d] = boundaryIndex[d];
757  list[getLocalIndex(localMeshIndex)].push_back(particle);
758  }
759 
760  //Add the three rib contributions
761  for (int d = 0; d < 3; d++)
762  {
763  std::vector<int> localMeshIndex = boundaryIndex;
764  //All rib boundary indices are given by the boundaryIndex and setting one of the components to zero
765  localMeshIndex[d] = 0;
766  list[getLocalIndex(localMeshIndex)].push_back(particle);
767  }
768  }
769 
770  //Add the corner contribution
771  list[getLocalIndex(boundaryIndex)].push_back(particle);
772  break;
773 
774  default :
775  logger(INFO, "boundaryIndex : %,%,% | list_complexity: %", boundaryIndex[0], boundaryIndex[1], boundaryIndex[2],
776  list_complexity);
777  logger(ERROR, "Particle is in contact with the wrong number of boundaries");
778  break;
779  }
780 }
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
@ INFO
@ ERROR
void setCommunicationComplexity(unsigned complexity)
Set the communication complexity of the particle.
Definition: BaseParticle.cc:196
std::vector< int > findNearbyBoundaries(BaseParticle *particle, Mdouble offset=0)
This function finds if a given particle is close to a given boundary.
Definition: Domain.cc:554
int getLocalIndex(int i, int j, int k)
return the local index of a domain given local mesh indices i,j and k
Definition: Domain.cc:498

References ERROR, findNearbyBoundaries(), getLocalIndex(), INFO, logger, and BaseParticle::setCommunicationComplexity().

Referenced by findNewMPIParticle().

◆ cleanCommunicationList()

void Domain::cleanCommunicationList ( std::vector< BaseParticle * > &  list)

Removes nullptr's from a given particle list.

Removes nullptrs from a list of base particles efficiently by replacing the last entry to an empty nullptr space.m

Parameters
[in]listThe list that needs to be cleansed from nullptrs
1758 {
1759  for (int i = 0; i < list.size(); i++)
1760  {
1761  if (list[i] == nullptr)
1762  {
1763  list[i] = list.back();
1764  list.pop_back();
1765  i--;
1766  }
1767  }
1768 }
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51

References constants::i.

Referenced by cleanCommunicationLists().

◆ cleanCommunicationLists()

void Domain::cleanCommunicationLists ( )

Removes nullptrs from boundaryParticleList_ and boundaryParticleListNeighbour_.

After particles have been updated, the communication lists contains nullptrs, remove these from the boundaryParticleList and boundaryParticleListNeighbour

1743 {
1744  //For all active boundaries
1745  for (int i : boundaryList_)
1746  {
1749  }
1750 }
void cleanCommunicationList(std::vector< BaseParticle * > &list)
Removes nullptr's from a given particle list.
Definition: Domain.cc:1757

References boundaryList_, boundaryParticleList_, boundaryParticleListNeighbour_, cleanCommunicationList(), and constants::i.

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

◆ collectBoundaryParticleData()

void Domain::collectBoundaryParticleData ( int  localIndex)

collects the data of a particle that has to be communicated to other processors

collects the data of a particles that has to be communicated to other processors

Only the relevant data of a baseParticle is being send to other processors, therefore this function collects the relevant data and puts it in a format compatible with data transmission

Parameters
[in]localIndexthe local index of a boundary
910 {
911  //For all particles
912  for (BaseParticle* particle : newBoundaryParticleList_[localIndex])
913  {
914  //Add the data to the transmission list
915  boundaryParticleDataSend_[localIndex].push_back(copyDataFromParticleToMPIParticle(particle));
916  }
917 }
MPIParticle copyDataFromParticleToMPIParticle(BaseParticle *p)
Copies data from a NonSphericalParticle to an MPIParticle class and returns this.
Definition: MpiDataClass.cc:124
Definition: BaseParticle.h:54

References boundaryParticleDataSend_, copyDataFromParticleToMPIParticle(), and newBoundaryParticleList_.

Referenced by performBoundaryDataTransmission().

◆ collectInteractionData()

void Domain::collectInteractionData ( int  localIndex)

Collects the data of an interaction that has to be communicated to other processors.

Interactions have to be reformatted in an MPI-suitable format to transmit over to other processors

Parameters
[in]localIndexThe local index of a boundary
925 {
926  //Copy interactions to the data array
927  unsigned int indexInteraction = 0;
928  for (BaseInteraction* interaction : newInteractionList_[localIndex])
929  {
930  interaction->getMPIInteraction(interactionDataSend_[localIndex], indexInteraction);
931  indexInteraction++;
932  }
933 }
Stores information about interactions between two interactable objects; often particles but could be ...
Definition: BaseInteraction.h:60

References interactionDataSend_, and newInteractionList_.

Referenced by performBoundaryDataTransmission().

◆ constructor()

void Domain::constructor ( )

contructor of a domain

constructs the domain

the boundaries are set to infinity, no processor is assigned. all lists that require a full 3D domain element to function are created

134 {
136  domainHandler_ = nullptr;
139 
140  //A cube has 3^3=27 neighbours
141  int numberOfNeighbours = 27;
142 
143  //Create all lists
144  localIndexToGlobalIndexTable_ = std::vector<int>(numberOfNeighbours);
145  localIndexToProcessorList_ = std::vector<int>(numberOfNeighbours);
146  boundaryParticleList_ = std::vector<std::vector<BaseParticle*> >(numberOfNeighbours, std::vector<BaseParticle*>(0));
147  boundaryParticleListNeighbour_ = std::vector<std::vector<BaseParticle*> >(numberOfNeighbours,
148  std::vector<BaseParticle*>(0));
149  newBoundaryParticleList_ = std::vector<std::vector<BaseParticle*> >(numberOfNeighbours,
150  std::vector<BaseParticle*>(0));
151  newInteractionList_ = std::vector<std::vector<BaseInteraction*> >(numberOfNeighbours,
152  std::vector<BaseInteraction*>(0));
153  numberOfParticlesSend_ = std::vector<unsigned>(numberOfNeighbours);
154  numberOfParticlesReceive_ = std::vector<unsigned>(numberOfNeighbours);
155  numNewInteractionsSend_ = std::vector<unsigned>(numberOfNeighbours);
156  numNewInteractionsReceive_ = std::vector<unsigned>(numberOfNeighbours);
157  boundaryParticleDataSend_ = std::vector<std::vector<MPIParticle> >(numberOfNeighbours);
158  boundaryParticleDataReceive_ = std::vector<std::vector<MPIParticle> >(numberOfNeighbours);
159  updatePositionDataSend_ = std::vector<std::vector<MPIParticlePosition> >(numberOfNeighbours);
160  updatePositionDataReceive_ = std::vector<std::vector<MPIParticlePosition> >(numberOfNeighbours);
161  updateVelocityDataSend_ = std::vector<std::vector<MPIParticleVelocity> >(numberOfNeighbours);
162  updateVelocityDataReceive_ = std::vector<std::vector<MPIParticleVelocity> >(numberOfNeighbours);
163  interactionDataSend_ = std::vector<void*>(numberOfNeighbours);
164  interactionDataReceive_ = std::vector<void*>(numberOfNeighbours);
165  activeBoundaryList_ = std::vector<bool>(numberOfNeighbours, true);
166  boundaryList_ = std::vector<int>(0);
167 }
const Mdouble inf
Definition: GeneralDefine.h:44
const int intMax
Definition: GeneralDefine.h:45

References activeBoundaryList_, boundaryList_, boundaryParticleDataReceive_, boundaryParticleDataSend_, boundaryParticleList_, boundaryParticleListNeighbour_, domainHandler_, domainMax_, domainMin_, constants::inf, interactionDataReceive_, interactionDataSend_, constants::intMax, localIndexToGlobalIndexTable_, localIndexToProcessorList_, newBoundaryParticleList_, newInteractionList_, numberOfParticlesReceive_, numberOfParticlesSend_, numNewInteractionsReceive_, numNewInteractionsSend_, rank_, updatePositionDataReceive_, updatePositionDataSend_, updateVelocityDataReceive_, and updateVelocityDataSend_.

Referenced by Domain().

◆ containsParticle()

bool Domain::containsParticle ( BaseParticle particle,
Mdouble  offset = 0.0 
)

Check to see if a given particle is within the current domain.

Checks if a particle is in the domain.

Checks if the particle is in the domain, but with an offset. this offset is set to zero standard

Parameters
[in]particlePointer to a particle
[in]offsetoffset from the domain boundary
Returns
True if the particle is in the domain. False if it is outside
401 {
402  for (unsigned i = 0; i < 3; i++)
403  {
404  if (!(((domainMin_[i] + offset) < particle->getPosition().getComponent(i))
405  &&
406  ((domainMax_[i] - offset) >= particle->getPosition().getComponent(i)))
407  )
408  {
409  return false;
410  }
411  }
412  return true;
413 }
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
Definition: BaseInteractable.h:218
Mdouble getComponent(int index) const
Returns the requested component of this Vec3D.
Definition: Vector.cc:194

References domainMax_, domainMin_, Vec3D::getComponent(), BaseInteractable::getPosition(), and constants::i.

Referenced by PeriodicBoundaryHandler::getMPIFlags(), isInCommunicationZone(), isInGreaterDomain(), isInInnerDomain(), DPMBase::mpiInsertParticleCheck(), prepareBoundaryDataTransmission(), and updateParticles().

◆ copy()

Domain * Domain::copy ( ) const
virtual

Function that creates a copy of this current domain, using the copy constructor.

Copy method.

Uses copy constructor to create a copy on the heap. Useful for polymorphism.

Returns
pointer to the domain's copy
176 {
177  return new Domain(*this);
178 }
Domain()
Default Domain constructor.
Definition: Domain.cc:48

References Domain().

◆ createLookUpTable()

void Domain::createLookUpTable ( )

Create a look up table between local index system to global index system.

Function that creates a lookup table from the local index system to the global index system

452 {
453  int localIndex;
454  int globalIndex;
455  //Get the global decomposition vector, (nx,ny,nz) and compute the mesh multipliers: (1,nx,nx*ny)
456  std::vector<unsigned> numberOfDomains = domainHandler_->getNumberOfDomains();
457  std::vector<unsigned> globalMeshMultiplier = {1,
458  numberOfDomains[Direction::XAXIS],
459  numberOfDomains[Direction::XAXIS] *
460  numberOfDomains[Direction::YAXIS]};
461 
462  //Compute the globalIndex of this domain
464  globalMeshMultiplier[Direction::YAXIS] * globalMeshIndex_[Direction::YAXIS] +
465  globalMeshMultiplier[Direction::ZAXIS] * globalMeshIndex_[Direction::ZAXIS];
466 
467  //Create the lookup table from localIndex to globalIndex of the neihbours
468  for (int i = -1; i < 2; i++)
469  {
470  for (int j = -1; j < 2; j++)
471  {
472  for (int k = -1; k < 2; k++)
473  {
474  //Get the local index
475  localIndex = i + 3 * j + 9 * k + 13;
476  //Compute the global index
477  globalIndex = globalMeshMultiplier[Direction::XAXIS] * (globalMeshIndex_[Direction::XAXIS] + i) +
478  globalMeshMultiplier[Direction::YAXIS] * (globalMeshIndex_[Direction::YAXIS] + j) +
479  globalMeshMultiplier[Direction::ZAXIS] * (globalMeshIndex_[Direction::ZAXIS] + k);
480  //Fill in the look-up table
481  localIndexToGlobalIndexTable_[localIndex] = globalIndex;
482  }
483  }
484  }
485  //Create the lookup table from localIndex to processorRank
488 }
@ YAXIS
Definition: GeneralDefine.h:78
@ XAXIS
Definition: GeneralDefine.h:78
@ ZAXIS
Definition: GeneralDefine.h:78
std::vector< unsigned > getNumberOfDomains()
Gets the number of domains in the domain handler.
Definition: DomainHandler.cc:287
int globalIndex_
Global index of the domain in the mesh.
Definition: Domain.h:469

References domainHandler_, DomainHandler::getNumberOfDomains(), globalIndex_, globalMeshIndex_, constants::i, localIndexToGlobalIndexTable_, localIndexToProcessorList_, rank_, XAXIS, YAXIS, and ZAXIS.

◆ debugInformation()

void Domain::debugInformation ( )
1096  {
1097  std::stringstream s;
1098  std::stringstream m;
1099  for (auto p : getHandler()->getDPMBase()->particleHandler) {
1100  if (p->isMPIParticle())
1101  m << std::setw(4) << p->getId();
1102  else
1103  s << std::setw(4) << p->getId();
1104  }
1105  logger(INFO,"Particles %, MPI %",s.str(),m.str());
1106 }
DomainHandler * getHandler() const
Gets the domainHandler.
Definition: Domain.cc:1578

References getHandler(), INFO, and logger.

◆ disableBoundaries()

void Domain::disableBoundaries ( )

disables all domain boundaries that have no neighbour

This function can only disable a square mesh. If you want to make a concave mesh then this function has to be adapted, especially for the case when the numberOfDomains[d] = 1.

598 {
599  std::vector<unsigned> numberOfDomains = domainHandler_->getNumberOfDomains();
600  std::vector<int> localMeshIndex(3);
601  int localIndex;
602 
603  //disble own list
604  activeBoundaryList_[13] = false;
605 
606  //Special case when numberOfDomains[d] = 1 -> disable all d direction boundaries
607  for (unsigned d = 0; d < 3; d++) //Loop over all dimensions
608  {
609  //If there is only one domain in the d-direction, take action
610  if (numberOfDomains[d] == 1)
611  {
612  //Loop over all locaIndices
613  for (int i = -1; i < 2; i++)
614  {
615  localMeshIndex[Direction::XAXIS] = i;
616  for (int j = -1; j < 2; j++)
617  {
618  localMeshIndex[Direction::YAXIS] = j;
619  for (int k = -1; k < 2; k++)
620  {
621  localMeshIndex[Direction::ZAXIS] = k;
622  //Disable all boundaries that are not in the "middle" of the mesh in the d-direction
623  // i.e. a localMeshIndex[d] = -1 is a neighbour in the d-direction, however there is only one
624  // element in that direction so it can't be a real neighbour.
625  if (localMeshIndex[d] != 0)
626  {
627  //Disable the boundary
628  localIndex = getLocalIndex(localMeshIndex);
629  activeBoundaryList_[localIndex] = false;
630  }
631  }
632  }
633  }
634  }
635  }
636 
637  //Compute the boundaryIndex for all other cases where numberOfDomains is larger than 1
638  std::vector<int> boundaryIndex(3);
639  for (int d = 0; d < 3; d++)
640  {
641  //Check if the domain is on the simulationDomainMin boundary
642  if (globalMeshIndex_[d] == 0)
643  {
644  //Update boundary index
645  boundaryIndex[d] = -1;
646  }
647  //Check if the domain is on the simulationDomainMax boundary
648  else if (globalMeshIndex_[d] == (numberOfDomains[d] - 1))
649  {
650  //Update boundary index
651  boundaryIndex[d] = 1;
652  }
653  }
654 
655  //Disable the boundaries that are on the edge of the simulation domain
656  for (int d = 0; d < 3; d++)
657  {
658  //If boundary is on the edge of the simulation domain
659  if (boundaryIndex[d] != 0)
660  {
661  //Loop over all local indices
662  for (int i = -1; i < 2; i++)
663  {
664  for (int j = -1; j < 2; j++)
665  {
666  for (int k = -1; k < 2; k++)
667  {
668  localMeshIndex = {i, j, k};
669  //Set the localMeshIndex to the boundaryIndex in the d-direction
670  //Since we are only interested in the domains on this boundary
671  localMeshIndex[d] = boundaryIndex[d];
672  //Disable the boundary
673  localIndex = getLocalIndex(localMeshIndex);
674  activeBoundaryList_[localIndex] = false;
675  }
676  }
677  }
678  }
679  }
680 
681  //Create a list of the active boundaries
682  localIndex = 0;
683  for (bool active : activeBoundaryList_)
684  {
685  if (active)
686  {
687  boundaryList_.push_back(localIndex);
688  }
689  localIndex++;
690  }
691 }

References activeBoundaryList_, boundaryList_, domainHandler_, getLocalIndex(), DomainHandler::getNumberOfDomains(), globalMeshIndex_, constants::i, XAXIS, YAXIS, and ZAXIS.

◆ disableBoundary()

void Domain::disableBoundary ( unsigned  localIndex)

Disables a boundary of the domain with a neighbouring domain.

This function disables the communication of a boundary. Each domain in the parallel code has 27 boundaries: (6 sides, 12 ribs, 8 corners) and for convenience one is associated with the domain itself (used for local indexing). Boundaries that are inactive, such as domains that extend to infinity, do not need to be considered in the parallel computation. This function disables that boundary.

Parameters
[in]localIndexThe local index of a neighbour of the current domain
379 {
380  activeBoundaryList_[localIndex] = false;
381 }

References activeBoundaryList_.

◆ finaliseBoundaryDataTransmission()

void Domain::finaliseBoundaryDataTransmission ( )

This function processes the transmitted data.

copies the received mpi data into the particles/interacions and adds them to the particleHandler/interactionHandler All vectors that have been used in transmitting data are then cleaned up

Parameters
[in,out]particleHandlerHandles all particles in the current domain, on output contains the newly received particles
[in,out]interactionHandlerHandles all interactions in the current domain, on output contains the newly received interactions
1263  {
1264  //For all boundaries
1265  for (int localIndex : boundaryList_)
1266  {
1267  //copy the received data into the particleHandler and neighbour particle list
1268  std::vector<BaseParticle*> newParticles;
1269  processReceivedBoundaryParticleData(localIndex, newParticles);
1270  //All particles in the current domain that have been send to the other domains need to be flagged as communicating particles
1271  processSentBoundaryParticles(localIndex);
1272  //copy the received interaction data into the standard dpm structure
1273  processReceivedInteractionData(localIndex, newParticles);
1274 
1275  //Delete all send/receive data
1276  boundaryParticleDataSend_[localIndex].clear();
1277  boundaryParticleDataReceive_[localIndex].clear();
1280  interactionDataReceive_[localIndex]);
1281 
1282  //Reset all counters
1283  numberOfParticlesSend_[localIndex] = 0;
1284  numberOfParticlesReceive_[localIndex] = 0;
1285  numNewInteractionsSend_[localIndex] = 0;
1286  numNewInteractionsReceive_[localIndex] = 0;
1287 
1288  //Reset all lists
1289  newBoundaryParticleList_[localIndex].clear();
1290  newInteractionList_[localIndex].clear();
1291  }
1292  }
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:725
InteractionHandler interactionHandler
An object of the class InteractionHandler.
Definition: DPMBase.h:1467
void processReceivedBoundaryParticleData(unsigned index, std::vector< BaseParticle * > &newParticles)
Function that copies the mpi data format of a base particle to a real particle and adds it to the par...
Definition: Domain.cc:941
void processReceivedInteractionData(unsigned index, std::vector< BaseParticle * > &newParticles)
Processes the received interactions from newly added mpi particles
Definition: Domain.cc:999
void processSentBoundaryParticles(unsigned index)
Bookkeep the newly send particles.
Definition: Domain.cc:977
void deleteMPIInteractionDataArray(void *dataArray)
deletes an MPIInteractionDataArray
Definition: InteractionHandler.cc:227

References boundaryList_, boundaryParticleDataReceive_, boundaryParticleDataSend_, InteractionHandler::deleteMPIInteractionDataArray(), BaseHandler< T >::getDPMBase(), getHandler(), interactionDataReceive_, interactionDataSend_, DPMBase::interactionHandler, newBoundaryParticleList_, newInteractionList_, numberOfParticlesReceive_, numberOfParticlesSend_, numNewInteractionsReceive_, numNewInteractionsSend_, processReceivedBoundaryParticleData(), processReceivedInteractionData(), and processSentBoundaryParticles().

Referenced by addNewParticles(), and addParticle().

◆ finalisePositionAndVelocityUpdate()

void Domain::finalisePositionAndVelocityUpdate ( std::set< BaseParticle * > &  ghostParticlesToBeDeleted)

processes position and velocity data for ghost particles

After the data has been received from other processors, this function will update the ghost particles with the new position and velocity data. Afterwards the status of the particles will be updated based on their new positions. Sometimes a particle needs to be removed from the simulation, however since this particle might still be active in the periodic boundary it is not deleted straight away but stored in ghostParticlesToBeDeleted. Finally the communication data is removed.

Parameters
[in,out]ghostParticlesToBeDeletedA vector containing particles that need to be removed from the simulation
1502 {
1503 
1504  //For all active boundaries
1505  for (int localIndex : boundaryList_)
1506  {
1507  updateParticlePosition(localIndex);
1508  updateParticleVelocity(localIndex);
1509  }
1510 
1511  //Based on the new position, update the particle lists.
1512  //Remove particles that left the communication zone, they will be re-communicated in a later step
1513  updateParticles(ghostParticlesToBeDeleted);
1514 
1515  //For all active boundaries clear the data lists
1516  for (int localIndex : boundaryList_)
1517  {
1518  updatePositionDataSend_[localIndex].clear();
1519  updateVelocityDataSend_[localIndex].clear();
1520  updatePositionDataReceive_[localIndex].clear();
1521  updateVelocityDataReceive_[localIndex].clear();
1522  }
1523 
1524 }
void updateParticles(std::set< BaseParticle * > &ghostParticlesToBeDeleted)
This step updates all communication lists and particles in the communication zone.
Definition: Domain.cc:1308
void updateParticlePosition(int localIndex)
Updates the position of particles which are flagged as MPIParticles.
Definition: Domain.cc:1412
void updateParticleVelocity(int localIndex)
Updates the velocity of particles which are flagged as MPIParticles.
Definition: Domain.cc:1441

References boundaryList_, updateParticlePosition(), updateParticles(), updateParticleVelocity(), updatePositionDataReceive_, updatePositionDataSend_, updateVelocityDataReceive_, and updateVelocityDataSend_.

Referenced by updateStatus().

◆ finaliseVelocityUpdate()

void Domain::finaliseVelocityUpdate ( )

Processes particle velocity data for ghost particles.

This function is not in use

1558 {
1559  //For all active boundaries
1560  for (int localIndex : boundaryList_)
1561  {
1562  updateParticleVelocity(localIndex);
1563  }
1564 
1565  //For all active boundaries clear the data lists
1566  for (int localIndex : boundaryList_)
1567  {
1568  updateVelocityDataSend_[localIndex].clear();
1569  updateVelocityDataReceive_[localIndex].clear();
1570  }
1571 }

References boundaryList_, updateParticleVelocity(), updateVelocityDataReceive_, and updateVelocityDataSend_.

Referenced by updateVelocity().

◆ findNearbyBoundaries()

std::vector< int > Domain::findNearbyBoundaries ( BaseParticle particle,
Mdouble  offset = 0 
)

This function finds if a given particle is close to a given boundary.

This function detects in how many boundaries the particle is located and is stored in the boundaryIndex. The boundary Index in the x-direction: a) -1 if the particle is at the left boundary b) 0 if the particle is not at a boundary c) 1 if the particle is at the right boundary The same holds for the y and z direction as well

Parameters
[in]particlea base particle
[out]offsetthe L1 distance between the domain boundary and the wanted boundary
Returns
boundaryIndex a vector indicating at which boundary the particle is
555 {
556  std::vector<int> boundaryIndex(3);
557  Mdouble interactionDistance = domainHandler_->getInteractionDistance();
558 
559  //for x,y,z directions, find if the particle is close to the left or right wall or not at all
560  for (int d = 0; d < 3; d++)
561  {
562  //Check if the particle is close to Lx
563  if ((particle->getPosition().getComponent(d)) < (domainMin_[d] + interactionDistance + offset))
564  {
565  //Update switch
566  boundaryIndex[d] = -1;
567  }
568  //Check if particle is close to Rx
569  else if ((particle->getPosition().getComponent(d)) >= (domainMax_[d] - interactionDistance - offset))
570  {
571  //Update switch
572  boundaryIndex[d] = 1;
573  }
574  }
575  return boundaryIndex;
576 }
double Mdouble
Definition: GeneralDefine.h:34
Mdouble getInteractionDistance()
Gets the interaction distance of the domain handler.
Definition: DomainHandler.cc:324

References domainHandler_, domainMax_, domainMin_, Vec3D::getComponent(), DomainHandler::getInteractionDistance(), and BaseInteractable::getPosition().

Referenced by addParticlesToLists(), inBoundary(), and updateParticles().

◆ findNewMPIInteractions()

void Domain::findNewMPIInteractions ( )

Finds interactions that have to be send over to another domain.

Finds interactions that have to be sent over to another domain.

Newly added particles to the communication lists might have history interactions with the particles already there. The other domains need to be aware of these history interactions and this function collects the relevant interactions.

825  {
826  //For all active boundaries
827  for (int localIndex : boundaryList_)
828  {
829  //Check all newly added particles for interactions with already known particles
830  for (BaseParticle* newBoundaryParticle : newBoundaryParticleList_[localIndex])
831  {
832  //Loop over all interactions of the new particle
833  std::vector<BaseInteraction*> interactions = newBoundaryParticle->getInteractions();
834  for (BaseInteraction* interaction : interactions)
835  {
836  //Find out what the new particle is interacting with
837  BaseParticle* particleP = dynamic_cast<BaseParticle*>(interaction->getP());
838  BaseParticle* objectI = dynamic_cast<BaseParticle*>(interaction->getI());
839 
840  //If the P in the interaction structure is the new particle, find I
841  if (newBoundaryParticle == particleP)
842  {
843  //Check if the new particle is interacting with a wall
844  if (!objectI)
845  {
846  //Check if the interaction is still valid
847  BaseWall* wall = dynamic_cast<BaseWall*>(interaction->getI());
848  Mdouble distance;
849  Vec3D normal;
850  wall->getDistanceAndNormal(*particleP, distance, normal);
851  if (distance <= particleP->getMaxInteractionRadius())
852  {
853  //Add the interaction to the list if there are still in contact (hence the if statement)
854  newInteractionList_[localIndex].push_back(interaction);
855  }
856  }
857  else //is I a particle
858  {
859  //check if particle is in mpi domain OR (TODO) if it is in the newBoundaryParticleList_
860  if (objectI->isInMPIDomain() || isInNewBoundaryParticleList(objectI, localIndex))
861  {
862  // iff the interaction partner of the new particle is in the communication zone, transmit the interaction
863  if (inBoundary(objectI,localIndex))
864  {
865  //Is the particle still interacting after the position update?
866  Vec3D branchVector = particleP->getPosition() - objectI->getPosition();
867  //Get the square of the distance between particle i and particle j
868  Mdouble distanceSquared = Vec3D::getLengthSquared(branchVector);
869  Mdouble sumOfInteractionRadii =
870  objectI->getSumOfInteractionRadii(particleP);
871  if (distanceSquared < (sumOfInteractionRadii * sumOfInteractionRadii))
872  {
873  //Add the interaction to the list
874  newInteractionList_[localIndex].push_back(interaction);
875  }
876  }
877  }
878  }
879  }
880  else //newBoundaryParticle is I in the interaction, P can only be a particle
881  {
882  //it is "I" in the interaction structure, check if its in the mpi domain
883  if (particleP->isInMPIDomain() || isInNewBoundaryParticleList(particleP, localIndex))
884  {
885  //Is the particle still interacting after the position update?
886  Vec3D branchVector = particleP->getPosition() - objectI->getPosition();
887  //Get the square of the distance between particle i and particle j
888  Mdouble distanceSquared = Vec3D::getLengthSquared(branchVector);
889  Mdouble sumOfInteractionRadii =
890  objectI->getSumOfInteractionRadii(particleP);
891  if (distanceSquared < (sumOfInteractionRadii * sumOfInteractionRadii))
892  {
893  //Add the interaction to the list
894  newInteractionList_[localIndex].push_back(interaction);
895  }
896  }
897  }
898  }
899  }
900  }
901 }
bool isInMPIDomain()
Indicates if the particle is in the communication zone of the mpi domain.
Definition: BaseParticle.cc:276
Mdouble getSumOfInteractionRadii(const BaseParticle *particle) const
returns the sum of the radii plus the interactionDistance
Definition: BaseParticle.h:379
Basic class for walls.
Definition: BaseWall.h:49
virtual bool getDistanceAndNormal(const BaseParticle &P, Mdouble &distance, Vec3D &normal_return) const =0
Pure virtual function that computes the distance of a BaseParticle to this wall and returns the norma...
bool inBoundary(BaseParticle *particle, int localIndex)
Definition: Domain.cc:578
bool isInNewBoundaryParticleList(BaseParticle *object, int localIndex) const
Definition: Domain.cc:809
Definition: Vector.h:51
Mdouble getLengthSquared() const
Calculates the squared length of this Vec3D: .
Definition: Vector.cc:184

References boundaryList_, BaseWall::getDistanceAndNormal(), Vec3D::getLengthSquared(), BaseInteractable::getPosition(), BaseParticle::getSumOfInteractionRadii(), inBoundary(), BaseParticle::isInMPIDomain(), isInNewBoundaryParticleList(), newBoundaryParticleList_, and newInteractionList_.

Referenced by prepareBoundaryDataTransmission().

◆ findNewMPIParticle()

void Domain::findNewMPIParticle ( BaseParticle particle)

Function that check if a given particle should be added to the communication lists.

Function that checks if a given particle should be added to the communication lists and adds it accordingly.

Parameters
[in]particlepoint to a particle that is being checked if it should be added to the communication lists
801 {
802  //If the particle is an MPI particle
803  if (!particle->isInMPIDomain() && !particle->isPeriodicGhostParticle())
804  {
806  }
807 }
bool isPeriodicGhostParticle() const
Indicates if this particle is a ghost in the periodic boundary.
Definition: BaseParticle.cc:297
void addParticlesToLists(BaseParticle *particle, std::vector< std::vector< BaseParticle * > > &list)
Function that adds the particles to the approriate boundary list.
Definition: Domain.cc:701

References addParticlesToLists(), BaseParticle::isInMPIDomain(), BaseParticle::isPeriodicGhostParticle(), and newBoundaryParticleList_.

Referenced by findNewMPIParticles(), and prepareBoundaryDataTransmission().

◆ findNewMPIParticles()

void Domain::findNewMPIParticles ( const ParticleHandler particleHandler)

Function that finds new particles in the particle handler that should be added to the communication lists.

Parameters
[in]particleHandlerthe container that contains all particles
787 {
788  //For all particles inside the given domain, loop over all the particles to
789  //see if we have to add the particles to the new particle list
790  for (BaseParticle* particle : particleHandler)
791  {
792  findNewMPIParticle(particle);
793  }
794 }
void findNewMPIParticle(BaseParticle *particle)
Function that check if a given particle should be added to the communication lists.
Definition: Domain.cc:800

References findNewMPIParticle().

Referenced by prepareBoundaryDataTransmission().

◆ findParticleInList()

BaseParticle * Domain::findParticleInList ( unsigned int  identification,
std::vector< BaseParticle * >  particleList 
)

Searches for a particle with a specific id in a list of particles.

When interactions are copied over MPI from an MPI particle, the unique id of the particles they interact with need to be looked up. This functions searches for the correct particle

Todo:
MX: This is probably not the fastest method
Parameters
[in]indentificationThe unique ID of a particle
[in]particleListList of particles
Returns
Either the particle with the id identification or a nullptr when the particle has not been found
530 {
531  for (BaseParticle* particle : particleList)
532  {
533  if (particle->getId() == identification)
534  {
535  return particle;
536  }
537  }
538  return nullptr;
539 }

◆ flushParticles()

void Domain::flushParticles ( std::set< BaseParticle * > &  toBeFlushedList)

Particles that are going to be deleted from the simulation are flushed out of the communication boundaries.

Parameters
[in]toBeDeletedListA list of particles that is going to be deleted
1699 {
1700  //For all active boundaries
1701  for (int localIndex : boundaryList_)
1702  {
1703  flushParticlesFromList(boundaryParticleList_[localIndex], toBeFlushedList);
1704  flushParticlesFromList(boundaryParticleListNeighbour_[localIndex], toBeFlushedList);
1705  }
1706 }
void flushParticlesFromList(std::vector< BaseParticle * > &list, std::set< BaseParticle * > &toBeDeletedList)
Particles that are going to be deleted from the simulation are flushed out of a give communcation bou...
Definition: Domain.cc:1708

References boundaryList_, boundaryParticleList_, boundaryParticleListNeighbour_, and flushParticlesFromList().

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

◆ flushParticlesFromList()

void Domain::flushParticlesFromList ( std::vector< BaseParticle * > &  list,
std::set< BaseParticle * > &  toBeDeletedList 
)

Particles that are going to be deleted from the simulation are flushed out of a give communcation boundary.

1709 {
1710  //Firstly: turn all particles that need to be flushed into nullptrs
1711  for (auto& p : list)
1712  {
1713  if (p != nullptr)
1714  {
1715  BaseParticle* particle1 = p;
1716  for (BaseParticle* particle2 : toBeFlushedList)
1717  {
1718  //If the particle was found in the list, make a nullptr
1719  if (particle1 == particle2)
1720  {
1721  logger(VERBOSE, "Removing particle from mpi domain at: %", particle1->getPosition());
1722  p = nullptr;
1723  }
1724  }
1725  }
1726  }
1727 }
@ VERBOSE

References BaseInteractable::getPosition(), logger, and VERBOSE.

Referenced by flushParticles().

◆ getActiveBoundaryList()

std::vector< bool > Domain::getActiveBoundaryList ( )

Returns a list of boundaries that are active in mpi communication.

Returns a list of boundaries that are active in mpi communication

Returns
List of active mpi communication boundaries
388 {
389  return activeBoundaryList_;
390 }

References activeBoundaryList_.

◆ getDomainMax()

std::vector< double > Domain::getDomainMax ( )

Gets the maximum domain bounds.

Gets the domain's maximum domain bounds

Returns
Maximum bounds of the domain
320 {
321  return domainMax_;
322 }

References domainMax_.

Referenced by DomainHandler::setInteractionDistance().

◆ getDomainMin()

std::vector< double > Domain::getDomainMin ( )

Gets the minimum domain bounds.

Gets the domain's minimum domain bounds

Returns
Minimum bounds of the domain
311 {
312  return domainMin_;
313 }

References domainMin_.

Referenced by DomainHandler::setInteractionDistance().

◆ getGlobalIndex()

int Domain::getGlobalIndex ( )

Gets the global index of the domain.

Returns the global index of the domain in the whole simulation domain

Returns
Returns the global index of the domain
347 {
348  return globalIndex_;
349 }

References globalIndex_.

◆ getGlobalMeshIndex()

std::vector< unsigned > Domain::getGlobalMeshIndex ( )

Gets the global mesh index of the domain.

returns a vector with the globa mesh indices (i,j,k)

Returns
global mesh indices i,j and k
356 {
357  return globalMeshIndex_;
358 }

References globalMeshIndex_.

◆ getHandler()

DomainHandler * Domain::getHandler ( ) const

Gets the domainHandler.

Returns the pointer to the DomainHandler the domain belongs to

Returns
pointer to the handler
1579 {
1580  return domainHandler_;
1581 }

References domainHandler_.

Referenced by debugInformation(), finaliseBoundaryDataTransmission(), performBoundaryDataTransmission(), prepareBoundaryDataTransmission(), processReceivedBoundaryParticleData(), processReceivedInteractionData(), setBounds(), setRange(), and updateParticlePosition().

◆ getLocalIndex() [1/2]

int Domain::getLocalIndex ( int  i,
int  j,
int  k 
)

return the local index of a domain given local mesh indices i,j and k

Given i,j,k (where i=0,j=0,k=0 is the current domain), get the local index of a neighbouring domain

Parameters
[in]iIndex in the x-direction with i=0 corresponding to the current domain
[in]jIndex in the y-direction with j=0 corresponding to the current domain
[in]kIndex in the z-direction with k=0 corresponding to the current domain
Returns
The localIndex of the neighbour is returned.
499 {
500  return i + 3 * j + 9 * k + 13;
501 }

References constants::i.

Referenced by addParticlesToLists(), and disableBoundaries().

◆ getLocalIndex() [2/2]

int Domain::getLocalIndex ( std::vector< int >  localMeshIndex)

return the local index of a doman given the localMeshIndex vector

Given i,j,k (where i=0,j=0,k=0 is the current domain), get the local index of a neighbouring domain

Parameters
[in]localMeshIndex(i,j,k) where (0,0,0) corresponds to the current domain
Returns
The localIndex of the neighbour is returned.
510 {
511  return localMeshIndex[Direction::XAXIS] + 3 * localMeshIndex[Direction::YAXIS] +
512  9 * localMeshIndex[Direction::ZAXIS] + 13;
513 }

References XAXIS, YAXIS, and ZAXIS.

◆ getLocalIndexInverse()

std::vector< int > Domain::getLocalIndexInverse ( int  localMeshIndex)

Does the inverse action of getLocalIndex (un-bundles the localIndex into the three dimensions)

515  {
516  localIndex -= 13;
517  return {localIndex%3, (localIndex/3)%3, (localIndex/9)%3};
518 }

Referenced by inBoundary().

◆ getMiddle()

Vec3D Domain::getMiddle ( ) const

Gives the middle of the domain.

Returns the middle of this square domain, required for periodic particles

Returns
middle_ The middle position of a cubic domain
1734 {
1735  return middle_;
1736 }

References middle_.

Referenced by PeriodicBoundaryHandler::findTargetProcessor(), and ForceLawsMPI2Test::printTime().

◆ getName()

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

Returns the name of the object.

Returns the object's class name (i.e. 'DeletionBoundary').

Returns
the object's class name

Implements BaseObject.

208 {
209  return "Domain";
210 }

◆ getNumberOfMPIParticles()

unsigned int Domain::getNumberOfMPIParticles ( )

Obtains the number of particles in the particleHandler that are MPIParticles.

All the MPIParticles are located in the neighbour lists and we only need to take a sum of these lists to obtain the number of MPIParticles. This function is required to keep track of the number of real particles in the domain.

1665 {
1666  unsigned int count = 0;
1667  for (auto& index : boundaryParticleListNeighbour_)
1668  {
1669  count += index.size();
1670  }
1671  return count;
1672 }

References boundaryParticleListNeighbour_.

◆ getNumberOfTrueMPIParticles()

unsigned int Domain::getNumberOfTrueMPIParticles ( )

Obtains the number of particles in the particleHandler that are MPIParticles, but NOT periodic particles.

All the MPIParticles are located in the neighbour lists and we only need to take a sum of these lists to obtain the number of MPIParticles. This function is required to keep track of the number of real particles in the domain.

1680 {
1681  unsigned int count = 0;
1682  for (auto& index : boundaryParticleListNeighbour_)
1683  {
1684  for (auto& p : index)
1685  {
1686  if (!p->isPeriodicGhostParticle())
1687  {
1688  count++;
1689  }
1690  }
1691  }
1692  return count;
1693 }

References boundaryParticleListNeighbour_.

Referenced by ParticleHandler::getNumberOfRealObjectsLocal().

◆ getRank()

int Domain::getRank ( )

Gets the rank associated with the assigned processorID.

Gets the domain's rank, corresponding to a processorID.

Returns
rank of the domain
329 {
330  return rank_;
331 }

References rank_.

◆ inBoundary()

bool Domain::inBoundary ( BaseParticle particle,
int  localIndex 
)

checks whether the particle is in the localIndex zone.

578  {
579  std::vector<int> boundaryIndex = findNearbyBoundaries(particle);
580  std::vector<int> localIndex = getLocalIndexInverse(localIndex_);
581  // if the particle is in the boundary zone into which we want to transmit
582  for (int i = 0; i < 3; ++i)
583  {
584  if (localIndex[i]!=0 && boundaryIndex[i]!=localIndex[i]) {
585  return false;
586  }
587  }
588  return true;
589 }
std::vector< int > getLocalIndexInverse(int localMeshIndex)
Definition: Domain.cc:515

References findNearbyBoundaries(), getLocalIndexInverse(), and constants::i.

Referenced by findNewMPIInteractions().

◆ isInCommunicationZone()

bool Domain::isInCommunicationZone ( BaseParticle particle)

Check if the particle is in the communication zone of the current domain.

Check if the particle is inside the communication zone

Parameters
[in]particlePointer to a particle
Returns
True if the particle is in the communication zone, i.e. in the domain, but not in the inner domain. False if it is outside the communication zone.
442 {
443  //First check if the particle is actually in the domain
444  //Secondly check if the particle is in the inner domain
445  return containsParticle(particle) && !(isInInnerDomain(particle));
446 }
bool isInInnerDomain(BaseParticle *particle)
Check if the particle is in the current domain but not in the communication zone.
Definition: Domain.cc:430
bool containsParticle(BaseParticle *particle, Mdouble offset=0.0)
Check to see if a given particle is within the current domain.
Definition: Domain.cc:400

References containsParticle(), and isInInnerDomain().

Referenced by DPMBase::mpiIsInCommunicationZone().

◆ isInGreaterDomain()

bool Domain::isInGreaterDomain ( BaseParticle particle)

Check to see if a given particle is in the current domain or in neighbouring communication zones.

Check if the particle is inside the domain + the communication zone around it

Parameters
[in]particlePointer to a particle
Returns
True if the particle is in the domain or the whole communication zone around it. False if it is outside
421 {
423 }

References containsParticle(), domainHandler_, and DomainHandler::getInteractionDistance().

Referenced by PeriodicBoundaryHandler::getMPIFlags().

◆ isInInnerDomain()

bool Domain::isInInnerDomain ( BaseParticle particle)

Check if the particle is in the current domain but not in the communication zone.

Parameters
[in]particlePointer to a particle
Returns
Returns true if the particle is in the inner domain (i.e. not in the communication zone of the domain)
431 {
433 }

References containsParticle(), domainHandler_, and DomainHandler::getInteractionDistance().

Referenced by PeriodicBoundaryHandler::getMPIFlags(), and isInCommunicationZone().

◆ isInNewBoundaryParticleList()

bool Domain::isInNewBoundaryParticleList ( BaseParticle object,
int  localIndex 
) const
810 {
811  for (BaseParticle *q : newBoundaryParticleList_[localIndex]) {
812  if (q == objectI)
813  return true;
814  }
815  return false;
816 }

References newBoundaryParticleList_.

Referenced by findNewMPIInteractions().

◆ performBoundaryDataTransmission()

void Domain::performBoundaryDataTransmission ( )

Collects data to be transmitted and then performs the transmission of the data.

The particles and interactions are copied into a data class that can be transmitted to other processors. The data is then accordingly send to the appropriate processors

Parameters
[in]interactionHandlerHandler that contains all interactions, required to collect interaction data
1222  {
1223  //For all active boundaries
1224  for (int localIndex : boundaryList_)
1225  {
1226  //make sure enough memory is reserved to receive the data
1227  boundaryParticleDataReceive_[localIndex].resize(numberOfParticlesReceive_[localIndex]);
1228 
1229  //Collect the particle data
1230  collectBoundaryParticleData(localIndex);
1231 
1232  //Send the data
1234  boundaryParticleDataReceive_[localIndex].data(), numberOfParticlesReceive_[localIndex],
1235  boundaryParticleDataSend_[localIndex].data(), numberOfParticlesSend_[localIndex],
1236  localIndex);
1237 
1238 
1239  //create arrays for sending and receiving interaction data
1241  numNewInteractionsSend_[localIndex]);
1243  numNewInteractionsReceive_[localIndex]);
1244 
1245  //Collect the interaction data
1246  collectInteractionData(localIndex);
1247 
1248  //Send the data
1250  interactionDataReceive_[localIndex], numNewInteractionsReceive_[localIndex],
1251  interactionDataSend_[localIndex], numNewInteractionsSend_[localIndex], localIndex);
1252  }
1253  }
@ INTERACTION_DATA
Definition: MpiContainer.h:84
@ PARTICLE_DATA
Definition: MpiContainer.h:79
@ INTERACTION
Definition: MpiContainer.h:67
@ PARTICLE
Definition: MpiContainer.h:67
void sendAndReceiveMPIData(MercuryMPITag tag, MercuryMPIType type, T *receiveData, unsigned receiveCount, T *sendData, unsigned sendCount, unsigned localIndexNeighbour)
Function that sends transmissionData/positionData/velocityData to other processors.
Definition: Domain.h:369
void collectBoundaryParticleData(int localIndex)
collects the data of a particle that has to be communicated to other processors
Definition: Domain.cc:909
void collectInteractionData(int localIndex)
Collects the data of an interaction that has to be communicated to other processors.
Definition: Domain.cc:924
void * createMPIInteractionDataArray(unsigned int numberOfInteractions) const
creates an empty MPIInteractionDataArray
Definition: InteractionHandler.cc:211

References boundaryList_, boundaryParticleDataReceive_, boundaryParticleDataSend_, collectBoundaryParticleData(), collectInteractionData(), InteractionHandler::createMPIInteractionDataArray(), BaseHandler< T >::getDPMBase(), getHandler(), INTERACTION, INTERACTION_DATA, interactionDataReceive_, interactionDataSend_, DPMBase::interactionHandler, numberOfParticlesReceive_, numberOfParticlesSend_, numNewInteractionsReceive_, numNewInteractionsSend_, PARTICLE, PARTICLE_DATA, and sendAndReceiveMPIData().

Referenced by addNewParticles(), and addParticle().

◆ prepareBoundaryDataTransmission() [1/2]

void Domain::prepareBoundaryDataTransmission ( )

Prepares the MPI transmission of particle and interaction data from particles in particleHandler.

This function checks all the particles in the particle handler to see if they have moved in the communication domain. If that is the case they are added to a list of particles that need to be send. After all particles are evaluated the number of new particles to be send is send to the appropriate processors The same is being done to the interactions of the newly found particles

Parameters
[in]particleHandlerhandles all the particles in the current domain
1147  {
1148  //Find new particles that have entered the communication zone
1149  findNewMPIParticles(getHandler()->getDPMBase()->particleHandler);
1150 
1151  //Find interactions between new particles and other particles in the communication zone
1153 
1154  //Compute number of particles to send
1155  //For all boundaries
1156  for (int localIndex : boundaryList_)
1157  {
1158  numberOfParticlesSend_[localIndex] = newBoundaryParticleList_[localIndex].size();
1159  numNewInteractionsSend_[localIndex] = newInteractionList_[localIndex].size();
1160  }
1161 
1162  //For all active boundaries
1163  for (int localIndex : boundaryList_)
1164  {
1165  //Send and receive the number of new boundary particles
1167  (numberOfParticlesSend_[localIndex]), localIndex);
1168 
1169  //Send and receive the new interactions
1171  (numNewInteractionsSend_[localIndex]), localIndex);
1172  }
1173  }
@ INTERACTION_COUNT
Definition: MpiContainer.h:83
@ PARTICLE_COUNT
Definition: MpiContainer.h:78
void sendAndReceiveCount(MercuryMPITag tag, unsigned &countReceive, unsigned &countSend, unsigned localIndexNeighbour)
A symmetric communication between two domains exchanging a send/recieve count.
Definition: Domain.cc:1119
void findNewMPIInteractions()
Finds interactions that have to be send over to another domain.
Definition: Domain.cc:824
void findNewMPIParticles(const ParticleHandler &particleHandler)
Function that finds new particles in the particle handler that should be added to the communication l...
Definition: Domain.cc:786

References boundaryList_, findNewMPIInteractions(), findNewMPIParticles(), getHandler(), INTERACTION_COUNT, newBoundaryParticleList_, newInteractionList_, numberOfParticlesReceive_, numberOfParticlesSend_, numNewInteractionsReceive_, numNewInteractionsSend_, PARTICLE_COUNT, and sendAndReceiveCount().

Referenced by addNewParticles(), and addParticle().

◆ prepareBoundaryDataTransmission() [2/2]

void Domain::prepareBoundaryDataTransmission ( BaseParticle particle)

Prepares the MPI transmission of a single particle and its interactions.

When a single particle has to be added to the communication zone (i.e. when the user adds a particle during the simulation) then all processors should be informed if they receive the particle or not. The functionality of this function is practically the same as that of prepareBoundaryDataTransmission(ParticleHandler &particleHandler) The same is being done to the interactions of the newly found particles

Parameters
[in]particleA base particle that needs to be transmitted
1184  {
1185  //Assign the particle to the correct lists if the particle belongs to this domain
1186  if (containsParticle(particle))
1187  {
1188  findNewMPIParticle(particle);
1189  }
1190 
1191  //Note: When inserting a single particle, it has no interactions, so no interactions to be copied either
1192 
1193  //Compute number of particles to send
1194  //For all boundaries
1195  for (int localIndex : boundaryList_)
1196  {
1197  numberOfParticlesSend_[localIndex] = newBoundaryParticleList_[localIndex].size();
1198  numNewInteractionsSend_[localIndex] = newInteractionList_[localIndex].size();
1199  }
1200 
1201 
1202  //For all active boundaries
1203  for (int localIndex : boundaryList_)
1204  {
1205  //Send and recieve the number of new boundary particles
1207  (numberOfParticlesSend_[localIndex]), localIndex);
1208 
1209  //Send and receive the new interactions
1211  (numNewInteractionsSend_[localIndex]), localIndex);
1212  }
1213  }

References boundaryList_, containsParticle(), findNewMPIParticle(), INTERACTION_COUNT, newBoundaryParticleList_, newInteractionList_, numberOfParticlesReceive_, numberOfParticlesSend_, numNewInteractionsReceive_, numNewInteractionsSend_, PARTICLE_COUNT, and sendAndReceiveCount().

◆ preparePositionAndVelocityUpdate()

void Domain::preparePositionAndVelocityUpdate ( )

Function that sends particle position and velocity data for ghost particles to other processors.

When the real particle moves on it's actual domain, it's ghost particles have to get an update this function sends the data to the processors that require the update

1461 {
1462  //For all active boundaries
1463  for (int localIndex : boundaryList_)
1464  {
1465  numberOfParticlesSend_[localIndex] = boundaryParticleList_[localIndex].size();
1466  numberOfParticlesReceive_[localIndex] = boundaryParticleListNeighbour_[localIndex].size();
1467 
1468  //Increase capacity for the receiving data files
1469  updatePositionDataReceive_[localIndex].resize(numberOfParticlesReceive_[localIndex]);
1470  updateVelocityDataReceive_[localIndex].resize(numberOfParticlesReceive_[localIndex]);
1471 
1472 
1473  //Collect data
1474  for (BaseParticle* particle : boundaryParticleList_[localIndex])
1475  {
1476  updatePositionDataSend_[localIndex].push_back(copyPositionFrom(particle));
1477  updateVelocityDataSend_[localIndex].push_back(copyVelocityFrom(particle));
1478  }
1479 
1480  //Send and receive the data
1482  updatePositionDataReceive_[localIndex].data(), numberOfParticlesReceive_[localIndex],
1483  updatePositionDataSend_[localIndex].data(), numberOfParticlesSend_[localIndex],
1484  localIndex);
1486  updateVelocityDataReceive_[localIndex].data(), numberOfParticlesReceive_[localIndex],
1487  updateVelocityDataSend_[localIndex].data(), numberOfParticlesSend_[localIndex],
1488  localIndex);
1489  }
1490 }
@ VELOCITY_DATA
Definition: MpiContainer.h:82
@ POSITION_DATA
Definition: MpiContainer.h:80
@ VELOCITY
Definition: MpiContainer.h:67
@ POSITION
Definition: MpiContainer.h:67
MPIParticlePosition copyPositionFrom(BaseParticle *particle)
Copies the position from a particle to an MPIParticlePosition class.
Definition: MpiDataClass.cc:174
MPIParticleVelocity copyVelocityFrom(BaseParticle *particle)
Copies the velocity from a particle to an MPIParticleVelocity class.
Definition: MpiDataClass.cc:190

References boundaryList_, boundaryParticleList_, boundaryParticleListNeighbour_, copyPositionFrom(), copyVelocityFrom(), numberOfParticlesReceive_, numberOfParticlesSend_, POSITION, POSITION_DATA, sendAndReceiveMPIData(), updatePositionDataReceive_, updatePositionDataSend_, updateVelocityDataReceive_, updateVelocityDataSend_, VELOCITY, and VELOCITY_DATA.

Referenced by updateStatus().

◆ prepareVelocityUpdate()

void Domain::prepareVelocityUpdate ( )

Function that sends particle velocity data for ghost particles.

This function is not in use

1530 {
1531  //For all active boundaries
1532  for (int localIndex : boundaryList_)
1533  {
1534  numberOfParticlesSend_[localIndex] = boundaryParticleList_[localIndex].size();
1535  numberOfParticlesReceive_[localIndex] = boundaryParticleListNeighbour_[localIndex].size();
1536 
1537  //Resize the vector to the correct size
1538  updateVelocityDataReceive_[localIndex].resize(numberOfParticlesReceive_[localIndex]);
1539 
1540  //Collect data
1541  for (BaseParticle* particle : boundaryParticleList_[localIndex])
1542  {
1543  updateVelocityDataSend_[localIndex].push_back(copyVelocityFrom(particle));
1544  }
1545 
1546  //Send the data
1548  updateVelocityDataReceive_[localIndex].data(), numberOfParticlesReceive_[localIndex],
1549  updateVelocityDataSend_[localIndex].data(), numberOfParticlesSend_[localIndex],
1550  localIndex);
1551  }
1552 }

References boundaryList_, boundaryParticleList_, boundaryParticleListNeighbour_, copyVelocityFrom(), numberOfParticlesReceive_, numberOfParticlesSend_, sendAndReceiveMPIData(), updateVelocityDataReceive_, updateVelocityDataSend_, VELOCITY, and VELOCITY_DATA.

Referenced by updateVelocity().

◆ processReceivedBoundaryParticleData()

void Domain::processReceivedBoundaryParticleData ( unsigned  index,
std::vector< BaseParticle * > &  newParticles 
)

Function that copies the mpi data format of a base particle to a real particle and adds it to the particleHandler.

When adding a particle with this function it's always a ghost particle and therefor gets the MPIParticle flag

Parameters
[in]indexThe boundary index of the boundary list currently being treated
[in,out]particleHandlerContainer containing the particles of the current domain, will contain the new MPI particles as well
942 {
943 
944  ParticleHandler& particleHandler = getHandler()->getDPMBase()->particleHandler;
945  //for all MPIPparticles that have been received on the other side
946  for (int i = 0; i < numberOfParticlesReceive_[index]; i++)
947  {
948  //copy data from data
950  copyDataFromMPIParticleToParticle(&(boundaryParticleDataReceive_[index][i]), p0, &particleHandler);
951 
952  //Flag that the particle is a ghost particle of a real particle in the neighbour domain
953  p0->setMPIParticle(true);
954  //Flag that the particle is list as a particle in the mpi domain
955  p0->setInMPIDomain(true);
956  //add particle to handler
957  particleHandler.addGhostObject(p0);
958  //Set previous position as current position
959  BaseParticle* pGhost = particleHandler.getLastObject();
960  pGhost->setPreviousPosition(particleHandler.getLastObject()->getPosition());
961  //Add to the newParticle list
962  newParticles.push_back(pGhost);
963  logger(VERBOSE, "Adding mpi particle % at: %", particleHandler.getLastObject()->getId(),
964  particleHandler.getLastObject()->getPosition());
965 
966  //add pointer to the particle to the list and set the status to idle
967  boundaryParticleListNeighbour_[index].push_back(particleHandler.getLastObject());
968  }
969 }
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:105
T * getLastObject()
Gets a pointer to the last Object in this BaseHandler.
Definition: BaseHandler.h:634
unsigned int getId() const
Returns the unique identifier of any particular object.
Definition: BaseObject.h:125
void setPreviousPosition(const Vec3D &pos)
Sets the particle's position in the previous time step.
Definition: BaseParticle.cc:614
void setInMPIDomain(bool flag)
Flags the status of the particle if wether it is in the communication zone or not.
Definition: BaseParticle.cc:281
void setMPIParticle(bool flag)
Flags the mpi particle status.
Definition: BaseParticle.cc:191
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created.
Definition: DPMBase.h:1437
static BaseParticle * newParticle()
Definition: MpiDataClass.cc:157
Container to store all BaseParticle.
Definition: ParticleHandler.h:48
void addGhostObject(int fromProcessor, int toProcessor, BaseParticle *p)
Adds a ghost particle located at fromProcessor to toProcessor.
Definition: ParticleHandler.cc:287

References ParticleHandler::addGhostObject(), boundaryParticleDataReceive_, boundaryParticleListNeighbour_, copyDataFromMPIParticleToParticle(), BaseHandler< T >::getDPMBase(), getHandler(), BaseObject::getId(), BaseHandler< T >::getLastObject(), BaseInteractable::getPosition(), constants::i, logger, MPISphericalParticle::newParticle(), numberOfParticlesReceive_, DPMBase::particleHandler, BaseParticle::setInMPIDomain(), BaseParticle::setMPIParticle(), BaseParticle::setPreviousPosition(), and VERBOSE.

Referenced by finaliseBoundaryDataTransmission().

◆ processReceivedInteractionData()

void Domain::processReceivedInteractionData ( unsigned  index,
std::vector< BaseParticle * > &  newParticles 
)

Processes the received interactions from newly added mpi particles

Processes the received interactions from newly added mpi particles.

The received interaction data is scanned for interaction id's P and I they are then matches to the actual particle or wall and the interaction is created. The history details of the interaction are filled in after creation.

Bug:
There is a subtle and very rare bug in here, where two particles with an interaction across a periodic boundary pass into the next domain at the same time step. In this case, the interactions should be copied over before the ghost-particles are constructed. However, since the interaction is with the ghost particle, this cannot be done. That is why there is a 'continue' if one of the particles of the interaction is not found. An illustration of this situation is given in PeriodicBoundaryEnteringMpiDomainMPI2Test.
Parameters
[in]localIndexThe boundary index of the boundary list currently being treated
[in,out]interactionHandlerHandler containing all interactions on the current domain
1000 {
1002  for (unsigned int l = 0; l < numNewInteractionsReceive_[localIndex]; l++)
1003  {
1004  unsigned int identificationP;
1005  unsigned int identificationI;
1006  bool isWallInteraction;
1007  unsigned timeStamp;
1008 
1009  //Get the general information required to setup a new interaction
1011  l, identificationP, identificationI,
1012  isWallInteraction, timeStamp);
1013 
1014  logger(VERBOSE, "interaction details: %, %, idP %, idI %, wall %, time %", interactionDataReceive_[localIndex],
1015  l, identificationP, identificationI,
1016  isWallInteraction, timeStamp);
1017 
1018  //Find the particle in the newParticle list
1019  BaseParticle* pGhost = nullptr;
1020  int idOther;
1021  for (BaseParticle* particle : newParticles)
1022  {
1023  if (particle->getId() == identificationP)
1024  {
1025  pGhost = particle;
1026  idOther = identificationI;
1027  break;
1028  }
1029 
1030  if (particle->getId() == identificationI)
1031  {
1032  pGhost = particle;
1033  idOther = identificationP;
1034  break;
1035  }
1036  }
1037  if (pGhost == nullptr)
1038  {
1039  logger(WARN, "In Domain::processReceivedInteractionData: pGhost (id %) is nullptr, the interaction data is not copied. Two particles possibly moved into domain simultaneously.", identificationP);
1040  continue;
1041  }
1042 
1043  //If it is a wall interaction, do stuff
1044  if (isWallInteraction)
1045  {
1046  BaseInteractable* I = getHandler()->getDPMBase()->wallHandler.getObjectById(identificationI);
1047  //Create interactions
1048  BaseInteraction* j = I->getInteractionWith(pGhost, timeStamp, &iH);
1049  if (j!= nullptr) j->setMPIInteraction(interactionDataReceive_[localIndex], l, false);
1050 
1051  }
1052  else
1053  {
1054  //Obtain potential interaction particles
1055  std::vector<BaseParticle*> interactingParticleList;
1056  getHandler()->getDPMBase()->hGridGetInteractingParticleList(pGhost, interactingParticleList);
1057 
1058  //Find the other interacting particle
1059  BaseParticle* otherParticle = nullptr;
1060  for (BaseParticle* p2 : interactingParticleList)
1061  {
1062  if (p2->getId() == idOther)
1063  {
1064  otherParticle = p2;
1065  break;
1066  }
1067  }
1068  if (otherParticle == nullptr) {
1069  //search for the other particle in the newParticles list
1070  for (BaseParticle *particle : newParticles) {
1071  if (particle->getId() == idOther) {
1072  otherParticle = particle;
1073  break;
1074  }
1075  }
1076  if (otherParticle == nullptr) {
1077  logger(WARN,
1078  "In Domain::processReceivedInteractionData: otherParticle (id %) is nullptr, the interaction data with pGhost (id %) is not copied. Two particles possibly moved into domain simultaneously. nt = %",
1079  identificationI, identificationP, getHandler()->getDPMBase()->getNumberOfTimeSteps());
1080  continue;
1081  }
1082  }
1083  //Add the interaction
1084  // flipped order of other and ghost, so it is in the same order as received
1085  BaseInteraction* j;
1086  if (otherParticle->getId() < pGhost->getId()) {
1087  j = pGhost->getInteractionWith(otherParticle, timeStamp, &iH);
1088  } else {
1089  j = otherParticle->getInteractionWith(pGhost, timeStamp, &iH);
1090  }
1091  if (j != nullptr) j->setMPIInteraction(interactionDataReceive_[localIndex], l, false);
1092  }
1093  }
1094 }
@ WARN
T * getObjectById(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:565
Defines the basic properties that a interactable object can have.
Definition: BaseInteractable.h:55
virtual BaseInteraction * getInteractionWith(BaseParticle *P, unsigned timeStamp, InteractionHandler *interactionHandler)=0
Returns the interaction between this object and a given BaseParticle.
virtual void setMPIInteraction(void *interactionDataArray, unsigned int index, bool resetPointers)
Definition: BaseInteraction.cc:907
BaseInteraction * getInteractionWith(BaseParticle *P, unsigned timeStamp, InteractionHandler *interactionHandler) override
Checks if particle is in interaction with given particle P, and if so, returns vector of pointer to t...
Definition: BaseParticle.cc:690
virtual void hGridGetInteractingParticleList(BaseParticle *obj, std::vector< BaseParticle * > &list)
Creates a list of neighbour particles obtained from the hgrid.
Definition: DPMBase.h:1000
WallHandler wallHandler
An object of the class WallHandler. Contains pointers to all the walls created.
Definition: DPMBase.h:1447
Container to store Interaction objects.
Definition: InteractionHandler.h:45
void getInteractionDetails(void *interactionData, unsigned int index, unsigned int &identificationP, unsigned int &identificationI, bool &isWallInteraction, unsigned &timeStamp)
reads the basic interaction details from an MPIInteractionDataArray
Definition: InteractionHandler.cc:245

References BaseHandler< T >::getDPMBase(), getHandler(), BaseObject::getId(), InteractionHandler::getInteractionDetails(), BaseParticle::getInteractionWith(), BaseInteractable::getInteractionWith(), BaseHandler< T >::getObjectById(), DPMBase::hGridGetInteractingParticleList(), interactionDataReceive_, DPMBase::interactionHandler, logger, numNewInteractionsReceive_, BaseInteraction::setMPIInteraction(), VERBOSE, DPMBase::wallHandler, and WARN.

Referenced by finaliseBoundaryDataTransmission().

◆ processSentBoundaryParticles()

void Domain::processSentBoundaryParticles ( unsigned  index)

Bookkeep the newly send particles.

Each domain keeps a list of particles that have copies on other domains. The order of these lists is exactly the same order of the neighbour particle lists of the neighbour domain.

Parameters
[in]indexThe boundary index of the boundary list currently being treated
978 {
979  for (BaseParticle* particle : newBoundaryParticleList_[index])
980  {
981  boundaryParticleList_[index].push_back(particle);
982  particle->setInMPIDomain(true);
983  }
984 }

References boundaryParticleList_, and newBoundaryParticleList_.

Referenced by finaliseBoundaryDataTransmission().

◆ read()

void Domain::read ( std::istream &  is)
overridevirtual

This function does nothing.

Reads the object from a given istream.

Reads the object's id_ from the given istream

Parameters
[in,out]isistream the id_ is read from
Todo:
MX: why would this function be called?

Implements BaseObject.

187 {
188  logger(WARN, "[Domain::read] should not be called");
189  //BaseObject::read(is);
190 }

References logger, and WARN.

◆ sendAndReceiveCount()

void Domain::sendAndReceiveCount ( MercuryMPITag  tag,
unsigned &  countReceive,
unsigned &  countSend,
unsigned  localIndexNeighbour 
)

A symmetric communication between two domains exchanging a send/recieve count.

Before real data (i.e. particle data) can be transmitted to other processors, these receiving processors need to know how many data objects they are receiving. This function facilitates a symmetric send mechanism between two domains to communicate how much objects they get from eachother

Parameters
[in]tagA MercuryMPITag that indicates what type of count is being send
[out]countReceiveunsigned integer containing the receiving count
[in]countSendunsigned integer containing the sending count
[in]localIndexNeighbourthe local index of the domain with which the communication is being done
1121  {
1122  int globalIndexNeighbour = localIndexToGlobalIndexTable_[localIndexNeighbour];
1123  int processor = localIndexToProcessorList_[localIndexNeighbour];
1124 
1125  //Create communication tags
1126  int tagReceive = globalIndexNeighbour * MAX_PROC + globalIndex_ * 10 + tag;
1127  int tagSend = globalIndex_ * MAX_PROC + globalIndexNeighbour * 10 + tag;
1128 
1129  logger.assert_debug(tagSend > 0, "Send tag is wrong. Tag: %", tagSend);
1130  logger.assert_debug(tagReceive > 0, "Receive tag is wrong. Tag: %", tagReceive);
1131  logger.assert_debug(processor >= 0, "Processor is wrong. processor: %", processor);
1132 
1133  //Communicate the requests
1134  MPIContainer::Instance().receive(countReceive, processor, tagReceive);
1135  MPIContainer::Instance().send(countSend, processor, tagSend);
1136  }
#define MAX_PROC
Definition: GeneralDefine.h:51
std::enable_if< std::is_scalar< T >::value, void >::type receive(T &t, int from, int tag)
asynchronously receive a scalar from some other processor.
Definition: MpiContainer.h:221
std::enable_if< std::is_scalar< T >::value, void >::type send(T &t, int to, int tag)
Asynchronously send a scalar to some other processor.
Definition: MpiContainer.h:171

References globalIndex_, MPIContainer::Instance(), localIndexToGlobalIndexTable_, localIndexToProcessorList_, logger, MAX_PROC, MPIContainer::receive(), and MPIContainer::send().

Referenced by prepareBoundaryDataTransmission().

◆ sendAndReceiveMPIData()

template<typename T >
void Domain::sendAndReceiveMPIData ( MercuryMPITag  tag,
MercuryMPIType  type,
T *  receiveData,
unsigned  receiveCount,
T *  sendData,
unsigned  sendCount,
unsigned  localIndexNeighbour 
)
inline

Function that sends transmissionData/positionData/velocityData to other processors.

This function is heavily templated on the type of data that can be send. All the types that are located in the MercuryMPIType enum class can be used to transmit data. Examples are MPIParticle and MPIParticlePosition data types

Parameters
[in]tagA MercuryMPITag that indicates what type of data is being send
[in]typeA MercuryMPIType that tells the MPI what MPI_Data structure to use
[out]receiveDataThe data that will be received by the current domain
[in]receiveCountThe number of items that are being received by the current domain
[in]sendDataThe data that will be send by the current domain
[in]sendCountThe number of items that are being send by the current domain
[in]localIndexNeighbourthe local index to the neighbouring domain
372  {
373  int globalIndexNeighbour = localIndexToGlobalIndexTable_[localIndexNeighbour];
374  int processor = localIndexToProcessorList_[localIndexNeighbour];
375  int tagReceive = globalIndexNeighbour * MAX_PROC + globalIndex_ * 10 + tag;
376  int tagSend = globalIndex_ * MAX_PROC + globalIndexNeighbour * 10 + tag;
377 
378  //Communicate the requests
379  if (receiveCount != 0)
380  {
381  MPIContainer::Instance().receive(receiveData, type, receiveCount, processor, tagReceive);
382  }
383  if (sendCount != 0)
384  {
385  MPIContainer::Instance().send(sendData, type, sendCount, processor, tagSend);
386  }
387  }

References globalIndex_, MPIContainer::Instance(), localIndexToGlobalIndexTable_, localIndexToProcessorList_, MAX_PROC, MPIContainer::receive(), and MPIContainer::send().

Referenced by performBoundaryDataTransmission(), preparePositionAndVelocityUpdate(), and prepareVelocityUpdate().

◆ setBounds()

void Domain::setBounds ( std::vector< double domainMin,
std::vector< double domainMax,
bool  computeMiddle 
)

Sets the domain bounds.

This function sets the bound for the domain, it also computes the middle of the square domain, useful for mixed periodic/mpi particles.

Parameters
[in]domainMinMinimum values of the domain in x-,y-,z-direction
[in]domainMaxMaximum values of the domain in x-,y-,z-direction
269 {
270  domainMin_ = domainMin;
271  domainMax_ = domainMax;
272 
273  //Compute the middle of the closed domain
274  if (computeMiddle)
275  {
276  double minClosed;
277  double maxClosed;
278  for (int i = 0; i < 3; i++)
279  {
280  minClosed = domainMin_[i];
281  maxClosed = domainMax_[i];
282  if (domainMin_[i] == -constants::inf)
283  {
284  minClosed = getHandler()->getDPMBase()->getMin().getComponent(i);
285  }
286 
287  if (domainMax_[i] == constants::inf)
288  {
289  maxClosed = getHandler()->getDPMBase()->getMax().getComponent(i);
290  }
291 
292  middle_.setComponent(i, minClosed + (maxClosed - minClosed) / 2.0);
293  }
294  }
295 }
Vec3D getMax() const
Definition: DPMBase.h:670
Vec3D getMin() const
Definition: DPMBase.h:664
void setComponent(int index, double val)
Sets the requested component of this Vec3D to the requested value.
Definition: Vector.cc:217

References domainMax_, domainMin_, Vec3D::getComponent(), BaseHandler< T >::getDPMBase(), getHandler(), DPMBase::getMax(), DPMBase::getMin(), constants::i, constants::inf, middle_, and Vec3D::setComponent().

Referenced by DomainHandler::createDomains(), and DomainHandler::initialise().

◆ setGlobalMeshIndex()

void Domain::setGlobalMeshIndex ( std::vector< unsigned >  globalMeshIndex)

Sets the global mesh index of theh domain.

sets the global mesh index

global mesh index has the shape of (i,j,k)

Parameters
[in]globalMeshIndexthe mesh index vector i,j,k
366 {
367  globalMeshIndex_ = globalMeshIndex;
368 }

References globalMeshIndex_.

◆ setHandler()

void Domain::setHandler ( DomainHandler domainHandler)

Sets the domainHandler.

Sets the pointer to the DomainHandler the domain belongs to

Parameters
[in]domainHandlerpointer to the DomainHandler
338 {
339  domainHandler_ = domainHandler;
340 }

References domainHandler_.

Referenced by DomainHandler::createDomains(), and DomainHandler::initialise().

◆ setRange()

void Domain::setRange ( Direction  direction,
Mdouble  min,
Mdouble  max 
)

Sets the domain range in a given direction.

Sets the domain's range in a given direction.

Parameters
[in]directionDirection 0,1,2 corresponds to direction x,y,z respectively
[in]minMinimum domain bound
[in]maxMaximum domain bound
220 {
221  if (min > max)
222  {
223  logger(ERROR, "[MercuryMPI ERROR]: min is larger than max. (%,%)", min, max);
224  }
225 
226  double maxClosed;
227  double minClosed;
228  if (min == -constants::inf)
229  {
230  minClosed = getHandler()->getDPMBase()->getMin().getComponent(direction);
231  }
232 
233  if (max == constants::inf)
234  {
235  maxClosed = getHandler()->getDPMBase()->getMax().getComponent(direction);
236  }
237 
238 
239  switch (direction)
240  {
241  case Direction::XAXIS :
242  domainMin_[0] = min;
243  domainMax_[0] = max;
244  middle_.X = minClosed + (maxClosed - minClosed) / 2.0;
245  break;
246  case Direction::YAXIS :
247  domainMin_[1] = min;
248  domainMax_[1] = max;
249  middle_.Y = minClosed + (maxClosed - minClosed) / 2.0;
250  break;
251  case Direction::ZAXIS :
252  domainMin_[2] = min;
253  domainMax_[2] = max;
254  middle_.Z = minClosed + (maxClosed - minClosed) / 2.0;
255  break;
256  default :
257  logger(ERROR, "Direction is not a valid direction. (%)", direction);
258  break;
259  }
260 }
Mdouble Y
Definition: Vector.h:66
Mdouble Z
Definition: Vector.h:66
Mdouble X
the vector components
Definition: Vector.h:66

References domainMax_, domainMin_, ERROR, Vec3D::getComponent(), BaseHandler< T >::getDPMBase(), getHandler(), DPMBase::getMax(), DPMBase::getMin(), constants::inf, logger, middle_, Vec3D::X, XAXIS, Vec3D::Y, YAXIS, Vec3D::Z, and ZAXIS.

◆ setRank()

void Domain::setRank ( int  rank)

Sets the rank associated with the assigned processorID.

Sets the domain's rank, corresponding to a processorID.

Parameters
[in]rankInteger corresponding to a processorID
302 {
303  rank_ = rank;
304 }

References rank_.

◆ updateParticlePosition()

void Domain::updateParticlePosition ( int  localIndex)

Updates the position of particles which are flagged as MPIParticles.

Manually updates the position of the particles, the displacement and the orientation It additionally updates the position of the particle in the hGrid

Parameters
[in]localIndexan index to the boundary being updated
1413  {
1414  //process the updated information
1415  unsigned int index = 0;
1416  for (BaseParticle* particle : boundaryParticleListNeighbour_[localIndex])
1417  {
1418  logger.assert_debug(particle->getId() == updatePositionDataReceive_[localIndex][index].id,
1419  "MPI particle lists are not in sync");
1420 
1421  //set position
1422  particle->setPreviousPosition(particle->getPosition());
1423  particle->setPosition(updatePositionDataReceive_[localIndex][index].position);
1424  particle->setOrientation(updatePositionDataReceive_[localIndex][index].orientation);
1425  if (std::is_base_of<MPILiquidFilmParticle,MPIParticle>())
1426  static_cast<LiquidFilmParticle*>(particle)->setLiquidVolume(updatePositionDataReceive_[localIndex][index].liquidVolume);
1427 
1428  //Update hGrid
1429  Vec3D displacement = particle->getPreviousPosition() - particle->getPosition();
1430  getHandler()->getDPMBase()->hGridUpdateMove(particle, displacement.getLengthSquared());
1431 
1432  index++;
1433  }
1434 }
virtual void hGridUpdateMove(BaseParticle *, Mdouble)
Definition: DPMBase.cc:1933
Definition: LiquidFilmParticle.h:36
static Mdouble getLengthSquared(const Vec3D &a)
Calculates the squared length of a Vec3D: .
Definition: Vector.h:332

References boundaryParticleListNeighbour_, BaseHandler< T >::getDPMBase(), getHandler(), Vec3D::getLengthSquared(), DPMBase::hGridUpdateMove(), logger, and updatePositionDataReceive_.

Referenced by finalisePositionAndVelocityUpdate().

◆ updateParticles()

void Domain::updateParticles ( std::set< BaseParticle * > &  ghostParticlesToBeDeleted)

This step updates all communication lists and particles in the communication zone.

After all the mpi particles have received a position and velocity update, a check is required to see if the particle needs to be treated differently. Comments inside the code show all possible options. Note that when a particle needs to be deleted, it will not be deleted straight away, but added to a list to be deleted later. Additionally the location in the communication lists will not be emptied by assigning a nullptr to it. When all particles are considered this nullptrs are removed from the list, to ensure that the mirror list on another processor keeps the same order in particles. A) The particle moves from the Neighbour domain to the current domain B) The particle moves out of the communication zone, into the neighbouring domain C) The particle moves out of the communication zone, into the current domain D) The particle changes complexity: A special case where the particle required a re-evaluation in which boundary list it belongs

Parameters
[in]particleHandlerHandler that takes care of all particles in this domain
1309  {
1310  int complexityNew;
1311  std::vector<int> boundaryIndex;
1312 
1313  //For all active boundaries
1314  for (int localIndex : boundaryList_)
1315  {
1316  //Step 1A: Remove the particles from the boundaryParticleList_ which require re-assignment
1317  //or have just moved away from the region
1318  for (int p = 0; p < boundaryParticleList_[localIndex].size(); p++)
1319  {
1320  BaseParticle* particle = boundaryParticleList_[localIndex][p];
1321  //Check if the particle is still in the domain, but not in the communication zone
1322  if (containsParticle(particle))
1323  {
1324  //check if the complexity has changed
1325  boundaryIndex = findNearbyBoundaries(particle);
1326  complexityNew = boundaryIndex[0] + 3 * boundaryIndex[1] + 9 * boundaryIndex[2] + 13;
1327  if (particle->getCommunicationComplexity() != complexityNew)
1328  {
1329  logger(VERBOSE, "time: % | global index: % in list % | particle % | CURRENT DOMAIN - CHANGES "
1330  "COMPLEXITY", domainHandler_->getDPMBase()->getTime(), globalIndex_,
1331  localIndexToGlobalIndexTable_[localIndex], particle->getId());
1332  //Flag the particle that it no longer participates in the communication layer
1333  //so it can be reintroduced in the transmission step
1334  particle->setMPIParticle(false);
1335  particle->setInMPIDomain(false);
1336  particle->setCommunicationComplexity(0);
1337  boundaryParticleList_[localIndex][p] = nullptr;
1338  }
1339  }
1340  else
1341  {
1342  logger(VERBOSE, "time: % | global index: % in list % | particle % | CURRENT DOMAIN - TO NEIGHBOURING "
1343  "DOMAIN", domainHandler_->getDPMBase()->getTime(), globalIndex_,
1344  localIndexToGlobalIndexTable_[localIndex], particle->getId());
1345 
1346  ghostParticlesToBeDeleted.insert(particle);
1347  boundaryParticleList_[localIndex][p] = nullptr;
1348  }
1349  }
1350 
1351  //Step 1B: Remove the particles from the boundaryParticleListNeightbour_ which require re-assignment
1352  //or have just moved away from the region
1353  for (int p = 0; p < boundaryParticleListNeighbour_[localIndex].size(); p++)
1354  {
1355  BaseParticle* particle = boundaryParticleListNeighbour_[localIndex][p];
1356  //Check if the particle moved out of the neighbour domain
1358  {
1359  //The particle has moved to this domain
1360  if (containsParticle(particle))
1361  {
1362  logger(VERBOSE,
1363  "time: % | global index: % in list % | particle % | NEIGHBOURING DOMAIN - TO CURRENT DOMAIN",
1365  localIndexToGlobalIndexTable_[localIndex], particle->getId());
1366 
1367  //Flag the particle as not yet communicated
1368  particle->setMPIParticle(false);
1369  particle->setInMPIDomain(false);
1370  particle->setCommunicationComplexity(0);
1371  boundaryParticleListNeighbour_[localIndex][p] = nullptr;
1372  }
1373  //The particle has moved to a different domain
1374  else
1375  {
1376  logger(VERBOSE,
1377  "time: % | global index: % in list % | particle % | NEIGBOURING DOMAIN - TO OTHER DOMAIN",
1379  localIndexToGlobalIndexTable_[localIndex], particle->getId());
1380  //Cruelly destroy the particle without any mercy.
1381  ghostParticlesToBeDeleted.insert(particle);
1382  boundaryParticleListNeighbour_[localIndex][p] = nullptr;
1383  }
1384  }
1385  else
1386  {
1387  //check if the complexity has changed
1388  boundaryIndex = domainHandler_->getObject(
1389  localIndexToGlobalIndexTable_[localIndex])->findNearbyBoundaries(particle);
1390  complexityNew = boundaryIndex[0] + 3 * boundaryIndex[1] + 9 * boundaryIndex[2] + 13;
1391  if (particle->getCommunicationComplexity() != complexityNew)
1392  {
1393  logger(VERBOSE,
1394  "time: % | global index: % in list % | particle % | NEIGHBOURING DOMAIN - CHANGES COMPLEXITY",
1396  localIndexToGlobalIndexTable_[localIndex], particle->getId());
1397  //Cruelly destroy the particle without any mercy.
1398  ghostParticlesToBeDeleted.insert(particle);
1399  boundaryParticleListNeighbour_[localIndex][p] = nullptr;
1400  }
1401  }
1402  }
1403  }
1404  }
T * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:613
unsigned getCommunicationComplexity()
Obtains the communication complexity of the particle.
Definition: BaseParticle.cc:201
Mdouble getTime() const
Returns the current simulation time.
Definition: DPMBase.cc:808

References boundaryList_, boundaryParticleList_, boundaryParticleListNeighbour_, containsParticle(), domainHandler_, findNearbyBoundaries(), BaseParticle::getCommunicationComplexity(), BaseHandler< T >::getDPMBase(), BaseObject::getId(), BaseHandler< T >::getObject(), DPMBase::getTime(), globalIndex_, localIndexToGlobalIndexTable_, logger, BaseParticle::setCommunicationComplexity(), BaseParticle::setInMPIDomain(), BaseParticle::setMPIParticle(), and VERBOSE.

Referenced by finalisePositionAndVelocityUpdate().

◆ updateParticleVelocity()

void Domain::updateParticleVelocity ( int  localIndex)

Updates the velocity of particles which are flagged as MPIParticles.

Updates the translation but also the angular velocity

Parameters
[in]localIndexan index to the boundary being updated
1442 {
1443  //process the updated information
1444  unsigned int index = 0;
1445  for (BaseParticle* particle: boundaryParticleListNeighbour_[localIndex])
1446  {
1447  //set velocity
1448  particle->setVelocity(updateVelocityDataReceive_[localIndex][index].velocity);
1449  particle->setAngularVelocity(updateVelocityDataReceive_[localIndex][index].angularVelocity);
1450  index++;
1451  }
1452 }

References boundaryParticleListNeighbour_, and updateVelocityDataReceive_.

Referenced by finalisePositionAndVelocityUpdate(), and finaliseVelocityUpdate().

◆ updateStatus()

void Domain::updateStatus ( std::set< BaseParticle * > &  ghostParticlesToBeDeleted)

Updates particles that are not in the current domain and communicates newly added particles.

First the newly positions of the ghost particles are communicated, based on the new positions these particles will be updated accordingly. Secondly a new sweep through all particles is performed to see if we need to add any particles to the list which have moved into the communication zone. Particles that need to be removed from the simulation are stored in a vector and will be destroyed at a later point in the code.

Parameters
[in,out]ghostParticlesToBeDeletedA list of particles which will be deleted afterwards
1634 {
1635  //Collect new positions and velocities and send them to the other domains
1638 
1639  //Receive the new positions and velocities from other domains
1640  //and update the mpi flagged particles accordingly. removes and switched particles in the lists
1641  finalisePositionAndVelocityUpdate(ghostParticlesToBeDeleted);
1643 }
void finalisePositionAndVelocityUpdate(std::set< BaseParticle * > &ghostParticlesToBeDeleted)
processes position and velocity data for ghost particles
Definition: Domain.cc:1501
void preparePositionAndVelocityUpdate()
Function that sends particle position and velocity data for ghost particles to other processors.
Definition: Domain.cc:1460

References finalisePositionAndVelocityUpdate(), MPIContainer::Instance(), preparePositionAndVelocityUpdate(), and MPIContainer::sync().

Referenced by DomainHandler::updateStatus().

◆ updateVelocity()

void Domain::updateVelocity ( )

Updates MPI particle velocity at the half-time step.

: not in use

1649 {
1650  //collect new velocity data and send
1653 
1654  //process the received data
1657 }
void prepareVelocityUpdate()
Function that sends particle velocity data for ghost particles.
Definition: Domain.cc:1529
void finaliseVelocityUpdate()
Processes particle velocity data for ghost particles.
Definition: Domain.cc:1557

References finaliseVelocityUpdate(), MPIContainer::Instance(), prepareVelocityUpdate(), and MPIContainer::sync().

Referenced by DomainHandler::updateVelocity().

◆ write()

void Domain::write ( std::ostream &  os) const
overridevirtual

This function does nothing.

Adds the object's id_ to the given ostream

Parameters
[in]osostream the id_ is added to
Todo:
MX: why would this function be called?

Implements BaseObject.

198 {
199  logger(WARN, "[Domain::write] should not be called");
200  //BaseObject::write(os);
201 }

References logger, and WARN.

Member Data Documentation

◆ activeBoundaryList_

std::vector<bool> Domain::activeBoundaryList_
private

A list of flags corresponding to an inactive or active boundary.

Referenced by constructor(), disableBoundaries(), disableBoundary(), Domain(), and getActiveBoundaryList().

◆ boundaryList_

◆ boundaryParticleDataReceive_

std::vector<std::vector<MPIParticle> > Domain::boundaryParticleDataReceive_
private

Container that keeps a list of MPIParticles that are being received by this domain.

Referenced by constructor(), Domain(), finaliseBoundaryDataTransmission(), performBoundaryDataTransmission(), and processReceivedBoundaryParticleData().

◆ boundaryParticleDataSend_

std::vector<std::vector<MPIParticle> > Domain::boundaryParticleDataSend_
private

Container that keeps a list of MPIParticles that are being send to other domains.

Referenced by collectBoundaryParticleData(), constructor(), Domain(), finaliseBoundaryDataTransmission(), and performBoundaryDataTransmission().

◆ boundaryParticleList_

std::vector<std::vector<BaseParticle*> > Domain::boundaryParticleList_
private

A list of boundary particles in the communication zone that are ghost particles on other domains.

Referenced by cleanCommunicationLists(), constructor(), Domain(), flushParticles(), preparePositionAndVelocityUpdate(), prepareVelocityUpdate(), processSentBoundaryParticles(), and updateParticles().

◆ boundaryParticleListNeighbour_

std::vector<std::vector<BaseParticle*> > Domain::boundaryParticleListNeighbour_
private

◆ domainHandler_

DomainHandler* Domain::domainHandler_
private

◆ domainMax_

std::vector<double> Domain::domainMax_
private

Maximum domain bounds in the x,y and z direction.

Referenced by constructor(), containsParticle(), Domain(), findNearbyBoundaries(), getDomainMax(), setBounds(), and setRange().

◆ domainMin_

std::vector<double> Domain::domainMin_
private

Minimum domain bounds in the x,y and z direction.

Referenced by constructor(), containsParticle(), Domain(), findNearbyBoundaries(), getDomainMin(), setBounds(), and setRange().

◆ globalIndex_

int Domain::globalIndex_
private

Global index of the domain in the mesh.

Note
for a standard decomposition this compares straight to the rank of the processor

Referenced by createLookUpTable(), getGlobalIndex(), sendAndReceiveCount(), sendAndReceiveMPIData(), and updateParticles().

◆ globalMeshIndex_

std::vector<unsigned> Domain::globalMeshIndex_
private

Vector containing the global mesh indices i,j,k.

Referenced by createLookUpTable(), disableBoundaries(), Domain(), getGlobalMeshIndex(), and setGlobalMeshIndex().

◆ interactionDataReceive_

std::vector<void*> Domain::interactionDataReceive_
private

Container that keeps a void array of all the interaction data that is being received by this domain, interpretation is done by the interaction handler.

Referenced by constructor(), Domain(), finaliseBoundaryDataTransmission(), performBoundaryDataTransmission(), and processReceivedInteractionData().

◆ interactionDataSend_

std::vector<void*> Domain::interactionDataSend_
private

Container that keeps a void array of all the interaction data that are being send to other domains, interpretation is done by the interaction handler.

Referenced by collectInteractionData(), constructor(), Domain(), finaliseBoundaryDataTransmission(), and performBoundaryDataTransmission().

◆ localIndexToGlobalIndexTable_

std::vector<int> Domain::localIndexToGlobalIndexTable_
private

look-up table to get the global index given a local domain index

Todo:
TW@Marnix should this be unsigned int

Referenced by constructor(), createLookUpTable(), Domain(), sendAndReceiveCount(), sendAndReceiveMPIData(), and updateParticles().

◆ localIndexToProcessorList_

std::vector<int> Domain::localIndexToProcessorList_
private

look-up table to get the processor of the domain given a local domain index

Todo:
TW@Marnix should this be unsigned int

Referenced by constructor(), createLookUpTable(), Domain(), sendAndReceiveCount(), and sendAndReceiveMPIData().

◆ middle_

Vec3D Domain::middle_
private

Middle of the closed domain.

Referenced by Domain(), getMiddle(), setBounds(), and setRange().

◆ newBoundaryParticleList_

std::vector<std::vector<BaseParticle*> > Domain::newBoundaryParticleList_
private

◆ newInteractionList_

std::vector<std::vector<BaseInteraction*> > Domain::newInteractionList_
private

Array that queues interactions that need to be transmitted.

Referenced by collectInteractionData(), constructor(), Domain(), finaliseBoundaryDataTransmission(), findNewMPIInteractions(), and prepareBoundaryDataTransmission().

◆ numberOfParticlesReceive_

std::vector<unsigned> Domain::numberOfParticlesReceive_
private

◆ numberOfParticlesSend_

std::vector<unsigned> Domain::numberOfParticlesSend_
private

Counter that keeps track of the number of particles that are being send to other domains.

Referenced by constructor(), Domain(), finaliseBoundaryDataTransmission(), performBoundaryDataTransmission(), prepareBoundaryDataTransmission(), preparePositionAndVelocityUpdate(), and prepareVelocityUpdate().

◆ numNewInteractionsReceive_

std::vector<unsigned> Domain::numNewInteractionsReceive_
private

Counter that keeps track of the number of interactions that are being received by this domain.

Referenced by constructor(), Domain(), finaliseBoundaryDataTransmission(), performBoundaryDataTransmission(), prepareBoundaryDataTransmission(), and processReceivedInteractionData().

◆ numNewInteractionsSend_

std::vector<unsigned> Domain::numNewInteractionsSend_
private

Counter that keeps track of the number of interactions that are being send to other domains.

Referenced by constructor(), Domain(), finaliseBoundaryDataTransmission(), performBoundaryDataTransmission(), and prepareBoundaryDataTransmission().

◆ rank_

int Domain::rank_
private

Rank of the domain which identifies to which processor it belongs.

Referenced by constructor(), createLookUpTable(), Domain(), getRank(), and setRank().

◆ updatePositionDataReceive_

std::vector<std::vector<MPIParticlePosition> > Domain::updatePositionDataReceive_
private

Container that keeps a list of MPIParticlePositions that are being received by this domain.

Referenced by constructor(), Domain(), finalisePositionAndVelocityUpdate(), preparePositionAndVelocityUpdate(), and updateParticlePosition().

◆ updatePositionDataSend_

std::vector<std::vector<MPIParticlePosition> > Domain::updatePositionDataSend_
private

Container that keeps a list of MPIParticlePositions that are being send to other domains.

Referenced by constructor(), Domain(), finalisePositionAndVelocityUpdate(), and preparePositionAndVelocityUpdate().

◆ updateVelocityDataReceive_

std::vector<std::vector<MPIParticleVelocity> > Domain::updateVelocityDataReceive_
private

Container that keeps a list of MPIParticleVelocities that are being received by this domain.

Referenced by constructor(), Domain(), finalisePositionAndVelocityUpdate(), finaliseVelocityUpdate(), preparePositionAndVelocityUpdate(), prepareVelocityUpdate(), and updateParticleVelocity().

◆ updateVelocityDataSend_

std::vector<std::vector<MPIParticleVelocity> > Domain::updateVelocityDataSend_
private

Container that keeps a list of MPIParticleVelocities that are being send to other domains.

Referenced by constructor(), Domain(), finalisePositionAndVelocityUpdate(), finaliseVelocityUpdate(), preparePositionAndVelocityUpdate(), and prepareVelocityUpdate().


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