MercuryDPM  Beta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PossibleContact.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2014, 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 POSSIBLECONTACT_H
27 #define POSSIBLECONTACT_H
28 
29 #include "Particles/BaseParticle.h"
30 #include "Logger.h"
31 
42 {
43 public:
48  {
49  P1_ = nullptr;
50  P2_ = nullptr;
51  Next_ = nullptr;
52  Prev_ = nullptr;
53  Next1_ = nullptr;
54  Prev1_ = nullptr;
55  Next2_ = nullptr;
56  Prev2_ = nullptr;
57  index_ = 0;
58  }
59 
66  {
67  P1_ = P1;
68  P2_ = P2;
69  Next_ = nullptr;
70  Prev_ = nullptr;
71  Next1_ = nullptr;
72  Prev1_ = nullptr;
73  Next2_ = nullptr;
74  Prev2_ = nullptr;
75  index_ = 0;
76  }
77 
85  {
86  P1_ = P1;
87  P2_ = P2;
88  Next_ = Next;
89  Prev_ = nullptr;
90  if (Next != nullptr)
91  index_ = Next->getIndex() + 1;
92  else
93  index_ = 0;
94 
95  Next1_ = nullptr;
96  Prev1_ = nullptr;
97  Next2_ = nullptr;
98  Prev2_ = nullptr;
99  }
100 
110  {
111  P1_ = P1;
112  P2_ = P2;
113  Next_ = Next;
114  Next1_ = Next1;
115  Next2_ = Next2;
116  Prev_ = 0;
117  Prev1_ = 0;
118  Prev2_ = 0;
119  if (Next != nullptr)
120  index_ = Next->getIndex() + 1;
121  else
122  index_ = 0;
123  }
124 
130  {
131  return P1_;
132  }
133 
139  {
140  return P2_;
141  }
142 
149  {
150  if (P1_ == P)
151  return P2_;
152  else if (P2_ == P)
153  return P1_;
154  else
155  {
156  std::cout << "Particle* getOtherParticle(Particle *P), no match for " << P->getIndex() << " posibilities are " << P1_->getIndex() << " and " << P2_->getIndex() << std::endl;
157  return nullptr;
158  }
159  }
160 
166  {
167  return Next_;
168  }
169 
176  {
177  if (P1_ == P)
178  return Next1_;
179  else if (P2_ == P)
180  return Next2_;
181  else
182  {
183  logger(WARN, "PossibleContact* getNext(Particle* P), no match for %. Possibilities are % and %.", P->getIndex(), P1_->getIndex(), P2_->getIndex());
184  return nullptr;
185  }
186  }
187 
193  {
194  return Prev_;
195  }
196 
203  {
204  if (P1_ == P)
205  return Prev1_;
206  else if (P2_ == P)
207  return Prev2_;
208  else
209  {
210  logger(WARN, "PossibleContact* getPrevious(Particle* P), no match for %. Possibilities are % and %.", P->getIndex(), P1_->getIndex(), P2_->getIndex());
211  return nullptr;
212  }
213  }
214 
220  {
221  return Next1_;
222  }
223 
229  {
230  return Prev1_;
231  }
232 
238  {
239  return Next2_;
240  }
241 
247  {
248  return Prev2_;
249  }
250 
255  int getIndex()
256  {
257  return index_;
258  }
259 
264  void setP1(BaseParticle* P1)
265  {
266  P1_ = P1;
267  }
268 
273  void setP2(BaseParticle* P2)
274  {
275  P2_ = P2;
276  }
277 
283  {
284  Next_ = Next;
285  }
286 
293  {
294  if (P1_ == P)
295  Next1_ = Next;
296  else if (P2_ == P)
297  Next2_ = Next;
298  else
299  logger(WARN, "void setNextPosition(Particle* P,PossibleContact* Next), no match for %. Possibilities are % and % ", P->getIndex(), P1_->getIndex(), P2_->getIndex());
300  }
301 
307  {
308  Prev_ = Prev;
309  }
310 
317  {
318  if (P1_ == P)
319  Prev1_ = Prev;
320  else if (P2_ == P)
321  Prev2_ = Prev;
322  else
323  logger(WARN, "void setPreviousPosition(Particle* P,PossibleContact* Prev), no match for %. Possibilities are % and % ", P->getIndex(), P1_->getIndex(), P2_->getIndex());
324  }
325 
331  {
332  Next1_ = Next1;
333  }
334 
340  {
341  Prev1_ = Prev1;
342  }
343 
349  {
350  Next2_ = Next2;
351  }
352 
358  {
359  Prev2_ = Prev2;
360  }
361 
368  friend std::ostream& operator <<(std::ostream& os, const PossibleContact& o)
369  {
370  os<<o.index_<<" between ("<<o.P1_->getIndex()<<","<<o.P2_->getIndex()<<")";
371  return os;
372  }
373 
374 private:
378  int index_;
411 
412 };
413 
414 #endif
PossibleContact * Prev2_
A pointer to the PossibleContact that comes before this one in the linked list associated with the se...
unsigned int getIndex() const
Returns the index of the object in the handler.
Definition: BaseObject.cc:106
PossibleContact()
Default constructor, sets all pointers to nullptr.
PossibleContact * getNext2()
Gets the next PossibleContact in the linked list of PossibleContact of the second particle in this Po...
PossibleContact * getPrevious2()
Gets the previous PossibleContact in the linked list of PossibleContact of the second particle in thi...
BaseParticle * getP1()
Gets a pointer to the first BaseParticle in this PossibleContact.
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
PossibleContact(BaseParticle *P1, BaseParticle *P2)
Constructor that takes two BaseParticle and sets them to be the BaseParticle associated with this Pos...
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...
void setNextPosition1(PossibleContact *Next1)
Sets 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.
PossibleContact * Next1_
A pointer to the PossibleContact that comes after this one in the linked list associated with the fir...
BaseParticle * getP2()
Gets a pointer to the second BaseParticle in this PossibleContact.
PossibleContact * Next_
A pointer to the PossibleContact that comes after this one in the linked list.
PossibleContact(BaseParticle *P1, BaseParticle *P2, PossibleContact *Next, PossibleContact *Next1, PossibleContact *Next2)
Constructor that should be used, takes all required information as parameters and sets it in the data...
PossibleContact * getPrevious1()
Gets the previous PossibleContact in the linked list of PossibleContact of the first particle in this...
PossibleContact * getNext()
Gets the next PossibleContact in the general linked list of PossibleContact.
PossibleContact * getNext(BaseParticle *P)
Gets the next PossibleContact in the linked list of PossibleContact of the given particle.
PossibleContact * getPrevious(BaseParticle *P)
Gets the previous PossibleContact in the linked list of PossibleContact of the given particle...
void setNextPosition2(PossibleContact *Next2)
Sets the next PossibleContact in the linked list of PossibleContact of the second particle in this Po...
void setPreviousPosition1(PossibleContact *Prev1)
Sets the previous PossibleContact in the linked list of PossibleContact of the first particle in this...
PossibleContact * Next2_
A pointer to the PossibleContact that comes after this one in the linked list associated with the sec...
int index_
The index of this PossibleContact.
PossibleContact * Prev1_
A pointer to the PossibleContact that comes before this one in the linked list associated with the fi...
void setNextPosition(BaseParticle *P, PossibleContact *Next)
Sets the next PossibleContact in the linked list of PossibleContact of the given particle.
void setPreviousPosition(BaseParticle *P, PossibleContact *Prev)
Sets the previous PossibleContact in the linked list of PossibleContact of the given particle...
friend std::ostream & operator<<(std::ostream &os, const PossibleContact &o)
Writes the index of this PossibleContact and the indices of the BaseParticle of this PossibleContact ...
void setPreviousPosition2(PossibleContact *Prev2)
Sets the previous PossibleContact in the linked list of PossibleContact of the second particle in thi...
BaseParticle * P1_
A pointer to the first BaseParticle in this PossibleContact.
PossibleContact(BaseParticle *P1, BaseParticle *P2, PossibleContact *Next)
Constructor that takes two BaseParticle and the next global PossibleContact in the list and construct...
void setNextPosition(PossibleContact *Next)
Sets the next PossibleContact in the linked list of PossibleContac.
void setP2(BaseParticle *P2)
Sets the second particle in this PossibleContact.
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.
BaseParticle * P2_
A pointer to the second BaseParticle in this PossibleContact.
void setP1(BaseParticle *P1)
Sets the first particle in this PossibleContact.
int getIndex()
Gets the index of this PossibleContact.
PossibleContact * Prev_
A pointer to the PossibleContact that comes before this one in the linked list.