ensightCells.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::ensightCells
28 
29 Description
30  Sorting/classification of cells (3D) into corresponding ensight element
31  types.
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef Foam_ensightCells_H
36 #define Foam_ensightCells_H
37 
38 #include "ensightPart.H"
39 #include "FixedList.H"
40 #include "Map.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 // Forward Declarations
48 class bitSet;
49 class polyMesh;
50 template<class T> class InfoProxy;
51 
52 /*---------------------------------------------------------------------------*\
53  Class ensightCells Declaration
54 \*---------------------------------------------------------------------------*/
55 
56 class ensightCells
57 :
58  public ensightPart
59 {
60 public:
61 
62  // Public Data
63 
64  //- Supported ensight 'Cell' element types
65  // Must be zero-based since they are also for internal bookkeeping.
66  enum elemType
67  {
68  TETRA4 = 0,
69  PYRAMID5,
70  PENTA6,
71  HEXA8,
72  NFACED
73  };
74 
75  //- Number of 'Cell' element types (5)
76  static constexpr int nTypes = 5;
77 
78  //- The ensight 'Cell' element type names
79  static const char* elemNames[nTypes];
80 
81 
82  // Static Functions
83 
84  //- The ensight element name for the specified 'Cell' type
85  inline static const char* key(const elemType etype) noexcept;
86 
87 
88 private:
89 
90  // Private Data
91 
92  //- Manifold cells detected
93  bool manifold_;
94 
95  //- Begin/end offsets for address of each element type
97 
98  //- List of global sizes for each element type.
99  // Used temporarily for local sizes when building the element lists.
101 
102 
103  // Private Member Functions
104 
105  //- Low-level internal addition routine
106  // \return insertion locaion
107  inline label add(const elemType etype, label id);
108 
109  //- Use temporarily stored sizes to redimension the element lists
110  void resizeAll();
111 
112  //- Classify cell types, set element lists for selection
113  // (implementation)
114  template<class Addressing>
115  void classifyImpl(const polyMesh& mesh, const Addressing& cellIds);
116 
117 
118  label meshPointMapppings
119  (
120  const polyMesh& mesh,
121  labelList& pointToGlobal, // Can also be labelList::null()
122  labelList& uniqueMeshPointLabels,
123  bool parallel
124  ) const;
125 
126 
127  //- Write cell connectivity for polyhedral cells
128  static void writePolysConnectivity
129  (
131  const polyMesh& mesh,
132  const ensightCells& part,
133  const labelList& pointToGlobal,
134  bool parallel
135  );
136 
137  //- Write cell connectivity for specified (non-poly) type
138  static void writeShapeConnectivity
139  (
141  const polyMesh& mesh,
142  const ensightCells::elemType etype,
143  const ensightCells& part,
144  const labelList& pointToGlobal,
145  bool parallel
146  );
147 
148 
149 public:
150 
151  //- Declare type-name, virtual type (with debug switch)
152  TypeName("ensightCells");
153 
154 
155  // Constructors
156 
157  //- Default construct, with part index 0
158  ensightCells();
159 
160  //- Default construct, with description/partName
161  explicit ensightCells(const string& description);
162 
163 
164  //- Destructor
165  virtual ~ensightCells() = default;
166 
167 
168  // Member Functions
169 
170  // Access
171 
172  //- Manifold mesh cells detected? Globally consistent quantity.
173  inline bool manifold() const noexcept;
174 
175  //- Processor-local size of all elements.
176  using ensightPart::size;
177 
178  //- Processor-local size of the specified element type.
179  inline label size(const elemType etype) const;
180 
181  //- Processor-local offset/size of element type.
182  inline labelRange range(const elemType etype) const;
183 
184  //- The global size of all element types.
185  // This value is only meaningful after a reduce operation.
186  label totalSize() const noexcept;
187 
188  //- Same as totalSize()
189  label total() const noexcept { return totalSize(); }
190 
191  //- The global size of the specified element type.
192  // This value is only meaningful after a reduce operation.
193  inline label total(const elemType etype) const;
194 
195  //- The global sizes for each element type.
196  // This value is only meaningful after a reduce operation.
197  inline const FixedList<label, nTypes>& totals() const;
198 
199  //- Processor-local sizes per element type.
201 
202  //- Processor-local cell ids of all elements
203  inline const labelList& cellIds() const;
204 
205  //- Processor-local cell ids of the specified element type
206  inline const labelUList cellIds(const elemType etype) const;
207 
208 
209  // Addressing
210 
211  //- Mesh point map.
212  // Map mesh point index to local (compact) point index
213  Map<label> meshPointMap(const polyMesh& mesh) const;
214 
215 
216  // Edit
217 
218  //- Classify cell types and set the element lists.
219  void classify(const polyMesh& mesh);
220 
221  //- Classify cell types and set element lists,
222  //- using a subgroup of cells (eg, from a cellZone etc).
223  void classify(const polyMesh& mesh, const labelUList& cellIds);
224 
225  //- Classify cell types and set element lists,
226  //- using a subgroup of cells
227  void classify(const polyMesh& mesh, const bitSet& selection);
228 
229 
230  //- Clear any demand-driven data
231  void clearOut();
232 
233  //- Set addressable sizes to zero, free up addressing memory.
234  void clear();
235 
236  //- Sum element counts across all processes.
237  void reduce();
238 
239  //- Sort element lists numerically.
240  void sort();
241 
242 
243  // Advanced (use with caution)
244 
245  //- Increase cell ids by specified offset value
246  // Eg, to change zone local Ids to global Ids
247  inline void incrCellIds(const label off);
248 
249  //- Decrease face ids by specified offset value
250  // Eg, to change global Ids to zone local Ids
251  inline void decrCellIds(const label off);
252 
253 
254 
255  // Output
256 
257  //- Return info proxy,
258  //- used to print information to a stream
259  InfoProxy<ensightCells> info() const noexcept { return *this; }
260 
261 
262  //- Globally unique mesh points. Required when writing point fields.
263  label uniqueMeshPoints
264  (
265  const polyMesh& mesh,
266  labelList& uniqueMeshPointLabels,
267  bool parallel
268  ) const;
269 
270 
271  //- Write information about the object as a dictionary,
272  //- optionally write all element addresses
273  virtual void writeDict(Ostream& os, const bool full=false) const;
274 
275  //- Write geometry, using a mesh reference (serial only)
276  virtual void write
277  (
279  const polyMesh& mesh,
280  bool parallel
281  ) const;
282 };
283 
284 
285 //- Print information via proxy
286 template<>
287 Ostream& operator<<(Ostream&, const InfoProxy<ensightCells>&);
288 
289 
290 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
291 
292 } // End namespace Foam
293 
294 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
295 
296 #include "ensightCellsI.H"
297 
298 #endif
299 
300 // ************************************************************************* //
void classify(const polyMesh &mesh)
Classify cell types and set the element lists.
Definition: ensightCells.C:235
label uniqueMeshPoints(const polyMesh &mesh, labelList &uniqueMeshPointLabels, bool parallel) const
Globally unique mesh points. Required when writing point fields.
InfoProxy< ensightCells > info() const noexcept
Return info proxy, used to print information to a stream.
Definition: ensightCells.H:338
Map< label > meshPointMap(const polyMesh &mesh) const
Mesh point map.
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:52
void sort()
Sort element lists numerically.
Definition: ensightCells.C:141
label size() const noexcept
Processor-local size of all elements.
Definition: ensightPart.H:193
Specialized Ensight output with extra geometry file header.
virtual void writeDict(Ostream &os, const bool full=false) const
Write information about the object as a dictionary, optionally write all element addresses.
Definition: ensightCells.C:262
labelRange range(const elemType etype) const
Processor-local offset/size of element type.
Definition: ensightCellsI.H:66
ensightCells()
Default construct, with part index 0.
Definition: ensightCells.C:72
void decrCellIds(const label off)
Decrease face ids by specified offset value.
Definition: ensightCellsI.H:91
label total() const noexcept
Same as totalSize()
Definition: ensightCells.H:231
virtual ~ensightCells()=default
Destructor.
void clearOut()
Clear any demand-driven data.
Definition: ensightCells.C:127
dynamicFvMesh & mesh
FixedList< label, nTypes > sizes() const
Processor-local sizes per element type.
Definition: ensightCells.C:91
Sorting/classification of cells (3D) into corresponding ensight element types.
Definition: ensightCells.H:49
elemType
Supported ensight &#39;Cell&#39; element types.
Definition: ensightCells.H:62
void incrCellIds(const label off)
Increase cell ids by specified offset value.
Definition: ensightCellsI.H:85
void reduce()
Sum element counts across all processes.
Definition: ensightCells.C:131
virtual void write(ensightGeoFile &os, const polyMesh &mesh, bool parallel) const
Write geometry, using a mesh reference (serial only)
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
void clear()
Set addressable sizes to zero, free up addressing memory.
Definition: ensightCells.C:115
Base class for ensightCells, ensightFaces, ensightOutputSurfaces.
Definition: ensightPart.H:49
OBJstream os(runTime.globalPath()/outputName)
static const char * key(const elemType etype) noexcept
The ensight element name for the specified &#39;Cell&#39; type.
Definition: ensightCellsI.H:42
A helper class for outputting values to Ostream.
Definition: ensightCells.H:43
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:59
const FixedList< label, nTypes > & totals() const
The global sizes for each element type.
Definition: ensightCellsI.H:48
TypeName("ensightCells")
Declare type-name, virtual type (with debug switch)
static const char * elemNames[nTypes]
The ensight &#39;Cell&#39; element type names.
Definition: ensightCells.H:79
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
bool manifold() const noexcept
Manifold mesh cells detected? Globally consistent quantity.
Definition: ensightCellsI.H:36
label totalSize() const noexcept
The global size of all element types.
Definition: ensightCells.C:104
Namespace for OpenFOAM.
const labelList & cellIds() const
Processor-local cell ids of all elements.
Definition: ensightCellsI.H:72
static constexpr int nTypes
Number of &#39;Cell&#39; element types (5)
Definition: ensightCells.H:74