Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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\*---------------------------------------------------------------------------*/
29#include "CollisionRecordList.H"
30#include "IOstreams.H"
31
32// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33
34template<class PairType, class WallType>
36:
37 pairRecords_(is),
38 wallRecords_(is)
39{
41}
42
43
44template<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 {
68 FatalErrorInFunction
69 << "Pair field size mismatch." << nl
70 << pairAccessed << nl
71 << pairOrigProcOfOther << nl
72 << pairOrigIdOfOther << nl
73 << pairData << nl
74 << abort(FatalError);
75 }
76
78 {
79 pairRecords_.append
80 (
82 (
83 pairAccessed[i],
86 pairData[i]
87 )
88 );
89 }
90
91 label nWall = wallAccessed.size();
92
93 if (wallPRel.size() != nWall || wallData.size() != nWall)
94 {
95 FatalErrorInFunction
96 << "Wall field size mismatch." << nl
97 << wallAccessed << nl
98 << wallPRel << nl
99 << wallData << nl
100 << abort(FatalError);
101 }
102
104 {
105 wallRecords_.append
106 (
107 WallCollisionRecord<WallType>
108 (
109 wallAccessed[i],
110 wallPRel[i],
111 wallData[i]
112 )
113 );
114 }
116
117
118// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
119
120template<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
135template<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
150template<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
165template<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
180template<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
195template<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
210template<class PairType, class WallType>
213{
214 Field<WallType> f(wallRecords_.size());
215
216 forAll(wallRecords_, i)
217 {
218 f[i] = wallRecords_[i].collisionData();
219 }
221 return f;
222}
223
224
225template<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 return pairRecords_.emplace_back(true, origProcOfOther, origIdOfOther);
254}
255
256
257template<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 }
274 return false;
275}
276
277
278template<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.
304
305 return wallRecords_.emplace_back(true, pRel);
306}
307
308
309template<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 }
325
326 return false;
327}
328
329
330template<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 {
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;
364}
365
366
367// * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
368
369template<class PairType, class WallType>
370inline bool Foam::operator==
371(
374)
375{
376 return
377 (
378 a.pairRecords_ == b.pairRecords_
379 && a.wallRecords_ == b.wallRecords_
380 );
381}
382
383
384template<class PairType, class WallType>
385inline 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
397template<class PairType, class WallType>
398Foam::Istream& Foam::operator>>
399(
400 Istream& is,
402)
403{
404 is >> cRL.pairRecords_ >> cRL.wallRecords_;
405
406 is.check(FUNCTION_NAME);
407 return is;
408}
409
410
411template<class PairType, class WallType>
412Foam::Ostream& Foam::operator<<
413(
414 Ostream& os,
416)
417{
418 os << cRL.pairRecords_ << cRL.wallRecords_;
419
421 return os;
422}
423
424
425// ************************************************************************* //
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
PairCollisionRecord< PairType > & matchPairRecord(label origProcOfOther, label origIdOfOther)
Enquires if the proc and id pair of the other particle are.
labelField pairAccessed() const
Return field of pair accessed from each record, used for.
labelField pairOrigIdOfOther() const
Return field of pair origIdOfOther from each record, used.
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.
Field< WallType > wallData() const
Return field of wall data from each record, used for field IO.
Field< PairType > pairData() const
Return field of pair data from each record, used for field IO.
WallCollisionRecord< WallType > & matchWallRecord(const vector &pRel, scalar radius)
Enquires if the position of wall impact relative to the.
labelField wallAccessed() const
Return field of wall accessed from each record, used for field IO.
bool checkWallRecord(const vector &pRel, scalar radius)
Enquire if the specified record exists without modifying.
void update()
Update the collision records, deleting any records not.
labelField pairOrigProcOfOther() const
Return field of pair origProcOfOther from each record,.
CollisionRecordList()=default
Default construct.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
void append(const T &val)
Copy append an element to the end of this list.
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
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:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Record of a collision between the particle holding the record and the particle with the stored id.
bool match(label queryOrigProcOfOther, label queryOrigIdOfOther) const
void setAccessed()
Set the accessed property of the record to accessed.
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
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)
void setAccessed()
Set the accessed property of the record to accessed.
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
Field< vector > vectorField
Specialisation of Field<T> for vector.
Field< label > labelField
Specialisation of Field<T> for label.
Definition labelField.H:48
Vector< scalar > vector
Definition vector.H:57
labelList f(nPoints)
volScalarField & b
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299