Zone.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-2024 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::Zone
26 
27 Description
28  Base class for zones
29 
30 SourceFiles
31  Zone.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef Zone_H
36 #define Zone_H
37 
38 #include "labelList.H"
39 #include "typeInfo.H"
40 #include "dictionary.H"
41 #include "Map.H"
42 #include "pointFieldFwd.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 // Forward declaration of friend functions and operators
50 
51 class polyTopoChangeMap;
52 class polyMeshMap;
53 class polyDistributionMap;
54 
55 template<class ZoneType, class ZonesType> class Zone;
56 
57 template<class ZoneType, class ZonesType>
59 
60 /*---------------------------------------------------------------------------*\
61  Class Zone Declaration
62 \*---------------------------------------------------------------------------*/
63 
64 template<class ZoneType, class ZonesType>
65 class Zone
66 :
67  public labelList
68 {
69 
70 protected:
71 
72  // Protected data
73 
74  //- Name of zone
75  word name_;
76 
77  //- Reference to zone list
78  const ZonesType& zones_;
79 
80 
81  // Demand-driven private data
82 
83  //- Map of labels in zone for fast location lookup
84  mutable Map<label>* lookupMapPtr_;
85 
86 
87  // Protected Member Functions
88 
89  //- Select the
90  template<class Type>
91  void select(const Type& zone);
92 
93  //- Construct the look-up map
94  void calcLookupMap() const;
95 
96  //- Update the addressing using the maps provided
97  void topoChange(const labelList& map, const labelList& reverseMap);
98 
99 
100 public:
101 
102  // Declare run-time constructor selection tables
103 
105  (
106  autoPtr,
107  ZoneType,
108  dictionary,
109  (
110  const word& name,
111  const dictionary& dict,
112  const ZonesType& mz
113  ),
114  (name, dict, mz)
115  );
116 
117 
118  // Constructors
119 
120  //- Construct from components
121  Zone
122  (
123  const word& name,
124  const labelUList& indices,
125  const ZonesType& zones
126  );
127 
128  //- Construct from components, moving contents
129  Zone
130  (
131  const word& name,
132  labelList&& indices,
133  const ZonesType& zones
134  );
135 
136  //- Construct from dictionary
137  Zone
138  (
139  const word& name,
140  const dictionary&,
141  const ZonesType& zones
142  );
143 
144  //- Construct given the original zone and resetting the
145  // cell list and mesh zones information
146  Zone
147  (
148  const Zone&,
149  const labelUList& indices,
150  const ZonesType& zones
151  );
152 
153  //- Construct given the original zone, resetting the
154  // cell list and mesh zones information
155  Zone
156  (
157  const Zone&,
158  labelList&& indices,
159  const ZonesType& zones
160  );
161 
162  //- Disallow default bitwise copy construction
163  Zone(const Zone&) = delete;
164 
165 
166  // Selectors
167 
168  //- Return a pointer to a new cell zone
169  // created on freestore from dictionary
170  static autoPtr<ZoneType> New
171  (
172  const word& name,
173  const dictionary&,
174  const ZonesType&
175  );
176 
177 
178  //- Destructor
179  virtual ~Zone();
180 
181 
182  // Member Functions
183 
184  //- Return name
185  const word& name() const
186  {
187  return name_;
188  }
189 
190  //- Return name as the keyword
191  const word& keyword() const
192  {
193  return name_;
194  }
195 
196  //- Return ZonesType reference
197  const ZonesType& zones() const;
198 
199  //- Map storing the local index for every global index. Used to find
200  // the index of the item in the zone from the known global index. If
201  // the item is not in the zone, returns -1
202  label localIndex(const label globalIndex) const;
203 
204  //- Return a reference to the look-up map
205  const Map<label>& lookupMap() const;
206 
207  //- Clear addressing
208  virtual void clearAddressing();
209 
210  //- Check zone definition with max size given. Return true if in error.
211  bool checkDefinition
212  (
213  const label maxSize,
214  const bool report = false
215  ) const;
216 
217  //- Insert given indices into zone
218  void insert(const labelHashSet& newIndices);
219 
220  //- Swap two zones
221  void swap(Zone&);
222 
223  //- Correct patch after moving points
224  virtual void movePoints(const pointField&)
225  {}
226 
227  //- Update zone using the given map
228  virtual void topoChange(const polyTopoChangeMap& map) = 0;
229 
230  //- Update from another mesh using the given map
231  virtual void mapMesh(const polyMeshMap&);
232 
233  //- Redistribute or update using the given distribution map
234  virtual void distribute(const polyDistributionMap&);
235 
236  //- Write dictionary
237  virtual void writeDict(Ostream&) const = 0;
238 
239 
240  // Member Operators
241 
242  //- Assignment operator
243  void operator=(const Zone&);
244 
245  //- Move assignment operator
246  void operator=(Zone&&);
247 
248  //- Assignment operator to indices
249  void operator=(const labelUList&);
250 
251  //- Move assignment of indices
252  void operator=(labelList&&);
253 
254 
255  // I-O
256 
257  //- Ostream Operator
258  friend Ostream& operator<< <ZoneType, ZonesType>
259  (
260  Ostream&,
262  );
263 };
264 
265 
266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
267 
268 } // End namespace Foam
269 
270 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
271 
272 #ifdef NoRepository
273  #include "Zone.C"
274 #endif
275 
276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
277 
278 #endif
279 
280 // ************************************************************************* //
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Base class for zones.
Definition: Zone.H:67
const Map< label > & lookupMap() const
Return a reference to the look-up map.
Definition: Zone.C:260
void swap(Zone &)
Swap two zones.
Definition: Zone.C:337
Zone(const word &name, const labelUList &indices, const ZonesType &zones)
Construct from components.
Definition: Zone.C:112
virtual void writeDict(Ostream &) const =0
Write dictionary.
void topoChange(const labelList &map, const labelList &reverseMap)
Update the addressing using the maps provided.
Definition: Zone.C:79
bool checkDefinition(const label maxSize, const bool report=false) const
Check zone definition with max size given. Return true if in error.
Definition: Zone.C:280
virtual void movePoints(const pointField &)
Correct patch after moving points.
Definition: Zone.H:223
word name_
Name of zone.
Definition: Zone.H:74
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
Definition: Zone.C:352
label localIndex(const label globalIndex) const
Map storing the local index for every global index. Used to find.
Definition: Zone.C:240
const word & keyword() const
Return name as the keyword.
Definition: Zone.H:190
void calcLookupMap() const
Construct the look-up map.
Definition: Zone.C:56
Map< label > * lookupMapPtr_
Map of labels in zone for fast location lookup.
Definition: Zone.H:83
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
Definition: Zone.C:345
virtual ~Zone()
Destructor.
Definition: Zone.C:223
void insert(const labelHashSet &newIndices)
Insert given indices into zone.
Definition: Zone.C:328
virtual void clearAddressing()
Clear addressing.
Definition: Zone.C:272
void select(const Type &zone)
Select the.
Definition: Zone.C:35
static autoPtr< ZoneType > New(const word &name, const dictionary &, const ZonesType &)
Return a pointer to a new cell zone.
Definition: Zone.C:187
const word & name() const
Return name.
Definition: Zone.H:184
void operator=(const Zone &)
Assignment operator.
Definition: Zone.C:361
declareRunTimeSelectionTable(autoPtr, ZoneType, dictionary,(const word &name, const dictionary &dict, const ZonesType &mz),(name, dict, mz))
const ZonesType & zones_
Reference to zone list.
Definition: Zone.H:77
const ZonesType & zones() const
Return ZonesType reference.
Definition: Zone.C:232
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:64
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.
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)
dictionary dict
Basic run-time type information using word as the type's name. Used to enhance the standard RTTI to c...