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-2021 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 ensightOutput_H
39 #define 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 "DynamicList.H"
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 // Local definitions, could be relocated to ListListOps directly
58 
59 namespace Foam
60 {
61 namespace ListListOps
62 {
63 
64 //- Return the sizes of the sub-lists
65 template<class T, class Addr, class AccessOp>
67 (
68  const IndirectListBase<T, Addr>& lists,
69  AccessOp aop
70 )
71 {
72  labelList output(lists.size());
73  auto out = output.begin();
74 
75  for (const T& sub : lists)
76  {
77  *out = aop(sub).size();
78  ++out;
79  }
80 
81  return output;
82 }
83 
84 
85 //- Inplace renumber the values (not the indices) of a list of lists.
86 // Negative IntListType elements are left untouched.
87 template<class IntListType>
88 void inplaceRenumber
89 (
90  const labelUList& oldToNew,
91  IntListType& lists
92 )
93 {
94  for (auto& sub : lists)
95  {
96  for (auto& item : sub)
97  {
98  if (item >= 0)
99  {
100  item = oldToNew[item];
101  }
102  }
103  }
104 }
105 
106 } // End namespace ListListOps
107 } // End namespace Foam
108 
109 
110 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
111 
112 namespace Foam
113 {
114 
115 // Forward Declarations
116 class cellShape;
117 class polyMesh;
118 
119 namespace ensightOutput
120 {
121 
122 /*---------------------------------------------------------------------------*\
123  Geometry Output
124 \*---------------------------------------------------------------------------*/
125 
126 //- Write list of faces
127 void writeFaceList
128 (
129  ensightGeoFile& os,
130  const UList<face>& faces
131 );
132 
133 //- Write list of faces
134 void writeFaceList
135 (
136  ensightGeoFile& os,
137  const UIndirectList<face>& faces
138 );
139 
140 //- Write cell connectivity via cell shapes
141 void writeCellShapes
142 (
143  ensightGeoFile& os,
144  const UList<cellShape>& shapes
145 );
146 
147 
148 //- Write the point ids per poly element.
149 // Points have been already renumbered
150 void writePolysPoints
151 (
152  ensightGeoFile& os,
153  const cellUList& meshCells,
154  const labelUList& addr,
155  const faceUList& meshFaces,
156  const labelUList& faceOwner
157 );
158 
159 //- Write the point ids per poly element, with point renumbering
160 void writePolysPoints
161 (
162  ensightGeoFile& os,
163  const polyMesh& mesh,
164  const labelUList& addr,
165  const labelList& pointMap
166 );
167 
168 
169 //- Write the regular face connectivity for specified type and
170 //- and specified faces
172 (
173  ensightGeoFile& os,
174  const ensightFaces::elemType etype,
175  const label nTotal,
176  const UIndirectList<face>& faces,
177  bool parallel
178 );
179 
180 
181 //- Write the regular face connectivity for specified type
183 (
184  ensightGeoFile& os,
185  const ensightFaces::elemType etype,
186  const label nTotal,
187  const faceUList& faces,
188  bool parallel
189 );
190 
191 
192 //- Write the face connectivity for the part
194 (
195  ensightGeoFile& os,
196  const ensightFaces& part,
197  const faceUList& faces,
198  bool parallel
199 );
200 
201 
202 //- Write the \b presorted face connectivity for the part
203 // This is a special case when the list of faces is already in
204 // ensight sorted order
206 (
207  ensightGeoFile& os,
208  const ensightFaces& part,
209  const faceUList& faces,
210  bool parallel
211 );
212 
213 
214 /*---------------------------------------------------------------------------*\
215  Field Output
216 \*---------------------------------------------------------------------------*/
217 
218 //- Write a field of cell values as an indirect list,
219 //- using the cell ids from ensightCells
220 template<class Type>
221 bool writeField
222 (
223  ensightFile& os,
224  const Field<Type>& fld,
225  const ensightCells& part,
226  bool parallel
227 );
228 
229 //- Write a field of faces values as an indirect list,
230 //- using the face ids from ensightFaces
231 template<class Type>
232 bool writeField
233 (
234  ensightFile& os,
235  const Field<Type>& fld,
236  const ensightFaces& part,
237  bool parallel
238 );
239 
240 
241 /*---------------------------------------------------------------------------*\
242  Namespace ensightOutput::Detail
243 \*---------------------------------------------------------------------------*/
244 
245 //- \brief Implementation details and output backends that would not normally
246 //- be called directly by a user.
247 
248 namespace Detail
249 {
250 
251 //- Return sizes of faces in the list
252 labelList getFaceSizes(const UList<face>& faces);
253 
254 //- Return sizes of faces in the list
256 
257 //- The number of faces per poly element
258 labelList getPolysNFaces(const polyMesh& mesh, const labelUList& addr);
259 
260 //- The number of points for each face of the poly elements
262 
263 
264 //- Copy specified field component into a scalar buffer
265 //- works for various lists types. Must be adequately sized before calling
266 template<template<typename> class FieldContainer, class Type>
267 void copyComponent
268 (
269  List<scalar>& cmptBuffer,
270  const FieldContainer<Type>& input,
271  const direction cmpt
272 );
273 
274 
275 //- Write field content (component-wise)
276 template<template<typename> class FieldContainer, class Type>
278 (
279  ensightFile& os,
280  const FieldContainer<Type>& fld,
281  bool parallel
282 );
283 
284 
285 //- Write coordinates (component-wise) for the given part
286 template<template<typename> class FieldContainer>
287 bool writeCoordinates
288 (
290  const label partId,
291  const word& partName,
292  const label nPoints,
293  const FieldContainer<Foam::point>& fld,
294  bool parallel
295 );
296 
297 
298 //- Write field content (component-wise) for the given ensight element type
299 template<template<typename> class FieldContainer, class Type>
301 (
302  ensightFile& os,
303  const char* key,
304  const FieldContainer<Type>& fld,
305  bool parallel
306 );
307 
308 
309 //- Write a sub-field of faces values as an indirect list,
310 //- using the sub-list sizing information from ensightFaces
311 template<class Type>
313 (
314  ensightFile& os,
315  const Field<Type>& fld,
316  const ensightFaces& part,
317  bool parallel
318 );
319 
320 
321 //- Write a field of faces values as an indirect list,
322 //- using the face order from ensightFaces
323 template<class Type>
325 (
326  ensightFile& os,
327  const Field<Type>& fld,
328  const ensightFaces& part,
329  bool parallel
330 );
331 
332 
333 } // End namespace Detail
334 
335 
336 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
337 
338 } // End namespace ensightOutput
339 } // End namespace Foam
340 
341 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
342 
343 #ifdef NoRepository
344  #include "ensightOutputTemplates.C"
345 #endif
346 
347 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
348 
349 #endif
350 
351 // ************************************************************************* //
ensightOutputTemplates.C
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::output
static Ostream & output(Ostream &os, const IntRange< T > &range)
Definition: IntRanges.C:66
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
ensightFaces.H
ListListOps.H
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
Foam::ensightOutput::Detail::writeFieldComponents
bool writeFieldComponents(ensightFile &os, const char *key, const FieldContainer< Type > &fld, bool parallel)
Write field content (component-wise) for the given ensight element type.
Definition: ensightOutputTemplates.C:161
Foam::ListListOps::subSizes
labelList subSizes(const IndirectListBase< T, Addr > &lists, AccessOp aop)
Return the sizes of the sub-lists.
Definition: ensightOutput.H:67
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::ensightOutput::writeFaceConnectivity
void writeFaceConnectivity(ensightGeoFile &os, const ensightFaces::elemType etype, const label nTotal, const UIndirectList< face > &faces, bool parallel)
Definition: ensightOutput.C:369
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
Foam::ensightOutput::Detail::writeFaceLocalField
bool writeFaceLocalField(ensightFile &os, const Field< Type > &fld, const ensightFaces &part, bool parallel)
Definition: ensightOutputTemplates.C:247
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
Foam::Field
Generic templated field type.
Definition: Field.H:63
ensightPTraits.H
ensightFile.H
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
IndirectList.H
Foam::ListListOps::inplaceRenumber
void inplaceRenumber(const labelUList &oldToNew, IntListType &lists)
Inplace renumber the values (not the indices) of a list of lists.
Definition: ensightOutput.H:89
Foam::cellUList
UList< cell > cellUList
A UList of cells.
Definition: cellListFwd.H:44
fld
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))
Definition: gmvOutputLagrangian.H:23
cellListFwd.H
Forwards for various types of cell lists.
Foam::ensightOutput::Detail::writeFaceSubField
bool writeFaceSubField(ensightFile &os, const Field< Type > &fld, const ensightFaces &part, bool parallel)
Definition: ensightOutputTemplates.C:197
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::IndirectListBase::size
label size() const noexcept
The number of elements in the list.
Definition: IndirectListBase.H:125
Foam::ensightFile
Ensight output with specialized write() for strings, integers and floats. Correctly handles binary wr...
Definition: ensightFile.H:52
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
ensightGeoFile.H
Foam::ensightFaces::elemType
elemType
Supported ensight 'Face' element types.
Definition: ensightFaces.H:81
Foam::ensightOutput::writeField
bool writeField(ensightFile &os, const Field< Type > &fld, const ensightCells &part, bool parallel)
Definition: ensightOutputTemplates.C:313
Foam::ensightOutput::Detail::getPolysNFaces
labelList getPolysNFaces(const polyMesh &mesh, const labelUList &addr)
The number of faces per poly element.
Definition: ensightOutput.C:79
Foam::faceUList
UList< face > faceUList
A UList of faces.
Definition: faceListFwd.H:44
Foam::List< label >
Foam::UList< label >
Foam::direction
uint8_t direction
Definition: direction.H:52
Foam::input
static Istream & input(Istream &is, IntRange< T > &range)
Definition: IntRanges.C:55
Foam::ensightOutput::Detail::getFaceSizes
labelList getFaceSizes(const UList< face > &faces)
Return sizes of faces in the list.
Definition: ensightOutput.C:41
Foam::UIndirectList
A List with indirect addressing.
Definition: faMatrix.H:60
DynamicList.H
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
Foam::IndirectListBase
Base for lists with indirect addressing, templated on the list contents type and the addressing type....
Definition: IndirectListBase.H:56
ListOps.H
Various functions to operate on Lists.
faceListFwd.H
Forwards for various types of face lists.
Foam::labelUList
UList< label > labelUList
A UList of labels.
Definition: UList.H:85
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
Foam::ensightOutput::Detail::writeFieldContent
void writeFieldContent(ensightFile &os, const FieldContainer< Type > &fld, bool parallel)
Write field content (component-wise)
Definition: ensightOutputTemplates.C:62
Foam::ensightOutput::Detail::copyComponent
void copyComponent(List< scalar > &cmptBuffer, const FieldContainer< Type > &input, const direction cmpt)
Definition: ensightOutputTemplates.C:36
Foam::ensightOutput::Detail::writeCoordinates
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.
Definition: ensightOutputTemplates.C:136
ensightCells.H