BUGFIX: Uninitialised member variables
[foam-extend-3.2.git] / applications / utilities / postProcessing / graphics / newEnsightFoamReader / USERD_set_filenames.H
blob14959b29da16dc8d3d1167635f3529a93c759998
1 //======================================================================
2 //  Setting filenames
3 //======================================================================
4 int USERD_set_filenames
6     char filename_1[],
7     char filename_2[],
8     char the_path[],
9     int swapbytes
12 #ifdef ENSIGHTDEBUG
13     Info << "Entering: USERD_set_filenames" << endl << flush;
14 #endif
16     char tmp[100];
18     label lRoot = strlen(the_path);
19     label lCase = strlen(filename_1);
21     bool cleared = false;
23     while (!cleared)
24     {
25         lRoot = strlen(the_path);
26         lCase = strlen(filename_1);
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     }
39     rootDir = the_path;
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;
50     if (!isDir(rootDir/caseDir))
51     {
52        Info<< rootDir/caseDir << " is not a valid directory."
53            << endl;
54        return Z_ERR;
55     }
58     // construct the global pointers to the database and mesh
60     delete meshPtr;
61     delete runTimePtr;
63     runTimePtr = new Time
64     (
65         Time::controlDictName,
66         rootDir,
67         caseDir
68     );
70     Time& runTime = *runTimePtr;
72     meshPtr = new fvMesh
73     (
74         IOobject
75         (
76             fvMesh::defaultRegion,
77             runTime.timeName(),
78             runTime
79         )
80     );
82     // set the available number of time-steps
83     TimeList = (const instantList&)Foam::Time::findTimes(rootDir/caseDir);
85     Num_time_steps = TimeList.size() - 1;
87     nPatches = meshPtr->boundaryMesh().size();
89     // set the number of fields and store their names
90     // a valid field must exist for all time-steps
91     runTime.setTime(TimeList[TimeList.size()-1], TimeList.size()-1);
92     IOobjectList objects(*meshPtr, runTime.timeName());
94     fieldNames = (const wordList&)objects.names();
96     // because of the spray being a 'field' ...
97     // get the availabe number of variables and
98     // check for type (scalar/vector/tensor)
100     label nVar = 0;
101     wordList scalars = objects.names(scalarName);
103     for (label n=0; n<fieldNames.size(); 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     }
117     wordList vectors = objects.names(vectorName);
119     for (label n=0; n<fieldNames.size(); 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     }
133     wordList tensors = objects.names(tensorName);
135     for (label n=0; n<fieldNames.size(); 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     }
149     bool lagrangianNamesFound = false;
150     label n = 0;
151     while ((!lagrangianNamesFound) && (n<Num_time_steps))
152     {
153         runTime.setTime(TimeList[n+1], n+1);
155         Cloud<passiveParticle> lagrangian(*meshPtr);
157         n++;
158         if (lagrangian.size()>0)
159         {
160             lagrangianNamesFound = true;
161         }
162     }
164     IOobject sprayHeader
165     (
166         "positions",
167         runTime.timeName(),
168         "lagrangian",
169         runTime,
170         IOobject::NO_READ,
171         IOobject::NO_WRITE,
172         false
173     );
176     if (sprayHeader.headerOk())
177     {
178         Info << "[Found lagrangian]" << endl;
180         delete sprayPtr;
182         sprayPtr = new Cloud<passiveParticle>(*meshPtr);
184         IOobjectList objects(*meshPtr, runTime.timeName(), "lagrangian");
186         lagrangianScalarNames =
187             (const wordList&)objects.names(sprayScalarFieldName);
188         lagrangianVectorNames =
189             (const wordList&)objects.names(sprayVectorFieldName);
191         isSpray[fieldNames.size()] = true;
193         nSprayVariables += lagrangianScalarNames.size();
194         nSprayVariables += lagrangianVectorNames.size();
196         Num_unstructured_parts++;
197     }
199     Current_time_step = Num_time_steps;
200     runTime.setTime(TimeList[Current_time_step], Current_time_step);
202     Num_variables = nVar + nSprayVariables;
205     // Check if second mesh (region) exist.
206     IOobject ensightReaderDictHeader
207     (
208         IOobject
209         (
210             "ensightReaderDict",
211             runTime.constant(),
212             *meshPtr,
213             IOobject::MUST_READ,
214             IOobject::NO_WRITE
215         )
216     );
218     word secondRegionName("solid");
220     if(ensightReaderDictHeader.headerOk())
221     {
222         IOdictionary ensightReaderDict
223         (
224             IOobject
225             (
226                 "ensightReaderDict",
227                 runTime.constant(),
228                 *meshPtr,
229                 IOobject::MUST_READ,
230                 IOobject::NO_WRITE
231             )
232         );
234         if (ensightReaderDict.found("secondRegionName"))
235         {
236             secondRegionName = word
237             (
238                 ensightReaderDict.lookup("secondRegionName")
239             );
240         }
242         if (ensightReaderDict.found("scalingFactor"))
243         {
244             scalingFactor = readScalar
245             (
246                 ensightReaderDict.lookup("scalingFactor")
247             );
248         }
249     }
251     objectRegistry secondMeshObjReg
252     (
253         IOobject
254         (
255             secondRegionName,
256             runTime.timeName(),
257             runTime,
258             IOobject::MUST_READ
259         )
260     );
262     IOobject pointsHeader
263     (
264         "points",
265         runTime.constant(),
266         polyMesh::meshSubDir,
267         secondMeshObjReg
268     );
270     if(pointsHeader.headerOk())
271     {
272         secondMeshPtr = new fvMesh
273         (
274             IOobject
275             (
276                 secondRegionName,
277                 runTime.timeName(),
278                 runTime,
279                 IOobject::MUST_READ
280             )
281         );
282     }
284     if(secondMeshPtr)
285     {
286         Num_unstructured_parts += 1;
288         nSecondMeshPatches = secondMeshPtr->boundaryMesh().size();
290         IOobjectList secondMeshObjects(*secondMeshPtr, runTime.timeName());
292         secondMeshFieldNames = (const wordList&)secondMeshObjects.names();
294         label nVar = 0;
295         wordList scalars = secondMeshObjects.names(scalarName);
297         for (label n=0; n<secondMeshFieldNames.size(); n++)
298         {
299             bool isitScalar = false;
300             forAll(scalars,i)
301             {
302                 if (secondMeshFieldNames[n] == scalars[i])
303                 {
304                     isitScalar = true;
305                     secondMeshVar2field[nVar++] = n;
306                 }
307             }
308             secondMeshIsScalar[n] = isitScalar;
309         }
311         wordList vectors = secondMeshObjects.names(vectorName);
313         for (label n=0; n<secondMeshFieldNames.size(); n++)
314         {
315             bool isitVector = false;
316             forAll(vectors,i)
317             {
318                 if (secondMeshFieldNames[n] == vectors[i])
319                 {
320                     isitVector = true;
321                     secondMeshVar2field[nVar++] = n;
322                 }
323             }
324             secondMeshIsVector[n] = isitVector;
325         }
327         wordList tensors = secondMeshObjects.names(tensorName);
329         for (label n=0; n<secondMeshFieldNames.size(); n++)
330         {
331             bool isitTensor = false;
332             forAll(tensors,i)
333             {
334                 if (secondMeshFieldNames[n] == tensors[i])
335                 {
336                     isitTensor = true;
337                     secondMeshVar2field[nVar++] = n;
338                 }
339             }
340             secondMeshIsTensor[n] = isitTensor;
341         }
343         Num_variables += nVar;
344         nSecondMeshVariables = nVar;
345     }
347     secondMeshPartNum = nPatches+2;
349     if(sprayPtr)
350     {
351         secondMeshPartNum += 1;
352     }
355     // Check if finite area mesh exists
356     IOobject faMeshBoundaryIOobj
357     (
358         "boundary",
359         meshPtr->time().findInstance
360         (
361             meshPtr->dbDir()/fvMesh::meshSubDir, "boundary"
362         ),
363         faMesh::meshSubDir,
364         *meshPtr,
365         IOobject::MUST_READ,
366         IOobject::NO_WRITE
367     );
370     if(faMeshBoundaryIOobj.headerOk())
371     {
372         Info << "\nFound finite area mesh" << endl;
373         faMeshPtr = new faMesh(*meshPtr);
374     }
377     if(faMeshPtr)
378     {
379         Num_unstructured_parts += 1;
381         IOobjectList faMeshObjects(faMeshPtr->time(), runTime.timeName());
383         faMeshFieldNames = (const wordList&)faMeshObjects.names();
385         Info << faMeshFieldNames << endl;
387         label nVar = 0;
388         wordList scalars = faMeshObjects.names(faScalarName);
390         for (label n=0; n<faMeshFieldNames.size(); n++)
391         {
392             bool isitScalar = false;
393             forAll(scalars,i)
394             {
395                 if (faMeshFieldNames[n] == scalars[i])
396                 {
397                     isitScalar = true;
398                     faMeshVar2field[nVar++] = n;
399                 }
400             }
401             faMeshIsScalar[n] = isitScalar;
402         }
404         wordList vectors = faMeshObjects.names(faVectorName);
406         for (label n=0; n<faMeshFieldNames.size(); n++)
407         {
408             bool isitVector = false;
409             forAll(vectors,i)
410             {
411                 if (faMeshFieldNames[n] == vectors[i])
412                 {
413                     isitVector = true;
414                     faMeshVar2field[nVar++] = n;
415                 }
416             }
417             faMeshIsVector[n] = isitVector;
418         }
420         wordList tensors = faMeshObjects.names(faTensorName);
422         for (label n=0; n<faMeshFieldNames.size(); n++)
423         {
424             bool isitTensor = false;
425             forAll(tensors,i)
426             {
427                 if (faMeshFieldNames[n] == tensors[i])
428                 {
429                     isitTensor = true;
430                     faMeshVar2field[nVar++] = n;
431                 }
432             }
433             faMeshIsTensor[n] = isitTensor;
434         }
436         Num_variables += nVar;
437         nFaMeshVariables = nVar;
438     }
441     Numparts_available = Num_unstructured_parts + Num_structured_parts
442         + nPatches + nSecondMeshPatches;
445 #ifdef ENSIGHTDEBUG
446     Info << "Leaving: USERD_set_filenames" << endl << flush;
447 #endif
449     return Z_OK;