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  (
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  (
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  }
130 
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  }
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].origIdOfOther();
159  }
160 
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  }
175 
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  }
190 
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  }
205 
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.
252 
253  pairRecords_.append
254  (
255  PairCollisionRecord<PairType>(true, origProcOfOther, origIdOfOther)
256  );
257 
258  return pairRecords_.last();
259 }
260 
261 
262 template<class PairType, class WallType>
264 (
265  label origProcOfOther,
266  label origIdOfOther
267 )
268 {
269  forAll(pairRecords_, i)
270  {
271  PairCollisionRecord<PairType>& pCR = pairRecords_[i];
272 
273  if (pCR.match(origProcOfOther, origIdOfOther))
274  {
275  return true;
276  }
277  }
278 
279  return false;
280 }
281 
282 
283 template<class PairType, class WallType>
286 (
287  const vector& pRel,
288  scalar radius
289 )
290 {
291  // Returning the first record that matches the relative position.
292  // Two records with the same relative position is not supported.
293 
294  forAll(wallRecords_, i)
295  {
296  WallCollisionRecord<WallType>& wCR = wallRecords_[i];
297 
298  if (wCR.match(pRel, radius))
299  {
300  wCR.setAccessed();
301 
302  return wCR;
303  }
304  }
305 
306  // Record not found, create a new one and return it as the last
307  // member of the list. Setting the status of the record to be accessed
308  // on construction.
309 
310  wallRecords_.append(WallCollisionRecord<WallType>(true, pRel));
311 
312  return wallRecords_.last();
313 }
314 
315 
316 template<class PairType, class WallType>
318 (
319  const vector& pRel,
320  scalar radius
321 )
322 {
323  forAll(wallRecords_, i)
324  {
325  WallCollisionRecord<WallType>& wCR = wallRecords_[i];
326 
327  if (wCR.match(pRel, radius))
328  {
329  return true;
330  }
331  }
332 
333  return false;
334 }
335 
336 
337 template<class PairType, class WallType>
339 {
340  {
342 
343  forAll(pairRecords_, i)
344  {
345  if (pairRecords_[i].accessed())
346  {
347  pairRecords_[i].setUnaccessed();
348 
349  updatedRecords.append(pairRecords_[i]);
350  }
351  }
352 
353  pairRecords_ = updatedRecords;
354  }
355 
356  {
358 
359  forAll(wallRecords_, i)
360  {
361  if (wallRecords_[i].accessed())
362  {
363  wallRecords_[i].setUnaccessed();
364 
365  updatedRecords.append(wallRecords_[i]);
366  }
367  }
368 
369  wallRecords_ = updatedRecords;
370  }
371 }
372 
373 
374 // * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
375 
376 template<class PairType, class WallType>
377 inline bool Foam::operator==
378 (
381 )
382 {
383  return
384  (
385  a.pairRecords_ == b.pairRecords_
386  && a.wallRecords_ == b.wallRecords_
387  );
388 }
389 
390 
391 template<class PairType, class WallType>
392 inline bool Foam::operator!=
393 (
396 )
397 {
398  return !(a == b);
399 }
400 
401 
402 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
403 
404 template<class PairType, class WallType>
405 Foam::Istream& Foam::operator>>
406 (
407  Istream& is,
408  CollisionRecordList<PairType, WallType>& cRL
409 )
410 {
411  is >> cRL.pairRecords_ >> cRL.wallRecords_;
412 
413  is.check(FUNCTION_NAME);
414  return is;
415 }
416 
417 
418 template<class PairType, class WallType>
419 Foam::Ostream& Foam::operator<<
420 (
421  Ostream& os,
422  const CollisionRecordList<PairType, WallType>& cRL
423 )
424 {
425  os << cRL.pairRecords_ << cRL.wallRecords_;
426 
427  os.check(FUNCTION_NAME);
428  return os;
429 }
430 
431 
432 // ************************************************************************* //
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:197
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:55
Foam::CollisionRecordList::CollisionRecordList
CollisionRecordList()=default
Default construct.
Foam::CollisionRecordList::wallAccessed
labelField wallAccessed() const
Return field of wall accessed from each record, used for field IO.
Definition: CollisionRecordList.C:182
Foam::CollisionRecordList::pairOrigIdOfOther
labelField pairOrigIdOfOther() const
Return field of pair origIdOfOther from each record, used.
Definition: CollisionRecordList.C:152
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::CollisionRecordList
Definition: CollisionRecordList.H:52
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:318
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:264
Foam::DynamicList::append
DynamicList< T, SizeMin > & append(const T &val)
Append an element to the end of this list.
Definition: DynamicListI.H:511
Foam::PairCollisionRecord::match
bool match(label queryOrigProcOfOther, label queryOrigIdOfOther) const
Definition: PairCollisionRecordI.H:32
Foam::CollisionRecordList::pairData
Field< PairType > pairData() const
Return field of pair data from each record, used for field IO.
Definition: CollisionRecordList.C:167
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:58
Foam::FatalError
error FatalError
Foam::CollisionRecordList::pairOrigProcOfOther
labelField pairOrigProcOfOther() const
Return field of pair origProcOfOther from each record,.
Definition: CollisionRecordList.C:137
os
OBJstream os(runTime.globalPath()/outputName)
Foam::WallCollisionRecord::match
bool match(const vector &pRel, scalar radius)
Definition: WallCollisionRecordI.H:32
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::CollisionRecordList::wallData
Field< WallType > wallData() const
Return field of wall data from each record, used for field IO.
Definition: CollisionRecordList.C:212
CollisionRecordList.H
Foam::CollisionRecordList::update
void update()
Update the collision records, deleting any records not.
Definition: CollisionRecordList.C:338
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::nl
constexpr char nl
Definition: Ostream.H:404
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:228
Foam::Vector< scalar >
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:295
Foam::CollisionRecordList::pairAccessed
labelField pairAccessed() const
Return field of pair accessed from each record, used for.
Definition: CollisionRecordList.C:122
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:286