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-------------------------------------------------------------------------------
10License
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
26Namespace
27 Foam::ensightOutput
28
29Description
30 A collection of functions for writing ensight file content.
31
32SourceFiles
33 ensightOutput.C
34 ensightOutputTemplates.C
35
36\*---------------------------------------------------------------------------*/
37
38#ifndef Foam_ensightOutput_H
39#define Foam_ensightOutput_H
40
41#include "ensightFile.H"
42#include "ensightGeoFile.H"
43#include "ensightCells.H"
44#include "ensightFaces.H"
45#include "ensightPTraits.H"
46
47#include "faceListFwd.H"
48#include "cellListFwd.H"
49
50#include "ListOps.H"
51#include "ListListOps.H"
52#include "IndirectList.H"
53#include "CompactListList.H"
54#include "DynamicList.H"
55
56// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57
58// Local definitions, could be relocated to ListListOps directly
59
60namespace Foam
61{
62namespace ListListOps
63{
64
65//- Return the sizes of the sub-lists
66template<class T, class Addr, class AccessOp>
68(
69 const IndirectListBase<T, Addr>& lists,
70 AccessOp aop
71)
72{
73 labelList output(lists.size());
74 auto out = output.begin();
75
76 for (const T& sub : lists)
77 {
78 *out = aop(sub).size();
79 ++out;
80 }
81
82 return output;
83}
84
85
86//- Inplace renumber the values (not the indices) of a list of lists.
87// Negative IntListType elements are left untouched.
88template<class IntListType>
90(
91 const labelUList& oldToNew,
92 IntListType& lists
93)
94{
95 for (auto& sub : lists)
96 {
97 for (auto& item : sub)
98 {
99 if (item >= 0)
100 {
101 item = oldToNew[item];
102 }
103 }
104 }
105}
106
107} // End namespace ListListOps
108} // End namespace Foam
109
110
111// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
112
113namespace Foam
114{
115
116// Forward Declarations
117class cellShape;
118class polyMesh;
119
120namespace ensightOutput
121{
122
123/*---------------------------------------------------------------------------*\
124 Geometry Output
125\*---------------------------------------------------------------------------*/
126
127//- Write list of faces
128void writeFaceList
129(
130 ensightGeoFile& os,
131 const UList<face>& faces,
132 const label pointOffset = 0
133);
134
135//- Write list of faces (indirect addressing)
136void writeFaceList
137(
138 ensightGeoFile& os,
139 const UIndirectList<face>& faces,
140 const label pointOffset = 0
141);
142
143//- Write list of faces (stored in compact form)
144void writeFaceList
145(
146 ensightGeoFile& os,
147 const CompactListList<label>& faces,
148 const label pointOffset = 0
149);
150
151//- Write cell connectivity via cell shapes
153(
154 ensightGeoFile& os,
155 const UList<cellShape>& shapes,
156 const label pointOffset = 0
157);
158
159
160//- Write the point ids per poly element.
161// Points have been already renumbered
163(
164 ensightGeoFile& os,
165 const cellUList& meshCells,
166 const labelUList& addr,
167 const faceUList& meshFaces,
168 const labelUList& faceOwner
169);
170
171//- Write the point ids per poly element, with point renumbering
173(
174 ensightGeoFile& os,
175 const polyMesh& mesh,
176 const labelUList& addr,
177 const labelList& pointMap
178);
179
180
181//- Write the regular face connectivity for specified type and
182//- and specified faces
184(
185 ensightGeoFile& os,
186 const ensightFaces::elemType etype,
187 const label nTotal,
188 const UIndirectList<face>& faces,
189 bool parallel
190);
191
192
193//- Write the regular face connectivity for specified type
195(
196 ensightGeoFile& os,
197 const ensightFaces::elemType etype,
198 const label nTotal,
199 const faceUList& faces,
200 bool parallel
201);
202
203
204//- Write the face connectivity for the part
206(
207 ensightGeoFile& os,
208 const ensightFaces& part,
209 const faceUList& faces,
210 bool parallel
211);
212
213
214//- Write the \b presorted face connectivity for the part
215// This is a special case when the list of faces is already in
216// ensight sorted order
218(
219 ensightGeoFile& os,
220 const ensightFaces& part,
221 const faceUList& faces,
222 bool parallel
223);
224
225
226/*---------------------------------------------------------------------------*\
227 Field Output
228\*---------------------------------------------------------------------------*/
229
230//- Write a field of cell values as an indirect list,
231//- using the cell ids from ensightCells
232template<class Type>
233bool writeField
234(
235 ensightFile& os,
236 const Field<Type>& fld,
237 const ensightCells& part,
238 bool parallel
239);
240
241//- Write a field of faces values as an indirect list,
242//- using the face ids from ensightFaces
243template<class Type>
244bool writeField
245(
246 ensightFile& os,
247 const Field<Type>& fld,
248 const ensightFaces& part,
249 bool parallel
250);
251
252
253/*---------------------------------------------------------------------------*\
254 Namespace ensightOutput::Detail
255\*---------------------------------------------------------------------------*/
256
257//- \brief Implementation details and output backends that would not normally
258//- be called directly by a user.
259
260namespace Detail
261{
262
263//- Return sizes of faces in the list
265
266//- Return sizes of faces in the list
268
269//- The number of faces per poly element
270labelList getPolysNFaces(const polyMesh& mesh, const labelUList& addr);
271
272//- The number of points for each face of the poly elements
274
275//- Generate 0-based point ids for each poly element face
276// The returned CompactListList is divided per output face
278(
279 const polyMesh& mesh,
280 const labelUList& addr,
281 const labelList& pointMap
282);
283
284
285//- Write CompactListList<label> by components
287(
289 const labelUList& offsets,
290 const labelUList& values,
291 const label pointOffset
292);
293
294
295//- Write a list of faces or cell shapes with one-entity per line
296template<class LabelListListType>
298(
300 const LabelListListType& listOfLists,
301 const label pointOffset
302);
303
304
305//- Copy specified field component into a scalar buffer
306//- works for various lists types. Must be adequately sized before calling
307template<template<typename> class FieldContainer, class Type>
308void copyComponent
309(
310 List<scalar>& cmptBuffer,
311 const FieldContainer<Type>& input,
312 const direction cmpt
313);
314
315
316//- Write field content (component-wise)
317template<template<typename> class FieldContainer, class Type>
319(
321 const FieldContainer<Type>& fld,
322 bool parallel
323);
324
325
326//- Write coordinates (component-wise) for the given part
327template<template<typename> class FieldContainer>
329(
331 const label partId,
332 const word& partName,
333 const label nPoints,
334 const FieldContainer<Foam::point>& fld,
335 bool parallel
336);
337
338
339//- Write field content (component-wise) for the given ensight element type
340template<template<typename> class FieldContainer, class Type>
342(
344 const char* key,
345 const FieldContainer<Type>& fld,
346 bool parallel
347);
348
349
350//- Write a sub-field of faces values as an indirect list,
351//- using the sub-list sizing information from ensightFaces
352template<class Type>
354(
356 const Field<Type>& fld,
357 const ensightFaces& part,
358 bool parallel
359);
360
361
362//- Write a field of faces values as an indirect list,
363//- using the face order from ensightFaces
364template<class Type>
366(
368 const Field<Type>& fld,
369 const ensightFaces& part,
370 bool parallel
371);
372
373
374} // End namespace Detail
375
376
377// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
378
379} // End namespace ensightOutput
380} // End namespace Foam
381
382// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
383
384#ifdef NoRepository
385 #include "ensightOutputTemplates.C"
386#endif
387
388// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
389
390#endif
391
392// ************************************************************************* //
Various functions to operate on Lists.
Forwards for various types of cell lists.
Info<< nl<< "Wrote faMesh in vtk format: "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.mesh().time().globalPath()/"finiteArea-edges"));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
A packed storage unstructured matrix of objects of type <T> using an offset table for access.
Generic templated field type.
Definition: Field.H:82
Base for lists with indirect addressing, templated on the list contents type and the addressing type....
label size() const noexcept
The number of elements in the list.
A List with indirect addressing. Like IndirectList but does not store addressing.
Definition: IndirectList.H:79
Sorting/classification of faces (2D) into corresponding ensight types.
Definition: ensightFaces.H:75
elemType
Supported ensight 'Face' element types.
Definition: ensightFaces.H:83
Ensight output with specialized write() for strings, integers and floats. Correctly handles binary wr...
Definition: ensightFile.H:55
Specialized Ensight output with extra geometry file header.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
A class for handling words, derived from Foam::string.
Definition: word.H:68
const volScalarField & T
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
Forwards for various types of face lists.
label nPoints
labelList subSizes(const IndirectListBase< T, Addr > &lists, AccessOp aop)
Return the sizes of the sub-lists.
Definition: ensightOutput.H:68
void inplaceRenumber(const labelUList &oldToNew, IntListType &lists)
Inplace renumber the values (not the indices) of a list of lists.
Definition: ensightOutput.H:90
labelList getFaceSizes(const UList< face > &faces)
Return sizes of faces in the list.
Definition: ensightOutput.C:41
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.
bool writeFaceSubField(ensightFile &os, const Field< Type > &fld, const ensightFaces &part, bool parallel)
labelList getPolysNPointsPerFace(const polyMesh &mesh, const labelUList &addr)
The number of points for each face of the poly elements.
labelList getPolysNFaces(const polyMesh &mesh, const labelUList &addr)
The number of faces per poly element.
Definition: ensightOutput.C:79
bool writeFieldComponents(ensightFile &os, const char *key, const FieldContainer< Type > &fld, bool parallel)
Write field content (component-wise) for the given ensight element type.
void copyComponent(List< scalar > &cmptBuffer, const FieldContainer< Type > &input, const direction cmpt)
CompactListList< label > getPolysFacePoints(const polyMesh &mesh, const labelUList &addr, const labelList &pointMap)
Generate 0-based point ids for each poly element face.
void writeFieldContent(ensightFile &os, const FieldContainer< Type > &fld, bool parallel)
Write field content (component-wise)
void writeLabelListList(ensightGeoFile &os, const labelUList &offsets, const labelUList &values, const label pointOffset)
Write CompactListList<label> by components.
bool writeFaceLocalField(ensightFile &os, const Field< Type > &fld, const ensightFaces &part, bool parallel)
void writePolysPoints(ensightGeoFile &os, const cellUList &meshCells, const labelUList &addr, const faceUList &meshFaces, const labelUList &faceOwner)
Write the point ids per poly element.
bool writeField(ensightFile &os, const Field< Type > &fld, const ensightCells &part, bool parallel)
void writeFaceConnectivityPresorted(ensightGeoFile &os, const ensightFaces &part, const faceUList &faces, bool parallel)
Write the presorted face connectivity for the part.
void writeFaceConnectivity(ensightGeoFile &os, const ensightFaces::elemType etype, const label nTotal, const UIndirectList< face > &faces, bool parallel)
void writeCellShapes(ensightGeoFile &os, const UList< cellShape > &shapes, const label pointOffset=0)
Write cell connectivity via cell shapes.
void writeFaceList(ensightGeoFile &os, const UList< face > &faces, const label pointOffset=0)
Write list of faces.
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: List.H:66
static Istream & input(Istream &is, IntRange< T > &range)
Definition: IntRanges.C:55
UList< cell > cellUList
A UList of cells.
Definition: cellListFwd.H:46
UList< face > faceUList
A UList of faces.
Definition: faceListFwd.H:46
static Ostream & output(Ostream &os, const IntRange< T > &range)
Definition: IntRanges.C:66
uint8_t direction
Definition: direction.H:56
UList< label > labelUList
A UList of labels.
Definition: UList.H:85