PossibleContactList.h
Go to the documentation of this file.
1 // This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2 // Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3 // License: BSD 3-Clause License; see the LICENSE file in the root directory.
4 
5 #ifndef POSSIBLECONTACTLIST_H
6 #define POSSIBLECONTACTLIST_H
7 
8 #include "PossibleContact.h"
9 
23 {
24 public:
25 
30  {
31  firstPossibleContact_ = nullptr;
32  logger(DEBUG, "PossibleContactList() constructor finished.");
33  }
34 
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  }
57 
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  }
108 
113  void write(std::ostream& os) const
114  {
115  os << "Possible contacts are: " << std::endl;
117  while (it != nullptr)
118  {
119  os << *it << std::endl;
120  it = it->getNext();
121  }
122  }
123 
129  {
130  return firstPossibleContact_;
131  }
132 
133 private:
140 
141 };
142 
143 #endif
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
@ DEBUG
@ VERBOSE
@ O
Definition: StatisticsVector.h:21
unsigned int getIndex() const
Returns the index of the object in the handler.
Definition: BaseObject.h:97
Definition: BaseParticle.h:33
Manages the linked list of PossibleContact.
Definition: PossibleContactList.h:23
void write(std::ostream &os) const
Write all PossibleContact to the given ostream.
Definition: PossibleContactList.h:113
void remove_ParticlePosibleContacts(BaseParticle *P)
Remove all PossibleContact with given BaseParticle from the linked list.
Definition: PossibleContactList.h:67
void add_PossibleContact(BaseParticle *P1, BaseParticle *P2)
Add the possible contact between two given BaseParticle to the linked list.
Definition: PossibleContactList.h:43
PossibleContact * firstPossibleContact_
The pointer to the first PossibleContact on the linked list.
Definition: PossibleContactList.h:139
PossibleContactList()
Constructor, sets the firstPossibleContact_ to a nullptr since there are no possible interactions yet...
Definition: PossibleContactList.h:29
PossibleContact * getFirstPossibleContact()
Get the front of the linked list of PossibleContact.
Definition: PossibleContactList.h:128
Class that describes a possible contact between two BaseParticle.
Definition: PossibleContact.h:21
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 * 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
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
void setPreviousPosition(PossibleContact *Prev)
Sets the previous PossibleContact in the linked list of PossibleContact of the given particle.
Definition: PossibleContact.h:291
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