updated to incorporate particle post-processing

This commit is contained in:
andy
2008-06-16 10:37:57 +01:00
parent 9bd3861cd2
commit 750a8c78ad
11 changed files with 524 additions and 369 deletions

View File

@ -5,4 +5,3 @@ foamToEnsight.C
ensightWriteBinary.C ensightWriteBinary.C
EXE = $(FOAM_APPBIN)/foamToEnsight EXE = $(FOAM_APPBIN)/foamToEnsight
//EXE = $(FOAM_USER_APPBIN)/foamToEnsight

View File

@ -1,7 +1,9 @@
EXE_INC = \ EXE_INC = \
-DFULLDEBUG -g -O0 \
-I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/lagrangian/basic/lnInclude -I$(LIB_SRC)/lagrangian/basic/lnInclude
EXE_LIBS = \ EXE_LIBS = \
-lfiniteVolume \ -lfiniteVolume \
-llagrangian -llagrangian \

View File

@ -1,13 +0,0 @@
forAll(Times, n1)
{
IOobject fieldObjectHeader
(
fieldName,
Times[n1].name(),
"lagrangian",
mesh,
IOobject::NO_READ
);
variableGood = variableGood && fieldObjectHeader.headerOk();
}

View File

@ -24,7 +24,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "ensightSprayField.H" #include "ensightCloudField.H"
#include "Time.H" #include "Time.H"
#include "IOField.H" #include "IOField.H"
#include "OFstream.H" #include "OFstream.H"
@ -35,39 +35,48 @@ using namespace Foam;
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
template<class Type> template<class Type>
void ensightSprayField void ensightCloudField
( (
const Foam::IOobject& fieldObject, const Foam::IOobject& fieldObject,
const Foam::fileName& postProcPath, const Foam::fileName& postProcPath,
const Foam::word& prepend, const Foam::word& prepend,
const Foam::label timeIndex, const Foam::label timeIndex,
const Foam::word& sprayName, const Foam::word& cloudName,
Foam::Ostream& ensightCaseFile Foam::Ostream& ensightCaseFile,
const bool dataExists
) )
{ {
Info<< "Converting spray field " << fieldObject.name() << endl; if (dataExists)
{
Info<< "Converting cloud " << cloudName
<< " field " << fieldObject.name() << endl;
}
else
{
Info<< "Creating empty cloud " << cloudName
<< " field " << fieldObject.name() << endl;
}
word timeFile = prepend + itoa(timeIndex); word timeFile = prepend + itoa(timeIndex);
const Time& runTime = fieldObject.time(); const Time& runTime = fieldObject.time();
if (timeIndex == 0) if (timeIndex == 0 && Pstream::master())
{ {
ensightCaseFile ensightCaseFile
<< pTraits<Type>::typeName << " per measured node: 1 "; << pTraits<Type>::typeName << " per measured node: 1 ";
ensightCaseFile.width(15); ensightCaseFile.width(15);
ensightCaseFile.setf(ios_base::left); ensightCaseFile.setf(ios_base::left);
ensightCaseFile ensightCaseFile
<< ("s" + fieldObject.name()).c_str() << ("c" + fieldObject.name()).c_str()
<< (' ' + prepend + "***." + sprayName << (' ' + prepend + "***." + cloudName
+ "." + fieldObject.name()).c_str() + "." + fieldObject.name()).c_str()
<< nl; << nl;
} }
// set the filename of the ensight file
fileName ensightFileName fileName ensightFileName
( (
timeFile + "." + sprayName +"." + fieldObject.name() timeFile + "." + cloudName +"." + fieldObject.name()
); );
OFstream ensightFile OFstream ensightFile
@ -78,8 +87,10 @@ void ensightSprayField
runTime.writeCompression() runTime.writeCompression()
); );
ensightFile << pTraits<Type>::typeName << " values" << nl; ensightFile<< pTraits<Type>::typeName << " values" << nl;
if (dataExists)
{
IOField<Type> vf(fieldObject); IOField<Type> vf(fieldObject);
ensightFile.setf(ios_base::scientific, ios_base::floatfield); ensightFile.setf(ios_base::scientific, ios_base::floatfield);
@ -105,10 +116,11 @@ void ensightSprayField
} }
} }
if ( (count % 6 != 0) || (count==0) ) if ((count % 6 != 0) || (count==0))
{ {
ensightFile << nl; ensightFile << nl;
} }
}
} }

View File

@ -28,33 +28,34 @@ InApplication
Description Description
SourceFiles SourceFiles
ensightSprayField.C ensightCloudField.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef ensightSprayField_H #ifndef ensightCloudField_H
#define ensightSprayField_H #define ensightCloudField_H
#include "IOobject.H" #include "IOobject.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type> template<class Type>
void ensightSprayField void ensightCloudField
( (
const Foam::IOobject& fieldObject, const Foam::IOobject& fieldObject,
const Foam::fileName& postProcPath, const Foam::fileName& postProcPath,
const Foam::word& prepend, const Foam::word& prepend,
const Foam::label timeIndex, const Foam::label timeIndex,
const Foam::word& timeFile, const Foam::word& timeFile,
const Foam::word& sprayName, const Foam::word& cloudName,
Foam::Ostream& ensightCaseFile Foam::Ostream& ensightCaseFile,
const bool dataExists
); );
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository #ifdef NoRepository
# include "ensightSprayField.C" # include "ensightCloudField.C"
#endif #endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -278,7 +278,7 @@ bool writePatchField
const Foam::label patchi, const Foam::label patchi,
const Foam::label ensightPatchi, const Foam::label ensightPatchi,
const Foam::faceSets& boundaryFaceSet, const Foam::faceSets& boundaryFaceSet,
const Foam::ensightMesh::nFacePrims& nfp, const Foam::ensightMesh::nFacePrimitives& nfp,
const Foam::labelList& patchProcessors, const Foam::labelList& patchProcessors,
Foam::OFstream& ensightFile Foam::OFstream& ensightFile
) )
@ -338,7 +338,7 @@ bool writePatchFieldBinary
const Foam::label patchi, const Foam::label patchi,
const Foam::label ensightPatchi, const Foam::label ensightPatchi,
const Foam::faceSets& boundaryFaceSet, const Foam::faceSets& boundaryFaceSet,
const Foam::ensightMesh::nFacePrims& nfp, const Foam::ensightMesh::nFacePrimitives& nfp,
const Foam::labelList& patchProcessors, const Foam::labelList& patchProcessors,
std::ofstream& ensightFile std::ofstream& ensightFile
) )
@ -403,12 +403,13 @@ void writePatchField
Foam::Ostream& ensightCaseFile Foam::Ostream& ensightCaseFile
) )
{ {
const Time& runTime = eMesh.mesh.time(); const Time& runTime = eMesh.mesh().time();
const List<faceSets>& boundaryFaceSets = eMesh.boundaryFaceSets; const List<faceSets>& boundaryFaceSets = eMesh.boundaryFaceSets;
const HashTable<labelList>& allPatchNames = eMesh.allPatchNames; const HashTable<labelList>& allPatchNames = eMesh.allPatchNames;
const HashTable<label>& patchIndices = eMesh.patchIndices; const HashTable<label>& patchIndices = eMesh.patchIndices;
const HashTable<ensightMesh::nFacePrims>& nPatchPrims = eMesh.nPatchPrims; const HashTable<ensightMesh::nFacePrimitives>&
nPatchPrims = eMesh.nPatchPrims();
label patchi = -1; label patchi = -1;
@ -521,15 +522,16 @@ void ensightFieldAscii
word timeFile = prepend + itoa(timeIndex); word timeFile = prepend + itoa(timeIndex);
const fvMesh& mesh = eMesh.mesh; const fvMesh& mesh = eMesh.mesh();
const Time& runTime = mesh.time(); const Time& runTime = mesh.time();
const cellSets& meshCellSets = eMesh.meshCellSets; const cellSets& meshCellSets = eMesh.meshCellSets();
const List<faceSets>& boundaryFaceSets = eMesh.boundaryFaceSets; const List<faceSets>& boundaryFaceSets = eMesh.boundaryFaceSets();
const HashTable<labelList>& allPatchNames = eMesh.allPatchNames; const HashTable<labelList>& allPatchNames = eMesh.allPatchNames();
const HashTable<label>& patchIndices = eMesh.patchIndices; const HashTable<label>& patchIndices = eMesh.patchIndices();
const wordHashSet& patchNames = eMesh.patchNames; const wordHashSet& patchNames = eMesh.patchNames();
const HashTable<ensightMesh::nFacePrims>& nPatchPrims = eMesh.nPatchPrims; const HashTable<ensightMesh::nFacePrimitives>&
nPatchPrims = eMesh.nPatchPrims();
const labelList& tets = meshCellSets.tets; const labelList& tets = meshCellSets.tets;
const labelList& pyrs = meshCellSets.pyrs; const labelList& pyrs = meshCellSets.pyrs;
@ -701,15 +703,16 @@ void ensightFieldBinary
word timeFile = prepend + itoa(timeIndex); word timeFile = prepend + itoa(timeIndex);
const fvMesh& mesh = eMesh.mesh; const fvMesh& mesh = eMesh.mesh();
//const Time& runTime = mesh.time(); //const Time& runTime = mesh.time();
const cellSets& meshCellSets = eMesh.meshCellSets; const cellSets& meshCellSets = eMesh.meshCellSets();
const List<faceSets>& boundaryFaceSets = eMesh.boundaryFaceSets; const List<faceSets>& boundaryFaceSets = eMesh.boundaryFaceSets();
const HashTable<labelList>& allPatchNames = eMesh.allPatchNames; const HashTable<labelList>& allPatchNames = eMesh.allPatchNames();
const HashTable<label>& patchIndices = eMesh.patchIndices; const HashTable<label>& patchIndices = eMesh.patchIndices();
const wordHashSet& patchNames = eMesh.patchNames; const wordHashSet& patchNames = eMesh.patchNames();
const HashTable<ensightMesh::nFacePrims>& nPatchPrims = eMesh.nPatchPrims; const HashTable<ensightMesh::nFacePrimitives>&
nPatchPrims = eMesh.nPatchPrims();
const labelList& tets = meshCellSets.tets; const labelList& tets = meshCellSets.tets;
const labelList& pyrs = meshCellSets.pyrs; const labelList& pyrs = meshCellSets.pyrs;

View File

@ -52,12 +52,7 @@ public:
const HashTable<labelList>& y const HashTable<labelList>& y
) const ) const
{ {
for forAllConstIter(HashTable<labelList>, y, iter)
(
HashTable<labelList>::const_iterator iter = y.begin();
iter != y.end();
++iter
)
{ {
HashTable<labelList>::iterator xiter = x.find(iter.key()); HashTable<labelList>::iterator xiter = x.find(iter.key());
@ -89,38 +84,46 @@ public:
Foam::ensightMesh::ensightMesh Foam::ensightMesh::ensightMesh
( (
const fvMesh& fMesh, const fvMesh& mesh,
const argList& args, const argList& args,
const bool binary const bool binary
) )
: :
binary_(binary), binary_(binary),
mesh(fMesh), mesh_(mesh),
meshCellSets(mesh.nCells()), meshCellSets_(mesh_.nCells()),
boundaryFaceSets(mesh.boundary().size()) boundaryFaceSets_(mesh_.boundary().size()),
allPatchNames_(0),
patchIndices_(0),
patchNames_(0),
nPatchPrims_(0)
{ {
forAll (mesh.boundaryMesh(), patchi) forAll (mesh_.boundaryMesh(), patchi)
{ {
if (typeid(mesh.boundaryMesh()[patchi]) != typeid(processorPolyPatch)) if
{
if (!allPatchNames.found(mesh.boundaryMesh()[patchi].name()))
{
allPatchNames.insert
( (
mesh.boundaryMesh()[patchi].name(), typeid(mesh_.boundaryMesh()[patchi])
!= typeid(processorPolyPatch)
)
{
if (!allPatchNames_.found(mesh_.boundaryMesh()[patchi].name()))
{
allPatchNames_.insert
(
mesh_.boundaryMesh()[patchi].name(),
labelList(1, Pstream::myProcNo()) labelList(1, Pstream::myProcNo())
); );
patchIndices.insert patchIndices_.insert
( (
mesh.boundaryMesh()[patchi].name(), mesh_.boundaryMesh()[patchi].name(),
patchi patchi
); );
} }
} }
} }
combineReduce(allPatchNames, concatPatchNames()); combineReduce(allPatchNames_, concatPatchNames());
if (args.options().found("patches")) if (args.options().found("patches"))
{ {
@ -128,12 +131,12 @@ Foam::ensightMesh::ensightMesh
if (!patchNameList.size()) if (!patchNameList.size())
{ {
patchNameList = allPatchNames.toc(); patchNameList = allPatchNames_.toc();
} }
forAll (patchNameList, i) forAll (patchNameList, i)
{ {
patchNames.insert(patchNameList[i]); patchNames_.insert(patchNameList[i]);
} }
} }
@ -145,12 +148,12 @@ Foam::ensightMesh::ensightMesh
const cellModel& wedge = *(cellModeller::lookup("wedge")); const cellModel& wedge = *(cellModeller::lookup("wedge"));
const cellModel& hex = *(cellModeller::lookup("hex")); const cellModel& hex = *(cellModeller::lookup("hex"));
labelList& tets = meshCellSets.tets; labelList& tets = meshCellSets_.tets;
labelList& pyrs = meshCellSets.pyrs; labelList& pyrs = meshCellSets_.pyrs;
labelList& prisms = meshCellSets.prisms; labelList& prisms = meshCellSets_.prisms;
labelList& wedges = meshCellSets.wedges; labelList& wedges = meshCellSets_.wedges;
labelList& hexes = meshCellSets.hexes; labelList& hexes = meshCellSets_.hexes;
labelList& polys = meshCellSets.polys; labelList& polys = meshCellSets_.polys;
// Count the shapes // Count the shapes
label nTets = 0; label nTets = 0;
@ -160,7 +163,7 @@ Foam::ensightMesh::ensightMesh
label nHexes = 0; label nHexes = 0;
label nPolys = 0; label nPolys = 0;
if (!patchNames.size()) if (!patchNames_.size())
{ {
forAll(cellShapes, celli) forAll(cellShapes, celli)
{ {
@ -200,20 +203,20 @@ Foam::ensightMesh::ensightMesh
hexes.setSize(nHexes); hexes.setSize(nHexes);
polys.setSize(nPolys); polys.setSize(nPolys);
meshCellSets.nTets = nTets; meshCellSets_.nTets = nTets;
reduce(meshCellSets.nTets, sumOp<label>()); reduce(meshCellSets_.nTets, sumOp<label>());
meshCellSets.nPyrs = nPyrs; meshCellSets_.nPyrs = nPyrs;
reduce(meshCellSets.nPyrs, sumOp<label>()); reduce(meshCellSets_.nPyrs, sumOp<label>());
meshCellSets.nPrisms = nPrisms; meshCellSets_.nPrisms = nPrisms;
reduce(meshCellSets.nPrisms, sumOp<label>()); reduce(meshCellSets_.nPrisms, sumOp<label>());
meshCellSets.nHexesWedges = nHexes + nWedges; meshCellSets_.nHexesWedges = nHexes + nWedges;
reduce(meshCellSets.nHexesWedges, sumOp<label>()); reduce(meshCellSets_.nHexesWedges, sumOp<label>());
meshCellSets.nPolys = nPolys; meshCellSets_.nPolys = nPolys;
reduce(meshCellSets.nPolys, sumOp<label>()); reduce(meshCellSets_.nPolys, sumOp<label>());
} }
@ -223,9 +226,9 @@ Foam::ensightMesh::ensightMesh
{ {
const polyPatch& p = mesh.boundaryMesh()[patchi]; const polyPatch& p = mesh.boundaryMesh()[patchi];
labelList& tris = boundaryFaceSets[patchi].tris; labelList& tris = boundaryFaceSets_[patchi].tris;
labelList& quads = boundaryFaceSets[patchi].quads; labelList& quads = boundaryFaceSets_[patchi].quads;
labelList& polys = boundaryFaceSets[patchi].polys; labelList& polys = boundaryFaceSets_[patchi].polys;
tris.setSize(p.size()); tris.setSize(p.size());
quads.setSize(p.size()); quads.setSize(p.size());
@ -259,26 +262,21 @@ Foam::ensightMesh::ensightMesh
} }
} }
for forAllConstIter(HashTable<labelList>, allPatchNames_, iter)
(
HashTable<labelList>::const_iterator iter = allPatchNames.begin();
iter != allPatchNames.end();
++iter
)
{ {
const word& patchName = iter.key(); const word& patchName = iter.key();
nFacePrims nfp; nFacePrimitives nfp;
if (!patchNames.size() || patchNames.found(patchName)) if (!patchNames_.size() || patchNames_.found(patchName))
{ {
if (patchIndices.found(patchName)) if (patchIndices_.found(patchName))
{ {
label patchi = patchIndices.find(patchName)(); label patchi = patchIndices_.find(patchName)();
nfp.nPoints = mesh.boundaryMesh()[patchi].localPoints().size(); nfp.nPoints = mesh.boundaryMesh()[patchi].localPoints().size();
nfp.nTris = boundaryFaceSets[patchi].tris.size(); nfp.nTris = boundaryFaceSets_[patchi].tris.size();
nfp.nQuads = boundaryFaceSets[patchi].quads.size(); nfp.nQuads = boundaryFaceSets_[patchi].quads.size();
nfp.nPolys = boundaryFaceSets[patchi].polys.size(); nfp.nPolys = boundaryFaceSets_[patchi].polys.size();
} }
} }
@ -287,7 +285,7 @@ Foam::ensightMesh::ensightMesh
reduce(nfp.nQuads, sumOp<label>()); reduce(nfp.nQuads, sumOp<label>());
reduce(nfp.nPolys, sumOp<label>()); reduce(nfp.nPolys, sumOp<label>());
nPatchPrims.insert(patchName, nfp); nPatchPrims_.insert(patchName, nfp);
} }
} }
@ -308,7 +306,7 @@ void Foam::ensightMesh::writePoints
{ {
forAll(pointsComponent, pointi) forAll(pointsComponent, pointi)
{ {
ensightGeometryFile << setw(12) << float(pointsComponent[pointi]) << nl; ensightGeometryFile<< setw(12) << float(pointsComponent[pointi]) << nl;
} }
} }
@ -408,7 +406,7 @@ void Foam::ensightMesh::writePrimsBinary
if (cellShapes.size() > 0) if (cellShapes.size() > 0)
{ {
// All the cellShapes have the same number of elements! // All the cellShapes have the same number of elements!
int numIntElem = cellShapes.size() * cellShapes[0].size(); int numIntElem = cellShapes.size()*cellShapes[0].size();
List<int> temp(numIntElem); List<int> temp(numIntElem);
int n = 0; int n = 0;
@ -866,11 +864,11 @@ void Foam::ensightMesh::writeAscii
Ostream& ensightCaseFile Ostream& ensightCaseFile
) const ) const
{ {
const Time& runTime = mesh.time(); const Time& runTime = mesh_.time();
const pointField& points = mesh.points(); const pointField& points = mesh_.points();
const cellList& cellFaces = mesh.cells(); const cellList& cellFaces = mesh_.cells();
const faceList& faces = mesh.faces(); const faceList& faces = mesh_.faces();
const cellShapeList& cellShapes = mesh.cellShapes(); const cellShapeList& cellShapes = mesh_.cellShapes();
word timeFile = prepend; word timeFile = prepend;
@ -878,7 +876,7 @@ void Foam::ensightMesh::writeAscii
{ {
timeFile += "000."; timeFile += "000.";
} }
else if (mesh.moving()) else if (mesh_.moving())
{ {
timeFile += itoa(timeIndex) + '.'; timeFile += itoa(timeIndex) + '.';
} }
@ -919,7 +917,7 @@ void Foam::ensightMesh::writeAscii
labelList pointOffsets(Pstream::nProcs(), 0); labelList pointOffsets(Pstream::nProcs(), 0);
if (!patchNames.size()) if (!patchNames_.size())
{ {
label nPoints = points.size(); label nPoints = points.size();
Pstream::gather(nPoints, sumOp<label>()); Pstream::gather(nPoints, sumOp<label>());
@ -962,8 +960,8 @@ void Foam::ensightMesh::writeAscii
writeAllPrims writeAllPrims
( (
"hexa8", "hexa8",
meshCellSets.nHexesWedges, meshCellSets_.nHexesWedges,
map(cellShapes, meshCellSets.hexes, meshCellSets.wedges), map(cellShapes, meshCellSets_.hexes, meshCellSets_.wedges),
pointOffsets, pointOffsets,
ensightGeometryFile ensightGeometryFile
); );
@ -971,8 +969,8 @@ void Foam::ensightMesh::writeAscii
writeAllPrims writeAllPrims
( (
"penta6", "penta6",
meshCellSets.nPrisms, meshCellSets_.nPrisms,
map(cellShapes, meshCellSets.prisms), map(cellShapes, meshCellSets_.prisms),
pointOffsets, pointOffsets,
ensightGeometryFile ensightGeometryFile
); );
@ -980,8 +978,8 @@ void Foam::ensightMesh::writeAscii
writeAllPrims writeAllPrims
( (
"pyramid5", "pyramid5",
meshCellSets.nPyrs, meshCellSets_.nPyrs,
map(cellShapes, meshCellSets.pyrs), map(cellShapes, meshCellSets_.pyrs),
pointOffsets, pointOffsets,
ensightGeometryFile ensightGeometryFile
); );
@ -989,25 +987,25 @@ void Foam::ensightMesh::writeAscii
writeAllPrims writeAllPrims
( (
"tetra4", "tetra4",
meshCellSets.nTets, meshCellSets_.nTets,
map(cellShapes, meshCellSets.tets), map(cellShapes, meshCellSets_.tets),
pointOffsets, pointOffsets,
ensightGeometryFile ensightGeometryFile
); );
if (meshCellSets.nPolys) if (meshCellSets_.nPolys)
{ {
if (Pstream::master()) if (Pstream::master())
{ {
/* /*
ensightGeometryFile ensightGeometryFile
<< "nfaced" << nl << "nfaced" << nl
<< setw(10) << meshCellSets.nPolys << nl; << setw(10) << meshCellSets_.nPolys << nl;
*/ */
writePolys writePolys
( (
meshCellSets.polys, meshCellSets_.polys,
cellFaces, cellFaces,
faces, faces,
0, 0,
@ -1034,7 +1032,7 @@ void Foam::ensightMesh::writeAscii
else else
{ {
OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
toMaster<< meshCellSets.polys << cellFaces << faces; toMaster<< meshCellSets_.polys << cellFaces << faces;
} }
} }
} }
@ -1042,19 +1040,14 @@ void Foam::ensightMesh::writeAscii
label ensightPatchi = 2; label ensightPatchi = 2;
for forAllConstIter(HashTable<labelList>, allPatchNames_, iter)
(
HashTable<labelList>::const_iterator iter = allPatchNames.begin();
iter != allPatchNames.end();
++iter
)
{ {
const labelList& patchProcessors = iter(); const labelList& patchProcessors = iter();
if (!patchNames.size() || patchNames.found(iter.key())) if (!patchNames_.size() || patchNames_.found(iter.key()))
{ {
const word& patchName = iter.key(); const word& patchName = iter.key();
const nFacePrims& nfp = nPatchPrims.find(patchName)(); const nFacePrimitives& nfp = nPatchPrims_.find(patchName)();
const labelList *trisPtr = NULL; const labelList *trisPtr = NULL;
const labelList *quadsPtr = NULL; const labelList *quadsPtr = NULL;
@ -1063,14 +1056,14 @@ void Foam::ensightMesh::writeAscii
const pointField *patchPointsPtr = NULL; const pointField *patchPointsPtr = NULL;
const faceList *patchFacesPtr = NULL; const faceList *patchFacesPtr = NULL;
if (patchIndices.found(iter.key())) if (patchIndices_.found(iter.key()))
{ {
label patchi = patchIndices.find(iter.key())(); label patchi = patchIndices_.find(iter.key())();
const polyPatch& p = mesh.boundaryMesh()[patchi]; const polyPatch& p = mesh_.boundaryMesh()[patchi];
trisPtr = &boundaryFaceSets[patchi].tris; trisPtr = &boundaryFaceSets_[patchi].tris;
quadsPtr = &boundaryFaceSets[patchi].quads; quadsPtr = &boundaryFaceSets_[patchi].quads;
polysPtr = &boundaryFaceSets[patchi].polys; polysPtr = &boundaryFaceSets_[patchi].polys;
patchPointsPtr = &(p.localPoints()); patchPointsPtr = &(p.localPoints());
patchFacesPtr = &(p.localFaces()); patchFacesPtr = &(p.localFaces());
@ -1207,10 +1200,10 @@ void Foam::ensightMesh::writeBinary
) const ) const
{ {
//const Time& runTime = mesh.time(); //const Time& runTime = mesh.time();
const pointField& points = mesh.points(); const pointField& points = mesh_.points();
const cellList& cellFaces = mesh.cells(); const cellList& cellFaces = mesh_.cells();
const faceList& faces = mesh.faces(); const faceList& faces = mesh_.faces();
const cellShapeList& cellShapes = mesh.cellShapes(); const cellShapeList& cellShapes = mesh_.cellShapes();
word timeFile = prepend; word timeFile = prepend;
@ -1218,7 +1211,7 @@ void Foam::ensightMesh::writeBinary
{ {
timeFile += "000."; timeFile += "000.";
} }
else if (mesh.moving()) else if (mesh_.moving())
{ {
timeFile += itoa(timeIndex) + '.'; timeFile += itoa(timeIndex) + '.';
} }
@ -1230,7 +1223,11 @@ void Foam::ensightMesh::writeBinary
if (Pstream::master()) if (Pstream::master())
{ {
ensightGeometryFilePtr = new std::ofstream((postProcPath/ensightGeometryFileName).c_str(), ios_base::out | ios_base::binary | ios_base::trunc); ensightGeometryFilePtr = new std::ofstream
(
(postProcPath/ensightGeometryFileName).c_str(),
ios_base::out | ios_base::binary | ios_base::trunc
);
// Check on file opened? // Check on file opened?
} }
@ -1247,7 +1244,7 @@ void Foam::ensightMesh::writeBinary
labelList pointOffsets(Pstream::nProcs(), 0); labelList pointOffsets(Pstream::nProcs(), 0);
if (!patchNames.size()) if (!patchNames_.size())
{ {
label nPoints = points.size(); label nPoints = points.size();
Pstream::gather(nPoints, sumOp<label>()); Pstream::gather(nPoints, sumOp<label>());
@ -1290,8 +1287,8 @@ void Foam::ensightMesh::writeBinary
writeAllPrimsBinary writeAllPrimsBinary
( (
"hexa8", "hexa8",
meshCellSets.nHexesWedges, meshCellSets_.nHexesWedges,
map(cellShapes, meshCellSets.hexes, meshCellSets.wedges), map(cellShapes, meshCellSets_.hexes, meshCellSets_.wedges),
pointOffsets, pointOffsets,
ensightGeometryFile ensightGeometryFile
); );
@ -1299,8 +1296,8 @@ void Foam::ensightMesh::writeBinary
writeAllPrimsBinary writeAllPrimsBinary
( (
"penta6", "penta6",
meshCellSets.nPrisms, meshCellSets_.nPrisms,
map(cellShapes, meshCellSets.prisms), map(cellShapes, meshCellSets_.prisms),
pointOffsets, pointOffsets,
ensightGeometryFile ensightGeometryFile
); );
@ -1308,8 +1305,8 @@ void Foam::ensightMesh::writeBinary
writeAllPrimsBinary writeAllPrimsBinary
( (
"pyramid5", "pyramid5",
meshCellSets.nPyrs, meshCellSets_.nPyrs,
map(cellShapes, meshCellSets.pyrs), map(cellShapes, meshCellSets_.pyrs),
pointOffsets, pointOffsets,
ensightGeometryFile ensightGeometryFile
); );
@ -1317,24 +1314,24 @@ void Foam::ensightMesh::writeBinary
writeAllPrimsBinary writeAllPrimsBinary
( (
"tetra4", "tetra4",
meshCellSets.nTets, meshCellSets_.nTets,
map(cellShapes, meshCellSets.tets), map(cellShapes, meshCellSets_.tets),
pointOffsets, pointOffsets,
ensightGeometryFile ensightGeometryFile
); );
if (meshCellSets.nPolys) if (meshCellSets_.nPolys)
{ {
if (Pstream::master()) if (Pstream::master())
{ {
/* /*
ensightGeometryFile ensightGeometryFile
<< "nfaced" << nl << "nfaced" << nl
<< setw(10) << meshCellSets.nPolys << nl; << setw(10) << meshCellSets_.nPolys << nl;
*/ */
writePolysBinary writePolysBinary
( (
meshCellSets.polys, meshCellSets_.polys,
cellFaces, cellFaces,
faces, faces,
0, 0,
@ -1361,7 +1358,7 @@ void Foam::ensightMesh::writeBinary
else else
{ {
OPstream toMaster(Pstream::scheduled, Pstream::masterNo()); OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
toMaster<< meshCellSets.polys << cellFaces << faces; toMaster<< meshCellSets_.polys << cellFaces << faces;
} }
} }
@ -1371,20 +1368,15 @@ void Foam::ensightMesh::writeBinary
label iCount = 0; label iCount = 0;
for forAllConstIter(HashTable<labelList>, allPatchNames_, iter)
(
HashTable<labelList>::const_iterator iter = allPatchNames.begin();
iter != allPatchNames.end();
++iter
)
{ {
iCount ++; iCount ++;
const labelList& patchProcessors = iter(); const labelList& patchProcessors = iter();
if (!patchNames.size() || patchNames.found(iter.key())) if (!patchNames_.size() || patchNames_.found(iter.key()))
{ {
const word& patchName = iter.key(); const word& patchName = iter.key();
const nFacePrims& nfp = nPatchPrims.find(patchName)(); const nFacePrimitives& nfp = nPatchPrims_.find(patchName)();
const labelList *trisPtr = NULL; const labelList *trisPtr = NULL;
const labelList *quadsPtr = NULL; const labelList *quadsPtr = NULL;
@ -1393,14 +1385,14 @@ void Foam::ensightMesh::writeBinary
const pointField *patchPointsPtr = NULL; const pointField *patchPointsPtr = NULL;
const faceList *patchFacesPtr = NULL; const faceList *patchFacesPtr = NULL;
if (patchIndices.found(iter.key())) if (patchIndices_.found(iter.key()))
{ {
label patchi = patchIndices.find(iter.key())(); label patchi = patchIndices_.find(iter.key())();
const polyPatch& p = mesh.boundaryMesh()[patchi]; const polyPatch& p = mesh_.boundaryMesh()[patchi];
trisPtr = &boundaryFaceSets[patchi].tris; trisPtr = &boundaryFaceSets_[patchi].tris;
quadsPtr = &boundaryFaceSets[patchi].quads; quadsPtr = &boundaryFaceSets_[patchi].quads;
polysPtr = &boundaryFaceSets[patchi].polys; polysPtr = &boundaryFaceSets_[patchi].polys;
patchPointsPtr = &(p.localPoints()); patchPointsPtr = &(p.localPoints());
patchFacesPtr = &(p.localFaces()); patchFacesPtr = &(p.localFaces());

View File

@ -57,11 +57,48 @@ class argList;
class ensightMesh class ensightMesh
{ {
class nFacePrimitives
{
public:
label nPoints;
label nTris;
label nQuads;
label nPolys;
nFacePrimitives()
:
nPoints(0),
nTris(0),
nQuads(0),
nPolys(0)
{}
};
// Private data // Private data
//- Set binary file output //- Set binary file output
bool binary_; bool binary_;
//- Reference to the OpenFOAM mesh
const fvMesh& mesh_;
cellSets meshCellSets_;
List<faceSets> boundaryFaceSets_;
HashTable<labelList> allPatchNames_;
HashTable<label> patchIndices_;
wordHashSet patchNames_;
HashTable<nFacePrimitives> nPatchPrims_;
// Private Member Functions // Private Member Functions
@ -203,37 +240,6 @@ class ensightMesh
public: public:
// Public data
const fvMesh& mesh;
cellSets meshCellSets;
List<faceSets> boundaryFaceSets;
HashTable<labelList> allPatchNames;
HashTable<label> patchIndices;
wordHashSet patchNames;
class nFacePrims
{
public:
label nPoints;
label nTris;
label nQuads;
label nPolys;
nFacePrims()
:
nPoints(0),
nTris(0),
nQuads(0),
nPolys(0)
{}
};
HashTable<nFacePrims> nPatchPrims;
// Constructors // Constructors
//- Construct from fvMesh //- Construct from fvMesh
@ -247,6 +253,46 @@ public:
// Member Functions // Member Functions
// Access
const fvMesh& mesh() const
{
return mesh_;
}
const cellSets& meshCellSets() const
{
return meshCellSets_;
}
const List<faceSets>& boundaryFaceSets() const
{
return boundaryFaceSets_;
}
const HashTable<labelList>& allPatchNames() const
{
return allPatchNames_;
}
const HashTable<label>& patchIndices() const
{
return patchIndices_;
}
const wordHashSet& patchNames() const
{
return patchNames_;
}
const HashTable<nFacePrimitives>& nPatchPrims() const
{
return nPatchPrims_;
}
// I-O
void write void write
( (
const fileName& postProcPath, const fileName& postProcPath,

View File

@ -41,14 +41,22 @@ void ensightParticlePositions
const Foam::fvMesh& mesh, const Foam::fvMesh& mesh,
const Foam::fileName& postProcPath, const Foam::fileName& postProcPath,
const Foam::word& timeFile, const Foam::word& timeFile,
const Foam::word& sprayName const Foam::word& cloudName,
const bool dataExists
) )
{ {
if (dataExists)
{
Info<< "Converting cloud " << cloudName << " positions" << endl;
}
else
{
Info<< "Creating empty cloud " << cloudName << " positions" << endl;
}
const Time& runTime = mesh.time(); const Time& runTime = mesh.time();
Cloud<passiveParticle> parcels(mesh); fileName ensightFileName(timeFile + "." + cloudName);
fileName ensightFileName(timeFile + "."+ sprayName);
OFstream ensightFile OFstream ensightFile
( (
postProcPath/ensightFileName, postProcPath/ensightFileName,
@ -59,24 +67,23 @@ void ensightParticlePositions
// Output header // Output header
ensightFile ensightFile
<< "lagrangian " << nl << cloudName.c_str() << nl
<< "particle coordinates" << nl; << "particle coordinates" << nl;
if (dataExists)
{
Cloud<passiveParticle> parcels(mesh, cloudName, false);
// Set Format // Set Format
ensightFile.setf(ios_base::scientific, ios_base::floatfield); ensightFile.setf(ios_base::scientific, ios_base::floatfield);
ensightFile.precision(5); ensightFile.precision(5);
ensightFile << setw(8) << parcels.size() << nl; ensightFile<< setw(8) << parcels.size() << nl;
label nParcels = 0; label nParcels = 0;
// Output position // Output positions
for forAllConstIter(Cloud<passiveParticle>, parcels, elmnt)
(
Cloud<passiveParticle>::iterator elmnt = parcels.begin();
elmnt != parcels.end();
++elmnt
)
{ {
const vector& p = elmnt().position(); const vector& p = elmnt().position();
@ -85,6 +92,12 @@ void ensightParticlePositions
<< setw(12) << p.x() << setw(12) << p.y() << setw(12) << p.z() << setw(12) << p.x() << setw(12) << p.y() << setw(12) << p.z()
<< nl; << nl;
} }
}
else
{
label nParcels = 0;
ensightFile<< setw(8) << nParcels << nl;
}
} }

View File

@ -44,7 +44,8 @@ void ensightParticlePositions
const Foam::fvMesh& mesh, const Foam::fvMesh& mesh,
const Foam::fileName& postProcPath, const Foam::fileName& postProcPath,
const Foam::word& timeFile, const Foam::word& timeFile,
const Foam::word& sprayName const Foam::word& CloudName,
const bool dataExists
); );
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -24,22 +24,26 @@ License
Description Description
Translates FOAM data to EnSight format Translates FOAM data to EnSight format
Parallel support for cloud data is not supported
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "argList.H" #include "argList.H"
#include "volFields.H"
#include "tensorIOField.H"
#include "IOobjectList.H" #include "IOobjectList.H"
#include "OFstream.H"
#include "IOmanip.H" #include "IOmanip.H"
#include "OFstream.H"
#include "volFields.H"
#include "labelIOField.H"
#include "scalarIOField.H" #include "scalarIOField.H"
#include "tensorIOField.H"
#include "ensightMesh.H" #include "ensightMesh.H"
#include "ensightField.H" #include "ensightField.H"
#include "ensightParticlePositions.H" #include "ensightParticlePositions.H"
#include "ensightSprayField.H" #include "ensightCloudField.H"
#include "fvc.H" #include "fvc.H"
@ -47,6 +51,24 @@ using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
bool inFileNameList
(
const fileNameList& nameList,
const word& name
)
{
forAll(nameList, i)
{
if (nameList[i] == name)
{
return true;
}
}
return false;
}
// Main program: // Main program:
int main(int argc, char *argv[]) int main(int argc, char *argv[])
@ -55,21 +77,15 @@ int main(int argc, char *argv[])
argList::validOptions.insert("binary", "" ); argList::validOptions.insert("binary", "" );
# include "addTimeOptions.H" # include "addTimeOptions.H"
const label nTypes = 2;
const word fieldTypes[] =
{
volScalarField::typeName,
volVectorField::typeName
};
const label nSprayFieldTypes = 2;
const word sprayFieldTypes[] =
{
scalarIOField::typeName,
vectorIOField::typeName
};
# include "setRootCase.H" # include "setRootCase.H"
// Check options
bool binary = false;
if (args.options().found("binary"))
{
binary = true;
}
# include "createTime.H" # include "createTime.H"
// get the available time-steps // get the available time-steps
@ -79,12 +95,29 @@ int main(int argc, char *argv[])
runTime.setTime(Times[startTime], startTime); runTime.setTime(Times[startTime], startTime);
# include "createMesh.H" # include "createNamedMesh.H"
// Mesh instance (region0 gets filtered out)
fileName regionPrefix = "";
if (regionName != polyMesh::defaultRegion)
{
regionPrefix = regionName;
}
const label nTypes = 2;
const word fieldTypes[] =
{
volScalarField::typeName,
volVectorField::typeName
};
// Create the output folder
const word postProcDir = "EnSight"; const word postProcDir = "EnSight";
const word prepend = args.globalCaseName() + '.';
const word sprayName = "lagrangian";
// Path to EnSight folder at case level only
// - For parallel cases, data only written from master
// fileName postProcPath = runTime.path()/postProcDir;
fileName postProcPath = args.rootPath()/args.globalCaseName()/postProcDir; fileName postProcPath = args.rootPath()/args.globalCaseName()/postProcDir;
if (Pstream::master()) if (Pstream::master())
@ -97,18 +130,14 @@ int main(int argc, char *argv[])
mkDir(postProcPath); mkDir(postProcPath);
} }
// Start of case file header output
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const word prepend = args.globalCaseName() + '.';
OFstream *ensightCaseFilePtr = NULL; OFstream *ensightCaseFilePtr = NULL;
// Check options
bool binary = false;
if (args.options().found("binary"))
{
binary = true;
}
if (Pstream::master()) if (Pstream::master())
{ {
// Open the Case file
fileName ensightCaseFileName = prepend + "case"; fileName ensightCaseFileName = prepend + "case";
if (!binary) if (!binary)
@ -137,49 +166,117 @@ int main(int argc, char *argv[])
OFstream& ensightCaseFile = *ensightCaseFilePtr; OFstream& ensightCaseFile = *ensightCaseFilePtr;
# include "ensightCaseHeader.H"
// Construct the EnSight mesh // Construct the EnSight mesh
ensightMesh eMesh(mesh, args, binary); ensightMesh eMesh(mesh, args, binary);
// Set Time to the last time before looking for the spray objects // Set Time to the last time before looking for the lagrangian objects
runTime.setTime(Times[Times.size()-1], Times.size()-1); runTime.setTime(Times[Times.size()-1], Times.size()-1);
IOobjectList objects(mesh, runTime.timeName()); IOobjectList objects(mesh, runTime.timeName());
IOobjectList sprayObjects(mesh, runTime.timeName(), "lagrangian");
bool lagrangianExist = false;
if (!eMesh.patchNames.size())
{
IOobject lagrangianHeader
(
"positions",
runTime.timeName(),
"lagrangian",
mesh,
IOobject::NO_READ
);
if (lagrangianHeader.headerOk())
{
lagrangianExist = true;
}
}
# include "ensightCaseHeader.H"
# include "checkMeshMoving.H" # include "checkMeshMoving.H"
wordHashSet allCloudNames;
word geomCaseFileName = prepend + "000"; word geomCaseFileName = prepend + "000";
if (Pstream::master()) if (Pstream::master())
{ {
// test pre check variable if there is a moving mesh // test pre check variable if there is a moving mesh
if (meshMoving == true) geomCaseFileName = prepend + "***"; if (meshMoving == true)
{
geomCaseFileName = prepend + "***";
}
ensightCaseFile ensightCaseFile
<< "GEOMETRY" << nl << "GEOMETRY" << nl
<< "model: 1 " << "model: 1 "
<< (geomCaseFileName + ".mesh").c_str() << nl; << (geomCaseFileName + ".mesh").c_str() << nl;
} }
// Identify if lagrangian data exists at each time, and add clouds
// to the 'allCloudNames' hash set
for (label n=startTime; n<endTime; n++)
{
runTime.setTime(Times[n], n);
fileNameList cloudDirs = readDir
(
runTime.timePath()/regionPrefix/"lagrangian",
fileName::DIRECTORY
);
forAll(cloudDirs, cloudI)
{
IOobjectList cloudObjs
(
mesh,
runTime.timeName(),
"lagrangian"/cloudDirs[cloudI]
);
IOobject* positionsPtr = cloudObjs.lookup("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())
{
ensightCaseFile
<< (
"measured: 1 "
+ prepend
+ "***."
+ cloudIter.key()
).c_str()
<< 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
for (label n=startTime; n<endTime; n++)
{
runTime.setTime(Times[n], n);
IOobjectList cloudObjs
(
mesh,
runTime.timeName(),
"lagrangian"/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()
);
}
}
}
}
label nTimeSteps = 0; label nTimeSteps = 0;
for (label n=startTime; n<endTime; n++) for (label n=startTime; n<endTime; n++)
{ {
@ -190,7 +287,7 @@ int main(int argc, char *argv[])
word timeName = itoa(timeIndex); word timeName = itoa(timeIndex);
word timeFile = prepend + timeName; word timeFile = prepend + timeName;
Info << "Translating time = " << runTime.timeName() << nl; Info<< "Translating time = " << runTime.timeName() << nl;
# include "moveMesh.H" # include "moveMesh.H"
@ -205,22 +302,19 @@ int main(int argc, char *argv[])
); );
} }
if (Pstream::master() && timeIndex == 0)
// Start of field data output
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
if (timeIndex == 0 && Pstream::master())
{ {
if (lagrangianExist) ensightCaseFile<< nl << "VARIABLE" << nl;
{
ensightCaseFile
<< (
"measured: 1 "
+ prepend
+ "***."
+ sprayName
).c_str()
<< nl;
}
ensightCaseFile << nl << "VARIABLE" << nl;
} }
// Cell field data output
// ~~~~~~~~~~~~~~~~~~~~~~
for (label i=0; i<nTypes; i++) for (label i=0; i<nTypes; i++)
{ {
wordList fieldNames = objects.names(fieldTypes[i]); wordList fieldNames = objects.names(fieldTypes[i]);
@ -313,70 +407,75 @@ int main(int argc, char *argv[])
} }
} }
if (lagrangianExist)
// Cloud field data output
// ~~~~~~~~~~~~~~~~~~~~~~~
forAllConstIter(HashTable<HashTable<word> >, allCloudFields, cloudIter)
{ {
const word& cloudName = cloudIter.key();
fileNameList currentCloudDirs = readDir
(
runTime.timePath()/regionPrefix/"lagrangian",
fileName::DIRECTORY
);
bool cloudExists = inFileNameList(currentCloudDirs, cloudName);
ensightParticlePositions ensightParticlePositions
( (
mesh, mesh,
postProcPath, postProcPath,
timeFile, timeFile,
sprayName cloudName,
cloudExists
); );
for (label i=0; i<nSprayFieldTypes; i++) forAllConstIter(HashTable<word>, cloudIter(), fieldIter)
{ {
wordList fieldNames = sprayObjects.names(sprayFieldTypes[i]); const word& fieldName = fieldIter.key();
const word& fieldType = fieldIter();
for (label j=0; j<fieldNames.size(); j++)
{
word fieldName = fieldNames[j];
IOobject fieldObject IOobject fieldObject
( (
fieldName, fieldName,
mesh.time().timeName(), mesh.time().timeName(),
"lagrangian", "lagrangian"/cloudName,
mesh, mesh,
IOobject::MUST_READ, IOobject::MUST_READ
IOobject::NO_WRITE
); );
if (sprayFieldTypes[i] == scalarIOField::typeName) bool fieldExists = fieldObject.headerOk();
if (fieldType == scalarIOField::typeName)
{ {
ensightSprayField<scalar> ensightCloudField<scalar>
( (
fieldObject, fieldObject,
postProcPath, postProcPath,
prepend, prepend,
timeIndex, timeIndex,
sprayName, cloudName,
ensightCaseFile ensightCaseFile,
fieldExists
); );
} }
else if (sprayFieldTypes[i] == vectorIOField::typeName) else if (fieldType == vectorIOField::typeName)
{ {
ensightSprayField<vector> ensightCloudField<vector>
( (
fieldObject, fieldObject,
postProcPath, postProcPath,
prepend, prepend,
timeIndex, timeIndex,
sprayName, cloudName,
ensightCaseFile ensightCaseFile,
fieldExists
); );
} }
else if (sprayFieldTypes[i] == tensorIOField::typeName) else
{ {
ensightSprayField<tensor> Info<< "Unable to convert field type " << fieldType
( << " for field " << fieldName << endl;
fieldObject,
postProcPath,
prepend,
timeIndex,
sprayName,
ensightCaseFile
);
}
} }
} }
} }