00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 #include <OpenFOAM/argList.H>
00077 #include <OpenFOAM/timeSelector.H>
00078
00079 #include <finiteVolume/volFields.H>
00080 #include <OpenFOAM/OFstream.H>
00081 #include <OpenFOAM/IOmanip.H>
00082 #include <OpenFOAM/IOobjectList.H>
00083 #include <OpenFOAM/scalarIOField.H>
00084 #include <OpenFOAM/tensorIOField.H>
00085
00086 #include <conversion/ensightParts.H>
00087 #include "ensightOutputFunctions.H"
00088
00089 using namespace Foam;
00090
00091
00092
00093
00094
00095 int main(int argc, char *argv[])
00096 {
00097
00098
00099
00100 timeSelector::addOptions(true, false);
00101 argList::noParallel();
00102 argList::validOptions.insert("ascii", "");
00103 argList::validOptions.insert("index", "start");
00104 argList::validOptions.insert("noMesh", "");
00105
00106
00107 wordHashSet volFieldTypes;
00108 volFieldTypes.insert(volScalarField::typeName);
00109 volFieldTypes.insert(volVectorField::typeName);
00110 volFieldTypes.insert(volSphericalTensorField::typeName);
00111 volFieldTypes.insert(volSymmTensorField::typeName);
00112 volFieldTypes.insert(volTensorField::typeName);
00113
00114
00115 wordHashSet cloudFieldTypes;
00116 cloudFieldTypes.insert(scalarIOField::typeName);
00117 cloudFieldTypes.insert(vectorIOField::typeName);
00118 cloudFieldTypes.insert(tensorIOField::typeName);
00119
00120 const char* geometryName = "geometry";
00121
00122 # include <OpenFOAM/setRootCase.H>
00123 # include <OpenFOAM/createTime.H>
00124
00125
00126 instantList timeDirs = timeSelector::select0(runTime, args);
00127
00128
00129 IOstream::streamFormat format = IOstream::BINARY;
00130 if (args.optionFound("ascii"))
00131 {
00132 format = IOstream::ASCII;
00133 }
00134
00135
00136 bool optIndex = false;
00137 label indexingNumber = 0;
00138 if (args.optionFound("index"))
00139 {
00140 optIndex = true;
00141 indexingNumber = args.optionRead<label>("index");
00142 }
00143
00144
00145 bool optNoMesh = args.optionFound("noMesh");
00146
00147 fileName ensightDir = args.rootPath()/args.globalCaseName()/"Ensight";
00148 fileName dataDir = ensightDir/"data";
00149 fileName caseFileName = "Ensight.case";
00150 fileName dataMask = fileName("data")/ensightFile::mask();
00151
00152
00153
00154
00155 if (isDir(ensightDir))
00156 {
00157 Info<<"Warning: reusing existing directory" << nl
00158 << " " << ensightDir << endl;
00159 }
00160 mkDir(ensightDir);
00161 mkDir(dataDir);
00162
00163 # include <OpenFOAM/createNamedMesh.H>
00164
00165
00166 fileName regionPrefix;
00167
00168 if (regionName != polyMesh::defaultRegion)
00169 {
00170 regionPrefix = regionName;
00171 }
00172
00173
00174 ensightParts partsList(mesh);
00175
00176
00177 {
00178 OFstream partsInfoFile(ensightDir/"partsInfo");
00179
00180 partsInfoFile
00181 << "// summary of ensight parts" << nl << nl;
00182 partsList.writeSummary(partsInfoFile);
00183 }
00184
00185 # include "checkHasMovingMesh.H"
00186 # include "findFields.H"
00187
00188 if (hasMovingMesh && optNoMesh)
00189 {
00190 Info<< "mesh is moving: ignoring '-noMesh' option" << endl;
00191 optNoMesh = false;
00192 }
00193
00194
00195
00196 Map<scalar> timeIndices;
00197
00198
00199 DynamicList<label> fieldTimesUsed;
00200
00201
00202
00203
00204
00205 HashTable<autoPtr<DynamicList<label> > > cloudTimesUsed;
00206
00207
00208 forAllConstIter(HashTable<HashTable<word> >, cloudFields, cloudIter)
00209 {
00210 cloudTimesUsed.insert(cloudIter.key(),
00211 autoPtr<DynamicList<label> >(new DynamicList<label>()));
00212 }
00213
00214
00215 forAll(timeDirs, timeI)
00216 {
00217 runTime.setTime(timeDirs[timeI], timeI);
00218
00219 # include "getTimeIndex.H"
00220
00221
00222 fieldTimesUsed.append(timeIndex);
00223
00224
00225 fileName subDir = ensightFile::subDir(timeIndex);
00226 mkDir(dataDir/subDir);
00227
00228
00229 {
00230 OFstream timeStamp(dataDir/subDir/"time");
00231 timeStamp
00232 << "# timestep time" << nl
00233 << subDir.c_str() << " " << runTime.timeName() << nl;
00234 }
00235
00236 # include "moveMesh.H"
00237
00238 if (timeI == 0 || mesh.moving())
00239 {
00240 if (mesh.moving())
00241 {
00242 partsList.recalculate(mesh);
00243 }
00244
00245 if (!optNoMesh)
00246 {
00247 fileName geomDir;
00248 if (hasMovingMesh)
00249 {
00250 geomDir = dataDir/subDir;
00251 }
00252
00253 ensightGeoFile geoFile(ensightDir/geomDir/geometryName, format);
00254 partsList.writeGeometry(geoFile);
00255 Info<< nl;
00256 }
00257 }
00258
00259 Info<< "write volume field (" << flush;
00260
00261 forAllConstIter(HashTable<word>, volumeFields, fieldIter)
00262 {
00263 const word& fieldName = fieldIter.key();
00264 const word& fieldType = fieldIter();
00265
00266 IOobject fieldObject
00267 (
00268 fieldName,
00269 mesh.time().timeName(),
00270 mesh,
00271 IOobject::MUST_READ,
00272 IOobject::NO_WRITE
00273 );
00274
00275 if (fieldType == volScalarField::typeName)
00276 {
00277 ensightVolField<scalar>
00278 (
00279 partsList,
00280 fieldObject,
00281 mesh,
00282 dataDir,
00283 subDir,
00284 format
00285 );
00286
00287 }
00288 else if (fieldType == volVectorField::typeName)
00289 {
00290 ensightVolField<vector>
00291 (
00292 partsList,
00293 fieldObject,
00294 mesh,
00295 dataDir,
00296 subDir,
00297 format
00298 );
00299
00300 }
00301 else if (fieldType == volSphericalTensorField::typeName)
00302 {
00303 ensightVolField<sphericalTensor>
00304 (
00305 partsList,
00306 fieldObject,
00307 mesh,
00308 dataDir,
00309 subDir,
00310 format
00311 );
00312
00313 }
00314 else if (fieldType == volSymmTensorField::typeName)
00315 {
00316 ensightVolField<symmTensor>
00317 (
00318 partsList,
00319 fieldObject,
00320 mesh,
00321 dataDir,
00322 subDir,
00323 format
00324 );
00325 }
00326 else if (fieldType == volTensorField::typeName)
00327 {
00328 ensightVolField<tensor>
00329 (
00330 partsList,
00331 fieldObject,
00332 mesh,
00333 dataDir,
00334 subDir,
00335 format
00336 );
00337 }
00338 }
00339 Info<< " )" << endl;
00340
00341
00342 forAllConstIter(HashTable<HashTable<word> >, cloudFields, cloudIter)
00343 {
00344 const word& cloudName = cloudIter.key();
00345
00346 if
00347 (
00348 !isDir
00349 (
00350 runTime.timePath()/regionPrefix/
00351 cloud::prefix/cloudName
00352 )
00353 )
00354 {
00355 continue;
00356 }
00357
00358 IOobjectList cloudObjs
00359 (
00360 mesh,
00361 runTime.timeName(),
00362 cloud::prefix/cloudName
00363 );
00364
00365
00366 if (cloudObjs.lookup("positions"))
00367 {
00368 ensightParticlePositions
00369 (
00370 mesh,
00371 dataDir,
00372 subDir,
00373 cloudName,
00374 format
00375 );
00376 }
00377 else
00378 {
00379 continue;
00380 }
00381
00382 Info<< "write " << cloudName << " (" << flush;
00383
00384 forAllConstIter(HashTable<word>, cloudIter(), fieldIter)
00385 {
00386 const word& fieldName = fieldIter.key();
00387 const word& fieldType = fieldIter();
00388
00389 IOobject *fieldObject = cloudObjs.lookup(fieldName);
00390
00391 if (!fieldObject)
00392 {
00393 Info<< "missing "
00394 << runTime.timeName()/cloud::prefix/cloudName
00395 / fieldName
00396 << endl;
00397 continue;
00398 }
00399
00400 if (fieldType == scalarIOField::typeName)
00401 {
00402 ensightLagrangianField<scalar>
00403 (
00404 *fieldObject,
00405 dataDir,
00406 subDir,
00407 cloudName,
00408 format
00409 );
00410
00411 }
00412 else if (fieldType == vectorIOField::typeName)
00413 {
00414 ensightLagrangianField<vector>
00415 (
00416 *fieldObject,
00417 dataDir,
00418 subDir,
00419 cloudName,
00420 format
00421 );
00422
00423 }
00424 else if (fieldType == tensorIOField::typeName)
00425 {
00426 ensightLagrangianField<tensor>
00427 (
00428 *fieldObject,
00429 dataDir,
00430 subDir,
00431 cloudName,
00432 format
00433 );
00434
00435 }
00436 }
00437
00438 Info<< " )" << endl;
00439
00440
00441 cloudTimesUsed[cloudName]->append(timeIndex);
00442 }
00443 }
00444
00445 # include "ensightOutputCase.H"
00446
00447 Info<< "\nEnd\n"<< endl;
00448
00449 return 0;
00450 }
00451
00452
00453