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-2021 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  const word& regionDir =
33  (
34  regionName != polyMesh::defaultRegion
35  ? regionName
36  : word::null
37  );
38 
39  const fileName cloudPrefix(regionDir/cloud::prefix);
40 
41  for (const instant& inst : timeDirs)
42  {
43  const word& timeName = inst.name();
44 
45  // DO NOT USE -->> runTime.setTime(timeDirs[timeI], timeI); <<--
46  // It incurs a large overhead when done so frequently.
47 
48  fileNameList cloudDirs
49  (
50  readDir
51  (
52  mesh.time().path()/timeName/cloudPrefix,
53  fileName::DIRECTORY
54  )
55  );
56 
57  for (fileName& cloudDir : cloudDirs)
58  {
59  const word cloudName(std::move(cloudDir));
60 
61  IOobjectList cloudObjs
62  (
63  mesh,
64  timeName,
65  cloudPrefix/cloudName
66  );
67 
68  // Clouds require "coordinates".
69  // The "positions" are for v1706 and lower.
70  // - detect and remove since these are treated specially
71 
72  bool isCloud = false;
73  if (cloudObjs.erase("coordinates"))
74  {
75  isCloud = true;
76  }
77  if (cloudObjs.erase("positions"))
78  {
79  isCloud = true;
80  }
81 
82  if (isCloud)
83  {
84  // Save the cloud fields on a per cloud basis
85  auto& fieldsPerCloud = cloudFields(cloudName);
86 
87  forAllConstIters(cloudObjs, fieldIter)
88  {
89  const IOobject* io = *fieldIter;
90 
91  // Field name/type
92  fieldsPerCloud.insert
93  (
94  io->name(),
95  io->headerClassName()
96  );
97  }
98  }
99  }
100  }
101  }
102 
103  if (Pstream::parRun())
104  {
105  for (auto& cloudFields : regionCloudFields)
106  {
107  Pstream::mapCombineGather
108  (
109  cloudFields,
110  HashTableOps::plusEqOp<word>()
111  );
112  Pstream::mapCombineScatter(cloudFields);
113  }
114  }
115 }
116 
117 // Sorted list of cloud names
118 List<wordList> regionCloudNames(meshes.size());
119 
120 {
121  wordHashSet allRegionClouds;
122 
123  forAll(regionCloudNames, regioni)
124  {
125  regionCloudNames[regioni] = regionCloudFields[regioni].sortedToc();
126 
127  allRegionClouds.insert(regionCloudNames[regioni]);
128  }
129 
130  const wordList allCloudNames(allRegionClouds.sortedToc());
131 
132  if (allRegionClouds.empty())
133  {
134  Info<< "none detected." << endl;
135  }
136  else
137  {
138  // Complete the echo information - as flatOutput
139  allRegionClouds.writeList(Info) << endl;
140  }
141 }
142 
143 
144 // ************************************************************************* //
cloudName
const word cloudName(propsDict.get< word >("cloud"))
forAll
forAll(regionCloudNames, regioni)
Definition: findCloudFields.H:132
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
allCloudNames
const wordList allCloudNames(allRegionClouds.sortedToc())
regionNames
wordList regionNames
Definition: getAllRegionOptions.H:37
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:62
Foam::flush
Ostream & flush(Ostream &os)
Flush stream.
Definition: Ostream.H:361
regionName
Foam::word regionName
Definition: createNamedDynamicFvMesh.H:1
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
meshes
Foam::PtrList< Foam::fvMesh > meshes(regionNames.size())
timeName
word timeName
Definition: getTimeIndex.H:3
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fileNameList
List< fileName > fileNameList
A List of fileNames.
Definition: fileNameList.H:58
forAllConstIters
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28
regionCloudNames
List< wordList > regionCloudNames(meshes.size())
Foam::wordHashSet
HashSet< word, Hash< word > > wordHashSet
A HashSet of words, uses string hasher.
Definition: HashSet.H:77
regionDir
const word & regionDir
Definition: findMeshDefinitionDict.H:34
Foam::readDir
fileNameList readDir(const fileName &directory, const fileName::Type type=fileName::FILE, const bool filtergz=true, const bool followLink=true)
Read a directory and return the entries as a fileName List.
Definition: MSwindows.C:707
regionCloudFields
List< HashTable< HashTable< word > > > regionCloudFields(meshes.size())