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-2015 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  << "Pair field size mismatch." << nl
80  << pairAccessed << nl
81  << pairOrigProcOfOther << nl
82  << pairOrigIdOfOther << nl
83  << pairData << nl
84  << abort(FatalError);
85  }
86 
87  forAll(pairAccessed, i)
88  {
89  pairRecords_.append
90  (
92  (
93  pairAccessed[i],
94  pairOrigProcOfOther[i],
95  pairOrigIdOfOther[i],
96  pairData[i]
97  )
98  );
99  }
100 
101  label nWall = wallAccessed.size();
102 
103  if (wallPRel.size() != nWall || wallData.size() != nWall)
104  {
106  << "Wall field size mismatch." << nl
107  << wallAccessed << nl
108  << wallPRel << nl
109  << wallData << nl
110  << abort(FatalError);
111  }
112 
113  forAll(wallAccessed, i)
114  {
115  wallRecords_.append
116  (
118  (
119  wallAccessed[i],
120  wallPRel[i],
121  wallData[i]
122  )
123  );
124  }
125 }
126 
127 
128 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * /
129 
130 template<class PairType, class WallType>
132 {}
133 
134 
135 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
136 
137 template<class PairType, class WallType>
140 {
141  labelField f(pairRecords_.size());
142 
143  forAll(pairRecords_, i)
144  {
145  f[i] = pairRecords_[i].accessed();
146  }
147 
148  return f;
149 }
150 
151 
152 template<class PairType, class WallType>
155 {
156  labelField f(pairRecords_.size());
157 
158  forAll(pairRecords_, i)
159  {
160  f[i] = pairRecords_[i].origProcOfOther();
161  }
162 
163  return f;
164 }
165 
166 
167 template<class PairType, class WallType>
170 {
171  labelField f(pairRecords_.size());
172 
173  forAll(pairRecords_, i)
174  {
175  f[i] = pairRecords_[i].origIdOfOther();
176  }
177 
178  return f;
179 }
180 
181 
182 template<class PairType, class WallType>
185 {
186  Field<PairType> f(pairRecords_.size());
187 
188  forAll(pairRecords_, i)
189  {
190  f[i] = pairRecords_[i].collisionData();
191  }
192 
193  return f;
194 }
195 
196 
197 template<class PairType, class WallType>
200 {
201  labelField f(wallRecords_.size());
202 
203  forAll(wallRecords_, i)
204  {
205  f[i] = wallRecords_[i].accessed();
206  }
207 
208  return f;
209 }
210 
211 
212 template<class PairType, class WallType>
215 {
216  vectorField f(wallRecords_.size());
217 
218  forAll(wallRecords_, i)
219  {
220  f[i] = wallRecords_[i].pRel();
221  }
222 
223  return f;
224 }
225 
226 
227 template<class PairType, class WallType>
230 {
231  Field<WallType> f(wallRecords_.size());
232 
233  forAll(wallRecords_, i)
234  {
235  f[i] = wallRecords_[i].collisionData();
236  }
237 
238  return f;
239 }
240 
241 
242 template<class PairType, class WallType>
245 (
246  label origProcOfOther,
247  label origIdOfOther
248 )
249 {
250  // Returning the first record that matches the particle
251  // identifiers. Two records with the same identification is not
252  // supported.
253 
254  forAll(pairRecords_, i)
255  {
256  PairCollisionRecord<PairType>& pCR = pairRecords_[i];
257 
258  if (pCR.match(origProcOfOther, origIdOfOther))
259  {
260  pCR.setAccessed();
261 
262  return pCR;
263  }
264  }
265 
266  // Record not found, create a new one and return it as the last
267  // member of the list. Setting the status of the record to be accessed
268  // on construction.
269 
270  pairRecords_.append
271  (
272  PairCollisionRecord<PairType>(true, origProcOfOther, origIdOfOther)
273  );
274 
275  return pairRecords_.last();
276 }
277 
278 
279 template<class PairType, class WallType>
281 (
282  label origProcOfOther,
283  label origIdOfOther
284 )
285 {
286  forAll(pairRecords_, i)
287  {
288  PairCollisionRecord<PairType>& pCR = pairRecords_[i];
289 
290  if (pCR.match(origProcOfOther, origIdOfOther))
291  {
292  return true;
293  }
294  }
295 
296  return false;
297 }
298 
299 
300 template<class PairType, class WallType>
303 (
304  const vector& pRel,
305  scalar radius
306 )
307 {
308  // Returning the first record that matches the relative position.
309  // Two records with the same relative position is not supported.
310 
311  forAll(wallRecords_, i)
312  {
313  WallCollisionRecord<WallType>& wCR = wallRecords_[i];
314 
315  if (wCR.match(pRel, radius))
316  {
317  wCR.setAccessed();
318 
319  return wCR;
320  }
321  }
322 
323  // Record not found, create a new one and return it as the last
324  // member of the list. Setting the status of the record to be accessed
325  // on construction.
326 
327  wallRecords_.append(WallCollisionRecord<WallType>(true, pRel));
328 
329  return wallRecords_.last();
330 }
331 
332 
333 template<class PairType, class WallType>
335 (
336  const vector& pRel,
337  scalar radius
338 )
339 {
340  forAll(wallRecords_, i)
341  {
342  WallCollisionRecord<WallType>& wCR = wallRecords_[i];
343 
344  if (wCR.match(pRel, radius))
345  {
346  return true;
347  }
348  }
349 
350  return false;
351 }
352 
353 
354 template<class PairType, class WallType>
356 {
357  {
359 
360  forAll(pairRecords_, i)
361  {
362  if (pairRecords_[i].accessed())
363  {
364  pairRecords_[i].setUnaccessed();
365 
366  updatedRecords.append(pairRecords_[i]);
367  }
368  }
369 
370  pairRecords_ = updatedRecords;
371  }
372 
373  {
375 
376  forAll(wallRecords_, i)
377  {
378  if (wallRecords_[i].accessed())
379  {
380  wallRecords_[i].setUnaccessed();
381 
382  updatedRecords.append(wallRecords_[i]);
383  }
384  }
385 
386  wallRecords_ = updatedRecords;
387  }
388 }
389 
390 
391 // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
392 
393 template<class PairType, class WallType>
395 (
397 )
398 {
399  // Check for assignment to self
400  if (this == &rhs)
401  {
403  << "Attempted assignment to self"
404  << abort(FatalError);
405  }
406 
407  pairRecords_ = rhs.pairRecords_;
408  wallRecords_ = rhs.wallRecords_;
409 }
410 
411 
412 // * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
413 
414 template<class PairType, class WallType>
415 inline bool Foam::operator==
416 (
419 )
420 {
421  return
422  (
423  a.pairRecords_ == b.pairRecords_
424  && a.wallRecords_ == b.wallRecords_
425  );
426 }
427 
428 
429 template<class PairType, class WallType>
430 inline bool Foam::operator!=
431 (
434 )
435 {
436  return !(a == b);
437 }
438 
439 
440 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
441 
442 template<class PairType, class WallType>
443 Foam::Istream& Foam::operator>>
444 (
445  Istream& is,
446  CollisionRecordList<PairType, WallType>& cRL
447 )
448 {
449  is >> cRL.pairRecords_ >> cRL.wallRecords_;
450 
451  // Check state of Istream
452  is.check
453  (
454  "Foam::Istream& Foam::operator>>"
455  "(Foam::Istream&, Foam::CollisionRecordList<PairType, WallType>&)"
456  );
457 
458  return is;
459 }
460 
461 
462 template<class PairType, class WallType>
463 Foam::Ostream& Foam::operator<<
464 (
465  Ostream& os,
466  const CollisionRecordList<PairType, WallType>& cRL
467 )
468 {
469  os << cRL.pairRecords_ << cRL.wallRecords_;
470 
471  // Check state of Ostream
472  os.check
473  (
474  "Foam::Ostream& Foam::operator<<(Foam::Ostream&, "
475  "const Foam::CollisionRecordList<PairType, WallType>&)"
476  );
477 
478  return os;
479 }
480 
481 
482 // ************************************************************************* //
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::CollisionRecordList::wallPRel
vectorField wallPRel() const
Return field of wall pRel from each record, used for field IO.
Definition: CollisionRecordList.C:214
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:56
Foam::CollisionRecordList::wallAccessed
labelField wallAccessed() const
Return field of wall accessed from each record, used for field IO.
Definition: CollisionRecordList.C:199
Foam::CollisionRecordList::wallRecords_
DynamicList< WallCollisionRecord< WallType > > wallRecords_
List of active wall collisions.
Definition: CollisionRecordList.H:85
Foam::CollisionRecordList::pairOrigIdOfOther
labelField pairOrigIdOfOther() const
Return field of pair origIdOfOther from each record, used.
Definition: CollisionRecordList.C:169
Foam::CollisionRecordList::pairRecords_
DynamicList< PairCollisionRecord< PairType > > pairRecords_
List of active pair collisions.
Definition: CollisionRecordList.H:82
Foam::CollisionRecordList
Definition: CollisionRecordList.H:49
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:59
Foam::constant::physicoChemical::b
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:28
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::CollisionRecordList::checkWallRecord
bool checkWallRecord(const vector &pRel, scalar radius)
Enquire if the specified record exists without modifying.
Definition: CollisionRecordList.C:335
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::CollisionRecordList::checkPairRecord
bool checkPairRecord(label origProcOfOther, label origIdOfOther)
Enquire if the specified record exists without modifying.
Definition: CollisionRecordList.C:281
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::PairCollisionRecord::match
bool match(label queryOrigProcOfOther, label queryOrigIdOfOther) const
Definition: PairCollisionRecordI.H:30
Foam::CollisionRecordList::~CollisionRecordList
~CollisionRecordList()
Destructor.
Definition: CollisionRecordList.C:131
Foam::CollisionRecordList::pairData
Field< PairType > pairData() const
Return field of pair data from each record, used for field IO.
Definition: CollisionRecordList.C:184
Foam::WallCollisionRecord
Record of a collision between the particle holding the record and a wall face at the position relativ...
Definition: WallCollisionRecord.H:49
Foam::PairCollisionRecord
Record of a collision between the particle holding the record and the particle with the stored id.
Definition: PairCollisionRecord.H:56
Foam::WallCollisionRecord::setAccessed
void setAccessed()
Set the accessed property of the record to accessed.
Definition: WallCollisionRecordI.H:102
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
Foam::FatalError
error FatalError
Foam::CollisionRecordList::pairOrigProcOfOther
labelField pairOrigProcOfOther() const
Return field of pair origProcOfOther from each record,.
Definition: CollisionRecordList.C:154
Foam::WallCollisionRecord::match
bool match(const vector &pRel, scalar radius)
Definition: WallCollisionRecordI.H:30
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::CollisionRecordList::wallData
Field< WallType > wallData() const
Return field of wall data from each record, used for field IO.
Definition: CollisionRecordList.C:229
Foam::DynamicList::append
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
CollisionRecordList.H
Foam::CollisionRecordList::update
void update()
Update the collision records, deleting any records not.
Definition: CollisionRecordList.C:355
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
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:245
Foam::Vector< scalar >
Foam::CollisionRecordList::CollisionRecordList
CollisionRecordList()
Construct null.
Definition: CollisionRecordList.C:32
Foam::CollisionRecordList::pairAccessed
labelField pairAccessed() const
Return field of pair accessed from each record, used for.
Definition: CollisionRecordList.C:139
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::PairCollisionRecord::setAccessed
void setAccessed()
Set the accessed property of the record to accessed.
Definition: PairCollisionRecordI.H:80
Foam::CollisionRecordList::matchWallRecord
WallCollisionRecord< WallType > & matchWallRecord(const vector &pRel, scalar radius)
Enquires if the position of wall impact relative to the.
Definition: CollisionRecordList.C:303