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) 2011-2013 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
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 
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 
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 
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 {
318  ensightPart::writeGeometry(os, points_);
319 }
320 
321 
322 // ************************************************************************* //
Foam::ensightPartFaces::tria3Elements
@ tria3Elements
Definition: ensightPartFaces.H:75
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:979
Foam::ensightPartFaces::nsidedElements
@ nsidedElements
Definition: ensightPartFaces.H:77
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::List::null
static const List< T > & null()
Return a null List.
Definition: ListI.H:43
Foam::ensightPartFaces::elemTypes_
static const List< word > elemTypes_
Definition: ensightPartFaces.H:83
Foam::ensightPart::size
label size() const
Number of elements in this part.
Definition: ensightPart.H:227
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::ensightPartFaces::calcLocalPoints
virtual localPoints calcLocalPoints() const
Track points used.
Definition: ensightPartFaces.C:204
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::ensightPart::elemLists_
labelListList elemLists_
Simple labelList with a name.
Definition: ensightPart.H:76
ensightPartFaces.H
Foam::ensightPart::localPoints::nPoints
label nPoints
Number of points used.
Definition: ensightPart.H:101
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::ensightPartFaces::~ensightPartFaces
virtual ~ensightPartFaces()
Destructor.
Definition: ensightPartFaces.C:198
Foam::ensightPartFaces::quad4Elements
@ quad4Elements
Definition: ensightPartFaces.H:76
Foam::List::transfer
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Foam::ensightPartFaces::writeGeometry
virtual void writeGeometry(ensightGeoFile &) const
Write geometry.
Definition: ensightPartFaces.C:316
Foam::ensightPart::reconstruct
void reconstruct(Istream &)
Reconstruct part characteristics (eg, element types) from Istream.
Definition: ensightPartIO.C:101
Foam::ensightPartFaces::elementTypes
virtual const List< word > & elementTypes() const
Static listing of the element types.
Definition: ensightPartFaces.H:166
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
IStringStream.H
Foam::ensightPartFaces::writeConnectivity
virtual void writeConnectivity(ensightGeoFile &, const word &key, const labelUList &idList, const labelUList &pointMap) const
Element connectivity.
Definition: ensightPartFaces.C:298
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
Foam::ensightPart::localPoints::list
labelList list
Map global to local indices.
Definition: ensightPart.H:104
Foam::ensightGeoFile
Specialized Ensight output with extra geometry file header.
Definition: ensightGeoFile.H:45
Foam::label
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
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::ensightFile::newline
void newline()
Add carriage return to ascii stream.
Definition: ensightFile.C:259
Foam::ensightFile::write
virtual Ostream & write(const char *buf, std::streamsize count)
Binary write.
Definition: ensightFile.C:136
Foam::ensightPart::isCellData_
bool isCellData_
Cell or face data.
Definition: ensightPart.H:85
Foam::identity
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
Definition: ListOps.C:104
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::ensightPart::localPoints
Track the points used by the part and map global to local indices.
Definition: ensightPart.H:97
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::polyPatch::start
label start() const
Return start label of this patch in the polyMesh face list.
Definition: polyPatch.H:312
Foam::ensightPartFaces::classify
void classify(const faceList &)
Classify the face shapes, set elemLists.
Definition: ensightPartFaces.C:52
Foam::ensightPart::size_
label size_
Number of elements in this part.
Definition: ensightPart.H:82
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::polyMesh::faces
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1004
f
labelList f(nPoints)
Foam::List< Foam::word >
Foam::ensightPart
Base class for ensightPartCells and ensightPartFaces.
Definition: ensightPart.H:57
Foam::UList
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
points
const pointField & points
Definition: gmvOutputHeader.H:1
dictionary.H
Foam::ensightGeoFile::writeKeyword
virtual Ostream & writeKeyword(const string &key)
Write keyword with trailing newline.
Definition: ensightGeoFile.C:53
Foam::ensightPartFaces
An implementation of ensightPart to hold volume mesh faces.
Definition: ensightPartFaces.H:48
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::UList::size
label size() const
Return the number of elements in the UList.
Definition: UListI.H:299
Foam::ensightPartFaces::ensightPartFaces
ensightPartFaces(label partNumber, const string &partDescription)
Construct empty part with number and description.
Definition: ensightPartFaces.C:121
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::patchIdentifier::name
const word & name() const
Return name.
Definition: patchIdentifier.H:109
Foam::ensightPart::writeGeometry
virtual void writeGeometry(ensightGeoFile &) const
Write geometry.
Definition: ensightPart.H:299