PossibleContact.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2023, 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  PossibleContact* Next2)
111  {
112  P1_ = P1;
113  P2_ = P2;
114  Next_ = Next;
115  Next1_ = Next1;
116  Next2_ = Next2;
117  Prev_ = 0;
118  Prev1_ = 0;
119  Prev2_ = 0;
120  if (Next != nullptr)
121  index_ = Next->getIndex() + 1;
122  else
123  index_ = 0;
124  }
125 
131  {
132  return P1_;
133  }
134 
140  {
141  return P2_;
142  }
143 
150  {
151  if (P1_ == P)
152  return P2_;
153  else if (P2_ == P)
154  return P1_;
155  else
156  {
157  logger(WARN, "Particle* getOtherParticle(Particle *P), no match for % posibilities are % and %",
158  P->getIndex(), P1_->getIndex(), P2_->getIndex());
159  return nullptr;
160  }
161  }
162 
168  {
169  return Next_;
170  }
171 
178  {
179  if (P1_ == P)
180  return Next1_;
181  else if (P2_ == P)
182  return Next2_;
183  else
184  {
185  logger(WARN, "PossibleContact* getNext(Particle* P), no match for %. Possibilities are % and %.",
186  P->getIndex(), P1_->getIndex(), P2_->getIndex());
187  return nullptr;
188  }
189  }
190 
196  {
197  return Prev_;
198  }
199 
206  {
207  if (P1_ == P)
208  return Prev1_;
209  else if (P2_ == P)
210  return Prev2_;
211  else
212  {
213  logger(WARN, "PossibleContact* getPrevious(Particle* P), no match for %. Possibilities are % and %.",
214  P->getIndex(), P1_->getIndex(), P2_->getIndex());
215  return nullptr;
216  }
217  }
218 
224  {
225  return Next1_;
226  }
227 
233  {
234  return Prev1_;
235  }
236 
242  {
243  return Next2_;
244  }
245 
251  {
252  return Prev2_;
253  }
254 
259  int getIndex()
260  {
261  return index_;
262  }
263 
268  void setP1(BaseParticle* P1)
269  {
270  P1_ = P1;
271  }
272 
277  void setP2(BaseParticle* P2)
278  {
279  P2_ = P2;
280  }
281 
287  {
288  Next_ = Next;
289  }
290 
297  {
298  if (P1_ == P)
299  Next1_ = Next;
300  else if (P2_ == P)
301  Next2_ = Next;
302  else
303  logger(WARN,
304  "void setNextPosition(Particle* P,PossibleContact* Next), no match for %. Possibilities are % and % ",
305  P->getIndex(), P1_->getIndex(), P2_->getIndex());
306  }
307 
313  {
314  Prev_ = Prev;
315  }
316 
323  {
324  if (P1_ == P)
325  Prev1_ = Prev;
326  else if (P2_ == P)
327  Prev2_ = Prev;
328  else
329  logger(WARN,
330  "void setPreviousPosition(Particle* P,PossibleContact* Prev), no match for %. Possibilities are % and % ",
331  P->getIndex(), P1_->getIndex(), P2_->getIndex());
332  }
333 
339  {
340  Next1_ = Next1;
341  }
342 
348  {
349  Prev1_ = Prev1;
350  }
351 
357  {
358  Next2_ = Next2;
359  }
360 
366  {
367  Prev2_ = Prev2;
368  }
369 
376  friend std::ostream& operator<<(std::ostream& os, const PossibleContact& o)
377  {
378  os << o.index_ << " between (" << o.P1_->getIndex() << "," << o.P2_->getIndex() << ")";
379  return os;
380  }
381 
382 private:
386  int index_;
419 
420 };
421 
422 #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:118
Definition: BaseParticle.h:54
Class that describes a possible contact between two BaseParticle.
Definition: PossibleContact.h:42
void setP1(BaseParticle *P1)
Sets the first particle in this PossibleContact.
Definition: PossibleContact.h:268
BaseParticle * getP2()
Gets a pointer to the second BaseParticle in this PossibleContact.
Definition: PossibleContact.h:139
PossibleContact * Prev2_
A pointer to the PossibleContact that comes before this one in the linked list associated with the se...
Definition: PossibleContact.h:418
PossibleContact * getPrevious1()
Gets the previous PossibleContact in the linked list of PossibleContact of the first particle in this...
Definition: PossibleContact.h:232
PossibleContact * getPrevious2()
Gets the previous PossibleContact in the linked list of PossibleContact of the second particle in thi...
Definition: PossibleContact.h:250
PossibleContact * Next1_
A pointer to the PossibleContact that comes after this one in the linked list associated with the fir...
Definition: PossibleContact.h:406
BaseParticle * P1_
A pointer to the first BaseParticle in this PossibleContact.
Definition: PossibleContact.h:390
PossibleContact * Prev_
A pointer to the PossibleContact that comes before this one in the linked list.
Definition: PossibleContact.h:402
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:109
BaseParticle * P2_
A pointer to the second BaseParticle in this PossibleContact.
Definition: PossibleContact.h:394
void setNextPosition1(PossibleContact *Next1)
Sets the next PossibleContact in the linked list of PossibleContact of the first particle in this Pos...
Definition: PossibleContact.h:338
PossibleContact * Next2_
A pointer to the PossibleContact that comes after this one in the linked list associated with the sec...
Definition: PossibleContact.h:414
void setNextPosition(PossibleContact *Next)
Sets the next PossibleContact in the linked list of PossibleContac.
Definition: PossibleContact.h:286
void setP2(BaseParticle *P2)
Sets the second particle in this PossibleContact.
Definition: PossibleContact.h:277
PossibleContact * getNext1()
Gets the next PossibleContact in the linked list of PossibleContact of the first particle in this Pos...
Definition: PossibleContact.h:223
PossibleContact * getNext2()
Gets the next PossibleContact in the linked list of PossibleContact of the second particle in this Po...
Definition: PossibleContact.h:241
PossibleContact()
Default constructor, sets all pointers to nullptr.
Definition: PossibleContact.h:47
void setPreviousPosition1(PossibleContact *Prev1)
Sets the previous PossibleContact in the linked list of PossibleContact of the first particle in this...
Definition: PossibleContact.h:347
void setPreviousPosition(BaseParticle *P, PossibleContact *Prev)
Sets the previous PossibleContact in the linked list of PossibleContact of the given particle.
Definition: PossibleContact.h:322
void setPreviousPosition2(PossibleContact *Prev2)
Sets the previous PossibleContact in the linked list of PossibleContact of the second particle in thi...
Definition: PossibleContact.h:365
void setNextPosition(BaseParticle *P, PossibleContact *Next)
Sets the next PossibleContact in the linked list of PossibleContact of the given particle.
Definition: PossibleContact.h:296
int index_
The index of this PossibleContact.
Definition: PossibleContact.h:386
PossibleContact * getNext(BaseParticle *P)
Gets the next PossibleContact in the linked list of PossibleContact of the given particle.
Definition: PossibleContact.h:177
PossibleContact(BaseParticle *P1, BaseParticle *P2)
Constructor that takes two BaseParticle and sets them to be the BaseParticle associated with this Pos...
Definition: PossibleContact.h:65
PossibleContact * Next_
A pointer to the PossibleContact that comes after this one in the linked list.
Definition: PossibleContact.h:398
PossibleContact * Prev1_
A pointer to the PossibleContact that comes before this one in the linked list associated with the fi...
Definition: PossibleContact.h:410
PossibleContact * getNext()
Gets the next PossibleContact in the general linked list of PossibleContact.
Definition: PossibleContact.h:167
PossibleContact * getPrevious(BaseParticle *P)
Gets the previous PossibleContact in the linked list of PossibleContact of the given particle.
Definition: PossibleContact.h:205
PossibleContact * getPrevious()
Gets the previous PossibleContact in the general linked list of PossibleContact.
Definition: PossibleContact.h:195
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:84
BaseParticle * getOtherParticle(BaseParticle *P)
Given one BaseParticle of the interacting pair, this function gets the other.
Definition: PossibleContact.h:149
void setNextPosition2(PossibleContact *Next2)
Sets the next PossibleContact in the linked list of PossibleContact of the second particle in this Po...
Definition: PossibleContact.h:356
void setPreviousPosition(PossibleContact *Prev)
Sets the previous PossibleContact in the linked list of PossibleContact of the given particle.
Definition: PossibleContact.h:312
BaseParticle * getP1()
Gets a pointer to the first BaseParticle in this PossibleContact.
Definition: PossibleContact.h:130
int getIndex()
Gets the index of this PossibleContact.
Definition: PossibleContact.h:259
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:376
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:73