GIT: Resolved conflicts arising from merge with develop branch

This commit is contained in:
Andrew Heather
2016-09-26 10:57:34 +01:00
48 changed files with 2484 additions and 1295 deletions

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -34,27 +34,38 @@ Description
Usage
\b foamToEnsight [OPTION]
Translates OpenFOAM data to EnSight format
Options:
- \par -ascii
Write Ensight data in ASCII format instead of "C Binary"
- \par -patches patchList
Specify particular patches to write.
Specifying an empty list suppresses writing the internalMesh.
- \par -noZero
Exclude the often incomplete initial conditions.
- \par -noLagrangian \n
Suppress writing lagrangian positions and fields.
- \par -noPatches
Suppress writing any patches.
- \par -faceZones zoneList
- \par -patches patchList \n
Specify particular patches to write.
Specifying an empty list suppresses writing the internalMesh.
- \par -faceZones zoneList \n
Specify faceZones to write, with wildcards
- \par -cellZone zoneName
Specify single cellZone to write (not lagrangian)
- \par -width \<n\>\n
Width of EnSight data subdir (default: 8)
Note
Parallel support for cloud data is not supported
- writes to \a EnSight directory to avoid collisions with foamToEnsightParts
- writes to \a EnSight directory to avoid collisions with
foamToEnsightParts
\*---------------------------------------------------------------------------*/
@ -70,14 +81,12 @@ Note
#include "scalarIOField.H"
#include "tensorIOField.H"
#include "ensightFile.H"
#include "ensightMesh.H"
#include "ensightField.H"
#include "ensightParticlePositions.H"
#include "ensightCloudField.H"
#include "ensightCloud.H"
#include "fvc.H"
#include "cellSet.H"
#include "fvMeshSubset.H"
@ -87,11 +96,7 @@ using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
bool inFileNameList
(
const fileNameList& nameList,
const word& name
)
bool inFileNameList(const fileNameList& nameList, const word& name)
{
forAll(nameList, i)
{
@ -105,7 +110,6 @@ bool inFileNameList
}
int main(int argc, char *argv[])
{
timeSelector::addOptions();
@ -122,6 +126,11 @@ int main(int argc, char *argv[])
"write values in nodes"
);
argList::addBoolOption
(
"noLagrangian",
"suppress writing lagrangian positions and fields"
);
argList::addBoolOption
(
"noPatches",
"suppress writing any patches"
@ -151,32 +160,21 @@ int main(int argc, char *argv[])
"word",
"specify cellZone to write"
);
argList::addOption
(
"name",
"subdir",
"define sub-directory name to use for ensight data "
"(default: 'EnSight')"
);
argList::addOption
(
"width",
"n",
"width of ensight data subdir"
);
#include "setRootCase.H"
// Check options
const bool binary = !args.optionFound("ascii");
const bool nodeValues = args.optionFound("nodeValues");
cpuTime timer;
memInfo mem;
Info<< "Initial memory "
<< mem.update().size() << " kB" << endl;
#include "createTime.H"
instantList Times = timeSelector::select0(runTime, args);
#include "createNamedMesh.H"
// Mesh instance (region0 gets filtered out)
fileName regionPrefix = "";
if (regionName != polyMesh::defaultRegion)
{
regionPrefix = regionName;
}
// the volume field types that we handle
const label nVolFieldTypes = 10;
const word volFieldTypes[] =
{
@ -193,38 +191,90 @@ int main(int argc, char *argv[])
volTensorField::Internal::typeName
};
#include "setRootCase.H"
// default to binary output, unless otherwise specified
const IOstream::streamFormat format =
(
args.optionFound("ascii")
? IOstream::ASCII
: IOstream::BINARY
);
const bool nodeValues = args.optionFound("nodeValues");
cpuTime timer;
memInfo mem;
Info<< "Initial memory "
<< mem.update().size() << " kB" << endl;
#include "createTime.H"
instantList timeDirs = timeSelector::select0(runTime, args);
// adjust output width
if (args.optionFound("width"))
{
ensightFile::subDirWidth(args.optionRead<label>("width"));
}
// define sub-directory name to use for EnSight data
fileName ensightDir = "EnSight";
args.optionReadIfPresent("name", ensightDir);
// Path to EnSight directory at case level only
// - For parallel cases, data only written from master
fileName ensightDir = args.rootPath()/args.globalCaseName()/"EnSight";
if (!ensightDir.isAbsolute())
{
ensightDir = args.rootPath()/args.globalCaseName()/ensightDir;
}
const fileName dataDir = ensightDir/"data";
const fileName dataMask = dataDir.name()/ensightFile::mask();
if (Pstream::master())
{
// EnSight and EnSight/data directories must exist
// - remove old data for a clean conversion of everything
if (isDir(ensightDir))
{
rmDir(ensightDir);
}
mkDir(ensightDir);
mkDir(dataDir);
}
#include "createNamedMesh.H"
// Mesh instance (region0 gets filtered out)
fileName regionPrefix;
if (regionName != polyMesh::defaultRegion)
{
regionPrefix = regionName;
}
// Start of case file header output
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const word prepend = args.globalCaseName() + '.';
OFstream *ensightCaseFilePtr = nullptr;
OFstream *ensightCaseFilePtr(nullptr);
if (Pstream::master())
{
fileName caseFileName = prepend + "case";
Info<< nl << "write case: " << caseFileName.c_str() << endl;
fileName caseFileName = args.globalCaseName() + ".case";
// the case file is always ASCII
Info<< "Converting " << timeDirs.size() << " time steps" << nl
<< "Ensight case: " << caseFileName.c_str() << endl;
// The case file is always ASCII
ensightCaseFilePtr = new OFstream
(
ensightDir/caseFileName,
IOstream::ASCII
);
ensightCaseFilePtr->setf(ios_base::left);
ensightCaseFilePtr->setf(ios_base::scientific, ios_base::floatfield);
ensightCaseFilePtr->precision(5);
*ensightCaseFilePtr
<< "FORMAT" << nl
<< "type: ensight gold" << nl << nl;
@ -253,6 +303,8 @@ int main(int argc, char *argv[])
fieldPatterns = wordReList(args.optionLookup("fields")());
}
const bool noLagrangian = args.optionFound("noLagrangian");
word cellZoneName;
const bool doCellZone = args.optionReadIfPresent("cellZone", cellZoneName);
@ -280,133 +332,84 @@ int main(int argc, char *argv[])
patchPatterns,
selectedZones,
zonePatterns,
binary
format
);
// Set Time to the last time before looking for the lagrangian objects
runTime.setTime(Times.last(), Times.size()-1);
runTime.setTime(timeDirs.last(), timeDirs.size()-1);
IOobjectList objects(mesh, runTime.timeName());
#include "checkMeshMoving.H"
#include "findCloudFields.H"
if (meshMoving)
{
Info<< "Detected a moving mesh (multiple polyMesh/points files)."
<< " Writing meshes for every timestep." << endl;
}
wordHashSet allCloudNames;
if (Pstream::master())
{
word geomFileName = prepend + "0000";
// test the pre-check variable if there is a moving mesh
// time-set for geometries
// TODO: split off into separate time-set,
// but need to verify ensight spec
// test pre check variable if there is a moving mesh
if (meshMoving)
{
geomFileName = prepend + "****";
ensightCaseFile
<< "GEOMETRY" << nl
<< setw(16) << "model: 1"
<< (dataMask/ensightMesh::geometryName).c_str() << nl;
}
ensightCaseFile
<< "GEOMETRY" << nl
<< "model: 1 "
<< (geomFileName + ".mesh").c_str() << nl;
}
// Identify if lagrangian data exists at each time, and add clouds
// to the 'allCloudNames' hash set
forAll(Times, timeI)
{
runTime.setTime(Times[timeI], timeI);
fileNameList cloudDirs = readDir
(
runTime.timePath()/regionPrefix/cloud::prefix,
fileName::DIRECTORY
);
forAll(cloudDirs, cloudI)
{
IOobjectList cloudObjs
(
mesh,
runTime.timeName(),
cloud::prefix/cloudDirs[cloudI]
);
IOobject* positionsPtr = cloudObjs.lookup(word("positions"));
if (positionsPtr)
{
allCloudNames.insert(cloudDirs[cloudI]);
}
}
}
HashTable<HashTable<word>> allCloudFields;
forAllConstIter(wordHashSet, allCloudNames, cloudIter)
{
// Add the name of the cloud(s) to the case file header
if (Pstream::master())
else
{
ensightCaseFile
<< (
"measured: 1 "
+ prepend
+ "****."
+ cloudIter.key()
).c_str()
<< nl;
<< "GEOMETRY" << nl
<< setw(16) << "model:"
<< ensightMesh::geometryName << nl;
}
// Create a new hash table for each cloud
allCloudFields.insert(cloudIter.key(), HashTable<word>());
// Identify the new cloud in the hash table
HashTable<HashTable<word>>::iterator newCloudIter =
allCloudFields.find(cloudIter.key());
// Loop over all times to build list of fields and field types
// for each cloud
forAll(Times, timeI)
// Add the name of the cloud(s) to the case file header
forAll(cloudNames, cloudNo)
{
runTime.setTime(Times[timeI], timeI);
const word& cloudName = cloudNames[cloudNo];
IOobjectList cloudObjs
(
mesh,
runTime.timeName(),
cloud::prefix/cloudIter.key()
);
forAllConstIter(IOobjectList, cloudObjs, fieldIter)
{
const IOobject obj = *fieldIter();
if (obj.name() != "positions")
{
// Add field and field type
newCloudIter().insert
(
obj.name(),
obj.headerClassName()
);
}
}
ensightCaseFile
<< setw(16) << "measured: 1"
<< fileName
(
dataMask/cloud::prefix/cloudName/"positions"
).c_str() << nl;
}
}
Info<< "Startup in "
<< timer.cpuTimeIncrement() << " s, "
<< mem.update().size() << " kB" << nl << endl;
// ignore special fields (_0 fields),
// ignore fields we don't handle,
// ignore fields that are not available for all time-steps
HashTable<bool> fieldsToUse;
label nTimeSteps = 0;
forAll(Times, timeIndex)
forAll(timeDirs, timeIndex)
{
nTimeSteps++;
runTime.setTime(Times[timeIndex], timeIndex);
++nTimeSteps;
runTime.setTime(timeDirs[timeIndex], timeIndex);
word timeName = itoa(timeIndex);
word timeFile = prepend + timeName;
Info<< "Time [" << timeIndex << "] = " << runTime.timeName() << nl;
Info<< "Translating time = " << runTime.timeName() << nl;
if (Pstream::master())
{
// the data/ITER subdirectory must exist
// Note that data/ITER is indeed a valid ensight::FileName
const fileName subDir = ensightFile::subDir(timeIndex);
mkDir(dataDir/subDir);
// place a timestamp in the directory for future reference
OFstream timeStamp(dataDir/subDir/"time");
timeStamp
<< "# timestep time" << nl
<< subDir.c_str() << " " << runTime.timeName() << nl;
}
polyMesh::readUpdateState meshState = mesh.readUpdate();
if (timeIndex != 0 && meshSubsetter.hasSubMesh())
@ -420,7 +423,6 @@ int main(int argc, char *argv[])
meshSubsetter.setLargeCellSubset(c0, 0);
}
if (meshState != polyMesh::UNCHANGED)
{
eMesh.correct();
@ -430,8 +432,7 @@ int main(int argc, char *argv[])
{
eMesh.write
(
ensightDir,
prepend,
dataDir,
timeIndex,
meshMoving,
ensightCaseFile
@ -450,8 +451,9 @@ int main(int argc, char *argv[])
// Cell field data output
// ~~~~~~~~~~~~~~~~~~~~~~
Info<< "Write volume field (";
for (label i=0; i<nVolFieldTypes; i++)
for (label i=0; i<nVolFieldTypes; ++i)
{
wordList fieldNames = objects.names(volFieldTypes[i]);
@ -470,7 +472,7 @@ int main(int argc, char *argv[])
#include "checkData.H"
if (!variableGood)
if (!fieldsToUse[fieldName])
{
continue;
}
@ -491,10 +493,8 @@ int main(int argc, char *argv[])
(
volField(meshSubsetter, vf),
eMesh,
ensightDir,
prepend,
dataDir,
timeIndex,
binary,
nodeValues,
ensightCaseFile
);
@ -506,10 +506,8 @@ int main(int argc, char *argv[])
(
volField(meshSubsetter, vf),
eMesh,
ensightDir,
prepend,
dataDir,
timeIndex,
binary,
nodeValues,
ensightCaseFile
);
@ -521,10 +519,8 @@ int main(int argc, char *argv[])
(
volField(meshSubsetter, vf),
eMesh,
ensightDir,
prepend,
dataDir,
timeIndex,
binary,
nodeValues,
ensightCaseFile
);
@ -536,10 +532,8 @@ int main(int argc, char *argv[])
(
volField(meshSubsetter, vf),
eMesh,
ensightDir,
prepend,
dataDir,
timeIndex,
binary,
nodeValues,
ensightCaseFile
);
@ -551,10 +545,8 @@ int main(int argc, char *argv[])
(
volField(meshSubsetter, vf),
eMesh,
ensightDir,
prepend,
dataDir,
timeIndex,
binary,
nodeValues,
ensightCaseFile
);
@ -570,10 +562,8 @@ int main(int argc, char *argv[])
(
volField<scalar>(meshSubsetter, df),
eMesh,
ensightDir,
prepend,
dataDir,
timeIndex,
binary,
nodeValues,
ensightCaseFile
);
@ -588,10 +578,8 @@ int main(int argc, char *argv[])
(
volField<vector>(meshSubsetter, df),
eMesh,
ensightDir,
prepend,
dataDir,
timeIndex,
binary,
nodeValues,
ensightCaseFile
);
@ -607,10 +595,8 @@ int main(int argc, char *argv[])
(
volField<sphericalTensor>(meshSubsetter, df),
eMesh,
ensightDir,
prepend,
dataDir,
timeIndex,
binary,
nodeValues,
ensightCaseFile
);
@ -625,10 +611,8 @@ int main(int argc, char *argv[])
(
volField<symmTensor>(meshSubsetter, df),
eMesh,
ensightDir,
prepend,
dataDir,
timeIndex,
binary,
nodeValues,
ensightCaseFile
);
@ -643,24 +627,29 @@ int main(int argc, char *argv[])
(
volField<tensor>(meshSubsetter, df),
eMesh,
ensightDir,
prepend,
dataDir,
timeIndex,
binary,
nodeValues,
ensightCaseFile
);
}
else
{
// Do not currently handle this type - blacklist for the future.
fieldsToUse.set(fieldName, false);
}
}
}
Info<< " )" << nl;
// Cloud field data output
// ~~~~~~~~~~~~~~~~~~~~~~~
forAllConstIter(HashTable<HashTable<word>>, allCloudFields, cloudIter)
forAll(cloudNames, cloudNo)
{
const word& cloudName = cloudIter.key();
const word& cloudName = cloudNames[cloudNo];
const HashTable<word>& theseCloudFields = cloudFields[cloudName];
fileNameList currentCloudDirs = readDir
(
@ -668,17 +657,22 @@ int main(int argc, char *argv[])
fileName::DIRECTORY
);
Info<< "Write " << cloudName << " (";
bool cloudExists = inFileNameList(currentCloudDirs, cloudName);
reduce(cloudExists, orOp<bool>());
ensightParticlePositions
(
mesh,
ensightDir,
timeFile,
dataDir,
timeIndex,
cloudName,
cloudExists
cloudExists,
format
);
forAllConstIter(HashTable<word>, cloudIter(), fieldIter)
forAllConstIter(HashTable<word>, theseCloudFields, fieldIter)
{
const word& fieldName = fieldIter.key();
const word& fieldType = fieldIter();
@ -696,17 +690,20 @@ int main(int argc, char *argv[])
(
false
);
reduce(fieldExists, orOp<bool>());
if (fieldType == scalarIOField::typeName)
{
ensightCloudField<scalar>
(
fieldObject,
ensightDir,
prepend,
dataDir,
timeIndex,
cloudName,
cloudNo,
ensightCaseFile,
fieldExists
fieldExists,
format
);
}
else if (fieldType == vectorIOField::typeName)
@ -714,37 +711,34 @@ int main(int argc, char *argv[])
ensightCloudField<vector>
(
fieldObject,
ensightDir,
prepend,
dataDir,
timeIndex,
cloudName,
cloudNo,
ensightCaseFile,
fieldExists
fieldExists,
format
);
}
else
{
Info<< "Unable to convert field type " << fieldType
<< " for field " << fieldName << endl;
}
}
Info<< " )" << nl;
}
Info<< "Wrote in "
<< timer.cpuTimeIncrement() << " s, "
<< mem.update().size() << " kB" << endl;
<< mem.update().size() << " kB" << nl << nl;
}
#include "ensightCaseTail.H"
if (Pstream::master())
if (ensightCaseFilePtr) // on master only
{
delete ensightCaseFilePtr;
}
Info<< "\nEnd: "
Info<< "End: "
<< timer.elapsedCpuTime() << " s, "
<< mem.update().peak() << " kB (peak)\n" << endl;
<< mem.update().peak() << " kB (peak)" << nl << endl;
return 0;
}