CollisionRecordList.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "CollisionRecordList.H"
27 #include "IOstreams.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class PairType, class WallType>
33 :
34  pairRecords_(),
35  wallRecords_()
36 {}
37 
38 
39 template<class PairType, class WallType>
41 :
42  pairRecords_(is),
43  wallRecords_(is)
44 {
45  // Check state of Istream
46  is.check
47  (
48  "Foam::CollisionRecordList<PairType, WallType>::"
49  "CollisionRecordList(Foam::Istream&)"
50  );
51 }
52 
53 
54 template<class PairType, class WallType>
56 (
57  const labelField& pairAccessed,
58  const labelField& pairOrigProcOfOther,
59  const labelField& pairOrigIdOfOther,
60  const Field<PairType>& pairData,
61  const labelField& wallAccessed,
62  const vectorField& wallPRel,
63  const Field<WallType>& wallData
64 )
65 :
66  pairRecords_(),
67  wallRecords_()
68 {
69  label nPair = pairAccessed.size();
70 
71  if
72  (
73  pairOrigProcOfOther.size() != nPair
74  || pairOrigIdOfOther.size() != nPair
75  || pairData.size() != nPair
76  )
77  {
79  (
80  "Foam::CollisionRecordList<PairType, WallType>::CollisionRecordList"
81  "("
82  "const labelField& pairAccessed,"
83  "const labelField& pairOrigProcOfOther,"
84  "const labelField& pairOrigIdOfOther,"
85  "const Field<PairType>& pairData,"
86  "const labelField& wallAccessed,"
87  "const vectorField& wallPRel,"
88  "const Field<WallType>& wallData"
89  ")"
90  )
91  << "Pair field size mismatch." << nl
92  << pairAccessed << nl
93  << pairOrigProcOfOther << nl
94  << pairOrigIdOfOther << nl
95  << pairData << nl
96  << abort(FatalError);
97  }
98 
99  forAll(pairAccessed, i)
100  {
101  pairRecords_.append
102  (
104  (
105  pairAccessed[i],
106  pairOrigProcOfOther[i],
107  pairOrigIdOfOther[i],
108  pairData[i]
109  )
110  );
111  }
112 
113  label nWall = wallAccessed.size();
114 
115  if (wallPRel.size() != nWall || wallData.size() != nWall)
116  {
118  (
119  "Foam::CollisionRecordList<PairType, WallType>::CollisionRecordList"
120  "("
121  "const labelField& pairAccessed,"
122  "const labelField& pairOrigProcOfOther,"
123  "const labelField& pairOrigIdOfOther,"
124  "const Field<PairType>& pairData,"
125  "const labelField& wallAccessed,"
126  "const vectorField& wallPRel,"
127  "const Field<WallType>& wallData"
128  ")"
129  )
130  << "Wall field size mismatch." << nl
131  << wallAccessed << nl
132  << wallPRel << nl
133  << wallData << nl
134  << abort(FatalError);
135  }
136 
137  forAll(wallAccessed, i)
138  {
139  wallRecords_.append
140  (
142  (
143  wallAccessed[i],
144  wallPRel[i],
145  wallData[i]
146  )
147  );
148  }
149 }
150 
151 
152 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * /
153 
154 template<class PairType, class WallType>
156 {}
157 
158 
159 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
160 
161 template<class PairType, class WallType>
164 {
165  labelField f(pairRecords_.size());
166 
167  forAll(pairRecords_, i)
168  {
169  f[i] = pairRecords_[i].accessed();
170  }
171 
172  return f;
173 }
174 
175 
176 template<class PairType, class WallType>
179 {
180  labelField f(pairRecords_.size());
181 
182  forAll(pairRecords_, i)
183  {
184  f[i] = pairRecords_[i].origProcOfOther();
185  }
186 
187  return f;
188 }
189 
190 
191 template<class PairType, class WallType>
194 {
195  labelField f(pairRecords_.size());
196 
197  forAll(pairRecords_, i)
198  {
199  f[i] = pairRecords_[i].origIdOfOther();
200  }
201 
202  return f;
203 }
204 
205 
206 template<class PairType, class WallType>
209 {
210  Field<PairType> f(pairRecords_.size());
211 
212  forAll(pairRecords_, i)
213  {
214  f[i] = pairRecords_[i].collisionData();
215  }
216 
217  return f;
218 }
219 
220 
221 template<class PairType, class WallType>
224 {
225  labelField f(wallRecords_.size());
226 
227  forAll(wallRecords_, i)
228  {
229  f[i] = wallRecords_[i].accessed();
230  }
231 
232  return f;
233 }
234 
235 
236 template<class PairType, class WallType>
239 {
240  vectorField f(wallRecords_.size());
241 
242  forAll(wallRecords_, i)
243  {
244  f[i] = wallRecords_[i].pRel();
245  }
246 
247  return f;
248 }
249 
250 
251 template<class PairType, class WallType>
254 {
255  Field<WallType> f(wallRecords_.size());
256 
257  forAll(wallRecords_, i)
258  {
259  f[i] = wallRecords_[i].collisionData();
260  }
261 
262  return f;
263 }
264 
265 
266 template<class PairType, class WallType>
269 (
270  label origProcOfOther,
271  label origIdOfOther
272 )
273 {
274  // Returning the first record that matches the particle
275  // identifiers. Two records with the same identification is not
276  // supported.
277 
278  forAll(pairRecords_, i)
279  {
280  PairCollisionRecord<PairType>& pCR = pairRecords_[i];
281 
282  if (pCR.match(origProcOfOther, origIdOfOther))
283  {
284  pCR.setAccessed();
285 
286  return pCR;
287  }
288  }
289 
290  // Record not found, create a new one and return it as the last
291  // member of the list. Setting the status of the record to be accessed
292  // on construction.
293 
294  pairRecords_.append
295  (
296  PairCollisionRecord<PairType>(true, origProcOfOther, origIdOfOther)
297  );
298 
299  return pairRecords_.last();
300 }
301 
302 
303 template<class PairType, class WallType>
305 (
306  label origProcOfOther,
307  label origIdOfOther
308 )
309 {
310  forAll(pairRecords_, i)
311  {
312  PairCollisionRecord<PairType>& pCR = pairRecords_[i];
313 
314  if (pCR.match(origProcOfOther, origIdOfOther))
315  {
316  return true;
317  }
318  }
319 
320  return false;
321 }
322 
323 
324 template<class PairType, class WallType>
327 (
328  const vector& pRel,
329  scalar radius
330 )
331 {
332  // Returning the first record that matches the relative position.
333  // Two records with the same relative position is not supported.
334 
335  forAll(wallRecords_, i)
336  {
337  WallCollisionRecord<WallType>& wCR = wallRecords_[i];
338 
339  if (wCR.match(pRel, radius))
340  {
341  wCR.setAccessed();
342 
343  return wCR;
344  }
345  }
346 
347  // Record not found, create a new one and return it as the last
348  // member of the list. Setting the status of the record to be accessed
349  // on construction.
350 
351  wallRecords_.append(WallCollisionRecord<WallType>(true, pRel));
352 
353  return wallRecords_.last();
354 }
355 
356 
357 template<class PairType, class WallType>
359 (
360  const vector& pRel,
361  scalar radius
362 )
363 {
364  forAll(wallRecords_, i)
365  {
366  WallCollisionRecord<WallType>& wCR = wallRecords_[i];
367 
368  if (wCR.match(pRel, radius))
369  {
370  return true;
371  }
372  }
373 
374  return false;
375 }
376 
377 
378 template<class PairType, class WallType>
380 {
381  {
383 
384  forAll(pairRecords_, i)
385  {
386  if (pairRecords_[i].accessed())
387  {
388  pairRecords_[i].setUnaccessed();
389 
390  updatedRecords.append(pairRecords_[i]);
391  }
392  }
393 
394  pairRecords_ = updatedRecords;
395  }
396 
397  {
399 
400  forAll(wallRecords_, i)
401  {
402  if (wallRecords_[i].accessed())
403  {
404  wallRecords_[i].setUnaccessed();
405 
406  updatedRecords.append(wallRecords_[i]);
407  }
408  }
409 
410  wallRecords_ = updatedRecords;
411  }
412 }
413 
414 
415 // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
416 
417 template<class PairType, class WallType>
418 void Foam::CollisionRecordList<PairType, WallType>::operator=
419 (
421 )
422 {
423  // Check for assignment to self
424  if (this == &rhs)
425  {
427  (
428  "Foam::CollisionRecordList<PairType, WallType>::operator="
429  "(const Foam::CollisionRecordList<PairType, WallType>&)"
430  )
431  << "Attempted assignment to self"
432  << abort(FatalError);
433  }
434 
435  pairRecords_ = rhs.pairRecords_;
436  wallRecords_ = rhs.wallRecords_;
437 }
438 
439 
440 // * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
441 
442 template<class PairType, class WallType>
443 inline bool Foam::operator==
444 (
447 )
448 {
449  return
450  (
451  a.pairRecords_ == b.pairRecords_
452  && a.wallRecords_ == b.wallRecords_
453  );
454 }
455 
456 
457 template<class PairType, class WallType>
458 inline bool Foam::operator!=
459 (
462 )
463 {
464  return !(a == b);
465 }
466 
467 
468 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
469 
470 template<class PairType, class WallType>
471 Foam::Istream& Foam::operator>>
472 (
473  Istream& is,
475 )
476 {
477  is >> cRL.pairRecords_ >> cRL.wallRecords_;
478 
479  // Check state of Istream
480  is.check
481  (
482  "Foam::Istream& Foam::operator>>"
483  "(Foam::Istream&, Foam::CollisionRecordList<PairType, WallType>&)"
484  );
485 
486  return is;
487 }
488 
489 
490 template<class PairType, class WallType>
491 Foam::Ostream& Foam::operator<<
492 (
493  Ostream& os,
495 )
496 {
497  os << cRL.pairRecords_ << cRL.wallRecords_;
498 
499  // Check state of Ostream
500  os.check
501  (
502  "Foam::Ostream& Foam::operator<<(Foam::Ostream&, "
503  "const Foam::CollisionRecordList<PairType, WallType>&)"
504  );
505 
506  return os;
507 }
508 
509 
510 // ************************************************************************* //
bool checkPairRecord(label origProcOfOther, label origIdOfOther)
Enquire if the specified record exists without modifying.
void setAccessed()
Set the accessed property of the record to accessed.
bool match(label queryOrigProcOfOther, label queryOrigIdOfOther) const
bool match(const vector &pRel, scalar radius)
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:28
labelList f(nPoints)
PairCollisionRecord< PairType > & matchPairRecord(label origProcOfOther, label origIdOfOther)
Enquires if the proc and id pair of the other particle are.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Field< WallType > wallData() const
Return field of wall data from each record, used for field IO.
Field< PairType > pairData() const
Return field of pair data from each record, used for field IO.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:310
labelField pairAccessed() const
Return field of pair accessed from each record, used for.
void update()
Update the collision records, deleting any records not.
labelField wallAccessed() const
Return field of wall accessed from each record, used for field IO.
Record of a collision between the particle holding the record and the particle with the stored id...
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
CollisionRecordList()
Construct null.
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
static const char nl
Definition: Ostream.H:260
vectorField wallPRel() const
Return field of wall pRel from each record, used for field IO.
bool checkWallRecord(const vector &pRel, scalar radius)
Enquire if the specified record exists without modifying.
labelField pairOrigIdOfOther() const
Return field of pair origIdOfOther from each record, used.
#define forAll(list, i)
Definition: UList.H:421
labelField pairOrigProcOfOther() const
Return field of pair origProcOfOther from each record,.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
WallCollisionRecord< WallType > & matchWallRecord(const vector &pRel, scalar radius)
Enquires if the position of wall impact relative to the.
Record of a collision between the particle holding the record and a wall face at the position relativ...
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
error FatalError
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
void setAccessed()
Set the accessed property of the record to accessed.