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.

51  {
52  firstPossibleContact_ = nullptr;
53  logger(DEBUG, "PossibleContactList() constructor finished.");
54  }
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:160

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.

65  {
66  firstPossibleContact_ = new PossibleContact(P1, P2, firstPossibleContact_, P1->getFirstPossibleContact(),
67  P2->getFirstPossibleContact());
68  P1->setFirstPossibleContact(firstPossibleContact_);
69  P2->setFirstPossibleContact(firstPossibleContact_);
76  logger(VERBOSE, "Added new possible contact between particles % and % ", P1->getIndex(), P2->getIndex());
77  }
@ VERBOSE
unsigned int getIndex() const
Returns the index of the object in the handler.
Definition: BaseObject.h:118
Class that describes a possible contact between two BaseParticle.
Definition: PossibleContact.h:42
PossibleContact * getNext1()
Gets the next PossibleContact in the linked list of PossibleContact of the first particle in this Pos...
Definition: PossibleContact.h:223
PossibleContact * getNext2()
Gets the next PossibleContact in the linked list of PossibleContact of the second particle in this Po...
Definition: PossibleContact.h:241
PossibleContact * getNext()
Gets the next PossibleContact in the general linked list of PossibleContact.
Definition: PossibleContact.h:167
void setPreviousPosition(PossibleContact *Prev)
Sets the previous PossibleContact in the linked list of PossibleContact of the given particle.
Definition: PossibleContact.h:312

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.
150  {
151  return firstPossibleContact_;
152  }

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.

89  {
90  logger(VERBOSE, "Removing all contacts of particle %.", P->getIndex());
91  //The BaseParticle that shares a PossibleContact with P.
92  BaseParticle* O;
93  //The next possible contact for P.
94  PossibleContact* Next;
95  //The current possible contact for P.
96  PossibleContact* Curr = P->getFirstPossibleContact();
97  while (Curr != nullptr)
98  {
99  logger(VERBOSE, "Removing possible contacts index = % between particles % and %.", Curr->getIndex(),
100  Curr->getP1()->getIndex(), Curr->getP2()->getIndex());
101  Next = Curr->getNext(P);
102  O = Curr->getOtherParticle(P);
103  //Set the pointers of the next global possible contact.
104  if (Curr->getNext())
105  Curr->getNext()->setPreviousPosition(Curr->getPrevious());
106 
107  //Set the pointers of the previous possible contact.
108  if (Curr->getPrevious())
109  Curr->getPrevious()->setNextPosition(Curr->getNext());
110  else
111  firstPossibleContact_ = Curr->getNext();
112 
113  //Set the pointers of the other object of the possible contact.
114  if (Curr->getNext(O))
115  Curr->getNext(O)->setPreviousPosition(O, Curr->getPrevious(O));
116 
117  if (Curr->getPrevious(O))
118  Curr->getPrevious(O)->setNextPosition(O, Curr->getNext(O));
119  else
120  O->setFirstPossibleContact(Curr->getNext(O));
121 
122  //Delete the possible contact and update the the pointer Curr to the
123  //next possible contact with P.
124  delete Curr;
125  Curr = Next;
126  }
127  P->setFirstPossibleContact(nullptr);
128  }
@ O
Definition: StatisticsVector.h:42
Definition: BaseParticle.h:54
BaseParticle * getP2()
Gets a pointer to the second BaseParticle in this PossibleContact.
Definition: PossibleContact.h:139
void setNextPosition(PossibleContact *Next)
Sets the next PossibleContact in the linked list of PossibleContac.
Definition: PossibleContact.h:286
PossibleContact * getPrevious()
Gets the previous PossibleContact in the general linked list of PossibleContact.
Definition: PossibleContact.h:195
BaseParticle * getOtherParticle(BaseParticle *P)
Given one BaseParticle of the interacting pair, this function gets the other.
Definition: PossibleContact.h:149
BaseParticle * getP1()
Gets a pointer to the first BaseParticle in this PossibleContact.
Definition: PossibleContact.h:130
int getIndex()
Gets the index of this PossibleContact.
Definition: PossibleContact.h:259
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:73

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.
135  {
136  os << "Possible contacts are: " << std::endl;
138  while (it != nullptr)
139  {
140  os << *it << std::endl;
141  it = it->getNext();
142  }
143  }

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: