MercuryDPM  Beta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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.

Definition at line 43 of file PossibleContactList.h.

Constructor & Destructor Documentation

PossibleContactList::PossibleContactList ( )
inline

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

Definition at line 50 of file PossibleContactList.h.

References DEBUG, firstPossibleContact_, and logger.

51  {
52  firstPossibleContact_ = nullptr;
53  logger(DEBUG, "PossibleContactList() constructor finished.");
54  }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
PossibleContact * firstPossibleContact_
The pointer to the first PossibleContact on the linked list.

Member Function Documentation

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.

Definition at line 64 of file PossibleContactList.h.

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

65  {
66  firstPossibleContact_ = new PossibleContact(P1, P2, firstPossibleContact_, P1->getFirstPossibleContact(), P2->getFirstPossibleContact());
67  P1->setFirstPossibleContact(firstPossibleContact_);
68  P2->setFirstPossibleContact(firstPossibleContact_);
75  logger(VERBOSE, "Added new possible contact between particles % and % ", P1->getIndex(), P2->getIndex());
76  }
unsigned int getIndex() const
Returns the index of the object in the handler.
Definition: BaseObject.cc:106
PossibleContact * getNext2()
Gets the next PossibleContact in the linked list of PossibleContact of the second particle in this Po...
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
void setPreviousPosition(PossibleContact *Prev)
Sets the previous PossibleContact in the linked list of PossibleContact of the given particle...
PossibleContact * getNext1()
Gets the next PossibleContact in the linked list of PossibleContact of the first particle in this Pos...
PossibleContact * getNext()
Gets the next PossibleContact in the general linked list of PossibleContact.
PossibleContact * firstPossibleContact_
The pointer to the first PossibleContact on the linked list.
Class that describes a possible contact between two BaseParticle.
PossibleContact* PossibleContactList::getFirstPossibleContact ( )
inline

Get the front of the linked list of PossibleContact.

Returns
A pointer to the first PossibleContact on the linked list.

Definition at line 147 of file PossibleContactList.h.

References firstPossibleContact_.

148  {
149  return firstPossibleContact_;
150  }
PossibleContact * firstPossibleContact_
The pointer to the first PossibleContact on the linked list.
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.

Definition at line 87 of file PossibleContactList.h.

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

88  {
89  logger(VERBOSE, "Removing all contacts of particle %.", P->getIndex());
90  //The BaseParticle that shares a PossibleContact with P.
91  BaseParticle* O;
92  //The next possible contact for P.
93  PossibleContact* Next;
94  //The current possible contact for P.
95  PossibleContact* Curr = P->getFirstPossibleContact();
96  while (Curr != nullptr)
97  {
98  logger(VERBOSE, "Removing possible contacts index = % between particles % and %.", Curr->getIndex(), Curr->getP1()->getIndex(), Curr->getP2()->getIndex());
99  Next = Curr->getNext(P);
100  O = Curr->getOtherParticle(P);
101  //Set the pointers of the next global possible contact.
102  if (Curr->getNext())
103  Curr->getNext()->setPreviousPosition(Curr->getPrevious());
104 
105  //Set the pointers of the previous possible contact.
106  if (Curr->getPrevious())
107  Curr->getPrevious()->setNextPosition(Curr->getNext());
108  else
109  firstPossibleContact_ = Curr->getNext();
110 
111  //Set the pointers of the other object of the possible contact.
112  if (Curr->getNext(O))
113  Curr->getNext(O)->setPreviousPosition(O, Curr->getPrevious(O));
114 
115  if (Curr->getPrevious(O))
116  Curr->getPrevious(O)->setNextPosition(O, Curr->getNext(O));
117  else
118  O->setFirstPossibleContact(Curr->getNext(O));
119 
120  //Delete the possible contact and update the the pointer Curr to the
121  //next possible contact with P.
122  delete Curr;
123  Curr = Next;
124  }
125  P->setFirstPossibleContact(nullptr);
126  }
unsigned int getIndex() const
Returns the index of the object in the handler.
Definition: BaseObject.cc:106
BaseParticle * getP1()
Gets a pointer to the first BaseParticle in this PossibleContact.
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
void setPreviousPosition(PossibleContact *Prev)
Sets the previous PossibleContact in the linked list of PossibleContact of the given particle...
PossibleContact * getPrevious()
Gets the previous PossibleContact in the general linked list of PossibleContact.
BaseParticle * getP2()
Gets a pointer to the second BaseParticle in this PossibleContact.
PossibleContact * getNext()
Gets the next PossibleContact in the general linked list of PossibleContact.
PossibleContact * firstPossibleContact_
The pointer to the first PossibleContact on the linked list.
void setNextPosition(PossibleContact *Next)
Sets the next PossibleContact in the linked list of PossibleContac.
BaseParticle * getOtherParticle(BaseParticle *P)
Given one BaseParticle of the interacting pair, this function gets the other.
Class that describes a possible contact between two BaseParticle.
int getIndex()
Gets the index of this PossibleContact.
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.

Definition at line 132 of file PossibleContactList.h.

References firstPossibleContact_, and PossibleContact::getNext().

133  {
134  os << "Possible contacts are: " << std::endl;
136  while(it != nullptr)
137  {
138  os << *it << std::endl;
139  it = it->getNext();
140  }
141  }
PossibleContact * getNext()
Gets the next PossibleContact in the general linked list of PossibleContact.
PossibleContact * firstPossibleContact_
The pointer to the first PossibleContact on the linked list.
Class that describes a possible contact between two BaseParticle.

Member Data Documentation

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.

Definition at line 158 of file PossibleContactList.h.

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


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