ensightOutput.H
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) 2016-2022 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 Namespace
27  Foam::ensightOutput
28 
29 Description
30  A collection of functions for writing ensight file content.
31 
32 SourceFiles
33  ensightOutput.C
34  ensightOutputTemplates.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef Foam_ensightOutput_H
39 #define Foam_ensightOutput_H
40 
41 #include "ensightOutputFwd.H"
42 #include "ensightFile.H"
43 #include "ensightGeoFile.H"
44 #include "ensightCells.H"
45 #include "ensightFaces.H"
46 #include "ensightPTraits.H"
47 
48 #include "faceListFwd.H"
49 #include "cellListFwd.H"
50 
51 #include "ListOps.H"
52 #include "ListListOps.H"
53 #include "IndirectList.H"
54 #include "CompactListList.H"
55 #include "DynamicList.H"
56 
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58 
59 // Local definitions, could be relocated to ListListOps directly
60 
61 namespace Foam
62 {
63 namespace ListListOps
64 {
65 
66 //- Return the sizes of the sub-lists
67 template<class T, class Addr, class AccessOp>
69 (
70  const IndirectListBase<T, Addr>& lists,
71  AccessOp aop
72 )
73 {
74  labelList output(lists.size());
75  auto out = output.begin();
76 
77  for (const T& sub : lists)
78  {
79  *out = aop(sub).size();
80  ++out;
81  }
82 
83  return output;
84 }
85 
86 
87 //- Inplace renumber the values (not the indices) of a list of lists.
88 // Negative IntListType elements are left untouched.
89 template<class IntListType>
90 void inplaceRenumber
91 (
92  const labelUList& oldToNew,
93  IntListType& lists
94 )
95 {
96  for (auto& sub : lists)
97  {
98  for (auto& item : sub)
99  {
100  if (item >= 0)
101  {
102  item = oldToNew[item];
103  }
104  }
105  }
106 }
107 
108 } // End namespace ListListOps
109 } // End namespace Foam
110 
111 
112 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
113 
114 namespace Foam
115 {
116 
117 // Forward Declarations
118 class cellShape;
119 class polyMesh;
120 
121 namespace ensightOutput
122 {
123 
124 /*---------------------------------------------------------------------------*\
125  Geometry Output
126 \*---------------------------------------------------------------------------*/
127 
128 //- Write list of faces
129 void writeFaceList
130 (
131  ensightGeoFile& os,
132  const UList<face>& faces,
133  const label pointOffset = 0
134 );
135 
136 //- Write list of faces (indirect addressing)
137 void writeFaceList
138 (
139  ensightGeoFile& os,
140  const UIndirectList<face>& faces,
141  const label pointOffset = 0
142 );
143 
144 //- Write list of faces (stored in compact form)
145 void writeFaceList
146 (
147  ensightGeoFile& os,
148  const CompactListList<label>& faces,
149  const label pointOffset = 0
150 );
151 
152 //- Write cell connectivity via cell shapes
153 void writeCellShapes
154 (
155  ensightGeoFile& os,
156  const UList<cellShape>& shapes,
157  const label pointOffset = 0
158 );
159 
160 
161 //- Write the point ids per poly element.
162 // Points have been already renumbered
163 void writePolysPoints
164 (
165  ensightGeoFile& os,
166  const cellUList& meshCells,
167  const labelUList& addr,
168  const faceUList& meshFaces,
169  const labelUList& faceOwner
170 );
171 
172 //- Write the point ids per poly element, with point renumbering
173 void writePolysPoints
174 (
175  ensightGeoFile& os,
176  const polyMesh& mesh,
177  const labelUList& addr,
178  const labelList& pointMap
179 );
180 
181 
182 //- Write the regular face connectivity for specified type and
183 //- and specified faces
185 (
186  ensightGeoFile& os,
187  const ensightFaces::elemType etype,
188  const label nTotal,
189  const UIndirectList<face>& faces,
191  bool parallel
192 );
193 
194 
195 //- Write the regular face connectivity for specified type
197 (
198  ensightGeoFile& os,
199  const ensightFaces::elemType etype,
200  const label nTotal,
201  const faceUList& faces,
203  bool parallel
204 );
205 
206 
207 //- Write the face connectivity for the part
209 (
210  ensightGeoFile& os,
211  const ensightFaces& part,
212  const faceUList& faces,
214  bool parallel
215 );
216 
217 
218 //- Write the \b presorted face connectivity for the part
219 // This is a special case when the list of faces is already in
220 // ensight sorted order
222 (
223  ensightGeoFile& os,
224  const ensightFaces& part,
225  const faceUList& faces,
227  bool parallel
228 );
229 
230 
231 /*---------------------------------------------------------------------------*\
232  Field Output
233 \*---------------------------------------------------------------------------*/
234 
235 //- Write a field of cell values as an indirect list,
236 //- using the cell ids from ensightCells
237 template<class Type>
238 bool writeField
239 (
242 
244  ensightFile& os,
245 
247  const Field<Type>& fld,
248 
250  const ensightCells& part,
251 
253  bool parallel
254 );
255 
256 //- Write a field of faces values as an indirect list,
257 //- using the face ids from ensightFaces
258 template<class Type>
259 bool writeField
260 (
263 
265  ensightFile& os,
266 
268  const Field<Type>& fld,
269 
271  const ensightFaces& part,
272 
274  bool parallel
275 );
276 
277 
278 //- Write a field of cell values as an indirect list,
279 //- using the cell ids from ensightCells
280 template<class Type>
281 bool writeField
282 (
284  ensightFile& os,
285 
287  const Field<Type>& fld,
288 
290  const ensightCells& part,
291 
293  bool parallel
294 )
295 {
297  return ensightOutput::writeField(scratch, os, fld, part, parallel);
298 }
299 
300 
301 //- Write a field of faces values as an indirect list,
302 //- using the face ids from ensightFaces
303 template<class Type>
304 bool writeField
305 (
307  ensightFile& os,
308 
310  const Field<Type>& fld,
313  const ensightFaces& part,
314 
316  bool parallel
317 )
318 {
320  return ensightOutput::writeField(scratch, os, fld, part, parallel);
321 }
322 
323 
324 /*---------------------------------------------------------------------------*\
325  Namespace ensightOutput::Detail
326 \*---------------------------------------------------------------------------*/
327 
328 //- \brief Implementation details and output backends that would not normally
329 //- be called directly by a user.
330 
331 namespace Detail
332 {
333 
334 //- Return sizes of faces in the list
335 labelList getFaceSizes(const UList<face>& faces);
337 //- Return sizes of faces in the list
339 
340 //- The number of faces per poly element
341 labelList getPolysNFaces(const polyMesh& mesh, const labelUList& addr);
342 
343 //- The number of points for each face of the poly elements
345 
346 //- Generate 0-based point ids for each poly element face
347 // The returned CompactListList is divided per output face
349 (
350  const polyMesh& mesh,
351  const labelUList& addr,
352  const labelList& pointMap
353 );
354 
355 
356 //- Write CompactListList<label> by components
358 (
360  const labelUList& offsets,
361  const labelUList& values,
362  const label pointOffset
363 );
365 
366 //- Write a list of faces or cell shapes with one-entity per line
367 template<class LabelListListType>
369 (
371  const LabelListListType& listOfLists,
372  const label pointOffset
373 );
374 
375 
376 //- Copy specified field component into a scalar buffer.
377 //- Works for various lists types. Must be adequately sized before calling
378 template<template<typename> class FieldContainer, class Type>
379 void copyComponent
380 (
382  const FieldContainer<Type>& input,
383 
385  const direction cmpt,
386 
388  UList<float>& cmptBuffer
389 );
390 
391 
392 //- Write coordinates (component-wise) for the given part.
393 //
394 // Has internal check for (nPoints != 0)
395 template<template<typename> class FieldContainer>
396 bool writeCoordinates
397 (
400 
402  const label partId,
403 
405  const word& partName,
406 
408  const label nPoints,
409 
411  const FieldContainer<Foam::point>& fld,
412 
414  bool parallel
415 );
416 
417 
418 //- Write field content (component-wise) for the given ensight element type.
419 template<template<typename> class FieldContainer, class Type>
421 (
424 
426  ensightFile& os,
427 
429  const char* key,
430 
432  const FieldContainer<Type>& fld,
433 
435  bool parallel
436 );
437 
438 //- Write field content (component-wise) for the given ensight element type.
439 template<template<typename> class FieldContainer, class Type>
441 (
443  ensightFile& os,
444 
446  const char* key,
447 
449  const FieldContainer<Type>& fld,
450 
452  bool parallel
453 )
454 {
456  Detail::writeFieldComponents(scratch, os, key, fld, parallel);
457 }
458 
459 
460 //- Write a sub-field of faces values as an indirect list,
461 //- using the sub-list sizing information from ensightFaces
462 template<class Type>
464 (
467 
469  ensightFile& os,
470 
472  const Field<Type>& fld,
473 
475  const ensightFaces& part,
476 
478  bool parallel
479 );
480 
481 
482 //- Write a sub-field of faces values as an indirect list,
483 //- using the sub-list sizing information from ensightFaces
484 template<class Type>
486 (
488  ensightFile& os,
489 
491  const Field<Type>& fld,
492 
494  const ensightFaces& part,
495 
497  bool parallel
498 )
499 {
501  return Detail::writeFaceSubField(scratch, os, fld, part, parallel);
502 }
503 
504 
505 //- Write a field of faces values as an indirect list,
506 //- using the face order from ensightFaces
507 template<class Type>
509 (
512 
514  ensightFile& os,
515 
517  const Field<Type>& fld,
518 
520  const ensightFaces& part,
521 
523  bool parallel
524 );
525 
526 //- Write a field of faces values as an indirect list,
527 //- using the face order from ensightFaces
528 template<class Type>
530 (
532  ensightFile& os,
533 
535  const Field<Type>& fld,
536 
538  const ensightFaces& part,
539 
541  bool parallel
542 )
543 {
545  return Detail::writeFaceLocalField(scratch, os, fld, part, parallel);
546 }
548 
549 } // End namespace Detail
550 
551 
552 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
553 
554 } // End namespace ensightOutput
555 } // End namespace Foam
556 
557 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
558 
559 #ifdef NoRepository
560  #include "ensightOutputTemplates.C"
561 #endif
562 
563 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
564 
565 #endif
566 
567 // ************************************************************************* //
Ensight output with specialized write() for strings, integers and floats. Correctly handles binary wr...
Definition: ensightFile.H:46
uint8_t direction
Definition: direction.H:46
void writeFaceConnectivity(ensightGeoFile &os, const ensightFaces::elemType etype, const label nTotal, const UIndirectList< face > &faces, bool parallel)
Write the regular face connectivity for specified type and and specified faces.
Specialized Ensight output with extra geometry file header.
Sorting/classification of faces (2D) into corresponding ensight types.
Definition: ensightFaces.H:66
bool writeFaceSubField(ensightOutput::floatBufferType &scratch, ensightFile &os, const Field< Type > &fld, const ensightFaces &part, bool parallel)
Write a sub-field of faces values as an indirect list, using the sub-list sizing information from ens...
void writeFaceConnectivityPresorted(ensightGeoFile &os, const ensightFaces &part, const faceUList &faces, bool parallel)
Write the presorted face connectivity for the part.
bool writeFaceLocalField(ensightOutput::floatBufferType &scratch, ensightFile &os, const Field< Type > &fld, const ensightFaces &part, bool parallel)
Write a field of faces values as an indirect list, using the face order from ensightFaces.
labelList getPolysNPointsPerFace(const polyMesh &mesh, const labelUList &addr)
The number of points for each face of the poly elements.
bool writeField(ensightOutput::floatBufferType &scratch, ensightFile &os, const Field< Type > &fld, const ensightCells &part, bool parallel)
Write a field of cell values as an indirect list, using the cell ids from ensightCells.
Base for lists with indirect addressing, templated on the list contents type and the addressing type...
void writeFaceList(ensightGeoFile &os, const UList< face > &faces, const label pointOffset=0)
Write list of faces.
UList< label > labelUList
A UList of labels.
Definition: UList.H:78
Various functions to operate on Lists.
CompactListList< label > getPolysFacePoints(const polyMesh &mesh, const labelUList &addr, const labelList &pointMap)
Generate 0-based point ids for each poly element face.
void inplaceRenumber(const labelUList &oldToNew, IntListType &lists)
Inplace renumber the values (not the indices) of a list of lists.
Definition: ensightOutput.H:92
Forwards for various types of cell lists.
void copyComponent(const FieldContainer< Type > &input, const direction cmpt, UList< float > &cmptBuffer)
Copy specified field component into a scalar buffer. Works for various lists types. Must be adequately sized before calling.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:164
labelList subSizes(const IndirectListBase< T, Addr > &lists, AccessOp aop)
Return the sizes of the sub-lists.
Definition: ensightOutput.H:67
UList< cell > cellUList
UList of cell.
Definition: cellListFwd.H:43
dynamicFvMesh & mesh
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:51
void writeFieldComponents(ensightOutput::floatBufferType &scratch, ensightFile &os, const char *key, const FieldContainer< Type > &fld, bool parallel)
Write field content (component-wise) for the given ensight element type.
UList< face > faceUList
UList of faces.
Definition: faceListFwd.H:43
Generic templated field type.
Definition: Field.H:62
A class for handling words, derived from Foam::string.
Definition: word.H:63
label nPoints
static Istream & input(Istream &is, IntRange< T > &range)
Definition: IntRanges.C:33
label size() const noexcept
The number of elements in the list.
DynamicList< float > floatBufferType
The list type used for component-wise buffering.
A packed storage of objects of type <T> using an offset table for access.
void writePolysPoints(ensightGeoFile &os, const cellUList &meshCells, const labelUList &addr, const faceUList &meshFaces, const labelUList &faceOwner)
Write the point ids per poly element.
OBJstream os(runTime.globalPath()/outputName)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
elemType
Supported ensight &#39;Face&#39; element types.
Definition: ensightFaces.H:79
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Forwards for various types of face lists.
labelList getPolysNFaces(const polyMesh &mesh, const labelUList &addr)
The number of faces per poly element.
Definition: ensightOutput.C:89
void writeLabelListList(ensightGeoFile &os, const labelUList &offsets, const labelUList &values, const label pointOffset)
Write CompactListList<label> by components.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:103
labelList getFaceSizes(const UList< face > &faces)
Return sizes of faces in the list.
Definition: ensightOutput.C:51
A List with indirect addressing. Like IndirectList but does not store addressing. ...
Definition: faMatrix.H:56
static Ostream & output(Ostream &os, const IntRange< T > &range)
Definition: IntRanges.C:44
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
List< label > labelList
A List of labels.
Definition: List.H:62
Namespace for OpenFOAM.
bool writeCoordinates(ensightGeoFile &os, const label partId, const word &partName, const label nPoints, const FieldContainer< Foam::point > &fld, bool parallel)
Write coordinates (component-wise) for the given part.
void writeCellShapes(ensightGeoFile &os, const UList< cellShape > &shapes, const label pointOffset=0)
Write cell connectivity via cell shapes.