particleTracksSamplerTemplates.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) 2022 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "objectRegistry.H"
29 #include "ListOps.H"
30 
31 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
32 
33 template<class Type>
35 (
36  const UList<Type>& values,
37  List<DynamicList<Type>>& trackValues
38 ) const
39 {
40  List<Type> allValues(cloudGather_.gather(values));
41 
42  const label nTracks = trackValues.size();
43 
44  forAll(allValues, i)
45  {
46  const label globalId =
47  origParcelAddr_.toGlobal(origProcIds_[i], origParcelIds_[i]);
48 
49  if (globalId % stride_ == 0)
50  {
51  const label trackId = globalId/stride_;
52 
53  if
54  (
55  trackId < nTracks
56  && trackValues[trackId].size() < maxPositions_
57  )
58  {
59  trackValues[trackId].append(allValues[i]);
60  }
61  }
62  }
63 }
64 
65 
66 template<class Type>
68 (
69  const objectRegistry& obr,
70  HashTable<List<DynamicList<Type>>>& fieldTable
71 ) const
72 {
73  // First time - obtain field names and populate storage locations
74  if (fieldTable.empty())
75  {
76  wordList fieldNames = obr.names<IOField<Type>>();
77 
78  Pstream::combineReduce(fieldNames, ListOps::uniqueEqOp<word>());
79 
80  for (const word& fieldName : fieldNames)
81  {
82  fieldTable(fieldName).resize(nTracks());
83  }
84  }
85 
86  // Process in parallel-consistent order
87  for (const word& fieldName : fieldTable.sortedToc())
88  {
89  auto& output = fieldTable[fieldName];
90 
91  const auto* ptr = obr.cfindObject<IOField<Type>>(fieldName);
92 
93  this->createTrackField
94  (
95  ptr ? static_cast<const UList<Type>&>(*ptr) : UList<Type>::null(),
96  output
97  );
98  }
99 
100  return fieldTable.size();
101 }
102 
103 
104 // ************************************************************************* //
labelField origProcIds_
The originating processor ids.
labelField origParcelIds_
The originating parcel ids.
Various functions to operate on Lists.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
label setTrackFields(const objectRegistry &obr, HashTable< List< DynamicList< Type >>> &fieldTable) const
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:164
static void combineReduce(const List< commsStruct > &comms, T &value, const CombineOp &cop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce) applying cop to inplace combine value from different processors...
label nTracks() const noexcept
Number of tracks to generate.
static const UList< Type > & null()
Return a UList reference to a nullObject.
Definition: UListI.H:90
List< word > wordList
List of word.
Definition: fileName.H:59
label toGlobal(const label proci, const label i) const
From local to global on proci.
Definition: globalIndexI.H:308
void createTrackField(const UList< Type > &values, List< DynamicList< Type >> &trackValues) const
static Ostream & output(Ostream &os, const IntRange< T > &range)
Definition: IntRanges.C:44
static void gather(const labelUList &offsets, const label comm, const ProcIDsContainer &procIDs, const UList< Type > &fld, List< Type > &allFld, const int tag=UPstream::msgType(), const UPstream::commsTypes=UPstream::commsTypes::nonBlocking)
Collect data in processor order on master (== procIDs[0]).