refinementHistory.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) 2011-2012 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::refinementHistory
26 
27 Description
28  All refinement history. Used in unrefinement.
29 
30  - visibleCells: valid for the current mesh and contains per cell -1
31  (cell unrefined) or an index into splitCells_.
32  - splitCells: for every split contains the parent (also index into
33  splitCells) and optionally a subsplit as 8 indices into splitCells.
34  Note that the numbers in splitCells are not cell labels, they are purely
35  indices into splitCells.
36 
37  E.g. 2 cells, cell 1 gets refined so end up with 9 cells:
38  \verbatim
39  // splitCells
40  9
41  (
42  -1 (1 2 3 4 5 6 7 8)
43  0 0()
44  0 0()
45  0 0()
46  0 0()
47  0 0()
48  0 0()
49  0 0()
50  0 0()
51  )
52 
53  // visibleCells
54  9(-1 1 2 3 4 5 6 7 8)
55  \endverbatim
56 
57 
58  So cell0 (visibleCells=-1) is unrefined.
59  Cells 1-8 have all valid splitCells entries which are:
60  - parent:0
61  - subsplits:0()
62 
63  The parent 0 refers back to the splitcell entries.
64 
65 
66 SourceFiles
67  refinementHistory.C
68 
69 \*---------------------------------------------------------------------------*/
70 
71 #ifndef refinementHistory_H
72 #define refinementHistory_H
73 
74 #include "DynamicList.H"
75 #include "labelList.H"
76 #include "FixedList.H"
77 #include "SLList.H"
78 #include "autoPtr.H"
79 #include "regIOobject.H"
80 
81 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
82 
83 namespace Foam
84 {
85 
86 // Forward declaration of classes
87 class mapPolyMesh;
88 class mapDistributePolyMesh;
89 
90 /*---------------------------------------------------------------------------*\
91  Class refinementHistory Declaration
92 \*---------------------------------------------------------------------------*/
93 
95 :
96  public regIOobject
97 {
98 public:
99 
101  {
102  public:
103 
104  // Index to original splitCell this cell was refined off from
105  // -1: top level cell
106  // -2: free splitCell (so should also be in freeSplitCells_)
107  label parent_;
108 
109  //- cells this cell was refined into
111 
112  //- Construct null (parent = -1)
113  splitCell8();
114 
115  //- Construct from parent
116  splitCell8(const label parent);
117 
118  //- Construct from Istream
119  splitCell8(Istream& is);
120 
121  //- Construct as deep copy
122  splitCell8(const splitCell8&);
123 
124  //- Copy operator since autoPtr otherwise 'steals' storage.
125  void operator=(const splitCell8& s)
126  {
127  // Check for assignment to self
128  if (this == &s)
129  {
130  FatalErrorIn("splitCell8::operator=(const Foam::splitCell8&)")
131  << "Attempted assignment to self"
132  << abort(FatalError);
133  }
134 
135  parent_ = s.parent_;
136 
137  addedCellsPtr_.reset
138  (
139  s.addedCellsPtr_.valid()
141  : NULL
142  );
143  }
144 
145  bool operator==(const splitCell8& s) const
146  {
147  if (addedCellsPtr_.valid() != s.addedCellsPtr_.valid())
148  {
149  return false;
150  }
151  else if (parent_ != s.parent_)
152  {
153  return false;
154  }
155  else if (addedCellsPtr_.valid())
156  {
157  return addedCellsPtr_() == s.addedCellsPtr_();
158  }
159  else
160  {
161  return true;
162  }
163  }
164 
165  bool operator!=(const splitCell8& s) const
166  {
167  return !operator==(s);
168  }
169 
170  friend Istream& operator>>(Istream&, splitCell8&);
171  friend Ostream& operator<<(Ostream&, const splitCell8&);
172  };
173 
174 
175 private:
176 
177  // Private data
178 
179  //- Storage for splitCells
180  DynamicList<splitCell8> splitCells_;
181 
182  //- Unused indices in splitCells
183  DynamicList<label> freeSplitCells_;
184 
185  //- Currently visible cells. Indices into splitCells.
186  labelList visibleCells_;
187 
188 
189  // Private Member Functions
190 
191  //- Debug write
192  static void writeEntry
193  (
194  const List<splitCell8>&,
195  const splitCell8&
196  );
197  //- Debug write
198  static void writeDebug
199  (
200  const labelList&,
201  const List<splitCell8>&
202  );
203 
204  //- Check consistency of structure, i.e. indices into splitCells_.
205  void checkIndices() const;
206 
207  //- Allocate a splitCell. Return index in splitCells_.
208  label allocateSplitCell(const label parent, const label i);
209 
210  //- Free a splitCell.
211  void freeSplitCell(const label index);
212 
213  //- Mark entry in splitCells. Recursively mark its parent and subs.
214  void markSplit
215  (
216  const label,
217  labelList& oldToNew,
219  ) const;
220 
221  void countProc
222  (
223  const label index,
224  const label newProcNo,
225  labelList& splitCellProc,
226  labelList& splitCellNum
227  ) const;
228 
229 public:
230 
231  // Declare name of the class and its debug switch
232  TypeName("refinementHistory");
233 
234 
235  // Constructors
236 
237  //- Construct (read) given an IOobject
238  refinementHistory(const IOobject&);
239 
240  //- Construct (read) or construct null
242  (
243  const IOobject&,
244  const List<splitCell8>& splitCells,
245  const labelList& visibleCells
246  );
247 
248  //- Construct (read) or construct from initial number of cells
249  // (all visible)
250  refinementHistory(const IOobject&, const label nCells);
251 
252  //- Construct as copy
254 
255  //- Construct from Istream
257 
258 
259  // Member Functions
260 
261 
262  //- Per cell in the current mesh (i.e. visible) either -1 (unrefined)
263  // or an index into splitCells.
264  const labelList& visibleCells() const
265  {
266  return visibleCells_;
267  }
268 
269  //- Storage for splitCell8s.
271  {
272  return splitCells_;
273  }
274 
275  //- Cache of unused indices in splitCells
277  {
278  return freeSplitCells_;
279  }
280 
281  //- Is there unrefinement history. Note that this will fall over if
282  // there are 0 cells in the mesh. But this gives problems with
283  // lots of other programs anyway.
284  bool active() const
285  {
286  return visibleCells_.size() > 0;
287  }
288 
289  //- Get parent of cell
290  label parentIndex(const label cellI) const
291  {
292  label index = visibleCells_[cellI];
293 
294  if (index < 0)
295  {
296  FatalErrorIn("refinementHistory::parentIndex(const label)")
297  << "Cell " << cellI << " is not visible"
298  << abort(FatalError);
299  }
300  return splitCells_[index].parent_;
301  }
302 
303  //- Store splitting of cell into 8
304  void storeSplit
305  (
306  const label cellI,
307  const labelList& addedCells
308  );
309 
310  //- Store combining 8 cells into master
311  void combineCells
312  (
313  const label masterCellI,
314  const labelList& combinedCells
315  );
316 
317 
318  //- Update numbering for mesh changes
319  void updateMesh(const mapPolyMesh&);
320 
321  //- Update numbering for subsetting
322  void subset
323  (
324  const labelList& pointMap,
325  const labelList& faceMap,
326  const labelList& cellMap
327  );
328 
329  //- Update local numbering for mesh redistribution.
330  // Can only distribute clusters sent across in one go; cannot
331  // handle parts recombined in multiple passes.
332  void distribute(const mapDistributePolyMesh&);
333 
334 
335  //- Compact splitCells_. Removes all freeSplitCells_ elements.
336  void compact();
337 
338  //- Extend/shrink storage. additional visibleCells_ elements get
339  // set to -1.
340  void resize(const label nCells);
341 
342  //- Debug write
343  void writeDebug() const;
344 
345 
346  //- ReadData function required for regIOobject read operation
347  virtual bool readData(Istream&);
348 
349  //- WriteData function required for regIOobject write operation
350  virtual bool writeData(Ostream&) const;
351 
352 
353  // Friend Functions
354 
355  // Friend Operators
356 
357  // IOstream Operators
358 
360  friend Ostream& operator<<(Ostream&, const refinementHistory&);
361 };
362 
363 
364 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
365 
366 } // End namespace Foam
367 
368 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
369 
370 #endif
371 
372 // ************************************************************************* //