1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "writeFaceSet.H"
28 #include "writeFuns.H"
30 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
32 void Foam::writeFaceSet
37 const fileName& fileName
40 const faceList& faces = vMesh.mesh().faces();
42 std::ofstream ostr(fileName.c_str());
44 writeFuns::writeHeader
51 ostr<< "DATASET POLYDATA" << std::endl;
53 //------------------------------------------------------------------
57 //------------------------------------------------------------------
60 // Construct primitivePatch of faces in faceSet.
62 faceList setFaces(set.size());
63 labelList setFaceLabels(set.size());
66 forAllConstIter(faceSet, set, iter)
68 setFaceLabels[setFaceI] = iter.key();
69 setFaces[setFaceI] = faces[iter.key()];
72 primitiveFacePatch fp(setFaces, vMesh.mesh().points());
75 // Write points and faces as polygons
77 ostr<< "POINTS " << fp.nPoints() << " float" << std::endl;
79 DynamicList<floatScalar> ptField(3*fp.nPoints());
81 writeFuns::insert(fp.localPoints(), ptField);
83 writeFuns::write(ostr, binary, ptField);
88 forAll(fp.localFaces(), faceI)
90 nFaceVerts += fp.localFaces()[faceI].size() + 1;
92 ostr<< "POLYGONS " << fp.size() << ' ' << nFaceVerts << std::endl;
95 DynamicList<label> vertLabels(nFaceVerts);
97 forAll(fp.localFaces(), faceI)
99 const face& f = fp.localFaces()[faceI];
101 vertLabels.append(f.size());
103 writeFuns::insert(f, vertLabels);
105 writeFuns::write(ostr, binary, vertLabels);
108 //-----------------------------------------------------------------
112 //-----------------------------------------------------------------
117 << "CELL_DATA " << fp.size() << std::endl
118 << "FIELD attributes 1" << std::endl;
121 ostr<< "faceID 1 " << fp.size() << " int" << std::endl;
123 writeFuns::write(ostr, binary, setFaceLabels);
127 // ************************************************************************* //