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