Commit edeb20c8 authored by mattijs's avatar mattijs
Browse files

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

(less memory)
parent 1a87cd16
......@@ -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())
......
......@@ -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;