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-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 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 
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 
56 // Local definitions, could be relocated to ListListOps directly
57 
58 namespace Foam
59 {
60 namespace ListListOps
61 {
62 
63 //- Return the sizes of the sub-lists
64 template<class T, class Addr, class AccessOp>
66 (
67  const IndirectListBase<T, Addr>& lists,
68  AccessOp aop
69 )
70 {
71  labelList output(lists.size());
72  auto out = output.begin();
73 
74  for (const T& sub : lists)
75  {
76  *out = aop(sub).size();
77  ++out;
78  }
79 
80  return output;
81 }
82 
83 
84 //- Inplace renumber the values (not the indices) of a list of lists.
85 // Negative IntListType elements are left untouched.
86 template<class IntListType>
87 void inplaceRenumber
88 (
89  const labelUList& oldToNew,
90  IntListType& lists
91 )
92 {
93  for (auto& sub : lists)
94  {
95  for (auto& item : sub)
96  {
97  if (item >= 0)
98  {
99  item = oldToNew[item];
100  }
101  }
102  }
103 }
104 
105 } // End namespace ListListOps
106 } // End namespace Foam
107 
108 
109 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
110 
111 namespace Foam
112 {
113 
114 // Forward Declarations
115 class cellShape;
116 class polyMesh;
117 
118 namespace ensightOutput
119 {
120 
121 /*---------------------------------------------------------------------------*\
122  Geometry Output
123 \*---------------------------------------------------------------------------*/
124 
125 //- Write list of faces
126 void writeFaceList
127 (
128  ensightGeoFile& os,
129  const UList<face>& faces
130 );
131 
132 //- Write list of faces
133 void writeFaceList
134 (
135  ensightGeoFile& os,
136  const UIndirectList<face>& faces
137 );
138 
139 //- Write cell connectivity via cell shapes
140 void writeCellShapes
141 (
142  ensightGeoFile& os,
143  const UList<cellShape>& shapes
144 );
145 
146 
147 //- Write the point ids per poly element.
148 // Points have been already renumbered
149 void writePolysPoints
150 (
151  ensightGeoFile& os,
152  const cellUList& meshCells,
153  const labelUList& addr,
154  const faceUList& meshFaces,
155  const labelUList& faceOwner
156 );
157 
158 //- Write the point ids per poly element, with point renumbering
159 void writePolysPoints
160 (
161  ensightGeoFile& os,
162  const polyMesh& mesh,
163  const labelUList& addr,
164  const labelList& pointMap
165 );
166 
167 
168 //- Write the regular face connectivity for specified type and
169 //- and specified faces
171 (
172  ensightGeoFile& os,
173  const ensightFaces::elemType etype,
174  const label nTotal,
175  const UIndirectList<face>& faces,
176  bool parallel
177 );
178 
179 
180 //- Write the regular face connectivity for specified type
182 (
183  ensightGeoFile& os,
184  const ensightFaces::elemType etype,
185  const label nTotal,
186  const faceUList& faces,
187  bool parallel
188 );
189 
190 
191 //- Write the face connectivity for the part
193 (
194  ensightGeoFile& os,
195  const ensightFaces& part,
196  const faceUList& faces,
197  bool parallel
198 );
199 
200 
201 //- Write the \b presorted face connectivity for the part
202 // This is a special case when the list of faces is already in
203 // ensight sorted order
205 (
206  ensightGeoFile& os,
207  const ensightFaces& part,
208  const faceUList& faces,
209  bool parallel
210 );
211 
212 
213 /*---------------------------------------------------------------------------*\
214  Field Output
215 \*---------------------------------------------------------------------------*/
216 
217 //- Write a field of cell values as an indirect list,
218 //- using the cell ids from ensightCells
219 template<class Type>
220 bool writeField
221 (
222  ensightFile& os,
223  const Field<Type>& fld,
224  const ensightCells& part,
225  bool parallel
226 );
227 
228 //- Write a field of faces values as an indirect list,
229 //- using the face ids from ensightFaces
230 template<class Type>
231 bool writeField
232 (
233  ensightFile& os,
234  const Field<Type>& fld,
235  const ensightFaces& part,
236  bool parallel
237 );
238 
239 
240 /*---------------------------------------------------------------------------*\
241  Namespace ensightOutput::Detail
242 \*---------------------------------------------------------------------------*/
243 
244 //- \brief Implementation details and output backends that would not normally
245 //- be called directly by a user.
246 
247 namespace Detail
248 {
249 
250 //- Return sizes of faces in the list
251 labelList getFaceSizes(const UList<face>& faces);
252 
253 //- Return sizes of faces in the list
255 
256 //- The number of faces per poly element
257 labelList getPolysNFaces(const polyMesh& mesh, const labelUList& addr);
258 
259 //- The number of points for each face of the poly elements
261 
262 
263 //- Copy specified field component into a scalarField
264 // works for various lists types
265 template<template<typename> class FieldContainer, class Type>
266 void copyComponent
267 (
268  scalarField& res,
269  const FieldContainer<Type>& input,
270  const direction cmpt
271 );
272 
273 
274 //- Write coordinates (component-wise) for the given part
275 template<template<typename> class FieldContainer>
276 bool writeCoordinates
277 (
278  ensightGeoFile& os,
279  const label partId,
280  const word& partName,
281  const label nPoints,
282  const FieldContainer<Foam::point>& fld,
283  bool parallel
284 );
285 
286 
287 //- Write field content (component-wise) for the given ensight element type
288 template<template<typename> class FieldContainer, class Type>
290 (
291  ensightFile& os,
292  const char* key,
293  const FieldContainer<Type>& fld,
294  bool parallel
295 );
296 
297 
298 //- Write a sub-field of faces values as an indirect list,
299 //- using the sub-list sizing information from ensightFaces
300 template<class Type>
302 (
303  ensightFile& os,
304  const Field<Type>& fld,
305  const ensightFaces& part,
306  bool parallel
307 );
308 
309 
310 } // End namespace Detail
311 
312 
313 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
314 
315 } // End namespace ensightOutput
316 } // End namespace Foam
317 
318 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
319 
320 #ifdef NoRepository
321  #include "ensightOutputTemplates.C"
322 #endif
323 
324 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
325 
326 #endif
327 
328 // ************************************************************************* //
ensightOutputTemplates.C
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:71
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:62
ensightFaces.H
ListListOps.H
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:124
Foam::ListListOps::subSizes
labelList subSizes(const IndirectListBase< T, Addr > &lists, AccessOp aop)
Return the sizes of the sub-lists.
Definition: ensightOutput.H:66
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:68
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::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< scalar >
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:88
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:208
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
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:78
Foam::ensightOutput::Detail::copyComponent
void copyComponent(scalarField &res, const FieldContainer< Type > &input, const direction cmpt)
Copy specified field component into a scalarField.
Definition: ensightOutputTemplates.C:35
Foam::ensightOutput::writeField
bool writeField(ensightFile &os, const Field< Type > &fld, const ensightCells &part, bool parallel)
Definition: ensightOutputTemplates.C:260
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
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:80
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::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:55
Foam::IndirectListBase::size
label size() const
The number of elements in the list.
Definition: IndirectListBase.H:125
ensightCells.H