diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightField.C b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightField.C index 1204ac5976..e446dcac89 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightField.C +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightField.C @@ -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::nComponents; cmpt++) - { - toMaster<< map(vf, prims, cmpt); - } - } - - pBufs.finishedSends(); - if (Pstream::master()) { ensightFile << key << nl; - PtrList fromSlaves(Pstream::nProcs()); - for (int slave=1; slave::nComponents; cmpt++) { writeData(map(vf, prims, cmpt), ensightFile); for (int slave=1; slave::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::nComponents; cmpt++) - { - toMaster<< map(vf, prims, cmpt); - } - } - - pBufs.finishedSends(); - if (Pstream::master()) { writeEnsDataBinary(key,ensightFile); - PtrList fromSlaves(Pstream::nProcs()); - for (int slave=1; slave::nComponents; cmpt++) { writeEnsDataBinary(map(vf, prims, cmpt), ensightFile); for (int slave=1; slave::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::nComponents; cmpt++) - { - toMaster<< map(pf, prims, cmpt); - } - } - - pBufs.finishedSends(); - if (Pstream::master()) { ensightFile << key << nl; - PtrList fromSlaves(Pstream::nProcs()); - for (int slave=1; slave::nComponents; cmpt++) { writeData(map(pf, prims, cmpt), ensightFile); for (int slave=1; slave::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::nComponents; cmpt++) - { - toMaster<< map(pf, prims, cmpt); - } - } - - pBufs.finishedSends(); - if (Pstream::master()) { writeEnsDataBinary(key,ensightFile); - PtrList fromSlaves(Pstream::nProcs()); - for (int slave=1; slave::nComponents; cmpt++) { writeEnsDataBinary(map(pf, prims, cmpt), ensightFile); for (int slave=1; slave::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& nPatchPrims = eMesh.nPatchPrims(); + const List& faceZoneFaceSets = eMesh.faceZoneFaceSets(); + const wordHashSet& faceZoneNames = eMesh.faceZoneNames(); + const HashTable& + 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::nComponents; cmpt++) - { - toMaster<< map(vf, hexes, wedges, cmpt); - } - } - - pBufs.finishedSends(); - if (Pstream::master()) { ensightFile << "hexa8" << nl; - PtrList fromSlaves(Pstream::nProcs()); - for (int slave=1; slave::nComponents; cmpt++) { writeData @@ -625,17 +574,57 @@ void ensightFieldAscii for (int slave=1; slave::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 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 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& nPatchPrims = eMesh.nPatchPrims(); + const List& faceZoneFaceSets = eMesh.faceZoneFaceSets(); + const wordHashSet& faceZoneNames = eMesh.faceZoneNames(); + const HashTable& + 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::nComponents; cmpt++) - { - toMaster<< map(vf, hexes, wedges, cmpt); - } - } - - pBufs.finishedSends(); - if (Pstream::master()) { writeEnsDataBinary("hexa8",ensightFile); - PtrList fromSlaves(Pstream::nProcs()); - for (int slave=1; slave::nComponents; cmpt++) { writeEnsDataBinary @@ -776,11 +828,20 @@ void ensightFieldBinary for (int slave=1; slave::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 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 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()) diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightMesh.C b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightMesh.C index 5f848736be..daece0473b 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightMesh.C +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightMesh.C @@ -30,11 +30,14 @@ License #include "fvMesh.H" #include "globalMeshData.H" #include "PstreamCombineReduceOps.H" +#include "processorPolyPatch.H" #include "cellModeller.H" #include "IOmanip.H" #include "itoa.H" #include "ensightWriteBinary.H" +#include "globalIndex.H" #include "mapDistribute.H" +#include "stringListOps.H" #include @@ -56,7 +59,11 @@ Foam::ensightMesh::ensightMesh boundaryFaceSets_(mesh_.boundary().size()), allPatchNames_(0), patchNames_(0), - nPatchPrims_(0) + nPatchPrims_(0), + faceZoneFaceSets_(mesh_.faceZones().size()), + faceZoneNames_(0), + nFaceZonePrims_(0), + boundaryFaceToBeIncluded_(0) { const cellShapeList& cellShapes = mesh.cellShapes(); @@ -80,10 +87,7 @@ Foam::ensightMesh::ensightMesh if (args.optionFound("patches")) { - wordList patchNameList - ( - args.optionLookup("patches")() - ); + wordList patchNameList(args.optionLookup("patches")()); if (patchNameList.empty()) { @@ -218,7 +222,6 @@ Foam::ensightMesh::ensightMesh } } - forAll(allPatchNames_, patchi) { const word& patchName = allPatchNames_[patchi]; @@ -240,6 +243,133 @@ Foam::ensightMesh::ensightMesh nPatchPrims_.insert(patchName, nfp); } + + // faceZones + if (args.optionFound("faceZones")) + { + wordList patchNameList(args.optionLookup("faceZones")()); + + const wordList faceZoneNamesAll = mesh_.faceZones().names(); + + // Find out faceZone names that match with what requested at command + // line + forAll(patchNameList, i) + { + labelList matches = findStrings(patchNameList[i], faceZoneNamesAll); + + forAll(matches, matchI) + { + faceZoneNames_.insert(faceZoneNamesAll[matches[matchI]]); + } + } + + // Build list of boundary faces to be exported + boundaryFaceToBeIncluded_.setSize + ( + mesh_.nFaces() + - mesh_.nInternalFaces(), + 1 + ); + + forAll(mesh_.boundaryMesh(), patchI) + { + const polyPatch& pp = mesh_.boundaryMesh()[patchI]; + if + ( + isA(pp) + && !refCast(pp).owner() + ) + { + label bFaceI = pp.start()-mesh_.nInternalFaces(); + forAll(pp, i) + { + boundaryFaceToBeIncluded_[bFaceI++] = 0; + } + } + } + + // Count face types in each faceZone + forAll(faceZoneNamesAll, zoneI) + { + //const word& zoneName = faceZoneNamesAll[zoneI]; + + const faceZone& fz = mesh.faceZones()[zoneI]; + + if (fz.size()) + { + labelList& tris = faceZoneFaceSets_[zoneI].tris; + labelList& quads = faceZoneFaceSets_[zoneI].quads; + labelList& polys = faceZoneFaceSets_[zoneI].polys; + + tris.setSize(fz.size()); + quads.setSize(fz.size()); + polys.setSize(fz.size()); + + label nTris = 0; + label nQuads = 0; + label nPolys = 0; + + label faceCounter = 0; + + forAll(fz, i) + { + label faceI = fz[i]; + + // Avoid counting faces on processor boundaries twice + if (faceToBeIncluded(faceI)) + { + const face& f = mesh_.faces()[faceI]; + + if (f.size() == 3) + { + tris[nTris++] = faceCounter; + } + else if (f.size() == 4) + { + quads[nQuads++] = faceCounter; + } + else + { + polys[nPolys++] = faceCounter; + } + + ++faceCounter; + } + } + + tris.setSize(nTris); + quads.setSize(nQuads); + polys.setSize(nPolys); + } + } + + forAll(faceZoneNamesAll, zoneI) + { + const word& zoneName = faceZoneNamesAll[zoneI]; + nFacePrimitives nfp; + + if (faceZoneNames_.found(zoneName)) + { + if + ( + faceZoneFaceSets_[zoneI].tris.size() + || faceZoneFaceSets_[zoneI].quads.size() || + faceZoneFaceSets_[zoneI].polys.size() + ) + { + nfp.nTris = faceZoneFaceSets_[zoneI].tris.size(); + nfp.nQuads = faceZoneFaceSets_[zoneI].quads.size(); + nfp.nPolys = faceZoneFaceSets_[zoneI].polys.size(); + } + } + + reduce(nfp.nTris, sumOp