ensightPartFaces.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
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"
27 #include "IOstreams.H"
28 #include "IStringStream.H"
29 #include "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 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
51 
53 {
54  // count the shapes
55  label nTri = 0;
56  label nQuad = 0;
57  label nPoly = 0;
58 
59  forAll(faces, facei)
60  {
61  const face& f = faces[facei];
62 
63  if (f.size() == 3)
64  {
65  nTri++;
66  }
67  else if (f.size() == 4)
68  {
69  nQuad++;
70  }
71  else
72  {
73  nPoly++;
74  }
75  }
76 
77  // we can avoid double looping, but at the cost of allocation
78 
79  labelList triCells(nTri);
80  labelList quadCells(nQuad);
81  labelList polygonCells(nPoly);
82 
83  nTri = 0;
84  nQuad = 0;
85  nPoly = 0;
86 
87  // classify the shapes
88  forAll(faces, facei)
89  {
90  const face& f = faces[facei];
91 
92  if (f.size() == 3)
93  {
94  triCells[nTri++] = facei;
95  }
96  else if (f.size() == 4)
97  {
98  quadCells[nQuad++] = facei;
99  }
100  else
101  {
102  polygonCells[nPoly++] = facei;
103  }
104  }
105 
106 
107  // MUST match with elementTypes
108  elemLists_.setSize(elementTypes().size());
109 
110  elemLists_[tria3Elements].transfer(triCells);
111  elemLists_[quad4Elements].transfer(quadCells);
112  elemLists_[nsidedElements].transfer(polygonCells);
113 
114  size_ = faces.size();
115 }
116 
117 
118 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
119 
121 (
122  label partNumber,
123  const string& partDescription
124 )
125 :
126  ensightPart(partNumber, partDescription),
127  faces_(faceList::null()),
128  contiguousPoints_(false)
129 {
130  isCellData_ = false;
131  offset_ = 0;
132  size_ = 0;
133 }
134 
135 
137 (
138  label partNumber,
139  const string& partDescription,
140  const pointField& points,
141  const faceList& faces,
142  const bool contiguousPoints
143 )
144 :
145  ensightPart(partNumber, partDescription, points),
146  faces_(faces),
147  contiguousPoints_(contiguousPoints)
148 {
149  isCellData_ = false;
150  offset_ = 0;
151  size_ = 0;
152 
153  // classify the face shapes
154  classify(faces);
155 }
156 
157 
159 (
160  label partNumber,
161  const polyMesh& mesh,
162  const polyPatch& patch
163 )
164 :
165  ensightPart(partNumber, patch.name(), mesh.points()),
166  faces_(mesh.faces()),
167  contiguousPoints_(false)
168 {
169  isCellData_ = false;
170  offset_ = patch.start();
171 
172  // classify the face shapes
173  classify(patch);
174 }
175 
176 
178 :
179  ensightPart(part),
180  faces_(part.faces_),
181  contiguousPoints_(part.contiguousPoints_)
182 {}
183 
184 
186 :
187  ensightPart(),
188  faces_(faceList::null()),
189  contiguousPoints_(false)
190 {
191  isCellData_ = false;
192  reconstruct(is);
193 }
194 
195 
196 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
197 
199 {}
200 
201 
202 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
203 
204 Foam::ensightPart::localPoints Foam::ensightPartFaces::calcLocalPoints() const
205 {
206  if (contiguousPoints_)
207  {
208  localPoints ptList;
209  ptList.list = identity(points_.size());
210  ptList.nPoints = points_.size();
211  return ptList;
212  }
213 
214  localPoints ptList(points_);
215  labelList& usedPoints = ptList.list;
216  label nPoints = 0;
217 
218  forAll(elemLists_, typeI)
219  {
220  const labelUList& idList = elemLists_[typeI];
221 
222  // add all points from faces
223  forAll(idList, i)
224  {
225  const label id = idList[i] + offset_;
226  const face& f = faces_[id];
227 
228  forAll(f, fp)
229  {
230  if (usedPoints[f[fp]] == -1)
231  {
232  usedPoints[f[fp]] = nPoints++;
233  }
234  }
235  }
236  }
237 
238  // this is not absolutely necessary, but renumber anyhow
239  nPoints = 0;
240  forAll(usedPoints, ptI)
241  {
242  if (usedPoints[ptI] > -1)
243  {
244  usedPoints[ptI] = nPoints++;
245  }
246  }
247 
248  ptList.nPoints = nPoints;
249  return ptList;
250 }
251 
252 
253 void Foam::ensightPartFaces::writeConnectivity
254 (
255  ensightGeoFile& os,
256  const word& key,
257  const faceList& faces,
258  const labelUList& idList,
259  const labelUList& pointMap
260 ) const
261 {
262  os.writeKeyword(key);
263  os.write(idList.size());
264  os.newline();
265 
266  // write (polygon) face sizes
267  if (key == "nsided")
268  {
269  // write the number of points per face
270  forAll(idList, i)
271  {
272  const label id = idList[i] + offset_;
273  const face& f = faces[id];
274 
275  os.write(f.size());
276  os.newline();
277  }
278  }
279 
280  // write the points describing the face
281  forAll(idList, i)
282  {
283  const label id = idList[i] + offset_;
284  const face& f = faces[id];
285 
286  // convert global -> local index
287  // (note: Ensight indices start with 1)
288  forAll(f, fp)
289  {
290  os.write(pointMap[f[fp]] + 1);
291  }
292  os.newline();
293  }
294 }
295 
296 
297 void Foam::ensightPartFaces::writeConnectivity
298 (
299  ensightGeoFile& os,
300  const word& key,
301  const labelUList& idList,
302  const labelUList& pointMap
303 ) const
304 {
305  writeConnectivity
306  (
307  os,
308  key,
309  faces_,
310  idList,
311  pointMap
312  );
313 }
314 
315 
317 {
319 }
320 
321 
322 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
const word & name() const
Return name.
label nPoints
Number of points used.
Definition: ensightPart.H:109
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
virtual ~ensightPartFaces()
Destructor.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Specialised Ensight output with extra geometry file header.
virtual void writeGeometry(ensightGeoFile &) const
Write geometry.
const pointField & points_
pointField referenced
Definition: ensightPart.H:99
Track the points used by the part and map global to local indices.
Definition: ensightPart.H:105
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
Definition: ListOps.C:104
bool isCellData_
Cell or face data.
Definition: ensightPart.H:93
static const List< face > & null()
Return a null List.
Definition: ListI.H:118
labelListList elemLists_
Simple labelList with a name.
Definition: ensightPart.H:84
static const List< word > elemTypes_
const bool contiguousPoints_
Can skip local point renumbering when points are contiguous.
labelList list
Map global to local indices.
Definition: ensightPart.H:112
Macros for easy insertion into run-time selection tables.
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1131
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
A class for handling words, derived from string.
Definition: word.H:59
label nPoints
void reconstruct(Istream &)
Reconstruct part characteristics (eg, element types) from Istream.
ensightPartFaces(label partNumber, const string &partDescription)
Construct empty part with number and description.
virtual void writeGeometry(ensightGeoFile &) const
Write geometry.
Definition: ensightPart.H:307
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1156
virtual Ostream & writeKeyword(const string &key)
Write keyword with trailing newline.
virtual Ostream & write(const char *buf, std::streamsize count)
Binary write.
Definition: ensightFile.C:136
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Base class for ensightPartCells and ensightPartFaces.
Definition: ensightPart.H:65
defineTypeNameAndDebug(combustionModel, 0)
labelList f(nPoints)
void setSize(const label)
Reset size of List.
Definition: List.C:281
void newline()
Add carriage return to ascii stream.
Definition: ensightFile.C:259
label offset_
Start offset for elemLists_.
Definition: ensightPart.H:87
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:309
An implementation of ensightPart to hold volume mesh faces.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
void classify(const faceList &)
Classify the face shapes, set elemLists.
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
label size() const
Return the number of elements in the UList.
Definition: UListI.H:311
const faceList & faces_
Faces referenced.
Namespace for OpenFOAM.