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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2015-2020 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::refinementHistory
29 
30 Description
31  All refinement history. Used in unrefinement.
32 
33  - visibleCells: valid for the current mesh and contains per cell -1
34  (cell unrefined) or an index into splitCells_.
35  - splitCells: for every split contains the parent (also index into
36  splitCells) and optionally a subsplit as 8 indices into splitCells.
37  Note that the numbers in splitCells are not cell labels, they are purely
38  indices into splitCells.
39 
40  E.g. 2 cells, cell 1 gets refined so end up with 9 cells:
41  \verbatim
42  // splitCells
43  9
44  (
45  -1 (1 2 3 4 5 6 7 8)
46  0 0()
47  0 0()
48  0 0()
49  0 0()
50  0 0()
51  0 0()
52  0 0()
53  0 0()
54  )
55 
56  // visibleCells
57  9(-1 1 2 3 4 5 6 7 8)
58  \endverbatim
59 
60 
61  So cell0 (visibleCells=-1) is unrefined.
62  Cells 1-8 have all valid splitCells entries which are:
63  - parent:0
64  - subsplits:0()
65 
66  The parent 0 refers back to the splitcell entries.
67 
68 SourceFiles
69  refinementHistory.C
70 
71 \*---------------------------------------------------------------------------*/
72 
73 #ifndef refinementHistory_H
74 #define refinementHistory_H
75 
76 #include "DynamicList.H"
77 #include "labelList.H"
78 #include "FixedList.H"
79 #include "autoPtr.H"
80 #include "regIOobject.H"
81 #include "boolList.H"
82 #include "labelPair.H"
83 
84 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
85 
86 namespace Foam
87 {
88 
89 // Forward Declarations
90 class mapPolyMesh;
91 class mapDistributePolyMesh;
92 class polyMesh;
93 class refinementHistory;
94 
95 Istream& operator>>(Istream&, refinementHistory&);
96 Ostream& operator<<(Ostream&, const refinementHistory&);
97 
98 
99 /*---------------------------------------------------------------------------*\
100  Class refinementHistory Declaration
101 \*---------------------------------------------------------------------------*/
102 
103 class refinementHistory
104 :
105  public regIOobject
106 {
107 public:
108 
109  class splitCell8
110  {
111  public:
112 
113  // Index to original splitCell this cell was refined off from
114  // -1: top level cell
115  // -2: free splitCell (so should also be in freeSplitCells_)
116  label parent_;
117 
118  //- Cells this cell was refined into
120 
121  //- Default construct (parent = -1)
122  splitCell8();
123 
124  //- Construct from parent
125  splitCell8(const label parent);
126 
127  //- Construct from Istream
128  splitCell8(Istream& is);
129 
130  //- Construct as deep copy
131  splitCell8(const splitCell8& rhs);
132 
133  //- Copy assignment (no autoPtr stealing)
134  void operator=(const splitCell8& rhs);
135 
136  bool operator==(const splitCell8& rhs) const;
137 
138  bool operator!=(const splitCell8& rhs) const;
139 
140  friend Istream& operator>>(Istream&, splitCell8&);
141  friend Ostream& operator<<(Ostream&, const splitCell8&);
142  };
143 
144 
145 private:
146 
147  // Private Data
148 
149  //- Is active?
150  bool active_;
151 
152  //- Storage for splitCells
153  DynamicList<splitCell8> splitCells_;
154 
155  //- Unused indices in splitCells
156  DynamicList<label> freeSplitCells_;
157 
158  //- Currently visible cells. Indices into splitCells.
159  labelList visibleCells_;
160 
161 
162  // Private Member Functions
163 
164  //- Debug write
165  static void writeEntry
166  (
167  const List<splitCell8>&,
168  const splitCell8&
169  );
170 
171  //- Debug write
172  static void writeDebug
173  (
174  const labelList&,
175  const List<splitCell8>&
176  );
177 
178  //- Read if IOobject flags set. Return true if read.
179  bool readContents();
180 
181  //- Check consistency of structure, i.e. indices into splitCells_.
182  void checkIndices() const;
183 
184  //- Allocate a splitCell. Return index in splitCells_.
185  label allocateSplitCell(const label parent, const label i);
186 
187  //- Free a splitCell.
188  void freeSplitCell(const label index);
189 
190  //- Mark entry in splitCells. Recursively mark its parent and subs.
191  void markSplit
192  (
193  const label,
194  labelList& oldToNew,
196  ) const;
197 
198  void countProc
199  (
200  const label index,
201  const label newProcNo,
202  labelList& splitCellProc,
203  labelList& splitCellNum
204  ) const;
205 
206  // For distribution:
207 
208  //- Mark index and all its descendants
209  void mark(const label, const label, labelList&) const;
210 
211  //- Mark cells according to top parent. Return number of clusters
212  // (set of cells originating from same parent)
213  label markCommonCells(labelList& cellToCluster) const;
214 
215 public:
216 
217  // Declare name of the class and its debug switch
218  TypeName("refinementHistory");
219 
220 
221  // Constructors
222 
223  //- Construct (read) given an IOobject.
224  // If global number of visible cells > 0 becomes active
225  explicit refinementHistory(const IOobject&);
226 
227  //- Construct (read) or construct from components
229  (
230  const IOobject&,
232  const labelList& visibleCells,
233  const bool active
234  );
235 
236  //- Construct (read) or construct from initial number of cells
237  //- (all visible).
238  // If global number of visible cells > 0 becomes active
239  refinementHistory(const IOobject&, const label nCells);
240 
241  //- Construct (read) or construct from initial number of cells
242  //- (all visible) and active flag
244  (
245  const IOobject&,
246  const label nCells,
247  const bool active
248  );
249 
250  //- Construct as copy
252 
253  //- Construct from multiple refinement histories.
254  // If global number of visible cells > 0 becomes active
256  (
257  const IOobject&,
258  const UPtrList<const labelList>& cellMaps,
260  );
261 
262  //- Construct from Istream.
263  // If global number of visible cells > 0 becomes active
264  explicit refinementHistory(const IOobject&, Istream&);
265 
266 
267  // Member Functions
268 
269 
270  //- Per cell in the current mesh (i.e. visible) either -1 (unrefined)
271  //- or an index into splitCells.
272  const labelList& visibleCells() const
273  {
274  return visibleCells_;
275  }
276 
277  //- Storage for splitCell8s
278  const DynamicList<splitCell8>& splitCells() const
279  {
280  return splitCells_;
281  }
282 
283  //- Cache of unused indices in splitCells
284  const DynamicList<label>& freeSplitCells() const
285  {
286  return freeSplitCells_;
287  }
288 
289  //- Is there unrefinement history?
290  bool active() const
291  {
292  return active_;
293  }
294 
295  //- Is there unrefinement history?
296  bool& active()
297  {
298  return active_;
299  }
300 
301  //- Get parent of cell
302  label parentIndex(const label celli) const
303  {
304  label index = visibleCells_[celli];
305 
306  if (index < 0)
307  {
309  << "Cell " << celli << " is not visible"
310  << abort(FatalError);
311  }
312  return splitCells_[index].parent_;
313  }
314 
315  //- Store splitting of cell into 8
316  void storeSplit
317  (
318  const label celli,
319  const labelList& addedCells
320  );
321 
322  //- Store combining 8 cells into master
323  void combineCells
324  (
325  const label masterCelli,
326  const labelList& combinedCells
327  );
328 
329  //- Low level clone
331  (
332  const IOobject& io,
333  const labelList& decomposition,
334  const labelList& splitCellProc,
335  const labelList& splitCellNum,
336  const label procI,
337  labelList& oldToNewSplit
338  ) const;
339 
340  //- Create clone from subset
342  (
343  const IOobject& io,
344  const labelList& cellMap
345  ) const;
346 
347  //- Update numbering for mesh changes
348  void updateMesh(const mapPolyMesh&);
349 
350  //- Update numbering for subsetting
351  void subset
352  (
353  const labelList& pointMap,
354  const labelList& faceMap,
355  const labelList& cellMap
356  );
357 
358  //- Update local numbering for mesh redistribution.
359  // Can only distribute clusters sent across in one go; cannot
360  // handle parts recombined in multiple passes.
361  void distribute(const mapDistributePolyMesh&);
362 
363  //- Compact splitCells_. Removes all freeSplitCells_ elements.
364  void compact();
365 
366  //- Extend/shrink storage. additional visibleCells_ elements get
367  // set to -1.
368  void resize(const label nCells);
369 
370  //- Debug write
371  void writeDebug() const;
372 
373 
374  //- Read object. If global number of visible cells > 0 becomes active
375  virtual bool read();
376 
377  //- ReadData function required for regIOobject read operation. Note:
378  // does not do a reduction - does not set active_ flag
379  virtual bool readData(Istream&);
380 
381  //- WriteData function required for regIOobject write operation
382  virtual bool writeData(Ostream&) const;
383 
384  // Helpers for decompositionConstraint
385 
386  //- Add my decomposition constraints
387  void add
388  (
389  boolList& blockedFace,
390  PtrList<labelList>& specifiedProcessorFaces,
391  labelList& specifiedProcessor,
392  List<labelPair>& explicitConnections
393  ) const;
394 
395  //- Apply any additional post-decomposition constraints
396  void apply
397  (
398  const boolList& blockedFace,
399  const PtrList<labelList>& specifiedProcessorFaces,
400  const labelList& specifiedProcessor,
401  const List<labelPair>& explicitConnections,
402  labelList& decomposition
403  ) const;
404 
405 
406  //- Helper: remove all sets files from mesh instance
407  static void removeFiles(const polyMesh&);
408 
409 
410  // IOstream Operators
411 
412  //- Istream operator. Note: does not do a reduction - does not set
413  // active_ flag
415 
416  friend Ostream& operator<<(Ostream&, const refinementHistory&);
417 };
418 
419 
422 
423 
424 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
425 
426 } // End namespace Foam
427 
428 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
429 
430 #endif
431 
432 // ************************************************************************* //
void operator=(const splitCell8 &rhs)
Copy assignment (no autoPtr stealing)
autoPtr< IOobject > clone() const
Clone.
Definition: IOobject.H:621
bool operator==(const splitCell8 &rhs) const
const DynamicList< splitCell8 > & splitCells() const
Storage for splitCell8s.
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
bool active() const
Is there unrefinement history?
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
splitCell8()
Default construct (parent = -1)
autoPtr< FixedList< label, 8 > > addedCellsPtr_
Cells this cell was refined into.
refinementHistory(const IOobject &)
Construct (read) given an IOobject.
virtual bool writeData(Ostream &) const
WriteData function required for regIOobject write operation.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:157
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
void combineCells(const label masterCelli, const labelList &combinedCells)
Store combining 8 cells into master.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:51
bool operator!=(const splitCell8 &rhs) const
Istream & operator>>(Istream &, directionInfo &)
void subset(const labelList &pointMap, const labelList &faceMap, const labelList &cellMap)
Update numbering for subsetting.
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: HashTable.H:106
errorManip< error > abort(error &err)
Definition: errorManip.H:139
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
virtual bool read()
Read object. If global number of visible cells > 0 becomes active.
virtual bool readData(Istream &)
ReadData function required for regIOobject read operation. Note:
const DynamicList< label > & freeSplitCells() const
Cache of unused indices in splitCells.
void compact()
Compact splitCells_. Removes all freeSplitCells_ elements.
void storeSplit(const label celli, const labelList &addedCells)
Store splitting of cell into 8.
friend Ostream & operator<<(Ostream &, const splitCell8 &)
void updateMesh(const mapPolyMesh &)
Update numbering for mesh changes.
void distribute(const mapDistributePolyMesh &)
Update local numbering for mesh redistribution.
const labelList & visibleCells() const
Per cell in the current mesh (i.e. visible) either -1 (unrefined) or an index into splitCells...
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
static void removeFiles(const polyMesh &)
Helper: remove all sets files from mesh instance.
void apply(const boolList &blockedFace, const PtrList< labelList > &specifiedProcessorFaces, const labelList &specifiedProcessor, const List< labelPair > &explicitConnections, labelList &decomposition) const
Apply any additional post-decomposition constraints.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
label parentIndex(const label celli) const
Get parent of cell.
TypeName("refinementHistory")
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:66
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
List< label > labelList
A List of labels.
Definition: List.H:62
All refinement history. Used in unrefinement.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
void add(boolList &blockedFace, PtrList< labelList > &specifiedProcessorFaces, labelList &specifiedProcessor, List< labelPair > &explicitConnections) const
Add my decomposition constraints.
void writeDebug() const
Debug write.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
void resize(const label nCells)
Extend/shrink storage. additional visibleCells_ elements get.
friend Istream & operator>>(Istream &, splitCell8 &)
friend Ostream & operator<<(Ostream &, const refinementHistory &)
Namespace for OpenFOAM.
friend Istream & operator>>(Istream &, refinementHistory &)
Istream operator. Note: does not do a reduction - does not set.