MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MpiDataClass.cc
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 #include "MpiDataClass.h"
27 #include "DPMBase.h"
31 #include "Logger.h"
32 
52 {
53 
54  //Set important quantities
55  p->setId(id);
56  p->setRadius(radius);
62 
63  //Set HGrid values
64  p->setHGridNextObject(nullptr);
65  p->setHGridPrevObject(nullptr);
66  p->setHGridX(99999);
67  p->setHGridY(99999);
68  p->setHGridZ(99999);
70 
71  //This is not a periodic particle
72  p->setPeriodicFromParticle(nullptr);
73  p->setInPeriodicDomain(false);
74 
75  //Fix maser if it is maser
77 
78  //Fixed particles need to be fixed again
79  if (isFixed)
80  {
81  p->fixParticle();
82  }
83 }
84 
86 {
88  p->setAxes(axes);
90 }
91 
93 {
95  static_cast<LiquidFilmParticle*>(p)->setLiquidVolume(liquidVolume);
96 }
97 
106 {
107  //Set the species of the particle, but before we can do that we have to set the handler
108  p->setHandler(particleHandler);
109  //p->setIndSpecies(bP->indSpecies);
111  p->setSpecies(species);
113 }
114 
125 {
126  MPIParticle bP;
128  return bP;
129 }
130 
132  id = p->getId();
133  indSpecies = p->getIndSpecies();
134  radius = p->getRadius();
135  position = p->getPosition();
137  velocity = p->getVelocity();
139  HGridLevel = p->getHGridLevel();
141  isMaser = p->isMaserParticle();
142  isFixed = p->isFixed();
143 }
144 
147  axes = p->getAxes();
148  epsilon1 = p->getExponentEps1();
149  epsilon2 = p->getExponentEps2();
150 }
151 
154  liquidVolume = static_cast<LiquidFilmParticle*>(p)->getLiquidVolume();
155 }
156 
158  return new SphericalParticle;
159 }
160 
162  return new SuperQuadricParticle;
163 }
164 
166  return new LiquidFilmParticle;
167 }
168 
175 {
176  MPIParticlePosition particlePosition;
177  particlePosition.id = particle->getId();
178  particlePosition.position = particle->getPosition();
179  particlePosition.orientation = particle->getOrientation();
180  if (std::is_base_of<MPILiquidFilmParticle,MPIParticle>())
181  particlePosition.liquidVolume = static_cast<LiquidFilmParticle*>(particle)->getLiquidVolume();
182  return particlePosition;
183 }
184 
191 {
192  MPIParticleVelocity particleVelocity;
193  particleVelocity.velocity = particle->getVelocity();
194  particleVelocity.angularVelocity = particle->getAngularVelocity();
195 
196  return particleVelocity;
197 }
198 
200 {
201 #ifdef MERCURY_USE_MPI
202  //Sum up over all domains
203  Vec3D valGlobal = {0.0,0.0,0.0};
204  MPIContainer& communicator = MPIContainer::Instance();
205  communicator.allReduce(val.X, valGlobal.X, MPI_SUM);
206  communicator.allReduce(val.Y, valGlobal.Y, MPI_SUM);
207  communicator.allReduce(val.Z, valGlobal.Z, MPI_SUM);
208  return valGlobal;
209 #else
210  return val;
211 #endif
212 }
213 
214 double getMPISum(double val)
215 {
216 #ifdef MERCURY_USE_MPI
217  //Sum up over all domains
218  double valGlobal = 0.0;
219  MPIContainer& communicator = MPIContainer::Instance();
220  communicator.allReduce(val, valGlobal, MPI_SUM);
221  return valGlobal;
222 #else
223  return val;
224 #endif
225 }
void copyDataFromMPIParticleToParticle(BaseParticle *p)
Copies data from a BaseParticle to an MPIParticle class and returns this.
Definition: MpiDataClass.cc:51
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:125
void copyDataFromParticleToMPIParticle(BaseParticle *p)
unsigned int getId() const
Returns the unique identifier of any particular object.
Definition: BaseObject.h:125
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:130
Mdouble X
the vector components
Definition: Vector.h:65
static BaseParticle * newParticle()
unsigned int id
Definition: MpiDataClass.h:92
A basic particle.
void setVelocity(const Vec3D &velocity)
set the velocity of the BaseInteractable.
bool isMaserParticle() const
Indicates if this particle belongs to the maser boundary.
void setHGridLevel(const unsigned int level)
Sets the particle's HGrid level.
Definition: BaseParticle.h:469
virtual void setRadius(Mdouble radius)
Sets the particle's radius_ (and adjusts the mass_ accordingly, based on the particle's species) ...
Data class to send a particle velocity over MPI.
Definition: MpiDataClass.h:102
unsigned int indSpecies
Definition: MpiDataClass.h:43
static BaseParticle * newParticle()
void setHandler(ParticleHandler *handler)
Sets the pointer to the particle's ParticleHandler.
virtual void setAxes(const Vec3D &axes)
Only ustilised in case of superquadric particles.
Definition: BaseParticle.h:524
void setHGridY(const int y)
Sets the particle's HGrid cell Y-coordinate.
Definition: BaseParticle.h:454
void setCommunicationComplexity(unsigned complexity)
Set the communication complexity of the particle.
virtual Mdouble getExponentEps1() const
Only ustilised in case of superquadric particles. Had to create a virtual function to allow function ...
virtual Vec3D getAxes() const
Only ustilised in case of superquadric particles. Had to create a virtual function to allow function ...
void setHGridNextObject(BaseParticle *p)
Sets the pointer to the next object in the particle's HGrid cell & level.
Definition: BaseParticle.h:477
void setPeriodicFromParticle(BaseParticle *p)
Assigns the pointer to the 'original' particle this one's a periodic copy of (used in periodic bounda...
Definition: BaseParticle.h:438
Mdouble epsilon1
Definition: MpiDataClass.h:62
virtual Mdouble getExponentEps2() const
Only ustilised in case of superquadric particles. Had to create a virtual function to allow function ...
virtual const Vec3D & getAngularVelocity() const
Returns the angular velocity of this interactable.
void setSpecies(const ParticleSpecies *species)
void setHGridX(const int x)
Sets the particle's HGrid cell X-coordinate.
Definition: BaseParticle.h:446
ParticleHandler * getHandler() const
Returns pointer to the particle's ParticleHandler.
Quaternion orientation
Definition: MpiDataClass.h:94
virtual void setExponents(const Mdouble &eps1, const Mdouble &eps2)
Only ustilised in case of superquadric particles.
Definition: BaseParticle.h:529
void copyDataFromMPIParticleToParticle(BaseParticle *p)
Definition: MpiDataClass.cc:92
void copyDataFromMPIParticleToParticle(MPIParticle *bP, BaseParticle *p, ParticleHandler *particleHandler)
Copies data from an MPIParticle class to a BaseParticle and sets the particleHandler and species...
static BaseParticle * newParticle()
Quaternion orientation
Definition: MpiDataClass.h:49
MPIParticle copyDataFromParticleToMPIParticle(BaseParticle *p)
Copies data from a SuperQuadricParticle to an MPIParticle class and returns this. ...
void copyDataFromParticleToMPIParticle(BaseParticle *p)
T * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:613
Data class to send a particle over MPI.
Definition: MpiDataClass.h:81
void setHGridZ(const int z)
Sets the particle's HGrid cell Z-coordinate.
Definition: BaseParticle.h:462
Vec3D getMPISum(Vec3D &val)
Sums the values over all processors using MPI_reduce.
Mdouble getRadius() const
Returns the particle's radius.
Definition: BaseParticle.h:345
bool isFixed() const override
Is fixed Particle function. It returns whether a Particle is fixed or not, by checking its inverse Ma...
Definition: BaseParticle.h:93
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. LinearViscoelasticSpecies, etc.
Definition: DPMBase.h:1319
Container to store all BaseParticle.
Mdouble Y
Definition: Vector.h:65
MPIParticlePosition copyPositionFrom(BaseParticle *particle)
Copies the position from a particle to an MPIParticlePosition class.
unsigned communicationComplexity
Definition: MpiDataClass.h:50
Data class to send a particle position over MPI.
Definition: MpiDataClass.h:89
void setMaserParticle(bool flag)
Flags the status of the particle if it belongs to the maser boundary or not.
void setPosition(const Vec3D &position)
Sets the position of this BaseInteractable.
Mdouble epsilon2
Definition: MpiDataClass.h:63
unsigned getCommunicationComplexity()
Obtains the communication complexity of the particle.
void setHGridPrevObject(BaseParticle *p)
Sets the pointer to the previous object in the particle's HGrid cell & level.
Definition: BaseParticle.h:485
void setOrientation(const Quaternion &orientation)
Sets the orientation of this BaseInteractable.
unsigned int HGridLevel
Definition: MpiDataClass.h:44
unsigned int getIndSpecies() const
Returns the index of the species associated with the interactable object.
virtual const Vec3D & getVelocity() const
Returns the velocity of this interactable.
Definition: Vector.h:49
MPIParticleVelocity copyVelocityFrom(BaseParticle *particle)
Copies the velocity from a particle to an MPIParticleVelocity class.
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:725
unsigned int getHGridLevel() const
Returns particle's HGrid level.
Definition: BaseParticle.h:234
void setInPeriodicDomain(bool flag)
Flags the status of the particle wether it is in the periodic communication zone or not...
const Quaternion & getOrientation() const
Returns the orientation of this BaseInteractable.
Mdouble Z
Definition: Vector.h:65
void setAngularVelocity(const Vec3D &angularVelocity)
set the angular velocity of the BaseInteractble.
void copyDataFromParticleToMPIParticle(BaseParticle *p)
void copyDataFromMPIParticleToParticle(BaseParticle *p)
Definition: MpiDataClass.cc:85
void setId(unsigned long id)
Assigns a unique identifier to each object in the handler (container) which remains constant even aft...
Definition: BaseObject.cc:72
void fixParticle()
Fix Particle function. It fixes a Particle by setting its inverse mass and inertia and velocities to ...