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_(is),
38  wallRecords_(is)
39 {
40  is.check(FUNCTION_NAME);
41 }
42 
43 
44 template<class PairType, class WallType>
46 (
47  const labelField& pairAccessed,
48  const labelField& pairOrigProcOfOther,
49  const labelField& pairOrigIdOfOther,
50  const Field<PairType>& pairData,
51  const labelField& wallAccessed,
52  const vectorField& wallPRel,
53  const Field<WallType>& wallData
54 )
55 :
56  pairRecords_(),
57  wallRecords_()
58 {
59  label nPair = pairAccessed.size();
60 
61  if
62  (
63  pairOrigProcOfOther.size() != nPair
64  || pairOrigIdOfOther.size() != nPair
65  || pairData.size() != nPair
66  )
67  {
69  << "Pair field size mismatch." << nl
70  << pairAccessed << nl
71  << pairOrigProcOfOther << nl
72  << pairOrigIdOfOther << nl
73  << pairData << nl
74  << abort(FatalError);
75  }
76 
77  forAll(pairAccessed, i)
78  {
79  pairRecords_.append
80  (
81  PairCollisionRecord<PairType>
82  (
83  pairAccessed[i],
84  pairOrigProcOfOther[i],
85  pairOrigIdOfOther[i],
86  pairData[i]
87  )
88  );
89  }
90 
91  label nWall = wallAccessed.size();
92 
93  if (wallPRel.size() != nWall || wallData.size() != nWall)
94  {
96  << "Wall field size mismatch." << nl
97  << wallAccessed << nl
98  << wallPRel << nl
99  << wallData << nl
100  << abort(FatalError);
101  }
102 
103  forAll(wallAccessed, i)
104  {
105  wallRecords_.append
106  (
107  WallCollisionRecord<WallType>
108  (
109  wallAccessed[i],
110  wallPRel[i],
111  wallData[i]
112  )
113  );
114  }
115 }
116 
117 
118 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
119 
120 template<class PairType, class WallType>
123 {
124  labelField f(pairRecords_.size());
125 
126  forAll(pairRecords_, i)
127  {
128  f[i] = pairRecords_[i].accessed();
129  }
131  return f;
132 }
133 
134 
135 template<class PairType, class WallType>
138 {
139  labelField f(pairRecords_.size());
140 
141  forAll(pairRecords_, i)
142  {
143  f[i] = pairRecords_[i].origProcOfOther();
144  }
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].origIdOfOther();
159  }
161  return f;
162 }
163 
164 
165 template<class PairType, class WallType>
168 {
169  Field<PairType> f(pairRecords_.size());
170 
171  forAll(pairRecords_, i)
172  {
173  f[i] = pairRecords_[i].collisionData();
174  }
176  return f;
177 }
178 
179 
180 template<class PairType, class WallType>
183 {
184  labelField f(wallRecords_.size());
185 
186  forAll(wallRecords_, i)
187  {
188  f[i] = wallRecords_[i].accessed();
189  }
191  return f;
192 }
193 
194 
195 template<class PairType, class WallType>
198 {
199  vectorField f(wallRecords_.size());
200 
201  forAll(wallRecords_, i)
202  {
203  f[i] = wallRecords_[i].pRel();
204  }
206  return f;
207 }
208 
209 
210 template<class PairType, class WallType>
213 {
214  Field<WallType> f(wallRecords_.size());
215 
216  forAll(wallRecords_, i)
217  {
218  f[i] = wallRecords_[i].collisionData();
219  }
220 
221  return f;
222 }
223 
224 
225 template<class PairType, class WallType>
228 (
229  label origProcOfOther,
230  label origIdOfOther
231 )
232 {
233  // Returning the first record that matches the particle
234  // identifiers. Two records with the same identification is not
235  // supported.
236 
237  forAll(pairRecords_, i)
238  {
239  PairCollisionRecord<PairType>& pCR = pairRecords_[i];
240 
241  if (pCR.match(origProcOfOther, origIdOfOther))
242  {
243  pCR.setAccessed();
244 
245  return pCR;
246  }
247  }
248 
249  // Record not found, create a new one and return it as the last
250  // member of the list. Setting the status of the record to be accessed
251  // on construction.
253  return pairRecords_.emplace_back(true, origProcOfOther, origIdOfOther);
254 }
255 
256 
257 template<class PairType, class WallType>
259 (
260  label origProcOfOther,
261  label origIdOfOther
262 )
263 {
264  forAll(pairRecords_, i)
265  {
266  PairCollisionRecord<PairType>& pCR = pairRecords_[i];
267 
268  if (pCR.match(origProcOfOther, origIdOfOther))
269  {
270  return true;
271  }
272  }
273 
274  return false;
275 }
276 
277 
278 template<class PairType, class WallType>
281 (
282  const vector& pRel,
283  scalar radius
284 )
285 {
286  // Returning the first record that matches the relative position.
287  // Two records with the same relative position is not supported.
288 
289  forAll(wallRecords_, i)
290  {
291  WallCollisionRecord<WallType>& wCR = wallRecords_[i];
292 
293  if (wCR.match(pRel, radius))
294  {
295  wCR.setAccessed();
296 
297  return wCR;
298  }
299  }
300 
301  // Record not found, create a new one and return it as the last
302  // member of the list. Setting the status of the record to be accessed
303  // on construction.
305  return wallRecords_.emplace_back(true, pRel);
306 }
307 
308 
309 template<class PairType, class WallType>
311 (
312  const vector& pRel,
313  scalar radius
314 )
315 {
316  forAll(wallRecords_, i)
317  {
318  WallCollisionRecord<WallType>& wCR = wallRecords_[i];
319 
320  if (wCR.match(pRel, radius))
321  {
322  return true;
323  }
324  }
325 
326  return false;
327 }
328 
329 
330 template<class PairType, class WallType>
332 {
333  {
334  DynamicList<PairCollisionRecord<PairType>> updatedRecords;
335 
336  forAll(pairRecords_, i)
337  {
338  if (pairRecords_[i].accessed())
339  {
340  pairRecords_[i].setUnaccessed();
341 
342  updatedRecords.append(pairRecords_[i]);
343  }
344  }
345 
346  pairRecords_ = updatedRecords;
347  }
348 
349  {
350  DynamicList<WallCollisionRecord<WallType>> updatedRecords;
351 
352  forAll(wallRecords_, i)
353  {
354  if (wallRecords_[i].accessed())
355  {
356  wallRecords_[i].setUnaccessed();
357 
358  updatedRecords.append(wallRecords_[i]);
359  }
360  }
361 
362  wallRecords_ = updatedRecords;
363  }
364 }
365 
366 
367 // * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
368 
369 template<class PairType, class WallType>
370 inline bool Foam::operator==
371 (
372  const CollisionRecordList<PairType, WallType>& a,
373  const CollisionRecordList<PairType, WallType>& b
374 )
375 {
376  return
377  (
378  a.pairRecords_ == b.pairRecords_
379  && a.wallRecords_ == b.wallRecords_
380  );
381 }
382 
383 
384 template<class PairType, class WallType>
385 inline bool Foam::operator!=
386 (
387  const CollisionRecordList<PairType, WallType>& a,
388  const CollisionRecordList<PairType, WallType>& b
389 )
390 {
391  return !(a == b);
392 }
393 
394 
395 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
396 
397 template<class PairType, class WallType>
398 Foam::Istream& Foam::operator>>
399 (
400  Istream& is,
401  CollisionRecordList<PairType, WallType>& cRL
402 )
403 {
404  is >> cRL.pairRecords_ >> cRL.wallRecords_;
405 
406  is.check(FUNCTION_NAME);
407  return is;
408 }
409 
410 
411 template<class PairType, class WallType>
412 Foam::Ostream& Foam::operator<<
413 (
414  Ostream& os,
415  const CollisionRecordList<PairType, WallType>& cRL
416 )
417 {
418  os << cRL.pairRecords_ << cRL.wallRecords_;
419 
420  os.check(FUNCTION_NAME);
421  return os;
422 }
423 
424 
425 // ************************************************************************* //
Field< WallType > wallData() const
Return field of wall data from each record, used for field IO.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
labelField wallAccessed() const
Return field of wall accessed from each record, used for field IO.
bool match(label queryOrigProcOfOther, label queryOrigIdOfOther) const
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:45
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
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.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
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.
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
labelField pairOrigProcOfOther() const
Return field of pair origProcOfOther from each record,.
labelField pairOrigIdOfOther() const
Return field of pair origIdOfOther from each record, used.
errorManip< error > abort(error &err)
Definition: errorManip.H:139
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:56
PairCollisionRecord< PairType > & matchPairRecord(label origProcOfOther, label origIdOfOther)
Enquires if the proc and id pair of the other particle are.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
CollisionRecordList()=default
Default construct.
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
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.