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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
12 
13 Description
14  Check time directories for lagrangian data.
15 
16 \*---------------------------------------------------------------------------*/
17 
18 // The fields for each cloud:
19 List<HashTable<HashTable<word>>> regionCloudFields(meshes.size());
20 
21 // Identify if lagrangian data exist at any time step.
22 if (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,
61  timeName,
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::mapCombineReduce
105  (
106  cloudFields,
107  HashTableOps::plusEqOp<word>()
108  );
109  }
110  }
111 }
112 
113 // Sorted list of cloud names
114 List<wordList> regionCloudNames(meshes.size());
115 
116 {
117  wordHashSet allRegionClouds;
118 
119  forAll(regionCloudNames, regioni)
120  {
121  regionCloudNames[regioni] = regionCloudFields[regioni].sortedToc();
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  }
137 }
138 
139 
140 // ************************************************************************* //
forAll(regionCloudNames, regioni)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
wordList regionNames
List< HashTable< HashTable< word > > > regionCloudFields(meshes.size())
word timeName
Definition: getTimeIndex.H:3
dynamicFvMesh & mesh
const word cloudName(propsDict.get< word >("cloud"))
label size() const noexcept
The number of entries in the list.
Definition: UPtrListI.H:106
Foam::PtrList< Foam::fvMesh > meshes(regionNames.size())
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
Definition: HashSet.H:73
const wordList allCloudNames(allRegionClouds.sortedToc())
List< word > wordList
List of word.
Definition: fileName.H:59
Ostream & flush(Ostream &os)
Flush stream.
Definition: Ostream.H:521
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
messageStream Info
Information stream (stdout output on master, null elsewhere)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
List< fileName > fileNameList
List of fileName.
Definition: fileNameList.H:32
fileNameList readDir(const fileName &directory, const fileName::Type type=fileName::Type::FILE, const bool filtergz=true, const bool followLink=true)
Read a directory and return the entries as a fileName List.
Definition: POSIX.C:963
List< wordList > regionCloudNames(meshes.size())
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28