USERD_set_filenames.H
Go to the documentation of this file.
1 //======================================================================
2 // Setting filenames
3 //======================================================================
5 (
6  char filename_1[],
7  char filename_2[],
8  char the_path[],
9  int swapbytes
10 )
11 {
12 #ifdef ENSIGHTDEBUG
13  Info<< "Entering: USERD_set_filenames" << endl << flush;
14 #endif
15 
16  char tmp[100];
17 
18  label lRoot = strlen(the_path);
19  label lCase = strlen(filename_1);
20 
21  bool cleared = false;
22 
23  while (!cleared)
24  {
25  lRoot = strlen(the_path);
26  lCase = strlen(filename_1);
27 
28  // remove the last '/' from rootDir
29  if (the_path[lRoot-1] == '/')
30  {
31  the_path[lRoot-1] = '\0';
32  }
33  else
34  {
35  cleared = true;
36  }
37  }
38 
39  rootDir = the_path;
40 
41  // the path is pre-pended to filename_1
42  // 1 is the 'Geometry' : 2 the 'Result' which is null here
43  // since two_field is FALSE
44  for (label i=0; i<lCase-lRoot;i++)
45  {
46  tmp[i] = filename_1[i+1+lRoot];
47  }
48  caseDir = tmp;
49 
50  if (!isDir(rootDir/caseDir))
51  {
52  Info<< rootDir/caseDir << " is not a valid directory."
53  << endl;
54  return Z_ERR;
55  }
56 
57  // construct the global pointers to the database and mesh
58 
59  delete meshPtr;
60  delete runTimePtr;
61 
62  runTimePtr = new Time
63  (
64  Time::controlDictName,
65  rootDir,
66  caseDir
67  );
68 
69  Time& runTime = *runTimePtr;
70 
71  meshPtr = new fvMesh
72  (
73  IOobject
74  (
75  fvMesh::defaultRegion,
76  runTime.timeName(),
77  runTime
78  ),
79  false
80  );
81 
82  // set the available number of time-steps
84 
85  Num_time_steps = timeDirs.size() - 1;
86 
87  nPatches = meshPtr->boundaryMesh().size();
88 
89  // set the number of fields and store their names
90  // a valid field must exist for all time-steps
91  runTime.setTime(timeDirs.last(), timeDirs.size()-1);
92  IOobjectList objects(*meshPtr, runTime.timeName());
93 
94  fieldNames = objects.names();
95 
96  // because of the spray being a 'field' ...
97  // get the available number of variables and
98  // check for type (scalar/vector/tensor)
99 
100  label nVar = 0;
101  wordList scalars = objects.names(scalarName);
102 
103  forAll(fieldNames, n)
104  {
105  bool isitScalar = false;
106  forAll(scalars,i)
107  {
108  if (fieldNames[n] == scalars[i])
109  {
110  isitScalar = true;
111  var2field[nVar++] = n;
112  }
113  }
114  isScalar[n] = isitScalar;
115  }
116 
117  wordList vectors = objects.names(vectorName);
118 
119  forAll(fieldNames, n)
120  {
121  bool isitVector = false;
122  forAll(vectors,i)
123  {
124  if (fieldNames[n] == vectors[i])
125  {
126  isitVector = true;
127  var2field[nVar++] = n;
128  }
129  }
130  isVector[n] = isitVector;
131  }
132 
133  wordList tensors = objects.names(tensorName);
134 
135  forAll(fieldNames, n)
136  {
137  bool isitTensor = false;
138  forAll(tensors,i)
139  {
140  if (fieldNames[n] == tensors[i])
141  {
142  isitTensor = true;
143  var2field[nVar++] = n;
144  }
145  }
146  isTensor[n] = isitTensor;
147  }
148 
149  bool lagrangianNamesFound = false;
150  label n = 0;
151  while (!lagrangianNamesFound && n < Num_time_steps)
152  {
153  runTime.setTime(timeDirs[n+1], n+1);
154 
155  Cloud<passiveParticle> lagrangian(*meshPtr, cloud::defaultName);
156 
157  n++;
158  if (lagrangian.size())
159  {
160  lagrangianNamesFound = true;
161  }
162  }
163 
164  IOobject sprayHeader
165  (
166  "positions",
167  runTime.timeName(),
168  cloud::prefix,
169  runTime,
170  IOobject::NO_READ,
171  IOobject::NO_WRITE,
172  false
173  );
174 
175  if (sprayHeader.headerOk())
176  {
177  Info<< "[Found lagrangian]" << endl;
178 
179  delete sprayPtr;
180 
181  sprayPtr = new Cloud<passiveParticle>(*meshPtr, cloud::defaultName);
182 
183  IOobjectList objects(*meshPtr, runTime.timeName(), cloud::prefix);
184 
189 
190  isSpray[fieldNames.size()] = true;
191 
192  nSprayVariables += lagrangianScalarNames.size();
194 
196  }
197 
199  runTime.setTime(timeDirs[Current_time_step], Current_time_step);
200 
204 
205 #ifdef ENSIGHTDEBUG
206  Info<< "Leaving: USERD_set_filenames" << endl << flush;
207 #endif
208 
209  return Z_OK;
210 }
label nPatches
Definition: readKivaGrid.H:402
static int Num_variables
Definition: globalFoam.H:20
#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.
static word sprayScalarFieldName
Definition: globalFoam.H:35
static bool isSpray[maxNames]
Definition: globalFoam.H:30
static fvMesh * meshPtr
Definition: globalFoam.H:52
static Cloud< passiveParticle > * sprayPtr
Definition: globalFoam.H:53
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
static List< word > lagrangianScalarNames
Definition: globalFoam.H:47
static int Current_time_step
Definition: globalFoam.H:22
static word sprayVectorFieldName
Definition: globalFoam.H:36
static int Numparts_available
Definition: globalFoam.H:13
static fileName rootDir
Definition: globalFoam.H:41
static bool isVector[maxNames]
Definition: globalFoam.H:28
static List< word > fieldNames
Definition: globalFoam.H:46
static int Num_time_steps
Definition: globalFoam.H:18
static word scalarName
Definition: globalFoam.H:32
static word tensorName
Definition: globalFoam.H:34
static instantList timeDirs
Definition: globalFoam.H:44
static label nSprayVariables
Definition: globalFoam.H:24
static Time * runTimePtr
Definition: globalFoam.H:51
bool isDir(const fileName &, const bool followLink=true)
Does the name exist as a directory in the file system?
Definition: POSIX.C:539
static int Num_unstructured_parts
Definition: globalFoam.H:11
static List< word > lagrangianVectorNames
Definition: globalFoam.H:48
static bool isTensor[maxNames]
Definition: globalFoam.H:29
objects
static fileName caseDir
Definition: globalFoam.H:42
int USERD_set_filenames(char filename_1[], char filename_2[], char the_path[], int swapbytes)
static instantList findTimes(const fileName &, const word &constantName="constant")
Search a given directory for valid time directories.
Definition: findTimes.C:36
List< word > wordList
A List of words.
Definition: fileName.H:54
static int Num_structured_parts
Definition: globalFoam.H:12
Ostream & flush(Ostream &os)
Flush stream.
Definition: Ostream.H:243
messageStream Info
label n
static word vectorName
Definition: globalFoam.H:33
static label var2field[maxNames]
Definition: globalFoam.H:49
static bool isScalar[maxNames]
Definition: globalFoam.H:27