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-2021 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 ensightFaces_H
53 #define 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 
68 /*---------------------------------------------------------------------------*\
69  Class ensightFaces Declaration
70 \*---------------------------------------------------------------------------*/
71 
72 class ensightFaces
73 :
74  public ensightPart
75 {
76 public:
77 
78  // Public Data
79 
80  //- Supported ensight 'Face' element types.
81  // Must be zero-based since they are also for internal bookkeeping.
82  enum elemType
83  {
84  TRIA3 = 0,
86  NSIDED
87  };
88 
89  //- Number of 'Face' element types (3)
90  static constexpr int nTypes = 3;
91 
92  //- The ensight 'Face' element type names
93  static const char* elemNames[nTypes];
94 
95 
96  // Static Functions
97 
98  //- The ensight element name for the specified 'Face' type
99  static inline const char* key(const elemType etype);
100 
101 
102 private:
103 
104  // Private Data
105 
106  //- The input face order, for indirect face lists
107  labelList faceOrder_;
108 
109  //- List of face-flips (optional)
110  boolList flipMap_;
111 
112  //- Begin/end offsets for address/flips of each element type
114 
115  //- List of global sizes for each element type.
116  // Used temporarily for local sizes when building the element lists.
118 
119 
120  // Private Member Functions
121 
122  //- Low-level internal addition routine.
123  // \return insertion locaion
124  inline label add(const elemType etype, label id, bool flip=false);
125 
126  //- Use temporarily stored sizes to redimension the element lists
127  void resizeAll();
128 
129 
130 public:
131 
132  //- Declare type-name, virtual type (with debug switch)
133  TypeName("ensightFaces");
134 
135 
136  // Constructors
137 
138  //- Default construct, with part index 0
139  ensightFaces();
140 
141  //- Default construct, with description/partName
142  explicit ensightFaces(const string& description);
143 
144 
145  //- Destructor
146  virtual ~ensightFaces() = default;
147 
148 
149  // Member Functions
150 
151  // Access
152 
153  //- Processor-local size of all elements.
154  using ensightPart::size;
155 
156  //- Processor-local size of the specified element type.
157  inline label size(const elemType etype) const;
158 
159  //- Processor-local offset/size of element type.
160  inline labelRange range(const elemType etype) const;
161 
162  //- The global size of all element types.
163  // This value is only meaningful after a reduce operation.
164  label total() const;
165 
166  //- The global size of the specified element type.
167  // This value is only meaningful after a reduce operation.
168  inline label total(const elemType etype) const;
169 
170  //- The global sizes for each element type.
171  // This value is only meaningful after a reduce operation.
172  inline const FixedList<label, nTypes>& totals() const;
173 
174  //- Processor-local sizes per element type.
176 
177  //- Processor-local face ids of all elements
178  inline const labelList& faceIds() const noexcept;
179 
180  //- Processor-local face ids of the specified element type
181  inline const labelUList faceIds(const elemType etype) const;
182 
183  //- Processor-local flip-map of all elements
184  inline const boolList& flipMap() const;
185 
186  //- True for non-zero flip-map that spans the addresses
187  inline bool usesFlipMap() const;
188 
189  //- Processor-local face order
190  //- (where applicable)
191  inline const labelList& faceOrder() const noexcept;
192 
193  //- Processor-local face order of specified element type
194  //- (where applicable)
195  inline const labelUList faceOrder(const elemType etype) const;
196 
197 
198  // Edit
199 
200  //- Classify the face types and set the element lists.
201  void classify(const UList<face>& faces);
202 
203  //- Classify face types (for a sublist) and set element lists.
204  void classify(const UList<face>& faces, const labelRange& range);
205 
206  //- Classify the face types and set the element lists.
207  // The indirect addressing can be used when classifying groups of
208  // face (eg, from a faceZone etc) with an optional flipMap.
209  // The optional exclude marker can be used to skip faces on particular
210  // boundary types or regions.
211  void classify
212  (
213  const UList<face>& faces,
214  const labelUList& addr,
215  const boolList& flipMap = boolList(),
216  const bitSet& exclude = bitSet()
217  );
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  //- Inplace sort element lists numerically.
230  void sort();
231 
232 
233  // Advanced (use with caution)
234 
235  //- Increase face ids by specified offset value
236  // Eg, to change patch local Ids to global Ids
237  void incrFaceIds(const label off);
238 
239  //- Decrease face ids by specified offset value
240  // Eg, to change global Ids to patch local Ids
241  void decrFaceIds(const label off);
242 
243 
244  // Output
245 
246  //- Globally unique mesh points.
247  //- Required when writing point fields.
248  label uniqueMeshPoints
249  (
250  const polyMesh& mesh,
251  labelList& uniqueMeshPointLabels,
252  bool parallel
253  ) const;
254 
255  //- Write information about the object as a dictionary,
256  //- optionally write all element addresses
257  virtual void writeDict(Ostream& os, const bool full=false) const;
258 
259  //- Write geometry, using a mesh reference
260  virtual void write
261  (
263  const polyMesh& mesh,
264  bool parallel
265  ) const;
266 };
267 
268 
269 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
270 
271 } // End namespace Foam
272 
273 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
274 
275 #include "ensightFacesI.H"
276 
277 #endif
278 
279 // ************************************************************************* //
Foam::ensightFaces::faceIds
const labelList & faceIds() const noexcept
Processor-local face ids of all elements.
Definition: ensightFacesI.H:79
Foam::ensightFaces::flipMap
const boolList & flipMap() const
Processor-local flip-map of all elements.
Definition: ensightFacesI.H:92
Foam::ensightFaces::decrFaceIds
void decrFaceIds(const label off)
Decrease face ids by specified offset value.
Definition: ensightFacesI.H:124
Foam::ensightFaces::nTypes
static constexpr int nTypes
Number of 'Face' element types (3)
Definition: ensightFaces.H:89
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:63
Foam::ensightFaces::NSIDED
"nsided"
Definition: ensightFaces.H:85
Foam::ensightFaces::key
static const char * key(const elemType etype)
The ensight element name for the specified 'Face' type.
Definition: ensightFacesI.H:49
Foam::ensightFaces::TypeName
TypeName("ensightFaces")
Declare type-name, virtual type (with debug switch)
Foam::ensightFaces::usesFlipMap
bool usesFlipMap() const
True for non-zero flip-map that spans the addresses.
Definition: ensightFacesI.H:98
face.H
Foam::ensightFaces::clearOut
void clearOut()
Clear any demand-driven data.
Definition: ensightFaces.C:160
bitSet.H
Foam::ensightFaces
Sorting/classification of faces (2D) into corresponding ensight types.
Definition: ensightFaces.H:71
Foam::ensightFaces::writeDict
virtual void writeDict(Ostream &os, const bool full=false) const
Definition: ensightFaces.C:325
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::ensightFaces::range
labelRange range(const elemType etype) const
Processor-local offset/size of element type.
Definition: ensightFacesI.H:73
Foam::ensightFaces::write
virtual void write(ensightGeoFile &os, const polyMesh &mesh, bool parallel) const
Write geometry, using a mesh reference.
Definition: ensightFacesIO.C:39
Foam::ensightFaces::total
label total() const
The global size of all element types.
Definition: ensightFaces.C:136
Foam::ensightGeoFile
Specialized Ensight output with extra geometry file header.
Definition: ensightGeoFile.H:48
Foam::ensightFaces::TRIA3
"tria3"
Definition: ensightFaces.H:83
Foam::ensightFaces::~ensightFaces
virtual ~ensightFaces()=default
Destructor.
Foam::ensightFaces::reduce
void reduce()
Sum element counts across all processes.
Definition: ensightFaces.C:164
Foam::ensightFaces::sizes
FixedList< label, nTypes > sizes() const
Processor-local sizes per element type.
Definition: ensightFaces.C:123
Foam::labelRange
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:55
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::ensightFaces::faceOrder
const labelList & faceOrder() const noexcept
Definition: ensightFacesI.H:105
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::ensightFaces::ensightFaces
ensightFaces()
Default construct, with part index 0.
Definition: ensightFaces.C:103
Foam::ensightFaces::uniqueMeshPoints
label uniqueMeshPoints(const polyMesh &mesh, labelList &uniqueMeshPointLabels, bool parallel) const
Definition: ensightFacesAddr.C:39
Foam::ensightFaces::totals
const FixedList< label, nTypes > & totals() const
The global sizes for each element type.
Definition: ensightFacesI.H:55
Foam::ensightFaces::incrFaceIds
void incrFaceIds(const label off)
Increase face ids by specified offset value.
Definition: ensightFacesI.H:118
Foam::ensightFaces::QUAD4
"quad4"
Definition: ensightFaces.H:84
Foam::ensightFaces::elemType
elemType
Supported ensight 'Face' element types.
Definition: ensightFaces.H:81
Foam::List< label >
Foam::ensightPart
Base class for ensightCells, ensightFaces, ensightOutputSurfaces.
Definition: ensightPart.H:53
Foam::ensightFaces::clear
void clear()
Set addressable sizes to zero, free up addressing memory.
Definition: ensightFaces.C:147
Foam::FixedList< label, nTypes+1 >
Foam::UList< label >
Foam::ensightFaces::sort
void sort()
Inplace sort element lists numerically.
Definition: ensightFaces.C:175
Foam::ensightFaces::elemNames
static const char * elemNames[nTypes]
The ensight 'Face' element type names.
Definition: ensightFaces.H:92
ensightPart.H
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:72
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
FixedList.H
Foam::ensightFaces::classify
void classify(const UList< face > &faces)
Classify the face types and set the element lists.
Definition: ensightFaces.C:219