FreeFOAM The Cross-Platform CFD Toolkit
writeFaceSet.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 Description
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "writeFaceSet.H"
29 #include <OpenFOAM/OFstream.H>
30 #include "writeFuns.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 
37 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
38 
39 void writeFaceSet
40 (
41  const bool binary,
42  const vtkMesh& vMesh,
43  const faceSet& set,
44  const fileName& fileName
45 )
46 {
47  const faceList& faces = vMesh.mesh().faces();
48 
49  std::ofstream pStream(fileName.c_str());
50 
51  pStream
52  << "# vtk DataFile Version 2.0" << std::endl
53  << set.name() << std::endl;
54  if (binary)
55  {
56  pStream << "BINARY" << std::endl;
57  }
58  else
59  {
60  pStream << "ASCII" << std::endl;
61  }
62  pStream << "DATASET POLYDATA" << std::endl;
63 
64 
65  //------------------------------------------------------------------
66  //
67  // Write topology
68  //
69  //------------------------------------------------------------------
70 
71 
72  // Construct primitivePatch of faces in faceSet.
73 
74  faceList setFaces(set.size());
75  labelList setFaceLabels(set.size());
76  label setFaceI = 0;
77 
78  for
79  (
80  faceSet::const_iterator iter = set.begin();
81  iter != set.end();
82  ++iter
83  )
84  {
85  setFaceLabels[setFaceI] = iter.key();
86  setFaces[setFaceI] = faces[iter.key()];
87  setFaceI++;
88  }
89  primitiveFacePatch fp(setFaces, vMesh.mesh().points());
90 
91 
92  // Write points and faces as polygons
93 
94  pStream << "POINTS " << fp.nPoints() << " float" << std::endl;
95 
96  DynamicList<floatScalar> ptField(3*fp.nPoints());
97 
98  writeFuns::insert(fp.localPoints(), ptField);
99 
100  writeFuns::write(pStream, binary, ptField);
101 
102 
103  label nFaceVerts = 0;
104 
105  forAll(fp.localFaces(), faceI)
106  {
107  nFaceVerts += fp.localFaces()[faceI].size() + 1;
108  }
109  pStream << "POLYGONS " << fp.size() << ' ' << nFaceVerts
110  << std::endl;
111 
112 
113  DynamicList<label> vertLabels(nFaceVerts);
114 
115  forAll(fp.localFaces(), faceI)
116  {
117  const face& f = fp.localFaces()[faceI];
118 
119  vertLabels.append(f.size());
120 
121  writeFuns::insert(f, vertLabels);
122  }
123  writeFuns::write(pStream, binary, vertLabels);
124 
125 
126  //-----------------------------------------------------------------
127  //
128  // Write data
129  //
130  //-----------------------------------------------------------------
131 
132  // Write faceID
133 
134  pStream
135  << "CELL_DATA " << fp.size() << std::endl
136  << "FIELD attributes 1" << std::endl;
137 
138  // Cell ids first
139  pStream << "faceID 1 " << fp.size() << " int" << std::endl;
140 
141  writeFuns::write(pStream, binary, setFaceLabels);
142 }
143 
144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145 
146 } // End namespace Foam
147 
148 // ************************ vim: set sw=4 sts=4 et: ************************ //