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