MercuryDPM  Trunk
 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(),
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  }
unsigned int getIndex() const
Returns the index of the object in the handler.
Definition: BaseObject.h:118
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 149 of file PossibleContactList.h.

References firstPossibleContact_.

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

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  }
unsigned int getIndex() const
Returns the index of the object in the handler.
Definition: BaseObject.h:118
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 134 of file PossibleContactList.h.

References firstPossibleContact_, and PossibleContact::getNext().

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