FreeFOAM The Cross-Platform CFD Toolkit
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 | Copyright (C) 1991-2010 OpenCFD Ltd.
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::cellZone
26 
27 Description
28  A subset of mesh cells.
29 
30  Currently set up as an indirect list but will be extended to use a
31  primitive mesh. For quick check whether a cell belongs to the zone use
32  the lookup mechanism in cellZoneMesh, where all the zoned cells are
33  registered with their zone number.
34 
35 SourceFiles
36  cellZone.C
37  newCellZone.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef cellZone_H
42 #define cellZone_H
43 
44 #include <OpenFOAM/labelList.H>
45 #include <OpenFOAM/typeInfo.H>
46 #include <OpenFOAM/dictionary.H>
48 #include <OpenFOAM/pointFieldFwd.H>
49 #include <OpenFOAM/Map.H>
50 
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 
53 namespace Foam
54 {
55 
56 // Forward declaration of friend functions and operators
57 
58 class cellZone;
59 Ostream& operator<<(Ostream&, const cellZone&);
60 
61 
62 /*---------------------------------------------------------------------------*\
63  Class cellZone Declaration
64 \*---------------------------------------------------------------------------*/
65 
66 class cellZone
67 :
68  public labelList
69 {
70  // Private data
71 
72  //- Name of zone
73  word name_;
74 
75  //- Index of zone
76  label index_;
77 
78  //- Reference to zone list
79  const cellZoneMesh& zoneMesh_;
80 
81  // Demand-driven private data
82 
83  //- Map of cell labels in zone for fast location lookup
84  mutable Map<label>* cellLookupMapPtr_;
85 
86 
87  // Private Member Functions
88 
89  //- Disallow default bitwise copy construct
90  cellZone(const cellZone&);
91 
92  //- Return map of local cell indices
93  const Map<label>& cellLookupMap() const;
94 
95  //- Build map of local cell indices
96  void calcCellLookupMap() const;
97 
98 
99 public:
100 
101  //- Runtime type information
102  TypeName("cellZone");
103 
104 
105  // Declare run-time constructor selection tables
106 
108  (
109  autoPtr,
110  cellZone,
111  dictionary,
112  (
113  const word& name,
114  const dictionary& dict,
115  const label index,
116  const cellZoneMesh& zm
117  ),
118  (name, dict, index, zm)
119  );
120 
121 
122  // Constructors
123 
124  //- Construct from components
125  cellZone
126  (
127  const word& name,
128  const labelList& addr,
129  const label index,
130  const cellZoneMesh&
131  );
132 
133  //- Construct from components, transferring contents
134  cellZone
135  (
136  const word& name,
137  const Xfer<labelList>& addr,
138  const label index,
139  const cellZoneMesh&
140  );
141 
142  //- Construct from dictionary
143  cellZone
144  (
145  const word& name,
146  const dictionary&,
147  const label index,
148  const cellZoneMesh&
149  );
150 
151  //- Construct given the original zone and resetting the
152  // cell list and zone mesh information
153  cellZone
154  (
155  const cellZone&,
156  const labelList& addr,
157  const label index,
158  const cellZoneMesh&
159  );
160 
161  //- Construct given the original zone, resetting the
162  // cell list and zone mesh information
163  cellZone
164  (
165  const cellZone&,
166  const Xfer<labelList>& addr,
167  const label index,
168  const cellZoneMesh&
169  );
170 
171  //- Construct and return a clone, resetting the zone mesh
172  virtual autoPtr<cellZone> clone(const cellZoneMesh& zm) const
173  {
174  return autoPtr<cellZone>
175  (
176  new cellZone(*this, *this, index(), zm)
177  );
178  }
179 
180  //- Construct and return a clone, resetting the cell list
181  // and zone mesh
182  virtual autoPtr<cellZone> clone
183  (
184  const labelList& addr,
185  const label index,
186  const cellZoneMesh& zm
187  ) const
188  {
189  return autoPtr<cellZone>
190  (
191  new cellZone(*this, addr, index, zm)
192  );
193  }
194 
195 
196  // Selectors
197 
198  //- Return a pointer to a new cell zone
199  // created on freestore from dictionary
200  static autoPtr<cellZone> New
201  (
202  const word& name,
203  const dictionary&,
204  const label index,
205  const cellZoneMesh&
206  );
207 
208 
209  //- Destructor
210 
211  virtual ~cellZone();
212 
213 
214  // Member Functions
215 
216  //- Return name
217  const word& name() const
218  {
219  return name_;
220  }
221 
222  //- Map storing the local cell index for every global cell
223  // index. Used to find out the index of cell in the zone from
224  // the known global cell index. If the cell is not in the
225  // zone, returns -1
226  label whichCell(const label globalCellID) const;
227 
228  //- Return the index of this zone in zone list
229  label index() const
230  {
231  return index_;
232  }
233 
234  //- Return zoneMesh reference
235  const cellZoneMesh& zoneMesh() const;
236 
237  //- Clear addressing
238  void clearAddressing();
239 
240  //- Check zone definition. Return true if in error.
241  bool checkDefinition(const bool report = false) const;
242 
243  //- Correct patch after moving points
244  virtual void movePoints(const pointField&)
245  {}
246 
247  //- Write
248  virtual void write(Ostream&) const;
249 
250  //- Write dictionary
251  virtual void writeDict(Ostream&) const;
252 
253 
254  // Member Operators
255 
256  //- Assign to zone clearing demand-driven data
257  void operator=(const cellZone&);
258 
259  //- Assign addressing clearing demand-driven data
260  void operator=(const labelList&);
261 
262 
263  // Ostream Operator
264 
265  friend Ostream& operator<<(Ostream&, const cellZone&);
266 };
267 
268 
269 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
270 
271 } // End namespace Foam
272 
273 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
274 
275 #endif
276 
277 // ************************ vim: set sw=4 sts=4 et: ************************ //