revision: v0.14
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)
 
FileType getWriteVTK () const
 
std::string getName () const override
 Returns the name of the object. More...
 
double getLiquidBridgeVolume () 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...
 
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 std::string getName () const=0
 Gets the name of this handler. 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.

44 {
45  writeVTK_ = FileType::NO_FILE;
46  logger(DEBUG, "InteractionHandler::InteractionHandler() finished");
47 }

References FATAL, logger, 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.
57 {
58  writeVTK_ = IH.writeVTK_;
59  //By default interactions are not copied.
60  logger(DEBUG, "InteractionHandler::InteractionHandler(const "
61  "InteractionHandler &IH) finished, please note that no interactions"
62  " have been copied.");
63 }

References FATAL, logger, and writeVTK_.

◆ ~InteractionHandler()

InteractionHandler::~InteractionHandler ( )
override

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

80 {
81  logger(DEBUG, "InteractionHandler::~InteractionHandler() finished");
82 }

References FATAL, and logger.

Member Function Documentation

◆ actionsAfterTimeStep()

void InteractionHandler::actionsAfterTimeStep ( )
399 {
400  for (auto i: *this)
401  {
402  i->actionsAfterTimeStep();
403  }
404 }

References constants::i.

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

◆ addInteraction()

◆ addNewObjectsOMP()

void InteractionHandler::addNewObjectsOMP ( )
132  {
133  for (auto objects : newObjects_) {
134  for (auto object : objects) {
135  addObject(object);
136  }
137  }
138 }

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.
88 {
89  //set the particleHandler pointer
90  I->setHandler(this);
91  //Puts the interaction in the Interaction list
93  I->getP()->addInteraction(I);
94  I->getI()->addInteraction(I);
95 }

References BaseInteractable::addInteraction(), BaseHandler< T >::addObject(), BaseInteraction::getI(), BaseInteraction::getP(), and BaseInteraction::setHandler().

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

186 {
187  //NOTE: assuming the interaction type of a species is the same for all species
188  BaseSpecies* species = this->getDPMBase()->speciesHandler.getObject(0);
189  BaseInteraction* emptyInteraction = species->getEmptyInteraction();
190 
191  return emptyInteraction;
192 }

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
215 {
216  BaseInteraction* emptyInteraction = this->createEmptyInteraction();
217  //create a vector based on the first interaction. This is to avoid templating the whole class
218  void* historyData = emptyInteraction->createMPIInteractionDataArray(numberOfInteractions);
219  this->deleteEmptyInteraction(emptyInteraction);
220 
221  return historyData;
222 }

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
201 {
202  BaseSpecies* species = this->getDPMBase()->speciesHandler.getObject(0);
203  species->deleteEmptyInteraction(interaction);
204 }

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
231 {
232  BaseInteraction* emptyInteraction = this->createEmptyInteraction();
233  emptyInteraction->deleteMPIInteractionDataArray(dataArray);
234  this->deleteEmptyInteraction(emptyInteraction);
235 }

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());
381 {
382  //std::cout<<"void InteractionHandler::eraseOldInteractions(Mdouble lastTimeStep)"<<std::endl;
383  //std::cout<<"Current interactions="<<getNumberOfObjects()<<std::endl;
384  //Remove_if reconstructs the vector with only elements passing the check_spring_time function
385  //Erase removes the end of the vector
387  for (unsigned int id = 0; id < getNumberOfObjects(); id++)
388  {
389  if (getObject(id)->getTimeStamp() <= currentNTime)
390  {
391  getObject(id)->actionsOnErase();
392  removeObject(id);
393  --id;
394  }
395  }
396 }

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.
104 {
105  //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
106  {
107  for (unsigned j = 0; j < P->getInteractions().size(); ++j) {
108  auto i = P->getInteractions()[j];
109  if (i->getI() == I) {
110  return i;
111  }
112  }
113  }
114  return nullptr;
115 }

References BaseInteractable::getInteractions(), and constants::i.

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
150 {
151  const BaseSpecies* const species = getDPMBase()->speciesHandler.getMixedObject(P->getIndSpecies(),
152  I->getIndSpecies());
153 
155  if (C == nullptr) {
156  C = species->getNewInteraction(P, I, timeStamp);
157  #ifdef MERCURY_USE_OMP
158  if (omp_get_num_threads()>1) {
159  newObjects_[omp_get_thread_num()].push_back(C);
160  C->setHandler(this);
161  } else {
162  addObject(C);
163  }
164  #else
165  addObject(C);
166  #endif
167  }
168 
169  //set timeStamp
170  C->setTimeStamp(timeStamp);
171 
173  //set species of collision
174  C->setSpecies(species);
175 
176  return C;
177 }

References addObject(), BaseHandler< BaseInteraction >::getDPMBase(), getExistingInteraction(), BaseInteractable::getIndSpecies(), SpeciesHandler::getMixedObject(), BaseSpecies::getNewInteraction(), newObjects_, BaseInteraction::setHandler(), BaseInteraction::setSpecies(), BaseInteraction::setTimeStamp(), and DPMBase::speciesHandler.

Referenced by BaseParticle::getInteractionWith(), ArcWall::getInteractionWith(), BaseWall::getInteractionWith(), Combtooth::getInteractionWith(), MeshTriangle::getInteractionWith(), SineWall::getInteractionWith(), TriangulatedWall::getInteractionWith(), VChute::getInteractionWith(), SuperQuadricParticle::getInteractionWithSuperQuad(), main(), readAndAddObject(), ChargedBondedInteractionSelfTest::setupInitialConditions(), TwoBondedParticleElasticCollision::setupInitialConditions(), UnionOfWalls::setupInitialConditions(), and ChargedBondedParticleUnitTest::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
268 {
269  BaseInteraction* c = nullptr;
270  Mdouble dNormalMax = 0.9; //minimal agreement required
271  for (const auto& i : P->getInteractions())
272  {
273  if (i->getI() == I && i->getTimeStamp() != timeStamp)
274  {
275  const Mdouble dNormal = Vec3D::dot(normal, i->getNormal());
276  if (dNormal > dNormalMax)
277  {
278  c = i;
279  dNormalMax = dNormal;
280  }
281  }
282  }
283 
285 
286  if (c)
287  {
288  c->setTimeStamp(timeStamp);
289  }
290  else
291  {
292  c = species->getNewInteraction(P, I, timeStamp);
293  c->setSpecies(species);
294  addObject(c);
295  //logger(INFO,"new interaction t=%: i=%, n=%",timeStamp,getNumberOfObjects(),normal);
296  }
297 
298  return c;
299 }

References addObject(), Vec3D::dot(), BaseHandler< BaseInteraction >::getDPMBase(), BaseInteractable::getIndSpecies(), BaseInteractable::getInteractions(), SpeciesHandler::getMixedObject(), BaseSpecies::getNewInteraction(), constants::i, BaseInteraction::setSpecies(), BaseInteraction::setTimeStamp(), 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
251 {
252  BaseInteraction* emptyInteraction = this->createEmptyInteraction();
253  emptyInteraction->getInteractionDetails(interactionData, index, identificationP, identificationI, isWallInteraction,
254  timeStamp);
255  this->deleteEmptyInteraction(emptyInteraction);
256 }

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

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

◆ getLiquidBridgeVolume()

double InteractionHandler::getLiquidBridgeVolume ( ) const
563  {
564  double liquidVolume = 0;
565  for (auto i : objects_) {
566  auto j = dynamic_cast<LiquidMigrationWilletInteraction*>(i);
567  if (j and !static_cast<BaseParticle*>(j->getP())->isMPIParticle()) liquidVolume += j->getLiquidBridgeVolume();
568  }
569  return getMPISum(liquidVolume);
570 };

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

Referenced by LiquidMigrationMPI2Test::printTime().

◆ getMeanOverlap()

Mdouble InteractionHandler::getMeanOverlap ( ) const

The mean overlap of all interactions.

Returns
The mean overlap of all interactions
410 {
411  Mdouble sum = 0;
412  Mdouble n = 0;
413  for (BaseInteraction* const p : objects_)
414  {
415  if (p->getOverlap() > 0)
416  {
417  sum += p->getOverlap();
418  n++;
419  }
420  }
421  return sum / n;
422 }

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

Referenced by InitialConditions< SpeciesType >::getMeanRelativeContactRadius(), Sintering::getMeanRelativeContactRadius(), regimeForceUnitTest::getMeanRelativeContactRadius(), and main().

◆ getName()

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

Returns the name of the object.

Returns
the string InteractionHandler
428 {
429  return "InteractionHandler";
430 }

Referenced by read().

◆ 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.
69 {
70  if (this != &rhs)
71  {
72  clear();
73  }
74  writeVTK_ = rhs.writeVTK_;
75  logger(DEBUG, "InteractionHandler::operator =(const InteractionHandler& rhs) finished.");
76  return *this;
77 }

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

◆ read()

void InteractionHandler::read ( std::istream &  is)
Parameters
[in]isThe input stream from which the information is read.
458 {
459  clear();
460  unsigned int N;
461  std::string dummy;
462  is >> dummy;
463  std::stringstream line;
465  line >> N;
466  if (N > 1e5)
467  {
468  logger(INFO, "Reading % %", N, dummy);
469  }
470  logger(VERBOSE, "In %::read(is): reading in % objects.", getName(), N);
472  // set map
473  particleById.clear();
474  for (BaseParticle* p: getDPMBase()->particleHandler)
475  {
476  particleById[p->getId()] = p;
477  }
478  wallById.clear();
479  for (BaseWall* w: getDPMBase()->wallHandler)
480  {
481  wallById[w->getId()] = w;
482  }
483  for (unsigned int i = 0; i < N; i++)
484  {
485  readAndAddObject(is);
486  }
487  particleById.clear();
488  wallById.clear();
489 }

References BaseHandler< BaseInteraction >::clear(), BaseHandler< BaseInteraction >::getDPMBase(), helpers::getLineFromStringStream(), getName(), constants::i, INFO, logger, particleById, readAndAddObject(), BaseHandler< BaseInteraction >::setStorageCapacity(), VERBOSE, 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 >.

496 {
497  std::string type, dummy, idType;
498  unsigned int id0, id1;
499  Mdouble doubleTimeStamp;
500  unsigned timeStamp;
501 
503  is >> type;
504  logger(DEBUG, "InteractionHandler::readAndAddObject(is): reading type %.", type);
505  Mdouble timeStampDouble;
506  is >> idType >> id0 >> id1 >> dummy >> timeStampDouble;
507  timeStamp = timeStampDouble; //in order to read old restart files
508 
510  BaseInteraction* C;
511 
512 #ifdef MERCURY_USE_MPI
513  if (idType.compare("particleIds") == 0)
514  {
515  std::vector<BaseParticle*> list0 = getDPMBase()->particleHandler.getObjectsById(id0);
516  std::vector<BaseParticle*> list1 = getDPMBase()->particleHandler.getObjectsById(id1);
517  for (int p0 = 0; p0 < list0.size(); p0++)
518  {
519  for (int p1 = 0; p1 < list1.size(); p1++)
520  {
521  C = getInteraction(list0[p0],list1[p1], timeStamp);
522  if (C != nullptr)
523  {
524  is >> *C;
525  }
526  }
527  }
528 
529  }
530  else
531  {
532  std::vector<BaseParticle*> list0 = getDPMBase()->particleHandler.getObjectsById(id0);
533  for (int p0 = 0; p0 < list0.size(); p0++)
534  {
535  C = getInteraction(list0[p0],getDPMBase()->wallHandler.getObjectById(id1), timeStamp);
536  if (C != nullptr)
537  {
538  is >> *C;
539  }
540  }
541  }
542 #else
543  //this requires particleById/wallById to be set, which is done in the read() function
544  if (idType == "particleIds")
545  C = getInteraction(particleById[id0],particleById[id1],timeStamp);
546  else
547  C = getInteraction(particleById[id0],wallById[id1], timeStamp);
548  is >> (*C);
549 #endif
550  is.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
551 }

References FATAL, BaseHandler< BaseInteraction >::getDPMBase(), getInteraction(), BaseHandler< T >::getObjectsById(), logger, particleById, DPMBase::particleHandler, 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.
320 {
321  BaseInteraction* iMain = getObject(id);
322 
323  BaseParticle* P = dynamic_cast<BaseParticle*>(iMain->getP());
324  BaseParticle* I = dynamic_cast<BaseParticle*>(iMain->getI());
325  if (P != nullptr && I != nullptr) //check that both P and I are particles (not walls)
326  {
328  if (realI != nullptr && !P->getPeriodicFromParticle()) //check that P is a real and I is a ghost particle
329  {
330  if (P->getIndex() < realI->getIndex())
331  {
332  BaseInteraction* iOther = getExistingInteraction(P, realI);
333  //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
335  if (iOther == nullptr)
336  {
337  iOther = getExistingInteraction(realI, P);
338  }
339  if (iOther != nullptr) //if the interaction existed before the ghost particles were created
340  {
341  //Here we decide which of the two interactions should be kept:
342  //the interaction between the two real particles (iMain), or
343  //the interaction between the real and a ghost particle (iOther).
344  //It picks the one for which a collision has happened,
345  //i.e. the one with the newer timeStamp.
347  if (iOther->getTimeStamp() <
348  iMain->getTimeStamp()) //if the interaction has been active during the last computeForce routine, make this the new (real) interaction.
349 
350  {
351  iMain->setI(realI);
352  removeObject(iOther->getIndex());
353  return;
354  }
355  else //if the interaction has not been active during the last computeForce routine
356  {
358  return;
359  }
360  }
361  else //if the interaction has been created during the last computeForce routine, make this a new (real) interaction.
362  {
363  iMain->setI(realI);
364  return;
365  }
366  }
367  }
368  }
369  //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
371 }

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

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

◆ resetNewObjectsOMP()

void InteractionHandler::resetNewObjectsOMP ( )
125  {
126  #ifdef MERCURY_USE_OMP
127  newObjects_.clear();
128  newObjects_.resize(getDPMBase()->getNumberOfOMPThreads());
129  #endif
130 }

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

Referenced by DPMBase::computeAllForces().

◆ setWriteVTK()

void InteractionHandler::setWriteVTK ( FileType  f)
554 {
555  writeVTK_ = fileType;
556 }

References writeVTK_.

Referenced by DPMBase::read(), DPMBase::setInteractionsWriteVTK(), and MovingWalls::setupInitialConditions().

◆ 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.
437 {
438 #ifdef MERCURY_USE_MPI
439  //note: this function only prints the particles on processor 0
440  //The rest of the particles are processed in the restart file write function
441  MPIContainer& communicator = MPIContainer::Instance();
442  unsigned int totalNumberOfInteractions = getNumberOfObjects();
443  os << "Interactions " << totalNumberOfInteractions << '\n';
444  //logger(INFO,"% interactions",getNumberOfObjects());
445  for (BaseInteraction* it : *this)
446  {
447  os << (*it) << '\n';
448  }
449 #else
450  os << "Interactions " << getNumberOfObjects() << '\n';
451  for (BaseInteraction* i : objects_)
452  os << (*i) << '\n';
453 #endif
454 }

References BaseHandler< BaseInteraction >::getNumberOfObjects(), constants::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:
BaseInteraction::getInteractionDetails
virtual void getInteractionDetails(void *interactionDataArray, unsigned int index, unsigned int &identificationP, unsigned int &identificationI, bool &isWallInteraction, unsigned &timeStamp)
Definition: BaseInteraction.cc:876
BaseInteraction::setHandler
void setHandler(InteractionHandler *handler)
Sets the pointer to the interaction hander which is storing this interaction.
Definition: BaseInteraction.cc:259
BaseHandler< BaseInteraction >
InteractionHandler::createEmptyInteraction
BaseInteraction * createEmptyInteraction() const
Creates an empty interaction.
Definition: InteractionHandler.cc:185
InteractionHandler::getExistingInteraction
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:103
BaseParticle::getPeriodicFromParticle
BaseParticle * getPeriodicFromParticle() const
Returns the 'original' particle this one's a periodic copy of.
Definition: BaseParticle.h:341
LiquidMigrationWilletInteraction::getLiquidBridgeVolume
Mdouble getLiquidBridgeVolume() const
Definition: LiquidMigrationWilletInteraction.cc:462
InteractionHandler::readAndAddObject
void readAndAddObject(std::istream &is) override
Reads an Interaction into the InteractionHandler from restart data.
Definition: InteractionHandler.cc:495
InteractionHandler::getName
std::string getName() const override
Returns the name of the object.
Definition: InteractionHandler.cc:427
BaseWall
Basic class for walls.
Definition: BaseWall.h:48
logger
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
BaseInteraction::setSpecies
void setSpecies(const BaseSpecies *species)
Set the Species of the interaction; note this can either be a Species or MixedSpecies.
Definition: BaseInteraction.cc:346
BaseInteraction::getI
BaseInteractable * getI()
Returns a pointer to the second object involved in the interaction (often a wall or a particle).
Definition: BaseInteraction.h:280
Vec3D::dot
static Mdouble dot(const Vec3D &a, const Vec3D &b)
Calculates the dot product of two Vec3D: .
Definition: Vector.cc:76
SpeciesHandler::getMixedObject
std::enable_if<!std::is_pointer< typename U::MixedSpeciesType >::value, typename U::MixedSpeciesType * >::type getMixedObject(const U *S, const U *T)
Definition: SpeciesHandler.h:74
InteractionHandler::writeVTK_
FileType writeVTK_
Definition: InteractionHandler.h:206
BaseInteractable::getIndSpecies
unsigned int getIndSpecies() const
Returns the index of the species associated with the interactable object.
Definition: BaseInteractable.h:88
INFO
LL< Log::INFO > INFO
Info log level.
Definition: Logger.cc:55
BaseHandler< BaseInteraction >::setStorageCapacity
void setStorageCapacity(const unsigned int N)
Sets the storage capacity of this BaseHandler.
Definition: BaseHandler.h:669
BaseInteractable
Defines the basic properties that a interactable object can have.
Definition: BaseInteractable.h:55
BaseInteraction::deleteMPIInteractionDataArray
virtual void deleteMPIInteractionDataArray(void *dataArray)
Definition: BaseInteraction.cc:870
BaseHandler::getObjectsById
std::vector< T * > getObjectsById(const unsigned int id)
Gets a vector of pointers to the objects with the specific id.
Definition: BaseHandler.h:593
BaseInteraction
Stores information about interactions between two interactable objects; often particles but could be ...
Definition: BaseInteraction.h:60
Mdouble
double Mdouble
Definition: GeneralDefine.h:34
BaseSpecies
BaseSpecies is the class from which all other species are derived.
Definition: BaseSpecies.h:50
BaseHandler< BaseInteraction >::objects_
std::vector< BaseInteraction * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
BaseParticle::isMPIParticle
bool isMPIParticle() const
Indicates if this particle is a ghost in the MPI domain.
Definition: BaseParticle.cc:175
VERBOSE
LL< Log::VERBOSE > VERBOSE
Verbose information.
Definition: Logger.cc:57
BaseHandler< BaseInteraction >::removeObject
virtual void removeObject(unsigned const int index)
Removes an Object from the BaseHandler.
Definition: BaseHandler.h:472
LiquidMigrationWilletInteraction
Defines the liquid bridge willet interaction between two particles or walls.
Definition: LiquidMigrationWilletInteraction.h:45
BaseSpecies::getEmptyInteraction
virtual BaseInteraction * getEmptyInteraction() const =0
Log::FATAL
@ FATAL
DPMBase::speciesHandler
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. LinearViscoelasticSpecies, etc.
Definition: DPMBase.h:1385
BaseObject::getIndex
unsigned int getIndex() const
Returns the index of the object in the handler.
Definition: BaseObject.h:118
BaseInteraction::setI
void setI(BaseInteractable *I)
Sets the second object involved in the interaction (often particle or wall).
Definition: BaseInteraction.cc:391
InteractionHandler::particleById
std::map< unsigned, BaseParticle * > particleById
Definition: InteractionHandler.h:208
BaseHandler< BaseInteraction >::getNumberOfObjects
virtual unsigned int getNumberOfObjects() const
Gets the number of real Object in this BaseHandler. (i.e. no mpi or periodic particles)
Definition: BaseHandler.h:648
BaseInteraction::getTimeStamp
Mdouble getTimeStamp() const
Returns an Mdouble which is the time stamp of the interaction.
Definition: BaseInteraction.h:314
BaseInteractable::addInteraction
void addInteraction(BaseInteraction *I)
Adds an interaction to this BaseInteractable.
Definition: BaseInteractable.cc:292
MPIContainer
This class contains all information and functions required for communication between processors.
Definition: MpiContainer.h:130
getMPISum
Vec3D getMPISum(Vec3D &val)
Definition: MpiDataClass.cc:199
InteractionHandler::getInteraction
BaseInteraction * getInteraction(BaseInteractable *P, BaseInteractable *I, unsigned timeStamp)
Returns the Interaction between the BaseInteractable's P and I.
Definition: InteractionHandler.cc:149
helpers::getLineFromStringStream
void getLineFromStringStream(std::istream &in, std::stringstream &out)
Reads a line from one stringstream into another, and prepares the latter for reading in.
Definition: Helpers.cc:423
BaseInteraction::actionsOnErase
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
constants::i
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
BaseHandler::getObject
T * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:613
InteractionHandler::newObjects_
std::vector< std::vector< BaseInteraction * > > newObjects_
Definition: InteractionHandler.h:200
BaseHandler< BaseInteraction >::getDPMBase
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:725
BaseParticle
Definition: BaseParticle.h:54
BaseInteractable::getInteractions
const std::vector< BaseInteraction * > & getInteractions() const
Returns a list of interactions which belong to this interactable.
Definition: BaseInteractable.h:277
n
const unsigned n
Definition: CG3DPackingUnitTest.cpp:32
BaseSpecies::getNewInteraction
virtual BaseInteraction * getNewInteraction(BaseInteractable *P, BaseInteractable *I, unsigned timeStamp) const =0
returns new Interaction object.
InteractionHandler::addObject
void addObject(BaseInteraction *I) override
Adds an Interaction to the InteractionHandler.
Definition: InteractionHandler.cc:87
BaseHandler< BaseInteraction >::clear
virtual void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0.
Definition: BaseHandler.h:528
BaseInteraction::setTimeStamp
void setTimeStamp(unsigned timeStamp)
Updates the time step of the interacting. Note, time steps used to find completed interactions.
Definition: BaseInteraction.cc:249
DPMBase::particleHandler
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created.
Definition: DPMBase.h:1395
InteractionHandler::deleteEmptyInteraction
void deleteEmptyInteraction(BaseInteraction *interaction) const
Deletes an empty interaction.
Definition: InteractionHandler.cc:200
BaseInteraction::createMPIInteractionDataArray
virtual void * createMPIInteractionDataArray(unsigned int numberOfInteractions) const
Definition: BaseInteraction.cc:863
BaseHandler::addObject
virtual void addObject(T *object)
Adds a new Object to the BaseHandler.
Definition: BaseHandler.h:431
InteractionHandler::wallById
std::map< unsigned, BaseWall * > wallById
Definition: InteractionHandler.h:209
BaseSpecies::deleteEmptyInteraction
virtual void deleteEmptyInteraction(BaseInteraction *interaction) const =0
BaseInteraction::getP
BaseInteractable * getP()
Returns a pointer to first object involved in the interaction (normally a particle).
Definition: BaseInteraction.h:269
MPIContainer::Instance
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:134