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
78 if (Pstream::parRun())
79 {
80 Pstream::combineGather(fieldNames, ListOps::uniqueEqOp<word>());
81 Pstream::broadcast(fieldNames);
82 }
83
84 for (const word& fieldName : fieldNames)
85 {
86 fieldTable(fieldName).resize(nTracks());
87 }
88 }
89
90 // Process in parallel-consistent order
91 for (const word& fieldName : fieldTable.sortedToc())
92 {
93 auto& output = fieldTable[fieldName];
94
95 const auto* ptr = obr.cfindObject<IOField<Type>>(fieldName);
96
97 this->createTrackField
98 (
99 ptr ? static_cast<const UList<Type>&>(*ptr) : UList<Type>::null(),
100 output
101 );
102 }
103
104 return fieldTable.size();
105}
106
107
108// ************************************************************************* //
Various functions to operate on Lists.
static void combineGather(const List< commsStruct > &comms, T &value, const CombineOp &cop, const int tag, const label comm)
static void broadcast(Type &value, const label comm=UPstream::worldComm)
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
label toGlobal(const label i) const
From local to global index.
Definition: globalIndexI.H:260
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]).
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.
List< word > wordList
A List of words.
Definition: fileName.H:63
static Ostream & output(Ostream &os, const IntRange< T > &range)
Definition: IntRanges.C:66
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333