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  inline void add(const elemType etype, label id);
103 
104  //- Use temporarily stored sizes to redimension the element lists
105  void resizeAll();
106 
107  //- Classify cell types, set element lists for selection
108  // (implementation)
109  template<class Addressing>
110  void classifyImpl(const polyMesh& mesh, const Addressing& cellIds);
111 
112 
113  label meshPointMapppings
114  (
115  const polyMesh& mesh,
116  labelList& pointToGlobal, // Can also be labelList::null()
117  labelList& uniqueMeshPointLabels,
118  bool parallel
119  ) const;
120 
121 
122  //- Write cell connectivity for polyhedral cells
123  static void writePolysConnectivity
124  (
125  ensightGeoFile& os,
126  const polyMesh& mesh,
127  const ensightCells& part,
128  const labelList& pointToGlobal,
129  bool parallel
130  );
131 
132  //- Write cell connectivity for specified (non-poly) type
133  static void writeShapeConnectivity
134  (
135  ensightGeoFile& os,
136  const polyMesh& mesh,
137  const ensightCells::elemType etype,
138  const ensightCells& part,
139  const labelList& pointToGlobal,
140  bool parallel
141  );
142 
143 
144 public:
145 
146  //- Declare type-name, virtual type (with debug switch)
147  TypeName("ensightCells");
148 
149 
150  // Constructors
151 
152  //- Default construct, with part index 0
153  ensightCells();
154 
155  //- Default construct, with description/partName
156  explicit ensightCells(const string& description);
157 
158 
159  //- Destructor
160  virtual ~ensightCells() = default;
161 
162 
163 
164  // Member Functions
165 
166  // Access
167 
168  //- Processor-local size of all elements.
169  using ensightPart::size;
170 
171  //- Processor-local size of the specified element type.
172  inline label size(const elemType etype) const;
173 
174  //- Processor-local offset/size of element type.
175  inline labelRange range(const elemType etype) const;
176 
177  //- The global size of all element types.
178  // This value is only meaningful after a reduce operation.
179  label total() const;
180 
181  //- The global size of the specified element type.
182  // This value is only meaningful after a reduce operation.
183  inline label total(const elemType etype) const;
184 
185  //- The global sizes for each element type.
186  // This value is only meaningful after a reduce operation.
187  inline const FixedList<label, nTypes>& totals() const;
188 
189  //- Processor-local sizes per element type.
191 
192  //- Processor-local cell ids of all elements
193  inline const labelList& cellIds() const;
194 
195  //- Processor-local cell ids of the specified element type
196  inline const labelUList cellIds(const elemType etype) const;
197 
198 
199  // Addressing
200 
201  //- Mesh point map.
202  // Map mesh point index to local (compact) point index
203  Map<label> meshPointMap(const polyMesh& mesh) const;
204 
205 
206  // Edit
207 
208  //- Classify cell types and set the element lists.
209  void classify(const polyMesh& mesh);
210 
211  //- Classify cell types and set element lists,
212  //- using a subgroup of cells (eg, from a cellZone etc).
213  void classify(const polyMesh& mesh, const labelUList& cellIds);
214 
215  //- Classify cell types and set element lists,
216  //- using a subgroup of cells
217  void classify(const polyMesh& mesh, const bitSet& selection);
218 
219 
220  //- Clear any demand-driven data
221  void clearOut();
222 
223  //- Set addressable sizes to zero, free up addressing memory.
224  void clear();
225 
226  //- Sum element counts across all processes.
227  void reduce();
228 
229  //- Sort element lists numerically.
230  void sort();
231 
232 
233  // Advanced (use with caution)
234 
235  //- Increase cell ids by specified offset value
236  // Eg, to change zone local Ids to global Ids
237  inline void incrCellIds(const label off);
238 
239  //- Decrease face ids by specified offset value
240  // Eg, to change global Ids to zone local Ids
241  inline void decrCellIds(const label off);
242 
243 
244 
245  // Output
246 
247  //- Globally unique mesh points. Required when writing point fields.
248  label uniqueMeshPoints
249  (
250  const polyMesh& mesh,
251  labelList& uniqueMeshPointLabels,
252  bool parallel
253  ) const;
254 
255 
256  //- Write information about the object as a dictionary,
257  //- optionally write all element addresses
258  virtual void writeDict(Ostream& os, const bool full=false) const;
259 
260  //- Write geometry, using a mesh reference (serial only)
261  virtual void write
262  (
263  ensightGeoFile& os,
264  const polyMesh& mesh,
265  bool parallel
266  ) const;
267 };
268 
269 
270 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
271 
272 } // End namespace Foam
273 
274 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
275 
276 #include "ensightCellsI.H"
277 
278 #endif
279 
280 // ************************************************************************* //
Foam::ensightCells::range
labelRange range(const elemType etype) const
Processor-local offset/size of element type.
Definition: ensightCellsI.H:65
Foam::ensightPart::size
label size() const
Processor-local size of all elements.
Definition: ensightPart.H:154
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:41
Foam::ensightCells::sort
void sort()
Sort element lists numerically.
Definition: ensightCells.C:144
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:263
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:76
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:107
Foam::ensightCells::cellIds
const labelList & cellIds() const
Processor-local cell ids of all elements.
Definition: ensightCellsI.H:71
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
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:90
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:129
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:84
Foam::ensightCells::classify
void classify(const polyMesh &mesh)
Classify cell types and set the element lists.
Definition: ensightCells.C:236
Foam::ensightCells::sizes
FixedList< label, nTypes > sizes() const
Processor-local sizes per element type.
Definition: ensightCells.C:94
Foam::ensightCells::reduce
void reduce()
Sum element counts across all processes.
Definition: ensightCells.C:133
Foam::ensightCells::clear
void clear()
Set addressable sizes to zero, free up addressing memory.
Definition: ensightCells.C:118
Foam::ensightCells::totals
const FixedList< label, nTypes > & totals() const
The global sizes for each element type.
Definition: ensightCellsI.H:47
Foam::ensightCells::HEXA8
"hexa8"
Definition: ensightCells.H:69