Loading...
Searching...
No Matches
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 ensightOutput.txx
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
61namespace Foam
62{
63namespace ListListOps
64{
65
66//- Return the sizes of the sub-lists
67template<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.
89template<class IntListType>
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
114namespace Foam
115{
116
117// Forward Declarations
118class cellShape;
119class polyMesh;
120
121namespace ensightOutput
122{
123
124/*---------------------------------------------------------------------------*\
125 Geometry Output
126\*---------------------------------------------------------------------------*/
127
128//- Write list of faces
129void writeFaceList
130(
131 ensightGeoFile& os,
132 const UList<face>& faces,
133 const label pointOffset = 0
134);
135
136//- Write list of faces (indirect addressing)
137void 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)
145void writeFaceList
146(
147 ensightGeoFile& os,
148 const CompactListList<label>& faces,
149 const label pointOffset = 0
150);
151
152//- Write cell connectivity via cell shapes
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
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
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
237template<class Type>
238bool 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
258template<class Type>
259bool writeField
260(
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
280template<class Type>
281bool writeField
282(
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
303template<class Type>
304bool writeField
305(
308
311
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
331namespace Detail
332{
333
334//- Return sizes of faces in the list
336
337//- Return sizes of faces in the list
339
340//- The number of faces per poly element
341labelList 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
367template<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
378template<template<typename> class FieldContainer, class Type>
379void 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)
395template<template<typename> class FieldContainer>
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);
417
418//- Write field content (component-wise) for the given ensight element type.
419template<template<typename> class FieldContainer, class Type>
421(
424
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.
439template<template<typename> class FieldContainer, class Type>
441(
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
462template<class Type>
464(
467
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
484template<class Type>
486(
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
507template<class Type>
509(
512
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
528template<class Type>
530(
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);
547
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 "ensightOutput.txx"
561#endif
562
563// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
564
565#endif
566
567// ************************************************************************* //
Various functions to operate on Lists.
Forwards for various types of cell lists.
Info<< nl;Info<< "Write faMesh in vtk format:"<< nl;{ vtk::uindirectPatchWriter writer(aMesh.patch(), fileName(aMesh.time().globalPath()/vtkBaseFileName));writer.writeGeometry();globalIndex procAddr(aMesh.nFaces());labelList cellIDs;if(UPstream::master()) { cellIDs.resize(procAddr.totalSize());for(const labelRange &range :procAddr.ranges()) { auto slice=cellIDs.slice(range);slice=identity(range);} } writer.beginCellData(4);writer.writeProcIDs();writer.write("cellID", cellIDs);writer.write("area", aMesh.S().field());writer.write("normal", aMesh.faceAreaNormals());writer.beginPointData(1);writer.write("normal", aMesh.pointAreaNormals());Info<< " "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edges")));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
A packed storage of objects of type <T> using an offset table for access.
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
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.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
iterator begin() noexcept
Return an iterator to begin traversing the UList.
Definition UListI.H:410
An analytical geometric cellShape.
Definition cellShape.H:71
Sorting/classification of cells (3D) into corresponding ensight element types.
Sorting/classification of faces (2D) into corresponding ensight types.
elemType
Supported ensight 'Face' element types.
A variant of OFstream with specialised handling for Ensight writing of strings, integers and floats (...
Definition ensightFile.H:50
A variant of ensightFile (Ensight writing) that includes the extra geometry file header information.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
A class for handling words, derived from Foam::string.
Definition word.H:66
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
Forwards for various types of face lists.
label nPoints
Implementation details for various OpenFOAM classes.
Definition zoneSubSet.C:30
Various utility functions to work on Lists of Lists (usually resulting from 'gather'ing and combining...
labelList subSizes(const IndirectListBase< T, Addr > &lists, AccessOp aop)
Return the sizes of the sub-lists.
void inplaceRenumber(const labelUList &oldToNew, IntListType &lists)
Inplace renumber the values (not the indices) of a list of lists.
Implementation details and output backends that would not normally be called directly by a user.
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 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.
labelList getFaceSizes(const UList< face > &faces)
Return sizes of faces in the list.
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 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.
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....
labelList getPolysNFaces(const polyMesh &mesh, const labelUList &addr)
The number of faces per poly element.
CompactListList< label > getPolysFacePoints(const polyMesh &mesh, const labelUList &addr, const labelList &pointMap)
Generate 0-based point ids for each poly element face.
void writeLabelListList(ensightGeoFile &os, const labelUList &offsets, const labelUList &values, const label pointOffset)
Write CompactListList<label> by components.
A collection of functions for writing ensight file content.
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.
void writePolysPoints(ensightGeoFile &os, const cellUList &meshCells, const labelUList &addr, const faceUList &meshFaces, const labelUList &faceOwner)
Write the point ids per poly element.
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)
Write the regular face connectivity for specified type and and specified faces.
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.
DynamicList< float > floatBufferType
The list type used for component-wise buffering.
Namespace for OpenFOAM.
UList< cell > cellUList
UList of cell.
Definition cellListFwd.H:43
List< label > labelList
A List of labels.
Definition List.H:62
uint8_t direction
Definition direction.H:49
UList< label > labelUList
A UList of labels.
Definition UList.H:75
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
UList< face > faceUList
UList of faces.
Definition faceListFwd.H:43