BaseInteraction.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2023, 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 
247  Mdouble getOverlapVolume() const;
251  Mdouble getContactRadius() const;
252 
256  void removeFromHandler();
257 
261  void copySwitchPointer(const BaseInteractable* original, BaseInteractable* ghost) const;
262 
268 
275  {
276  logger.assert_debug(P_ != nullptr, "First particle in interaction % is nullptr", getId());
277  return P_;
278  }
279 
286  {
287  logger.assert_debug(I_ != nullptr, "Second particle in interaction % is nullptr", getId());
288  return I_;
289  }
290 
297  const BaseInteractable* getP() const
298  {
299  logger.assert_debug(P_ != nullptr, "First particle in interaction % is nullptr", getId());
300  return P_;
301  }
302 
308  const BaseInteractable* getI() const
309  {
310  logger.assert_debug(I_ != nullptr, "Second particle in interaction % is nullptr", getId());
311  return I_;
312  }
313 
320  { return timeStamp_; }
321 
325  virtual void integrate(Mdouble timeStep);
326 
330  virtual Mdouble getTangentialOverlap() const;
331 
335  Mdouble getDistance() const;
336 
340  const Vec3D& getRelativeVelocity() const;
341 
346 
351 
355  virtual BaseInteraction* copy() const = 0;
356 
357  void setFStatData(std::fstream& fstat, BaseParticle* P, BaseWall* I);
358 
359  void setFStatData(std::fstream& fstat, BaseParticle* P, BaseParticle* I);
360 
361  unsigned int getMultiContactIdentifier() const;
362 
364 
370  virtual void rotateHistory(Matrix3D& rotationMatrix);
371 
372  virtual void actionsAfterTimeStep();
373 
374  virtual unsigned getNumberOfFieldsVTK() const;
375 
376  virtual std::string getTypeVTK(unsigned i) const;
377 
378  virtual std::string getNameVTK(unsigned i) const;
379 
380  virtual std::vector<Mdouble> getFieldVTK(unsigned i) const;
381 
385  void addForce(Vec3D force);
386 
390  void addTorque(Vec3D torque);
391 
395  void setForce(Vec3D force);
396 
400  void setTorque(Vec3D torque);
401 
402 protected:
403 
407  virtual const Vec3D getTangentialForce() const;
408 
412  Mdouble getEffectiveRadius() const;
413 
417  Mdouble getEffectiveMass() const;
418 
422  void setRelativeVelocity(Vec3D relativeVelocity);
423 
427  void setNormalRelativeVelocity(Mdouble normalRelativeVelocit);
428 
432  void setAbsoluteNormalForce(Mdouble absoluteNormalForce);
433 
434  virtual Mdouble getElasticEnergyAtEquilibrium(Mdouble adhesiveForce) const
435  { return 0; }
436 
440  virtual void reverseHistory();
441 
442 
446  void writeInteraction(std::ostream& os, bool created) const;
447 
448 public:
449 
453  const BaseSpecies* getBaseSpecies() const;
454 
455  // create the mpi data type for the history data class
456  virtual void createMPIType();
457 
458  // creates the array for the history data
459  virtual void* createMPIInteractionDataArray(unsigned int numberOfInteractions) const;
460 
461  virtual void deleteMPIInteractionDataArray(void* dataArray);
462 
464  virtual void getMPIInteraction(void* historyDataArray, unsigned int index) const;
465 
466 
467  virtual void getInteractionDetails(void* interactionDataArray, unsigned int index, unsigned int& identificationP,
468  unsigned int& identificationI, bool& isWallInteraction, unsigned& timeStamp);
469 
470 
471  //Sets the interactionData from the MPI class into the current thingy
472  virtual void setMPIInteraction(void* interactionDataArray, unsigned int index, bool resetPointers);
473 
474  void
475  setBasicMPIInteractionValues(int P, int I, unsigned timeStamp, Vec3D force, Vec3D torque, bool isWallInteraction,
476  bool resetPointers);
477 
478  void setIdentificationP(unsigned int identification);
479 
480  void setIdentificationI(int identification);
481 
482  void setWallInteraction(bool flag);
483 
484  unsigned int getIdentificationP();
485 
486  int getIdentificationI();
487 
488  bool isWallInteraction();
489 
490  // returns true is the interaction is an 'internal' bond.
491  // This is used in BaseInteraction::writeToFstat to detect internal bonds;
492  // these internal forces are not written to fstat and thus don't contribute to fstatistics.
493  virtual bool isBonded() const {return false;}
494 
495 private:
496 
497 
502 
507 
512 
513 
514  // used in mpi code, which can't deal with the pointers above
515  unsigned int identificationP_;
518 
523 
528 
533 
538 
543 
548 
553 
558  unsigned timeStamp_;
559 
564 
569 
574 
579 
584 
585 };
586 
587 #endif
double Mdouble
Definition: GeneralDefine.h:34
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
Defines the basic properties that a interactable object can have.
Definition: BaseInteractable.h:55
Stores information about interactions between two interactable objects; often particles but could be ...
Definition: BaseInteraction.h:60
unsigned int identificationP_
Definition: BaseInteraction.h:515
void setBasicMPIInteractionValues(int P, int I, unsigned timeStamp, Vec3D force, Vec3D torque, bool isWallInteraction, bool resetPointers)
Definition: BaseInteraction.cc:961
void read(std::istream &is) override
Interaction read function, which accepts an std::istream as input.
Definition: BaseInteraction.cc:188
const Vec3D & getForce() const
Gets the current force (vector) between the two interacting objects.
Definition: BaseInteraction.h:210
void copySwitchPointer(const BaseInteractable *original, BaseInteractable *ghost) const
This copies the interactions of the original particle and replaces the original with the ghost copy.
Definition: BaseInteraction.cc:341
~BaseInteraction() override
The destructor. It removes this interactions from the objects that were interacting,...
Definition: BaseInteraction.cc:125
const Vec3D & getTorque() const
Gets the current torque (vector) between the two interacting objects.
Definition: BaseInteraction.h:218
virtual void createMPIType()
Definition: BaseInteraction.cc:899
unsigned int getMultiContactIdentifier() const
Definition: BaseInteraction.cc:763
const BaseSpecies * species_
Definition: BaseInteraction.h:573
void writeInteraction(std::ostream &os, bool created) const
Writes information about a interaction to the interaction file.
Definition: BaseInteraction.cc:729
void importI(BaseInteractable *I)
Sets the second object involved in the interaction (often particle or wall).
Definition: BaseInteraction.cc:451
void setHandler(InteractionHandler *handler)
Sets the pointer to the interaction hander which is storing this interaction.
Definition: BaseInteraction.cc:261
void setIdentificationP(unsigned int identification)
Definition: BaseInteraction.cc:930
std::string getName() const override
Virtual function which allows interactions to be named.
Definition: BaseInteraction.cc:202
Mdouble getLagrangeMultiplier()
Definition: BaseInteraction.h:190
const Vec3D & getRelativeVelocity() const
Returns a constant reference to a vector of relative velocity.
Definition: BaseInteraction.cc:573
Mdouble getEffectiveMass() const
Returns a Mdouble to the effective radius of the interaction. (Not corrected for the overlap)
Definition: BaseInteraction.cc:810
void setAbsoluteNormalForce(Mdouble absoluteNormalForce)
the absolute values of the norm (length) of the normal force
Definition: BaseInteraction.cc:670
void setDistance(Mdouble distance)
Sets the interaction distance between the two interacting objects.
Definition: BaseInteraction.cc:221
Mdouble getAbsoluteNormalForce() const
Returns the absolute value of the norm (length) of the Normal force vector.
Definition: BaseInteraction.cc:596
virtual std::vector< Mdouble > getFieldVTK(unsigned i) const
Definition: BaseInteraction.cc:893
Vec3D torque_
Definition: BaseInteraction.h:552
Vec3D getIC() const
Definition: BaseInteraction.cc:466
virtual void getInteractionDetails(void *interactionDataArray, unsigned int index, unsigned int &identificationP, unsigned int &identificationI, bool &isWallInteraction, unsigned &timeStamp)
Definition: BaseInteraction.cc:923
bool isWallInteraction_
Definition: BaseInteraction.h:517
const Vec3D & getContactPoint() const
Gets constant reference to contact point (vector).
Definition: BaseInteraction.h:234
void setTimeStamp(unsigned timeStamp)
Updates the time step of the interacting. Note, time steps used to find completed interactions.
Definition: BaseInteraction.cc:251
virtual void computeForce()
Virtual function that contains the force law between the two objects interacting.
Definition: BaseInteraction.cc:694
Vec3D normal_
Definition: BaseInteraction.h:563
virtual bool isBonded() const
Definition: BaseInteraction.h:493
Vec3D force_
Definition: BaseInteraction.h:547
void setContactPoint(Vec3D contactPoint)
Set the location of the contact point between the two interacting objects.
Definition: BaseInteraction.cc:240
void setMultiContactIdentifier(unsigned int multiContactIdentifier_)
Definition: BaseInteraction.cc:768
const Vec3D & getNormal() const
Gets the normal vector between the two interacting objects.
Definition: BaseInteraction.h:226
virtual std::string getTypeVTK(unsigned i) const
Definition: BaseInteraction.cc:883
virtual Mdouble getTangentialOverlap() const
get the length of the current tangential overlap
Definition: BaseInteraction.cc:551
Mdouble absoluteNormalForce_
Definition: BaseInteraction.h:537
Mdouble getTimeStamp() const
Returns an Mdouble which is the time stamp of the interaction.
Definition: BaseInteraction.h:319
virtual Mdouble getElasticEnergy() const
Returns a Mdouble which is the current about of Elastic energy in the interaction.
Definition: BaseInteraction.cc:703
Mdouble lagrangeMultiplier_
Definition: BaseInteraction.h:578
BaseInteractable * P_
Definition: BaseInteraction.h:506
void gatherContactStatistics()
Definition: BaseInteraction.cc:825
void importP(BaseInteractable *P)
Sets the first object involved in the interaction (normally a particle).
Definition: BaseInteraction.cc:419
Mdouble normalRelativeVelocity_
Definition: BaseInteraction.h:532
void setP(BaseInteractable *P)
Sets the first object involved in the interaction (normally a particle).
Definition: BaseInteraction.cc:403
virtual BaseInteraction * copy() const =0
Makes a copy of the interaction and returns a pointer to the copy.
virtual unsigned getNumberOfFieldsVTK() const
Definition: BaseInteraction.cc:878
Vec3D getCP() const
Definition: BaseInteraction.cc:472
void setFStatData(std::fstream &fstat, BaseParticle *P, BaseWall *I)
Definition: BaseInteraction.cc:994
virtual void setMPIInteraction(void *interactionDataArray, unsigned int index, bool resetPointers)
Definition: BaseInteraction.cc:907
void removeFromHandler()
Removes this interaction from its interaction hander.
Definition: BaseInteraction.cc:322
void setWallInteraction(bool flag)
Definition: BaseInteraction.cc:950
bool isWallInteraction()
Definition: BaseInteraction.cc:955
Mdouble overlap_
Definition: BaseInteraction.h:568
virtual void deleteMPIInteractionDataArray(void *dataArray)
Definition: BaseInteraction.cc:917
virtual void * createMPIInteractionDataArray(unsigned int numberOfInteractions) const
Definition: BaseInteraction.cc:911
virtual void actionsAfterTimeStep()
Definition: BaseInteraction.cc:818
int identificationI_
Definition: BaseInteraction.h:516
const BaseInteractable * getI() const
Returns a constant pointer to the second object involved in the interaction.
Definition: BaseInteraction.h:308
const BaseInteractable * getP() const
Returns a constant pointer to the first object involved in the interaction.
Definition: BaseInteraction.h:297
void setI(BaseInteractable *I)
Sets the second object involved in the interaction (often particle or wall).
Definition: BaseInteraction.cc:435
void addForce(Vec3D force)
add an force increment to the total force.
Definition: BaseInteraction.cc:606
int getIdentificationI()
Definition: BaseInteraction.cc:945
Mdouble getDistance() const
Returns an Mdouble which is the norm (length) of distance vector.
Definition: BaseInteraction.cc:539
virtual std::string getNameVTK(unsigned i) const
Definition: BaseInteraction.cc:888
virtual void actionsOnErase()
If an interaction needs to do something before it gets erased, add it here. E.g. Liquid bridges ruptu...
Definition: BaseInteraction.h:84
Vec3D contactPoint_
Definition: BaseInteraction.h:522
Mdouble getNormalRelativeVelocity() const
Returns a double which is the norm (length) of the relative velocity vector.
Definition: BaseInteraction.cc:584
const BaseSpecies * getBaseSpecies() const
Return a constant point to BaseSpecies of the interaction.
Definition: BaseInteraction.cc:682
virtual const Vec3D getTangentialForce() const
Definition: BaseInteraction.cc:563
void setLagrangeMultiplier(Mdouble multiplier)
Definition: BaseInteraction.h:185
virtual Mdouble getElasticEnergyAtEquilibrium(Mdouble adhesiveForce) const
Definition: BaseInteraction.h:434
Mdouble getEffectiveRadius() const
Returns a Mdouble to the effective radius of the interaction. (Not corrected for the overlap)
Definition: BaseInteraction.cc:793
virtual void integrate(Mdouble timeStep)
integrates variables of the interaction which need to be integrate e.g. the tangential overlap.
Definition: BaseInteraction.cc:378
unsigned timeStamp_
Definition: BaseInteraction.h:558
void setRelativeVelocity(Vec3D relativeVelocity)
set the relative velocity of the current of the interactions.
Definition: BaseInteraction.cc:649
void setNormal(Vec3D normal)
Sets the normal vector between the two interacting objects.
Definition: BaseInteraction.cc:212
void setSpecies(const BaseSpecies *species)
Set the Species of the interaction; note this can either be a Species or MixedSpecies.
Definition: BaseInteraction.cc:390
unsigned int getIdentificationP()
Definition: BaseInteraction.cc:940
BaseInteractable * getI()
Returns a pointer to the second object involved in the interaction (often a wall or a particle).
Definition: BaseInteraction.h:285
Mdouble distance_
Definition: BaseInteraction.h:542
BaseInteractable * I_
Definition: BaseInteraction.h:511
BaseInteractable * getP()
Returns a pointer to first object involved in the interaction (normally a particle).
Definition: BaseInteraction.h:274
Mdouble getContactRadius() const
Returns a Mdouble with the current contact between the two interacting objects.
Definition: BaseInteraction.cc:366
void write(std::ostream &os) const override
Interaction print function, which accepts an std::ostream as input.
Definition: BaseInteraction.cc:159
void writeToFStat(std::ostream &os, Mdouble time) const
Writes forces data to the FStat file.
Definition: BaseInteraction.cc:487
InteractionHandler * getHandler() const
Gets a point to the interaction handlers to which this interaction belongs.
Definition: BaseInteraction.cc:267
void setIdentificationI(int identification)
Definition: BaseInteraction.cc:935
void setNormalRelativeVelocity(Mdouble normalRelativeVelocit)
set the normal component of the relative velocity.
Definition: BaseInteraction.cc:660
void addTorque(Vec3D torque)
add a torque increment to the total torque.
Definition: BaseInteraction.cc:616
Vec3D getIP() const
Definition: BaseInteraction.cc:459
virtual void reverseHistory()
When periodic particles some interaction need certain history properties reversing....
Definition: BaseInteraction.cc:718
Mdouble getOverlapVolume() const
Returns the overlap volume between two interacting objects.
Definition: BaseInteraction.cc:277
virtual void getMPIInteraction(void *historyDataArray, unsigned int index) const
copies the history interactions into the data array
Definition: BaseInteraction.cc:903
void setForce(Vec3D force)
set total force (this is used by the normal force, tangential forces are added use addForce)
Definition: BaseInteraction.cc:627
void setTorque(Vec3D torque)
set the total force (this is used by the normal force, tangential torques are added use addTorque)
Definition: BaseInteraction.cc:638
Mdouble getOverlap() const
Returns a Mdouble with the current overlap between the two interacting objects.
Definition: BaseInteraction.h:240
unsigned multiContactIdentifier_
Definition: BaseInteraction.h:583
void setOverlap(Mdouble overlap)
Set the overlap between the two interacting object.
Definition: BaseInteraction.cc:231
virtual void rotateHistory(Matrix3D &rotationMatrix)
When periodic particles are used, some interactions need certain history properties rotated (e....
Definition: BaseInteraction.cc:774
Vec3D relativeVelocity_
Definition: BaseInteraction.h:527
InteractionHandler * handler_
Definition: BaseInteraction.h:501
BaseInteraction()
Definition: BaseInteraction.cc:65
It is an abstract base class due to the purely virtual functions declared below. Even if the function...
Definition: BaseObject.h:51
unsigned int getId() const
Returns the unique identifier of any particular object.
Definition: BaseObject.h:125
Definition: BaseParticle.h:54
BaseSpecies is the class from which all other species are derived.
Definition: BaseSpecies.h:50
Basic class for walls.
Definition: BaseWall.h:49
Container to store Interaction objects.
Definition: InteractionHandler.h:45
Implementation of a 3D matrix.
Definition: Matrix.h:38
Definition: Vector.h:51
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:73
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51