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-2022 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  //- Disallow default bitwise assignment
83  void operator=(const MeshZones<ZoneType, MeshType>&);
84 
85 
86  //- Create zone map
87  void calcZoneMap() const;
88 
89 
90 public:
91 
92  // Constructors
93 
94  //- Read constructor given IOobject and a MeshType reference
95  MeshZones
96  (
97  const IOobject&,
98  const MeshType&
99  );
100 
101  //- Construct given size
102  MeshZones
103  (
104  const IOobject&,
105  const MeshType&,
106  const label size
107  );
108 
109  //- Construct given a PtrList
110  MeshZones
111  (
112  const IOobject&,
113  const MeshType&,
114  const PtrList<ZoneType>&
115  );
116 
117  //- Move constructor
118  MeshZones(MeshZones&&) = default;
119 
120  //- Disallow default bitwise copy construction
121  MeshZones(const MeshZones&) = delete;
122 
123 
124  //- Destructor
125  ~MeshZones();
126 
127 
128  // Member Functions
129 
130  //- Return the mesh reference
131  const MeshType& mesh() const
132  {
133  return mesh_;
134  }
135 
136  //- Map of zones containing zone index for all zoned elements
137  // Return -1 if the object is not in the zone
138  const Map<label>& zoneMap() const;
139 
140  //- Given a global object index, return the zone it is in.
141  // If object does not belong to any zones, return -1
142  label whichZone(const label objectIndex) const;
143 
144  //- Return a list of zone types
145  wordList types() const;
146 
147  //- Return a list of zone names
148  wordList names() const;
149 
150  //- Return zone indices for all matches
151  labelList findIndices(const wordRe&) const;
152 
153  //- Return zone index for the first match, return -1 if not found
154  label findIndex(const wordRe&) const;
155 
156  //- Find zone index given a name
157  label findZoneID(const word& zoneName) const;
158 
159  //- Mark cells that match the zone specification
160  PackedBoolList findMatching(const wordRe&) const;
161 
162  //- Clear addressing
163  void clearAddressing();
164 
165  //- Clear the zones
166  void clear();
167 
168  //- Check zone definition. Return true if in error.
169  bool checkDefinition(const bool report = false) const;
170 
171  //- Check whether all procs have all zones and in same order. Return
172  // true if in error.
173  bool checkParallelSync(const bool report = false) const;
174 
175  //- Correct zones after moving points
176  void movePoints(const pointField&);
177 
178  //- writeData member function required by regIOobject
179  bool writeData(Ostream&) const;
180 
181 
182  // Member Operators
183 
184  //- Return const and non-const reference to ZoneType by index.
186 
187  //- Return const reference to ZoneType by name.
188  const ZoneType& operator[](const word&) const;
189 
190  //- Return reference to ZoneType by name.
191  ZoneType& operator[](const word&);
192 
193 
194  // Ostream operator
195 
196  friend Ostream& operator<< <ZoneType, MeshType>
197  (
198  Ostream&,
200  );
201 };
202 
203 
204 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205 
206 } // End namespace Foam
207 
208 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
209 
210 #ifdef NoRepository
211  #include "MeshZones.C"
212 #endif
213 
214 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
215 
216 #endif
217 
218 // ************************************************************************* //
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
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:130
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 &)