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 (
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 (
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 (
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 (
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 (
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 (
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 IntRange<int> senders =
294  (
295  parallel
296  ? Pstream::subProcs()
297  : IntRange<int>()
298  );
299 
300  if (Pstream::master())
301  {
302  os.writeKeyword(ensightFaces::key(etype));
303  os.write(nTotal);
304  os.newline();
305  }
306 
307  if (etype == ensightFaces::NSIDED)
308  {
309  // Face sizes (number of points per face)
310 
312 
313  if (Pstream::master())
314  {
315  // Main
316  os.writeLabels(send);
317 
318  // Others
319  for (const int proci : senders)
320  {
321  IPstream fromOther(Pstream::commsTypes::scheduled, proci);
322  labelList recv(fromOther);
323 
324  os.writeLabels(recv);
325  }
326  }
327  else if (senders)
328  {
329  OPstream toMaster
330  (
331  Pstream::commsTypes::scheduled,
332  Pstream::masterNo()
333  );
334 
335  toMaster << send;
336  }
337  }
338 
339 
340  // List of points id for each face
341  if (Pstream::master())
342  {
343  // Main
344  writeFaceList(os, faces);
345 
346  // Others
347  for (const int proci : senders)
348  {
349  IPstream fromOther(Pstream::commsTypes::scheduled, proci);
350  List<face> recv(fromOther);
351 
352  writeFaceList(os, recv);
353  }
354  }
355  else if (senders)
356  {
357  OPstream toMaster
358  (
359  Pstream::commsTypes::scheduled,
360  Pstream::masterNo()
361  );
362 
363  toMaster << faces;
364  }
365 }
366 
367 
369 (
371  const ensightFaces::elemType etype,
372  const label nTotal,
373  const UIndirectList<face>& faces,
374  bool parallel
375 )
376 {
377  if (!nTotal)
378  {
379  return;
380  }
381 
382  parallel = parallel && Pstream::parRun();
383 
384  const IntRange<int> senders =
385  (
386  parallel
387  ? Pstream::subProcs()
388  : IntRange<int>()
389  );
390 
391 
392  if (Pstream::master())
393  {
394  os.writeKeyword(ensightFaces::key(etype));
395  os.write(nTotal);
396  os.newline();
397  }
398 
399  if (etype == ensightFaces::NSIDED)
400  {
401  // Face sizes (number of points per face)
402 
404 
405  if (Pstream::master())
406  {
407  // Main
408  os.writeLabels(send);
409 
410  // Others
411  for (const int proci : senders)
412  {
413  IPstream fromOther(Pstream::commsTypes::scheduled, proci);
414  labelList recv(fromOther);
415 
416  os.writeLabels(recv);
417  }
418  }
419  else if (senders)
420  {
421  OPstream toMaster
422  (
423  Pstream::commsTypes::scheduled,
424  Pstream::masterNo()
425  );
426 
427  toMaster << send;
428  }
429  }
430 
431 
432  // List of points id per face
433 
434  if (Pstream::master())
435  {
436  // Main
437  writeFaceList(os, faces);
438 
439  // Others
440  for (const int proci : senders)
441  {
442  IPstream fromOther(Pstream::commsTypes::scheduled, proci);
443  List<face> recv(fromOther);
444 
445  writeFaceList(os, recv);
446  }
447  }
448  else if (senders)
449  {
450  OPstream toMaster
451  (
452  Pstream::commsTypes::scheduled,
453  Pstream::masterNo()
454  );
455 
456  toMaster << faces;
457  }
458 }
459 
460 
462 (
464  const ensightFaces& part,
465  const faceUList& faces,
466  bool parallel
467 )
468 {
469  for (label typei=0; typei < ensightFaces::nTypes; ++typei)
470  {
471  const auto etype = ensightFaces::elemType(typei);
472 
474  (
475  os,
476  etype,
477  part.total(etype),
478  UIndirectList<face>(faces, part.faceIds(etype)),
479  parallel
480  );
481  }
482 }
483 
484 
486 (
488  const ensightFaces& part,
489  const faceUList& faces,
490  bool parallel
491 )
492 {
493  for (label typei=0; typei < ensightFaces::nTypes; ++typei)
494  {
495  const auto etype = ensightFaces::elemType(typei);
496 
498  (
499  os,
500  etype,
501  part.total(etype),
502  SubList<face>(faces, part.range(etype)),
503  parallel
504  );
505  }
506 }
507 
508 
509 // ************************************************************************* //
Foam::ensightFaces::faceIds
const labelList & faceIds() const noexcept
Processor-local face ids of all elements.
Definition: ensightFacesI.H:79
cell.H
Foam::IntRange
An interval of (signed) integers defined by a start and a size.
Definition: IntRange.H:63
Foam::OPstream
Output inter-processor communications stream.
Definition: OPstream.H:53
Foam::SubList
A List obtained as a section of another List.
Definition: SubList.H:54
Foam::glTF::key
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:108
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:71
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:73
Foam::ensightFaces::total
label total() const
The global size of all element types.
Definition: ensightFaces.C:136
Foam::ensightOutput::writeFaceConnectivity
void writeFaceConnectivity(ensightGeoFile &os, const ensightFaces::elemType etype, const label nTotal, const UIndirectList< face > &faces, bool parallel)
Definition: ensightOutput.C:369
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:486
Foam::ensightGeoFile
Specialized Ensight output with extra geometry file header.
Definition: ensightGeoFile.H:48
ensightOutput.H
faceId
label faceId(-1)
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::cellShape
An analytical geometric cellShape.
Definition: cellShape.H:69
cellId
label cellId
Definition: interrogateWallPatches.H:67
Foam::ensightFaces::elemType
elemType
Supported ensight 'Face' element types.
Definition: ensightFaces.H:81
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: BitOps.H:63
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::UIndirectList
A List with indirect addressing.
Definition: faMatrix.H:60
Foam::IPstream
Input inter-processor communications stream.
Definition: IPstream.H:53
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::UList::size
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
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