ensightOutput.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) 2020 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "ensightOutput.H"
29 
30 #include "cell.H"
31 #include "cellShape.H"
32 #include "face.H"
33 #include "polyMesh.H"
34 #include "ListOps.H"
35 
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 
38 // Sizes
39 
41 (
42  const UList<face>& faces
43 )
44 {
45  labelList list(faces.size());
46 
47  auto outIter = list.begin();
48 
49  for (const face& f : faces)
50  {
51  *outIter = f.size();
52  ++outIter;
53  }
54 
55  return list;
56 }
57 
58 
60 (
61  const UIndirectList<face>& faces
62 )
63 {
64  labelList list(faces.size());
65 
66  auto outIter = list.begin();
67 
68  for (const face& f : faces)
69  {
70  *outIter = f.size();
71  ++outIter;
72  }
73 
74  return list;
75 }
76 
77 
79 (
80  const polyMesh& mesh,
81  const labelUList& addr
82 )
83 {
84  const cellList& meshCells = mesh.cells();
85 
86  labelList list(addr.size());
87 
88  auto outIter = list.begin();
89 
90  // The number of faces per element
91  for (const label cellId : addr)
92  {
93  *outIter = meshCells[cellId].size();
94  ++outIter;
95  }
96 
97  return list;
98 }
99 
100 
102 (
103  const polyMesh& mesh,
104  const labelUList& addr
105 )
106 {
107  const cellList& meshCells = mesh.cells();
108  const faceList& meshFaces = mesh.faces();
109 
110  // Count the number of faces per element
111 
112  label nTotFaces = 0;
113  for (const label cellId : addr)
114  {
115  nTotFaces += meshCells[cellId].size();
116  }
117 
118  labelList list(nTotFaces);
119 
120  auto outIter = list.begin();
121 
122  // The number of points per element face
123  for (const label cellId : addr)
124  {
125  for (const label facei : meshCells[cellId])
126  {
127  *outIter = meshFaces[facei].size();
128  ++outIter;
129  }
130  }
131 
132  return list;
133 }
134 
135 
137 (
138  ensightGeoFile& os,
139  const UList<face>& faces
140 )
141 {
142  for (const face& f : faces)
143  {
144  for (const label labi : f)
145  {
146  os.write(labi + 1);
147  }
148 
149  os.newline();
150  }
151 }
152 
153 
155 (
156  ensightGeoFile& os,
157  const UIndirectList<face>& faces
158 )
159 {
160  for (const face& f : faces)
161  {
162  for (const label labi : f)
163  {
164  os.write(labi + 1);
165  }
166 
167  os.newline();
168  }
169 }
170 
171 
173 (
174  ensightGeoFile& os,
175  const UList<cellShape>& shapes
176 )
177 {
178  for (const cellShape& cellPoints : shapes)
179  {
180  // Convert global -> local index
181  // (note: Ensight indices start with 1)
182 
183  // In ASCII, write one cell per line
184  for (const label pointi : cellPoints)
185  {
186  os.write(pointi + 1);
187  }
188 
189  os.newline();
190  }
191 }
192 
193 
195 (
196  ensightGeoFile& os,
197  const polyMesh& mesh,
198  const labelUList& addr,
199  const labelList& pointMap
200 )
201 {
202  const cellList& meshCells = mesh.cells();
203  const faceList& meshFaces = mesh.faces();
204  const labelList& owner = mesh.faceOwner();
205 
206  for (const label cellId : addr)
207  {
208  for (const label faceId : meshCells[cellId])
209  {
210  const face& f = meshFaces[faceId];
211 
212  if (faceId < owner.size() && owner[faceId] != cellId)
213  {
214  // The neighbour of an internal face
215  // - write as face::reverseFace()
216 
217  os.write(pointMap[f[0]] + 1);
218  for (label pti = f.size()-1; pti > 0; --pti)
219  {
220  os.write(pointMap[f[pti]] + 1);
221  }
222  }
223  else
224  {
225  for (const label pointi : f)
226  {
227  os.write(pointMap[pointi] + 1);
228  }
229  }
230 
231  os.newline();
232  }
233  }
234 }
235 
236 
238 (
239  ensightGeoFile& os,
240  const cellUList& meshCells,
241  const labelUList& addr,
242  const faceUList& meshFaces,
243  const labelUList& owner
244 )
245 {
246  for (const label cellId : addr)
247  {
248  for (const label faceId : meshCells[cellId])
249  {
250  const face& f = meshFaces[faceId];
251 
252  if (faceId < owner.size() && owner[faceId] != cellId)
253  {
254  // The neighbour of an internal face
255  // - write as face::reverseFace()
256 
257  os.write(f[0] + 1);
258  for (label pti = f.size()-1; pti > 0; --pti)
259  {
260  os.write(f[pti] + 1);
261  }
262  }
263  else
264  {
265  for (const label pointi : f)
266  {
267  os.write(pointi + 1);
268  }
269  }
270 
271  os.newline();
272  }
273  }
274 }
275 
276 
278 (
279  ensightGeoFile& os,
280  const ensightFaces::elemType etype,
281  const label nTotal,
282  const faceUList& faces,
283  bool parallel
284 )
285 {
286  if (!nTotal)
287  {
288  return;
289  }
290 
291  parallel = parallel && Pstream::parRun();
292 
293  const label nSlaves = (parallel ? Pstream::nProcs() : 0);
294 
295  if (Pstream::master())
296  {
297  os.writeKeyword(ensightFaces::key(etype));
298  os.write(nTotal);
299  os.newline();
300  }
301 
302  if (etype == ensightFaces::NSIDED)
303  {
304  // Face sizes (number of points per face)
305 
307 
308  if (Pstream::master())
309  {
310  os.writeLabels(send);
311 
312  for (int slave=1; slave < nSlaves; ++slave)
313  {
314  IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
315  labelList recv(fromSlave);
316 
317  os.writeLabels(recv);
318  }
319  }
320  else if (nSlaves)
321  {
322  OPstream toMaster
323  (
324  Pstream::commsTypes::scheduled,
325  Pstream::masterNo()
326  );
327 
328  toMaster << send;
329  }
330  }
331 
332 
333  // List of points id for each face
334  if (Pstream::master())
335  {
336  writeFaceList(os, faces);
337 
338  for (int slave=1; slave < nSlaves; ++slave)
339  {
340  IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
341  List<face> recv(fromSlave);
342 
343  writeFaceList(os, recv);
344  }
345  }
346  else if (nSlaves)
347  {
348  OPstream toMaster
349  (
350  Pstream::commsTypes::scheduled,
351  Pstream::masterNo()
352  );
353 
354  toMaster << faces;
355  }
356 }
357 
358 
360 (
361  ensightGeoFile& os,
362  const ensightFaces::elemType etype,
363  const label nTotal,
364  const UIndirectList<face>& faces,
365  bool parallel
366 )
367 {
368  if (!nTotal)
369  {
370  return;
371  }
372 
373  parallel = parallel && Pstream::parRun();
374 
375  const label nSlaves = (parallel ? Pstream::nProcs() : 0);
376 
377  if (Pstream::master())
378  {
379  os.writeKeyword(ensightFaces::key(etype));
380  os.write(nTotal);
381  os.newline();
382  }
383 
384  if (etype == ensightFaces::NSIDED)
385  {
386  // Face sizes (number of points per face)
387 
389 
390  if (Pstream::master())
391  {
392  os.writeLabels(send);
393 
394  for (int slave=1; slave < nSlaves; ++slave)
395  {
396  IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
397  labelList recv(fromSlave);
398 
399  os.writeLabels(recv);
400  }
401  }
402  else if (nSlaves)
403  {
404  OPstream toMaster
405  (
406  Pstream::commsTypes::scheduled,
407  Pstream::masterNo()
408  );
409 
410  toMaster << send;
411  }
412  }
413 
414 
415  // List of points id per face
416 
417  if (Pstream::master())
418  {
419  writeFaceList(os, faces);
420 
421  for (int slave=1; slave < nSlaves; ++slave)
422  {
423  IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
424  List<face> recv(fromSlave);
425 
426  writeFaceList(os, recv);
427  }
428  }
429  else if (nSlaves)
430  {
431  OPstream toMaster
432  (
433  Pstream::commsTypes::scheduled,
434  Pstream::masterNo()
435  );
436 
437  toMaster << faces;
438  }
439 }
440 
441 
443 (
444  ensightGeoFile& os,
445  const ensightFaces& part,
446  const faceUList& faces,
447  bool parallel
448 )
449 {
450  for (label typei=0; typei < ensightFaces::nTypes; ++typei)
451  {
452  const auto etype = ensightFaces::elemType(typei);
453 
455  (
456  os,
457  etype,
458  part.total(etype),
459  UIndirectList<face>(faces, part.faceIds(etype)),
460  parallel
461  );
462  }
463 }
464 
465 
467 (
468  ensightGeoFile& os,
469  const ensightFaces& part,
470  const faceUList& faces,
471  bool parallel
472 )
473 {
474  for (label typei=0; typei < ensightFaces::nTypes; ++typei)
475  {
476  const auto etype = ensightFaces::elemType(typei);
477 
479  (
480  os,
481  etype,
482  part.total(etype),
483  SubList<face>(faces, part.range(etype)),
484  parallel
485  );
486  }
487 }
488 
489 
490 // ************************************************************************* //
cell.H
Foam::OPstream
Output inter-processor communications stream.
Definition: OPstream.H:52
Foam::SubList
A List obtained as a section of another List.
Definition: SubList.H:53
face.H
polyMesh.H
Foam::ensightOutput::Detail::getPolysNPointsPerFace
labelList getPolysNPointsPerFace(const polyMesh &mesh, const labelUList &addr)
The number of points for each face of the poly elements.
Definition: ensightOutput.C:102
Foam::ensightFaces
Sorting/classification of faces (2D) into corresponding ensight types.
Definition: ensightFaces.H:68
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::ensightFaces::range
labelRange range(const elemType etype) const
Processor-local offset/size of element type.
Definition: ensightFacesI.H:70
Foam::ensightFaces::total
label total() const
The global size of all element types.
Definition: ensightFaces.C:130
Foam::ensightOutput::writeFaceConnectivity
void writeFaceConnectivity(ensightGeoFile &os, const ensightFaces::elemType etype, const label nTotal, const UIndirectList< face > &faces, bool parallel)
Definition: ensightOutput.C:360
Foam::ensightFile::writeLabels
void writeLabels(const UList< label > &list)
Write a list of integers.
Definition: ensightFile.C:372
Foam::ensightOutput::writeFaceConnectivityPresorted
void writeFaceConnectivityPresorted(ensightGeoFile &os, const ensightFaces &part, const faceUList &faces, bool parallel)
Write the presorted face connectivity for the part.
Definition: ensightOutput.C:467
Foam::ensightGeoFile
Specialized Ensight output with extra geometry file header.
Definition: ensightGeoFile.H:48
ensightOutput.H
faceId
label faceId(-1)
Foam::ensightFile::newline
void newline()
Add carriage return to ascii stream.
Definition: ensightFile.C:304
Foam::ensightFile::write
virtual bool write(const token &)
Writing token does not make sense.
Definition: ensightFile.H:176
Foam::ensightFaces::faceIds
const labelList & faceIds() const
Processor-local face ids of all elements.
Definition: ensightFacesI.H:76
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::cellShape
An analytical geometric cellShape.
Definition: cellShape.H:71
cellId
label cellId
Definition: interrogateWallPatches.H:67
Foam::ensightFaces::elemType
elemType
Supported ensight 'Face' element types.
Definition: ensightFaces.H:78
Foam::ensightOutput::Detail::getPolysNFaces
labelList getPolysNFaces(const polyMesh &mesh, const labelUList &addr)
The number of faces per poly element.
Definition: ensightOutput.C:79
f
labelList f(nPoints)
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:102
Foam::ensightGeoFile::writeKeyword
virtual Ostream & writeKeyword(const keyType &key)
Write keyword with trailing newline.
Definition: ensightGeoFile.C:83
Foam::UList< face >
Foam::ensightOutput::Detail::getFaceSizes
labelList getFaceSizes(const UList< face > &faces)
Return sizes of faces in the list.
Definition: ensightOutput.C:41
cellShape.H
Foam::UList::size
void size(const label n) noexcept
Override size to be inconsistent with allocated storage.
Definition: UListI.H:360
Foam::UIndirectList
A List with indirect addressing.
Definition: fvMatrix.H:109
Foam::IPstream
Input inter-processor communications stream.
Definition: IPstream.H:52
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:72
Foam::ensightOutput::writePolysPoints
void writePolysPoints(ensightGeoFile &os, const cellUList &meshCells, const labelUList &addr, const faceUList &meshFaces, const labelUList &faceOwner)
Write the point ids per poly element.
Definition: ensightOutput.C:238
ListOps.H
Various functions to operate on Lists.
Foam::ensightOutput::writeFaceList
void writeFaceList(ensightGeoFile &os, const UList< face > &faces)
Write list of faces.
Definition: ensightOutput.C:137
Foam::ensightOutput::writeCellShapes
void writeCellShapes(ensightGeoFile &os, const UList< cellShape > &shapes)
Write cell connectivity via cell shapes.
Definition: ensightOutput.C:173