findFields.H
Go to the documentation of this file.
1 // check the final time directory for the following:
2 
3 // 1. volume fields
4 HashTable<word> volumeFields;
5 
6 // 2. the fields for each cloud:
7 HashTable<HashTable<word>> cloudFields;
8 
9 if (timeDirs.size())
10 {
11  IOobjectList objs(mesh, timeDirs.last().name());
12 
13  forAllConstIter(IOobjectList, objs, fieldIter)
14  {
15  const IOobject& obj = *fieldIter();
16  const word& fieldName = obj.name();
17  const word& fieldType = obj.headerClassName();
18 
19  if (fieldName.size() > 2 && fieldName(fieldName.size()-2, 2) == "_0")
20  {
21  // ignore _0 fields
22  }
23  else if (volFieldTypes.found(fieldType))
24  {
25  // simply ignore types that we don't handle
26  volumeFields.insert(fieldName, fieldType);
27  }
28  }
29 
30 
31  //
32  // now check for lagrangian/<cloudName>
33  //
34  fileNameList cloudDirs = readDir
35  (
36  runTime.path()
37  / timeDirs.last().name()
38  / regionPrefix
39  / cloud::prefix,
40  fileType::directory
41  );
42 
43  forAll(cloudDirs, cloudI)
44  {
45  const word& cloudName = cloudDirs[cloudI];
46 
47  // Create a new hash table for each cloud
48  cloudFields.insert(cloudName, HashTable<word>());
49 
50  // Identify the new cloud within the hash table
51  HashTable<HashTable<word>>::iterator cloudIter =
52  cloudFields.find(cloudName);
53 
54  IOobjectList objs
55  (
56  mesh,
57  timeDirs.last().name(),
58  cloud::prefix/cloudName
59  );
60 
61  bool hasPositions = false;
62  forAllConstIter(IOobjectList, objs, fieldIter)
63  {
64  const IOobject obj = *fieldIter();
65  const word& fieldName = obj.name();
66  const word& fieldType = obj.headerClassName();
67 
68  if (fieldName == "positions")
69  {
70  hasPositions = true;
71  }
72  else if (cloudFieldTypes.found(fieldType))
73  {
74  // simply ignore types that we don't handle
75  cloudIter().insert(fieldName, fieldType);
76  }
77  }
78 
79  // drop this cloud if it has no positions or is otherwise empty
80  if (!hasPositions || cloudIter().empty())
81  {
82  Info<< "removing cloud " << cloudName << endl;
83  cloudFields.erase(cloudIter);
84  }
85  }
86 
87  //
88  // verify that the variable is present for all times
89  //
90  for (label i=0; volumeFields.size() && i < timeDirs.size(); ++i)
91  {
92  IOobjectList objs(mesh, timeDirs[i].name());
93 
94  forAllIter(HashTable<word>, volumeFields, fieldIter)
95  {
96  const word& fieldName = fieldIter.key();
97 
98  if (!objs.found(fieldName))
99  {
100  volumeFields.erase(fieldIter);
101  }
102  }
103  }
104 }
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:459
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
fvMesh & mesh
HashTable< word > volumeFields
Definition: findFields.H:4
HashTable< HashTable< word > > cloudFields
Definition: findFields.H:7
static instantList timeDirs
Definition: globalFoam.H:44
fileNameList readDir(const fileName &, const fileType=fileType::file, const bool filterVariants=true, const bool followLink=true)
Read a directory and return the entries as a string list.
Definition: POSIX.C:662
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
messageStream Info
const word cloudName(propsDict.lookup("cloudName"))
List< fileName > fileNameList
A List of fileNames.
Definition: fileNameList.H:50