MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BaseInteraction.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 BASEINTERACTION_H
27 #define BASEINTERACTION_H
28 
29 #include <vector>
30 #include "BaseObject.h"
31 #include "Math/Vector.h"
32 #include "Math/Matrix.h"
33 #include "Logger.h"
34 
35 class InteractionHandler;
36 
37 class BaseParticle;
38 
39 class BaseWall;
40 
41 class BaseSpecies;
42 
43 class BaseInteractable;
44 
45 
60 {
61 public:
66  BaseInteraction(BaseInteractable* P, BaseInteractable* I, unsigned timeStamp);
67 
70 
73 
76  ~BaseInteraction() override;
77 
84  virtual void actionsOnErase()
85  {};
86 
90  virtual void computeForce();
91 
95  void read(std::istream& is) override;
96 
100  void write(std::ostream& os) const override;
101 
105  void writeToFStat(std::ostream& os, Mdouble time) const;
106 
110  std::string getName() const override;
111 
115  virtual Mdouble getElasticEnergy() const;
116 
120  void setDistance(Mdouble distance);
121 
125  void setNormal(Vec3D normal);
126 
130  void setOverlap(Mdouble overlap);
131 
135  void setContactPoint(Vec3D contactPoint);
136 
140  void setTimeStamp(unsigned timeStamp);
141 
145  void setSpecies(const BaseSpecies* species);
146 
150  void setP(BaseInteractable* P);
151 
155  void setI(BaseInteractable* I);
156 
160  void importP(BaseInteractable *P);
161 
165  void importI(BaseInteractable *I);
166 
171  Vec3D getIP() const;
172 
177  Vec3D getIC() const;
178 
183  Vec3D getCP() const;
184 
186  {
187  lagrangeMultiplier_ = multiplier;
188  }
189 
191  {
192  return lagrangeMultiplier_;
193  }
194 
198  void setHandler(InteractionHandler* handler);
199 
204 
210  const Vec3D& getForce() const
211  { return force_; }
212 
218  const Vec3D& getTorque() const
219  { return torque_; }
220 
226  const Vec3D& getNormal() const
227  { return normal_; }
228 
234  const Vec3D& getContactPoint() const
235  { return contactPoint_; }
236 
241  { return overlap_; }
242 
246  Mdouble getContactRadius() const;
247 
251  void removeFromHandler();
252 
256  void copySwitchPointer(const BaseInteractable* original, BaseInteractable* ghost) const;
257 
263 
270  {
271  logger.assert(P_ != nullptr, "First particle in interaction % is nullptr", getId());
272  return P_;
273  }
274 
281  {
282  logger.assert(I_ != nullptr, "Second particle in interaction % is nullptr", getId());
283  return I_;
284  }
285 
292  const BaseInteractable* getP() const
293  {
294  logger.assert(P_ != nullptr, "First particle in interaction % is nullptr", getId());
295  return P_;
296  }
297 
303  const BaseInteractable* getI() const
304  {
305  logger.assert(I_ != nullptr, "Second particle in interaction % is nullptr", getId());
306  return I_;
307  }
308 
315  { return timeStamp_; }
316 
320  virtual void integrate(Mdouble timeStep);
321 
325  virtual Mdouble getTangentialOverlap() const;
326 
330  Mdouble getDistance() const;
331 
335  const Vec3D& getRelativeVelocity() const;
336 
341 
346 
350  virtual BaseInteraction* copy() const = 0;
351 
352  void setFStatData(std::fstream& fstat, BaseParticle* P, BaseWall* I);
353 
354  void setFStatData(std::fstream& fstat, BaseParticle* P, BaseParticle* I);
355 
356  unsigned int getMultiContactIdentifier() const;
357 
359 
365  virtual void rotateHistory(Matrix3D& rotationMatrix);
366 
367  virtual void actionsAfterTimeStep();
368 
369  virtual unsigned getNumberOfFieldsVTK() const;
370 
371  virtual std::string getTypeVTK(unsigned i) const;
372 
373  virtual std::string getNameVTK(unsigned i) const;
374 
375  virtual std::vector<Mdouble> getFieldVTK(unsigned i) const;
376 
380  void setForce(Vec3D force);
381 
382 protected:
383 
387  virtual const Vec3D getTangentialForce() const;
388 
392  Mdouble getEffectiveRadius() const;
393 
397  Mdouble getEffectiveMass() const;
398 
399  //functions that only the derived Interactions have to know about:
403  void addForce(Vec3D force);
404 
405  /*
406  * \brief add a torque increment to the total torque.
407  */
408  void addTorque(Vec3D torque);
409 
410  //these functions are only used for normal forces and should be made private by the normal forces:
411 
415  void setTorque(Vec3D torque);
416 
420  void setRelativeVelocity(Vec3D relativeVelocity);
421 
425  void setNormalRelativeVelocity(Mdouble normalRelativeVelocit);
426 
430  void setAbsoluteNormalForce(Mdouble absoluteNormalForce);
431 
432  virtual Mdouble getElasticEnergyAtEquilibrium(Mdouble adhesiveForce) const
433  { return 0; }
434 
438  virtual void reverseHistory();
439 
440 
444  void writeInteraction(std::ostream& os, bool created) const;
445 
446 public:
447 
451  const BaseSpecies* getBaseSpecies() const;
452 
453  // create the mpi data type for the history data class
454  virtual void createMPIType();
455 
456  // creates the array for the history data
457  virtual void* createMPIInteractionDataArray(unsigned int numberOfInteractions) const;
458 
459  virtual void deleteMPIInteractionDataArray(void* dataArray);
460 
462  virtual void getMPIInteraction(void* historyDataArray, unsigned int index) const;
463 
464 
465  virtual void getInteractionDetails(void* interactionDataArray, unsigned int index, unsigned int& identificationP,
466  unsigned int& identificationI, bool& isWallInteraction, unsigned& timeStamp);
467 
468 
469  //Sets the interactionData from the MPI class into the current thingy
470  virtual void setMPIInteraction(void* interactionDataArray, unsigned int index, bool resetPointers);
471 
472  void
473  setBasicMPIInteractionValues(int P, int I, unsigned timeStamp, Vec3D force, Vec3D torque, bool isWallInteraction,
474  bool resetPointers);
475 
476  void setIdentificationP(unsigned int identification);
477 
478  void setIdentificationI(int identification);
479 
480  void setWallInteraction(bool flag);
481 
482  unsigned int getIdentificationP();
483 
484  int getIdentificationI();
485 
486  bool isWallInteraction();
487 
488  // returns true is the interaction is an 'internal' bond.
489  // This is used in BaseInteraction::writeToFstat to detect internal bonds;
490  // these internal forces are not written to fstat and thus don't contribute to fstatistics.
491  virtual bool isBonded() const {return false;}
492 
493 private:
494 
495 
500 
505 
510 
511 
512  // used in mpi code, which can't deal with the pointers above
513  unsigned int identificationP_;
516 
521 
526 
531 
536 
541 
546 
551 
555  unsigned timeStamp_;
557 
562 
567 
572 
577 
582 };
583 
584 #endif
BaseInteractable * I_
unsigned int getId() const
Returns the unique identifier of any particular object.
Definition: BaseObject.h:125
const Vec3D & getTorque() const
Gets the current torque (vector) between the two interacting objects.
virtual void actionsOnErase()
If an interaction needs to do something before it gets erased, add it here. E.g. Liquid bridges ruptu...
Mdouble getEffectiveRadius() const
Returns a Mdouble to the effective radius of the interaction. (Not corrected for the overlap) ...
void setNormal(Vec3D normal)
Sets the normal vector between the two interacting objects.
void copySwitchPointer(const BaseInteractable *original, BaseInteractable *ghost) const
This copies the interactions of the original particle and replaces the original with the ghost copy...
BaseSpecies is the class from which all other species are derived.
Definition: BaseSpecies.h:49
virtual void getInteractionDetails(void *interactionDataArray, unsigned int index, unsigned int &identificationP, unsigned int &identificationI, bool &isWallInteraction, unsigned &timeStamp)
virtual void * createMPIInteractionDataArray(unsigned int numberOfInteractions) const
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
InteractionHandler * getHandler() const
Gets a point to the interaction handlers to which this interaction belongs.
void setOverlap(Mdouble overlap)
Set the overlap between the two interacting object.
double Mdouble
Definition: GeneralDefine.h:34
const BaseSpecies * species_
virtual BaseInteraction * copy() const =0
Makes a copy of the interaction and returns a pointer to the copy.
virtual void actionsAfterTimeStep()
void setI(BaseInteractable *I)
Sets the second object involved in the interaction (often particle or wall).
It is an abstract base class due to the purely virtual functions declared below. Even if the function...
Definition: BaseObject.h:50
const Vec3D & getRelativeVelocity() const
Returns a constant reference to a vector of relative velocity.
const BaseInteractable * getI() const
Returns a constant pointer to the second object involved in the interaction.
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
virtual void reverseHistory()
When periodic particles some interaction need certain history properties reversing. This is the function for that.
void setRelativeVelocity(Vec3D relativeVelocity)
set the relative velocity of the current of the interactions.
void setContactPoint(Vec3D contactPoint)
Set the location of the contact point between the two interacting objects.
void addTorque(Vec3D torque)
void writeToFStat(std::ostream &os, Mdouble time) const
Writes forces data to the FStat file.
void removeFromHandler()
Removes this interaction from its interaction hander.
void setForce(Vec3D force)
set total force (this is used by the normal force, tangential forces are added use addForce) ...
virtual std::vector< Mdouble > getFieldVTK(unsigned i) const
virtual void createMPIType()
void setLagrangeMultiplier(Mdouble multiplier)
const Vec3D & getContactPoint() const
Gets constant reference to contact point (vector).
BaseInteractable * getI()
Returns a pointer to the second object involved in the interaction (often a wall or a particle)...
void setNormalRelativeVelocity(Mdouble normalRelativeVelocit)
set the normal component of the relative velocity.
unsigned int identificationP_
void setFStatData(std::fstream &fstat, BaseParticle *P, BaseWall *I)
void setDistance(Mdouble distance)
Sets the interaction distance between the two interacting objects.
void setTimeStamp(unsigned timeStamp)
Updates the time step of the interacting. Note, time steps used to find completed interactions...
Mdouble getTimeStamp() const
Returns an Mdouble which is the time stamp of the interaction.
void gatherContactStatistics()
Stores information about interactions between two interactable objects; often particles but could be ...
const Vec3D & getNormal() const
Gets the normal vector between the two interacting objects.
BaseInteractable * getP()
Returns a pointer to first object involved in the interaction (normally a particle).
BaseInteractable * P_
Mdouble getNormalRelativeVelocity() const
Returns a double which is the norm (length) of the relative velocity vector.
void setMultiContactIdentifier(unsigned int multiContactIdentifier_)
virtual void rotateHistory(Matrix3D &rotationMatrix)
When periodic particles are used, some interactions need certain history properties rotated (e...
const BaseSpecies * getBaseSpecies() const
Return a constant point to BaseSpecies of the interaction.
void setIdentificationP(unsigned int identification)
~BaseInteraction() override
The destructor.
Container to store Interaction objects.
void setHandler(InteractionHandler *handler)
Sets the pointer to the interaction hander which is storing this interaction.
virtual std::string getTypeVTK(unsigned i) const
void setP(BaseInteractable *P)
Sets the first object involved in the interaction (normally a particle).
Mdouble lagrangeMultiplier_
Mdouble getLagrangeMultiplier()
void setTorque(Vec3D torque)
set the total force (this is used by the normal force, tangential torques are added use addTorque) ...
void setSpecies(const BaseSpecies *species)
Set the Species of the interaction; note this can either be a Species or MixedSpecies.
virtual const Vec3D getTangentialForce() const
void writeInteraction(std::ostream &os, bool created) const
Writes information about a interaction to the interaction file.
const Vec3D & getForce() const
Gets the current force (vector) between the two interacting objects.
Basic class for walls.
Definition: BaseWall.h:47
unsigned int getIdentificationP()
Mdouble getOverlap() const
Returns a Mdouble with the current overlap between the two interacting objects.
virtual std::string getNameVTK(unsigned i) const
void addForce(Vec3D force)
add an force increment to the total force.
Vec3D getIP() const
void setAbsoluteNormalForce(Mdouble absoluteNormalForce)
the absolute values of the norm (length) of the normal force
Mdouble normalRelativeVelocity_
void importP(BaseInteractable *P)
Sets the first object involved in the interaction (normally a particle).
Vec3D getIC() const
virtual bool isBonded() const
unsigned multiContactIdentifier_
Vec3D getCP() const
Mdouble getDistance() const
Returns an Mdouble which is the norm (length) of distance vector.
virtual void integrate(Mdouble timeStep)
integrates variables of the interaction which need to be integrate e.g. the tangential overlap...
void read(std::istream &is) override
Interaction read function, which accepts an std::istream as input.
virtual Mdouble getElasticEnergyAtEquilibrium(Mdouble adhesiveForce) const
Mdouble getContactRadius() const
Returns a Mdouble with the current contact between the two interacting objects.
const BaseInteractable * getP() const
Returns a constant pointer to the first object involved in the interaction.
void setWallInteraction(bool flag)
Defines the basic properties that a interactable object can have.
virtual void setMPIInteraction(void *interactionDataArray, unsigned int index, bool resetPointers)
virtual Mdouble getElasticEnergy() const
Returns a Mdouble which is the current about of Elastic energy in the interaction.
Mdouble absoluteNormalForce_
virtual void computeForce()
Virtual function that contains the force law between the two objects interacting. ...
Implementation of a 3D matrix.
Definition: Matrix.h:37
Definition: Vector.h:49
void setBasicMPIInteractionValues(int P, int I, unsigned timeStamp, Vec3D force, Vec3D torque, bool isWallInteraction, bool resetPointers)
void write(std::ostream &os) const override
Interaction print function, which accepts an std::ostream as input.
virtual Mdouble getTangentialOverlap() const
get the length of the current tangential overlap
void setIdentificationI(int identification)
unsigned int getMultiContactIdentifier() const
std::string getName() const override
Virtual function which allows interactions to be named.
virtual void getMPIInteraction(void *historyDataArray, unsigned int index) const
copies the history interactions into the data array
void importI(BaseInteractable *I)
Sets the second object involved in the interaction (often particle or wall).
virtual void deleteMPIInteractionDataArray(void *dataArray)
Mdouble getEffectiveMass() const
Returns a Mdouble to the effective radius of the interaction. (Not corrected for the overlap) ...
InteractionHandler * handler_
virtual unsigned getNumberOfFieldsVTK() const
Mdouble getAbsoluteNormalForce() const
Returns the absolute value of the norm (length) of the Normal force vector.