ensightPartCells.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "ensightPartCells.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(ensightPartCells, 0);
36 }
37 
38 
39 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40 
41 Foam::ensightPart::localPoints Foam::ensightPartCells::calcLocalPoints() const
42 {
43  localPoints ptList(mesh_.points());
44  labelList& usedPoints = ptList.list;
45  label nPoints = 0;
46 
47  // Add all points from cells
48  const labelUList& idList = this->cellIds();
49 
50  for (const label id : idList)
51  {
52  const labelUList& cFaces = mesh_.cells()[id];
53 
54  forAll(cFaces, cFacei)
55  {
56  const face& f = mesh_.faces()[cFaces[cFacei]];
57 
58  forAll(f, fp)
59  {
60  if (usedPoints[f[fp]] == -1)
61  {
62  usedPoints[f[fp]] = nPoints++;
63  }
64  }
65  }
66  }
67 
68  // this is not absolutely necessary, but renumber anyhow
69  nPoints = 0;
70  forAll(usedPoints, ptI)
71  {
72  if (usedPoints[ptI] > -1)
73  {
74  usedPoints[ptI] = nPoints++;
75  }
76  }
77 
78  ptList.nPoints = nPoints;
79  return ptList;
80 }
81 
82 
83 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
84 
85 Foam::ensightPartCells::ensightPartCells
86 (
87  label partIndex,
88  const polyMesh& mesh,
89  const string& partName
90 )
91 :
92  ensightCells(partIndex),
93  ensightPart(partName),
94  mesh_(mesh)
95 {
96  classify(mesh);
97 }
98 
99 
100 Foam::ensightPartCells::ensightPartCells
101 (
102  label partIndex,
103  const polyMesh& mesh,
104  const labelUList& cellIds,
105  const string& partName
106 )
107 :
108  ensightCells(partIndex),
109  ensightPart(partName),
110  mesh_(mesh)
111 {
112  classify(mesh, cellIds);
113 }
114 
115 
116 Foam::ensightPartCells::ensightPartCells
117 (
118  label partIndex,
119  const polyMesh& mesh,
120  const bitSet& selection,
121  const string& partName
122 )
123 :
124  ensightCells(partIndex),
125  ensightPart(partName),
126  mesh_(mesh)
127 {
128  classify(mesh, selection);
129 }
130 
131 
132 Foam::ensightPartCells::ensightPartCells
133 (
134  label partIndex,
135  const polyMesh& mesh,
136  const cellZone& zn,
137  const string& partName
138 )
139 :
141  (
142  partIndex,
143  mesh,
144  static_cast<const labelList&>(zn),
145  zn.name()
146  )
147 {
148  if (!partName.empty())
149  {
150  rename(partName);
151  }
152 }
153 
154 
155 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
156 
157 void Foam::ensightPartCells::writeConnectivity
158 (
159  ensightGeoFile& os,
160  const word& key,
161  const labelUList& idList,
162  const labelUList& pointMap
163 ) const
164 {
165  if (idList.empty()) return;
166 
167  os.writeKeyword(key);
168  os.write(idList.size());
169  os.newline();
170 
171  // write polyhedral
172  if (key == "nfaced")
173  {
174  const faceList& meshFaces = mesh_.faces();
175  const labelUList& owner = mesh_.faceOwner();
176 
177  // write the number of faces per element
178  forAll(idList, i)
179  {
180  const label id = idList[i];
181  const labelUList& cFace = mesh_.cells()[id];
182 
183  os.write(cFace.size());
184  os.newline();
185  }
186 
187  // write the number of points per element face
188  forAll(idList, i)
189  {
190  const label id = idList[i];
191  const labelUList& cFace = mesh_.cells()[id];
192 
193  forAll(cFace, facei)
194  {
195  const face& cf = meshFaces[cFace[facei]];
196 
197  os.write(cf.size());
198  os.newline();
199  }
200  }
201 
202  // write the points describing each element face
203  forAll(idList, i)
204  {
205  const label id = idList[i];
206  const labelUList& cFace = mesh_.cells()[id];
207 
208  forAll(cFace, cFacei)
209  {
210  const label faceId = cFace[cFacei];
211  const face& cf = meshFaces[faceId];
212 
213  // convert global -> local index
214  // (note: Ensight indices start with 1)
215 
216  // ensight >= 9 needs consistently oriented nfaced cells
217  if (id == owner[faceId])
218  {
219  forAll(cf, ptI)
220  {
221  os.write(pointMap[cf[ptI]] + 1);
222  }
223  }
224  else
225  {
226  // as per face::reverseFace(), but without copying
227 
228  os.write(pointMap[cf[0]] + 1);
229  for (label ptI = cf.size()-1; ptI > 0; --ptI)
230  {
231  os.write(pointMap[cf[ptI]] + 1);
232  }
233  }
234 
235  os.newline();
236  }
237  }
238  }
239  else
240  {
241  // write primitive
242  const cellShapeList& shapes = mesh_.cellShapes();
243 
244  forAll(idList, i)
245  {
246  const label id = idList[i];
247  const cellShape& cellPoints = shapes[id];
248 
249  // convert global -> local index
250  // (note: Ensight indices start with 1)
251  forAll(cellPoints, ptI)
252  {
253  os.write(pointMap[cellPoints[ptI]] + 1);
254  }
255  os.newline();
256  }
257  }
258 }
259 
260 
262 (
263  ensightGeoFile& os,
264  const pointField& points
265 ) const
266 {
267  if (size())
268  {
269  const localPoints ptList = calcLocalPoints();
270  const labelUList& pointMap = ptList.list;
271 
272  os.beginPart(index(), name());
273  os.beginCoordinates(ptList.nPoints);
274 
275  for (direction cmpt=0; cmpt < point::nComponents; ++cmpt)
276  {
277  forAll(pointMap, ptI)
278  {
279  if (pointMap[ptI] > -1)
280  {
281  os.write(points[ptI].component(cmpt));
282  os.newline();
283  }
284  }
285  }
286 
287  // Write each element type
288  for (int typei=0; typei < ensightCells::nTypes; ++typei)
289  {
291 
292  writeConnectivity
293  (
294  os,
295  ensightCells::key(what),
296  cellIds(what),
297  pointMap
298  );
299  }
300  }
301 }
302 
303 
305 {
306  this->write(os, mesh_.points());
307 }
308 
309 
311 {
312  os.beginBlock(type());
313 
314  os.writeEntry("id", index()+1); // Ensight starts with 1
315  os.writeEntry("name", name());
316  os.writeEntry("size", size());
317 
318  os.endBlock();
319 }
320 
321 
323 {
324  os.beginBlock(type());
325 
326  os.writeEntry("id", index()+1); // Ensight starts with 1
327  os.writeEntry("name", name());
328  os.writeEntry("size", size());
329 
330  for (int typei=0; typei < ensightCells::nTypes; ++typei)
331  {
333  const labelUList& addr = this->cellIds(what);
334 
336 
337  addr.writeList(os, 0) << endEntry; // Flat output
338  }
339 
340  os.endBlock();
341 }
342 
343 
344 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:74
Foam::UList::writeList
Ostream & writeList(Ostream &os, const label shortLen=0) const
Write List, with line-breaks in ASCII when length exceeds shortLen.
Definition: UListIO.C:78
Foam::ensightPart::localPoints
Track the points used by the part and map global to local indices.
Definition: ensightPart.H:78
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1038
Foam::component
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
Definition: FieldFieldFunctions.C:44
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::ensightGeoFile::beginPart
void beginPart(const label index, const string &description)
Begin a "part" (0-based index), with a description.
Definition: ensightGeoFile.C:98
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:64
Foam::ensightCells::cellIds
const labelUList & cellIds() const
Return the cell ids of all elements.
Definition: ensightCellsI.H:89
Foam::cellShapeList
List< cellShape > cellShapeList
List of cellShapes and PtrList of List of cellShape.
Definition: cellShapeList.H:45
Foam::primitiveMesh::cells
const cellList & cells() const
Definition: primitiveMeshCells.C:138
Foam::Ostream::beginBlock
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.
Definition: Ostream.C:91
Foam::ensightGeoFile::beginCoordinates
void beginCoordinates(const label npoints)
Begin a "coordinates" block.
Definition: ensightGeoFile.C:109
Foam::ensightPartCells
An implementation of ensightPart to hold volume mesh cells.
Definition: ensightPartCells.H:53
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::cellZone
A subset of mesh cells.
Definition: cellZone.H:62
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
Foam::ensightGeoFile
Specialized Ensight output with extra geometry file header.
Definition: ensightGeoFile.H:48
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:62
Foam::ensightCells::nTypes
static constexpr int nTypes
Number of element types (5)
Definition: ensightCells.H:70
Foam::Field< vector >
Foam::ensightPartCells::writeSummary
virtual void writeSummary(Ostream &os) const
Write summary information about the object.
Definition: ensightPartCells.C:310
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
faceId
label faceId(-1)
Foam::ensightFile::newline
void newline()
Add carriage return to ascii stream.
Definition: ensightFile.C:269
Foam::ensightCells::key
static const char * key(const enum elemType)
Return the ensight element name for the specified type.
Definition: ensightCellsI.H:32
Foam::ensightFile::write
virtual Ostream & write(const char *buf, std::streamsize count)
Binary write.
Definition: ensightFile.C:157
Foam::ensightCells
Sorting/classification of cells (3D) into corresponding ensight element types.
Definition: ensightCells.H:53
Foam::Ostream::endBlock
virtual Ostream & endBlock()
Write end block group.
Definition: Ostream.C:109
Foam::UList::empty
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
Definition: UListI.H:374
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::Ostream::writeKeyword
virtual Ostream & writeKeyword(const keyType &kw)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:57
Foam::zone::name
const word & name() const
Return name.
Definition: zone.H:158
Foam::ensightCells::elemType
elemType
Addressable ensight element types.
Definition: ensightCells.H:60
Foam::polyMesh::faces
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1063
Foam::ensightPart::localPoints::list
labelList list
Map global to local indices.
Definition: ensightPart.H:84
f
labelList f(nPoints)
Foam::List< label >
Foam::ensightGeoFile::writeKeyword
virtual Ostream & writeKeyword(const keyType &key)
Write keyword with trailing newline.
Definition: ensightGeoFile.C:83
Foam::ensightPart
Base class for ensightPartCells and ensightPartFaces.
Definition: ensightPart.H:56
Foam::endEntry
Ostream & endEntry(Ostream &os)
Write end entry (';') followed by newline.
Definition: Ostream.H:363
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::ensightPartCells::dumpInfo
virtual void dumpInfo(Ostream &os) const
Print various types of debugging information.
Definition: ensightPartCells.C:322
Foam::UList< label >
points
const pointField & points
Definition: gmvOutputHeader.H:1
ensightPartCells.H
Foam::direction
uint8_t direction
Definition: direction.H:47
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:219
Foam::ensightPartCells::write
virtual void write(ensightGeoFile &os) const
Write geometry.
Definition: ensightPartCells.C:304
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:35
Foam::UList::size
void size(const label n) noexcept
Override size to be inconsistent with allocated storage.
Definition: UListI.H:360
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::labelUList
UList< label > labelUList
A UList of labels.
Definition: UList.H:79
Foam::ensightPart::localPoints::nPoints
label nPoints
Number of points used.
Definition: ensightPart.H:81
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::VectorSpace< Vector< scalar >, scalar, 3 >::nComponents
static constexpr direction nComponents
Number of components in this vector space.
Definition: VectorSpace.H:101