ENH: Added faceZones support. Reverted back to using scheduled comms

(less memory)
This commit is contained in:
mattijs
2010-03-04 13:47:09 +00:00
parent 1a87cd16fb
commit edeb20c856
4 changed files with 1157 additions and 649 deletions

View File

@ -110,40 +110,30 @@ void writeAllData
{
if (nPrims)
{
PstreamBuffers pBufs(Pstream::nonBlocking);
if (!Pstream::master())
{
UOPstream toMaster(Pstream::masterNo(), pBufs);
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{
toMaster<< map(vf, prims, cmpt);
}
}
pBufs.finishedSends();
if (Pstream::master())
{
ensightFile << key << nl;
PtrList<UIPstream> fromSlaves(Pstream::nProcs());
for (int slave=1; slave<Pstream::nProcs(); slave++)
{
fromSlaves.set(slave, new UIPstream(slave, pBufs));
}
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{
writeData(map(vf, prims, cmpt), ensightFile);
for (int slave=1; slave<Pstream::nProcs(); slave++)
{
scalarField data(fromSlaves[slave]);
IPstream fromSlave(Pstream::scheduled, slave);
scalarField data(fromSlave);
writeData(data, ensightFile);
}
}
}
else
{
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{
OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
toMaster<< map(vf, prims, cmpt);
}
}
}
}
@ -160,40 +150,30 @@ void writeAllDataBinary
{
if (nPrims)
{
PstreamBuffers pBufs(Pstream::nonBlocking);
if (!Pstream::master())
{
UOPstream toMaster(Pstream::masterNo(), pBufs);
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{
toMaster<< map(vf, prims, cmpt);
}
}
pBufs.finishedSends();
if (Pstream::master())
{
writeEnsDataBinary(key,ensightFile);
PtrList<UIPstream> fromSlaves(Pstream::nProcs());
for (int slave=1; slave<Pstream::nProcs(); slave++)
{
fromSlaves.set(slave, new UIPstream(slave, pBufs));
}
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{
writeEnsDataBinary(map(vf, prims, cmpt), ensightFile);
for (int slave=1; slave<Pstream::nProcs(); slave++)
{
scalarField data(fromSlaves[slave]);
IPstream fromSlave(Pstream::scheduled, slave);
scalarField data(fromSlave);
writeEnsDataBinary(data, ensightFile);
}
}
}
else
{
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{
OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
toMaster<< map(vf, prims, cmpt);
}
}
}
}
@ -210,40 +190,31 @@ void writeAllFaceData
{
if (nPrims)
{
PstreamBuffers pBufs(Pstream::nonBlocking);
if (!Pstream::master())
{
UOPstream toMaster(Pstream::masterNo(), pBufs);
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{
toMaster<< map(pf, prims, cmpt);
}
}
pBufs.finishedSends();
if (Pstream::master())
{
ensightFile << key << nl;
PtrList<UIPstream> fromSlaves(Pstream::nProcs());
for (int slave=1; slave<Pstream::nProcs(); slave++)
{
fromSlaves.set(slave, new UIPstream(slave, pBufs));
}
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{
writeData(map(pf, prims, cmpt), ensightFile);
for (int slave=1; slave<Pstream::nProcs(); slave++)
{
scalarField pf(fromSlaves[slave]);
IPstream fromSlave(Pstream::scheduled, slave);
scalarField pf(fromSlave);
writeData(pf, ensightFile);
}
}
}
else
{
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{
OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
toMaster<< map(pf, prims, cmpt);
}
}
}
}
@ -260,40 +231,31 @@ void writeAllFaceDataBinary
{
if (nPrims)
{
PstreamBuffers pBufs(Pstream::nonBlocking);
if (!Pstream::master())
{
UOPstream toMaster(Pstream::masterNo(), pBufs);
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{
toMaster<< map(pf, prims, cmpt);
}
}
pBufs.finishedSends();
if (Pstream::master())
{
writeEnsDataBinary(key,ensightFile);
PtrList<UIPstream> fromSlaves(Pstream::nProcs());
for (int slave=1; slave<Pstream::nProcs(); slave++)
{
fromSlaves.set(slave, new UIPstream(slave, pBufs));
}
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{
writeEnsDataBinary(map(pf, prims, cmpt), ensightFile);
for (int slave=1; slave<Pstream::nProcs(); slave++)
{
scalarField pf(fromSlaves[slave]);
IPstream fromSlave(Pstream::scheduled, slave);
scalarField pf(fromSlave);
writeEnsDataBinary(pf, ensightFile);
}
}
}
else
{
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{
OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
toMaster<< map(pf, prims, cmpt);
}
}
}
}
@ -539,6 +501,10 @@ void ensightFieldAscii
const wordHashSet& patchNames = eMesh.patchNames();
const HashTable<ensightMesh::nFacePrimitives>&
nPatchPrims = eMesh.nPatchPrims();
const List<faceSets>& faceZoneFaceSets = eMesh.faceZoneFaceSets();
const wordHashSet& faceZoneNames = eMesh.faceZoneNames();
const HashTable<ensightMesh::nFacePrimitives>&
nFaceZonePrims = eMesh.nFaceZonePrims();
const labelList& tets = meshCellSets.tets;
const labelList& pyrs = meshCellSets.pyrs;
@ -557,7 +523,7 @@ void ensightFieldAscii
postProcPath/ensightFileName,
runTime.writeFormat(),
runTime.writeVersion(),
runTime.writeCompression()
IOstream::UNCOMPRESSED
);
}
@ -567,6 +533,8 @@ void ensightFieldAscii
if (patchNames.empty())
{
eMesh.barrier();
if (Pstream::master())
{
if (timeIndex == 0)
@ -592,29 +560,10 @@ void ensightFieldAscii
if (meshCellSets.nHexesWedges)
{
PstreamBuffers pBufs(Pstream::nonBlocking);
if (!Pstream::master())
{
UOPstream toMaster(Pstream::masterNo(), pBufs);
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{
toMaster<< map(vf, hexes, wedges, cmpt);
}
}
pBufs.finishedSends();
if (Pstream::master())
{
ensightFile << "hexa8" << nl;
PtrList<UIPstream> fromSlaves(Pstream::nProcs());
for (int slave=1; slave<Pstream::nProcs(); slave++)
{
fromSlaves.set(slave, new UIPstream(slave, pBufs));
}
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{
writeData
@ -625,17 +574,57 @@ void ensightFieldAscii
for (int slave=1; slave<Pstream::nProcs(); slave++)
{
scalarField data(fromSlaves[slave]);
IPstream fromSlave(Pstream::scheduled, slave);
scalarField data(fromSlave);
writeData(data, ensightFile);
}
}
}
else
{
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{
OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
toMaster<< map(vf, hexes, wedges, cmpt);
}
}
}
writeAllData("penta6", vf, prisms, meshCellSets.nPrisms, ensightFile);
writeAllData("pyramid5", vf, pyrs, meshCellSets.nPyrs, ensightFile);
writeAllData("tetra4", vf, tets, meshCellSets.nTets, ensightFile);
writeAllData("nfaced", vf, polys, meshCellSets.nPolys, ensightFile);
writeAllData
(
"penta6",
vf,
prisms,
meshCellSets.nPrisms,
ensightFile
);
writeAllData
(
"pyramid5",
vf,
pyrs,
meshCellSets.nPyrs,
ensightFile
);
writeAllData
(
"tetra4",
vf,
tets,
meshCellSets.nTets,
ensightFile
);
writeAllData
(
"nfaced",
vf,
polys,
meshCellSets.nPolys,
ensightFile
);
}
label ensightPatchI = eMesh.patchPartOffset();
@ -644,6 +633,8 @@ void ensightFieldAscii
{
const word& patchName = allPatchNames[patchi];
eMesh.barrier();
if (patchNames.empty() || patchNames.found(patchName))
{
if
@ -664,6 +655,80 @@ void ensightFieldAscii
}
}
// write faceZones, if requested
if (faceZoneNames.size())
{
// Interpolates cell values to faces - needed only when exporting
// faceZones...
GeometricField<Type, fvsPatchField, surfaceMesh> sf
(
linearInterpolate(vf)
);
forAllConstIter(wordHashSet, faceZoneNames, iter)
{
const word& faceZoneName = iter.key();
eMesh.barrier();
label zoneID = mesh.faceZones().findZoneID(faceZoneName);
const faceZone& fz = mesh.faceZones()[zoneID];
// Prepare data to write
label nIncluded = 0;
forAll(fz, i)
{
if (eMesh.faceToBeIncluded(fz[i]))
{
++nIncluded;
}
}
Field<Type> values(nIncluded);
// Loop on the faceZone and store the needed field values
label j = 0;
forAll(fz, i)
{
label faceI = fz[i];
if (mesh.isInternalFace(faceI))
{
values[j] = sf[faceI];
++j;
}
else
{
if (eMesh.faceToBeIncluded(faceI))
{
label patchI = mesh.boundaryMesh().whichPatch(faceI);
const polyPatch& pp = mesh.boundaryMesh()[patchI];
label patchFaceI = pp.whichFace(faceI);
Type value = sf.boundaryField()[patchI][patchFaceI];
values[j] = value;
++j;
}
}
}
if
(
writePatchField
(
values,
zoneID,
ensightPatchI,
faceZoneFaceSets[zoneID],
nFaceZonePrims.find(faceZoneName)(),
ensightFile
)
)
{
ensightPatchI++;
}
}
}
if (Pstream::master())
{
delete ensightFilePtr;
@ -695,6 +760,10 @@ void ensightFieldBinary
const wordHashSet& patchNames = eMesh.patchNames();
const HashTable<ensightMesh::nFacePrimitives>&
nPatchPrims = eMesh.nPatchPrims();
const List<faceSets>& faceZoneFaceSets = eMesh.faceZoneFaceSets();
const wordHashSet& faceZoneNames = eMesh.faceZoneNames();
const HashTable<ensightMesh::nFacePrimitives>&
nFaceZonePrims = eMesh.nFaceZonePrims();
const labelList& tets = meshCellSets.tets;
const labelList& pyrs = meshCellSets.pyrs;
@ -722,6 +791,8 @@ void ensightFieldBinary
if (patchNames.empty())
{
eMesh.barrier();
if (Pstream::master())
{
if (timeIndex == 0)
@ -743,29 +814,10 @@ void ensightFieldBinary
if (meshCellSets.nHexesWedges)
{
PstreamBuffers pBufs(Pstream::nonBlocking);
if (!Pstream::master())
{
UOPstream toMaster(Pstream::masterNo(), pBufs);
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{
toMaster<< map(vf, hexes, wedges, cmpt);
}
}
pBufs.finishedSends();
if (Pstream::master())
{
writeEnsDataBinary("hexa8",ensightFile);
PtrList<UIPstream> fromSlaves(Pstream::nProcs());
for (int slave=1; slave<Pstream::nProcs(); slave++)
{
fromSlaves.set(slave, new UIPstream(slave, pBufs));
}
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{
writeEnsDataBinary
@ -776,11 +828,20 @@ void ensightFieldBinary
for (int slave=1; slave<Pstream::nProcs(); slave++)
{
scalarField data(fromSlaves[slave]);
IPstream fromSlave(Pstream::scheduled, slave);
scalarField data(fromSlave);
writeEnsDataBinary(data, ensightFile);
}
}
}
else
{
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{
OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
toMaster<< map(vf, hexes, wedges, cmpt);
}
}
}
writeAllDataBinary
@ -826,6 +887,8 @@ void ensightFieldBinary
{
const word& patchName = allPatchNames[patchi];
eMesh.barrier();
if (patchNames.empty() || patchNames.found(patchName))
{
if
@ -844,6 +907,81 @@ void ensightFieldBinary
ensightPatchI++;
}
}
}
// write faceZones, if requested
if (faceZoneNames.size())
{
// Interpolates cell values to faces - needed only when exporting
// faceZones...
GeometricField<Type, fvsPatchField, surfaceMesh> sf
(
linearInterpolate(vf)
);
forAllConstIter(wordHashSet, faceZoneNames, iter)
{
const word& faceZoneName = iter.key();
eMesh.barrier();
label zoneID = mesh.faceZones().findZoneID(faceZoneName);
const faceZone& fz = mesh.faceZones()[zoneID];
// Prepare data to write
label nIncluded = 0;
forAll(fz, i)
{
if (eMesh.faceToBeIncluded(fz[i]))
{
++nIncluded;
}
}
Field<Type> values(nIncluded);
// Loop on the faceZone and store the needed field values
label j = 0;
forAll(fz, i)
{
label faceI = fz[i];
if (mesh.isInternalFace(faceI))
{
values[j] = sf[faceI];
++j;
}
else
{
if (eMesh.faceToBeIncluded(faceI))
{
label patchI = mesh.boundaryMesh().whichPatch(faceI);
const polyPatch& pp = mesh.boundaryMesh()[patchI];
label patchFaceI = pp.whichFace(faceI);
Type value = sf.boundaryField()[patchI][patchFaceI];
values[j] = value;
++j;
}
}
}
if
(
writePatchFieldBinary
(
values,
zoneID,
ensightPatchI,
faceZoneFaceSets[zoneID],
nFaceZonePrims.find(faceZoneName)(),
ensightFile
)
)
{
ensightPatchI++;
}
}
}
if (Pstream::master())

View File

@ -42,7 +42,7 @@ SourceFiles
#include "fvMesh.H"
#include "OFstream.H"
#include <fstream>
#include "globalIndex.H"
#include "PackedBoolList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -51,6 +51,7 @@ namespace Foam
class fvMesh;
class argList;
class globalIndex;
/*---------------------------------------------------------------------------*\
Class ensightMesh Declaration
@ -98,6 +99,16 @@ private:
HashTable<nFacePrimitives> nPatchPrims_;
// faceZone - related variables
List<faceSets> faceZoneFaceSets_;
wordHashSet faceZoneNames_;
HashTable<nFacePrimitives> nFaceZonePrims_;
//- Per boundary face whether to include or not
PackedBoolList boundaryFaceToBeIncluded_;
// Private Member Functions
@ -206,6 +217,38 @@ private:
OFstream& ensightGeometryFile
) const;
void writeAllInternalPoints
(
const pointField& uniquePoints,
const label nPoints,
OFstream& ensightGeometryFile
) const;
void writeAllPatchPoints
(
label ensightPatchI,
const word& patchName,
const pointField& uniquePoints,
const label nPoints,
OFstream& ensightGeometryFile
) const;
void writeAllInternalPointsBinary
(
const pointField& uniquePoints,
const label nPoints,
std::ofstream& ensightGeometryFile
) const;
void writeAllPatchPointsBinary
(
label ensightPatchI,
const word& patchName,
const pointField& uniquePoints,
const label nPoints,
std::ofstream& ensightGeometryFile
) const;
void writeAscii
(
const fileName& postProcPath,
@ -311,7 +354,12 @@ public:
// Constructors
//- Construct from fvMesh
ensightMesh(const fvMesh&, const argList& args, const bool binary);
ensightMesh
(
const fvMesh&,
const argList& args,
const bool binary
);
//- Destructor
@ -352,12 +400,36 @@ public:
return nPatchPrims_;
}
const List<faceSets>& faceZoneFaceSets() const
{
return faceZoneFaceSets_;
}
const wordHashSet& faceZoneNames() const
{
return faceZoneNames_;
}
const HashTable<nFacePrimitives>& nFaceZonePrims() const
{
return nFaceZonePrims_;
}
//- The ensight part id for the first patch
label patchPartOffset() const
{
return patchPartOffset_;
}
// Other
//- When exporting faceZones, check if a given face has to be included
// or not (i.e. faces on processor boundaries)
bool faceToBeIncluded(const label faceI) const;
//- Helper to cause barrier. Necessary on Quadrics.
static void barrier();
// I-O
@ -368,6 +440,7 @@ public:
const label timeIndex,
Ostream& ensightCaseFile
) const;
};

View File

@ -41,6 +41,9 @@ Usage
@param -noPatches \n
Suppress writing any patches.
@param -faceZones zoneList \n
Specify faceZones to write, with wildcards
Note
Parallel support for cloud data is not supported
- writes to @a EnSight directory to avoid collisions with foamToEnsightParts
@ -113,6 +116,12 @@ int main(int argc, char *argv[])
"specify particular patches to write - eg '(inlet outlet)'. "
"An empty list suppresses writing the internalMesh."
);
argList::addOption
(
"faceZones",
"wordList",
"specify faceZones to write, with wildcards - eg '(mfp-.*)'. "
);
# include "setRootCase.H"