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