PeriodicBoundaryHandler.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2023, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 
27 #ifndef PERIODICBOUNDARYHANDLER_H
28 #define PERIODICBOUNDARYHANDLER_H
29 
30 #include "BaseHandler.h"
32 #include "MpiDataClass.h"
33 #include <set>
34 
35 
36 typedef std::vector<MpiPeriodicParticleID*> PeriodicList;
37 typedef std::vector<MpiPeriodicGhostParticleID*> PeriodicGhostList;
38 
45 class PeriodicBoundaryHandler final : public BaseHandler<BasePeriodicBoundary>
46 {
47 public:
52 
57 
62 
66  ~PeriodicBoundaryHandler() override;
67 
71  void addObject(BasePeriodicBoundary* P) override;
72 
74  void readAndAddObject(std::istream& is) override;
75 
79  std::string getName() const override;
80 
84  void setInteractionDistance(Mdouble interactionDistance);
85 
90 
94  void updateStatus(std::set<BaseParticle*>& ghostParticlesToBeDeleted);
95 
99  void shiftParticle(BaseParticle* particle);
100 
104  void shiftParticle(BaseParticle* particle, const std::vector<int>& complexity);
105 
109  std::vector<int> computePeriodicComplexity(Vec3D position);
110 
114  void computePeriodicComplexity(std::vector<int>& periodicComplexity, int& totalPeriodicComplexity, Vec3D position);
115 
119  void addNewParticles();
120 
124  void addNewParticle(BaseParticle* particle);
125 
129  unsigned int getNumberOfPeriodicGhostParticles();
130 
136 
140  void getMPIFlags(BaseParticle* particle, bool& isInMPIDomain, bool& isMPIParticle);
141 
145  void setMPIFlags(BaseParticle* particle);
146 
150  void generateGhosts(std::vector<std::vector<int> >& list, std::vector<int> periodicComplexity,
151  std::vector<int>& complexity, int level);
152 
157 
161  void collectInteractionData();
162 
166  void processReceivedGhostParticleData(int targetIndex, std::vector<BaseParticle*>& newParticles);
167 
171  void processReceivedInteractionData(int targetIndex, std::vector<BaseParticle*>& newParticles);
172 
176  void processLocalInteractionData(std::vector<BaseParticle*>& newParticles);
177 
182 
186  void processLocalGhostParticles(std::vector<BaseParticle*>& newParticles);
187 
191  void updateParticles();
192 
196  bool checkIsReal(std::vector<int> complexity);
197 
201  bool checkChanged(std::vector<int> previousComplexity, std::vector<int> complexity);
202 
206  void updateParticleStatus(std::set<BaseParticle*>& particlesToBeDeleted);
207 
211  int findTargetProcessor(const std::vector<int>& complexity);
212 
216  void findNewParticle(BaseParticle* particle);
217 
218  bool checkIfAddNewParticle(BaseParticle* particle);
219 
223  void findNewParticles();
224 
228  void findNewInteractions();
229 
234 
239 
244 
249 
254 
259 
264 
268  void flushParticles(std::set<BaseParticle*>& particlesToBeFlushed);
269 
273  void cleanCommunicationList(std::vector<MpiPeriodicParticleIDBase*>& list);
274 
276 
281 
285  void initialise();
286 
290  void flushPeriodicParticles(std::set<BaseParticle*>& particlesToBeDeleted);
291 
296 
300  void updateMaserParticle(BaseParticle* particle);
301 
305  void
306  findBoundariesToIgnore(BaseParticle* particle, std::vector<int>& periodicComplexity, int& totalPeriodicComplexity);
307 
308 
309 private:
315 
320  std::vector<int> receiveTargetList_;
321 
326  std::vector<int> sendTargetList_;
327 
333 
339 
344 
349 
353  std::vector<std::vector<MPIParticle> > periodicGhostParticleReceive_;
354 
358  std::vector<std::vector<MPIParticle> > periodicGhostParticleSend_;
359 
363  std::vector<std::vector<int> > periodicGhostComplexityReceive_;
364 
368  std::vector<std::vector<int> > periodicGhostComplexitySend_;
369 
373  std::vector<std::vector<MPIParticlePosition> > updatePositionDataReceive_;
374 
378  std::vector<std::vector<MPIParticlePosition> > updatePositionDataSend_;
379 
383  std::vector<std::vector<MPIParticleVelocity> > updateVelocityDataReceive_;
384 
388  std::vector<std::vector<MPIParticleVelocity> > updateVelocityDataSend_;
389 
393  std::vector<void*> interactionDataSend_;
394 
398  std::vector<void*> interactionDataReceive_;
399 
405  std::vector<PeriodicList> newPeriodicParticleList_;
406 
410  std::vector<std::vector<BaseInteraction*> > newInteractionList_;
411 
417  std::vector<PeriodicList> periodicParticleList_;
418 
424  std::vector<PeriodicGhostList> periodicGhostList_;
425 };
426 
427 #endif
428 
std::vector< MpiPeriodicParticleID * > PeriodicList
Definition: PeriodicBoundaryHandler.h:36
std::vector< MpiPeriodicGhostParticleID * > PeriodicGhostList
Definition: PeriodicBoundaryHandler.h:37
Container to store the pointers to all objects that one creates in a simulation.
Definition: BaseHandler.h:51
Definition: BaseParticle.h:54
Definition: BasePeriodicBoundary.h:41
Container to store pointers to all BasePeriodicBoundary objects.
Definition: PeriodicBoundaryHandler.h:46
void performActionsBeforeAddingParticles()
Actions that boundaries perform before adding new periodic/ghost particles.
Definition: PeriodicBoundaryHandler.cc:1794
void updateMaserParticle(BaseParticle *particle)
Updates the maser flag of particles leaving the maser.
Definition: PeriodicBoundaryHandler.cc:1864
void addObject(BasePeriodicBoundary *P) override
Adds a BasePeriodicBoundary to the PeriodicBoundaryHandler.
Definition: PeriodicBoundaryHandler.cc:90
std::vector< std::vector< MPIParticlePosition > > updatePositionDataReceive_
Data container for position data that is being received from other processors.
Definition: PeriodicBoundaryHandler.h:373
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:417
void cleanCommunicationLists()
Definition: PeriodicBoundaryHandler.cc:1772
Mdouble interactionDistance_
The interaction distance between a position and the boundary for which particles start to participate...
Definition: PeriodicBoundaryHandler.h:314
void processLocalInteractionData(std::vector< BaseParticle * > &newParticles)
Process the interaction data for local ghosts.
Definition: PeriodicBoundaryHandler.cc:692
void setMPIFlags(BaseParticle *particle)
Sets the MPIParticle and isMPIParticle flags of a given particle.
Definition: PeriodicBoundaryHandler.cc:443
void initialise()
Initialises the communication list vectors as they can not be determined on compile time.
Definition: PeriodicBoundaryHandler.cc:1787
void communicateTargetDomains()
Creats a list of send and receive targets for periodic/ghost particles.
Definition: PeriodicBoundaryHandler.cc:1394
std::vector< void * > interactionDataSend_
Stores the interaction data that is going to be send.
Definition: PeriodicBoundaryHandler.h:393
PeriodicBoundaryHandler operator=(const PeriodicBoundaryHandler &rhs)
Assignment operator, copies only the vector of BasePeriodicBoundary and sets the other variables to 0...
Definition: PeriodicBoundaryHandler.cc:66
void shiftParticle(BaseParticle *particle)
Shifts the position of the particle based on its current periodic complexity.
Definition: PeriodicBoundaryHandler.cc:170
std::vector< int > numberOfNewPeriodicGhostParticlesReceive_
A vector that stores how many new ghost particles will be received from other processors.
Definition: PeriodicBoundaryHandler.h:332
void prepareNewParticleTransmission()
Initial preparation work for sending ghost particles.
Definition: PeriodicBoundaryHandler.cc:1490
std::vector< int > numberOfNewPeriodicGhostParticlesSend_
A vector that stores how many particles are going to be send to other processors.
Definition: PeriodicBoundaryHandler.h:338
void communicateNumberOfNewParticlesAndInteractions()
Communicate the number of new particles and interactions to target processors.
Definition: PeriodicBoundaryHandler.cc:1448
void processPeriodicParticles()
Creates a periodioc particle ID for book keeping and moves the ID to the correct list.
Definition: PeriodicBoundaryHandler.cc:782
~PeriodicBoundaryHandler() override
Destructor, it destructs the PeriodicBoundaryHandler and all BasePeriodicBoundary it contains.
Definition: PeriodicBoundaryHandler.cc:78
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:465
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:401
void performNewParticleTransmission()
Collects and sends the ghost particle data.
Definition: PeriodicBoundaryHandler.cc:1505
unsigned int getNumberOfPeriodicGhostParticles()
Returns the number of particles that are flagged is periodicGhostParticle.
Definition: PeriodicBoundaryHandler.cc:357
bool checkIfAddNewParticle(BaseParticle *particle)
Definition: PeriodicBoundaryHandler.cc:1885
std::vector< int > computePeriodicComplexity(Vec3D position)
Computes the periodic complexity based on a given position.
Definition: PeriodicBoundaryHandler.cc:282
std::vector< std::vector< BaseInteraction * > > newInteractionList_
Definition: PeriodicBoundaryHandler.h:410
Mdouble getNumberOfTruePeriodicGhostParticles()
Returns the number of particles that are flagged as periodicGhostParticles, but not as MPIParticles.
Definition: PeriodicBoundaryHandler.cc:373
void updateStatus(std::set< BaseParticle * > &ghostParticlesToBeDeleted)
Updates the positions/velocity of ghost particles and accordingly the status of these particles.
Definition: PeriodicBoundaryHandler.cc:151
std::vector< void * > interactionDataReceive_
Stores the interaction data that is going to be received.
Definition: PeriodicBoundaryHandler.h:398
std::vector< PeriodicList > newPeriodicParticleList_
Definition: PeriodicBoundaryHandler.h:405
void addNewParticles()
Adds new particles to the periodic particle lists.
Definition: PeriodicBoundaryHandler.cc:300
bool checkChanged(std::vector< int > previousComplexity, std::vector< int > complexity)
checks of two periodic complexities differ
Definition: PeriodicBoundaryHandler.cc:1012
std::vector< std::vector< MPIParticlePosition > > updatePositionDataSend_
Data container for position data that is being send to other processors.
Definition: PeriodicBoundaryHandler.h:378
void processReceivedInteractionData(int targetIndex, std::vector< BaseParticle * > &newParticles)
Process the received interaction data.
Definition: PeriodicBoundaryHandler.cc:615
void preparePositionAndVelocityUpdate()
Collects the position and velocity data from periodic boundaries.
Definition: PeriodicBoundaryHandler.cc:1628
int findTargetProcessor(const std::vector< int > &complexity)
For a given complexity this function returns the target processor.
Definition: PeriodicBoundaryHandler.cc:1250
Mdouble getInteractionDistance()
Returns the interaction distance.
Definition: PeriodicBoundaryHandler.cc:137
void findNewInteractions()
Finds interactions that accompany future ghost particles.
Definition: PeriodicBoundaryHandler.cc:1343
void updateParticles()
Updates position/velocity and periodic complexity of ghost particles.
Definition: PeriodicBoundaryHandler.cc:860
std::vector< std::vector< int > > periodicGhostComplexityReceive_
Data container for periodic complexity that is being received from other processors.
Definition: PeriodicBoundaryHandler.h:363
void collectInteractionData()
Collects interaction data into an MPI data structure.
Definition: PeriodicBoundaryHandler.cc:528
void addNewParticle(BaseParticle *particle)
Adds a new particle to the periodic list.
Definition: PeriodicBoundaryHandler.cc:333
void clearCommunicationLists()
Removes all ghost particles and bookkeeping for a fresh start.
Definition: PeriodicBoundaryHandler.cc:1807
PeriodicBoundaryHandler()
Default constructor, it creates an empty PeriodicBoundaryHandler.
Definition: PeriodicBoundaryHandler.cc:42
std::vector< std::vector< MPIParticleVelocity > > updateVelocityDataReceive_
Data container for velocity data that is being received from other processors.
Definition: PeriodicBoundaryHandler.h:383
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:560
std::vector< std::vector< MPIParticle > > periodicGhostParticleSend_
Data container for particles that are being send to other processors.
Definition: PeriodicBoundaryHandler.h:358
void finaliseNewParticleTransmission()
creates the ghost particles and performs some bookkeeping to keep track of them
Definition: PeriodicBoundaryHandler.cc:1586
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:109
std::string getName() const override
Returns the name of the handler, namely the string "PeriodicBoundaryHandler".
Definition: PeriodicBoundaryHandler.cc:117
void processLocalGhostParticles(std::vector< BaseParticle * > &newParticles)
Creates ghost particles of periodic particles that are located on the same processor.
Definition: PeriodicBoundaryHandler.cc:805
void findNewParticles()
Loops over all particles in the simulation to check if they need to be added to the periodic lists.
Definition: PeriodicBoundaryHandler.cc:1328
std::vector< std::vector< MPIParticle > > periodicGhostParticleReceive_
Data container for particles that are being received from other processors.
Definition: PeriodicBoundaryHandler.h:353
void cleanCommunicationList(std::vector< MpiPeriodicParticleIDBase * > &list)
Removes the nullptr's from a communication list.
Definition: PeriodicBoundaryHandler.cc:1759
void updateParticleStatus(std::set< BaseParticle * > &particlesToBeDeleted)
Updates the status of periodic particles and ghost particles.
Definition: PeriodicBoundaryHandler.cc:1036
bool checkIsReal(std::vector< int > complexity)
checks if a periodic complexity is real
Definition: PeriodicBoundaryHandler.cc:988
std::vector< int > receiveTargetList_
A list that keeps track which target processors the current processor is receiving new particles from...
Definition: PeriodicBoundaryHandler.h:320
std::vector< int > numberOfNewInteractionsSend_
Stores the number of new interactions to be send to target processor corresponding to sendTargetList_...
Definition: PeriodicBoundaryHandler.h:343
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:424
std::vector< std::vector< MPIParticleVelocity > > updateVelocityDataSend_
Data container for velocity data that is being send to other processors.
Definition: PeriodicBoundaryHandler.h:388
void setInteractionDistance(Mdouble interactionDistance)
Sets the interaction distance.
Definition: PeriodicBoundaryHandler.cc:128
void flushParticles(std::set< BaseParticle * > &particlesToBeFlushed)
Removes particles from the periodiocParticleList_ and periociGhostList_.
Definition: PeriodicBoundaryHandler.cc:1705
std::vector< std::vector< int > > periodicGhostComplexitySend_
Data container for periodic complexity that is being send to other processors.
Definition: PeriodicBoundaryHandler.h:368
std::vector< int > numberOfNewInteractionsReceive_
Stores the number of new interactions to be received from target processor corresponding to receiveTa...
Definition: PeriodicBoundaryHandler.h:348
void finalisePositionAndVelocityUpdate()
Communicates position and velocity data from periodic boundaries and updates ghost particles.
Definition: PeriodicBoundaryHandler.cc:1692
std::vector< int > sendTargetList_
A list that keeps track to which targets this processor is sending new particles to.
Definition: PeriodicBoundaryHandler.h:326
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:1271
void collectGhostParticleData()
Collects ghost particle data that needs to be be sent to other processors.
Definition: PeriodicBoundaryHandler.cc:497
Definition: Vector.h:51
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:73