findCloudFields.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) 2018-2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
12
13Description
14 Check time directories for lagrangian data.
15
16\*---------------------------------------------------------------------------*/
17
18// The fields for each cloud:
19List<HashTable<HashTable<word>>> regionCloudFields(meshes.size());
20
21// Identify if lagrangian data exist at any time step.
22if (timeDirs.size() && doLagrangian)
23{
24 Info<< "Search for lagrangian ... " << flush;
25
26 forAll(meshes, regioni)
27 {
28 const fvMesh& mesh = meshes[regioni];
29 auto& cloudFields = regionCloudFields[regioni];
30
31 const word& regionName = regionNames[regioni];
32
33 const fileName cloudPrefix
34 (
35 polyMesh::regionName(regionName)/cloud::prefix
36 );
37
38 for (const instant& inst : timeDirs)
39 {
40 const word& timeName = inst.name();
41
42 // DO NOT USE -->> runTime.setTime(timeDirs[timeI], timeI); <<--
43 // It incurs a large overhead when done so frequently.
44
45 fileNameList cloudDirs
46 (
47 readDir
48 (
49 mesh.time().path()/timeName/cloudPrefix,
50 fileName::DIRECTORY
51 )
52 );
53
54 for (fileName& cloudDir : cloudDirs)
55 {
56 const word cloudName(std::move(cloudDir));
57
58 IOobjectList cloudObjs
59 (
60 mesh,
62 cloudPrefix/cloudName
63 );
64
65 // Clouds require "coordinates".
66 // The "positions" are for v1706 and lower.
67 // - detect and remove since these are treated specially
68
69 bool isCloud = false;
70 if (cloudObjs.erase("coordinates"))
71 {
72 isCloud = true;
73 }
74 if (cloudObjs.erase("positions"))
75 {
76 isCloud = true;
77 }
78
79 if (isCloud)
80 {
81 // Save the cloud fields on a per cloud basis
82 auto& fieldsPerCloud = cloudFields(cloudName);
83
84 forAllConstIters(cloudObjs, fieldIter)
85 {
86 const IOobject* io = *fieldIter;
87
88 // Field name/type
89 fieldsPerCloud.insert
90 (
91 io->name(),
92 io->headerClassName()
93 );
94 }
95 }
96 }
97 }
98 }
99
100 if (Pstream::parRun())
101 {
102 for (auto& cloudFields : regionCloudFields)
103 {
104 Pstream::mapCombineAllGather
105 (
106 cloudFields,
107 HashTableOps::plusEqOp<word>()
108 );
109 }
110 }
111}
112
113// Sorted list of cloud names
114List<wordList> regionCloudNames(meshes.size());
115
116{
117 wordHashSet allRegionClouds;
118
119 forAll(regionCloudNames, regioni)
120 {
121 regionCloudNames[regioni] = regionCloudFields[regioni].sortedToc();
122
123 allRegionClouds.insert(regionCloudNames[regioni]);
124 }
125
126 const wordList allCloudNames(allRegionClouds.sortedToc());
127
128 if (allRegionClouds.empty())
129 {
130 Info<< "none detected." << endl;
131 }
132 else
133 {
134 // Complete the echo information - as flatOutput
135 allRegionClouds.writeList(Info) << endl;
136 }
138
139
140// ************************************************************************* //
label size() const noexcept
The number of elements in the list.
Definition: UPtrListI.H:106
dynamicFvMesh & mesh
Foam::word regionName(Foam::polyMesh::defaultRegion)
Foam::PtrList< Foam::fvMesh > meshes(regionNames.size())
const wordList allCloudNames(allRegionClouds.sortedToc())
List< wordList > regionCloudNames(meshes.size())
List< HashTable< HashTable< word > > > regionCloudFields(meshes.size())
wordList regionNames
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
word timeName
Definition: getTimeIndex.H:3
List< word > wordList
A List of words.
Definition: fileName.H:63
messageStream Info
Information stream (stdout output on master, null elsewhere)
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
Definition: HashSet.H:82
Ostream & flush(Ostream &os)
Flush stream.
Definition: Ostream.H:364
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
#define forAllConstIters(container, iter)
Iterate across all elements of the container object with const access.
Definition: stdFoam.H:278
const word cloudName(propsDict.get< word >("cloud"))