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-------------------------------------------------------------------------------
10License
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
26Class
27 Foam::particleTracksSampler
28
29Description
30 Helper class when generating particle tracks.
31 The interface is fairly rudimentary.
32
33SourceFiles
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
49namespace Foam
50{
51
52// Forward Declarations
53class objectRegistry;
54
55/*---------------------------------------------------------------------------*\
56 Class particleTracksSampler Declaration
57\*---------------------------------------------------------------------------*/
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
82public:
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
96 const globalIndex& parcelAddr() const noexcept
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 }
145 void resetCloud(const label localCloudSize)
146 {
147 cloudGather_.reset(localCloudSize, globalIndex::gatherOnly{});
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>
160 (
161 const UList<Type>& values,
162 List<DynamicList<Type>>& trackValues
163 ) const;
164
165
166 template<class Type>
167 label setTrackFields
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// ************************************************************************* //
Info<< nl<< "Wrote faMesh in vtk format: "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.mesh().time().globalPath()/"finiteArea-edges"));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
A HashTable similar to std::unordered_map.
Definition: HashTable.H:123
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
void resize_nocopy(const label len)
Adjust allocated size of list without necessarily.
Definition: ListI.H:146
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:116
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:68
void reset(const label localSize, const label comm=UPstream::worldComm, const bool parallel=UPstream::parRun())
Definition: globalIndex.C:207
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).
label totalSize() const
Global sum of localSizes.
Definition: globalIndexI.H:125
Registry of regIOobjects.
Helper class when generating particle tracks. The interface is fairly rudimentary.
labelField origProcIds_
The originating processor ids.
void resetCloud(const label localCloudSize)
const globalIndex & parcelAddr() const noexcept
The original parcel addressing.
void reset(const labelUList &origParcelCounts)
Define the orig parcel mappings.
label setSampleRate(const label sampleFreq, const label maxPositions, const label maxTracks=-1)
Set the sampling stride, upper limits.
label nParticle() const
Total number of particles.
label nTracks() const noexcept
Number of tracks to generate.
void createTrackField(const UList< Type > &values, List< DynamicList< Type > > &trackValues) const
void gatherInplace(List< Type > &fld) const
label setTrackFields(const objectRegistry &obr, HashTable< List< DynamicList< Type > > > &fieldTable) const
labelField origParcelIds_
The originating parcel ids.
Header files for all the primitive types that Fields are instantiated for.
Namespace for OpenFOAM.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
const direction noexcept
Definition: Scalar.H:223
label maxTracks(propsDict.getOrDefault< label >("maxTracks", -1))
label maxPositions(propsDict.get< label >("maxPositions"))