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