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\*---------------------------------------------------------------------------*/
28
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 {
69 << "Pair field size mismatch." << nl
70 << pairAccessed << 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 {
96 << "Wall field size mismatch." << nl
97 << wallAccessed << nl
98 << wallPRel << nl
99 << wallData << nl
100 << abort(FatalError);
101 }
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
120template<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
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
150template<class PairType, class WallType>
153{
154 labelField f(pairRecords_.size());
156 forAll(pairRecords_, i)
157 {
158 f[i] = pairRecords_[i].origIdOfOther();
159 }
160
161 return f;
162}
163
164
165template<class PairType, class WallType>
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
180template<class PairType, class WallType>
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
195template<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
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 }
220
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 pairRecords_.append
254 (
255 PairCollisionRecord<PairType>(true, origProcOfOther, origIdOfOther)
256 );
257
258 return pairRecords_.last();
259}
260
261
262template<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
283template<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
316template<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
337template<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
376template<class PairType, class WallType>
377inline bool Foam::operator==
378(
381)
382{
383 return
384 (
385 a.pairRecords_ == b.pairRecords_
386 && a.wallRecords_ == b.wallRecords_
387 );
388}
389
390
391template<class PairType, class WallType>
392inline bool Foam::operator!=
393(
396)
397{
398 return !(a == b);
399}
400
401
402// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
403
404template<class PairType, class WallType>
405Foam::Istream& Foam::operator>>
406(
407 Istream& is,
408 CollisionRecordList<PairType, WallType>& cRL
409)
410{
411 is >> cRL.pairRecords_ >> cRL.wallRecords_;
412
414 return is;
415}
416
417
418template<class PairType, class WallType>
419Foam::Ostream& Foam::operator<<
420(
421 Ostream& os,
422 const CollisionRecordList<PairType, WallType>& cRL
423)
424{
425 os << cRL.pairRecords_ << cRL.wallRecords_;
426
428 return os;
429}
430
431
432// ************************************************************************* //
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:72
void append(const T &val)
Copy append an element to the end of this list.
Definition: DynamicListI.H:503
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
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:114
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.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
labelList f(nPoints)
volScalarField & b
Definition: createFields.H:27
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333