faceZone.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) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2017-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::faceZone
29 
30 Description
31  A subset of mesh faces organised as a primitive patch.
32 
33  For quick check whether a face belongs to the zone use the lookup
34  mechanism in faceZoneMesh, where all the zoned faces are registered
35  with their zone number.
36 
37 SourceFiles
38  faceZone.C
39  faceZoneNew.C
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #ifndef Foam_faceZone_H
44 #define Foam_faceZone_H
45 
46 #include "zone.H"
47 #include "faceZoneMeshFwd.H"
48 #include "primitivePatch.H"
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace Foam
53 {
54 
55 // Forward Declarations
56 class mapPolyMesh;
57 class faceZone;
58 Ostream& operator<<(Ostream& os, const faceZone& zn);
59 
60 
61 /*---------------------------------------------------------------------------*\
62  Class faceZone Declaration
63 \*---------------------------------------------------------------------------*/
64 
65 class faceZone
66 :
67  public zone
68 {
69  // // Public Data Types
70  //
71  // //- Side of the face zone
72  // enum side
73  // {
74  // FRONT = 1, //!< The front (positive normal) side of the face
75  // BACK = -1, //!< The back (negative normal) side of the face
76  // };
77 
78 
79  // Private Data
80 
81  //- Flip map for all faces in the zone.
82  // True if the face needs flipping for the correct orientation.
83  boolList flipMap_;
84 
85  //- Reference to zone list
86  const faceZoneMesh& zoneMesh_;
87 
88  //- Demand-driven: Primitive patch of correctly flipped faces
89  mutable std::unique_ptr<primitiveFacePatch> patchPtr_;
90 
91  //- Demand-driven: front cell layer (positive normal) side of faces
92  mutable std::unique_ptr<labelList> frontCellsPtr_;
93 
94  //- Demand-driven: back cell layer (negative normal) side of faces
95  mutable std::unique_ptr<labelList> backCellsPtr_;
96 
97  //- Demand-driven: Global edge addressing
98  mutable std::unique_ptr<labelList> mePtr_;
99 
100 
101  // Private Member Functions
102 
103  //- Set flip-map to uniform value
104  void setFlipMap(const bool val);
105 
106  //- Build primitive patch
107  void calcFaceZonePatch() const;
108 
109  //- Calculate front/back cell layers
110  void calcCellLayers() const;
111 
112  //- Check addressing
113  void checkAddressing() const;
114 
115  //- Clear out geometry and demand-driven data
116  void clearGeom();
117 
118 public:
119 
120  // Static Data Members
121 
122  //- The name associated with the zone-labels dictionary entry
123  //- ("faceLabels")
124  static const char * const labelsName;
125 
126 
127  //- Runtime type information
128  TypeName("faceZone");
129 
130 
131  // Declare run-time constructor selection tables
132 
134  (
135  autoPtr,
136  faceZone,
137  dictionary,
138  (
139  const word& name,
140  const dictionary& dict,
141  const label index,
142  const faceZoneMesh& zm
143  ),
144  (name, dict, index, zm)
145  );
146 
147 
148  // Constructors
149 
150  //- No copy construct
151  faceZone(const faceZone&) = delete;
152 
153  //- Construct an empty zone - name="", index=0
154  explicit faceZone(const faceZoneMesh& zm);
155 
156  //- Construct an empty zone with specified name and index
157  faceZone
158  (
159  const word& name,
160  const label index,
161  const faceZoneMesh& zm
162  );
163 
164  //- Construct from components with uniform flip map value
165  faceZone
166  (
167  const word& name,
168  const labelUList& addr,
169  const bool flipMapValue,
170  const label index,
171  const faceZoneMesh& zm
172  );
173 
174  //- Construct from components with uniform flip map value,
175  //- transferring addressing.
176  faceZone
177  (
178  const word& name,
179  labelList&& addr,
180  const bool flipMapValue,
181  const label index,
182  const faceZoneMesh& zm
183  );
184 
185  //- Construct from components, copying addressing
186  faceZone
187  (
188  const word& name,
189  const labelUList& addr,
190  const boolUList& fm,
191  const label index,
192  const faceZoneMesh& zm
193  );
194 
195  //- Construct from components, transferring addressing
196  faceZone
197  (
198  const word& name,
199  labelList&& addr,
200  boolList&& fm,
201  const label index,
202  const faceZoneMesh& zm
203  );
204 
205  //- Construct from dictionary
206  faceZone
207  (
208  const word& name,
209  const dictionary& dict,
210  const label index,
211  const faceZoneMesh& zm
212  );
213 
214  //- Construct empty with original zone information (name, index, groups)
215  //- and mesh reference. Optionally specify a new index.
216  faceZone
217  (
218  const faceZone& originalZone,
219  const Foam::zero,
220  const faceZoneMesh& zm,
221  const label newIndex = -1
222  );
223 
224  //- Construct empty with original zone information (name, groups),
225  //- resetting the index and zone mesh reference.
226  faceZone
227  (
228  const faceZone& originalZone,
229  const Foam::zero,
230  const label index,
231  const faceZoneMesh& zm
232  );
233 
234  //- Construct with a new index and zone mesh information, the name
235  //- of the original zone, resetting the face addressing
236  //- and flip-map.
237  faceZone
238  (
239  const faceZone& originalZone,
240  const labelUList& addr,
241  const boolUList& fm,
242  const label index,
243  const faceZoneMesh& zm
244  );
245 
246  //- Construct with a new index and zone mesh information, the name
247  //- of the original zone, (move) resetting the face addressing
248  //- and flip-map.
249  faceZone
250  (
251  const faceZone& originalZone,
252  labelList&& addr,
253  boolList&& fm,
254  const label index,
255  const faceZoneMesh& zm
256  );
257 
258  //- Construct and return a clone, resetting the zone mesh
259  virtual autoPtr<faceZone> clone(const faceZoneMesh& zm) const
260  {
261  return autoPtr<faceZone>::New(*this, *this, flipMap(), index(), zm);
262  }
263 
264  //- Construct and return a clone,
265  //- resetting the face list and zone mesh
266  virtual autoPtr<faceZone> clone
267  (
268  const labelUList& addr,
269  const boolUList& fm,
270  const label index,
271  const faceZoneMesh& zm
272  ) const
273  {
274  return autoPtr<faceZone>::New(*this, addr, fm, index, zm);
275  }
276 
277 
278  // Selectors
279 
280  //- Return a pointer to a new face zone
281  //- created on freestore from dictionary
282  static autoPtr<faceZone> New
283  (
284  const word& name,
285  const dictionary& dict,
286  const label index,
287  const faceZoneMesh& zm
288  );
289 
290 
291  //- Destructor
292  virtual ~faceZone() = default;
293 
294 
295  // Member Functions
296 
297  //- Return reference to the zone mesh
298  const faceZoneMesh& zoneMesh() const noexcept { return zoneMesh_; }
299 
300  //- The addressing (face IDs) used for the zone
301  const labelList& addressing() const noexcept
302  {
303  return static_cast<const labelList&>(*this);
304  }
305 
306  //- Return face flip map
307  const boolList& flipMap() const noexcept { return flipMap_; }
308 
309  //- Helper function to re-direct to zone::localID(...)
310  label whichFace(const label globalCellID) const;
311 
312  //- Return [demand-driven] reference to an equivalent primitive patch,
313  //- with faces oriented according to flipMap()
314  const primitiveFacePatch& patch() const;
315 
316 
317  // Addressing into mesh
318 
319  //- The front cells layer.
320  //- Cells on the positive normal side of faces.
321  // \warning may contain negative indices for boundary faces!
322  const labelList& frontCells() const;
323 
324  //- The back cells layer.
325  //- Cells on the negative normal side of faces.
326  // \warning may contain negative indices for boundary faces!
327  const labelList& backCells() const;
328 
329  //- Return global edge index for local edges
330  const labelList& meshEdges() const;
331 
332  //- Check zone definition. Return true if in error.
333  virtual bool checkDefinition(const bool report = false) const;
334 
335  //- Check whether all procs have faces synchronised.
336  // \return True if any errors.
337  virtual bool checkParallelSync(const bool report = false) const;
338 
339  //- Correct patch after moving points
340  virtual void movePoints(const pointField& pts);
341 
342  //- Update for changes in topology
343  virtual void updateMesh(const mapPolyMesh& mpm);
344 
345  //- Write
346  virtual void write(Ostream& os) const;
347 
348  //- Write dictionary
349  virtual void writeDict(Ostream& os) const;
350 
351 
352  // Assign addressing
353 
354  //- Clear addressing
355  //- (remove lookup maps, patch/geometric information)
356  virtual void clearAddressing();
357 
358  //- Clear primitive addressing
359  virtual void clearPrimitives();
360 
361  //- Move reset addressing and flip map from another zone
362  virtual void resetAddressing(faceZone&& zn);
363 
364  //- Copy reset addressing and flip map from another zone
365  virtual void resetAddressing(const faceZone& zn);
366 
367  //- Reset addressing - use uniform flip map value
368  // Clears demand-driven data.
369  virtual void resetAddressing
370  (
371  const labelUList& addr,
372  const bool flipMapValue
373  );
374 
375  //- Move reset addressing - use uniform flip map value
376  // Clears demand-driven data.
377  virtual void resetAddressing
378  (
379  labelList&& addr,
380  const bool flipMapValue
381  );
382 
383  //- Copy reset addressing and flip map.
384  // Clears demand-driven data.
385  virtual void resetAddressing
386  (
387  const labelUList& addr,
388  const boolUList& flipMap
389  );
390 
391  //- Assign addressing, clearing demand-driven data
392  void operator=(const faceZone& zn);
393 
394 
395  // I-O
396 
397  //- Ostream Operator
398  friend Ostream& operator<<(Ostream& os, const faceZone& zn);
399 
400 
401  // Housekeeping
402 
403  //- Deprecated(2023-09) same as patch()
404  // \deprecated(2023-09) same as patch()
405  const primitiveFacePatch& operator()() const { return this->patch(); }
406 
407  //- Deprecated(2023-09) same as frontCells
408  // \deprecated(2023-09) same as frontCells #1832
409  const labelList& masterCells() const { return frontCells(); }
410 
411  //- Deprecated(2023-09) same as backCells
412  // \deprecated(2023-09) same as backCells #1832
413  const labelList& slaveCells() const { return backCells(); }
414 };
415 
416 
417 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
418 
419 } // End namespace Foam
420 
421 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
422 
423 #endif
424 
425 // ************************************************************************* //
static autoPtr< faceZone > New(const word &name, const dictionary &dict, const label index, const faceZoneMesh &zm)
Return a pointer to a new face zone created on freestore from dictionary.
Definition: faceZoneNew.C:28
dictionary dict
virtual void movePoints(const pointField &pts)
Correct patch after moving points.
Definition: faceZone.C:671
ZoneMesh< faceZone, polyMesh > faceZoneMesh
A ZoneMesh with the type faceZone.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
virtual bool checkParallelSync(const bool report=false) const
Check whether all procs have faces synchronised.
Definition: faceZone.C:580
const labelList & frontCells() const
The front cells layer. Cells on the positive normal side of faces.
Definition: faceZone.C:413
label whichFace(const label globalCellID) const
Helper function to re-direct to zone::localID(...)
Definition: faceZone.C:397
const labelList & slaveCells() const
Deprecated(2023-09) same as backCells.
Definition: faceZone.H:528
faceZone(const faceZone &)=delete
No copy construct.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:157
const labelList & backCells() const
The back cells layer. Cells on the negative normal side of faces.
Definition: faceZone.C:423
void operator=(const faceZone &zn)
Assign addressing, clearing demand-driven data.
Definition: faceZone.C:702
const labelList & masterCells() const
Deprecated(2023-09) same as frontCells.
Definition: faceZone.H:521
A list of faces which address into the list of points.
const faceZoneMesh & zoneMesh() const noexcept
Return reference to the zone mesh.
Definition: faceZone.H:354
Base class for mesh zones.
Definition: zone.H:59
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual void writeDict(Ostream &os) const
Write dictionary.
Definition: faceZone.C:687
virtual void resetAddressing(faceZone &&zn)
Move reset addressing and flip map from another zone.
Definition: faceZone.C:477
virtual void clearPrimitives()
Clear primitive addressing.
Definition: faceZone.C:470
const labelList & meshEdges() const
Return global edge index for local edges.
Definition: faceZone.C:433
const primitiveFacePatch & patch() const
Return [demand-driven] reference to an equivalent primitive patch, with faces oriented according to f...
Definition: faceZone.C:403
virtual void write(Ostream &os) const
Write.
Definition: faceZone.C:679
const labelList & addressing() const noexcept
The addressing (face IDs) used for the zone.
Definition: faceZone.H:359
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
label index() const noexcept
The index of this zone in the zone list.
OBJstream os(runTime.globalPath()/outputName)
virtual void clearAddressing()
Clear addressing (remove lookup maps, patch/geometric information)
Definition: faceZone.C:463
static const char *const labelsName
The name associated with the zone-labels dictionary entry ("faceLabels")
Definition: faceZone.H:144
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
virtual ~faceZone()=default
Destructor.
const primitiveFacePatch & operator()() const
Deprecated(2023-09) same as patch()
Definition: faceZone.H:514
virtual void updateMesh(const mapPolyMesh &mpm)
Update for changes in topology.
Definition: faceZone.C:542
const word & name() const noexcept
The zone name.
virtual bool checkDefinition(const bool report=false) const
Check zone definition. Return true if in error.
Definition: faceZone.C:574
friend Ostream & operator<<(Ostream &os, const faceZone &zn)
Ostream Operator.
autoPtr< List< label > > clone() const
Clone.
Definition: ListI.H:121
const boolList & flipMap() const noexcept
Return face flip map.
Definition: faceZone.H:367
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
declareRunTimeSelectionTable(autoPtr, faceZone, dictionary,(const word &name, const dictionary &dict, const label index, const faceZoneMesh &zm),(name, dict, index, zm))
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:60
List< label > labelList
A List of labels.
Definition: List.H:62
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
Definition: autoPtr.H:178
TypeName("faceZone")
Runtime type information.
Namespace for OpenFOAM.
const pointField & pts