cellZone.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2017-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::cellZone
29 
30 Description
31  A subset of mesh cells.
32 
33  Currently set up as an indirect list but will be extended to use a
34  primitive mesh. For quick check whether a cell belongs to the zone use
35  the lookup mechanism in cellZoneMesh, where all the zoned cells are
36  registered with their zone number.
37 
38 SourceFiles
39  cellZone.C
40  cellZoneNew.C
41 
42 \*---------------------------------------------------------------------------*/
43 
44 #ifndef Foam_cellZone_H
45 #define Foam_cellZone_H
46 
47 #include "zone.H"
48 #include "cellZoneMeshFwd.H"
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace Foam
53 {
54 
55 // Forward Declarations
56 class cellZone;
57 Ostream& operator<<(Ostream& os, const cellZone& zn);
58 
59 /*---------------------------------------------------------------------------*\
60  Class cellZone Declaration
61 \*---------------------------------------------------------------------------*/
62 
63 class cellZone
64 :
65  public zone
66 {
67  // Private Data
68 
69  //- Reference to zone list
70  const cellZoneMesh& zoneMesh_;
71 
72 
73 public:
74 
75  // Static Data Members
76 
77  //- The name associated with the zone-labels dictionary entry
78  //- ("cellLabels")
79  static const char * const labelsName;
80 
81 
82  //- Runtime type information
83  TypeName("cellZone");
84 
85 
86  // Declare run-time constructor selection tables
87 
89  (
90  autoPtr,
91  cellZone,
92  dictionary,
93  (
94  const word& name,
95  const dictionary& dict,
96  const label index,
97  const cellZoneMesh& zm
98  ),
99  (name, dict, index, zm)
100  );
101 
102 
103  // Constructors
104 
105  //- No copy construct
106  cellZone(const cellZone&) = delete;
107 
108  //- Construct an empty zone - name="", index=0
109  explicit cellZone(const cellZoneMesh& zm);
110 
111  //- Construct an empty zone with specified name and index
112  cellZone
113  (
114  const word& name,
115  const label index,
116  const cellZoneMesh& zm
117  );
118 
119  //- Construct from components
120  cellZone
121  (
122  const word& name,
123  const labelUList& addr,
124  const label index,
125  const cellZoneMesh& zm
126  );
127 
128  //- Construct from components, transferring addressing
129  cellZone
130  (
131  const word& name,
132  labelList&& addr,
133  const label index,
134  const cellZoneMesh& zm
135  );
136 
137  //- Construct from dictionary
138  cellZone
139  (
140  const word& name,
141  const dictionary& dict,
142  const label index,
143  const cellZoneMesh& zm
144  );
145 
146  //- Construct empty with original zone information (name, index, groups)
147  //- and mesh reference. Optionally specify a new index.
148  cellZone
149  (
150  const cellZone& originalZone,
151  const Foam::zero,
152  const cellZoneMesh& zm,
153  const label newIndex = -1
154  );
155 
156  //- Construct empty with original zone information (name, groups),
157  //- resetting the index and zone mesh reference.
158  cellZone
159  (
160  const cellZone& originalZone,
161  const Foam::zero,
162  const label index,
163  const cellZoneMesh& zm
164  );
165 
166  //- Construct with original zone information (name, groups),
167  //- resetting the cell list, the index and zone mesh reference.
168  cellZone
169  (
170  const cellZone& originalZone,
171  const labelUList& addr,
172  const label index,
173  const cellZoneMesh& zm
174  );
175 
176  //- Construct with original zone information (name, groups),
177  //- resetting the cell list, the index and zone mesh reference.
178  cellZone
179  (
180  const cellZone& originalZone,
181  labelList&& addr,
182  const label index,
183  const cellZoneMesh& zm
184  );
185 
186 
187  //- Construct and return a clone, resetting the zone mesh
188  virtual autoPtr<cellZone> clone(const cellZoneMesh& zm) const
189  {
190  return autoPtr<cellZone>::New(*this, *this, index(), zm);
191  }
192 
193  //- Construct and return a clone,
194  //- resetting the cell list and zone mesh
195  virtual autoPtr<cellZone> clone
196  (
197  const labelUList& addr,
198  const label index,
199  const cellZoneMesh& zm
200  ) const
201  {
202  return autoPtr<cellZone>::New(*this, addr, index, zm);
203  }
204 
205 
206  // Selectors
207 
208  //- Return a pointer to a new cell zone
209  //- created on freestore from dictionary
210  static autoPtr<cellZone> New
211  (
212  const word& name,
213  const dictionary& dict,
214  const label index,
215  const cellZoneMesh& zm
216  );
217 
218 
219  //- Destructor
220  virtual ~cellZone() = default;
222 
223  // Member Functions
224 
225  //- Return reference to the zone mesh
226  const cellZoneMesh& zoneMesh() const noexcept { return zoneMesh_; }
227 
228  //- The addressing (cell IDs) used for the zone
229  const labelList& addressing() const noexcept
230  {
231  return static_cast<const labelList&>(*this);
232  }
233 
234  //- Helper function to re-direct to zone::localID(...)
235  label whichCell(const label globalCellID) const;
236 
237 
238  //- Check zone definition. Return true if in error.
239  virtual bool checkDefinition(const bool report = false) const;
240 
241  //- Check whether zone is synchronised across coupled boundaries.
242  // \return True if any errors.
243  virtual bool checkParallelSync(const bool report = false) const
244  {
245  return false;
246  }
247 
248  //- Write dictionary
249  virtual void writeDict(Ostream& os) const;
250 
251 
252  // Assign addressing
253 
254  //- Move reset addressing from another zone
255  virtual void resetAddressing(cellZone&& zn);
256 
257  //- Copy reset addressing from another zone
258  virtual void resetAddressing(const cellZone& zn);
259 
260  //- Copy assign addressing
261  virtual void resetAddressing(const labelUList& addr);
263  //- Move assign addressing
264  virtual void resetAddressing(labelList&& addr);
265 
266  //- Assign addressing, clearing demand-driven data
267  void operator=(const cellZone& zn);
268 
269  //- Assign addressing, clearing demand-driven data
270  void operator=(const labelUList& addr);
271 
272  //- Move assign addressing, clearing demand-driven data
273  void operator=(labelList&& addr);
274 
275 
276  // I-O
277 
278  //- Ostream Operator
279  friend Ostream& operator<<(Ostream& os, const cellZone& zn);
280 };
281 
282 
283 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
284 
285 } // End namespace Foam
286 
287 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
288 
289 #endif
290 
291 // ************************************************************************* //
label whichCell(const label globalCellID) const
Helper function to re-direct to zone::localID(...)
Definition: cellZone.C:156
dictionary dict
TypeName("cellZone")
Runtime type information.
virtual void resetAddressing(cellZone &&zn)
Move reset addressing from another zone.
Definition: cellZone.C:180
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
static autoPtr< cellZone > New(const word &name, const dictionary &dict, const label index, const cellZoneMesh &zm)
Return a pointer to a new cell zone created on freestore from dictionary.
Definition: cellZoneNew.C:28
void operator=(const cellZone &zn)
Assign addressing, clearing demand-driven data.
Definition: cellZone.C:221
virtual bool checkParallelSync(const bool report=false) const
Check whether zone is synchronised across coupled boundaries.
Definition: cellZone.H:283
virtual bool checkDefinition(const bool report=false) const
Check zone definition. Return true if in error.
Definition: cellZone.C:162
virtual ~cellZone()=default
Destructor.
const cellZoneMesh & zoneMesh() const noexcept
Return reference to the zone mesh.
Definition: cellZone.H:257
Base class for mesh zones.
Definition: zone.H:59
A class for handling words, derived from Foam::string.
Definition: word.H:63
friend Ostream & operator<<(Ostream &os, const cellZone &zn)
Ostream Operator.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
label index() const noexcept
The index of this zone in the zone list.
declareRunTimeSelectionTable(autoPtr, cellZone, dictionary,(const word &name, const dictionary &dict, const label index, const cellZoneMesh &zm),(name, dict, index, zm))
OBJstream os(runTime.globalPath()/outputName)
cellZone(const cellZone &)=delete
No copy construct.
A subset of mesh cells.
Definition: cellZone.H:58
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
const word & name() const noexcept
The zone name.
autoPtr< List< label > > clone() const
Clone.
Definition: ListI.H:121
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
static const char *const labelsName
The name associated with the zone-labels dictionary entry ("cellLabels")
Definition: cellZone.H:78
virtual void writeDict(Ostream &os) const
Write dictionary.
Definition: cellZone.C:168
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
Definition: autoPtr.H:178
const labelList & addressing() const noexcept
The addressing (cell IDs) used for the zone.
Definition: cellZone.H:262
Namespace for OpenFOAM.