ensightFaces.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 Class
27  Foam::ensightFaces
28 
29 Description
30  Sorting/classification of faces (2D) into corresponding ensight types.
31 
32  Some caution may be required when handling face addressing into a
33  boundaryField. Since the face addressing is absolute, it will be
34  necessary to work on a copy with local ids. For example,
35 
36  \code
37  // Operate on a copy
38  ensightFaces localPart(part);
39 
40  // Change from global faceIds to patch-local faceIds
41  localPart.decrFaceIds(patchStart);
42 
43  // Can now address into boundaryField
44  \endcode
45 
46  Additionally, for some uses (eg, finiteArea), the ordered
47  list of faces can be used for a direct local lookup into the field
48  instead of via the overall mesh face addressing.
49 
50 \*---------------------------------------------------------------------------*/
51 
52 #ifndef Foam_ensightFaces_H
53 #define Foam_ensightFaces_H
54 
55 #include "ensightPart.H"
56 #include "face.H"
57 #include "FixedList.H"
58 #include "bitSet.H"
59 
60 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
61 
62 namespace Foam
63 {
64 
65 // Forward Declarations
66 class polyMesh;
67 template<class T> class InfoProxy;
68 
69 /*---------------------------------------------------------------------------*\
70  Class ensightFaces Declaration
71 \*---------------------------------------------------------------------------*/
72 
73 class ensightFaces
74 :
75  public ensightPart
76 {
77 public:
78 
79  // Public Data
80 
81  //- Supported ensight 'Face' element types.
82  // Must be zero-based since they are also for internal bookkeeping.
83  enum elemType
84  {
85  TRIA3 = 0,
86  QUAD4,
87  NSIDED
88  };
89 
90  //- Number of 'Face' element types (3)
91  static constexpr int nTypes = 3;
92 
93  //- The ensight 'Face' element type names
94  static const char* elemNames[nTypes];
95 
96 
97  // Static Functions
98 
99  //- The ensight element name for the specified 'Face' type
100  static inline const char* key(const elemType etype) noexcept;
101 
102 
103 private:
104 
105  // Private Data
106 
107  //- The input face order, for indirect face lists
108  labelList faceOrder_;
109 
110  //- List of face-flips (optional)
111  boolList flipMap_;
112 
113  //- Begin/end offsets for address/flips of each element type
115 
116  //- List of global sizes for each element type.
117  // Used temporarily for local sizes when building the element lists.
119 
120 
121  // Private Member Functions
122 
123  //- Low-level internal addition routine.
124  // \return insertion locaion
125  inline label add(const elemType etype, label id, bool flip=false);
126 
127  //- Use temporarily stored sizes to redimension the element lists
128  void resizeAll();
129 
130 
131 public:
132 
133  //- Declare type-name, virtual type (with debug switch)
134  TypeName("ensightFaces");
135 
136 
137  // Constructors
138 
139  //- Default construct, with part index 0
140  ensightFaces();
141 
142  //- Default construct, with description/partName
143  explicit ensightFaces(const string& description);
144 
145 
146  //- Destructor
147  virtual ~ensightFaces() = default;
148 
149 
150  // Member Functions
151 
152  // Access
153 
154  //- Processor-local size of all elements.
155  using ensightPart::size;
156 
157  //- Processor-local size of the specified element type.
158  inline label size(const elemType etype) const;
159 
160  //- Processor-local offset/size of element type.
161  inline labelRange range(const elemType etype) const;
162 
163  //- The global size of all element types.
164  // This value is only meaningful after a reduce operation.
165  label totalSize() const noexcept;
166 
167  //- Same as totalSize
168  label total() const noexcept { return totalSize(); }
169 
170  //- The global size of the specified element type.
171  // This value is only meaningful after a reduce operation.
172  inline label total(const elemType etype) const;
173 
174  //- The global sizes for each element type.
175  // This value is only meaningful after a reduce operation.
176  inline const FixedList<label, nTypes>& totals() const;
177 
178  //- Processor-local sizes per element type.
180 
181  //- Processor-local face ids of all elements
182  inline const labelList& faceIds() const noexcept;
183 
184  //- Processor-local face ids of the specified element type
185  inline const labelUList faceIds(const elemType etype) const;
186 
187  //- Processor-local flip-map of all elements
188  inline const boolList& flipMap() const;
189 
190  //- True for non-zero flip-map that spans the addresses
191  inline bool usesFlipMap() const;
192 
193  //- Processor-local face order
194  //- (where applicable)
195  inline const labelList& faceOrder() const noexcept;
196 
197  //- Processor-local face order of specified element type
198  //- (where applicable)
199  inline const labelUList faceOrder(const elemType etype) const;
200 
201 
202  // Edit
204  //- Classify the face types and set the element lists.
205  void classify(const UList<face>& faces);
206 
207  //- Classify face types (for a sublist) and set element lists.
208  void classify(const UList<face>& faces, const labelRange& range);
209 
210  //- Classify the face types and set the element lists.
211  // The indirect addressing can be used when classifying groups of
212  // face (eg, from a faceZone etc) with an optional flipMap.
213  // The optional exclude marker can be used to skip faces on particular
214  // boundary types or regions.
215  void classify
216  (
217  const UList<face>& faces,
218  const labelUList& addr,
219  const boolList& flipMap = boolList(),
220  const bitSet& exclude = bitSet()
221  );
222 
223 
224  //- Clear any demand-driven data
225  void clearOut();
226 
227  //- Set addressable sizes to zero, free up addressing memory.
228  void clear();
229 
230  //- Sum element counts across all processes.
231  void reduce();
232 
233  //- Inplace sort element lists numerically.
234  void sort();
235 
236 
237  // Advanced (use with caution)
238 
239  //- Increase face ids by specified offset value
240  // Eg, to change patch local Ids to global Ids
241  void incrFaceIds(const label off);
242 
243  //- Decrease face ids by specified offset value
244  // Eg, to change global Ids to patch local Ids
245  void decrFaceIds(const label off);
246 
247 
248  // Output
249 
250  //- Return info proxy,
251  //- used to print information to a stream
252  InfoProxy<ensightFaces> info() const noexcept { return *this; }
253 
254 
255  //- Globally unique mesh points.
256  //- Required when writing point fields.
257  label uniqueMeshPoints
258  (
259  const polyMesh& mesh,
260  labelList& uniqueMeshPointLabels,
261  bool parallel
262  ) const;
263 
264  //- Write information about the object as a dictionary,
265  //- optionally write all element addresses
266  virtual void writeDict(Ostream& os, const bool full=false) const;
267 
268  //- Write geometry, using a mesh reference
269  virtual void write
270  (
272  const polyMesh& mesh,
273  bool parallel
274  ) const;
275 };
276 
277 
278 //- Print information via proxy
279 template<>
280 Ostream& operator<<(Ostream&, const InfoProxy<ensightFaces>&);
281 
282 
283 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
284 
285 } // End namespace Foam
286 
287 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
288 
289 #include "ensightFacesI.H"
290 
291 #endif
292 
293 // ************************************************************************* //
const FixedList< label, nTypes > & totals() const
The global sizes for each element type.
Definition: ensightFacesI.H:48
void clear()
Set addressable sizes to zero, free up addressing memory.
Definition: ensightFaces.C:140
label total() const noexcept
Same as totalSize.
Definition: ensightFaces.H:203
static const char * elemNames[nTypes]
The ensight &#39;Face&#39; element type names.
Definition: ensightFaces.H:94
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:68
FixedList< label, nTypes > sizes() const
Processor-local sizes per element type.
Definition: ensightFaces.C:116
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:52
label size() const noexcept
Processor-local size of all elements.
Definition: ensightPart.H:193
Specialized Ensight output with extra geometry file header.
labelRange range(const elemType etype) const
Processor-local offset/size of element type.
Definition: ensightFacesI.H:66
Sorting/classification of faces (2D) into corresponding ensight types.
Definition: ensightFaces.H:66
const labelList & faceOrder() const noexcept
Processor-local face order (where applicable)
Definition: ensightFacesI.H:98
void clearOut()
Clear any demand-driven data.
Definition: ensightFaces.C:153
bool usesFlipMap() const
True for non-zero flip-map that spans the addresses.
Definition: ensightFacesI.H:91
void reduce()
Sum element counts across all processes.
Definition: ensightFaces.C:157
label totalSize() const noexcept
The global size of all element types.
Definition: ensightFaces.C:129
void classify(const UList< face > &faces)
Classify the face types and set the element lists.
Definition: ensightFaces.C:211
dynamicFvMesh & mesh
virtual void write(ensightGeoFile &os, const polyMesh &mesh, bool parallel) const
Write geometry, using a mesh reference.
ensightFaces()
Default construct, with part index 0.
Definition: ensightFaces.C:96
virtual ~ensightFaces()=default
Destructor.
label uniqueMeshPoints(const polyMesh &mesh, labelList &uniqueMeshPointLabels, bool parallel) const
Globally unique mesh points. Required when writing point fields.
const boolList & flipMap() const
Processor-local flip-map of all elements.
Definition: ensightFacesI.H:85
const labelList & faceIds() const noexcept
Processor-local face ids of all elements.
Definition: ensightFacesI.H:72
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
Base class for ensightCells, ensightFaces, ensightOutputSurfaces.
Definition: ensightPart.H:49
OBJstream os(runTime.globalPath()/outputName)
void decrFaceIds(const label off)
Decrease face ids by specified offset value.
static constexpr int nTypes
Number of &#39;Face&#39; element types (3)
Definition: ensightFaces.H:89
InfoProxy< ensightFaces > info() const noexcept
Return info proxy, used to print information to a stream.
Definition: ensightFaces.H:330
static const char * key(const elemType etype) noexcept
The ensight element name for the specified &#39;Face&#39; type.
Definition: ensightFacesI.H:42
elemType
Supported ensight &#39;Face&#39; element types.
Definition: ensightFaces.H:79
TypeName("ensightFaces")
Declare type-name, virtual type (with debug switch)
A helper class for outputting values to Ostream.
Definition: ensightCells.H:43
void sort()
Inplace sort element lists numerically.
Definition: ensightFaces.C:167
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:59
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
void incrFaceIds(const label off)
Increase face ids by specified offset value.
virtual void writeDict(Ostream &os, const bool full=false) const
Write information about the object as a dictionary, optionally write all element addresses.
Definition: ensightFaces.C:317
Namespace for OpenFOAM.