/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright held by original author \\/ M anipulation | ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenFOAM; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA \*---------------------------------------------------------------------------*/ #include "argList.H" #include "Time.H" #include "ensightMesh.H" #include "fvMesh.H" #include "PstreamCombineReduceOps.H" #include "processorPolyPatch.H" #include "cellModeller.H" #include "IOmanip.H" #include "itoa.H" #include "ensightWriteBinary.H" #include // * * * * * * * * * * * * * Private Functions * * * * * * * * * * * * * * // namespace Foam { class concatPatchNames { public: void operator() ( HashTable& x, const HashTable& y ) const { forAllConstIter(HashTable, y, iter) { HashTable::iterator xiter = x.find(iter.key()); if (xiter == x.end()) { x.insert(iter.key(), iter()); } else { labelList& xPatches = xiter(); const labelList& yPatches = iter(); label offset = xPatches.size(); xPatches.setSize(offset + yPatches.size()); forAll(yPatches, i) { xPatches[i + offset] = yPatches[i]; } } } } }; } // End namespace Foam // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::ensightMesh::ensightMesh ( const fvMesh& mesh, const argList& args, const bool binary ) : binary_(binary), mesh_(mesh), meshCellSets_(mesh_.nCells()), boundaryFaceSets_(mesh_.boundary().size()), allPatchNames_(0), patchIndices_(0), patchNames_(0), nPatchPrims_(0) { forAll (mesh_.boundaryMesh(), patchi) { if ( typeid(mesh_.boundaryMesh()[patchi]) != typeid(processorPolyPatch) ) { if (!allPatchNames_.found(mesh_.boundaryMesh()[patchi].name())) { allPatchNames_.insert ( mesh_.boundaryMesh()[patchi].name(), labelList(1, Pstream::myProcNo()) ); patchIndices_.insert ( mesh_.boundaryMesh()[patchi].name(), patchi ); } } } combineReduce(allPatchNames_, concatPatchNames()); if (args.options().found("patches")) { wordList patchNameList(IStringStream(args.options()["patches"])()); if (!patchNameList.size()) { patchNameList = allPatchNames_.toc(); } forAll (patchNameList, i) { patchNames_.insert(patchNameList[i]); } } const cellShapeList& cellShapes = mesh.cellShapes(); const cellModel& tet = *(cellModeller::lookup("tet")); const cellModel& pyr = *(cellModeller::lookup("pyr")); const cellModel& prism = *(cellModeller::lookup("prism")); const cellModel& wedge = *(cellModeller::lookup("wedge")); const cellModel& hex = *(cellModeller::lookup("hex")); labelList& tets = meshCellSets_.tets; labelList& pyrs = meshCellSets_.pyrs; labelList& prisms = meshCellSets_.prisms; labelList& wedges = meshCellSets_.wedges; labelList& hexes = meshCellSets_.hexes; labelList& polys = meshCellSets_.polys; // Count the shapes label nTets = 0; label nPyrs = 0; label nPrisms = 0; label nWedges = 0; label nHexes = 0; label nPolys = 0; if (!patchNames_.size()) { forAll(cellShapes, celli) { const cellShape& cellShape = cellShapes[celli]; const cellModel& cellModel = cellShape.model(); if (cellModel == tet) { tets[nTets++] = celli; } else if (cellModel == pyr) { pyrs[nPyrs++] = celli; } else if (cellModel == prism) { prisms[nPrisms++] = celli; } else if (cellModel == wedge) { wedges[nWedges++] = celli; } else if (cellModel == hex) { hexes[nHexes++] = celli; } else { polys[nPolys++] = celli; } } tets.setSize(nTets); pyrs.setSize(nPyrs); prisms.setSize(nPrisms); wedges.setSize(nWedges); hexes.setSize(nHexes); polys.setSize(nPolys); meshCellSets_.nTets = nTets; reduce(meshCellSets_.nTets, sumOp