InteractionHandler Class Referencefinal

Container to store Interaction objects. More...

#include <InteractionHandler.h>

+ Inheritance diagram for InteractionHandler:

Public Member Functions

 InteractionHandler ()
 Default constructor, it creates an empty InteractionHandler. More...
 
 InteractionHandler (const InteractionHandler &IH UNUSED)
 Copy constructor, but since interactions must not be copied, it creates an empty InteractionHandler. More...
 
InteractionHandleroperator= (const InteractionHandler &rhs)
 Assignment operator. More...
 
 ~InteractionHandler () override
 Destructor, it destructs the InteractionHandler and all BaseInteraction it contains. More...
 
void addObject (BaseInteraction *I) override
 Adds an Interaction to the InteractionHandler. More...
 
void read (std::istream &is)
 
void readAndAddObject (std::istream &is) override
 Reads an Interaction into the InteractionHandler from restart data. More...
 
BaseInteractiongetExistingInteraction (const BaseInteractable *P, const BaseInteractable *I) const
 Returns the Interaction between the BaseInteractable's P and I if it exists, otherwise returns a null pointer. More...
 
BaseInteractionaddInteraction (BaseInteractable *P, BaseInteractable *I, unsigned timeStamp)
 
void resetNewObjectsOMP ()
 
void addNewObjectsOMP ()
 
BaseInteractiongetInteraction (BaseInteractable *P, BaseInteractable *I, unsigned timeStamp)
 Returns the Interaction between the BaseInteractable's P and I. More...
 
BaseInteractioncreateEmptyInteraction () const
 Creates an empty interaction. More...
 
void deleteEmptyInteraction (BaseInteraction *interaction) const
 Deletes an empty interaction. More...
 
void * createMPIInteractionDataArray (unsigned int numberOfInteractions) const
 creates an empty MPIInteractionDataArray More...
 
void deleteMPIInteractionDataArray (void *dataArray)
 deletes an MPIInteractionDataArray More...
 
void getInteractionDetails (void *interactionData, unsigned int index, unsigned int &identificationP, unsigned int &identificationI, bool &isWallInteraction, unsigned &timeStamp)
 reads the basic interaction details from an MPIInteractionDataArray More...
 
BaseInteractiongetInteraction (BaseInteractable *P, BaseInteractable *I, unsigned timeStamp, const Vec3D &normal)
 Returns the Interaction between the BaseInteractable's P and I closest to the contact point (should be used when multiple contacts are possible). More...
 
void removeObjectKeepingPeriodics (unsigned int id)
 Removes interactions of periodic particles when the periodic particles get deleted (see DPMBase::removeDuplicatePeriodicParticles) More...
 
void eraseOldInteractions (unsigned)
 erases interactions which have an old timestamp. More...
 
void actionsAfterTimeStep ()
 
Mdouble getMeanOverlap () const
 The mean overlap of all interactions. More...
 
void write (std::ostream &os) const
 Writes the InteractionHandler to an output stream, for example a restart file. More...
 
void setWriteVTK (FileType f)
 
void setWriteVTK (bool)
 
FileType getWriteVTK () const
 
std::string getName () const override
 Returns the name of the object. More...
 
double getLiquidBridgeVolume () const
 
unsigned getNumberOfLiquidBridges () const
 
unsigned getNumberOfWallContacts () const
 
- Public Member Functions inherited from BaseHandler< BaseInteraction >
 BaseHandler ()
 Default BaseHandler constructor, it creates an empty BaseHandler and assigns DPMBase_ to a null pointer. More...
 
 BaseHandler (const BaseHandler< BaseInteraction > &BH)
 Constructor that copies the objects of the given handler into itself and sets other variables to 0/nullptr. More...
 
virtual ~BaseHandler ()
 Destructor, it destructs the BaseHandler and all Object it contains. More...
 
void copyContentsFromOtherHandler (const BaseHandler< BaseInteraction > &BH)
 Function that copies the contents (vector of pointers, maxObject_, nextId_, DPMBase_) from one handler (container) to the other. More...
 
std::enable_if<!std::is_pointer< U >::value, U * >::type copyAndAddObject (const U &object)
 Creates a copy of a Object and adds it to the BaseHandler. More...
 
std::enable_if< std::is_pointer< U >::value, U >::type copyAndAddObject (const U object)
 Creates a copy of a Object and adds it to the BaseHandler. More...
 
std::enable_if<!std::is_pointer< U >::value, U * >::type copyAndAddGhostObject (const U &object)
 Creates a copy of a Object and adds it to the BaseHandler. This is one locally for inserting mpi particles, they avoid the global check if the particle can actually be inserted, because the mpi domain already knows that is the case. More...
 
std::enable_if< std::is_pointer< U >::value, U >::type copyAndAddGhostObject (const U object)
 Creates a copy of a Object and adds it to the BaseHandler. This is one locally for inserting mpi particles, they avoid the global check if the particle can actually be inserted, because the mpi domain already knows that is the case. More...
 
virtual void addExistingObject (BaseInteraction *O)
 Adds an existing object to the BaseHandler without changing the id of the object. More...
 
virtual void addObject (BaseInteraction *object)
 Adds a new Object to the BaseHandler. More...
 
virtual void addGhostObject (BaseInteraction *O)
 Adds a new Object to the BaseHandler. called by the to avoid increasing the id. More...
 
void removeIf (const std::function< bool(BaseInteraction *)> cond)
 
virtual void removeObject (unsigned const int index)
 Removes an Object from the BaseHandler. More...
 
virtual void removeObjects (std::vector< unsigned int > indices)
 
void removeLastObject ()
 Removes the last Object from the BaseHandler. More...
 
virtual void clear ()
 Empties the whole BaseHandler by removing all Objects and setting all other variables to 0. More...
 
void read (std::istream &is)
 Reads all objects from restart data. More...
 
BaseInteractiongetObjectById (const unsigned int id)
 Gets a pointer to the Object at the specified index in the BaseHandler. More...
 
std::vector< BaseInteraction * > getObjectsById (const unsigned int id)
 Gets a vector of pointers to the objects with the specific id. More...
 
BaseInteractiongetObject (const unsigned int id)
 Gets a pointer to the Object at the specified index in the BaseHandler.
More...
 
const BaseInteractiongetObject (const unsigned int id) const
 Gets a constant pointer to the Object at the specified index in the BaseHandler. More...
 
BaseInteractiongetLastObject ()
 Gets a pointer to the last Object in this BaseHandler. More...
 
const BaseInteractiongetLastObject () const
 Gets a constant pointer to the last Object in this BaseHandler. More...
 
virtual unsigned int getNumberOfObjects () const
 Gets the number of real Object in this BaseHandler. (i.e. no mpi or periodic particles) More...
 
unsigned int getSize () const
 Gets the size of the particleHandler (including mpi and periodic particles) More...
 
unsigned int getStorageCapacity () const
 Gets the storage capacity of this BaseHandler. More...
 
void setStorageCapacity (const unsigned int N)
 Sets the storage capacity of this BaseHandler. More...
 
void resize (const unsigned int N, const BaseInteraction &obj)
 Resizes the container to contain N elements. More...
 
const std::vector< BaseInteraction * >::const_iterator begin () const
 Gets the begin of the const_iterator over all Object in this BaseHandler. More...
 
const std::vector< BaseInteraction * >::iterator begin ()
 Gets the begin of the iterator over all BaseBoundary in this BaseHandler. More...
 
const std::vector< BaseInteraction * >::const_iterator end () const
 Gets the end of the const_iterator over all BaseBoundary in this BaseHandler. More...
 
const std::vector< BaseInteraction * >::iterator end ()
 Gets the end of the iterator over all BaseBoundary in this BaseHandler. More...
 
void setDPMBase (DPMBase *DPMBase)
 Sets the problem that is solved using this handler. More...
 
void setId (BaseInteraction *object, unsigned int id)
 
void increaseId ()
 
unsigned int getNextId ()
 
void setNextId (unsigned int id)
 
DPMBasegetDPMBase ()
 Gets the problem that is solved using this handler. More...
 
DPMBasegetDPMBase () const
 Gets the problem that is solved using this handler and does not change the class. More...
 
virtual void writeVTK () const
 now empty function for writing VTK files. More...
 
unsigned getNextGroupId ()
 Should be called each time you assign a groupId. Returns the value of nextGroupId_ and increases nextGroupId_ by one. More...
 

Public Attributes

std::vector< std::vector< BaseInteraction * > > newObjects_
 

Private Attributes

FileType writeVTK_
 
std::map< unsigned, BaseParticle * > particleById
 
std::map< unsigned, BaseWall * > wallById
 

Additional Inherited Members

- Protected Attributes inherited from BaseHandler< BaseInteraction >
std::vector< BaseInteraction * > objects_
 The actual list of Object pointers. More...
 

Detailed Description

Container to store Interaction objects.

The InteractionHandler is a container to store all Interaction objects. It is implemented as a vector of BaseInteraction pointers.

Constructor & Destructor Documentation

◆ InteractionHandler() [1/2]

InteractionHandler::InteractionHandler ( )

Default constructor, it creates an empty InteractionHandler.

Constructor of the ParticleHandler class. It creates and empty ParticleHandler.

24 {
26  logger(DEBUG, "InteractionHandler::InteractionHandler() finished");
27 }
@ NO_FILE
file will not be created/read
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
@ DEBUG
FileType writeVTK_
Definition: InteractionHandler.h:193

References DEBUG, logger, NO_FILE, and writeVTK_.

◆ InteractionHandler() [2/2]

InteractionHandler::InteractionHandler ( const InteractionHandler &IH  UNUSED)

Copy constructor, but since interactions must not be copied, it creates an empty InteractionHandler.

Parameters
[in]IHThe InteractionHandler that has to be copied.

This is not a copy constructor! It only clears all variables, since by default interactions are not copied.

Todo:
Please check if interactions indeed don't need to be copied.
37 {
38  writeVTK_ = IH.writeVTK_;
39  //By default interactions are not copied.
40  logger(DEBUG, "InteractionHandler::InteractionHandler(const "
41  "InteractionHandler &IH) finished, please note that no interactions"
42  " have been copied.");
43 }

References DEBUG, logger, and writeVTK_.

◆ ~InteractionHandler()

InteractionHandler::~InteractionHandler ( )
override

Destructor, it destructs the InteractionHandler and all BaseInteraction it contains.

60 {
61  logger(DEBUG, "InteractionHandler::~InteractionHandler() finished");
62 }

References DEBUG, and logger.

Member Function Documentation

◆ actionsAfterTimeStep()

void InteractionHandler::actionsAfterTimeStep ( )
376 {
377  for (auto i: *this)
378  {
379  i->actionsAfterTimeStep();
380  }
381 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9

References i.

Referenced by DPMBase::computeOneTimeStep(), and DPMBase::initialiseSolve().

◆ addInteraction()

BaseInteraction * InteractionHandler::addInteraction ( BaseInteractable P,
BaseInteractable I,
unsigned  timeStamp 
)
95 {
96  BaseSpecies* species = getDPMBase()->speciesHandler.getMixedObject(P->getIndSpecies(), I->getIndSpecies());
97  BaseInteraction* C = species->getNewInteraction(P, I, timeStamp);
98  addObject(C);
99  return C;
100 }
Matrix< Scalar, Dynamic, Dynamic > C
Definition: bench_gemm.cpp:49
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:733
Stores information about interactions between two interactable objects; often particles but could be ...
Definition: BaseInteraction.h:39
BaseSpecies is the class from which all other species are derived.
Definition: BaseSpecies.h:29
virtual BaseInteraction * getNewInteraction(BaseInteractable *P, BaseInteractable *I, unsigned timeStamp) const =0
returns new Interaction object.
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. LinearViscoelasticSpecies, etc.
Definition: DPMBase.h:1433
void addObject(BaseInteraction *I) override
Adds an Interaction to the InteractionHandler.
Definition: InteractionHandler.cc:67
std::enable_if<!std::is_pointer< typename U::MixedSpeciesType >::value, typename U::MixedSpeciesType * >::type getMixedObject(const U *S, const U *T)
Definition: SpeciesHandler.h:52
Definition: matrices.h:74
#define I
Definition: main.h:127
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:77

References addObject(), BaseHandler< BaseInteraction >::getDPMBase(), SpeciesHandler::getMixedObject(), BaseSpecies::getNewInteraction(), I, Global_Physical_Variables::P, and DPMBase::speciesHandler.

Referenced by DPMBase::readNextFStatFile().

◆ addNewObjectsOMP()

void InteractionHandler::addNewObjectsOMP ( )
109  {
110  for (auto objects : newObjects_) {
111  for (auto object : objects) {
112  addObject(object);
113  }
114  }
115 }
std::vector< std::vector< BaseInteraction * > > newObjects_
Definition: InteractionHandler.h:183

References addObject(), and newObjects_.

Referenced by DPMBase::computeAllForces().

◆ addObject()

void InteractionHandler::addObject ( BaseInteraction I)
override

Adds an Interaction to the InteractionHandler.

Parameters
[in]PA pointer to the BaseInteraction (or derived class) that has to be added.
68 {
69  //set the particleHandler pointer
70  I->setHandler(this);
71  //Puts the interaction in the Interaction list
73  I->getP()->addInteraction(I);
74  I->getI()->addInteraction(I);
75 }
virtual void addObject(T *object)
Adds a new Object to the BaseHandler.
Definition: BaseHandler.h:412

References BaseHandler< T >::addObject(), and I.

Referenced by addInteraction(), addNewObjectsOMP(), BaseInteraction::copySwitchPointer(), and getInteraction().

◆ createEmptyInteraction()

BaseInteraction * InteractionHandler::createEmptyInteraction ( ) const

Creates an empty interaction.

Returns the Interaction between the BaseInteractable's P and I.

Empty interactions are required when dealing with parallel code. it is used a proto type interaction that can handle the MPI interaction data type which is a void array

163 {
164  //NOTE: assuming the interaction type of a species is the same for all species
165  BaseSpecies* species = this->getDPMBase()->speciesHandler.getObject(0);
166  BaseInteraction* emptyInteraction = species->getEmptyInteraction();
167 
168  return emptyInteraction;
169 }
T * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:621
virtual BaseInteraction * getEmptyInteraction() const =0

References BaseHandler< BaseInteraction >::getDPMBase(), BaseSpecies::getEmptyInteraction(), BaseHandler< T >::getObject(), and DPMBase::speciesHandler.

Referenced by createMPIInteractionDataArray(), deleteMPIInteractionDataArray(), and getInteractionDetails().

◆ createMPIInteractionDataArray()

void * InteractionHandler::createMPIInteractionDataArray ( unsigned int  numberOfInteractions) const

creates an empty MPIInteractionDataArray

When sending interactions to other processors it is done with a void* array, because interactions come in many different sizes and shapes. The size of an interaction depends on the type f interaction. By creating an emptyInteraction, the size can be determined and an empty vector can be allocated

Parameters
[in]numberOfInteractionsThe number of interactions that are added to the MPIInteractionDataArray
Returns
Returns a void pointer to a block of memory that will contain the interaction data
192 {
193  BaseInteraction* emptyInteraction = this->createEmptyInteraction();
194  //create a vector based on the first interaction. This is to avoid templating the whole class
195  void* historyData = emptyInteraction->createMPIInteractionDataArray(numberOfInteractions);
196  this->deleteEmptyInteraction(emptyInteraction);
197 
198  return historyData;
199 }
virtual void * createMPIInteractionDataArray(unsigned int numberOfInteractions) const
Definition: BaseInteraction.cc:894
BaseInteraction * createEmptyInteraction() const
Creates an empty interaction.
Definition: InteractionHandler.cc:162
void deleteEmptyInteraction(BaseInteraction *interaction) const
Deletes an empty interaction.
Definition: InteractionHandler.cc:177

References createEmptyInteraction(), BaseInteraction::createMPIInteractionDataArray(), and deleteEmptyInteraction().

Referenced by PeriodicBoundaryHandler::collectInteractionData(), Domain::performBoundaryDataTransmission(), and PeriodicBoundaryHandler::performNewParticleTransmission().

◆ deleteEmptyInteraction()

void InteractionHandler::deleteEmptyInteraction ( BaseInteraction interaction) const

Deletes an empty interaction.

When handling the Interaction MPI data type, an empty interaction is created. This function destroys that empty function again

Parameters
[in,out]interactionPointer to a base interaction that needs to be deleted
178 {
179  BaseSpecies* species = this->getDPMBase()->speciesHandler.getObject(0);
180  species->deleteEmptyInteraction(interaction);
181 }
virtual void deleteEmptyInteraction(BaseInteraction *interaction) const =0

References BaseSpecies::deleteEmptyInteraction(), BaseHandler< BaseInteraction >::getDPMBase(), BaseHandler< T >::getObject(), and DPMBase::speciesHandler.

Referenced by createMPIInteractionDataArray(), deleteMPIInteractionDataArray(), and getInteractionDetails().

◆ deleteMPIInteractionDataArray()

void InteractionHandler::deleteMPIInteractionDataArray ( void *  dataArray)

deletes an MPIInteractionDataArray

An empty interaction is created that can recast the data array into an array of the interactions. After the conversion the data of the array is cleaned up

Parameters
[in]dataArrayvoid pointer to a data array
208 {
209  BaseInteraction* emptyInteraction = this->createEmptyInteraction();
210  emptyInteraction->deleteMPIInteractionDataArray(dataArray);
211  this->deleteEmptyInteraction(emptyInteraction);
212 }
virtual void deleteMPIInteractionDataArray(void *dataArray)
Definition: BaseInteraction.cc:900

References createEmptyInteraction(), deleteEmptyInteraction(), and BaseInteraction::deleteMPIInteractionDataArray().

Referenced by Domain::finaliseBoundaryDataTransmission().

◆ eraseOldInteractions()

void InteractionHandler::eraseOldInteractions ( unsigned  currentNTime)

erases interactions which have an old timestamp.

Each interaction contains a time stamp, which stores the last time that an interaction object has been called. Thus, one can see that an interaction has ended by comparing the time stamp with the last value of DPMBase::time_. This function erases all interactions that have ended.

Parameters
[in]lastTimeStepthe last used value of DPMBase::time_.
Todo:
TW: this function has to be sped up with sth like this: erase(remove_if(begin(), end(), bind2nd(checkSpringTime(), lastTimeStep)), end());
358 {
359  //std::cout<<"void InteractionHandler::eraseOldInteractions(Mdouble lastTimeStep)"<<std::endl;
360  //std::cout<<"Current interactions="<<getNumberOfObjects()<<std::endl;
361  //Remove_if reconstructs the vector with only elements passing the check_spring_time function
362  //Erase removes the end of the vector
364  for (unsigned int id = 0; id < getNumberOfObjects(); id++)
365  {
366  if (getObject(id)->getTimeStamp() <= currentNTime)
367  {
368  getObject(id)->actionsOnErase();
369  removeObject(id);
370  --id;
371  }
372  }
373 }
virtual void removeObject(unsigned const int index)
Removes an Object from the BaseHandler.
Definition: BaseHandler.h:453
virtual unsigned int getNumberOfObjects() const
Gets the number of real Object in this BaseHandler. (i.e. no mpi or periodic particles)
Definition: BaseHandler.h:656
Mdouble getTimeStamp() const
Returns an Mdouble which is the time stamp of the interaction.
Definition: BaseInteraction.h:298
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

References BaseInteraction::actionsOnErase(), BaseHandler< BaseInteraction >::getNumberOfObjects(), BaseHandler< BaseInteraction >::getObject(), BaseInteraction::getTimeStamp(), and BaseHandler< BaseInteraction >::removeObject().

Referenced by DPMBase::computeOneTimeStep().

◆ getExistingInteraction()

BaseInteraction * InteractionHandler::getExistingInteraction ( const BaseInteractable P,
const BaseInteractable I 
) const

Returns the Interaction between the BaseInteractable's P and I if it exists, otherwise returns a null pointer.

Parameters
[in]Pthe first BaseInteractable by which the interaction is defined.
[in]Ithe first BaseInteractable by which the interaction is defined.
Returns
the Interaction between the BaseInteractable's P and I, if it exists.
84 {
85  //for particle-particle collision it is assumed BaseInteractable P has a lower index then I, so we only have to check for I, not P
86  for (const auto i : P->getInteractions()) {
87  if (i->getI() == I) {
88  return i;
89  }
90  }
91  return nullptr;
92 }

References i, I, and Global_Physical_Variables::P.

Referenced by MeshTriangle::checkInteractions(), getInteraction(), and removeObjectKeepingPeriodics().

◆ getInteraction() [1/2]

BaseInteraction * InteractionHandler::getInteraction ( BaseInteractable P,
BaseInteractable I,
unsigned  timeStamp 
)

Returns the Interaction between the BaseInteractable's P and I.

Returns a pointer to the existing Interaction, if the Interaction already exists otherwise creates a new Interaction and returns a pointer to it.

Parameters
[in]Pthe first BaseInteractable by which the interaction is defined.
[in]Ithe first BaseInteractable by which the interaction is defined.
[in]timeStampthe current value of DPMBase::time_.
Returns
the Interaction between the BaseInteractable's P and I
Todo:
TW this can bet set earlier
127 {
128  const BaseSpecies* const species = getDPMBase()->speciesHandler.getMixedObject(P->getIndSpecies(),
129  I->getIndSpecies());
130 
132  if (C == nullptr) {
133  C = species->getNewInteraction(P, I, timeStamp);
134  #ifdef MERCURYDPM_USE_OMP
135  if (omp_get_num_threads()>1) {
136  newObjects_[omp_get_thread_num()].push_back(C);
137  C->setHandler(this);
138  } else {
139  addObject(C);
140  }
141  #else
142  addObject(C);
143  #endif
144  }
145 
146  //set timeStamp
147  C->setTimeStamp(timeStamp);
148 
150  //set species of collision
151  C->setSpecies(species);
152 
153  return C;
154 }
BaseInteraction * getExistingInteraction(const BaseInteractable *P, const BaseInteractable *I) const
Returns the Interaction between the BaseInteractable's P and I if it exists, otherwise returns a null...
Definition: InteractionHandler.cc:83

References addObject(), BaseHandler< BaseInteraction >::getDPMBase(), getExistingInteraction(), SpeciesHandler::getMixedObject(), BaseSpecies::getNewInteraction(), I, newObjects_, Global_Physical_Variables::P, and DPMBase::speciesHandler.

Referenced by BaseParticle::getInteractionWith(), ArcWall::getInteractionWith(), BaseWall::getInteractionWith(), Combtooth::getInteractionWith(), MeshTriangle::getInteractionWith(), SineWall::getInteractionWith(), TriangleMeshWall::getInteractionWith(), TriangulatedWall::getInteractionWith(), VChute::getInteractionWith(), SuperQuadricParticle::getInteractionWithSuperQuad(), main(), readAndAddObject(), MeltableForceLawSelfTest::setupInitialConditions(), ThermalConductionSelfTest::setupInitialConditions(), ChargedBondedInteractionSelfTest::setupInitialConditions(), TwoBondedParticleElasticCollision::setupInitialConditions(), UnionOfWalls::setupInitialConditions(), ChargedBondedParticleUnitTest::setupInitialConditions(), and MultiParticlesInsertion::setupInitialConditions().

◆ getInteraction() [2/2]

BaseInteraction * InteractionHandler::getInteraction ( BaseInteractable P,
BaseInteractable I,
unsigned  timeStamp,
const Vec3D normal 
)

Returns the Interaction between the BaseInteractable's P and I closest to the contact point (should be used when multiple contacts are possible).

Returns a pointer to the existing Interaction, if the Interaction already exists otherwise creates a new Interaction and returns a pointer to it.

Parameters
[in]Pthe first BaseInteractable by which the interaction is defined.
[in]Ithe first BaseInteractable by which the interaction is defined.
[in]timeStampthe current value of DPMBase::time_.
Returns
the Interaction between the BaseInteractable's P and I
245 {
246  BaseInteraction* c = nullptr;
247  Mdouble dNormalMax = 0.9; //minimal agreement required
248  for (const auto& i : P->getInteractions())
249  {
250  if (i->getI() == I && i->getTimeStamp() != timeStamp)
251  {
252  const Mdouble dNormal = Vec3D::dot(normal, i->getNormal());
253  if (dNormal > dNormalMax)
254  {
255  c = i;
256  dNormalMax = dNormal;
257  }
258  }
259  }
260 
261  BaseSpecies* species = getDPMBase()->speciesHandler.getMixedObject(P->getIndSpecies(), I->getIndSpecies());
262 
263  if (c)
264  {
265  c->setTimeStamp(timeStamp);
266  }
267  else
268  {
269  c = species->getNewInteraction(P, I, timeStamp);
270  c->setSpecies(species);
271  addObject(c);
272  //logger(INFO,"new interaction t=%: i=%, n=%",timeStamp,getNumberOfObjects(),normal);
273  }
274 
275  return c;
276 }
static Mdouble dot(const Vec3D &a, const Vec3D &b)
Calculates the dot product of two Vec3D: .
Definition: Vector.cc:56
void normal(const Vector< double > &x, Vector< double > &normal)
Definition: free_surface_rotation.cc:65
int c
Definition: calibrate.py:100

References addObject(), calibrate::c, Vec3D::dot(), BaseHandler< BaseInteraction >::getDPMBase(), SpeciesHandler::getMixedObject(), BaseSpecies::getNewInteraction(), i, I, WallFunction::normal(), Global_Physical_Variables::P, and DPMBase::speciesHandler.

◆ getInteractionDetails()

void InteractionHandler::getInteractionDetails ( void *  interactionData,
unsigned int  index,
unsigned int identificationP,
unsigned int identificationI,
bool isWallInteraction,
unsigned timeStamp 
)

reads the basic interaction details from an MPIInteractionDataArray

because the interactionData array is a void pointer array, it is not possibly to directly read out the interaction data this function reads the basic information such as which objects are interacting and at what time.

Parameters
[in]interactionDatavoid pointer to the mpi interaction data
[in]indexThe index of the interaction in the interaction data
[out]identificationPthe unique id of the P object
[out]idientificationIthe unique id of the I object
[out]isWallInteractiona bool that flags if the interaction is a wall interaction or not
[out]timeStampreads the timestamp of the interaction
228 {
229  BaseInteraction* emptyInteraction = this->createEmptyInteraction();
230  emptyInteraction->getInteractionDetails(interactionData, index, identificationP, identificationI, isWallInteraction,
231  timeStamp);
232  this->deleteEmptyInteraction(emptyInteraction);
233 }
virtual void getInteractionDetails(void *interactionDataArray, unsigned int index, unsigned int &identificationP, unsigned int &identificationI, bool &isWallInteraction, unsigned &timeStamp)
Definition: BaseInteraction.cc:906

References createEmptyInteraction(), deleteEmptyInteraction(), and BaseInteraction::getInteractionDetails().

Referenced by PeriodicBoundaryHandler::processLocalInteractionData(), PeriodicBoundaryHandler::processReceivedInteractionData(), and Domain::processReceivedInteractionData().

◆ getLiquidBridgeVolume()

double InteractionHandler::getLiquidBridgeVolume ( ) const
544  {
545  double liquidVolume = 0;
546  for (auto i : objects_) {
547  auto j = dynamic_cast<LiquidMigrationWilletInteraction*>(i);
548  if (j and !static_cast<BaseParticle*>(j->getP())->isMPIParticle()) liquidVolume += j->getLiquidBridgeVolume();
549  }
550  return getMPISum(liquidVolume);
551 };
Vec3D getMPISum(Vec3D &val)
Definition: MpiDataClass.cc:178
std::vector< BaseInteraction * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:283
Definition: BaseParticle.h:33
bool isMPIParticle() const
Indicates if this particle is a ghost in the MPI domain.
Definition: BaseParticle.cc:164
Defines the liquid bridge willet interaction between two particles or walls.
Definition: LiquidMigrationWilletInteraction.h:30
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References getMPISum(), i, BaseParticle::isMPIParticle(), j, and BaseHandler< BaseInteraction >::objects_.

Referenced by LiquidMigrationMPI2Test::printTime(), and EvaporationAndHeatTest::printTime().

◆ getMeanOverlap()

Mdouble InteractionHandler::getMeanOverlap ( ) const

The mean overlap of all interactions.

Returns
The mean overlap of all interactions
387 {
388  Mdouble sum = 0;
389  Mdouble n = 0;
390  for (BaseInteraction* const p : objects_)
391  {
392  if (p->getOverlap() > 0)
393  {
394  sum += p->getOverlap();
395  n++;
396  }
397  }
398  return sum / n;
399 }
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
float * p
Definition: Tutorial_Map_using.cpp:9

References n, BaseHandler< BaseInteraction >::objects_, and p.

Referenced by InitialConditions< SpeciesType >::getMeanRelativeContactRadius(), Sintering::getMeanRelativeContactRadius(), regimeForceUnitTest::getMeanRelativeContactRadius(), GranuDrum::printTime(), Drum::printTime(), RotatingDrumWet::printTime(), and RotatingDrumBidisperse::printTime().

◆ getName()

std::string InteractionHandler::getName ( ) const
overridevirtual

Returns the name of the object.

Returns
the string InteractionHandler

Implements BaseHandler< BaseInteraction >.

405 {
406  return "InteractionHandler";
407 }

Referenced by read().

◆ getNumberOfLiquidBridges()

unsigned InteractionHandler::getNumberOfLiquidBridges ( ) const
553  {
554  int liquidBridges = 0;
555  for (auto i : objects_) {
556  auto j = dynamic_cast<LiquidMigrationWilletInteraction*>(i);
557  if (j and !static_cast<BaseParticle*>(j->getP())->isMPIParticle() && j->getLiquidBridgeVolume()>0) liquidBridges++;
558  }
559  return getMPISum(liquidBridges);
560 };

References getMPISum(), i, BaseParticle::isMPIParticle(), j, and BaseHandler< BaseInteraction >::objects_.

Referenced by RotatingDrumWet::printTime().

◆ getNumberOfWallContacts()

unsigned InteractionHandler::getNumberOfWallContacts ( ) const
562  {
563  unsigned nWall = 0;
564  for (auto i : *this) {
565  if (dynamic_cast<BaseParticle*>(i->getI()) == nullptr) nWall++;
566  }
567  return nWall;
568 }

References i.

◆ getWriteVTK()

FileType InteractionHandler::getWriteVTK ( ) const

◆ operator=()

InteractionHandler & InteractionHandler::operator= ( const InteractionHandler rhs)

Assignment operator.

Parameters
[in]rhsThe BoundaryHandler on the right hand side of the assignment.
49 {
50  if (this != &rhs)
51  {
52  clear();
53  }
54  writeVTK_ = rhs.writeVTK_;
55  logger(DEBUG, "InteractionHandler::operator =(const InteractionHandler& rhs) finished.");
56  return *this;
57 }
virtual void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0.
Definition: BaseHandler.h:536

References BaseHandler< BaseInteraction >::clear(), DEBUG, logger, and writeVTK_.

◆ read()

void InteractionHandler::read ( std::istream &  is)
Parameters
[in]isThe input stream from which the information is read.
435 {
436  clear();
437  unsigned int N;
438  std::string dummy;
439  is >> dummy;
440  std::stringstream line;
442  line >> N;
443  if (N > 1e5)
444  {
445  logger(INFO, "Reading % %", N, dummy);
446  }
447  logger(VERBOSE, "In %::read(is): reading in % objects.", getName(), N);
449  // set map
450  particleById.clear();
451  for (BaseParticle* p: getDPMBase()->particleHandler)
452  {
453  particleById[p->getId()] = p;
454  }
455  wallById.clear();
456  for (BaseWall* w: getDPMBase()->wallHandler)
457  {
458  wallById[w->getId()] = w;
459  }
460  for (unsigned int i = 0; i < N; i++)
461  {
462  readAndAddObject(is);
463  }
464  particleById.clear();
465  wallById.clear();
466 }
@ INFO
@ VERBOSE
RowVector3d w
Definition: Matrix_resize_int.cpp:3
void setStorageCapacity(const unsigned int N)
Sets the storage capacity of this BaseHandler.
Definition: BaseHandler.h:677
Basic class for walls.
Definition: BaseWall.h:28
std::string getName() const override
Returns the name of the object.
Definition: InteractionHandler.cc:404
void readAndAddObject(std::istream &is) override
Reads an Interaction into the InteractionHandler from restart data.
Definition: InteractionHandler.cc:472
std::map< unsigned, BaseWall * > wallById
Definition: InteractionHandler.h:196
std::map< unsigned, BaseParticle * > particleById
Definition: InteractionHandler.h:195
@ N
Definition: constructor.cpp:22
line
Definition: calibrate.py:103
void getLineFromStringStream(std::istream &in, std::stringstream &out)
Reads a line from one stringstream into another, and prepares the latter for reading in.
Definition: StringHelpers.cc:41
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286

References BaseHandler< BaseInteraction >::clear(), BaseHandler< BaseInteraction >::getDPMBase(), helpers::getLineFromStringStream(), getName(), i, INFO, calibrate::line, logger, N, p, particleById, readAndAddObject(), BaseHandler< BaseInteraction >::setStorageCapacity(), oomph::Global_string_for_annotation::string(), VERBOSE, w, and wallById.

Referenced by DPMBase::read().

◆ readAndAddObject()

void InteractionHandler::readAndAddObject ( std::istream &  is)
overridevirtual

Reads an Interaction into the InteractionHandler from restart data.

Parameters
[in]isThe input stream from which the information is read.
Todo:
Ant This is a tmp fix as in some cases the line before has not be finished reading. This should be looked at again at a later date.
Todo:
TW: Change identifier in restart file from id to index; is there any reason the id should be kept after restarting, once this is done? (Note, the id is set to the old one in the particle handler because interactions store id, not indices; also note id's are slow

Implements BaseHandler< BaseInteraction >.

473 {
474  std::string type, dummy, idType;
475  unsigned int id0, id1;
476  unsigned timeStamp;
477 
479  is >> type;
480  logger(DEBUG, "InteractionHandler::readAndAddObject(is): reading type %.", type);
481  Mdouble timeStampDouble;
482  is >> idType >> id0 >> id1 >> dummy >> timeStampDouble;
483  timeStamp = timeStampDouble; //in order to read old restart files
484 
487 
488 #ifdef MERCURYDPM_USE_MPI
489  if (idType.compare("particleIds") == 0)
490  {
491  std::vector<BaseParticle*> list0 = getDPMBase()->particleHandler.getObjectsById(id0);
492  std::vector<BaseParticle*> list1 = getDPMBase()->particleHandler.getObjectsById(id1);
493  for (int p0 = 0; p0 < list0.size(); p0++)
494  {
495  for (int p1 = 0; p1 < list1.size(); p1++)
496  {
497  C = getInteraction(list0[p0],list1[p1], timeStamp);
498  if (C != nullptr)
499  {
500  is >> *C;
501  }
502  }
503  }
504 
505  }
506  else
507  {
508  std::vector<BaseParticle*> list0 = getDPMBase()->particleHandler.getObjectsById(id0);
509  for (int p0 = 0; p0 < list0.size(); p0++)
510  {
511  C = getInteraction(list0[p0],getDPMBase()->wallHandler.getObjectById(id1), timeStamp);
512  if (C != nullptr)
513  {
514  is >> *C;
515  }
516  }
517  }
518 #else
519  //this requires particleById/wallById to be set, which is done in the read() function
520  if (idType == "particleIds")
521  C = getInteraction(particleById[id0],particleById[id1],timeStamp);
522  else
523  C = getInteraction(particleById[id0],wallById[id1], timeStamp);
524  is >> (*C);
525 #endif
527 }
Vector3f p0
Definition: MatrixBase_all.cpp:2
Vector3f p1
Definition: MatrixBase_all.cpp:2
std::vector< T * > getObjectsById(const unsigned int id)
Gets a vector of pointers to the objects with the specific id.
Definition: BaseHandler.h:601
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created.
Definition: DPMBase.h:1443
BaseInteraction * getInteraction(BaseInteractable *P, BaseInteractable *I, unsigned timeStamp)
Returns the Interaction between the BaseInteractable's P and I.
Definition: InteractionHandler.cc:126
#define max(a, b)
Definition: datatypes.h:23
type
Definition: compute_granudrum_aor.py:141

References DEBUG, BaseHandler< BaseInteraction >::getDPMBase(), getInteraction(), BaseHandler< T >::getObjectsById(), logger, max, p0, p1, particleById, DPMBase::particleHandler, oomph::Global_string_for_annotation::string(), compute_granudrum_aor::type, and wallById.

Referenced by read().

◆ removeObjectKeepingPeriodics()

void InteractionHandler::removeObjectKeepingPeriodics ( unsigned int  id)

Removes interactions of periodic particles when the periodic particles get deleted (see DPMBase::removeDuplicatePeriodicParticles)

Deleting the three periodic interactions between two real particles is difficult, because its interaction information has to be saved. If the two real particles interacted (which can be checked by looking at the time stamp), the interaction between the real particles is kept, and all interactions that involve ghost particles gets removed; otherwise, the interaction between the lower-indexed real particle with the ghost particle of the higher indexed particles is saved (with the ghost particle replaced by the real particle), and all other interactions removed.

This is what this function is intended for, and it does it in the following way: When an interaction is removed the periodic particle has to be stored in the I pointer So when an interaction is removed where P is normal and I is periodic, and the information is new it will be transfered when the index of P is lower than the index of the real particle of I.

Parameters
[in]theid of the Interaction that needs to be deleted.
Todo:
TW The code assumes in a few places that P->getIndex()<I->getIndex(), but the copySwitchPointer function does not obey that rule; we have to check if this is valid behaviour.
Todo:
this function will create an error if the timeStamp is in the future! This should not happen (ever), but who knows.
297 {
298  BaseInteraction* iMain = getObject(id);
299 
300  BaseParticle* P = dynamic_cast<BaseParticle*>(iMain->getP());
301  BaseParticle* I = dynamic_cast<BaseParticle*>(iMain->getI());
302  if (P != nullptr && I != nullptr) //check that both P and I are particles (not walls)
303  {
304  BaseInteractable* realI = I->getPeriodicFromParticle();
305  if (realI != nullptr && !P->getPeriodicFromParticle()) //check that P is a real and I is a ghost particle
306  {
307  if (P->getIndex() < realI->getIndex())
308  {
309  BaseInteraction* iOther = getExistingInteraction(P, realI);
310  //You have to also check for existing interactions of the particles in reverse order since the copySwitchPointer function can revert the order of the particles
312  if (iOther == nullptr)
313  {
314  iOther = getExistingInteraction(realI, P);
315  }
316  if (iOther != nullptr) //if the interaction existed before the ghost particles were created
317  {
318  //Here we decide which of the two interactions should be kept:
319  //the interaction between the two real particles (iMain), or
320  //the interaction between the real and a ghost particle (iOther).
321  //It picks the one for which a collision has happened,
322  //i.e. the one with the newer timeStamp.
324  if (iOther->getTimeStamp() <
325  iMain->getTimeStamp()) //if the interaction has been active during the last computeForce routine, make this the new (real) interaction.
326 
327  {
328  iMain->setI(realI);
329  removeObject(iOther->getIndex());
330  return;
331  }
332  else //if the interaction has not been active during the last computeForce routine
333  {
335  return;
336  }
337  }
338  else //if the interaction has been created during the last computeForce routine, make this a new (real) interaction.
339  {
340  iMain->setI(realI);
341  return;
342  }
343  }
344  }
345  }
346  //this point is reached if either P or I are walls, or P and I are both ghost particles; in these cases, the interaction gets deleted
348 }
Defines the basic properties that a interactable object can have.
Definition: BaseInteractable.h:34
void setI(BaseInteractable *I)
Sets the second object involved in the interaction (often particle or wall).
Definition: BaseInteraction.cc:416
BaseInteractable * getI()
Returns a pointer to the second object involved in the interaction (often a wall or a particle).
Definition: BaseInteraction.h:264
BaseInteractable * getP()
Returns a pointer to first object involved in the interaction (normally a particle).
Definition: BaseInteraction.h:253
unsigned int getIndex() const
Returns the index of the object in the handler.
Definition: BaseObject.h:97

References getExistingInteraction(), BaseInteraction::getI(), BaseObject::getIndex(), BaseHandler< BaseInteraction >::getObject(), BaseInteraction::getP(), BaseInteraction::getTimeStamp(), I, Global_Physical_Variables::P, BaseHandler< T >::removeObject(), BaseHandler< BaseInteraction >::removeObject(), and BaseInteraction::setI().

Referenced by SilbertPeriodic::add_flow_particles(), and DPMBase::removeDuplicatePeriodicParticles().

◆ resetNewObjectsOMP()

void InteractionHandler::resetNewObjectsOMP ( )
102  {
103  #ifdef MERCURYDPM_USE_OMP
104  newObjects_.clear();
105  newObjects_.resize(getDPMBase()->getNumberOfOMPThreads());
106  #endif
107 }

References BaseHandler< BaseInteraction >::getDPMBase(), and newObjects_.

Referenced by DPMBase::computeAllForces().

◆ setWriteVTK() [1/2]

void InteractionHandler::setWriteVTK ( bool  writeVTK)
535 {
537 }
@ MULTIPLE_FILES
each time-step will be written into/read from separate files numbered consecutively: name_....
virtual void writeVTK() const
now empty function for writing VTK files.
Definition: BaseHandler.h:267

References MULTIPLE_FILES, NO_FILE, BaseHandler< BaseInteraction >::writeVTK(), and writeVTK_.

◆ setWriteVTK() [2/2]

void InteractionHandler::setWriteVTK ( FileType  f)

◆ write()

void InteractionHandler::write ( std::ostream &  os) const

Writes the InteractionHandler to an output stream, for example a restart file.

Parameters
[in]osThe output stream where the InteractionHandler must be written to, usually a restart file.
414 {
415 #ifdef MERCURYDPM_USE_MPI
416  //note: this function only prints the particles on processor 0
417  //The rest of the particles are processed in the restart file write function
418  MPIContainer& communicator = MPIContainer::Instance();
419  unsigned int totalNumberOfInteractions = getNumberOfObjects();
420  os << "Interactions " << totalNumberOfInteractions << '\n';
421  //logger(INFO,"% interactions",getNumberOfObjects());
422  for (BaseInteraction* it : *this)
423  {
424  os << (*it) << '\n';
425  }
426 #else
427  os << "Interactions " << getNumberOfObjects() << '\n';
428  for (BaseInteraction* i : objects_)
429  os << (*i) << '\n';
430 #endif
431 }
This class contains all information and functions required for communication between processors.
Definition: MpiContainer.h:109
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:113

References BaseHandler< BaseInteraction >::getNumberOfObjects(), i, MPIContainer::Instance(), and BaseHandler< BaseInteraction >::objects_.

Referenced by DPMBase::write().

Member Data Documentation

◆ newObjects_

std::vector<std::vector<BaseInteraction*> > InteractionHandler::newObjects_

◆ particleById

std::map<unsigned,BaseParticle*> InteractionHandler::particleById
private

Referenced by read(), and readAndAddObject().

◆ wallById

std::map<unsigned,BaseWall*> InteractionHandler::wallById
private

Referenced by read(), and readAndAddObject().

◆ writeVTK_

FileType InteractionHandler::writeVTK_
private

The documentation for this class was generated from the following files: