MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BaseParticle.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 #ifndef BASEPARTICLE_H
27 #define BASEPARTICLE_H
28 
29 #include <vector>
30 #include "Math/Vector.h"
31 #include "BaseInteractable.h"
32 #include "HGridCell.h"
34 
35 class ParticleHandler;
36 
37 class SpeciesHandler;
38 
39 class HGrid;
40 
41 class BaseInteraction;
42 
43 #ifdef CONTACT_LIST_HGRID
44 class PossibleContact;
45 #endif
46 
54 {
55 public:
59  BaseParticle();
60 
64  BaseParticle(const BaseParticle& p);
65 
66  explicit BaseParticle(const ParticleSpecies* s);
67 
71  ~BaseParticle() override;
72 
76  virtual BaseParticle* copy() const = 0;
77 
81  virtual Mdouble getVolume() const;
82 
86  void fixParticle();
87 
93  bool isFixed() const override
94  { return (invMass_ == 0.0); }
95 
99  bool isMPIParticle() const;
100 
104  void setMPIParticle(bool flag);
105 
109  bool isInMPIDomain();
110 
114  void setInMPIDomain(bool flag);
115 
119  bool isInPeriodicDomain() const;
120 
124  void setInPeriodicDomain(bool flag);
125 
129  bool isPeriodicGhostParticle() const;
130 
134  void setPeriodicGhostParticle(bool flag);
135 
139  bool isMaserParticle() const;
140 
144  void setMaserParticle(bool flag);
145 
149  void setCommunicationComplexity(unsigned complexity);
150 
154  unsigned getCommunicationComplexity();
155 
159  void setPeriodicComplexity(std::vector<int> complexity);
160 
164  void setPeriodicComplexity(int index, int value);
165 
169  const std::vector<int>& getPeriodicComplexity();
170 
174  void setPreviousPeriodicComplexity(std::vector<int> complexity);
175 
179  const std::vector<int>& getPreviousPeriodicComplexity() const;
180 
184  int getPeriodicComplexity(int index);
185 
186  //void setCurrentPeriodicPosition(Vec3D position);
187 
188  //Vec3D getCurrentPeriodicPosition();
189 
193  void unfix();
194 
198  void read(std::istream& is) override;
199 
204  virtual void oldRead(std::istream& is);
205 
209  void write(std::ostream& os) const override;
210 
214  std::string getName() const override;
215 
219  virtual void setInfo(Mdouble info);
220 
224  virtual Mdouble getInfo() const;
225 
229  void printHGrid(std::ostream& os) const;
230 
234  unsigned int getHGridLevel() const
235  { return hGridCell.getHGridLevel(); }
236 
243  { return hGridNextObject_; }
244 
251  { return hGridPrevObject_; }
252 
253 #ifdef CONTACT_LIST_HGRID
254 
258  PossibleContact* getFirstPossibleContact() const;
259 #endif
260 
265  int getHGridX() const
266  { return hGridCell.getHGridX(); }
267 
272  int getHGridY() const
273  { return hGridCell.getHGridY(); }
274 
279  int getHGridZ() const
280  { return hGridCell.getHGridZ(); }
281 
287  { return invInertia_; }
288 
293  Mdouble getInvMass() const override
294  { return invMass_; }
295 
296  Mdouble getCurvature(const Vec3D& labFixedCoordinates) const override
297  { return 1.0/radius_; }
298 
303  Mdouble getKineticEnergy() const;
304 
310 
317 
322  Mdouble getMass() const
323  { return 1.0 / invMass_; }
324 
326  { return getVelocity() / invMass_; }
327 
329  { return invInertia_.inverse(); }
330 
331  Vec3D getAngularMomentum() const;
332 
339  { return periodicFromParticle_; }
340 
346  { return radius_; }
347 
360  return getRadius() + getSpecies()->getMaxInteractionDistance() * 0.5;
361  }
362 
367  {
368  //const auto mixedSpecies = getSpecies()->getHandler()->getMixedObject(getSpecies(),particle->getSpecies());
369  //return mixedSpecies->getInteractionDistance();
371  }
372 
377  return getRadius() + particle->getRadius() + getInteractionDistance((const BaseInteractable*)particle);
378  }
379 
384  return getRadius() + getInteractionDistance((const BaseInteractable*)wall);
385  }
386 
392  const Vec3D& getDisplacement() const
393  { return displacement_; }
394 
400  const Vec3D& getPreviousPosition() const
401  { return previousPosition_; }
402 
408  const Vec3D getDisplacement2(Mdouble xmin, Mdouble xmax, Mdouble ymin, Mdouble ymax, Mdouble zmin, Mdouble zmax,
409  Mdouble t) const;
410 
414  virtual void setInertia();
415 
419  void setInertia(MatrixSymmetric3D inertia);
420 
424  void setInverseInertia(MatrixSymmetric3D inverseInertia);
425 
430  void setInfiniteInertia();
431 
439  { periodicFromParticle_ = p; };
440 
446  void setHGridX(const int x)
447  { hGridCell.setHGridX(x); }
448 
454  void setHGridY(const int y)
455  { hGridCell.setHGridY(y); }
456 
462  void setHGridZ(const int z)
463  { hGridCell.setHGridZ(z); }
464 
469  void setHGridLevel(const unsigned int level)
470  { hGridCell.setHGridLevel(level); }
471 
478  { hGridNextObject_ = p; }
479 
486  { hGridPrevObject_ = p; }
487 
488 #ifdef CONTACT_LIST_HGRID
489 
492  void setFirstPossibleContact(PossibleContact* PC);
493 #endif
494 
499  virtual void setRadius(Mdouble radius);
500 
501  /*
502  * The below 6 functions had to be declared virtual here in order to allow access of these functions in ParticleHandler class in the function writeVTK.
503  */
504 
508  virtual Vec3D getAxes() const;
509 
513  virtual Mdouble getExponentEps1() const;
514 
518  virtual Mdouble getExponentEps2() const;
519 
520 
524  virtual void setAxes(const Vec3D& axes){ }
525 
529  virtual void setExponents(const Mdouble& eps1, const Mdouble& eps2){}
530 
531  //
538  void setMass(Mdouble mass);
539 
545  void setMassForP3Statistics(Mdouble mass);
546 
551  void setDisplacement(const Vec3D& disp);
552 
556  void setPreviousPosition(const Vec3D& pos);
557 
561  void movePrevious(const Vec3D& posMove);
562 
566  void accelerate(const Vec3D& vel);
567 
571  void angularAccelerate(const Vec3D& angVel);
572 
576  void addDisplacement(const Vec3D& addDisp);
577 
581  void setHandler(ParticleHandler* handler);
582 
586  ParticleHandler* getHandler() const;
587 
592  BaseInteraction* getInteractionWith(BaseParticle* P, unsigned timeStamp, InteractionHandler* interactionHandler) override;
593 
597  virtual bool isInContactWith(const BaseParticle* P) const;
598 
604  void integrateBeforeForceComputation(double time, double timeStep);
605 
610  void integrateAfterForceComputation(double time, double timeStep);
611 
615  unsigned int getParticleDimensions() const;
616 
622  void setIndSpecies(unsigned int indSpecies) override;
623 
628  void setSpecies(const ParticleSpecies* species);
630 
631  virtual unsigned getNumberOfFieldsVTK() const;
632 
633  virtual std::string getTypeVTK(unsigned i) const;
634 
635  virtual std::string getNameVTK(unsigned i) const;
636 
637  virtual std::vector<Mdouble> getFieldVTK(unsigned i) const;
638 
639  virtual void actionsAfterTimeStep()
640  {};
641 
642  virtual bool isSphericalParticle() const {return false;}
643 
644  //const HGridCell& getHGridCell() const;
645  const HGridCell& getHGridCell() const
646  { return hGridCell; }
647 
648  virtual void computeMass(const ParticleSpecies& s);
649 
650 protected:
651 
655 
656 
657 private:
658 
663 
664 #ifdef CONTACT_LIST_HGRID
665 
668  PossibleContact* firstPossibleContact;
669 #endif
670 
674 
677 
680 
681  //MPI particle attributes
684  unsigned communicationComplexity_; //Determins if the particle in the corner of a domain, rib, side or not at all
685 
686  //Periodic boundary particle attributes
689  std::vector<int> previousPeriodicComplexity_;
690  std::vector<int> periodicComplexity_;
692 
695 
700  friend void ParticleSpecies::computeMass(BaseParticle*) const;
701 
702  Mdouble info_; // by default, the species ID (if a species is set)
703 };
704 
705 #endif
Mdouble getKineticEnergy() const
Calculates the particle's translational kinetic energy.
Container to store all ParticleSpecies.
const HGridCell & getHGridCell() const
Definition: BaseParticle.h:645
void read(std::istream &is) override
Particle read function, which accepts an std::istream as input.
void addDisplacement(const Vec3D &addDisp)
Adds a vector to the particle's displacement_.
bool isInPeriodicDomain() const
Indicates if the particle is in the periodic boundary communication zone.
MatrixSymmetric3D getInvInertia() const
Returns the inverse of the particle's inertia tensor.
Definition: BaseParticle.h:286
MERCURY_DEPRECATED void setIndSpecies(unsigned int indSpecies) override
void setPreviousPeriodicComplexity(std::vector< int > complexity)
Set the previous periodic communication complexity of the paritcle.
Mdouble getInteractionDistance(const BaseInteractable *i) const
Returns the interactionDistance_ of the mixed species of this particle and the particle or wall i...
Definition: BaseParticle.h:366
virtual void setInertia()
Mdouble getRotationalEnergy() const
Calculates the particle's rotational kinetic energy.
bool isMaserParticle() const
Indicates if this particle belongs to the maser boundary.
virtual bool isSphericalParticle() const
Definition: BaseParticle.h:642
void setInMPIDomain(bool flag)
Flags the status of the particle if wether it is in the communication zone or not.
virtual Mdouble getVolume() const
Get Particle volume function, which required a reference to the Species vector. It returns the volume...
void setInfiniteInertia()
Sets the particle's inertia_ to 'infinite' (1e20) and its invInertia_ to 0.
void setHGridLevel(const unsigned int level)
Sets the particle's HGrid level.
Definition: BaseParticle.h:469
int getHGridX() const
Definition: HGridCell.h:56
virtual bool isInContactWith(const BaseParticle *P) const
Get whether or not this particle is in contact with the given particle.
Vec3D getMomentum() const
Definition: BaseParticle.h:325
Vec3D getAngularMomentum() const
double Mdouble
Definition: GeneralDefine.h:34
void setDisplacement(const Vec3D &disp)
Sets the particle's displacement (= difference between current position and that of the previous time...
const ParticleSpecies * getSpecies() const
Returns a pointer to the species of this BaseInteractable.
virtual void setRadius(Mdouble radius)
Sets the particle's radius_ (and adjusts the mass_ accordingly, based on the particle's species) ...
Mdouble getMaxInteractionRadius() const
Returns the particle's interaction radius, which might be different from radius_ (e.g., when dealing with wet particles)
Definition: BaseParticle.h:359
bool isInMPIDomain_
returns true if the particle acts as an MPI particle instead of a real particle
Definition: BaseParticle.h:683
int getHGridY() const
Definition: HGridCell.h:66
Mdouble info_
Definition: BaseParticle.h:702
const std::vector< int > & getPreviousPeriodicComplexity() const
Sets the previous periodic communication complexity of the particle.
BaseInteraction * getInteractionWith(BaseParticle *P, unsigned timeStamp, InteractionHandler *interactionHandler) override
Checks if particle is in interaction with given particle P, and if so, returns vector of pointer to t...
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
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.
ParticleHandler * handler_
Inverse Particle inverse inertia (for computation optimization)
Definition: BaseParticle.h:662
virtual Mdouble getExponentEps1() const
Only ustilised in case of superquadric particles. Had to create a virtual function to allow function ...
Mdouble invMass_
Particle radius_.
Definition: BaseParticle.h:653
bool isPeriodicGhostParticle_
bool that indicates if a particle is in the periodic domain of any boundary
Definition: BaseParticle.h:688
Mdouble getSumOfInteractionRadii(const BaseParticle *particle) const
returns the sum of the radii plus the interactionDistance
Definition: BaseParticle.h:376
virtual Vec3D getAxes() const
Only ustilised in case of superquadric particles. Had to create a virtual function to allow function ...
void setInverseInertia(MatrixSymmetric3D inverseInertia)
Sets the particle's inertia_ (and adjusts invInertia_ accordingly)
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
void computeMass(BaseParticle *p) const
Compute Particle mass function, which required a reference to the Species vector. It computes the Par...
BaseParticle * getPeriodicFromParticle() const
Returns the 'original' particle this one's a periodic copy of.
Definition: BaseParticle.h:338
void unfix()
Unfix Particle function, which required a reference to the Species vector. It unfixes a Particle by c...
MatrixSymmetric3D invInertia_
Inverse Particle mass (for computation optimization)
Definition: BaseParticle.h:654
virtual Mdouble getExponentEps2() const
Only ustilised in case of superquadric particles. Had to create a virtual function to allow function ...
void setSpecies(const ParticleSpecies *species)
int getHGridY() const
Returns particle's HGrid cell Y-coordinate.
Definition: BaseParticle.h:272
virtual BaseParticle * copy() const =0
Particle copy method. It calls to copy constructor of this Particle, useful for polymorfism.
void setHGridX(const int x)
Sets the particle's HGrid cell X-coordinate.
Definition: BaseParticle.h:446
MERCURY_DEPRECATED void setMass(Mdouble mass)
Sets the particle's mass.
ParticleHandler * getHandler() const
Returns pointer to the particle's ParticleHandler.
std::string getName() const override
Returns the name of the object.
virtual void computeMass(const ParticleSpecies &s)
Computes the particle's (inverse) mass and inertia.
void accelerate(const Vec3D &vel)
Increases the particle's velocity_ by the given vector.
Mdouble getMaxInteractionDistance() const
returns the largest separation distance at which adhesive short-range forces can occur.
Mdouble getInvMass() const override
Returns the inverse of the particle's mass.
Definition: BaseParticle.h:293
Stores information about interactions between two interactable objects; often particles but could be ...
#define MERCURY_DEPRECATED
Definition: GeneralDefine.h:37
virtual void setExponents(const Mdouble &eps1, const Mdouble &eps2)
Only ustilised in case of superquadric particles.
Definition: BaseParticle.h:529
const BaseSpecies * getMixedSpecies(const ParticleSpecies *s) const
void printHGrid(std::ostream &os) const
Adds particle's HGrid level and cell coordinates to an ostream.
virtual void setInfo(Mdouble info)
Sets some user-defined information about this object (by default, species ID).
void integrateBeforeForceComputation(double time, double timeStep)
First step of Velocity Verlet integration.
void setMassForP3Statistics(Mdouble mass)
Sets the particle's mass This function should not be used, but is necessary to extend the CG toolbox ...
Mdouble getWallInteractionRadius(const BaseWall *wall) const
returns the radius plus the interactionDistance
Definition: BaseParticle.h:383
Vec3D displacement_
Indicates if this particle belongs to the maser boundary or is released into the wide open world...
Definition: BaseParticle.h:693
HGridCell hGridCell
All hGrid-information: the cell (x,y,z,level), and the previous and next particle in this cell compar...
Definition: BaseParticle.h:673
unsigned communicationComplexity_
returns true if it flagged as being in MPI domain
Definition: BaseParticle.h:684
bool isInMPIDomain()
Indicates if the particle is in the communication zone of the mpi domain.
Mdouble getMass() const
Returns the particle's mass.
Definition: BaseParticle.h:322
void setPreviousPosition(const Vec3D &pos)
Sets the particle's position in the previous time step.
In the HGrid class, here all information about the HGrid is stored.
Definition: HGrid.h:42
bool isInPeriodicDomain_
Definition: BaseParticle.h:687
int getHGridZ() const
Returns particle's HGrid cell Z-coordinate.
Definition: BaseParticle.h:279
void write(std::ostream &os) const override
Particle print function, which accepts an std::ostream as input.
Container to store Interaction objects.
~BaseParticle() override
Particle destructor, needs to be implemented and checked if it removes tangential spring information...
BaseParticle * hGridPrevObject_
Pointer to the next Particle in the same HGrid cell.
Definition: BaseParticle.h:676
void setHGridZ(const int z)
Sets the particle's HGrid cell Z-coordinate.
Definition: BaseParticle.h:462
void setHGridZ(int HGridZ)
Definition: HGridCell.h:81
Vec3D previousPosition_
Displacement (only used in StatisticsVector, StatisticsPoint)
Definition: BaseParticle.h:694
BaseParticle * hGridNextObject_
Definition: BaseParticle.h:675
Mdouble getRadius() const
Returns the particle's radius.
Definition: BaseParticle.h:345
virtual std::vector< Mdouble > getFieldVTK(unsigned i) const
Basic class for walls.
Definition: BaseWall.h:47
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
void setHGridY(int HGridY)
Definition: HGridCell.h:71
const Vec3D getDisplacement2(Mdouble xmin, Mdouble xmax, Mdouble ymin, Mdouble ymax, Mdouble zmin, Mdouble zmax, Mdouble t) const
void setHGridX(int HGridX)
Definition: HGridCell.h:61
bool isPeriodicGhostParticle() const
Indicates if this particle is a ghost in the periodic boundary.
Container to store all BaseParticle.
void setMaserParticle(bool flag)
Flags the status of the particle if it belongs to the maser boundary or not.
const std::vector< int > & getPeriodicComplexity()
Obtains the periodic communication complexity of the particle.
BaseParticle * getHGridPrevObject() const
Returns pointer to previous object in particle's HGrid level & cell.
Definition: BaseParticle.h:250
virtual std::string getTypeVTK(unsigned i) const
BaseParticle()
Basic Particle constructor, creates an Particle at (0,0,0) with radius, mass and inertia equal to 1...
Definition: BaseParticle.cc:33
unsigned getCommunicationComplexity()
Obtains the communication complexity of the particle.
virtual void oldRead(std::istream &is)
Mdouble radius_
Definition: BaseParticle.h:652
void setHGridPrevObject(BaseParticle *p)
Sets the pointer to the previous object in the particle's HGrid cell & level.
Definition: BaseParticle.h:485
void setPeriodicComplexity(std::vector< int > complexity)
Set the periodic communication complexity of the particle.
const Vec3D & getPreviousPosition() const
Returns the particle's position in the previous time step.
Definition: BaseParticle.h:400
bool isMPIParticle() const
Indicates if this particle is a ghost in the MPI domain.
void setMPIParticle(bool flag)
Flags the mpi particle status.
MatrixSymmetric3D getInertia() const
Definition: BaseParticle.h:328
const Vec3D & getDisplacement() const
Returns the particle's displacement relative to the previous time step.
Definition: BaseParticle.h:392
void setPeriodicGhostParticle(bool flag)
Flags the status of the particle to be a ghost in periodic boundary or not.
bool isMaserParticle_
Indicates the periodic complexity at current time step. Used to update periodic status.
Definition: BaseParticle.h:691
Contains the hGrid-information for a certain particle: x,y,z and level of the particle containing thi...
Definition: HGridCell.h:32
int getHGridZ() const
Definition: HGridCell.h:76
Defines the basic properties that a interactable object can have.
static MatrixSymmetric3D inverse(const MatrixSymmetric3D &A)
Computes the inverse of a matrix; exits if the inverse doesn't exist.
virtual std::string getNameVTK(unsigned i) const
void angularAccelerate(const Vec3D &angVel)
Increases the particle's angularVelocity_ by the given vector.
std::vector< int > periodicComplexity_
Indicates the periodic complexity at previous time step.
Definition: BaseParticle.h:690
Class that describes a possible contact between two BaseParticle.
void integrateAfterForceComputation(double time, double timeStep)
Second step of Velocity Verlet integration.
bool isMPIParticle_
Pointer to originating Particle.
Definition: BaseParticle.h:682
virtual const Vec3D & getVelocity() const
Returns the velocity of this interactable.
Definition: Vector.h:49
BaseParticle * getHGridNextObject() const
Returns pointer to next object in particle's HGrid level & cell.
Definition: BaseParticle.h:242
void setHGridLevel(unsigned int HGridLevel)
Definition: HGridCell.h:91
BaseParticle * periodicFromParticle_
Pointer to the previous Particle in the same HGrid cell.
Definition: BaseParticle.h:679
unsigned int getHGridLevel() const
Returns particle's HGrid level.
Definition: BaseParticle.h:234
virtual unsigned getNumberOfFieldsVTK() const
unsigned int getParticleDimensions() const
Returns the particle's dimensions (either 2 or 3).
Mdouble getCurvature(const Vec3D &labFixedCoordinates) const override
Definition: BaseParticle.h:296
void setInPeriodicDomain(bool flag)
Flags the status of the particle wether it is in the periodic communication zone or not...
std::vector< int > previousPeriodicComplexity_
Indicates if the particle is a ghost particle of a periodic particle.
Definition: BaseParticle.h:689
virtual void actionsAfterTimeStep()
Definition: BaseParticle.h:639
unsigned int getHGridLevel() const
Definition: HGridCell.h:86
virtual Mdouble getInfo() const
Returns some user-defined information about this object (by default, species ID). ...
Implementation of a 3D symmetric matrix.
void movePrevious(const Vec3D &posMove)
Adds a vector to the particle's previousPosition_.
Mdouble getGravitationalEnergy() const
Calculates the particle's gravitational energy.
void fixParticle()
Fix Particle function. It fixes a Particle by setting its inverse mass and inertia and velocities to ...
int getHGridX() const
Returns particle's HGrid cell X-coordinate.
Definition: BaseParticle.h:265