Loading...
Searching...
No Matches
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;
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
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
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
110 return nTracks_;
111 }
112
113 //- Define the orig parcel mappings
114 void reset(const labelUList& origParcelCounts)
115 {
116 origParcelAddr_.reset(origParcelCounts);
118 origProcIds_.clear();
119 trackIds_.clear();
120 }
121
122 //- Set the sampling stride, upper limits
123 // \return Number of tracks to generate
124 label setSampleRate
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)
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>
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// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182#ifdef NoRepository
184#endif
185
186// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
187
188#endif
190// ************************************************************************* //
label maxTracks(propsDict.getOrDefault< label >("maxTracks", -1))
label maxPositions(propsDict.get< label >("maxPositions"))
Info<< nl;Info<< "Write faMesh in vtk format:"<< nl;{ vtk::uindirectPatchWriter writer(aMesh.patch(), fileName(aMesh.time().globalPath()/vtkBaseFileName));writer.writeGeometry();globalIndex procAddr(aMesh.nFaces());labelList cellIDs;if(UPstream::master()) { cellIDs.resize(procAddr.totalSize());for(const labelRange &range :procAddr.ranges()) { auto slice=cellIDs.slice(range);slice=identity(range);} } writer.beginCellData(4);writer.writeProcIDs();writer.write("cellID", cellIDs);writer.write("area", aMesh.S().field());writer.write("normal", aMesh.faceAreaNormals());writer.beginPointData(1);writer.write("normal", aMesh.pointAreaNormals());Info<< " "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-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:68
A HashTable similar to std::unordered_map.
Definition HashTable.H:124
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
Calculates a non-overlapping list of offsets based on an input size (eg, number of cells) from differ...
Definition globalIndex.H:77
static void gatherInplace(const labelUList &offsets, const label comm, const ProcIDsContainer &procIDs, List< Type > &fld, const int tag=UPstream::msgType(), UPstream::commsTypes commsType=UPstream::commsTypes::nonBlocking)
Inplace collect in processor order on master (== procIDs[0]).
void reset(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.
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.
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:40
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition hashSets.C:26
Field< label > labelField
Specialisation of Field<T> for label.
Definition labelField.H:48
const direction noexcept
Definition scalarImpl.H:265
UList< label > labelUList
A UList of labels.
Definition UList.H:75
Dispatch tag: Construct 'one-sided' from local sizes, using gather but no broadcast.