FreeFOAM The Cross-Platform CFD Toolkit
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[timeDirs.size()-1].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[timeDirs.size()-1].name()
38  / regionPrefix
39  / cloud::prefix,
40  fileName::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[timeDirs.size()-1].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 }
105