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  //- Check consistency of structure, i.e. indices into splitCells_.
179  void checkIndices() const;
180 
181  //- Allocate a splitCell. Return index in splitCells_.
182  label allocateSplitCell(const label parent, const label i);
183 
184  //- Free a splitCell.
185  void freeSplitCell(const label index);
186 
187  //- Mark entry in splitCells. Recursively mark its parent and subs.
188  void markSplit
189  (
190  const label,
191  labelList& oldToNew,
193  ) const;
194 
195  void countProc
196  (
197  const label index,
198  const label newProcNo,
199  labelList& splitCellProc,
200  labelList& splitCellNum
201  ) const;
202 
203  // For distribution:
204 
205  //- Mark index and all its descendants
206  void mark(const label, const label, labelList&) const;
207 
208  //- Mark cells according to top parent. Return number of clusters
209  // (set of cells originating from same parent)
210  label markCommonCells(labelList& cellToCluster) const;
211 
212 public:
213 
214  // Declare name of the class and its debug switch
215  TypeName("refinementHistory");
216 
217 
218  // Constructors
219 
220  //- Construct (read) given an IOobject.
221  // If global number of visible cells > 0 becomes active
222  explicit refinementHistory(const IOobject&);
223 
224  //- Construct (read) or construct from components
226  (
227  const IOobject&,
229  const labelList& visibleCells,
230  const bool active
231  );
232 
233  //- Construct (read) or construct from initial number of cells
234  //- (all visible).
235  // If global number of visible cells > 0 becomes active
236  refinementHistory(const IOobject&, const label nCells);
237 
238  //- Construct (read) or construct from initial number of cells
239  //- (all visible) and active flag
241  (
242  const IOobject&,
243  const label nCells,
244  const bool active
245  );
246 
247  //- Construct as copy
249 
250  //- Construct from multiple refinement histories.
251  // If global number of visible cells > 0 becomes active
253  (
254  const IOobject&,
255  const UPtrList<const labelList>& cellMaps,
257  );
258 
259  //- Construct from Istream.
260  // If global number of visible cells > 0 becomes active
261  explicit refinementHistory(const IOobject&, Istream&);
262 
263 
264  // Member Functions
265 
266 
267  //- Per cell in the current mesh (i.e. visible) either -1 (unrefined)
268  //- or an index into splitCells.
269  const labelList& visibleCells() const
270  {
271  return visibleCells_;
272  }
273 
274  //- Storage for splitCell8s
275  const DynamicList<splitCell8>& splitCells() const
276  {
277  return splitCells_;
278  }
279 
280  //- Cache of unused indices in splitCells
281  const DynamicList<label>& freeSplitCells() const
282  {
283  return freeSplitCells_;
284  }
285 
286  //- Is there unrefinement history?
287  bool active() const
288  {
289  return active_;
290  }
291 
292  //- Is there unrefinement history?
293  bool& active()
294  {
295  return active_;
296  }
297 
298  //- Get parent of cell
299  label parentIndex(const label celli) const
300  {
301  label index = visibleCells_[celli];
302 
303  if (index < 0)
304  {
306  << "Cell " << celli << " is not visible"
307  << abort(FatalError);
308  }
309  return splitCells_[index].parent_;
310  }
311 
312  //- Store splitting of cell into 8
313  void storeSplit
314  (
315  const label celli,
316  const labelList& addedCells
317  );
318 
319  //- Store combining 8 cells into master
320  void combineCells
321  (
322  const label masterCelli,
323  const labelList& combinedCells
324  );
325 
326  //- Low level clone
328  (
329  const IOobject& io,
330  const labelList& decomposition,
331  const labelList& splitCellProc,
332  const labelList& splitCellNum,
333  const label procI,
334  labelList& oldToNewSplit
335  ) const;
336 
337  //- Create clone from subset
339  (
340  const IOobject& io,
341  const labelList& cellMap
342  ) const;
343 
344  //- Update numbering for mesh changes
345  void updateMesh(const mapPolyMesh&);
346 
347  //- Update numbering for subsetting
348  void subset
349  (
350  const labelList& pointMap,
351  const labelList& faceMap,
352  const labelList& cellMap
353  );
354 
355  //- Update local numbering for mesh redistribution.
356  // Can only distribute clusters sent across in one go; cannot
357  // handle parts recombined in multiple passes.
358  void distribute(const mapDistributePolyMesh&);
359 
360  //- Compact splitCells_. Removes all freeSplitCells_ elements.
361  void compact();
362 
363  //- Extend/shrink storage. additional visibleCells_ elements get
364  // set to -1.
365  void resize(const label nCells);
366 
367  //- Debug write
368  void writeDebug() const;
369 
370 
371  //- Read object. If global number of visible cells > 0 becomes active
372  virtual bool read();
373 
374  //- ReadData function required for regIOobject read operation. Note:
375  // does not do a reduction - does not set active_ flag
376  virtual bool readData(Istream&);
377 
378  //- WriteData function required for regIOobject write operation
379  virtual bool writeData(Ostream&) const;
380 
381  // Helpers for decompositionConstraint
382 
383  //- Add my decomposition constraints
384  void add
385  (
386  boolList& blockedFace,
387  PtrList<labelList>& specifiedProcessorFaces,
388  labelList& specifiedProcessor,
389  List<labelPair>& explicitConnections
390  ) const;
391 
392  //- Apply any additional post-decomposition constraints
393  void apply
394  (
395  const boolList& blockedFace,
396  const PtrList<labelList>& specifiedProcessorFaces,
397  const labelList& specifiedProcessor,
398  const List<labelPair>& explicitConnections,
399  labelList& decomposition
400  ) const;
401 
402 
403  //- Helper: remove all sets files from mesh instance
404  static void removeFiles(const polyMesh&);
405 
406 
407  // IOstream Operators
408 
409  //- Istream operator. Note: does not do a reduction - does not set
410  // active_ flag
412 
413  friend Ostream& operator<<(Ostream&, const refinementHistory&);
414 };
415 
416 
417 Istream& operator>>(Istream&, refinementHistory::splitCell8&);
418 Ostream& operator<<(Ostream&, const refinementHistory::splitCell8&);
419 
420 
421 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
422 
423 } // End namespace Foam
424 
425 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
426 
427 #endif
428 
429 // ************************************************************************* //
regIOobject.H
Foam::refinementHistory::visibleCells
const labelList & visibleCells() const
Definition: refinementHistory.H:268
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::refinementHistory::refinementHistory
refinementHistory(const IOobject &)
Construct (read) given an IOobject.
Definition: refinementHistory.C:549
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeTopological.C:94
boolList.H
Foam::refinementHistory::apply
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.
Definition: refinementHistory.C:489
Foam::refinementHistory::read
virtual bool read()
Read object. If global number of visible cells > 0 becomes active.
Definition: refinementHistory.C:1701
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:55
Foam::refinementHistory::storeSplit
void storeSplit(const label celli, const labelList &addedCells)
Store splitting of cell into 8.
Definition: refinementHistory.C:1640
Foam::refinementHistory::compact
void compact()
Compact splitCells_. Removes all freeSplitCells_ elements.
Definition: refinementHistory.C:1477
Foam::refinementHistory::active
bool active() const
Is there unrefinement history?
Definition: refinementHistory.H:286
Foam::refinementHistory::operator<<
friend Ostream & operator<<(Ostream &, const refinementHistory &)
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::refinementHistory::writeData
virtual bool writeData(Ostream &) const
WriteData function required for regIOobject write operation.
Definition: refinementHistory.C:1719
Foam::refinementHistory::splitCell8
Definition: refinementHistory.H:108
Foam::refinementHistory::splitCell8::parent_
label parent_
Definition: refinementHistory.H:115
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::refinementHistory::freeSplitCells
const DynamicList< label > & freeSplitCells() const
Cache of unused indices in splitCells.
Definition: refinementHistory.H:280
Foam::refinementHistory::splitCell8::operator!=
bool operator!=(const splitCell8 &rhs) const
Definition: refinementHistory.C:181
Foam::refinementHistory
All refinement history. Used in unrefinement.
Definition: refinementHistory.H:102
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::refinementHistory::splitCell8::splitCell8
splitCell8()
Default construct (parent = -1)
Definition: refinementHistory.C:112
Foam::refinementHistory::writeDebug
void writeDebug() const
Debug write.
Definition: refinementHistory.C:1633
Foam::refinementHistory::splitCell8::addedCellsPtr_
autoPtr< FixedList< label, 8 > > addedCellsPtr_
Cells this cell was refined into.
Definition: refinementHistory.H:118
labelList.H
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::refinementHistory::TypeName
TypeName("refinementHistory")
Foam::UPtrList
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: UPtrList.H:62
Foam::IOobject::clone
autoPtr< IOobject > clone() const
Clone.
Definition: IOobject.H:468
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:59
Foam::refinementHistory::splitCell8::operator>>
friend Istream & operator>>(Istream &, splitCell8 &)
Foam::FatalError
error FatalError
Foam::refinementHistory::resize
void resize(const label nCells)
Extend/shrink storage. additional visibleCells_ elements get.
Definition: refinementHistory.C:1080
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::refinementHistory::removeFiles
static void removeFiles(const polyMesh &)
Helper: remove all sets files from mesh instance.
Definition: refinementHistory.C:1727
Foam::refinementHistory::splitCell8::operator=
void operator=(const splitCell8 &rhs)
Copy assignment (no autoPtr stealing)
Definition: refinementHistory.C:143
Foam::refinementHistory::operator>>
friend Istream & operator>>(Istream &, refinementHistory &)
Istream operator. Note: does not do a reduction - does not set.
Foam::refinementHistory::readData
virtual bool readData(Istream &)
ReadData function required for regIOobject read operation. Note:
Definition: refinementHistory.C:1712
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::refinementHistory::combineCells
void combineCells(const label masterCelli, const labelList &combinedCells)
Store combining 8 cells into master.
Definition: refinementHistory.C:1678
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:73
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::refinementHistory::add
void add(boolList &blockedFace, PtrList< labelList > &specifiedProcessorFaces, labelList &specifiedProcessor, List< labelPair > &explicitConnections) const
Add my decomposition constraints.
Definition: refinementHistory.C:443
Foam::refinementHistory::splitCell8::operator==
bool operator==(const splitCell8 &rhs) const
Definition: refinementHistory.C:158
Foam::List< label >
Foam::refinementHistory::subset
void subset(const labelList &pointMap, const labelList &faceMap, const labelList &cellMap)
Update numbering for subsetting.
Definition: refinementHistory.C:1146
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:161
Foam::refinementHistory::splitCells
const DynamicList< splitCell8 > & splitCells() const
Storage for splitCell8s.
Definition: refinementHistory.H:274
Foam::refinementHistory::distribute
void distribute(const mapDistributePolyMesh &)
Update local numbering for mesh redistribution.
Definition: refinementHistory.C:1227
Foam::refinementHistory::updateMesh
void updateMesh(const mapPolyMesh &)
Update numbering for mesh changes.
Definition: refinementHistory.C:1100
DynamicList.H
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::mapDistributePolyMesh
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Definition: mapDistributePolyMesh.H:66
FixedList.H
Foam::refinementHistory::active
bool & active()
Is there unrefinement history?
Definition: refinementHistory.H:292
Foam::refinementHistory::parentIndex
label parentIndex(const label celli) const
Get parent of cell.
Definition: refinementHistory.H:298
Foam::refinementHistory::splitCell8::operator<<
friend Ostream & operator<<(Ostream &, const splitCell8 &)
labelPair.H
autoPtr.H