PossibleContactList Class Reference

Manages the linked list of PossibleContact. More...

#include <PossibleContactList.h>

Public Member Functions

 PossibleContactList ()
 Constructor, sets the firstPossibleContact_ to a nullptr since there are no possible interactions yet. More...
 
void add_PossibleContact (BaseParticle *P1, BaseParticle *P2)
 Add the possible contact between two given BaseParticle to the linked list. More...
 
void remove_ParticlePosibleContacts (BaseParticle *P)
 Remove all PossibleContact with given BaseParticle from the linked list. More...
 
void write (std::ostream &os) const
 Write all PossibleContact to the given ostream. More...
 
PossibleContactgetFirstPossibleContact ()
 Get the front of the linked list of PossibleContact. More...
 

Private Attributes

PossibleContactfirstPossibleContact_
 The pointer to the first PossibleContact on the linked list. More...
 

Detailed Description

Manages the linked list of PossibleContact.

Please note that the PossibleContact at the front of the list is the one that is added last, so firstPossibleContact_ is the PossibleContact that has been added last.

Todo:

Look at the memory management of PossibleContactList. Maybe a destructor that takes out all remaining PossibleContact? Or is there a Handler that calls remove_ParticlePosibleContacts for all particles?

Restart-tests are not working with CONTACT_LIST_HGRID turned on, so either finish the ContactList-related code, or get rid of it. If we keep it, clean up the code, in particular the naming-convention.

Constructor & Destructor Documentation

◆ PossibleContactList()

PossibleContactList::PossibleContactList ( )
inline

Constructor, sets the firstPossibleContact_ to a nullptr since there are no possible interactions yet.

30  {
31  firstPossibleContact_ = nullptr;
32  logger(DEBUG, "PossibleContactList() constructor finished.");
33  }
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
@ DEBUG
PossibleContact * firstPossibleContact_
The pointer to the first PossibleContact on the linked list.
Definition: PossibleContactList.h:139

References DEBUG, firstPossibleContact_, and logger.

Member Function Documentation

◆ add_PossibleContact()

void PossibleContactList::add_PossibleContact ( BaseParticle P1,
BaseParticle P2 
)
inline

Add the possible contact between two given BaseParticle to the linked list.

Parameters
[in]P1A pointer to the first BaseParticle we want to make a PossibleContact with.
[in]P2A pointer to the second BaseParticle we want to make a PossibleContact with.

If there is a PossibleContact between two BaseParticle, make a new PossibleContact and put it in front of the linked list. Then assign the newly made PossibleContact to the former front of the linked list.

44  {
45  firstPossibleContact_ = new PossibleContact(P1, P2, firstPossibleContact_, P1->getFirstPossibleContact(),
46  P2->getFirstPossibleContact());
47  P1->setFirstPossibleContact(firstPossibleContact_);
48  P2->setFirstPossibleContact(firstPossibleContact_);
55  logger(VERBOSE, "Added new possible contact between particles % and % ", P1->getIndex(), P2->getIndex());
56  }
@ VERBOSE
unsigned int getIndex() const
Returns the index of the object in the handler.
Definition: BaseObject.h:97
Class that describes a possible contact between two BaseParticle.
Definition: PossibleContact.h:21
PossibleContact * getNext1()
Gets the next PossibleContact in the linked list of PossibleContact of the first particle in this Pos...
Definition: PossibleContact.h:202
PossibleContact * getNext2()
Gets the next PossibleContact in the linked list of PossibleContact of the second particle in this Po...
Definition: PossibleContact.h:220
PossibleContact * getNext()
Gets the next PossibleContact in the general linked list of PossibleContact.
Definition: PossibleContact.h:146
void setPreviousPosition(PossibleContact *Prev)
Sets the previous PossibleContact in the linked list of PossibleContact of the given particle.
Definition: PossibleContact.h:291

References firstPossibleContact_, BaseObject::getIndex(), PossibleContact::getNext(), PossibleContact::getNext1(), PossibleContact::getNext2(), logger, PossibleContact::setPreviousPosition(), and VERBOSE.

◆ getFirstPossibleContact()

PossibleContact* PossibleContactList::getFirstPossibleContact ( )
inline

Get the front of the linked list of PossibleContact.

Returns
A pointer to the first PossibleContact on the linked list.
129  {
130  return firstPossibleContact_;
131  }

References firstPossibleContact_.

◆ remove_ParticlePosibleContacts()

void PossibleContactList::remove_ParticlePosibleContacts ( BaseParticle P)
inline

Remove all PossibleContact with given BaseParticle from the linked list.

Parameters
[in]PA pointer to the BaseParticle we want to remove all PossibleContact for.

To remove all PossibleContact with given BaseParticle from the linked list of all PossibleContact, go through all PossibleContact that are given as a list for the given BaseParticle, and then remove it from the global list by correcting all pointers and then delete the PossibleContact.

68  {
69  logger(VERBOSE, "Removing all contacts of particle %.", P->getIndex());
70  //The BaseParticle that shares a PossibleContact with P.
71  BaseParticle* O;
72  //The next possible contact for P.
73  PossibleContact* Next;
74  //The current possible contact for P.
75  PossibleContact* Curr = P->getFirstPossibleContact();
76  while (Curr != nullptr)
77  {
78  logger(VERBOSE, "Removing possible contacts index = % between particles % and %.", Curr->getIndex(),
79  Curr->getP1()->getIndex(), Curr->getP2()->getIndex());
80  Next = Curr->getNext(P);
81  O = Curr->getOtherParticle(P);
82  //Set the pointers of the next global possible contact.
83  if (Curr->getNext())
84  Curr->getNext()->setPreviousPosition(Curr->getPrevious());
85 
86  //Set the pointers of the previous possible contact.
87  if (Curr->getPrevious())
88  Curr->getPrevious()->setNextPosition(Curr->getNext());
89  else
91 
92  //Set the pointers of the other object of the possible contact.
93  if (Curr->getNext(O))
94  Curr->getNext(O)->setPreviousPosition(O, Curr->getPrevious(O));
95 
96  if (Curr->getPrevious(O))
97  Curr->getPrevious(O)->setNextPosition(O, Curr->getNext(O));
98  else
99  O->setFirstPossibleContact(Curr->getNext(O));
100 
101  //Delete the possible contact and update the the pointer Curr to the
102  //next possible contact with P.
103  delete Curr;
104  Curr = Next;
105  }
106  P->setFirstPossibleContact(nullptr);
107  }
@ O
Definition: StatisticsVector.h:21
Definition: BaseParticle.h:33
BaseParticle * getP2()
Gets a pointer to the second BaseParticle in this PossibleContact.
Definition: PossibleContact.h:118
void setNextPosition(PossibleContact *Next)
Sets the next PossibleContact in the linked list of PossibleContac.
Definition: PossibleContact.h:265
PossibleContact * getPrevious()
Gets the previous PossibleContact in the general linked list of PossibleContact.
Definition: PossibleContact.h:174
BaseParticle * getOtherParticle(BaseParticle *P)
Given one BaseParticle of the interacting pair, this function gets the other.
Definition: PossibleContact.h:128
BaseParticle * getP1()
Gets a pointer to the first BaseParticle in this PossibleContact.
Definition: PossibleContact.h:109
int getIndex()
Gets the index of this PossibleContact.
Definition: PossibleContact.h:238
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:77

References firstPossibleContact_, PossibleContact::getIndex(), BaseObject::getIndex(), PossibleContact::getNext(), PossibleContact::getOtherParticle(), PossibleContact::getP1(), PossibleContact::getP2(), PossibleContact::getPrevious(), logger, O, Global_Physical_Variables::P, PossibleContact::setNextPosition(), PossibleContact::setPreviousPosition(), and VERBOSE.

◆ write()

void PossibleContactList::write ( std::ostream &  os) const
inline

Write all PossibleContact to the given ostream.

Parameters
[in,out]osThe output stream the PossibleContactList must be written to.
114  {
115  os << "Possible contacts are: " << std::endl;
117  while (it != nullptr)
118  {
119  os << *it << std::endl;
120  it = it->getNext();
121  }
122  }

References firstPossibleContact_, and PossibleContact::getNext().

Member Data Documentation

◆ firstPossibleContact_

PossibleContact* PossibleContactList::firstPossibleContact_
private

The pointer to the first PossibleContact on the linked list.

Please note that this is the PossibleContact that has been added last.

Referenced by add_PossibleContact(), getFirstPossibleContact(), PossibleContactList(), remove_ParticlePosibleContacts(), and write().


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