MercuryDPM  Alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InteractionHandler Class Reference

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...
 
InteractionHandler operator= (const InteractionHandler &rhs)
 Assignment operator. More...
 
 ~InteractionHandler ()
 Destructor, it destructs the InteractionHandler and all BaseInteraction it contains. More...
 
void addObject (BaseInteraction *I)
 Adds an Interaction to the InteractionHandler. More...
 
void readObject (std::istream &is)
 Reads an Interaction into the InteractionHandler from restart data. More...
 
BaseInteractiongetExistingInteraction (BaseInteractable *P, BaseInteractable *I) const
 Returns the Interaction between the BaseInteractable's P and I if it exists, otherwise returns a null pointer. More...
 
BaseInteractiongetInteraction (BaseInteractable *P, BaseInteractable *I, Mdouble timeStamp)
 Returns the Interaction between the BaseInteractable's P and I. More...
 
BaseInteractiongetInteraction (BaseInteractable *P, BaseInteractable *I, Mdouble 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 const int id)
 Removes interactions of periodic particles when the periodic particles get deleted (see DPMBase::removeDuplicatePeriodicParticles) More...
 
void eraseOldInteractions (Mdouble lastTimeStep)
 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
 
void writeVTK () const
 Writes all particles into a vtk file format (unstructured grid), consisting of particle positions, velocities, radii and type of species (IndSpecies) More...
 
std::string getName () const
 Returns the name of the object. More...
 
- 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...
 
virtual void removeObject (unsigned const int id)
 Removes an Object from the BaseHandler. More...
 
void removeLastObject ()
 Removes the last Object from the BaseHandler. More...
 
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...
 
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...
 
unsigned int getNumberOfObjects () const
 Gets the number of Object in this BaseHandler. 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...
 
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...
 
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 ()
 Over written in WallHandler and ParticleHandler. More...
 

Private Attributes

FileType writeVTK_
 

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 37 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 39 of file InteractionHandler.cc.

References DEBUG, logger, NO_FILE, and writeVTK_.

40 {
42  logger(DEBUG, "InteractionHandler::InteractionHandler() finished");
43 }
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 51 of file InteractionHandler.cc.

References DEBUG, logger, and writeVTK_.

53 {
54  writeVTK_ = IH.writeVTK_;
55  //By default interactions are not copied.
56  logger(DEBUG, "InteractionHandler::InteractionHandler(const "
57  "InteractionHandler &IH) finished, please note that no interactions"
58  " have been copied.");
59 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
InteractionHandler::~InteractionHandler ( )

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

Definition at line 75 of file InteractionHandler.cc.

References DEBUG, and logger.

76 {
77  logger(DEBUG, "InteractionHandler::~InteractionHandler() finished");
78 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")

Member Function Documentation

void InteractionHandler::actionsAfterTimeStep ( )

Definition at line 278 of file InteractionHandler.cc.

Referenced by DPMBase::solve().

279 {
280  for (auto i: *this)
281  {
282  i->actionsAfterTimeStep();
283  }
284 }
void InteractionHandler::addObject ( BaseInteraction I)
virtual

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 83 of file InteractionHandler.cc.

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

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

84 {
85  //Puts the particle in the Particle list
87  //set the particleHandler pointer
88  I->setHandler(this);
89 }
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:313
void InteractionHandler::eraseOldInteractions ( Mdouble  lastTimeStep)

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 260 of file InteractionHandler.cc.

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

Referenced by DPMBase::solve().

261 {
262  //std::cout<<"void InteractionHandler::eraseOldInteractions(Mdouble lastTimeStep)"<<std::endl;
263  //std::cout<<"Current interactions="<<getNumberOfObjects()<<std::endl;
264  //Remove_if reconstructs the vector with only elements passing the check_spring_time function
265  //Erase removes the end of the vector
267  for (unsigned int id = 0; id < getNumberOfObjects(); id++)
268  {
269  if (getObject(id)->getTimeStamp() <= lastTimeStep)
270  {
271  getObject(id)->actionsOnErase();
272  removeObject(id);
273  --id;
274  }
275  }
276 }
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 id)
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.
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
BaseInteraction * InteractionHandler::getExistingInteraction ( BaseInteractable P,
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 96 of file InteractionHandler.cc.

References BaseInteractable::getInteractions().

Referenced by getInteraction(), and removeObjectKeepingPeriodics().

97 {
98  //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
99  for (BaseInteraction* i : P->getInteractions())
100  {
101  if (i->getI() == I)
102  {
103  return i;
104  }
105  }
106  return nullptr;
107 }
Stores information about interactions between two interactable objects; often particles but could be ...
const std::list< BaseInteraction * > & getInteractions() const
Returns a reference to the list of interactions in this BaseInteractable.
BaseInteraction * InteractionHandler::getInteraction ( BaseInteractable P,
BaseInteractable I,
Mdouble  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 117 of file InteractionHandler.cc.

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

Referenced by TriangulatedWall::getInteractionWith(), BaseWall::getInteractionWith(), BaseParticle::getInteractionWith(), and readObject().

118 {
120 
121  //std::cout << "Trying to reconnect to BaseInteraction between P=" << P->getId() << " and " << I->getId() << std::endl;
123  if (C == nullptr)
124  {
125  C = species->getNewInteraction(P, I, timeStamp);
126  addObject(C);
127  //std::cout << "Creating new interaction with index=" << getLastObject()->getIndex() << " id=" << getLastObject()->getId() << std::endl;
128  }
129 
130  //set timeStamp
131  C->setTimeStamp(timeStamp);
132 
134  //set species of collision
135  C->setSpecies(species);
136 
137  return C;
138 }
BaseSpecies is the class from which all other species are derived.
Definition: BaseSpecies.h:44
void setSpecies(BaseSpecies *species)
Set the Species of the interaction; note this can either be a Species or MixedSpecies.
Stores information about interactions between two interactable objects; often particles but could be ...
void setTimeStamp(Mdouble timeStamp)
Updates the time step of the interacting. Note, timesteps used to find completed interactions.
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. elastic, linear visco-elastic... et cetera...
Definition: DPMBase.h:991
std::enable_if<!std::is_pointer< typename U::MixedSpeciesType >::value, typename U::MixedSpeciesType * >::type getMixedObject(const U *S, const U *T)
BaseInteraction * getExistingInteraction(BaseInteractable *P, BaseInteractable *I) const
Returns the Interaction between the BaseInteractable's P and I if it exists, otherwise returns a null...
unsigned int getIndSpecies() const
Returns the index of the Species of this BaseInteractable.
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
void addObject(BaseInteraction *I)
Adds an Interaction to the InteractionHandler.
virtual BaseInteraction * getNewInteraction(BaseInteractable *P, BaseInteractable *I, Mdouble timeStamp) const =0
returns new Interaction object.
BaseInteraction * InteractionHandler::getInteraction ( BaseInteractable P,
BaseInteractable I,
Mdouble  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 149 of file InteractionHandler.cc.

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

150 {
151  BaseInteraction* c = nullptr;
152  Mdouble dNormalMax = 0.9; //minimal agreement required
153  for (const auto& i : P->getInteractions())
154  {
155  if (i->getI() == I && i->getTimeStamp() != timeStamp)
156  {
157  const Mdouble dNormal = Vec3D::dot(normal, i->getNormal());
158  if (dNormal > dNormalMax)
159  {
160  c = i;
161  dNormalMax = dNormal;
162  }
163  }
164  }
165 
167 
168  if (c)
169  {
170  c->setTimeStamp(timeStamp);
171  } else
172  {
173  c = species->getNewInteraction(P, I, timeStamp);
174  c->setSpecies(species);
175  addObject(c);
176  //logger(INFO,"new interaction t=%: i=%, n=%",timeStamp,getNumberOfObjects(),normal);
177  }
178 
179  return c;
180 }
BaseSpecies is the class from which all other species are derived.
Definition: BaseSpecies.h:44
double Mdouble
static Mdouble dot(const Vec3D &a, const Vec3D &b)
Calculates the dot product of two Vec3D: .
Definition: Vector.cc:167
void setSpecies(BaseSpecies *species)
Set the Species of the interaction; note this can either be a Species or MixedSpecies.
Stores information about interactions between two interactable objects; often particles but could be ...
void setTimeStamp(Mdouble timeStamp)
Updates the time step of the interacting. Note, timesteps used to find completed interactions.
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. elastic, linear visco-elastic... et cetera...
Definition: DPMBase.h:991
std::enable_if<!std::is_pointer< typename U::MixedSpeciesType >::value, typename U::MixedSpeciesType * >::type getMixedObject(const U *S, const U *T)
const std::list< BaseInteraction * > & getInteractions() const
Returns a reference to the list of interactions in this BaseInteractable.
unsigned int getIndSpecies() const
Returns the index of the Species of this BaseInteractable.
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
void addObject(BaseInteraction *I)
Adds an Interaction to the InteractionHandler.
virtual BaseInteraction * getNewInteraction(BaseInteractable *P, BaseInteractable *I, Mdouble timeStamp) const =0
returns new Interaction object.
Mdouble InteractionHandler::getMeanOverlap ( ) const

The mean overlap of all interactions.

Returns
The mean overlap of all interactions

Definition at line 289 of file InteractionHandler.cc.

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

290 {
291  Mdouble sum = 0;
292  for (BaseInteraction* const p : objects_)
293  {
294  sum += p->getOverlap();
295  }
296  return sum / getNumberOfObjects();
297 }
double Mdouble
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:216
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
std::string InteractionHandler::getName ( ) const
virtual

Returns the name of the object.

Returns
the string InteractionHandler

Implements BaseHandler< BaseInteraction >.

Definition at line 302 of file InteractionHandler.cc.

303 {
304  return "InteractionHandler";
305 }
FileType InteractionHandler::getWriteVTK ( ) const

Definition at line 460 of file InteractionHandler.cc.

References writeVTK_.

Referenced by DPMBase::write(), writeVTK(), and DPMBase::writeVTK().

460  {
461  return writeVTK_;
462 }
InteractionHandler InteractionHandler::operator= ( const InteractionHandler rhs)

Assignment operator.

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

Definition at line 64 of file InteractionHandler.cc.

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

65 {
66  if (this != &rhs)
67  {
68  clear();
69  }
70  writeVTK_ = rhs.writeVTK_;
71  logger(DEBUG, "InteractionHandler::operator =(const InteractionHandler& rhs) finished.");
72  return *this;
73 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
void InteractionHandler::readObject ( std::istream &  is)
virtual

Reads an Interaction into the InteractionHandler from restart data.

Parameters
[in]isThe input stream from which the information is read.
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 321 of file InteractionHandler.cc.

References BaseHandler< BaseInteraction >::getDPMBase(), getInteraction(), helpers::getLineFromStringStream(), BaseHandler< T >::getObjectById(), logger, DPMBase::particleHandler, VERBOSE, and DPMBase::wallHandler.

322 {
323  std::string type, dummy, idType;
324  unsigned int id0, id1;
325  Mdouble timeStamp;
326 
327  std::stringstream line(std::stringstream::in | std::stringstream::out);
329 
330  line >> type >> idType >> id0 >> id1 >> dummy >> timeStamp;
331  logger(VERBOSE, "InteractionHandler::readObject(is): reading type % % %", type, id0, id1);
333  BaseInteraction* C;
334  if (idType.compare("particleIds") == 0) {
335 // C = getDPMBase()->particleHandler.getObjectById(id1)->getInteractionWith(getDPMBase()->particleHandler.getObjectById(id0), timeStamp, this)[0];
336  C = getInteraction(getDPMBase()->particleHandler.getObjectById(id0),
337  getDPMBase()->particleHandler.getObjectById(id1), timeStamp);
338  }
339  else {
340 // C = getDPMBase()->wallHandler.getObjectById(id1)->getInteractionWith(getDPMBase()->particleHandler.getObjectById(id0), timeStamp, this)[0];
341  C = getInteraction(getDPMBase()->particleHandler.getObjectById(id0),
342  getDPMBase()->wallHandler.getObjectById(id1), timeStamp);
343  }
344  line >> (*C);
345 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
T * getObjectById(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:429
BaseInteraction * getInteraction(BaseInteractable *P, BaseInteractable *I, Mdouble timeStamp)
Returns the Interaction between the BaseInteractable's P and I.
double Mdouble
Stores information about interactions between two interactable objects; often particles but could be ...
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:396
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created...
Definition: DPMBase.h:1001
WallHandler wallHandler
An object of the class WallHandler. Contains pointers to all the walls created.
Definition: DPMBase.h:1006
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
void InteractionHandler::removeObjectKeepingPeriodics ( unsigned const 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 200 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().

201 {
202  BaseInteraction* iMain = getObject(id);
203 
204  BaseParticle* P = dynamic_cast<BaseParticle*>(iMain->getP());
205  BaseParticle* I = dynamic_cast<BaseParticle*>(iMain->getI());
206  if (P != nullptr && I != nullptr) //check that both P and I are particles (not walls)
207  {
209  if (realI != nullptr && !P->getPeriodicFromParticle()) //check that P is a real and I is a ghost particle
210  {
211  if (P->getIndex() < realI->getIndex())
212  {
213  BaseInteraction* iOther = getExistingInteraction(P, realI);
214  //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
216  if (iOther == nullptr)
217  {
218  iOther = getExistingInteraction(realI, P);
219  }
220  if (iOther != nullptr) //if the interaction existed before the ghost particles were created
221  {
222  //Here we decide which of the two interactions should be kept:
223  //the interaction between the two real particles (iMain), or
224  //the interaction between the real and a ghost particle (iOther).
225  //It picks the one for which a collision has happened,
226  //i.e. the one with the newer timeStamp.
228  if (iOther->getTimeStamp() < iMain->getTimeStamp()) //if the interaction has been active during the last computeForce routine, make this the new (real) interaction.
229 
230  {
231  iMain->setI(realI);
232  removeObject(iOther->getIndex());
233  return;
234  }
235  else //if the interaction has not been active during the last computeForce routine
236  {
238  return;
239  }
240  }
241  else //if the interaction has been created during the last computeForce routine, make this a new (real) interaction.
242  {
243  iMain->setI(realI);
244  return;
245  }
246  }
247  }
248  }
249  //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
251 }
unsigned int getIndex() const
Returns the index of the object in the handler.
Definition: BaseObject.cc:108
void setI(BaseInteractable *I)
Sets the second object involved in the interaction (often particle or wall).
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 ...
BaseParticle * getPeriodicFromParticle() const
Returns the 'original' particle this one's a periodic copy of.
virtual void removeObject(unsigned const int id)
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.
BaseInteractable * getI()
Defines the basic properties that a interactable object can have.
BaseInteraction * getExistingInteraction(BaseInteractable *P, BaseInteractable *I) const
Returns the Interaction between the BaseInteractable's P and I if it exists, otherwise returns a null...
BaseInteractable * getP()
Returns a pointer to first object involved in the interaction (normally a particle).
void InteractionHandler::setWriteVTK ( FileType  f)

Definition at line 456 of file InteractionHandler.cc.

References writeVTK_.

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

456  {
457  writeVTK_ = fileType;
458 }
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 311 of file InteractionHandler.cc.

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

Referenced by DPMBase::write().

312 {
313  os << "Interactions " << getNumberOfObjects() << std::endl;
314  for (BaseInteraction* i : objects_)
315  os << (*i) << std::endl;
316 }
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:216
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
void InteractionHandler::writeVTK ( ) const

Writes all particles into a vtk file format (unstructured grid), consisting of particle positions, velocities, radii and type of species (IndSpecies)

Writes all points ans cells to a file in the VTK format. The filename is hard-coded in this method, and is based on the name of the DPMBase and has a unique counter in it to ensure there are no two files with the same name.

Todo:
Check if this should indeed be a WARN

Definition at line 353 of file InteractionHandler.cc.

References BaseHandler< BaseInteraction >::getDPMBase(), BaseHandler< BaseInteraction >::getLastObject(), Files::getName(), BaseInteraction::getNameVTK(), BaseInteraction::getNumberOfFieldsVTK(), BaseHandler< BaseInteraction >::getNumberOfObjects(), BaseInteraction::getTypeVTK(), getWriteVTK(), INFO, logger, NO_FILE, helpers::to_string(), and WARN.

Referenced by DPMBase::writeVTK().

354 {
356  return;
357 
358  static unsigned fileCounter = 0;
359  const std::string fileName = getDPMBase()->getName() + "Interaction_" +
360  std::to_string(fileCounter++) + ".vtu";
361  logger(INFO, "writing % (t=%, N=%)", fileName, getDPMBase()->getTime(), this->getNumberOfObjects());
362 
363  std::fstream file;
364  file.open(fileName.c_str(), std::ios::out);
365  if (file.fail())
366  {
368  logger(WARN, "Error in writeToFile: file % could not be opened", fileName);
369  }
370 
371  file << "<?xml version=\"1.0\"?>\n\n";
372  file << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n";
373  file << "<UnstructuredGrid>\n";
374  file << "<Piece NumberOfPoints=\"" << this->getNumberOfObjects() << "\" NumberOfCells=\"" << 0 << "\">\n";
375  file << "<Points>\n";
376  file << " <DataArray type=\"Float32\" Name=\"Position\" NumberOfComponents=\"3\" format=\"ascii\">\n";
377  for (const auto &p: *this)
378  {
379  file << '\t' << p->getContactPoint() << '\n';
380  }
381  file << " </DataArray>\n";
382  file << "</Points>\n";
383  file << "<PointData Vectors=\"vector\">\n";
384  file << " <DataArray type=\"Float32\" Name=\"Normal\" NumberOfComponents=\"3\" format=\"ascii\">\n";
385  // Add velocity
386  for (const auto &p: *this)
387  {
388  file << '\t' << p->getNormal() << '\n';
389  }
390  file << " </DataArray>\n";
391  file << " <DataArray type=\"Float32\" Name=\"Overlap\" format=\"ascii\">\n";
392  // Add radius
393  for (const auto &p: *this)
394  {
395  file << '\t' << p->getOverlap() << '\n';
396  }
397  file << " </DataArray>\n";
398  file << " <DataArray type=\"Float32\" Name=\"ContactRadius\" format=\"ascii\">\n";
399  // Add radius
400  for (const auto &p: *this)
401  {
402  file << '\t' << p->getContactRadius() << '\n';
403  }
404  file << " </DataArray>\n";
405  file << " <DataArray type=\"Float32\" Name=\"Force\" format=\"ascii\">\n";
406  // Add species type
407  for (const auto &p: *this)
408  {
409  file << '\t' << p->getForce() << '\n';
410  }
411  file << " </DataArray>\n";
412  file << " <DataArray type=\"Float32\" Name=\"TangentialOverlap\" format=\"ascii\">\n";
413  // Add species type
414  for (const auto &p: *this)
415  {
416  file << '\t' << p->getTangentialOverlap() << '\n';
417  }
418  file << " </DataArray>\n";
419  file << " <DataArray type=\"Float32\" Name=\"Torque\" format=\"ascii\">\n";
420  // Add species type
421  for (const auto &p: *this)
422  {
423  file << '\t' << p->getTorque() << '\n';
424  }
425  file << " </DataArray>\n";
426  //check if this type of Interaction has extra fields
427  if (getLastObject()!= nullptr)
428  {
429  for (unsigned i = 0; i<getLastObject()->getNumberOfFieldsVTK(); i++)
430  {
431  file << " <DataArray type=\"" << getLastObject()->getTypeVTK(i) << "\" Name=\"" << getLastObject()->getNameVTK(i) << "\" format=\"ascii\">\n";
432  // Add species type
433  for (const auto &p: *this)
434  {
435  for (auto f : p->getFieldVTK(i))
436  file << '\t' << f << '\n';
437  }
438  file << " </DataArray>\n";
439  }
440  }
441  file << "</PointData>\n";
442  file << "<Cells>\n";
443  file << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n";
444  file << " </DataArray>\n";
445  file << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n";
446  file << " </DataArray>\n";
447  file << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n";
448  file << " </DataArray>\n";
449  file << "</Cells>\n";
450  file << "</Piece>\n";
451  file << "</UnstructuredGrid>\n";
452  file << "</VTKFile>\n";
453  file.close();
454 }
FileType getWriteVTK() const
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
file will not be created/read
virtual std::string getTypeVTK(unsigned i) const
virtual std::string getNameVTK(unsigned i) const
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
std::string to_string(const T &n)
Definition: Helpers.h:203
BaseInteraction * getLastObject()
Gets a pointer to the last Object in this BaseHandler.
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
const std::string & getName() const
Returns the name of the file. Does not allow to change it though.
Definition: Files.cc:132
virtual unsigned getNumberOfFieldsVTK() const

Member Data Documentation

FileType InteractionHandler::writeVTK_
private

Definition at line 133 of file InteractionHandler.h.

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


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