FreeFOAM The Cross-Platform CFD Toolkit
ensightPartFaces.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 \*----------------------------------------------------------------------------*/
25 
26 #include "ensightPartFaces.H"
28 #include <OpenFOAM/IOstreams.H>
29 #include <OpenFOAM/IStringStream.H>
30 #include <OpenFOAM/dictionary.H>
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(ensightPartFaces, 0);
37  addToRunTimeSelectionTable(ensightPart, ensightPartFaces, istream);
38 }
39 
40 
42 (
43  IStringStream
44  (
45  "(tria3 quad4 nsided)"
46  )()
47 );
48 
49 
50 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
51 
53 (
54  label partNumber,
55  const string& partDescription
56 )
57 :
58  ensightPart(partNumber, partDescription)
59 {
60  isCellData_ = false;
61 }
62 
63 
65 (
66  label partNumber,
67  const polyMesh& pMesh,
68  const polyPatch& pPatch
69 )
70 :
71  ensightPart(partNumber, pPatch.name(), pMesh)
72 {
73  isCellData_ = false;
74  offset_ = pPatch.start();
75  size_ = pPatch.size();
76 
77  // count the shapes
78  label nTri = 0;
79  label nQuad = 0;
80  label nPoly = 0;
81 
82  forAll (pPatch, patchfaceI)
83  {
84  const face& f = pMesh.faces()[patchfaceI + offset_];
85 
86  if (f.size() == 3)
87  {
88  nTri++;
89  }
90  else if (f.size() == 4)
91  {
92  nQuad++;
93  }
94  else
95  {
96  nPoly++;
97  }
98  }
99 
100  // we can avoid double looping, but at the cost of allocation
101 
102  labelList triCells(nTri);
103  labelList quadCells(nQuad);
104  labelList polygonCells(nPoly);
105 
106  nTri = 0;
107  nQuad = 0;
108  nPoly = 0;
109 
110  // classify the shapes
111  forAll(pPatch, patchfaceI)
112  {
113  const face& f = pMesh.faces()[patchfaceI + offset_];
114 
115  if (f.size() == 3)
116  {
117  triCells[nTri++] = patchfaceI;
118  }
119  else if (f.size() == 4)
120  {
121  quadCells[nQuad++] = patchfaceI;
122  }
123  else
124  {
125  polygonCells[nPoly++] = patchfaceI;
126  }
127  }
128 
129 
130  // MUST match with elementTypes
131  elemLists_.setSize(elementTypes().size());
132 
133  elemLists_[tria3Elements].transfer( triCells );
134  elemLists_[quad4Elements].transfer( quadCells );
135  elemLists_[nsidedElements].transfer( polygonCells );
136 }
137 
138 
140 :
141  ensightPart(part)
142 {}
143 
144 
146 :
147  ensightPart()
148 {
149  isCellData_ = false;
150  reconstruct(is);
151 }
152 
153 
154 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
155 
157 {}
158 
159 
160 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
161 
162 Foam::ensightPart::localPoints Foam::ensightPartFaces::calcLocalPoints() const
163 {
164  const polyMesh& mesh = *meshPtr_;
165 
166  localPoints ptList(mesh);
167  labelList& usedPoints = ptList.list;
168  label nPoints = 0;
169 
170  forAll(elemLists_, typeI)
171  {
172  const labelList& idList = elemLists_[typeI];
173 
174  // add all points from faces
175  forAll(idList, i)
176  {
177  label id = idList[i] + offset_;
178  const face& f = mesh.faces()[id];
179 
180  forAll(f, fp)
181  {
182  if (usedPoints[f[fp]] == -1)
183  {
184  usedPoints[f[fp]] = nPoints++;
185  }
186  }
187  }
188  }
189 
190  // this is not absolutely necessary, but renumber anyhow
191  nPoints = 0;
192  forAll(usedPoints, ptI)
193  {
194  if (usedPoints[ptI] > -1)
195  {
196  usedPoints[ptI] = nPoints++;
197  }
198  }
199 
200  ptList.nPoints = nPoints;
201  return ptList;
202 }
203 
204 
205 void Foam::ensightPartFaces::writeConnectivity
206 (
207  ensightGeoFile& os,
208  const string& key,
209  const labelList& idList,
210  const labelList& pointMap
211 ) const
212 {
213  os.writeKeyword(key);
214  os.write(idList.size());
215  os.newline();
216 
217  const faceList& meshFaces = meshPtr_->faces();
218 
219  // write (polygon) face sizes
220  if (word(key) == "nsided")
221  {
222  // write the number of points per face
223  forAll(idList, i)
224  {
225  label id = idList[i] + offset_;
226  const face& f = meshFaces[id];
227 
228  os.write( f.size() );
229  os.newline();
230  }
231  }
232 
233  // write the points describing the face
234  forAll(idList, i)
235  {
236  label id = idList[i] + offset_;
237  const face& f = meshFaces[id];
238 
239  // convert global -> local index
240  // (note: Ensight indices start with 1)
241  forAll(f, fp)
242  {
243  os.write( pointMap[f[fp]] + 1 );
244  }
245  os.newline();
246  }
247 }
248 
249 
250 // ************************ vim: set sw=4 sts=4 et: ************************ //