MeshZones.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::MeshZones
26 
27 Description
28  A list of mesh zones.
29 
30 SourceFiles
31  MeshZones.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef MeshZones_H
36 #define MeshZones_H
37 
38 #include "List.H"
39 #include "regIOobject.H"
40 #include "pointField.H"
41 #include "Map.H"
42 #include "PackedBoolList.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 // Forward declaration of friend functions and operators
52 
53 template<class ZoneType, class MeshType> class MeshZones;
54 
55 template<class ZoneType, class MeshType>
57 
58 /*---------------------------------------------------------------------------*\
59  Class MeshZones Declaration
60 \*---------------------------------------------------------------------------*/
61 
62 template<class ZoneType, class MeshType>
63 class MeshZones
64 :
65  public PtrList<ZoneType>,
66  public regIOobject
67 {
68  // Private Data
69 
70  //- Reference to mesh
71  const MeshType& mesh_;
72 
73  //- Map of zone labels for given element
74  mutable Map<label>* zoneMapPtr_;
75 
76 
77  // Private Member Functions
78 
79  //- Read if IOobject flags set. Return true if read.
80  bool read();
81 
82  //- Create zone map
83  void calcZoneMap() const;
84 
85 
86 public:
87 
88  // Constructors
89 
90  //- Read constructor given IOobject and a MeshType reference
91  MeshZones
92  (
93  const IOobject&,
94  const MeshType&
95  );
96 
97  //- Construct given size
98  MeshZones
99  (
100  const IOobject&,
101  const MeshType&,
102  const label size
103  );
104 
105  //- Construct given a PtrList
106  MeshZones
107  (
108  const IOobject&,
109  const MeshType&,
110  const PtrList<ZoneType>&
111  );
112 
113  //- Move constructor
114  MeshZones(MeshZones&&) = default;
115 
116  //- Disallow default bitwise copy construction
117  MeshZones(const MeshZones&) = delete;
118 
119 
120  //- Destructor
121  ~MeshZones();
122 
123 
124  // Member Functions
125 
126  //- Return the mesh reference
127  const MeshType& mesh() const
128  {
129  return mesh_;
130  }
131 
132  //- Map of zones containing zone index for all zoned elements
133  // Return -1 if the object is not in the zone
134  const Map<label>& zoneMap() const;
135 
136  //- Given a global object index, return the zone it is in.
137  // If object does not belong to any zones, return -1
138  label whichZone(const label objectIndex) const;
139 
140  //- Return a list of zone types
141  wordList types() const;
142 
143  //- Return a list of zone names
144  wordList names() const;
145 
146  //- Return zone indices for all matches
147  labelList findIndices(const wordRe&) const;
148 
149  //- Return zone index for the first match, return -1 if not found
150  label findIndex(const wordRe&) const;
151 
152  //- Find zone index given a name
153  label findZoneID(const word& zoneName) const;
154 
155  //- Mark cells that match the zone specification
156  PackedBoolList findMatching(const wordRe&) const;
157 
158  //- Clear addressing
159  void clearAddressing();
160 
161  //- Clear the zones
162  void clear();
163 
164  //- Check zone definition. Return true if in error.
165  bool checkDefinition(const bool report = false) const;
166 
167  //- Check whether all procs have all zones and in same order. Return
168  // true if in error.
169  bool checkParallelSync(const bool report = false) const;
170 
171  //- Correct zones after moving points
172  void movePoints(const pointField&);
173 
174  //- writeData member function required by regIOobject
175  bool writeData(Ostream&) const;
176 
177 
178  // Member Operators
179 
180  //- Return const and non-const reference to ZoneType by index.
182 
183  //- Return const reference to ZoneType by name.
184  const ZoneType& operator[](const word&) const;
185 
186  //- Return reference to ZoneType by name.
187  ZoneType& operator[](const word&);
188 
189  //- Disallow default bitwise assignment
190  void operator=(const MeshZones<ZoneType, MeshType>&) = delete;
191 
192 
193  // Ostream operator
194 
195  friend Ostream& operator<< <ZoneType, MeshType>
196  (
197  Ostream&,
199  );
200 };
201 
202 
203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
204 
205 } // End namespace Foam
206 
207 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
208 
209 #ifdef NoRepository
210  #include "MeshZones.C"
211 #endif
212 
213 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
214 
215 #endif
216 
217 // ************************************************************************* //
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
A list of mesh zones.
Definition: MeshZones.H:66
bool checkDefinition(const bool report=false) const
Check zone definition. Return true if in error.
Definition: MeshZones.C:410
label findZoneID(const word &zoneName) const
Find zone index given a name.
Definition: MeshZones.C:341
bool writeData(Ostream &) const
writeData member function required by regIOobject
Definition: MeshZones.C:517
wordList types() const
Return a list of zone types.
Definition: MeshZones.C:240
~MeshZones()
Destructor.
Definition: MeshZones.C:198
void operator=(const MeshZones< ZoneType, MeshType > &)=delete
Disallow default bitwise assignment.
labelList findIndices(const wordRe &) const
Return zone indices for all matches.
Definition: MeshZones.C:273
const ZoneType & operator[](const word &) const
Return const reference to ZoneType by name.
Definition: MeshZones.C:528
const Map< label > & zoneMap() const
Map of zones containing zone index for all zoned elements.
Definition: MeshZones.C:208
void clearAddressing()
Clear addressing.
Definition: MeshZones.C:387
void movePoints(const pointField &)
Correct zones after moving points.
Definition: MeshZones.C:505
const MeshType & mesh() const
Return the mesh reference.
Definition: MeshZones.H:126
label findIndex(const wordRe &) const
Return zone index for the first match, return -1 if not found.
Definition: MeshZones.C:306
void clear()
Clear the zones.
Definition: MeshZones.C:401
label whichZone(const label objectIndex) const
Given a global object index, return the zone it is in.
Definition: MeshZones.C:221
wordList names() const
Return a list of zone names.
Definition: MeshZones.C:256
bool checkParallelSync(const bool report=false) const
Check whether all procs have all zones and in same order. Return.
Definition: MeshZones.C:428
MeshZones(const IOobject &, const MeshType &)
Read constructor given IOobject and a MeshType reference.
Definition: MeshZones.C:137
PackedBoolList findMatching(const wordRe &) const
Mark cells that match the zone specification.
Definition: MeshZones.C:370
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A bit-packed bool list.
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:55
A wordRe is a word, but can also have a regular expression for matching words.
Definition: wordRe.H:77
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & operator<<(Ostream &, const ensightPart &)