PossibleContact.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 POSSIBLECONTACT_H
6 #define POSSIBLECONTACT_H
7 
9 #include "Logger.h"
10 
21 {
22 public:
27  {
28  P1_ = nullptr;
29  P2_ = nullptr;
30  Next_ = nullptr;
31  Prev_ = nullptr;
32  Next1_ = nullptr;
33  Prev1_ = nullptr;
34  Next2_ = nullptr;
35  Prev2_ = nullptr;
36  index_ = 0;
37  }
38 
45  {
46  P1_ = P1;
47  P2_ = P2;
48  Next_ = nullptr;
49  Prev_ = nullptr;
50  Next1_ = nullptr;
51  Prev1_ = nullptr;
52  Next2_ = nullptr;
53  Prev2_ = nullptr;
54  index_ = 0;
55  }
56 
64  {
65  P1_ = P1;
66  P2_ = P2;
67  Next_ = Next;
68  Prev_ = nullptr;
69  if (Next != nullptr)
70  index_ = Next->getIndex() + 1;
71  else
72  index_ = 0;
73 
74  Next1_ = nullptr;
75  Prev1_ = nullptr;
76  Next2_ = nullptr;
77  Prev2_ = nullptr;
78  }
79 
89  PossibleContact* Next2)
90  {
91  P1_ = P1;
92  P2_ = P2;
93  Next_ = Next;
94  Next1_ = Next1;
95  Next2_ = Next2;
96  Prev_ = 0;
97  Prev1_ = 0;
98  Prev2_ = 0;
99  if (Next != nullptr)
100  index_ = Next->getIndex() + 1;
101  else
102  index_ = 0;
103  }
104 
110  {
111  return P1_;
112  }
113 
119  {
120  return P2_;
121  }
122 
129  {
130  if (P1_ == P)
131  return P2_;
132  else if (P2_ == P)
133  return P1_;
134  else
135  {
136  logger(WARN, "Particle* getOtherParticle(Particle *P), no match for % posibilities are % and %",
137  P->getIndex(), P1_->getIndex(), P2_->getIndex());
138  return nullptr;
139  }
140  }
141 
147  {
148  return Next_;
149  }
150 
157  {
158  if (P1_ == P)
159  return Next1_;
160  else if (P2_ == P)
161  return Next2_;
162  else
163  {
164  logger(WARN, "PossibleContact* getNext(Particle* P), no match for %. Possibilities are % and %.",
165  P->getIndex(), P1_->getIndex(), P2_->getIndex());
166  return nullptr;
167  }
168  }
169 
175  {
176  return Prev_;
177  }
178 
185  {
186  if (P1_ == P)
187  return Prev1_;
188  else if (P2_ == P)
189  return Prev2_;
190  else
191  {
192  logger(WARN, "PossibleContact* getPrevious(Particle* P), no match for %. Possibilities are % and %.",
193  P->getIndex(), P1_->getIndex(), P2_->getIndex());
194  return nullptr;
195  }
196  }
197 
203  {
204  return Next1_;
205  }
206 
212  {
213  return Prev1_;
214  }
215 
221  {
222  return Next2_;
223  }
224 
230  {
231  return Prev2_;
232  }
233 
238  int getIndex()
239  {
240  return index_;
241  }
242 
247  void setP1(BaseParticle* P1)
248  {
249  P1_ = P1;
250  }
251 
256  void setP2(BaseParticle* P2)
257  {
258  P2_ = P2;
259  }
260 
266  {
267  Next_ = Next;
268  }
269 
276  {
277  if (P1_ == P)
278  Next1_ = Next;
279  else if (P2_ == P)
280  Next2_ = Next;
281  else
282  logger(WARN,
283  "void setNextPosition(Particle* P,PossibleContact* Next), no match for %. Possibilities are % and % ",
284  P->getIndex(), P1_->getIndex(), P2_->getIndex());
285  }
286 
292  {
293  Prev_ = Prev;
294  }
295 
302  {
303  if (P1_ == P)
304  Prev1_ = Prev;
305  else if (P2_ == P)
306  Prev2_ = Prev;
307  else
308  logger(WARN,
309  "void setPreviousPosition(Particle* P,PossibleContact* Prev), no match for %. Possibilities are % and % ",
310  P->getIndex(), P1_->getIndex(), P2_->getIndex());
311  }
312 
318  {
319  Next1_ = Next1;
320  }
321 
327  {
328  Prev1_ = Prev1;
329  }
330 
336  {
337  Next2_ = Next2;
338  }
339 
345  {
346  Prev2_ = Prev2;
347  }
348 
355  friend std::ostream& operator<<(std::ostream& os, const PossibleContact& o)
356  {
357  os << o.index_ << " between (" << o.P1_->getIndex() << "," << o.P2_->getIndex() << ")";
358  return os;
359  }
360 
361 private:
365  int index_;
398 
399 };
400 
401 #endif
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
@ WARN
unsigned int getIndex() const
Returns the index of the object in the handler.
Definition: BaseObject.h:97
Definition: BaseParticle.h:33
Class that describes a possible contact between two BaseParticle.
Definition: PossibleContact.h:21
void setP1(BaseParticle *P1)
Sets the first particle in this PossibleContact.
Definition: PossibleContact.h:247
BaseParticle * getP2()
Gets a pointer to the second BaseParticle in this PossibleContact.
Definition: PossibleContact.h:118
PossibleContact * Prev2_
A pointer to the PossibleContact that comes before this one in the linked list associated with the se...
Definition: PossibleContact.h:397
PossibleContact * getPrevious1()
Gets the previous PossibleContact in the linked list of PossibleContact of the first particle in this...
Definition: PossibleContact.h:211
PossibleContact * getPrevious2()
Gets the previous PossibleContact in the linked list of PossibleContact of the second particle in thi...
Definition: PossibleContact.h:229
PossibleContact * Next1_
A pointer to the PossibleContact that comes after this one in the linked list associated with the fir...
Definition: PossibleContact.h:385
BaseParticle * P1_
A pointer to the first BaseParticle in this PossibleContact.
Definition: PossibleContact.h:369
PossibleContact * Prev_
A pointer to the PossibleContact that comes before this one in the linked list.
Definition: PossibleContact.h:381
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...
Definition: PossibleContact.h:88
BaseParticle * P2_
A pointer to the second BaseParticle in this PossibleContact.
Definition: PossibleContact.h:373
void setNextPosition1(PossibleContact *Next1)
Sets the next PossibleContact in the linked list of PossibleContact of the first particle in this Pos...
Definition: PossibleContact.h:317
PossibleContact * Next2_
A pointer to the PossibleContact that comes after this one in the linked list associated with the sec...
Definition: PossibleContact.h:393
void setNextPosition(PossibleContact *Next)
Sets the next PossibleContact in the linked list of PossibleContac.
Definition: PossibleContact.h:265
void setP2(BaseParticle *P2)
Sets the second particle in this PossibleContact.
Definition: PossibleContact.h:256
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()
Default constructor, sets all pointers to nullptr.
Definition: PossibleContact.h:26
void setPreviousPosition1(PossibleContact *Prev1)
Sets the previous PossibleContact in the linked list of PossibleContact of the first particle in this...
Definition: PossibleContact.h:326
void setPreviousPosition(BaseParticle *P, PossibleContact *Prev)
Sets the previous PossibleContact in the linked list of PossibleContact of the given particle.
Definition: PossibleContact.h:301
void setPreviousPosition2(PossibleContact *Prev2)
Sets the previous PossibleContact in the linked list of PossibleContact of the second particle in thi...
Definition: PossibleContact.h:344
void setNextPosition(BaseParticle *P, PossibleContact *Next)
Sets the next PossibleContact in the linked list of PossibleContact of the given particle.
Definition: PossibleContact.h:275
int index_
The index of this PossibleContact.
Definition: PossibleContact.h:365
PossibleContact * getNext(BaseParticle *P)
Gets the next PossibleContact in the linked list of PossibleContact of the given particle.
Definition: PossibleContact.h:156
PossibleContact(BaseParticle *P1, BaseParticle *P2)
Constructor that takes two BaseParticle and sets them to be the BaseParticle associated with this Pos...
Definition: PossibleContact.h:44
PossibleContact * Next_
A pointer to the PossibleContact that comes after this one in the linked list.
Definition: PossibleContact.h:377
PossibleContact * Prev1_
A pointer to the PossibleContact that comes before this one in the linked list associated with the fi...
Definition: PossibleContact.h:389
PossibleContact * getNext()
Gets the next PossibleContact in the general linked list of PossibleContact.
Definition: PossibleContact.h:146
PossibleContact * getPrevious(BaseParticle *P)
Gets the previous PossibleContact in the linked list of PossibleContact of the given particle.
Definition: PossibleContact.h:184
PossibleContact * getPrevious()
Gets the previous PossibleContact in the general linked list of PossibleContact.
Definition: PossibleContact.h:174
PossibleContact(BaseParticle *P1, BaseParticle *P2, PossibleContact *Next)
Constructor that takes two BaseParticle and the next global PossibleContact in the list and construct...
Definition: PossibleContact.h:63
BaseParticle * getOtherParticle(BaseParticle *P)
Given one BaseParticle of the interacting pair, this function gets the other.
Definition: PossibleContact.h:128
void setNextPosition2(PossibleContact *Next2)
Sets the next PossibleContact in the linked list of PossibleContact of the second particle in this Po...
Definition: PossibleContact.h:335
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
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 ...
Definition: PossibleContact.h:355
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:77