MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Domain.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 
32 #ifndef Domain_H
33 #define Domain_H
34 
35 #include "BaseObject.h"
36 #include "MpiContainer.h"
37 #include "Math/Vector.h"
38 #include "ParticleHandler.h"
39 #include <vector>
40 #include <set>
41 
42 class DPMBase;
43 
44 class DomainHandler;
45 
46 class BaseParticle;
47 
48 class MPIParticle;
49 
51 
53 
54 class MPIParticleForce;
55 
63 class Domain final : public BaseObject
64 {
65 public:
69  Domain();
70 
74  explicit Domain(std::vector<unsigned> globalMeshIndex);
75 
80  Domain(const Domain& d);
81 
85  ~Domain() override;
86 
90  void constructor();
91 
96  virtual Domain* copy() const;
97 
101  void read(std::istream& is) override;
102 
106  void write(std::ostream& os) const override;
107 
111  std::string getName() const override;
112 
116  void setRange(Direction direction, Mdouble min, Mdouble max);
117 
121  void setBounds(std::vector<double> domainLeft, std::vector<double> domainRight, bool computeMiddle);
122 
126  std::vector<double> getDomainMin();
127 
131  std::vector<double> getDomainMax();
132 
136  int getRank();
137 
141  void setRank(int rank);
142 
146  void setHandler(DomainHandler* handler);
147 
151  DomainHandler* getHandler() const;
152 
156  int getGlobalIndex();
157 
161  std::vector<unsigned> getGlobalMeshIndex();
162 
166  void setGlobalMeshIndex(std::vector<unsigned> globalMeshIndex);
167 
171  void disableBoundary(unsigned localIndex);
172 
176  void disableBoundaries();
177 
181  std::vector<bool> getActiveBoundaryList();
182 
186  bool containsParticle(BaseParticle* particle, Mdouble offset = 0.0);
187 
192  bool isInGreaterDomain(BaseParticle* particle);
193 
197  bool isInInnerDomain(BaseParticle* particle);
198 
202  bool isInCommunicationZone(BaseParticle* particle);
203 
207  void createLookUpTable();
208 
212  int getLocalIndex(int i, int j, int k);
213 
217  int getLocalIndex(std::vector<int> localMeshIndex);
218 
222  BaseParticle* findParticleInList(unsigned int identification, std::vector<BaseParticle*> particleList);
223 
227  std::vector<int> findNearbyBoundaries(BaseParticle* particle, Mdouble offset = 0);
228 
232  void addParticlesToLists(BaseParticle* particle, std::vector<std::vector<BaseParticle*> >& list);
233 
237  void findNewMPIParticles(const ParticleHandler& particleHandler);
238 
242  void findNewMPIParticle(BaseParticle* particle);
243 
244  /*
245  * Checks whether a particle is in the list of new particles received by this thread
246  */
247  bool isInNewBoundaryParticleList(BaseParticle* object,int localIndex) const;
251  void findNewMPIInteractions();
252 
256  void collectBoundaryParticleData(int localIndex);
257 
261  void collectInteractionData(int localIndex);
262 
266  void processReceivedBoundaryParticleData(unsigned index, std::vector<BaseParticle*>& newParticles);
267 
271  void processSentBoundaryParticles(unsigned index);
272 
276  void processReceivedInteractionData(unsigned index, std::vector<BaseParticle*>& newParticles);
277 
278  /*
279  * Writes a list of all MPI particles on each thread to the logger.
280  */
281  void debugInformation();
282 
286  void
287  sendAndReceiveCount(MercuryMPITag tag, unsigned& countReceive, unsigned& countSend, unsigned localIndexNeighbour);
288 
293 
298 
303 
308 
312  void updateParticles(std::set<BaseParticle*>& ghostParticlesToBeDeleted);
313 
317  void updateParticlePosition(int localIndex);
318 
322  void updateParticleVelocity(int localIndex);
323 
329 
333  void finalisePositionAndVelocityUpdate(std::set<BaseParticle*>& ghostParticlesToBeDeleted);
334 
338  void prepareVelocityUpdate();
339 
343  void finaliseVelocityUpdate();
344 
358  template<typename T>
360  T* receiveData, unsigned receiveCount,
361  T* sendData, unsigned sendCount, unsigned localIndexNeighbour)
362  {
363  int globalIndexNeighbour = localIndexToGlobalIndexTable_[localIndexNeighbour];
364  int processor = localIndexToProcessorList_[localIndexNeighbour];
365  int tagReceive = globalIndexNeighbour * MAX_PROC + globalIndex_ * 10 + tag;
366  int tagSend = globalIndex_ * MAX_PROC + globalIndexNeighbour * 10 + tag;
367 
368  //Communicate the requests
369  if (receiveCount != 0)
370  {
371  MPIContainer::Instance().receive(receiveData, type, receiveCount, processor, tagReceive);
372  }
373  if (sendCount != 0)
374  {
375  MPIContainer::Instance().send(sendData, type, sendCount, processor, tagSend);
376  }
377  }
378 
382  void addNewParticles();
383 
387  void addParticle(BaseParticle* particle);
388 
392  void updateStatus(std::set<BaseParticle*>& ghostParticlesToBeDeleted);
393 
397  void updateVelocity();
398 
402  unsigned int getNumberOfMPIParticles();
403 
407  unsigned int getNumberOfTrueMPIParticles();
408 
412  void flushParticles(std::set<BaseParticle*>& toBeDeletedList);
413 
417  void flushParticlesFromList(std::vector<BaseParticle*>& list, std::set<BaseParticle*>& toBeDeletedList);
418 
422  Vec3D getMiddle() const ;
423 
428 
432  void cleanCommunicationList(std::vector<BaseParticle*>& list);
433 
434 private:
439 
443  std::vector<double> domainMin_;
444 
448  std::vector<double> domainMax_;
449 
454 
460 
464  std::vector<unsigned> globalMeshIndex_;
465 
471 
476  std::vector<int> localIndexToProcessorList_;
477 
481  std::vector<bool> activeBoundaryList_;
482 
487  std::vector<int> boundaryList_;
488 
492  std::vector<std::vector<BaseParticle*> > boundaryParticleList_;
493 
497  std::vector<std::vector<BaseParticle*> > boundaryParticleListNeighbour_;
498 
502  std::vector<std::vector<BaseParticle*> > newBoundaryParticleList_;
503 
507  std::vector<std::vector<BaseInteraction*> > newInteractionList_;
508 
512  std::vector<unsigned> numberOfParticlesSend_;
513 
517  std::vector<unsigned> numberOfParticlesReceive_;
518 
522  std::vector<unsigned> numNewInteractionsSend_;
523 
527  std::vector<unsigned> numNewInteractionsReceive_;
528 
532  std::vector<std::vector<MPIParticle> > boundaryParticleDataSend_;
533 
537  std::vector<std::vector<MPIParticle> > boundaryParticleDataReceive_;
538 
542  std::vector<std::vector<MPIParticlePosition> > updatePositionDataSend_;
543 
547  std::vector<std::vector<MPIParticlePosition> > updatePositionDataReceive_;
548 
552  std::vector<std::vector<MPIParticleVelocity> > updateVelocityDataSend_;
553 
557  std::vector<std::vector<MPIParticleVelocity> > updateVelocityDataReceive_;
558 
562  std::vector<void*> interactionDataSend_;
563 
567  std::vector<void*> interactionDataReceive_;
568 
572  int rank_;
573 };
574 
575 #endif
void prepareBoundaryDataTransmission()
Prepares the MPI transmission of particle and interaction data from particles in particleHandler.
Definition: Domain.cc:1117
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:562
std::vector< unsigned > numberOfParticlesReceive_
Counter that keeps track of the number of particles that are being received by this domain...
Definition: Domain.h:517
bool isInInnerDomain(BaseParticle *particle)
Check if the particle is in the current domain but not in the communication zone. ...
Definition: Domain.cc:430
void disableBoundary(unsigned localIndex)
Disables a boundary of the domain with a neighbouring domain.
Definition: Domain.cc:378
std::vector< bool > activeBoundaryList_
A list of flags corresponding to an inactive or active boundary.
Definition: Domain.h:481
void updateParticleVelocity(int localIndex)
Updates the velocity of particles which are flagged as MPIParticles.
Definition: Domain.cc:1412
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:130
The DPMBase header includes quite a few header files, defining all the handlers, which are essential...
Definition: DPMBase.h:72
void updateParticles(std::set< BaseParticle * > &ghostParticlesToBeDeleted)
This step updates all communication lists and particles in the communication zone.
Definition: Domain.cc:1279
void setBounds(std::vector< double > domainLeft, std::vector< double > domainRight, bool computeMiddle)
Sets the domain bounds.
Definition: Domain.cc:268
void addParticle(BaseParticle *particle)
Initialises a single particle which is added during the simulation.
Definition: Domain.cc:1581
int getGlobalIndex()
Gets the global index of the domain.
Definition: Domain.cc:346
MercuryMPIType
An enum that indicates what type of data is being send over MPI.
Definition: MpiContainer.h:65
void collectInteractionData(int localIndex)
Collects the data of an interaction that has to be communicated to other processors.
Definition: Domain.cc:901
int getRank()
Gets the rank associated with the assigned processorID.
Definition: Domain.cc:328
double Mdouble
Definition: GeneralDefine.h:34
void constructor()
contructor of a domain
Definition: Domain.cc:133
bool isInNewBoundaryParticleList(BaseParticle *object, int localIndex) const
Definition: Domain.cc:791
Data class to send a particle velocity over MPI.
Definition: MpiDataClass.h:102
std::vector< unsigned > numNewInteractionsSend_
Counter that keeps track of the number of interactions that are being send to other domains...
Definition: Domain.h:522
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:549
Vec3D middle_
Middle of the closed domain.
Definition: Domain.h:453
std::vector< double > domainMin_
Minimum domain bounds in the x,y and z direction.
Definition: Domain.h:443
std::vector< unsigned > getGlobalMeshIndex()
Gets the global mesh index of the domain.
Definition: Domain.cc:355
It is an abstract base class due to the purely virtual functions declared below. Even if the function...
Definition: BaseObject.h:50
std::vector< int > localIndexToGlobalIndexTable_
look-up table to get the global index given a local domain index
Definition: Domain.h:470
void debugInformation()
Definition: Domain.cc:1067
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
void flushParticles(std::set< BaseParticle * > &toBeDeletedList)
Particles that are going to be deleted from the simulation are flushed out of the communication bound...
Definition: Domain.cc:1669
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:213
void addNewParticles()
Initialises the MPIParticles by communicating newly found particles.
Definition: Domain.cc:1559
BaseParticle * findParticleInList(unsigned int identification, std::vector< BaseParticle * > particleList)
Searches for a particle with a specific id in a list of particles.
Definition: Domain.cc:524
std::vector< int > localIndexToProcessorList_
look-up table to get the processor of the domain given a local domain index
Definition: Domain.h:476
bool containsParticle(BaseParticle *particle, Mdouble offset=0.0)
Check to see if a given particle is within the current domain.
Definition: Domain.cc:400
Domain()
Default Domain constructor.
Definition: Domain.cc:48
void findNewMPIInteractions()
Finds interactions that have to be send over to another domain.
Definition: Domain.cc:806
void performBoundaryDataTransmission()
Collects data to be transmitted and then performs the transmission of the data.
Definition: Domain.cc:1192
std::vector< std::vector< BaseInteraction * > > newInteractionList_
Array that queues interactions that need to be transmitted.
Definition: Domain.h:507
bool isInGreaterDomain(BaseParticle *particle)
Check to see if a given particle is in the current domain or in neighbouring communication zones...
Definition: Domain.cc:420
void finaliseVelocityUpdate()
Processes particle velocity data for ghost particles.
Definition: Domain.cc:1528
std::vector< std::vector< MPIParticleVelocity > > updateVelocityDataReceive_
Container that keeps a list of MPIParticleVelocities that are being received by this domain...
Definition: Domain.h:557
void updateStatus(std::set< BaseParticle * > &ghostParticlesToBeDeleted)
Updates particles that are not in the current domain and communicates newly added particles...
Definition: Domain.cc:1604
std::vector< unsigned > globalMeshIndex_
Vector containing the global mesh indices i,j,k.
Definition: Domain.h:464
std::vector< int > boundaryList_
A list of indices of all the active boundaries.
Definition: Domain.h:487
unsigned int getNumberOfTrueMPIParticles()
Obtains the number of particles in the particleHandler that are MPIParticles, but NOT periodic partic...
Definition: Domain.cc:1650
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:567
void setRange(Direction direction, Mdouble min, Mdouble max)
Sets the domain range in a given direction.
Definition: Domain.cc:219
void updateParticlePosition(int localIndex)
Updates the position of particles which are flagged as MPIParticles.
Definition: Domain.cc:1383
void write(std::ostream &os) const override
This function does nothing.
Definition: Domain.cc:197
std::vector< std::vector< MPIParticlePosition > > updatePositionDataSend_
Container that keeps a list of MPIParticlePositions that are being send to other domains.
Definition: Domain.h:542
#define MAX_PROC
Definition: GeneralDefine.h:51
void processReceivedInteractionData(unsigned index, std::vector< BaseParticle * > &newParticles)
Processes the received interactions from newly added mpi particles.
Definition: Domain.cc:976
void cleanCommunicationLists()
Removes nullptrs from boundaryParticleList_ and boundaryParticleListNeighbour_.
Definition: Domain.cc:1713
void preparePositionAndVelocityUpdate()
Function that sends particle position and velocity data for ghost particles to other processors...
Definition: Domain.cc:1431
void finalisePositionAndVelocityUpdate(std::set< BaseParticle * > &ghostParticlesToBeDeleted)
processes position and velocity data for ghost particles
Definition: Domain.cc:1472
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:768
MercuryMPITag
An enum that facilitates the creation of unique communication tags in the parallel code...
Definition: MpiContainer.h:76
std::vector< double > getDomainMin()
Gets the minimum domain bounds.
Definition: Domain.cc:310
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:497
void cleanCommunicationList(std::vector< BaseParticle * > &list)
Removes nullptr's from a given particle list.
Definition: Domain.cc:1728
Data class to send a particle over MPI.
Definition: MpiDataClass.h:81
std::vector< std::vector< MPIParticleVelocity > > updateVelocityDataSend_
Container that keeps a list of MPIParticleVelocities that are being send to other domains...
Definition: Domain.h:552
DomainHandler * getHandler() const
Gets the domainHandler.
Definition: Domain.cc:1549
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:359
void sendAndReceiveCount(MercuryMPITag tag, unsigned &countReceive, unsigned &countSend, unsigned localIndexNeighbour)
A symmetric communication between two domains exchanging a send/recieve count.
Definition: Domain.cc:1090
std::vector< unsigned > numberOfParticlesSend_
Counter that keeps track of the number of particles that are being send to other domains.
Definition: Domain.h:512
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:918
DomainHandler * domainHandler_
Pointer to the domain's DomainHandler container.
Definition: Domain.h:438
void collectBoundaryParticleData(int localIndex)
collects the data of a particle that has to be communicated to other processors
Definition: Domain.cc:886
void read(std::istream &is) override
This function does nothing.
Definition: Domain.cc:186
std::vector< double > getDomainMax()
Gets the maximum domain bounds.
Definition: Domain.cc:319
void finaliseBoundaryDataTransmission()
This function processes the transmitted data.
Definition: Domain.cc:1233
void setRank(int rank)
Sets the rank associated with the assigned processorID.
Definition: Domain.cc:301
void findNewMPIParticle(BaseParticle *particle)
Function that check if a given particle should be added to the communication lists.
Definition: Domain.cc:782
Container to store all BaseParticle.
~Domain() override
Destructor, destroys the domain.
Definition: Domain.cc:121
Data class to send a particle position over MPI.
Definition: MpiDataClass.h:89
std::vector< std::vector< BaseParticle * > > newBoundaryParticleList_
Array that queues particles that need to be transmitted.
Definition: Domain.h:502
The simulation can be subdivided into Domain's used in parallel code.
Definition: Domain.h:63
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:167
Vec3D getMiddle() const
Gives the middle of the domain.
Definition: Domain.cc:1704
void createLookUpTable()
Create a look up table between local index system to global index system.
Definition: Domain.cc:451
bool isInCommunicationZone(BaseParticle *particle)
Check if the particle is in the communication zone of the current domain.
Definition: Domain.cc:441
void disableBoundaries()
disables all domain boundaries that have no neighbour
Definition: Domain.cc:579
Container to store all Domain.
Definition: DomainHandler.h:46
void updateVelocity()
Updates MPI particle velocity at the half-time step.
Definition: Domain.cc:1619
std::string getName() const override
Returns the name of the object.
Definition: Domain.cc:207
Direction
An enum that indicates the direction in Cartesian coordinates.
Definition: GeneralDefine.h:76
std::vector< std::vector< MPIParticlePosition > > updatePositionDataReceive_
Container that keeps a list of MPIParticlePositions that are being received by this domain...
Definition: Domain.h:547
int globalIndex_
Global index of the domain in the mesh.
Definition: Domain.h:459
int rank_
Rank of the domain which identifies to which processor it belongs.
Definition: Domain.h:572
std::vector< double > domainMax_
Maximum domain bounds in the x,y and z direction.
Definition: Domain.h:448
std::vector< std::vector< MPIParticle > > boundaryParticleDataReceive_
Container that keeps a list of MPIParticles that are being received by this domain.
Definition: Domain.h:537
void prepareVelocityUpdate()
Function that sends particle velocity data for ghost particles.
Definition: Domain.cc:1500
virtual Domain * copy() const
Function that creates a copy of this current domain, using the copy constructor.
Definition: Domain.cc:175
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:1679
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:492
void processSentBoundaryParticles(unsigned index)
Bookkeep the newly send particles.
Definition: Domain.cc:954
Definition: Vector.h:49
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
Data class to send a particle force over MPI.
Definition: MpiDataClass.h:113
std::vector< unsigned > numNewInteractionsReceive_
Counter that keeps track of the number of interactions that are being received by this domain...
Definition: Domain.h:527
void setHandler(DomainHandler *handler)
Sets the domainHandler.
Definition: Domain.cc:337
void addParticlesToLists(BaseParticle *particle, std::vector< std::vector< BaseParticle * > > &list)
Function that adds the particles to the approriate boundary list.
Definition: Domain.cc:683
std::vector< bool > getActiveBoundaryList()
Returns a list of boundaries that are active in mpi communication.
Definition: Domain.cc:387
unsigned int getNumberOfMPIParticles()
Obtains the number of particles in the particleHandler that are MPIParticles.
Definition: Domain.cc:1635
void setGlobalMeshIndex(std::vector< unsigned > globalMeshIndex)
Sets the global mesh index of theh domain.
Definition: Domain.cc:365
std::vector< std::vector< MPIParticle > > boundaryParticleDataSend_
Container that keeps a list of MPIParticles that are being send to other domains. ...
Definition: Domain.h:532