MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 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)
 This function sets the id and ensures that nextId is a bigger value than id. More...
 
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.

Definition at line 43 of file InteractionHandler.h.

Constructor & Destructor Documentation

InteractionHandler::InteractionHandler ( )

Default constructor, it creates an empty InteractionHandler.

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

Definition at line 43 of file InteractionHandler.cc.

References DEBUG, logger, NO_FILE, and writeVTK_.

44 {
46  logger(DEBUG, "InteractionHandler::InteractionHandler() finished");
47 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
file will not be created/read
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.

Definition at line 55 of file InteractionHandler.cc.

References DEBUG, logger, and writeVTK_.

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 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
InteractionHandler::~InteractionHandler ( )
override

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

Definition at line 79 of file InteractionHandler.cc.

References DEBUG, and logger.

80 {
81  logger(DEBUG, "InteractionHandler::~InteractionHandler() finished");
82 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")

Member Function Documentation

void InteractionHandler::actionsAfterTimeStep ( )

Definition at line 398 of file InteractionHandler.cc.

References constants::i.

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

399 {
400  for (auto i: *this)
401  {
402  i->actionsAfterTimeStep();
403  }
404 }
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
BaseInteraction * InteractionHandler::addInteraction ( BaseInteractable P,
BaseInteractable I,
unsigned  timeStamp 
)

Definition at line 117 of file InteractionHandler.cc.

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

Referenced by DPMBase::readNextFStatFile().

118 {
120  BaseInteraction* C = species->getNewInteraction(P, I, timeStamp);
121  addObject(C);
122  return C;
123 }
std::enable_if<!std::is_pointer< typename U::MixedSpeciesType >::value, typename U::MixedSpeciesType * >::type getMixedObject(const U *S, const U *T)
BaseSpecies is the class from which all other species are derived.
Definition: BaseSpecies.h:49
Stores information about interactions between two interactable objects; often particles but could be ...
void addObject(BaseInteraction *I) override
Adds an Interaction to the InteractionHandler.
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. LinearViscoelasticSpecies, etc.
Definition: DPMBase.h:1319
virtual BaseInteraction * getNewInteraction(BaseInteractable *P, BaseInteractable *I, unsigned timeStamp) const =0
returns new Interaction object.
unsigned int getIndSpecies() const
Returns the index of the species associated with the interactable object.
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
void InteractionHandler::addNewObjectsOMP ( )

Definition at line 132 of file InteractionHandler.cc.

References addObject(), and newObjects_.

Referenced by DPMBase::computeAllForces().

132  {
133  for (auto objects : newObjects_) {
134  for (auto object : objects) {
135  addObject(object);
136  }
137  }
138 }
std::vector< std::vector< BaseInteraction * > > newObjects_
void addObject(BaseInteraction *I) override
Adds an Interaction to the InteractionHandler.
void InteractionHandler::addObject ( BaseInteraction I)
overridevirtual

Adds an Interaction to the InteractionHandler.

Parameters
[in]PA pointer to the BaseInteraction (or derived class) that has to be added.

Reimplemented from BaseHandler< BaseInteraction >.

Definition at line 87 of file InteractionHandler.cc.

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

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

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 }
void addInteraction(BaseInteraction *I)
Adds an interaction to this BaseInteractable.
BaseInteractable * getI()
Returns a pointer to the second object involved in the interaction (often a wall or a particle)...
BaseInteractable * getP()
Returns a pointer to first object involved in the interaction (normally a particle).
void setHandler(InteractionHandler *handler)
Sets the pointer to the interaction hander which is storing this interaction.
virtual void addObject(T *object)
Adds a new Object to the BaseHandler.
Definition: BaseHandler.h:431
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

Definition at line 185 of file InteractionHandler.cc.

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

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

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 }
BaseSpecies is the class from which all other species are derived.
Definition: BaseSpecies.h:49
Stores information about interactions between two interactable objects; often particles but could be ...
T * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:613
virtual BaseInteraction * getEmptyInteraction() const =0
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. LinearViscoelasticSpecies, etc.
Definition: DPMBase.h:1319
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
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

Definition at line 214 of file InteractionHandler.cc.

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

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

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 }
BaseInteraction * createEmptyInteraction() const
Creates an empty interaction.
virtual void * createMPIInteractionDataArray(unsigned int numberOfInteractions) const
Stores information about interactions between two interactable objects; often particles but could be ...
void deleteEmptyInteraction(BaseInteraction *interaction) const
Deletes an empty interaction.
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

Definition at line 200 of file InteractionHandler.cc.

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

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

201 {
202  BaseSpecies* species = this->getDPMBase()->speciesHandler.getObject(0);
203  species->deleteEmptyInteraction(interaction);
204 }
virtual void deleteEmptyInteraction(BaseInteraction *interaction) const =0
BaseSpecies is the class from which all other species are derived.
Definition: BaseSpecies.h:49
T * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:613
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. LinearViscoelasticSpecies, etc.
Definition: DPMBase.h:1319
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
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

Definition at line 230 of file InteractionHandler.cc.

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

Referenced by Domain::finaliseBoundaryDataTransmission().

231 {
232  BaseInteraction* emptyInteraction = this->createEmptyInteraction();
233  emptyInteraction->deleteMPIInteractionDataArray(dataArray);
234  this->deleteEmptyInteraction(emptyInteraction);
235 }
BaseInteraction * createEmptyInteraction() const
Creates an empty interaction.
Stores information about interactions between two interactable objects; often particles but could be ...
void deleteEmptyInteraction(BaseInteraction *interaction) const
Deletes an empty interaction.
virtual void deleteMPIInteractionDataArray(void *dataArray)
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());

Definition at line 380 of file InteractionHandler.cc.

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

Referenced by DPMBase::computeOneTimeStep().

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 }
virtual void actionsOnErase()
If an interaction needs to do something before it gets erased, add it here. E.g. Liquid bridges ruptu...
Mdouble getTimeStamp() const
Returns an Mdouble which is the time stamp of the interaction.
virtual void removeObject(unsigned const int index)
Removes an Object from the BaseHandler.
BaseInteraction * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
virtual unsigned int getNumberOfObjects() const
Gets the number of real Object in this BaseHandler. (i.e. no mpi or periodic particles) ...
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.

Definition at line 103 of file InteractionHandler.cc.

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

Referenced by getInteraction(), and removeObjectKeepingPeriodics().

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 }
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
const std::vector< BaseInteraction * > & getInteractions() const
Returns a list of interactions which belong to this interactable.
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

Definition at line 149 of file InteractionHandler.cc.

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

Referenced by VChute::getInteractionWith(), Combtooth::getInteractionWith(), SineWall::getInteractionWith(), ArcWall::getInteractionWith(), TriangulatedWall::getInteractionWith(), BaseWall::getInteractionWith(), BaseParticle::getInteractionWith(), SuperQuadricParticle::getInteractionWithSuperQuad(), and readAndAddObject().

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 }
std::enable_if<!std::is_pointer< typename U::MixedSpeciesType >::value, typename U::MixedSpeciesType * >::type getMixedObject(const U *S, const U *T)
BaseSpecies is the class from which all other species are derived.
Definition: BaseSpecies.h:49
void setTimeStamp(unsigned timeStamp)
Updates the time step of the interacting. Note, time steps used to find completed interactions...
Stores information about interactions between two interactable objects; often particles but could be ...
void setHandler(InteractionHandler *handler)
Sets the pointer to the interaction hander which is storing this interaction.
std::vector< std::vector< BaseInteraction * > > newObjects_
void setSpecies(const BaseSpecies *species)
Set the Species of the interaction; note this can either be a Species or MixedSpecies.
void addObject(BaseInteraction *I) override
Adds an Interaction to the InteractionHandler.
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. LinearViscoelasticSpecies, etc.
Definition: DPMBase.h:1319
virtual BaseInteraction * getNewInteraction(BaseInteractable *P, BaseInteractable *I, unsigned timeStamp) const =0
returns new Interaction object.
unsigned int getIndSpecies() const
Returns the index of the species associated with the interactable object.
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
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...
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

Definition at line 267 of file InteractionHandler.cc.

References addObject(), Vec3D::dot(), BaseHandler< BaseInteraction >::getDPMBase(), BaseInteractable::getIndSpecies(), BaseInteractable::getInteractions(), SpeciesHandler::getMixedObject(), BaseSpecies::getNewInteraction(), constants::i, BaseInteraction::setSpecies(), BaseInteraction::setTimeStamp(), and DPMBase::speciesHandler.

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 }
std::enable_if<!std::is_pointer< typename U::MixedSpeciesType >::value, typename U::MixedSpeciesType * >::type getMixedObject(const U *S, const U *T)
BaseSpecies is the class from which all other species are derived.
Definition: BaseSpecies.h:49
double Mdouble
Definition: GeneralDefine.h:34
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
static Mdouble dot(const Vec3D &a, const Vec3D &b)
Calculates the dot product of two Vec3D: .
Definition: Vector.cc:76
void setTimeStamp(unsigned timeStamp)
Updates the time step of the interacting. Note, time steps used to find completed interactions...
Stores information about interactions between two interactable objects; often particles but could be ...
void setSpecies(const BaseSpecies *species)
Set the Species of the interaction; note this can either be a Species or MixedSpecies.
void addObject(BaseInteraction *I) override
Adds an Interaction to the InteractionHandler.
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. LinearViscoelasticSpecies, etc.
Definition: DPMBase.h:1319
const std::vector< BaseInteraction * > & getInteractions() const
Returns a list of interactions which belong to this interactable.
virtual BaseInteraction * getNewInteraction(BaseInteractable *P, BaseInteractable *I, unsigned timeStamp) const =0
returns new Interaction object.
unsigned int getIndSpecies() const
Returns the index of the species associated with the interactable object.
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
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

Definition at line 248 of file InteractionHandler.cc.

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

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

251 {
252  BaseInteraction* emptyInteraction = this->createEmptyInteraction();
253  emptyInteraction->getInteractionDetails(interactionData, index, identificationP, identificationI, isWallInteraction,
254  timeStamp);
255  this->deleteEmptyInteraction(emptyInteraction);
256 }
BaseInteraction * createEmptyInteraction() const
Creates an empty interaction.
virtual void getInteractionDetails(void *interactionDataArray, unsigned int index, unsigned int &identificationP, unsigned int &identificationI, bool &isWallInteraction, unsigned &timeStamp)
Stores information about interactions between two interactable objects; often particles but could be ...
void deleteEmptyInteraction(BaseInteraction *interaction) const
Deletes an empty interaction.
double InteractionHandler::getLiquidBridgeVolume ( ) const

Definition at line 557 of file InteractionHandler.cc.

References LiquidMigrationWilletInteraction::getLiquidBridgeVolume(), getMPISum(), constants::i, and BaseHandler< BaseInteraction >::objects_.

557  {
558  double liquidVolume = 0;
559  for (auto i : objects_) {
560  auto j = dynamic_cast<LiquidMigrationWilletInteraction*>(i);
561  if (j and !static_cast<BaseParticle*>(j->getP())->isMPIParticle()) liquidVolume += j->getLiquidBridgeVolume();
562  }
563  return getMPISum(liquidVolume);
564 };
Defines the liquid bridge willet interaction between two particles or walls.
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
Vec3D getMPISum(Vec3D &val)
Sums the values over all processors using MPI_reduce.
std::vector< BaseInteraction * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
Mdouble InteractionHandler::getMeanOverlap ( ) const

The mean overlap of all interactions.

Returns
The mean overlap of all interactions

Definition at line 409 of file InteractionHandler.cc.

References BaseHandler< BaseInteraction >::objects_.

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 }
double Mdouble
Definition: GeneralDefine.h:34
Stores information about interactions between two interactable objects; often particles but could be ...
std::vector< BaseInteraction * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
std::string InteractionHandler::getName ( ) const
overridevirtual

Returns the name of the object.

Returns
the string InteractionHandler

Implements BaseHandler< BaseInteraction >.

Definition at line 427 of file InteractionHandler.cc.

Referenced by read().

428 {
429  return "InteractionHandler";
430 }
FileType InteractionHandler::getWriteVTK ( ) const

Definition at line 552 of file InteractionHandler.cc.

References writeVTK_.

Referenced by DPMBase::write(), DPMBase::writePythonFileForVTKVisualisation(), and DPMBase::writeVTKFiles().

553 {
554  return writeVTK_;
555 }
InteractionHandler & InteractionHandler::operator= ( const InteractionHandler rhs)

Assignment operator.

Parameters
[in]rhsThe BoundaryHandler on the right hand side of the assignment.

Definition at line 68 of file InteractionHandler.cc.

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

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 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
virtual void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
void InteractionHandler::read ( std::istream &  is)
Parameters
[in]isThe input stream from which the information is read.

Definition at line 457 of file InteractionHandler.cc.

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().

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) logger(INFO, "Reading % %", N, dummy);
467  logger(VERBOSE, "In %::read(is): reading in % objects.", getName(), N);
469  // set map
470  particleById.clear();
471  for (BaseParticle* p : getDPMBase()->particleHandler) {
472  particleById[p->getId()] = p;
473  }
474  wallById.clear();
475  for (BaseWall* w : getDPMBase()->wallHandler) {
476  wallById[w->getId()] = w;
477  }
478  for (unsigned int i = 0; i < N; i++) {
479  readAndAddObject(is);
480  }
481  particleById.clear();
482  wallById.clear();
483 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
std::map< unsigned, BaseParticle * > particleById
void setStorageCapacity(const unsigned int N)
Sets the storage capacity of this BaseHandler.
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
std::string getName() const override
Returns the name of the object.
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:424
Basic class for walls.
Definition: BaseWall.h:47
std::map< unsigned, BaseWall * > wallById
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
void readAndAddObject(std::istream &is) override
Reads an Interaction into the InteractionHandler from restart data.
virtual void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
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 >.

Definition at line 489 of file InteractionHandler.cc.

References DEBUG, BaseHandler< BaseInteraction >::getDPMBase(), getInteraction(), BaseHandler< T >::getObjectsById(), logger, particleById, DPMBase::particleHandler, and wallById.

Referenced by read().

490 {
491  std::string type, dummy, idType;
492  unsigned int id0, id1;
493  Mdouble doubleTimeStamp;
494  unsigned timeStamp;
495 
497  is >> type;
498  logger(DEBUG, "InteractionHandler::readAndAddObject(is): reading type %.", type);
499  Mdouble timeStampDouble;
500  is >> idType >> id0 >> id1 >> dummy >> timeStampDouble;
501  timeStamp = timeStampDouble; //in order to read old restart files
502 
504  BaseInteraction* C;
505 
506 #ifdef MERCURY_USE_MPI
507  if (idType.compare("particleIds") == 0)
508  {
509  std::vector<BaseParticle*> list0 = getDPMBase()->particleHandler.getObjectsById(id0);
510  std::vector<BaseParticle*> list1 = getDPMBase()->particleHandler.getObjectsById(id1);
511  for (int p0 = 0; p0 < list0.size(); p0++)
512  {
513  for (int p1 = 0; p1 < list1.size(); p1++)
514  {
515  C = getInteraction(list0[p0],list1[p1], timeStamp);
516  if (C != nullptr)
517  {
518  is >> *C;
519  }
520  }
521  }
522 
523  }
524  else
525  {
526  std::vector<BaseParticle*> list0 = getDPMBase()->particleHandler.getObjectsById(id0);
527  for (int p0 = 0; p0 < list0.size(); p0++)
528  {
529  C = getInteraction(list0[p0],getDPMBase()->wallHandler.getObjectById(id1), timeStamp);
530  if (C != nullptr)
531  {
532  is >> *C;
533  }
534  }
535  }
536 #else
537  //this requires particleById/wallById to be set, which is done in the read() function
538  if (idType == "particleIds")
539  C = getInteraction(particleById[id0],particleById[id1],timeStamp);
540  else
541  C = getInteraction(particleById[id0],wallById[id1], timeStamp);
542  is >> (*C);
543 #endif
544  is.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
545 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
Definition: GeneralDefine.h:34
std::map< unsigned, BaseParticle * > particleById
std::vector< T * > getObjectsById(const unsigned int id)
Gets a vector of pointers to the objects with the specific id.
Definition: BaseHandler.h:593
Stores information about interactions between two interactable objects; often particles but could be ...
BaseInteraction * getInteraction(BaseInteractable *P, BaseInteractable *I, unsigned timeStamp)
Returns the Interaction between the BaseInteractable's P and I.
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created...
Definition: DPMBase.h:1329
std::map< unsigned, BaseWall * > wallById
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
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.

periodicBoundary.pdf
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.

Definition at line 319 of file InteractionHandler.cc.

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 DPMBase::removeDuplicatePeriodicParticles().

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 }
unsigned int getIndex() const
Returns the index of the object in the handler.
Definition: BaseObject.h:118
void setI(BaseInteractable *I)
Sets the second object involved in the interaction (often particle or wall).
BaseParticle * getPeriodicFromParticle() const
Returns the 'original' particle this one's a periodic copy of.
Definition: BaseParticle.h:338
BaseInteractable * getI()
Returns a pointer to the second object involved in the interaction (often a wall or a particle)...
Mdouble getTimeStamp() const
Returns an Mdouble which is the time stamp of the interaction.
Stores information about interactions between two interactable objects; often particles but could be ...
BaseInteractable * getP()
Returns a pointer to first object involved in the interaction (normally a particle).
virtual void removeObject(unsigned const int index)
Removes an Object from the BaseHandler.
BaseInteraction * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Defines the basic properties that a interactable object can have.
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...
void InteractionHandler::resetNewObjectsOMP ( )

Definition at line 125 of file InteractionHandler.cc.

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

Referenced by DPMBase::computeAllForces().

125  {
126  #ifdef MERCURY_USE_OMP
127  newObjects_.clear();
128  newObjects_.resize(getDPMBase()->getNumberOfOMPThreads());
129  #endif
130 }
std::vector< std::vector< BaseInteraction * > > newObjects_
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
void InteractionHandler::setWriteVTK ( FileType  f)

Definition at line 547 of file InteractionHandler.cc.

References writeVTK_.

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

548 {
549  writeVTK_ = fileType;
550 }
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.

Definition at line 436 of file InteractionHandler.cc.

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

Referenced by DPMBase::write().

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 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:125
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:130
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
Stores information about interactions between two interactable objects; often particles but could be ...
std::vector< BaseInteraction * > objects_
The actual list of Object pointers.
Definition: BaseHandler.h:302
virtual unsigned int getNumberOfObjects() const
Gets the number of real Object in this BaseHandler. (i.e. no mpi or periodic particles) ...

Member Data Documentation

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

Definition at line 200 of file InteractionHandler.h.

Referenced by addNewObjectsOMP(), getInteraction(), and resetNewObjectsOMP().

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

Definition at line 208 of file InteractionHandler.h.

Referenced by read(), and readAndAddObject().

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

Definition at line 209 of file InteractionHandler.h.

Referenced by read(), and readAndAddObject().

FileType InteractionHandler::writeVTK_
private

Definition at line 206 of file InteractionHandler.h.

Referenced by getWriteVTK(), InteractionHandler(), operator=(), and setWriteVTK().


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