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
29 Translates OpenFOAM data to Ensight format.
30 An Ensight part is created for each cellZone and patch.
33 - foamToEnsightParts [OPTION] \n
34 Translates OpenFOAM data to Ensight format
37 Write Ensight data in ASCII format instead of "C Binary"
40 Exclude the often incomplete initial conditions.
44 - writes to @a Ensight directory to avoid collisions with foamToEnsight.
46 \*---------------------------------------------------------------------------*/
49 #include "timeSelector.H"
51 #include "volFields.H"
54 #include "IOobjectList.H"
55 #include "scalarIOField.H"
56 #include "tensorIOField.H"
58 #include "ensightParts.H"
59 #include "ensightOutputFunctions.H"
63 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
67 int main(int argc, char *argv[])
69 // with -constant and -zeroTime
70 timeSelector::addOptions(true, false);
71 argList::noParallel();
72 argList::validOptions.insert("ascii", "");
74 const label nTypes = 2;
75 const word fieldTypes[] =
77 volScalarField::typeName,
78 volVectorField::typeName
81 const label nSprayFieldTypes = 2;
82 const word sprayFieldTypes[] =
84 scalarIOField::typeName,
85 vectorIOField::typeName
88 # include "setRootCase.H"
89 # include "createTime.H"
92 instantList timeDirs = timeSelector::select0(runTime, args);
94 // default to binary output, unless otherwise specified
95 IOstream::streamFormat format = IOstream::BINARY;
96 if (args.options().found("ascii"))
98 format = IOstream::ASCII;
101 fileName ensightDir = args.rootPath()/args.globalCaseName()/"Ensight";
102 fileName dataDir = ensightDir/"data";
103 fileName caseFileName = "Ensight.case";
104 fileName dataMask = fileName("data")/ensightFile::mask();
106 // Ensight and Ensight/data directories must exist
114 # include "createMesh.H"
115 // Construct the list of ensight parts for the entire mesh
116 ensightParts partsList(mesh);
118 // write summary information
120 OFstream partsInfoFile(ensightDir/"partsInfo");
123 << "// summary of ensight parts" << nl << nl;
124 partsList.writeSummary(partsInfoFile);
127 # include "checkHasMovingMesh.H"
128 # include "checkHasLagrangian.H"
130 // only take the objects that exists at the end of the calculation
131 IOobjectList objects(mesh, timeDirs[timeDirs.size()-1].name());
132 IOobjectList sprayObjects(mesh, timeDirs[timeDirs.size()-1].name(), "lagrangian");
134 // write single geometry or one per time step
135 fileName geometryFileName("geometry");
138 geometryFileName = dataMask/geometryFileName;
141 // the case file is always ASCII
142 Info << "write case: " << caseFileName.c_str() << endl;
144 OFstream caseFile(ensightDir/caseFileName, IOstream::ASCII);
145 caseFile.setf(ios_base::left);
148 << setw(16) << "type:" << "ensight gold" << nl << nl
150 << setw(16) << "model: 1" << geometryFileName.c_str() << nl;
155 << setw(16) << "measured: 2"
156 << fileName(dataMask/"lagrangian"/"positions").c_str() << nl;
159 << nl << "VARIABLE" << nl;
161 label nFieldTime = timeDirs.size();
167 List<label> fieldFileNumbers(nFieldTime);
168 List<label> sprayFileNumbers(nFieldTime);
170 // map used times used
171 Map<scalar> timeIndices;
174 label nSprayTime = 0;
176 forAll(timeDirs, timeI)
178 runTime.setTime(timeDirs[timeI], timeI);
180 # include "getTimeIndex.H"
182 fieldFileNumbers[nFieldTime++] = timeIndex;
184 // the data/ITER subdirectory must exist
185 fileName subDir = ensightFile::subDir(timeIndex);
186 mkDir(dataDir/subDir);
188 // place a timestamp in the directory for future reference
190 OFstream timeStamp(dataDir/subDir/"time");
192 << "# timestep time" << nl
193 << subDir.c_str() << " " << runTime.timeName() << nl;
196 # include "moveMesh.H"
198 if (nFieldTime == 1 || mesh.moving())
202 geometryFileName = dataDir/subDir/"geometry";
206 partsList.recalculate(mesh);
209 ensightGeoFile geoFile(ensightDir/geometryFileName, format);
210 partsList.writeGeometry(geoFile);
214 Info<< "write volume field: " << flush;
216 for (label i=0; i < nTypes; i++)
218 wordList fieldNames = objects.names(fieldTypes[i]);
220 forAll (fieldNames, fieldI)
222 word fieldName = fieldNames[fieldI];
224 # include "checkHasValidField.H"
234 mesh.time().timeName(),
240 if (fieldTypes[i] == volScalarField::typeName)
244 ensightCaseEntry<scalar>
252 ensightVolField<scalar>
263 else if (fieldTypes[i] == volVectorField::typeName)
267 ensightCaseEntry<vector>
275 ensightVolField<vector>
286 else if (fieldTypes[i] == volSphericalTensorField::typeName)
290 ensightCaseEntry<sphericalTensor>
298 ensightVolField<sphericalTensor>
309 else if (fieldTypes[i] == volSymmTensorField::typeName)
313 ensightCaseEntry<symmTensor>
321 ensightVolField<symmTensor>
332 else if (fieldTypes[i] == volTensorField::typeName)
336 ensightCaseEntry<tensor>
344 ensightVolField<tensor>
362 // check that the positions field is present for this time
367 mesh.time().timeName(),
373 if (ioHeader.headerOk())
375 sprayFileNumbers[nSprayTime++] = timeIndex;
379 Info<< "write spray field: " << flush;
381 ensightParticlePositions
389 for (label i=0; i < nSprayFieldTypes; i++)
391 wordList fieldNames = sprayObjects.names(sprayFieldTypes[i]);
393 forAll (fieldNames, fieldI)
395 word fieldName = fieldNames[fieldI];
397 # include "checkHasSprayField.H"
407 mesh.time().timeName(),
414 if (sprayFieldTypes[i] == scalarIOField::typeName)
418 ensightCaseEntry<scalar>
427 ensightSprayField<scalar>
436 else if (sprayFieldTypes[i] == vectorIOField::typeName)
440 ensightCaseEntry<vector>
449 ensightSprayField<vector>
458 else if (sprayFieldTypes[i] == tensorIOField::typeName)
462 ensightCaseEntry<tensor>
471 ensightSprayField<tensor>
486 fieldFileNumbers.setSize(nFieldTime);
487 sprayFileNumbers.setSize(nSprayTime);
490 caseFile << nl << "TIME" << nl;
491 # include "ensightCaseTimes.H"
493 Info<< "\nEnd\n"<< endl;
499 // ************************************************************************* //