particleTracksSampler.H
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 Class
27  Foam::particleTracksSampler
28 
29 Description
30  Helper class when generating particle tracks.
31  The interface is fairly rudimentary.
32 
33 SourceFiles
34  particleTracksSamplerTemplates.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef Foam_particleTracksSampler_H
39 #define Foam_particleTracksSampler_H
40 
41 #include "globalIndex.H"
42 #include "fieldTypes.H"
43 #include "IOField.H"
44 #include "labelField.H"
45 #include "DynamicList.H"
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 // Forward Declarations
53 class objectRegistry;
54 
55 /*---------------------------------------------------------------------------*\
56  Class particleTracksSampler Declaration
57 \*---------------------------------------------------------------------------*/
58 
60 {
61  // Private Data
62 
63  //- The sampling interval
64  label stride_ = 1;
65 
66  //- The number of tracks
67  label nTracks_ = 1;
68 
69  //- Upper limit for number of track positions
70  label maxPositions_ = 10000;
71 
72  //- The bin for sampled parcels.
73  labelField trackIds_;
74 
75  //- The addressing for gathering cloud fields etc
76  globalIndex cloudGather_;
77 
78  //- The originating parcel addressing
79  globalIndex origParcelAddr_;
80 
81 
82 public:
83 
84  // Data Members
85 
86  //- The originating parcel ids
88 
89  //- The originating processor ids
91 
92 
93  // Member Functions
94 
95  //- The original parcel addressing
97  {
98  return origParcelAddr_;
99  }
100 
101  //- Total number of particles
102  label nParticle() const
103  {
104  return origParcelAddr_.totalSize();
105  }
106 
107  //- Number of tracks to generate
108  label nTracks() const noexcept
109  {
110  return nTracks_;
111  }
112 
113  //- Define the orig parcel mappings
114  void reset(const labelUList& origParcelCounts)
115  {
116  origParcelAddr_.reset(origParcelCounts);
119  trackIds_.clear();
120  }
121 
122  //- Set the sampling stride, upper limits
123  // \return Number of tracks to generate
124  label setSampleRate
125  (
126  const label sampleFreq,
127  const label maxPositions,
128  const label maxTracks = -1
129  )
130  {
131  // numTracks = numParticles/stride
132 
133  stride_ = max(1, sampleFreq);
134  maxPositions_ = maxPositions;
135  nTracks_ = (origParcelAddr_.totalSize()/stride_);
136 
137  if (maxTracks > 0)
138  {
139  nTracks_ = min(nTracks_, maxTracks);
140  }
141 
142  return nTracks_;
143  }
144 
145  void resetCloud(const label localCloudSize)
146  {
147  cloudGather_.reset(globalIndex::gatherOnly{}, localCloudSize);
148  origParcelIds_.resize_nocopy(localCloudSize);
149  origProcIds_.resize_nocopy(localCloudSize);
150  }
151 
152  template<class Type>
153  void gatherInplace(List<Type>& fld) const
154  {
155  cloudGather_.gatherInplace(fld);
156  }
157 
158  template<class Type>
159  void createTrackField
160  (
161  const UList<Type>& values,
162  List<DynamicList<Type>>& trackValues
163  ) const;
164 
165 
166  template<class Type>
168  (
169  const objectRegistry& obr,
170  HashTable<List<DynamicList<Type>>>& fieldTable
171  ) const;
172 };
173 
174 
175 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
176 
177 } // End namespace Foam
178 
179 
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181 
182 #ifdef NoRepository
184 #endif
185 
186 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
187 
188 #endif
189 
190 // ************************************************************************* //
labelField origProcIds_
The originating processor ids.
void reset(const label localSize, const label comm=UPstream::worldComm, const bool parallel=UPstream::parRun())
Reset from local size, using gather/broadcast with default/specified communicator if parallel...
Definition: globalIndex.C:346
labelField origParcelIds_
The originating parcel ids.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
Dispatch tag: Construct &#39;one-sided&#39; from local sizes, using gather but no broadcast.
Definition: globalIndex.H:110
void gatherInplace(List< Type > &fld) const
void resize_nocopy(const label len)
Adjust allocated size of list without necessarily.
Definition: ListI.H:175
void reset(const labelUList &origParcelCounts)
Define the orig parcel mappings.
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
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:61
label totalSize() const noexcept
The total addressed size, which corresponds to the end offset and also the sum of all localSizes...
Definition: globalIndexI.H:165
label setSampleRate(const label sampleFreq, const label maxPositions, const label maxTracks=-1)
Set the sampling stride, upper limits.
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:137
Helper class when generating particle tracks. The interface is fairly rudimentary.
label nParticle() const
Total number of particles.
label maxPositions(propsDict.get< label >("maxPositions"))
A HashTable similar to std::unordered_map.
Definition: HashTable.H:108
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:26
label nTracks() const noexcept
Number of tracks to generate.
const direction noexcept
Definition: Scalar.H:258
const globalIndex & parcelAddr() const noexcept
The original parcel addressing.
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
label maxTracks(propsDict.getOrDefault< label >("maxTracks", -1))
void createTrackField(const UList< Type > &values, List< DynamicList< Type >> &trackValues) const
void resetCloud(const label localCloudSize)
void gatherInplace(List< Type > &fld, const int tag=UPstream::msgType(), const UPstream::commsTypes=UPstream::commsTypes::nonBlocking, const label comm=UPstream::worldComm) const
Inplace collect data in processor order on master (in serial: a no-op).
Registry of regIOobjects.
Namespace for OpenFOAM.