MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PeriodicBoundaryHandler.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2020, 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< int > numberOfNewInteractionsSend_
Stores the number of new interactions to be send to target processor corresponding to sendTargetList_...
void performNewParticleTransmission()
Collects and sends the ghost particle data.
void addNewParticle(BaseParticle *particle)
Adds a new particle to the periodic list.
std::vector< MpiPeriodicGhostParticleID * > PeriodicGhostList
std::vector< std::vector< int > > periodicGhostComplexityReceive_
Data container for periodic complexity that is being received from other processors.
void finalisePositionAndVelocityUpdate()
Communicates position and velocity data from periodic boundaries and updates ghost particles...
bool checkChanged(std::vector< int > previousComplexity, std::vector< int > complexity)
checks of two periodic complexities differ
std::vector< MpiPeriodicParticleID * > PeriodicList
void updateParticleStatus(std::set< BaseParticle * > &particlesToBeDeleted)
Updates the status of periodic particles and ghost particles.
void communicateTargetDomains()
Creats a list of send and receive targets for periodic/ghost particles.
double Mdouble
Definition: GeneralDefine.h:34
void processLocalGhostParticles(std::vector< BaseParticle * > &newParticles)
Creates ghost particles of periodic particles that are located on the same processor.
void finaliseNewParticleTransmission()
creates the ghost particles and performs some bookkeeping to keep track of them
std::vector< std::vector< int > > periodicGhostComplexitySend_
Data container for periodic complexity that is being send to other processors.
std::vector< std::vector< MPIParticleVelocity > > updateVelocityDataSend_
Data container for velocity data that is being send to other processors.
void updateMaserParticle(BaseParticle *particle)
Updates the maser flag of particles leaving the maser.
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...
Mdouble interactionDistance_
The interaction distance between a position and the boundary for which particles start to participate...
std::vector< PeriodicList > newPeriodicParticleList_
Mdouble getNumberOfTruePeriodicGhostParticles()
Returns the number of particles that are flagged as periodicGhostParticles, but not as MPIParticles...
void flushParticles(std::set< BaseParticle * > &particlesToBeFlushed)
Removes particles from the periodiocParticleList_ and periociGhostList_.
void findNewParticle(BaseParticle *particle)
Checks if a particle is in the periodic domain, but are not flagged as being in the periodic domain...
bool checkIsReal(std::vector< int > complexity)
checks if a periodic complexity is real
std::vector< int > numberOfNewInteractionsReceive_
Stores the number of new interactions to be received from target processor corresponding to receiveTa...
int findTargetProcessor(const std::vector< int > &complexity)
For a given complexity this function returns the target processor.
void findNewParticles()
Loops over all particles in the simulation to check if they need to be added to the periodic lists...
std::vector< std::vector< MPIParticle > > periodicGhostParticleSend_
Data container for particles that are being send to other processors.
std::vector< std::vector< MPIParticlePosition > > updatePositionDataReceive_
Data container for position data that is being received from other processors.
void collectGhostParticleData()
Collects ghost particle data that needs to be be sent to other processors.
void performActionsBeforeAddingParticles()
Actions that boundaries perform before adding new periodic/ghost particles.
void initialise()
Initialises the communication list vectors as they can not be determined on compile time...
std::vector< void * > interactionDataReceive_
Stores the interaction data that is going to be received.
void flushPeriodicParticles(std::set< BaseParticle * > &particlesToBeDeleted)
Flushes periodioc particles that need to be deleted from the periodic lists.
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.
void setMPIFlags(BaseParticle *particle)
Sets the MPIParticle and isMPIParticle flags of a given particle.
std::vector< std::vector< BaseInteraction * > > newInteractionList_
Container to store pointers to all BasePeriodicBoundary objects.
std::vector< int > numberOfNewPeriodicGhostParticlesReceive_
A vector that stores how many new ghost particles will be received from other processors.
~PeriodicBoundaryHandler() override
Destructor, it destructs the PeriodicBoundaryHandler and all BasePeriodicBoundary it contains...
void processLocalInteractionData(std::vector< BaseParticle * > &newParticles)
Process the interaction data for local ghosts.
void communicateNumberOfNewParticlesAndInteractions()
Communicate the number of new particles and interactions to target processors.
void findNewInteractions()
Finds interactions that accompany future ghost particles.
void processPeriodicParticles()
Creates a periodioc particle ID for book keeping and moves the ID to the correct list.
PeriodicBoundaryHandler operator=(const PeriodicBoundaryHandler &rhs)
Assignment operator, copies only the vector of BasePeriodicBoundary and sets the other variables to 0...
void updateStatus(std::set< BaseParticle * > &ghostParticlesToBeDeleted)
Updates the positions/velocity of ghost particles and accordingly the status of these particles...
void addNewParticles()
Adds new particles to the periodic particle lists.
unsigned int getNumberOfPeriodicGhostParticles()
Returns the number of particles that are flagged is periodicGhostParticle.
void shiftParticle(BaseParticle *particle)
Shifts the position of the particle based on its current periodic complexity.
std::string getName() const override
Returns the name of the handler, namely the string "PeriodicBoundaryHandler".
void collectInteractionData()
Collects interaction data into an MPI data structure.
std::vector< PeriodicGhostList > periodicGhostList_
A vector the size of the number of processors, each entry containing a vector of ghost periodioc part...
std::vector< PeriodicList > periodicParticleList_
A vector the size of the number of processors, each entry containing a vector of periodic particle ID...
std::vector< std::vector< MPIParticlePosition > > updatePositionDataSend_
Data container for position data that is being send to other processors.
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. ...
Container to store the pointers to all objects that one creates in a simulation.
Definition: BaseHandler.h:50
void processReceivedInteractionData(int targetIndex, std::vector< BaseParticle * > &newParticles)
Process the received interaction data.
bool checkIfAddNewParticle(BaseParticle *particle)
std::vector< int > numberOfNewPeriodicGhostParticlesSend_
A vector that stores how many particles are going to be send to other processors. ...
std::vector< void * > interactionDataSend_
Stores the interaction data that is going to be send.
PeriodicBoundaryHandler()
Default constructor, it creates an empty PeriodicBoundaryHandler.
void prepareNewParticleTransmission()
Initial preparation work for sending ghost particles.
void updateParticles()
Updates position/velocity and periodic complexity of ghost particles.
Mdouble getInteractionDistance()
Returns the interaction distance.
void readAndAddObject(std::istream &is) override
Pure virtual function needs implementation, but it does nothing for the periodicBoudnaryHandler.
std::vector< int > computePeriodicComplexity(Vec3D position)
Computes the periodic complexity based on a given position.
std::vector< std::vector< MPIParticleVelocity > > updateVelocityDataReceive_
Data container for velocity data that is being received from other processors.
Definition: Vector.h:49
void addObject(BasePeriodicBoundary *P) override
Adds a BasePeriodicBoundary to the PeriodicBoundaryHandler.
void preparePositionAndVelocityUpdate()
Collects the position and velocity data from periodic boundaries.
void cleanCommunicationList(std::vector< MpiPeriodicParticleIDBase * > &list)
Removes the nullptr's from a communication list.
void processReceivedGhostParticleData(int targetIndex, std::vector< BaseParticle * > &newParticles)
Processes the received ghost data, creates a ghost particle and does some book keeping.
std::vector< std::vector< MPIParticle > > periodicGhostParticleReceive_
Data container for particles that are being received from other processors.
void clearCommunicationLists()
Removes all ghost particles and bookkeeping for a fresh start.
std::vector< int > receiveTargetList_
A list that keeps track which target processors the current processor is receiving new particles from...
std::vector< int > sendTargetList_
A list that keeps track to which targets this processor is sending new particles to.
void setInteractionDistance(Mdouble interactionDistance)
Sets the interaction distance.