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 | 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 "ensightPartFaces.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(ensightPartFaces, 0);
36 }
37 
38 
39 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40 
41 Foam::ensightPart::localPoints Foam::ensightPartFaces::calcLocalPoints() const
42 {
43  if (contiguousPoints_)
44  {
45  localPoints ptList;
46  ptList.list = identity(points_.size());
47  ptList.nPoints = points_.size();
48  return ptList;
49  }
50 
51  localPoints ptList(points_);
52  labelList& usedPoints = ptList.list;
53  label nPoints = 0;
54 
55  // Add all points from faces
56  const labelUList& idList = this->faceIds();
57 
58  // Add all points from faces
59  forAll(idList, i)
60  {
61  const label id = idList[i] + start_;
62  const face& f = faces_[id];
63 
64  forAll(f, fp)
65  {
66  if (usedPoints[f[fp]] == -1)
67  {
68  usedPoints[f[fp]] = nPoints++;
69  }
70  }
71  }
72 
73 
74  // This is not absolutely necessary, but renumber anyhow
75  nPoints = 0;
76  forAll(usedPoints, ptI)
77  {
78  if (usedPoints[ptI] > -1)
79  {
80  usedPoints[ptI] = nPoints++;
81  }
82  }
83 
84  ptList.nPoints = nPoints;
85  return ptList;
86 }
87 
88 
89 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
90 
91 Foam::ensightPartFaces::ensightPartFaces
92 (
93  label partIndex,
94  const string& description,
95  const pointField& points,
96  const faceList& faces,
97  const bool contiguousPoints
98 )
99 :
100  ensightFaces(partIndex),
101  ensightPart(description),
102  start_(0),
103  patchIndex_(-1),
104  faces_(faces),
105  points_(points),
106  contiguousPoints_(contiguousPoints)
107 {
108  // Classify the face shapes
109  classify(faces);
110 }
111 
112 
113 Foam::ensightPartFaces::ensightPartFaces
114 (
115  label partIndex,
116  const polyMesh& mesh,
117  const polyPatch& patch,
118  const string& partName
119 )
120 :
121  ensightFaces(partIndex),
122  ensightPart(patch.name()),
123  start_(patch.start()),
124  patchIndex_(patch.index()),
125  faces_(mesh.faces()),
126  points_(mesh.points()),
127  contiguousPoints_(false)
128 {
129  if (!partName.empty())
130  {
131  rename(partName);
132  }
133 
134  // Classify the face shapes
135  classify(patch);
136 }
137 
138 
139 Foam::ensightPartFaces::ensightPartFaces
140 (
141  label partIndex,
142  const polyPatch& patch,
143  const string& partName
144 )
145 :
146  ensightPartFaces(partIndex, patch.boundaryMesh().mesh(), patch, partName)
147 {}
148 
149 
150 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
151 
152 void Foam::ensightPartFaces::writeConnectivity
153 (
154  ensightGeoFile& os,
155  const word& key,
156  const faceList& faces,
157  const labelUList& idList,
158  const labelUList& pointMap
159 ) const
160 {
161  if (idList.empty()) return;
162 
163  os.writeKeyword(key);
164  os.write(idList.size());
165  os.newline();
166 
167  // Write (polygon) face sizes
168  if (key == "nsided")
169  {
170  // Write the number of points per face
171  forAll(idList, i)
172  {
173  const label id = idList[i] + start_;
174  const face& f = faces[id];
175 
176  os.write(f.size());
177  os.newline();
178  }
179  }
180 
181  // Write the points describing the face
182  forAll(idList, i)
183  {
184  const label id = idList[i] + start_;
185  const face& f = faces[id];
186 
187  // Convert global -> local index
188  // (note: Ensight indices start with 1)
189  forAll(f, fp)
190  {
191  os.write(pointMap[f[fp]] + 1);
192  }
193  os.newline();
194  }
195 }
196 
197 
198 void Foam::ensightPartFaces::writeConnectivity
199 (
200  ensightGeoFile& os,
201  const word& key,
202  const labelUList& idList,
203  const labelUList& pointMap
204 ) const
205 {
206  writeConnectivity
207  (
208  os,
209  key,
210  faces_,
211  idList,
212  pointMap
213  );
214 }
215 
216 
218 (
219  ensightGeoFile& os,
220  const pointField& points
221 ) const
222 {
223  if (size())
224  {
225  const localPoints ptList = calcLocalPoints();
226  const labelUList& pointMap = ptList.list;
227 
228  os.beginPart(index(), name());
229  os.beginCoordinates(ptList.nPoints);
230 
231  for (direction cmpt=0; cmpt < point::nComponents; ++cmpt)
232  {
233  forAll(pointMap, ptI)
234  {
235  if (pointMap[ptI] > -1)
236  {
237  os.write(points[ptI].component(cmpt));
238  os.newline();
239  }
240  }
241  }
242 
243  // Write part
244  for (int typei=0; typei < ensightFaces::nTypes; ++typei)
245  {
247 
248  writeConnectivity
249  (
250  os,
251  ensightFaces::key(what),
252  faceIds(what),
253  pointMap
254  );
255  }
256  }
257 }
258 
259 
261 {
262  this->write(os, points_);
263 }
264 
265 
267 {
268  os.beginBlock(type());
269 
270  os.writeEntry("id", index()+1); // Ensight starts with 1
271  os.writeEntry("name", name());
272  os.writeEntry("start", start_);
273  os.writeEntry("size", size());
274 
275  os.endBlock();
276 }
277 
278 
280 {
281  os.beginBlock(type());
282 
283  os.writeEntry("id", index()+1); // Ensight starts with 1
284  os.writeEntry("name", name());
285  os.writeEntry("start", start_);
286  os.writeEntry("size", size());
287 
288  for (int typei=0; typei < ensightFaces::nTypes; ++typei)
289  {
291  const labelUList& addr = this->faceIds(what);
292 
294 
295  addr.writeList(os, 0) << endEntry; // Flat output
296  }
297 
298  os.endBlock();
299 }
300 
301 
302 // ************************************************************************* //
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::ensightFaces::nTypes
static constexpr int nTypes
Number of element types (3)
Definition: ensightFaces.H:66
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
ensightPartFaces.H
Foam::ensightFaces::key
static const char * key(const enum elemType)
Return the ensight element name for the specified type.
Definition: ensightFacesI.H:32
Foam::ensightPartFaces::dumpInfo
virtual void dumpInfo(Ostream &os) const
Print various types of debugging information.
Definition: ensightPartFaces.C:279
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::ensightFaces
Sorting/classification of faces (2D) into corresponding ensight types.
Definition: ensightFaces.H:51
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
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::Field< vector >
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::ensightFile::newline
void newline()
Add carriage return to ascii stream.
Definition: ensightFile.C:269
Foam::ensightFile::write
virtual Ostream & write(const char *buf, std::streamsize count)
Binary write.
Definition: ensightFile.C:157
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::ensightFaces::faceIds
const labelUList & faceIds() const
Return the processor local face ids of all elements.
Definition: ensightFacesI.H:89
Foam::Ostream::writeKeyword
virtual Ostream & writeKeyword(const keyType &kw)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:57
Foam::ensightFaces::elemType
elemType
Addressable ensight element types.
Definition: ensightFaces.H:58
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::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::List< face >
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::UList< label >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::identity
labelList identity(const label len, label start=0)
Create identity map of the given length with (map[i] == i)
Definition: labelList.C:38
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::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::ensightPartFaces
An implementation of ensightPart to hold mesh faces.
Definition: ensightPartFaces.H:53
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:74
Foam::ensightPartFaces::writeSummary
virtual void writeSummary(Ostream &os) const
Write summary information about the object.
Definition: ensightPartFaces.C:266
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
Foam::ensightPartFaces::write
virtual void write(ensightGeoFile &os) const
Write geometry.
Definition: ensightPartFaces.C:260