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] = (char)NULL;
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  );
80 
81  // set the available number of time-steps
83 
84  Num_time_steps = timeDirs.size() - 1;
85 
86  nPatches = meshPtr->boundaryMesh().size();
87 
88  // set the number of fields and store their names
89  // a valid field must exist for all time-steps
90  runTime.setTime(timeDirs.last(), timeDirs.size()-1);
91  IOobjectList objects(*meshPtr, runTime.timeName());
92 
93  fieldNames = objects.names();
94 
95  // because of the spray being a 'field' ...
96  // get the availabe number of variables and
97  // check for type (scalar/vector/tensor)
98 
99  label nVar = 0;
100  wordList scalars = objects.names(scalarName);
101 
102  forAll(fieldNames, n)
103  {
104  bool isitScalar = false;
105  forAll(scalars,i)
106  {
107  if (fieldNames[n] == scalars[i])
108  {
109  isitScalar = true;
110  var2field[nVar++] = n;
111  }
112  }
113  isScalar[n] = isitScalar;
114  }
115 
116  wordList vectors = objects.names(vectorName);
117 
118  forAll(fieldNames, n)
119  {
120  bool isitVector = false;
121  forAll(vectors,i)
122  {
123  if (fieldNames[n] == vectors[i])
124  {
125  isitVector = true;
126  var2field[nVar++] = n;
127  }
128  }
129  isVector[n] = isitVector;
130  }
131 
132  wordList tensors = objects.names(tensorName);
133 
134  forAll(fieldNames, n)
135  {
136  bool isitTensor = false;
137  forAll(tensors,i)
138  {
139  if (fieldNames[n] == tensors[i])
140  {
141  isitTensor = true;
142  var2field[nVar++] = n;
143  }
144  }
145  isTensor[n] = isitTensor;
146  }
147 
148  bool lagrangianNamesFound = false;
149  label n = 0;
150  while (!lagrangianNamesFound && n < Num_time_steps)
151  {
152  runTime.setTime(timeDirs[n+1], n+1);
153 
154  Cloud<passiveParticle> lagrangian(*meshPtr);
155 
156  n++;
157  if (lagrangian.size())
158  {
159  lagrangianNamesFound = true;
160  }
161  }
162 
163  IOobject sprayHeader
164  (
165  "positions",
166  runTime.timeName(),
167  cloud::prefix,
168  runTime,
169  IOobject::NO_READ,
170  IOobject::NO_WRITE,
171  false
172  );
173 
174  if (sprayHeader.headerOk())
175  {
176  Info<< "[Found lagrangian]" << endl;
177 
178  delete sprayPtr;
179 
180  sprayPtr = new Cloud<passiveParticle>(*meshPtr);
181 
182  IOobjectList objects(*meshPtr, runTime.timeName(), cloud::prefix);
183 
185  (const wordList&)objects.names(sprayScalarFieldName);
187  (const wordList&)objects.names(sprayVectorFieldName);
188 
189  isSpray[fieldNames.size()] = true;
190 
191  nSprayVariables += lagrangianScalarNames.size();
193 
195  }
196 
198  runTime.setTime(timeDirs[Current_time_step], Current_time_step);
199 
203 
204 #ifdef ENSIGHTDEBUG
205  Info<< "Leaving: USERD_set_filenames" << endl << flush;
206 #endif
207 
208  return Z_OK;
209 }
static int Num_time_steps
Definition: globalFoam.H:18
static fileName rootDir
Definition: globalFoam.H:41
Ostream & flush(Ostream &os)
Flush stream.
Definition: Ostream.H:240
static word tensorName
Definition: globalFoam.H:34
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
static word vectorName
Definition: globalFoam.H:33
static List< word > lagrangianScalarNames
Definition: globalFoam.H:47
static instantList timeDirs
Definition: globalFoam.H:44
static bool isScalar[maxNames]
Definition: globalFoam.H:27
static int Num_unstructured_parts
Definition: globalFoam.H:11
static Time * runTimePtr
Definition: globalFoam.H:51
static word scalarName
Definition: globalFoam.H:32
bool isDir(const fileName &)
Does the name exist as a DIRECTORY in the file system?
Definition: POSIX.C:616
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:248
label nPatches
Definition: readKivaGrid.H:402
int USERD_set_filenames(char filename_1[], char filename_2[], char the_path[], int swapbytes)
static bool isTensor[maxNames]
Definition: globalFoam.H:29
static label var2field[maxNames]
Definition: globalFoam.H:49
static fileName caseDir
Definition: globalFoam.H:42
static int Current_time_step
Definition: globalFoam.H:22
static int Numparts_available
Definition: globalFoam.H:13
static Cloud< passiveParticle > * sprayPtr
Definition: globalFoam.H:53
static List< word > lagrangianVectorNames
Definition: globalFoam.H:48
List< word > wordList
A List of words.
Definition: fileName.H:54
static word sprayVectorFieldName
Definition: globalFoam.H:36
static instantList findTimes(const fileName &, const word &constantName="constant")
Search a given directory for valid time directories.
Definition: findTimes.C:38
messageStream Info
label n
#define forAll(list, i)
Definition: UList.H:420
static word sprayScalarFieldName
Definition: globalFoam.H:35
static bool isSpray[maxNames]
Definition: globalFoam.H:30
static fvMesh * meshPtr
Definition: globalFoam.H:52
static int Num_structured_parts
Definition: globalFoam.H:12
static label nSprayVariables
Definition: globalFoam.H:24
static bool isVector[maxNames]
Definition: globalFoam.H:28
static int Num_variables
Definition: globalFoam.H:20
static List< word > fieldNames
Definition: globalFoam.H:46