Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
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
26\*---------------------------------------------------------------------------*/
27
28#include "objectRegistry.H"
29#include "ListOps.H"
30
31// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
32
33template<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
66template<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
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// ************************************************************************* //
Various functions to operate on Lists.
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 primitive field of type <T> with automated input and output.
Definition IOField.H:53
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
static void combineReduce(T &value, CombineOp cop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce) applying cop to inplace combine value from different processors.
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
static const UList< T > & null() noexcept
Return a null UList (reference to a nullObject). Behaves like an empty UList.
Definition UList.H:225
Registry of regIOobjects.
labelField origProcIds_
The originating processor ids.
label nTracks() const noexcept
Number of tracks to generate.
void createTrackField(const UList< Type > &values, List< DynamicList< Type > > &trackValues) const
label setTrackFields(const objectRegistry &obr, HashTable< List< DynamicList< Type > > > &fieldTable) const
labelField origParcelIds_
The originating parcel ids.
A class for handling words, derived from Foam::string.
Definition word.H:66
List< word > wordList
List of word.
Definition fileName.H:60
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299
List helper to append y unique elements onto the end of x.
Definition ListOps.H:721