1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 Translates FOAM data to EnSight format
29 - foamToEnsight [OPTION] \n
30 Translates OpenFOAM data to Ensight format
33 Write Ensight data in ASCII format instead of "C Binary"
36 Parallel support for cloud data is not supported
38 \*---------------------------------------------------------------------------*/
41 #include "IOobjectList.H"
45 #include "volFields.H"
47 #include "labelIOField.H"
48 #include "scalarIOField.H"
49 #include "tensorIOField.H"
51 #include "ensightMesh.H"
52 #include "ensightField.H"
54 #include "ensightParticlePositions.H"
55 #include "ensightCloudField.H"
61 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
65 const fileNameList& nameList,
71 if (nameList[i] == name)
83 int main(int argc, char *argv[])
85 argList::validOptions.insert("patches", "patch list");
86 argList::validOptions.insert("ascii", "" );
87 # include "addTimeOptions.H"
89 # include "setRootCase.H"
93 if (args.options().found("ascii"))
98 # include "createTime.H"
100 // get the available time-steps
101 instantList Times = runTime.times();
103 # include "checkTimeOptions.H"
105 runTime.setTime(Times[startTime], startTime);
107 # include "createNamedMesh.H"
109 // Mesh instance (region0 gets filtered out)
110 fileName regionPrefix = "";
112 if (regionName != polyMesh::defaultRegion)
114 regionPrefix = regionName;
117 const label nTypes = 2;
118 const word fieldTypes[] =
120 volScalarField::typeName,
121 volVectorField::typeName
124 // Create the output folder
125 const word postProcDir = "EnSight";
127 // Path to EnSight folder at case level only
128 // - For parallel cases, data only written from master
129 // fileName postProcPath = runTime.path()/postProcDir;
130 fileName postProcPath = args.rootPath()/args.globalCaseName()/postProcDir;
132 if (Pstream::master())
134 if (dir(postProcPath))
142 // Start of case file header output
143 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
145 const word prepend = args.globalCaseName() + '.';
147 OFstream *ensightCaseFilePtr = NULL;
148 if (Pstream::master())
150 fileName ensightCaseFileName = prepend + "case";
154 ensightCaseFilePtr = new OFstream
156 postProcPath/ensightCaseFileName,
157 runTime.writeFormat(),
158 runTime.writeVersion(),
159 runTime.writeCompression()
164 ensightCaseFilePtr = new OFstream
166 postProcPath/ensightCaseFileName,
167 runTime.writeFormat(),
168 runTime.writeVersion(),
169 IOstream::UNCOMPRESSED
173 Info<< nl << "Case file is " << ensightCaseFileName << endl;
176 OFstream& ensightCaseFile = *ensightCaseFilePtr;
178 # include "ensightCaseHeader.H"
180 // Construct the EnSight mesh
181 ensightMesh eMesh(mesh, args, binary);
183 // Set Time to the last time before looking for the lagrangian objects
184 runTime.setTime(Times[Times.size()-1], Times.size()-1);
186 IOobjectList objects(mesh, runTime.timeName());
188 # include "checkMeshMoving.H"
190 wordHashSet allCloudNames;
191 word geomCaseFileName = prepend + "000";
192 if (Pstream::master())
194 // test pre check variable if there is a moving mesh
195 if (meshMoving == true)
197 geomCaseFileName = prepend + "***";
203 << (geomCaseFileName + ".mesh").c_str() << nl;
206 // Identify if lagrangian data exists at each time, and add clouds
207 // to the 'allCloudNames' hash set
208 for (label n=startTime; n<endTime; n++)
210 runTime.setTime(Times[n], n);
212 fileNameList cloudDirs = readDir
214 runTime.timePath()/regionPrefix/"lagrangian",
218 forAll(cloudDirs, cloudI)
220 IOobjectList cloudObjs
224 "lagrangian"/cloudDirs[cloudI]
227 IOobject* positionsPtr = cloudObjs.lookup("positions");
231 allCloudNames.insert(cloudDirs[cloudI]);
236 HashTable<HashTable<word> > allCloudFields;
237 forAllConstIter(wordHashSet, allCloudNames, cloudIter)
239 // Add the name of the cloud(s) to the case file header
240 if (Pstream::master())
252 // Create a new hash table for each cloud
253 allCloudFields.insert(cloudIter.key(), HashTable<word>());
255 // Identify the new cloud in the hash table
256 HashTable<HashTable<word> >::iterator newCloudIter =
257 allCloudFields.find(cloudIter.key());
259 // Loop over all times to build list of fields and field types
261 for (label n=startTime; n<endTime; n++)
263 runTime.setTime(Times[n], n);
265 IOobjectList cloudObjs
269 "lagrangian"/cloudIter.key()
272 forAllConstIter(IOobjectList, cloudObjs, fieldIter)
274 const IOobject obj = *fieldIter();
276 if (obj.name() != "positions")
278 // Add field and field type
279 newCloudIter().insert
282 obj.headerClassName()
289 label nTimeSteps = 0;
290 for (label n=startTime; n<endTime; n++)
293 runTime.setTime(Times[n], n);
294 label timeIndex = n - startTime;
296 word timeName = itoa(timeIndex);
297 word timeFile = prepend + timeName;
299 Info<< "Translating time = " << runTime.timeName() << nl;
301 # include "moveMesh.H"
303 if (timeIndex == 0 || mesh.moving())
315 // Start of field data output
316 // ~~~~~~~~~~~~~~~~~~~~~~~~~~
318 if (timeIndex == 0 && Pstream::master())
320 ensightCaseFile<< nl << "VARIABLE" << nl;
324 // Cell field data output
325 // ~~~~~~~~~~~~~~~~~~~~~~
327 for (label i=0; i<nTypes; i++)
329 wordList fieldNames = objects.names(fieldTypes[i]);
331 for (label j=0; j<fieldNames.size(); j++)
333 word fieldName = fieldNames[j];
335 bool variableGood = true;
337 # include "checkData.H"
344 mesh.time().timeName(),
350 if (fieldTypes[i] == volScalarField::typeName)
363 else if (fieldTypes[i] == volVectorField::typeName)
376 else if (fieldTypes[i] == volSphericalTensorField::typeName)
378 ensightField<sphericalTensor>
389 else if (fieldTypes[i] == volSymmTensorField::typeName)
391 ensightField<symmTensor>
402 else if (fieldTypes[i] == volTensorField::typeName)
420 // Cloud field data output
421 // ~~~~~~~~~~~~~~~~~~~~~~~
423 forAllConstIter(HashTable<HashTable<word> >, allCloudFields, cloudIter)
425 const word& cloudName = cloudIter.key();
427 fileNameList currentCloudDirs = readDir
429 runTime.timePath()/regionPrefix/"lagrangian",
433 bool cloudExists = inFileNameList(currentCloudDirs, cloudName);
434 ensightParticlePositions
443 forAllConstIter(HashTable<word>, cloudIter(), fieldIter)
445 const word& fieldName = fieldIter.key();
446 const word& fieldType = fieldIter();
451 mesh.time().timeName(),
452 "lagrangian"/cloudName,
457 bool fieldExists = fieldObject.headerOk();
458 if (fieldType == scalarIOField::typeName)
460 ensightCloudField<scalar>
471 else if (fieldType == vectorIOField::typeName)
473 ensightCloudField<vector>
486 Info<< "Unable to convert field type " << fieldType
487 << " for field " << fieldName << endl;
493 # include "ensightCaseTail.H"
495 if (Pstream::master())
497 delete ensightCaseFilePtr;
504 // ************************************************************************* //