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-2021 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>
56 Ostream& operator<<(Ostream&, const MeshZones<ZoneType, 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 copy construction
83  MeshZones(const MeshZones&);
84 
85  //- Disallow default bitwise assignment
86  void operator=(const MeshZones<ZoneType, MeshType>&);
87 
88 
89  //- Create zone map
90  void calcZoneMap() const;
91 
92 
93 public:
94 
95  // Constructors
96 
97  //- Read constructor given IOobject and a MeshType reference
98  MeshZones
99  (
100  const IOobject&,
101  const MeshType&
102  );
103 
104  //- Construct given size
105  MeshZones
106  (
107  const IOobject&,
108  const MeshType&,
109  const label size
110  );
111 
112  //- Construct given a PtrList
113  MeshZones
114  (
115  const IOobject&,
116  const MeshType&,
117  const PtrList<ZoneType>&
118  );
119 
120 
121  //- Destructor
122  ~MeshZones();
123 
124 
125  // Member Functions
126 
127  //- Return the mesh reference
128  const MeshType& mesh() const
129  {
130  return mesh_;
131  }
132 
133  //- Map of zones containing zone index for all zoned elements
134  // Return -1 if the object is not in the zone
135  const Map<label>& zoneMap() const;
136 
137  //- Given a global object index, return the zone it is in.
138  // If object does not belong to any zones, return -1
139  label whichZone(const label objectIndex) const;
140 
141  //- Return a list of zone types
142  wordList types() const;
143 
144  //- Return a list of zone names
145  wordList names() const;
146 
147  //- Return zone indices for all matches
148  labelList findIndices(const wordRe&) const;
149 
150  //- Return zone index for the first match, return -1 if not found
151  label findIndex(const wordRe&) const;
152 
153  //- Find zone index given a name
154  label findZoneID(const word& zoneName) const;
155 
156  //- Mark cells that match the zone specification
157  PackedBoolList findMatching(const wordRe&) const;
158 
159  //- Clear addressing
160  void clearAddressing();
161 
162  //- Clear the zones
163  void clear();
164 
165  //- Check zone definition. Return true if in error.
166  bool checkDefinition(const bool report = false) const;
167 
168  //- Check whether all procs have all zones and in same order. Return
169  // true if in error.
170  bool checkParallelSync(const bool report = false) const;
171 
172  //- Correct zones after moving points
173  void movePoints(const pointField&);
174 
175  //- writeData member function required by regIOobject
176  bool writeData(Ostream&) const;
177 
178 
179  // Member Operators
180 
181  //- Return const and non-const reference to ZoneType by index.
183 
184  //- Return const reference to ZoneType by name.
185  const ZoneType& operator[](const word&) const;
186 
187  //- Return reference to ZoneType by name.
188  ZoneType& operator[](const word&);
189 
190 
191  // Ostream operator
192 
193  friend Ostream& operator<< <ZoneType, MeshType>
194  (
195  Ostream&,
197  );
198 };
199 
200 
201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
202 
203 } // End namespace Foam
204 
205 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
206 
207 #ifdef NoRepository
208  #include "MeshZones.C"
209 #endif
210 
211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212 
213 #endif
214 
215 // ************************************************************************* //
label findZoneID(const word &zoneName) const
Find zone index given a name.
Definition: MeshZones.C:341
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
IOobject(const word &name, const fileName &instance, const objectRegistry &registry, readOption r=NO_READ, writeOption w=NO_WRITE, bool registerObject=true)
Construct from name, instance, registry, io options.
Definition: IOobject.C:167
bool checkParallelSync(const bool report=false) const
Check whether all procs have all zones and in same order. Return.
Definition: MeshZones.C:428
bool checkDefinition(const bool report=false) const
Check zone definition. Return true if in error.
Definition: MeshZones.C:410
void clear()
Clear the zones.
Definition: MeshZones.C:401
void movePoints(const pointField &)
Correct zones after moving points.
Definition: MeshZones.C:505
PackedBoolList findMatching(const wordRe &) const
Mark cells that match the zone specification.
Definition: MeshZones.C:370
wordList names() const
Return a list of zone names.
Definition: MeshZones.C:256
wordList types() const
Return a list of zone types.
Definition: MeshZones.C:240
A class for handling words, derived from string.
Definition: word.H:59
const MeshType & mesh() const
Return the mesh reference.
Definition: MeshZones.H:127
A wordRe is a word, but can also have a regular expression for matching words.
Definition: wordRe.H:74
A list of mesh zones.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
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
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
label whichZone(const label objectIndex) const
Given a global object index, return the zone it is in.
Definition: MeshZones.C:221
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: List.H:70
label findIndex(const wordRe &) const
Return zone index for the first match, return -1 if not found.
Definition: MeshZones.C:306
~MeshZones()
Destructor.
Definition: MeshZones.C:198
bool writeData(Ostream &) const
writeData member function required by regIOobject
Definition: MeshZones.C:517
void clearAddressing()
Clear addressing.
Definition: MeshZones.C:387
Namespace for OpenFOAM.
labelList findIndices(const wordRe &) const
Return zone indices for all matches.
Definition: MeshZones.C:273