MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PossibleContactList.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2020, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 #ifndef POSSIBLECONTACTLIST_H
27 #define POSSIBLECONTACTLIST_H
28 
29 #include "PossibleContact.h"
30 
44 {
45 public:
46 
51  {
52  firstPossibleContact_ = nullptr;
53  logger(DEBUG, "PossibleContactList() constructor finished.");
54  }
55 
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  }
78 
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  }
129 
134  void write(std::ostream& os) const
135  {
136  os << "Possible contacts are: " << std::endl;
138  while (it != nullptr)
139  {
140  os << *it << std::endl;
141  it = it->getNext();
142  }
143  }
144 
150  {
151  return firstPossibleContact_;
152  }
153 
154 private:
161 
162 };
163 
164 #endif
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...
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 * getNext1()
Gets the next PossibleContact in the linked list of PossibleContact of the first particle in this Pos...
PossibleContact * getPrevious()
Gets the previous PossibleContact in the general linked list of PossibleContact.
void remove_ParticlePosibleContacts(BaseParticle *P)
Remove all PossibleContact with given BaseParticle from the linked list.
BaseParticle * getP2()
Gets a pointer to the second BaseParticle in this PossibleContact.
PossibleContactList()
Constructor, sets the firstPossibleContact_ to a nullptr since there are no possible interactions yet...
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.
Manages the linked list of PossibleContact.
void write(std::ostream &os) const
Write all PossibleContact to the given ostream.
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.
void add_PossibleContact(BaseParticle *P1, BaseParticle *P2)
Add the possible contact between two given BaseParticle to the linked list.
Class that describes a possible contact between two BaseParticle.
PossibleContact * getFirstPossibleContact()
Get the front of the linked list of PossibleContact.
int getIndex()
Gets the index of this PossibleContact.