PeriodicBoundaryHandler.h
Go to the documentation of this file.
1 // This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2 // Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3 // License: BSD 3-Clause License; see the LICENSE file in the root directory.
4 
5 #ifndef PERIODICBOUNDARYHANDLER_H
6 #define PERIODICBOUNDARYHANDLER_H
7 
8 #include "BaseHandler.h"
10 #include "MpiDataClass.h"
11 #include <set>
12 
13 
14 typedef std::vector<MpiPeriodicParticleID*> PeriodicList;
15 typedef std::vector<MpiPeriodicGhostParticleID*> PeriodicGhostList;
16 
23 class PeriodicBoundaryHandler final : public BaseHandler<BasePeriodicBoundary>
24 {
25 public:
30 
35 
40 
44  ~PeriodicBoundaryHandler() override;
45 
49  void addObject(BasePeriodicBoundary* P) override;
50 
52  void readAndAddObject(std::istream& is) override;
53 
57  std::string getName() const override;
58 
62  void setInteractionDistance(Mdouble interactionDistance);
63 
68 
72  void updateStatus(std::set<BaseParticle*>& ghostParticlesToBeDeleted);
73 
77  void shiftParticle(BaseParticle* particle);
78 
82  void shiftParticle(BaseParticle* particle, const std::vector<int>& complexity);
83 
87  std::vector<int> computePeriodicComplexity(Vec3D position);
88 
92  void computePeriodicComplexity(std::vector<int>& periodicComplexity, int& totalPeriodicComplexity, Vec3D position);
93 
97  void addNewParticles();
98 
102  void addNewParticle(BaseParticle* particle);
103 
107  unsigned int getNumberOfPeriodicGhostParticles();
108 
114 
118  void getMPIFlags(BaseParticle* particle, bool& isInMPIDomain, bool& isMPIParticle);
119 
123  void setMPIFlags(BaseParticle* particle);
124 
128  void generateGhosts(std::vector<std::vector<int> >& list, std::vector<int> periodicComplexity,
129  std::vector<int>& complexity, int level);
130 
135 
139  void collectInteractionData();
140 
144  void processReceivedGhostParticleData(int targetIndex, std::vector<BaseParticle*>& newParticles);
145 
149  void processReceivedInteractionData(int targetIndex, std::vector<BaseParticle*>& newParticles);
150 
154  void processLocalInteractionData(std::vector<BaseParticle*>& newParticles);
155 
160 
164  void processLocalGhostParticles(std::vector<BaseParticle*>& newParticles);
165 
169  void updateParticles();
170 
174  bool checkIsReal(std::vector<int> complexity);
175 
179  bool checkChanged(std::vector<int> previousComplexity, std::vector<int> complexity);
180 
184  void updateParticleStatus(std::set<BaseParticle*>& particlesToBeDeleted);
185 
189  int findTargetProcessor(const std::vector<int>& complexity);
190 
194  void findNewParticle(BaseParticle* particle);
195 
196  bool checkIfAddNewParticle(BaseParticle* particle);
197 
201  void findNewParticles();
202 
206  void findNewInteractions();
207 
212 
217 
222 
227 
232 
237 
242 
246  void flushParticles(std::set<BaseParticle*>& particlesToBeFlushed);
247 
251  void cleanCommunicationList(std::vector<MpiPeriodicParticleIDBase*>& list);
252 
254 
259 
263  void initialise();
264 
268  void flushPeriodicParticles(std::set<BaseParticle*>& particlesToBeDeleted);
269 
274 
278  void updateMaserParticle(BaseParticle* particle);
279 
283  void
284  findBoundariesToIgnore(BaseParticle* particle, std::vector<int>& periodicComplexity, int& totalPeriodicComplexity);
285 
286 
287 private:
293 
298  std::vector<int> receiveTargetList_;
299 
304  std::vector<int> sendTargetList_;
305 
311 
317 
322 
327 
331  std::vector<std::vector<MPIParticle> > periodicGhostParticleReceive_;
332 
336  std::vector<std::vector<MPIParticle> > periodicGhostParticleSend_;
337 
341  std::vector<std::vector<int> > periodicGhostComplexityReceive_;
342 
346  std::vector<std::vector<int> > periodicGhostComplexitySend_;
347 
351  std::vector<std::vector<MPIParticlePosition> > updatePositionDataReceive_;
352 
356  std::vector<std::vector<MPIParticlePosition> > updatePositionDataSend_;
357 
361  std::vector<std::vector<MPIParticleVelocity> > updateVelocityDataReceive_;
362 
366  std::vector<std::vector<MPIParticleVelocity> > updateVelocityDataSend_;
367 
371  std::vector<void*> interactionDataSend_;
372 
376  std::vector<void*> interactionDataReceive_;
377 
383  std::vector<PeriodicList> newPeriodicParticleList_;
384 
388  std::vector<std::vector<BaseInteraction*> > newInteractionList_;
389 
395  std::vector<PeriodicList> periodicParticleList_;
396 
402  std::vector<PeriodicGhostList> periodicGhostList_;
403 };
404 
405 #endif
406 
std::vector< MpiPeriodicParticleID * > PeriodicList
Definition: PeriodicBoundaryHandler.h:14
std::vector< MpiPeriodicGhostParticleID * > PeriodicGhostList
Definition: PeriodicBoundaryHandler.h:15
Container to store the pointers to all objects that one creates in a simulation.
Definition: BaseHandler.h:30
Definition: BaseParticle.h:33
Definition: BasePeriodicBoundary.h:20
Container to store pointers to all BasePeriodicBoundary objects.
Definition: PeriodicBoundaryHandler.h:24
void performActionsBeforeAddingParticles()
Actions that boundaries perform before adding new periodic/ghost particles.
Definition: PeriodicBoundaryHandler.cc:1772
void updateMaserParticle(BaseParticle *particle)
Updates the maser flag of particles leaving the maser.
Definition: PeriodicBoundaryHandler.cc:1842
void addObject(BasePeriodicBoundary *P) override
Adds a BasePeriodicBoundary to the PeriodicBoundaryHandler.
Definition: PeriodicBoundaryHandler.cc:68
std::vector< std::vector< MPIParticlePosition > > updatePositionDataReceive_
Data container for position data that is being received from other processors.
Definition: PeriodicBoundaryHandler.h:351
std::vector< PeriodicList > periodicParticleList_
A vector the size of the number of processors, each entry containing a vector of periodic particle ID...
Definition: PeriodicBoundaryHandler.h:395
void cleanCommunicationLists()
Definition: PeriodicBoundaryHandler.cc:1750
Mdouble interactionDistance_
The interaction distance between a position and the boundary for which particles start to participate...
Definition: PeriodicBoundaryHandler.h:292
void processLocalInteractionData(std::vector< BaseParticle * > &newParticles)
Process the interaction data for local ghosts.
Definition: PeriodicBoundaryHandler.cc:670
void setMPIFlags(BaseParticle *particle)
Sets the MPIParticle and isMPIParticle flags of a given particle.
Definition: PeriodicBoundaryHandler.cc:421
void initialise()
Initialises the communication list vectors as they can not be determined on compile time.
Definition: PeriodicBoundaryHandler.cc:1765
void communicateTargetDomains()
Creats a list of send and receive targets for periodic/ghost particles.
Definition: PeriodicBoundaryHandler.cc:1372
std::vector< void * > interactionDataSend_
Stores the interaction data that is going to be send.
Definition: PeriodicBoundaryHandler.h:371
PeriodicBoundaryHandler operator=(const PeriodicBoundaryHandler &rhs)
Assignment operator, copies only the vector of BasePeriodicBoundary and sets the other variables to 0...
Definition: PeriodicBoundaryHandler.cc:44
void shiftParticle(BaseParticle *particle)
Shifts the position of the particle based on its current periodic complexity.
Definition: PeriodicBoundaryHandler.cc:148
std::vector< int > numberOfNewPeriodicGhostParticlesReceive_
A vector that stores how many new ghost particles will be received from other processors.
Definition: PeriodicBoundaryHandler.h:310
void prepareNewParticleTransmission()
Initial preparation work for sending ghost particles.
Definition: PeriodicBoundaryHandler.cc:1468
std::vector< int > numberOfNewPeriodicGhostParticlesSend_
A vector that stores how many particles are going to be send to other processors.
Definition: PeriodicBoundaryHandler.h:316
void communicateNumberOfNewParticlesAndInteractions()
Communicate the number of new particles and interactions to target processors.
Definition: PeriodicBoundaryHandler.cc:1426
void processPeriodicParticles()
Creates a periodioc particle ID for book keeping and moves the ID to the correct list.
Definition: PeriodicBoundaryHandler.cc:760
~PeriodicBoundaryHandler() override
Destructor, it destructs the PeriodicBoundaryHandler and all BasePeriodicBoundary it contains.
Definition: PeriodicBoundaryHandler.cc:56
void generateGhosts(std::vector< std::vector< int > > &list, std::vector< int > periodicComplexity, std::vector< int > &complexity, int level)
generates a list of periodic complexities corresponding to a give real particle.
Definition: PeriodicBoundaryHandler.cc:443
void flushPeriodicParticles(std::set< BaseParticle * > &particlesToBeDeleted)
Flushes periodioc particles that need to be deleted from the periodic lists.
void getMPIFlags(BaseParticle *particle, bool &isInMPIDomain, bool &isMPIParticle)
Determines if a given particle is in the MPI domain and if it is an MPI Particle.
Definition: PeriodicBoundaryHandler.cc:379
void performNewParticleTransmission()
Collects and sends the ghost particle data.
Definition: PeriodicBoundaryHandler.cc:1483
unsigned int getNumberOfPeriodicGhostParticles()
Returns the number of particles that are flagged is periodicGhostParticle.
Definition: PeriodicBoundaryHandler.cc:335
bool checkIfAddNewParticle(BaseParticle *particle)
Definition: PeriodicBoundaryHandler.cc:1863
std::vector< int > computePeriodicComplexity(Vec3D position)
Computes the periodic complexity based on a given position.
Definition: PeriodicBoundaryHandler.cc:260
std::vector< std::vector< BaseInteraction * > > newInteractionList_
Definition: PeriodicBoundaryHandler.h:388
Mdouble getNumberOfTruePeriodicGhostParticles()
Returns the number of particles that are flagged as periodicGhostParticles, but not as MPIParticles.
Definition: PeriodicBoundaryHandler.cc:351
void updateStatus(std::set< BaseParticle * > &ghostParticlesToBeDeleted)
Updates the positions/velocity of ghost particles and accordingly the status of these particles.
Definition: PeriodicBoundaryHandler.cc:129
std::vector< void * > interactionDataReceive_
Stores the interaction data that is going to be received.
Definition: PeriodicBoundaryHandler.h:376
std::vector< PeriodicList > newPeriodicParticleList_
Definition: PeriodicBoundaryHandler.h:383
void addNewParticles()
Adds new particles to the periodic particle lists.
Definition: PeriodicBoundaryHandler.cc:278
bool checkChanged(std::vector< int > previousComplexity, std::vector< int > complexity)
checks of two periodic complexities differ
Definition: PeriodicBoundaryHandler.cc:990
std::vector< std::vector< MPIParticlePosition > > updatePositionDataSend_
Data container for position data that is being send to other processors.
Definition: PeriodicBoundaryHandler.h:356
void processReceivedInteractionData(int targetIndex, std::vector< BaseParticle * > &newParticles)
Process the received interaction data.
Definition: PeriodicBoundaryHandler.cc:593
void preparePositionAndVelocityUpdate()
Collects the position and velocity data from periodic boundaries.
Definition: PeriodicBoundaryHandler.cc:1606
int findTargetProcessor(const std::vector< int > &complexity)
For a given complexity this function returns the target processor.
Definition: PeriodicBoundaryHandler.cc:1228
Mdouble getInteractionDistance()
Returns the interaction distance.
Definition: PeriodicBoundaryHandler.cc:115
void findNewInteractions()
Finds interactions that accompany future ghost particles.
Definition: PeriodicBoundaryHandler.cc:1321
void updateParticles()
Updates position/velocity and periodic complexity of ghost particles.
Definition: PeriodicBoundaryHandler.cc:838
std::vector< std::vector< int > > periodicGhostComplexityReceive_
Data container for periodic complexity that is being received from other processors.
Definition: PeriodicBoundaryHandler.h:341
void collectInteractionData()
Collects interaction data into an MPI data structure.
Definition: PeriodicBoundaryHandler.cc:506
void addNewParticle(BaseParticle *particle)
Adds a new particle to the periodic list.
Definition: PeriodicBoundaryHandler.cc:311
void clearCommunicationLists()
Removes all ghost particles and bookkeeping for a fresh start.
Definition: PeriodicBoundaryHandler.cc:1785
PeriodicBoundaryHandler()
Default constructor, it creates an empty PeriodicBoundaryHandler.
Definition: PeriodicBoundaryHandler.cc:20
std::vector< std::vector< MPIParticleVelocity > > updateVelocityDataReceive_
Data container for velocity data that is being received from other processors.
Definition: PeriodicBoundaryHandler.h:361
void processReceivedGhostParticleData(int targetIndex, std::vector< BaseParticle * > &newParticles)
Processes the received ghost data, creates a ghost particle and does some book keeping.
Definition: PeriodicBoundaryHandler.cc:538
std::vector< std::vector< MPIParticle > > periodicGhostParticleSend_
Data container for particles that are being send to other processors.
Definition: PeriodicBoundaryHandler.h:336
void finaliseNewParticleTransmission()
creates the ghost particles and performs some bookkeeping to keep track of them
Definition: PeriodicBoundaryHandler.cc:1564
void findBoundariesToIgnore(BaseParticle *particle, std::vector< int > &periodicComplexity, int &totalPeriodicComplexity)
Disables boundaries that need to be ignored (i.e. a non-maser particle needs to ignore the maser boun...
void readAndAddObject(std::istream &is) override
Pure virtual function needs implementation, but it does nothing for the periodicBoudnaryHandler.
Definition: PeriodicBoundaryHandler.cc:87
std::string getName() const override
Returns the name of the handler, namely the string "PeriodicBoundaryHandler".
Definition: PeriodicBoundaryHandler.cc:95
void processLocalGhostParticles(std::vector< BaseParticle * > &newParticles)
Creates ghost particles of periodic particles that are located on the same processor.
Definition: PeriodicBoundaryHandler.cc:783
void findNewParticles()
Loops over all particles in the simulation to check if they need to be added to the periodic lists.
Definition: PeriodicBoundaryHandler.cc:1306
std::vector< std::vector< MPIParticle > > periodicGhostParticleReceive_
Data container for particles that are being received from other processors.
Definition: PeriodicBoundaryHandler.h:331
void cleanCommunicationList(std::vector< MpiPeriodicParticleIDBase * > &list)
Removes the nullptr's from a communication list.
Definition: PeriodicBoundaryHandler.cc:1737
void updateParticleStatus(std::set< BaseParticle * > &particlesToBeDeleted)
Updates the status of periodic particles and ghost particles.
Definition: PeriodicBoundaryHandler.cc:1014
bool checkIsReal(std::vector< int > complexity)
checks if a periodic complexity is real
Definition: PeriodicBoundaryHandler.cc:966
std::vector< int > receiveTargetList_
A list that keeps track which target processors the current processor is receiving new particles from...
Definition: PeriodicBoundaryHandler.h:298
std::vector< int > numberOfNewInteractionsSend_
Stores the number of new interactions to be send to target processor corresponding to sendTargetList_...
Definition: PeriodicBoundaryHandler.h:321
std::vector< PeriodicGhostList > periodicGhostList_
A vector the size of the number of processors, each entry containing a vector of ghost periodioc part...
Definition: PeriodicBoundaryHandler.h:402
std::vector< std::vector< MPIParticleVelocity > > updateVelocityDataSend_
Data container for velocity data that is being send to other processors.
Definition: PeriodicBoundaryHandler.h:366
void setInteractionDistance(Mdouble interactionDistance)
Sets the interaction distance.
Definition: PeriodicBoundaryHandler.cc:106
void flushParticles(std::set< BaseParticle * > &particlesToBeFlushed)
Removes particles from the periodiocParticleList_ and periociGhostList_.
Definition: PeriodicBoundaryHandler.cc:1683
std::vector< std::vector< int > > periodicGhostComplexitySend_
Data container for periodic complexity that is being send to other processors.
Definition: PeriodicBoundaryHandler.h:346
std::vector< int > numberOfNewInteractionsReceive_
Stores the number of new interactions to be received from target processor corresponding to receiveTa...
Definition: PeriodicBoundaryHandler.h:326
void finalisePositionAndVelocityUpdate()
Communicates position and velocity data from periodic boundaries and updates ghost particles.
Definition: PeriodicBoundaryHandler.cc:1670
std::vector< int > sendTargetList_
A list that keeps track to which targets this processor is sending new particles to.
Definition: PeriodicBoundaryHandler.h:304
void findNewParticle(BaseParticle *particle)
Checks if a particle is in the periodic domain, but are not flagged as being in the periodic domain.
Definition: PeriodicBoundaryHandler.cc:1249
void collectGhostParticleData()
Collects ghost particle data that needs to be be sent to other processors.
Definition: PeriodicBoundaryHandler.cc:475
Definition: Kernel/Math/Vector.h:30
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:77
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286