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) 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()) if (Pstream::master())
{ {
ensightFile << key << nl; 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++) for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{ {
writeData(map(vf, prims, cmpt), ensightFile); writeData(map(vf, prims, cmpt), ensightFile);
for (int slave=1; slave<Pstream::nProcs(); slave++) for (int slave=1; slave<Pstream::nProcs(); slave++)
{ {
scalarField data(fromSlaves[slave]); IPstream fromSlave(Pstream::scheduled, slave);
scalarField data(fromSlave);
writeData(data, ensightFile); 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) 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()) if (Pstream::master())
{ {
writeEnsDataBinary(key,ensightFile); 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++) for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{ {
writeEnsDataBinary(map(vf, prims, cmpt), ensightFile); writeEnsDataBinary(map(vf, prims, cmpt), ensightFile);
for (int slave=1; slave<Pstream::nProcs(); slave++) for (int slave=1; slave<Pstream::nProcs(); slave++)
{ {
scalarField data(fromSlaves[slave]); IPstream fromSlave(Pstream::scheduled, slave);
scalarField data(fromSlave);
writeEnsDataBinary(data, ensightFile); 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) 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()) if (Pstream::master())
{ {
ensightFile << key << nl; 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++) for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{ {
writeData(map(pf, prims, cmpt), ensightFile); writeData(map(pf, prims, cmpt), ensightFile);
for (int slave=1; slave<Pstream::nProcs(); slave++) for (int slave=1; slave<Pstream::nProcs(); slave++)
{ {
scalarField pf(fromSlaves[slave]); IPstream fromSlave(Pstream::scheduled, slave);
scalarField pf(fromSlave);
writeData(pf, ensightFile); 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) 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()) if (Pstream::master())
{ {
writeEnsDataBinary(key,ensightFile); 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++) for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{ {
writeEnsDataBinary(map(pf, prims, cmpt), ensightFile); writeEnsDataBinary(map(pf, prims, cmpt), ensightFile);
for (int slave=1; slave<Pstream::nProcs(); slave++) for (int slave=1; slave<Pstream::nProcs(); slave++)
{ {
scalarField pf(fromSlaves[slave]); IPstream fromSlave(Pstream::scheduled, slave);
scalarField pf(fromSlave);
writeEnsDataBinary(pf, ensightFile); 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 wordHashSet& patchNames = eMesh.patchNames();
const HashTable<ensightMesh::nFacePrimitives>& const HashTable<ensightMesh::nFacePrimitives>&
nPatchPrims = eMesh.nPatchPrims(); 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& tets = meshCellSets.tets;
const labelList& pyrs = meshCellSets.pyrs; const labelList& pyrs = meshCellSets.pyrs;
@ -557,7 +523,7 @@ void ensightFieldAscii
postProcPath/ensightFileName, postProcPath/ensightFileName,
runTime.writeFormat(), runTime.writeFormat(),
runTime.writeVersion(), runTime.writeVersion(),
runTime.writeCompression() IOstream::UNCOMPRESSED
); );
} }
@ -567,6 +533,8 @@ void ensightFieldAscii
if (patchNames.empty()) if (patchNames.empty())
{ {
eMesh.barrier();
if (Pstream::master()) if (Pstream::master())
{ {
if (timeIndex == 0) if (timeIndex == 0)
@ -592,29 +560,10 @@ void ensightFieldAscii
if (meshCellSets.nHexesWedges) 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()) if (Pstream::master())
{ {
ensightFile << "hexa8" << nl; 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++) for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{ {
writeData writeData
@ -625,17 +574,57 @@ void ensightFieldAscii
for (int slave=1; slave<Pstream::nProcs(); slave++) for (int slave=1; slave<Pstream::nProcs(); slave++)
{ {
scalarField data(fromSlaves[slave]); IPstream fromSlave(Pstream::scheduled, slave);
scalarField data(fromSlave);
writeData(data, ensightFile); 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
writeAllData("pyramid5", vf, pyrs, meshCellSets.nPyrs, ensightFile); (
writeAllData("tetra4", vf, tets, meshCellSets.nTets, ensightFile); "penta6",
writeAllData("nfaced", vf, polys, meshCellSets.nPolys, ensightFile); 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(); label ensightPatchI = eMesh.patchPartOffset();
@ -644,6 +633,8 @@ void ensightFieldAscii
{ {
const word& patchName = allPatchNames[patchi]; const word& patchName = allPatchNames[patchi];
eMesh.barrier();
if (patchNames.empty() || patchNames.found(patchName)) if (patchNames.empty() || patchNames.found(patchName))
{ {
if 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()) if (Pstream::master())
{ {
delete ensightFilePtr; delete ensightFilePtr;
@ -695,6 +760,10 @@ void ensightFieldBinary
const wordHashSet& patchNames = eMesh.patchNames(); const wordHashSet& patchNames = eMesh.patchNames();
const HashTable<ensightMesh::nFacePrimitives>& const HashTable<ensightMesh::nFacePrimitives>&
nPatchPrims = eMesh.nPatchPrims(); 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& tets = meshCellSets.tets;
const labelList& pyrs = meshCellSets.pyrs; const labelList& pyrs = meshCellSets.pyrs;
@ -722,6 +791,8 @@ void ensightFieldBinary
if (patchNames.empty()) if (patchNames.empty())
{ {
eMesh.barrier();
if (Pstream::master()) if (Pstream::master())
{ {
if (timeIndex == 0) if (timeIndex == 0)
@ -743,29 +814,10 @@ void ensightFieldBinary
if (meshCellSets.nHexesWedges) 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()) if (Pstream::master())
{ {
writeEnsDataBinary("hexa8",ensightFile); 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++) for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
{ {
writeEnsDataBinary writeEnsDataBinary
@ -776,11 +828,20 @@ void ensightFieldBinary
for (int slave=1; slave<Pstream::nProcs(); slave++) for (int slave=1; slave<Pstream::nProcs(); slave++)
{ {
scalarField data(fromSlaves[slave]); IPstream fromSlave(Pstream::scheduled, slave);
scalarField data(fromSlave);
writeEnsDataBinary(data, ensightFile); 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 writeAllDataBinary
@ -826,6 +887,8 @@ void ensightFieldBinary
{ {
const word& patchName = allPatchNames[patchi]; const word& patchName = allPatchNames[patchi];
eMesh.barrier();
if (patchNames.empty() || patchNames.found(patchName)) if (patchNames.empty() || patchNames.found(patchName))
{ {
if if
@ -844,6 +907,81 @@ void ensightFieldBinary
ensightPatchI++; 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()) if (Pstream::master())

View File

@ -42,7 +42,7 @@ SourceFiles
#include "fvMesh.H" #include "fvMesh.H"
#include "OFstream.H" #include "OFstream.H"
#include <fstream> #include <fstream>
#include "globalIndex.H" #include "PackedBoolList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -51,6 +51,7 @@ namespace Foam
class fvMesh; class fvMesh;
class argList; class argList;
class globalIndex;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class ensightMesh Declaration Class ensightMesh Declaration
@ -98,6 +99,16 @@ private:
HashTable<nFacePrimitives> nPatchPrims_; 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 // Private Member Functions
@ -206,6 +217,38 @@ private:
OFstream& ensightGeometryFile OFstream& ensightGeometryFile
) const; ) 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 void writeAscii
( (
const fileName& postProcPath, const fileName& postProcPath,
@ -311,7 +354,12 @@ public:
// Constructors // Constructors
//- Construct from fvMesh //- Construct from fvMesh
ensightMesh(const fvMesh&, const argList& args, const bool binary); ensightMesh
(
const fvMesh&,
const argList& args,
const bool binary
);
//- Destructor //- Destructor
@ -352,12 +400,36 @@ public:
return nPatchPrims_; 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 //- The ensight part id for the first patch
label patchPartOffset() const label patchPartOffset() const
{ {
return patchPartOffset_; 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 // I-O
@ -368,6 +440,7 @@ public:
const label timeIndex, const label timeIndex,
Ostream& ensightCaseFile Ostream& ensightCaseFile
) const; ) const;
}; };

View File

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