CollisionRecordList.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 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 // * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
392 
393 template<class PairType, class WallType>
394 inline bool Foam::operator==
395 (
398 )
399 {
400  return
401  (
402  a.pairRecords_ == b.pairRecords_
403  && a.wallRecords_ == b.wallRecords_
404  );
405 }
406 
407 
408 template<class PairType, class WallType>
409 inline bool Foam::operator!=
410 (
413 )
414 {
415  return !(a == b);
416 }
417 
418 
419 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
420 
421 template<class PairType, class WallType>
422 Foam::Istream& Foam::operator>>
423 (
424  Istream& is,
426 )
427 {
428  is >> cRL.pairRecords_ >> cRL.wallRecords_;
429 
430  // Check state of Istream
431  is.check
432  (
433  "Foam::Istream& Foam::operator>>"
434  "(Foam::Istream&, Foam::CollisionRecordList<PairType, WallType>&)"
435  );
436 
437  return is;
438 }
439 
440 
441 template<class PairType, class WallType>
442 Foam::Ostream& Foam::operator<<
443 (
444  Ostream& os,
446 )
447 {
448  os << cRL.pairRecords_ << cRL.wallRecords_;
449 
450  // Check state of Ostream
451  os.check
452  (
453  "Foam::Ostream& Foam::operator<<(Foam::Ostream&, "
454  "const Foam::CollisionRecordList<PairType, WallType>&)"
455  );
456 
457  return os;
458 }
459 
460 
461 // ************************************************************************* //
Field< WallType > wallData() const
Return field of wall data from each record, used for field IO.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
labelField wallAccessed() const
Return field of wall accessed from each record, used for field IO.
bool match(label queryOrigProcOfOther, label queryOrigIdOfOther) const
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
const dimensionedScalar b
Wien displacement law constant: default SI units: [m K].
Definition: createFields.H:27
Field< PairType > pairData() const
Return field of pair data from each record, used for field IO.
labelField pairAccessed() const
Return field of pair accessed from each record, used for.
void update()
Update the collision records, deleting any records not.
CollisionRecordList()
Construct null.
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
bool checkWallRecord(const vector &pRel, scalar radius)
Enquire if the specified record exists without modifying.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
labelField pairOrigProcOfOther() const
Return field of pair origProcOfOther from each record,.
labelField pairOrigIdOfOther() const
Return field of pair origIdOfOther from each record, used.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:296
errorManip< error > abort(error &err)
Definition: errorManip.H:131
void setAccessed()
Set the accessed property of the record to accessed.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
PairCollisionRecord< PairType > & matchPairRecord(label origProcOfOther, label origIdOfOther)
Enquires if the proc and id pair of the other particle are.
static const char nl
Definition: Ostream.H:260
labelList f(nPoints)
Record of a collision between the particle holding the record and a wall face at the position relativ...
bool match(const vector &pRel, scalar radius)
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 the particle with the stored id...
vectorField wallPRel() const
Return field of wall pRel from each record, used for field IO.
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.