BaseInteraction.h
Go to the documentation of this file.
1 // This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2 // Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3 // License: BSD 3-Clause License; see the LICENSE file in the root directory.
4 
5 #ifndef BASEINTERACTION_H
6 #define BASEINTERACTION_H
7 
8 #include <vector>
9 #include "BaseObject.h"
10 #include "Math/Vector.h"
11 #include "Math/Matrix.h"
12 #include "Logger.h"
13 
14 class InteractionHandler;
15 
16 class BaseParticle;
17 
18 class BaseWall;
19 
20 class BaseSpecies;
21 
22 class BaseInteractable;
23 
24 
39 {
40 public:
45  BaseInteraction(BaseInteractable* P, BaseInteractable* I, unsigned timeStamp);
46 
49 
52 
55  ~BaseInteraction() override;
56 
63  virtual void actionsOnErase()
64  {};
65 
69  virtual void computeForce();
70 
74  void read(std::istream& is) override;
75 
79  void write(std::ostream& os) const override;
80 
84  void writeToFStat(std::ostream& os, Mdouble time) const;
85 
89  std::string getName() const override;
90 
94  virtual Mdouble getElasticEnergy() const;
95 
99  void setDistance(Mdouble distance);
100 
104  void setNormal(Vec3D normal);
105 
109  void setOverlap(Mdouble overlap);
110 
114  void setContactPoint(Vec3D contactPoint);
115 
119  void setTimeStamp(unsigned timeStamp);
120 
124  void setSpecies(const BaseSpecies* species);
125 
129  void setP(BaseInteractable* P);
130 
134  void setI(BaseInteractable* I);
135 
139  void importP(BaseInteractable *P);
140 
144  void importI(BaseInteractable *I);
145 
150  Vec3D getIP() const;
151 
156  Vec3D getIC() const;
157 
162  Vec3D getCP() const;
163 
165  {
167  }
168 
170  {
171  return lagrangeMultiplier_;
172  }
173 
177  void setHandler(InteractionHandler* handler);
178 
183 
189  const Vec3D& getForce() const
190  { return force_; }
191 
197  const Vec3D& getTorque() const
198  { return torque_; }
199 
205  const Vec3D& getNormal() const
206  { return normal_; }
207 
213  const Vec3D& getContactPoint() const
214  { return contactPoint_; }
215 
220  { return overlap_; }
221 
226  Mdouble getOverlapVolume() const;
230  Mdouble getContactRadius() const;
231 
235  void removeFromHandler();
236 
240  void copySwitchPointer(const BaseInteractable* original, BaseInteractable* ghost) const;
241 
247 
254  {
255  logger.assert_debug(P_ != nullptr, "First particle in interaction % is nullptr", getId());
256  return P_;
257  }
258 
265  {
266  logger.assert_debug(I_ != nullptr, "Second particle in interaction % is nullptr", getId());
267  return I_;
268  }
269 
276  const BaseInteractable* getP() const
277  {
278  logger.assert_debug(P_ != nullptr, "First particle in interaction % is nullptr", getId());
279  return P_;
280  }
281 
287  const BaseInteractable* getI() const
288  {
289  logger.assert_debug(I_ != nullptr, "Second particle in interaction % is nullptr", getId());
290  return I_;
291  }
292 
299  { return timeStamp_; }
300 
304  virtual void integrate(Mdouble timeStep);
305 
309  virtual Mdouble getTangentialOverlap() const;
310 
314  Mdouble getDistance() const;
315 
319  const Vec3D& getRelativeVelocity() const;
320 
325 
330 
334  virtual BaseInteraction* copy() const = 0;
335 
336  void setFStatData(std::fstream& fstat, BaseParticle* P, BaseWall* I);
337 
338  void setFStatData(std::fstream& fstat, BaseParticle* P, BaseParticle* I);
339 
340  unsigned int getMultiContactIdentifier() const;
341 
343 
349  virtual void rotateHistory(Matrix3D& rotationMatrix);
350 
351  virtual void actionsAfterTimeStep();
352 
353  virtual unsigned getNumberOfFieldsVTK() const;
354 
355  virtual std::string getTypeVTK(unsigned i) const;
356 
357  virtual std::string getNameVTK(unsigned i) const;
358 
359  virtual std::vector<Mdouble> getFieldVTK(unsigned i) const;
360 
364  void addForce(Vec3D force);
365 
369  void addTorque(Vec3D torque);
370 
374  void setForce(Vec3D force);
375 
379  void setTorque(Vec3D torque);
380 
381 protected:
382 
386  virtual const Vec3D getTangentialForce() const;
387 
391  Mdouble getEffectiveRadius() const;
392 
396  Mdouble getEffectiveMass() const;
397 
401  void setRelativeVelocity(Vec3D relativeVelocity);
402 
406  void setNormalRelativeVelocity(Mdouble normalRelativeVelocit);
407 
411  void setAbsoluteNormalForce(Mdouble absoluteNormalForce);
412 
413  virtual Mdouble getElasticEnergyAtEquilibrium(Mdouble adhesiveForce) const
414  { return 0; }
415 
419  virtual void reverseHistory();
420 
421 
425  void writeInteraction(std::ostream& os, bool created) const;
426 
427 public:
428 
432  const BaseSpecies* getBaseSpecies() const;
433 
434  // create the mpi data type for the history data class
435  virtual void createMPIType();
436 
437  // creates the array for the history data
438  virtual void* createMPIInteractionDataArray(unsigned int numberOfInteractions) const;
439 
440  virtual void deleteMPIInteractionDataArray(void* dataArray);
441 
443  virtual void getMPIInteraction(void* historyDataArray, unsigned int index) const;
444 
445 
446  virtual void getInteractionDetails(void* interactionDataArray, unsigned int index, unsigned int& identificationP,
447  unsigned int& identificationI, bool& isWallInteraction, unsigned& timeStamp);
448 
449 
450  //Sets the interactionData from the MPI class into the current thingy
451  virtual void setMPIInteraction(void* interactionDataArray, unsigned int index, bool resetPointers);
452 
453  void
454  setBasicMPIInteractionValues(int P, int I, unsigned timeStamp, Vec3D force, Vec3D torque, bool isWallInteraction,
455  bool resetPointers);
456 
457  void setIdentificationP(unsigned int identification);
458 
459  void setIdentificationI(int identification);
460 
461  void setWallInteraction(bool flag);
462 
463  unsigned int getIdentificationP();
464 
465  int getIdentificationI();
466 
467  bool isWallInteraction();
468 
469  // returns true is the interaction is an 'internal' bond.
470  // This is used in BaseInteraction::writeToFstat to detect internal bonds;
471  // these internal forces are not written to fstat and thus don't contribute to fstatistics.
472  virtual bool isBonded() const {return false;}
473 
474 private:
475 
476 
481 
486 
491 
492 
493  // used in mpi code, which can't deal with the pointers above
494  unsigned int identificationP_;
497 
502 
507 
512 
517 
522 
527 
532 
537  unsigned timeStamp_;
538 
543 
548 
553 
558 
563 
564 };
565 
566 #endif
int i
Definition: BiCGSTAB_step_by_step.cpp:9
double Mdouble
Definition: GeneralDefine.h:13
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
float * p
Definition: Tutorial_Map_using.cpp:9
Defines the basic properties that a interactable object can have.
Definition: BaseInteractable.h:34
Stores information about interactions between two interactable objects; often particles but could be ...
Definition: BaseInteraction.h:39
unsigned int identificationP_
Definition: BaseInteraction.h:494
void setBasicMPIInteractionValues(int P, int I, unsigned timeStamp, Vec3D force, Vec3D torque, bool isWallInteraction, bool resetPointers)
Definition: BaseInteraction.cc:944
void read(std::istream &is) override
Interaction read function, which accepts an std::istream as input.
Definition: BaseInteraction.cc:165
const Vec3D & getForce() const
Gets the current force (vector) between the two interacting objects.
Definition: BaseInteraction.h:189
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:322
~BaseInteraction() override
The destructor. It removes this interactions from the objects that were interacting,...
Definition: BaseInteraction.cc:103
const Vec3D & getTorque() const
Gets the current torque (vector) between the two interacting objects.
Definition: BaseInteraction.h:197
virtual void createMPIType()
Definition: BaseInteraction.cc:882
unsigned int getMultiContactIdentifier() const
Definition: BaseInteraction.cc:744
const BaseSpecies * species_
Definition: BaseInteraction.h:552
void writeInteraction(std::ostream &os, bool created) const
Writes information about a interaction to the interaction file.
Definition: BaseInteraction.cc:710
void importI(BaseInteractable *I)
Sets the second object involved in the interaction (often particle or wall).
Definition: BaseInteraction.cc:432
void setHandler(InteractionHandler *handler)
Sets the pointer to the interaction hander which is storing this interaction.
Definition: BaseInteraction.cc:241
void setIdentificationP(unsigned int identification)
Definition: BaseInteraction.cc:913
std::string getName() const override
Virtual function which allows interactions to be named.
Definition: BaseInteraction.cc:182
Mdouble getLagrangeMultiplier()
Definition: BaseInteraction.h:169
const Vec3D & getRelativeVelocity() const
Returns a constant reference to a vector of relative velocity.
Definition: BaseInteraction.cc:554
Mdouble getEffectiveMass() const
Returns a Mdouble to the effective radius of the interaction. (Not corrected for the overlap)
Definition: BaseInteraction.cc:792
void setAbsoluteNormalForce(Mdouble absoluteNormalForce)
the absolute values of the norm (length) of the normal force
Definition: BaseInteraction.cc:651
void setDistance(Mdouble distance)
Sets the interaction distance between the two interacting objects.
Definition: BaseInteraction.cc:201
Mdouble getAbsoluteNormalForce() const
Returns the absolute value of the norm (length) of the Normal force vector.
Definition: BaseInteraction.cc:577
virtual std::vector< Mdouble > getFieldVTK(unsigned i) const
Definition: BaseInteraction.cc:876
Vec3D torque_
Definition: BaseInteraction.h:531
Vec3D getIC() const
Definition: BaseInteraction.cc:447
virtual void getInteractionDetails(void *interactionDataArray, unsigned int index, unsigned int &identificationP, unsigned int &identificationI, bool &isWallInteraction, unsigned &timeStamp)
Definition: BaseInteraction.cc:906
bool isWallInteraction_
Definition: BaseInteraction.h:496
const Vec3D & getContactPoint() const
Gets constant reference to contact point (vector).
Definition: BaseInteraction.h:213
void setTimeStamp(unsigned timeStamp)
Updates the time step of the interacting. Note, time steps used to find completed interactions.
Definition: BaseInteraction.cc:231
virtual void computeForce()
Virtual function that contains the force law between the two objects interacting.
Definition: BaseInteraction.cc:675
Vec3D normal_
Definition: BaseInteraction.h:542
virtual bool isBonded() const
Definition: BaseInteraction.h:472
Vec3D force_
Definition: BaseInteraction.h:526
void setContactPoint(Vec3D contactPoint)
Set the location of the contact point between the two interacting objects.
Definition: BaseInteraction.cc:220
void setMultiContactIdentifier(unsigned int multiContactIdentifier_)
Definition: BaseInteraction.cc:749
const Vec3D & getNormal() const
Gets the normal vector between the two interacting objects.
Definition: BaseInteraction.h:205
virtual std::string getTypeVTK(unsigned i) const
Definition: BaseInteraction.cc:866
virtual Mdouble getTangentialOverlap() const
get the length of the current tangential overlap
Definition: BaseInteraction.cc:532
Mdouble absoluteNormalForce_
Definition: BaseInteraction.h:516
Mdouble getTimeStamp() const
Returns an Mdouble which is the time stamp of the interaction.
Definition: BaseInteraction.h:298
virtual Mdouble getElasticEnergy() const
Returns a Mdouble which is the current about of Elastic energy in the interaction.
Definition: BaseInteraction.cc:684
Mdouble lagrangeMultiplier_
Definition: BaseInteraction.h:557
BaseInteractable * P_
Definition: BaseInteraction.h:485
void gatherContactStatistics()
Definition: BaseInteraction.cc:808
void importP(BaseInteractable *P)
Sets the first object involved in the interaction (normally a particle).
Definition: BaseInteraction.cc:400
Mdouble normalRelativeVelocity_
Definition: BaseInteraction.h:511
void setP(BaseInteractable *P)
Sets the first object involved in the interaction (normally a particle).
Definition: BaseInteraction.cc:384
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:861
Vec3D getCP() const
Definition: BaseInteraction.cc:453
void setFStatData(std::fstream &fstat, BaseParticle *P, BaseWall *I)
Definition: BaseInteraction.cc:977
virtual void setMPIInteraction(void *interactionDataArray, unsigned int index, bool resetPointers)
Definition: BaseInteraction.cc:890
void removeFromHandler()
Removes this interaction from its interaction hander.
Definition: BaseInteraction.cc:303
void setWallInteraction(bool flag)
Definition: BaseInteraction.cc:933
bool isWallInteraction()
Definition: BaseInteraction.cc:938
Mdouble overlap_
Definition: BaseInteraction.h:547
virtual void deleteMPIInteractionDataArray(void *dataArray)
Definition: BaseInteraction.cc:900
virtual void * createMPIInteractionDataArray(unsigned int numberOfInteractions) const
Definition: BaseInteraction.cc:894
virtual void actionsAfterTimeStep()
Definition: BaseInteraction.cc:801
int identificationI_
Definition: BaseInteraction.h:495
const BaseInteractable * getI() const
Returns a constant pointer to the second object involved in the interaction.
Definition: BaseInteraction.h:287
const BaseInteractable * getP() const
Returns a constant pointer to the first object involved in the interaction.
Definition: BaseInteraction.h:276
void setI(BaseInteractable *I)
Sets the second object involved in the interaction (often particle or wall).
Definition: BaseInteraction.cc:416
void addForce(Vec3D force)
add an force increment to the total force.
Definition: BaseInteraction.cc:587
int getIdentificationI()
Definition: BaseInteraction.cc:928
Mdouble getDistance() const
Returns an Mdouble which is the norm (length) of distance vector.
Definition: BaseInteraction.cc:520
virtual std::string getNameVTK(unsigned i) const
Definition: BaseInteraction.cc:871
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:63
Vec3D contactPoint_
Definition: BaseInteraction.h:501
Mdouble getNormalRelativeVelocity() const
Returns a double which is the norm (length) of the relative velocity vector.
Definition: BaseInteraction.cc:565
const BaseSpecies * getBaseSpecies() const
Return a constant point to BaseSpecies of the interaction.
Definition: BaseInteraction.cc:663
virtual const Vec3D getTangentialForce() const
Definition: BaseInteraction.cc:544
void setLagrangeMultiplier(Mdouble multiplier)
Definition: BaseInteraction.h:164
virtual Mdouble getElasticEnergyAtEquilibrium(Mdouble adhesiveForce) const
Definition: BaseInteraction.h:413
Mdouble getEffectiveRadius() const
Returns a Mdouble to the effective radius of the interaction. (Not corrected for the overlap)
Definition: BaseInteraction.cc:774
virtual void integrate(Mdouble timeStep)
integrates variables of the interaction which need to be integrate e.g. the tangential overlap.
Definition: BaseInteraction.cc:359
unsigned timeStamp_
Definition: BaseInteraction.h:537
void setRelativeVelocity(Vec3D relativeVelocity)
set the relative velocity of the current of the interactions.
Definition: BaseInteraction.cc:630
void setNormal(Vec3D normal)
Sets the normal vector between the two interacting objects.
Definition: BaseInteraction.cc:192
void setSpecies(const BaseSpecies *species)
Set the Species of the interaction; note this can either be a Species or MixedSpecies.
Definition: BaseInteraction.cc:371
unsigned int getIdentificationP()
Definition: BaseInteraction.cc:923
BaseInteractable * getI()
Returns a pointer to the second object involved in the interaction (often a wall or a particle).
Definition: BaseInteraction.h:264
Mdouble distance_
Definition: BaseInteraction.h:521
BaseInteractable * I_
Definition: BaseInteraction.h:490
BaseInteractable * getP()
Returns a pointer to first object involved in the interaction (normally a particle).
Definition: BaseInteraction.h:253
Mdouble getContactRadius() const
Returns a Mdouble with the current contact between the two interacting objects.
Definition: BaseInteraction.cc:347
void write(std::ostream &os) const override
Interaction print function, which accepts an std::ostream as input.
Definition: BaseInteraction.cc:137
void writeToFStat(std::ostream &os, Mdouble time) const
Writes forces data to the FStat file.
Definition: BaseInteraction.cc:468
InteractionHandler * getHandler() const
Gets a point to the interaction handlers to which this interaction belongs.
Definition: BaseInteraction.cc:247
void setIdentificationI(int identification)
Definition: BaseInteraction.cc:918
void setNormalRelativeVelocity(Mdouble normalRelativeVelocit)
set the normal component of the relative velocity.
Definition: BaseInteraction.cc:641
void addTorque(Vec3D torque)
add a torque increment to the total torque.
Definition: BaseInteraction.cc:597
Vec3D getIP() const
Definition: BaseInteraction.cc:440
virtual void reverseHistory()
When periodic particles some interaction need certain history properties reversing....
Definition: BaseInteraction.cc:699
Mdouble getOverlapVolume() const
Returns the overlap volume between two interacting objects.
Definition: BaseInteraction.cc:257
virtual void getMPIInteraction(void *historyDataArray, unsigned int index) const
copies the history interactions into the data array
Definition: BaseInteraction.cc:886
void setForce(Vec3D force)
set total force (this is used by the normal force, tangential forces are added use addForce)
Definition: BaseInteraction.cc:608
void setTorque(Vec3D torque)
set the total force (this is used by the normal force, tangential torques are added use addTorque)
Definition: BaseInteraction.cc:619
Mdouble getOverlap() const
Returns a Mdouble with the current overlap between the two interacting objects.
Definition: BaseInteraction.h:219
unsigned multiContactIdentifier_
Definition: BaseInteraction.h:562
void setOverlap(Mdouble overlap)
Set the overlap between the two interacting object.
Definition: BaseInteraction.cc:211
virtual void rotateHistory(Matrix3D &rotationMatrix)
When periodic particles are used, some interactions need certain history properties rotated (e....
Definition: BaseInteraction.cc:755
Vec3D relativeVelocity_
Definition: BaseInteraction.h:506
InteractionHandler * handler_
Definition: BaseInteraction.h:480
BaseInteraction()
Definition: BaseInteraction.cc:43
It is an abstract base class due to the purely virtual functions declared below. Even if the function...
Definition: BaseObject.h:30
unsigned int getId() const
Returns the unique identifier of any particular object.
Definition: BaseObject.h:104
Definition: BaseParticle.h:33
BaseSpecies is the class from which all other species are derived.
Definition: BaseSpecies.h:29
Basic class for walls.
Definition: BaseWall.h:28
Container to store Interaction objects.
Definition: InteractionHandler.h:25
Implementation of a 3D matrix.
Definition: Kernel/Math/Matrix.h:17
Definition: Kernel/Math/Vector.h:30
#define I
Definition: main.h:127
double multiplier(const Vector< double > &xi)
Definition: disk_oscillation.cc:63
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:77
void normal(const Vector< double > &x, Vector< double > &normal)
Definition: free_surface_rotation.cc:65
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286