ZoneList.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-2025 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::ZoneList
26 
27 Description
28  A list of mesh zones.
29 
30 SourceFiles
31  ZoneList.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef ZoneList_H
36 #define ZoneList_H
37 
38 #include "PtrListDictionary.H"
39 #include "regIOobject.H"
40 #include "pointFieldFwd.H"
41 #include "Map.H"
42 #include "boolList.H"
43 #include "PackedBoolList.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 // Forward declaration of friend functions and operators
53 
54 class polyTopoChangeMap;
55 class polyMeshMap;
56 class polyDistributionMap;
57 
58 template<class ZoneType, class ZonesType, class MeshType> class ZoneList;
59 
60 template<class ZoneType, class ZonesType, class MeshType>
62 
63 /*---------------------------------------------------------------------------*\
64  Class ZoneList Declaration
65 \*---------------------------------------------------------------------------*/
66 
67 template<class ZoneType, class ZonesType, class MeshType>
68 class ZoneList
69 :
70  public regIOobject,
71  public PtrListDictionary<ZoneType>
72 {
73  // Private Data
74 
75  //- Reference to mesh
76  const MeshType& mesh_;
77 
78  //- Current timeIndex
79  mutable label timeIndex_;
80 
81  mutable autoPtr<ZoneType> all_;
82 
83 
84  // Private Member Functions
85 
86  //- Read if IOobject flags set. Return true if read.
87  bool read();
88 
89 
90 public:
91 
92  typedef ZoneType zoneType;
93 
94 
95  // Constructors
96 
97  //- Read constructor given IOobject and a MeshType reference
98  ZoneList
99  (
100  const IOobject&,
101  const MeshType&
102  );
103 
104  //- Move constructor
105  ZoneList(ZoneList&&) = default;
106 
107  //- Disallow default bitwise copy construction
108  ZoneList(const ZoneList&) = delete;
109 
110 
111  //- Destructor
112  ~ZoneList();
113 
114 
115  // Member Functions
116 
117  //- Return the mesh reference
118  const MeshType& mesh() const
119  {
120  return mesh_;
121  }
122 
123  label timeIndex() const
124  {
125  return timeIndex_;
126  }
127 
129 
130  //- Return true if objectIndex is in any zone
131  bool found(const label objectIndex) const;
132 
134 
135  //- Return const reference to ZoneType by name
136  const ZoneType* lookupPtr(const word& name) const;
137 
138  //- Given a global object index, return the list of zones it is in
139  labelList whichZones(const label objectIndex) const;
140 
141  //- Return the set of zone indices corresponding to the given names
142  // By default warns if given names are not found
144  (
145  const UList<wordRe>& zoneNames,
146  const bool warnNotFound = true
147  ) const;
148 
149  //- Append or update a zone
150  const ZoneType& append(ZoneType*) const;
151 
152  //- Append or update a zone
153  const ZoneType& append(const ZoneType&) const;
154 
155  //- Clear addressing
156  void clearAddressing();
157 
158  //- Clear the zones
159  void clear();
160 
161  //- Check zone definition. Return true if in error.
162  bool checkDefinition(const bool report = false) const;
163 
164  //- Check whether all procs have all zones and in same order. Return
165  // true if in error.
166  bool checkParallelSync(const bool report = false) const;
167 
168  //- Insert given indices into zones
169  void insert(const List<labelHashSet>& zonesIndices);
170 
171  //- Return true if any of the zones were not updated by zoneGenerators
172  // following mesh topology change
173  bool noTopoUpdate() const;
174 
175  //- Correct zones after moving points
176  virtual void movePoints(const pointField&);
177 
178  //- Update topology using the given map
179  virtual void topoChange(const polyTopoChangeMap& map);
180 
181  //- Update from another mesh using the given map
182  virtual void mapMesh(const polyMeshMap&);
183 
184  //- Redistribute or update using the given distribution map
185  virtual void distribute(const polyDistributionMap&);
186 
187  //- Swap zones
188  // For run-time mesh replacement and mesh to mesh mapping
189  void swap(ZonesType&);
190 
191  //- Read zones if the zones file is present
192  bool readIfPresent();
193 
194  //- writeData member function required by regIOobject
195  virtual bool writeData(Ostream&) const;
196 
197  //- Write using given format, version and compression
198  // Only write the zones file if there are zones in the list
199  virtual bool writeObject
200  (
204  const bool write
205  ) const;
206 
207 
208  //- Return const reference to the all zone
209  const ZoneType& all() const;
210 
211 
212  // Member Operators
213 
215 
216  //- Return const reference to ZoneType by name
217  const ZoneType& operator[](const word& name) const;
218 
219  //- Return non-const reference to ZoneType by name
220  ZoneType& operator[](const word& name);
221 
222  //- Disallow default bitwise assignment
224 
225 
226  // Ostream operator
227 
228  friend Ostream& operator<< <ZoneType, ZonesType, MeshType>
229  (
230  Ostream&,
232  );
233 };
234 
235 
236 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
237 
238 } // End namespace Foam
239 
240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
241 
242 #ifdef NoRepository
243  #include "ZoneList.C"
244 #endif
245 
246 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
247 
248 #endif
249 
250 // ************************************************************************* //
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
const word & name() const
Return name.
Definition: IOobject.H:307
Version number type.
Definition: IOstream.H:97
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:194
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Template dictionary class which manages the storage associated with it.
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
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:74
A list of mesh zones.
Definition: ZoneList.H:71
bool checkDefinition(const bool report=false) const
Check zone definition. Return true if in error.
Definition: ZoneList.C:291
const ZoneType & all() const
Return const reference to the all zone.
Definition: ZoneList.C:596
label timeIndex() const
Definition: ZoneList.H:122
~ZoneList()
Destructor.
Definition: ZoneList.C:114
void insert(const List< labelHashSet > &zonesIndices)
Insert given indices into zones.
Definition: ZoneList.C:378
virtual bool writeData(Ostream &) const
writeData member function required by regIOobject
Definition: ZoneList.C:568
const ZoneType & append(ZoneType *) const
Append or update a zone.
Definition: ZoneList.C:214
bool found(const label objectIndex) const
Return true if objectIndex is in any zone.
Definition: ZoneList.C:124
ZoneList(const IOobject &, const MeshType &)
Read constructor given IOobject and a MeshType reference.
Definition: ZoneList.C:97
bool noTopoUpdate() const
Return true if any of the zones were not updated by zoneGenerators.
Definition: ZoneList.C:402
bool readIfPresent()
Read zones if the zones file is present.
Definition: ZoneList.C:560
virtual bool writeObject(IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType, const bool write) const
Write using given format, version and compression.
Definition: ZoneList.C:577
labelList whichZones(const label objectIndex) const
Given a global object index, return the list of zones it is in.
Definition: ZoneList.C:159
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
Definition: ZoneList.C:483
labelHashSet zoneSet(const UList< wordRe > &zoneNames, const bool warnNotFound=true) const
Return the set of zone indices corresponding to the given names.
Definition: ZoneList.C:179
void swap(ZonesType &)
Swap zones.
Definition: ZoneList.C:501
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
Definition: ZoneList.C:464
ZoneType zoneType
Definition: ZoneList.H:91
void clearAddressing()
Clear addressing.
Definition: ZoneList.C:270
void operator=(const ZoneList< ZoneType, ZonesType, MeshType > &)=delete
Disallow default bitwise assignment.
virtual void movePoints(const pointField &)
Correct zones after moving points.
Definition: ZoneList.C:420
const MeshType & mesh() const
Return the mesh reference.
Definition: ZoneList.H:117
void clear()
Clear the zones.
Definition: ZoneList.C:282
const ZoneType & operator[](const word &name) const
Return const reference to ZoneType by name.
Definition: ZoneList.C:618
bool checkParallelSync(const bool report=false) const
Check whether all procs have all zones and in same order. Return.
Definition: ZoneList.C:309
virtual void topoChange(const polyTopoChangeMap &map)
Update topology using the given map.
Definition: ZoneList.C:435
const ZoneType * lookupPtr(const word &name) const
Return const reference to ZoneType by name.
Definition: ZoneList.C:142
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:55
virtual bool write(const bool write=true) const
Write using setting from DB.
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 &os, const fvConstraints &constraints)