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-2016 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 
69 SourceFiles
70  refinementHistory.C
71 
72 \*---------------------------------------------------------------------------*/
73 
74 #ifndef refinementHistory_H
75 #define refinementHistory_H
76 
77 #include "DynamicList.H"
78 #include "labelList.H"
79 #include "FixedList.H"
80 #include "autoPtr.H"
81 #include "regIOobject.H"
82 #include "boolList.H"
83 #include "labelPair.H"
84 
85 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
86 
87 namespace Foam
88 {
89 
90 // Forward declaration of classes
91 class mapPolyMesh;
92 class mapDistributePolyMesh;
93 class polyMesh;
94 
95 // Forward declaration of friend functions and operators
96 
97 class refinementHistory;
98 
99 Istream& operator>>(Istream&, refinementHistory&);
100 Ostream& operator<<(Ostream&, const refinementHistory&);
101 
102 
103 /*---------------------------------------------------------------------------*\
104  Class refinementHistory Declaration
105 \*---------------------------------------------------------------------------*/
106 
107 class refinementHistory
108 :
109  public regIOobject
110 {
111 public:
112 
113  class splitCell8
114  {
115  public:
116 
117  // Index to original splitCell this cell was refined off from
118  // -1: top level cell
119  // -2: free splitCell (so should also be in freeSplitCells_)
120  label parent_;
121 
122  //- Cells this cell was refined into
124 
125  //- Construct null (parent = -1)
126  splitCell8();
127 
128  //- Construct from parent
129  splitCell8(const label parent);
130 
131  //- Construct from Istream
132  splitCell8(Istream& is);
133 
134  //- Construct as deep copy
135  splitCell8(const splitCell8&);
136 
137  //- Copy operator since autoPtr otherwise 'steals' storage.
138  void operator=(const splitCell8& s);
139 
140  bool operator==(const splitCell8& s) const;
141 
142  bool operator!=(const splitCell8& s) const;
143 
144  friend Istream& operator>>(Istream&, splitCell8&);
145  friend Ostream& operator<<(Ostream&, const splitCell8&);
146  };
147 
148 
149 private:
150 
151  // Private data
152 
153  //- Is active?
154  bool active_;
155 
156  //- Storage for splitCells
157  DynamicList<splitCell8> splitCells_;
158 
159  //- Unused indices in splitCells
160  DynamicList<label> freeSplitCells_;
161 
162  //- Currently visible cells. Indices into splitCells.
163  labelList visibleCells_;
164 
165 
166  // Private Member Functions
167 
168  //- Debug write
169  static void writeEntry
170  (
171  const List<splitCell8>&,
172  const splitCell8&
173  );
174 
175  //- Debug write
176  static void writeDebug
177  (
178  const labelList&,
179  const List<splitCell8>&
180  );
181 
182  //- Check consistency of structure, i.e. indices into splitCells_.
183  void checkIndices() const;
184 
185  //- Allocate a splitCell. Return index in splitCells_.
186  label allocateSplitCell(const label parent, const label i);
187 
188  //- Free a splitCell.
189  void freeSplitCell(const label index);
190 
191  //- Mark entry in splitCells. Recursively mark its parent and subs.
192  void markSplit
193  (
194  const label,
195  labelList& oldToNew,
197  ) const;
198 
199  void countProc
200  (
201  const label index,
202  const label newProcNo,
203  labelList& splitCellProc,
204  labelList& splitCellNum
205  ) const;
206 
207  // For distribution:
208 
209  //- Mark index and all its descendants
210  void mark(const label, const label, labelList&) const;
211 
212  //- Mark cells according to top parent. Return number of clusters
213  // (set of cells originating from same parent)
214  label markCommonCells(labelList& cellToCluster) const;
215 
216 public:
217 
218  // Declare name of the class and its debug switch
219  TypeName("refinementHistory");
220 
221 
222  // Constructors
223 
224  //- Construct (read) given an IOobject. If global number of visible
225  // cells > 0 becomes active
226  refinementHistory(const IOobject&);
227 
228  //- Construct (read) or construct from components
230  (
231  const IOobject&,
233  const labelList& visibleCells,
234  const bool active
235  );
236 
237  //- Construct (read) or construct from initial number of cells
238  // (all visible). If global number of visible
239  // cells > 0 becomes active
240  refinementHistory(const IOobject&, const label nCells);
241 
242  //- Construct (read) or construct from initial number of cells
243  // (all visible) and active flag
245  (
246  const IOobject&,
247  const label nCells,
248  const bool active
249  );
250 
251  //- Construct as copy
253 
254  //- Construct from multiple refinement histories. If global number of
255  // visible cells > 0 becomes active
257  (
258  const IOobject&,
259  const UPtrList<const labelList>& cellMaps,
261  );
262 
263  //- Construct from Istream. If global number of
264  // visible cells > 0 becomes active
266 
267 
268  // Member Functions
269 
270 
271  //- Per cell in the current mesh (i.e. visible) either -1 (unrefined)
272  // or an index into splitCells.
273  const labelList& visibleCells() const
274  {
275  return visibleCells_;
276  }
277 
278  //- Storage for splitCell8s.
279  const DynamicList<splitCell8>& splitCells() const
280  {
281  return splitCells_;
282  }
283 
284  //- Cache of unused indices in splitCells
285  const DynamicList<label>& freeSplitCells() const
286  {
287  return freeSplitCells_;
288  }
289 
290  //- Is there unrefinement history?
291  bool active() const
292  {
293  return active_;
294  }
295 
296  //- Is there unrefinement history?
297  bool& active()
298  {
299  return active_;
300  }
301 
302  //- Get parent of cell
303  label parentIndex(const label celli) const
304  {
305  label index = visibleCells_[celli];
306 
307  if (index < 0)
308  {
310  << "Cell " << celli << " is not visible"
311  << abort(FatalError);
312  }
313  return splitCells_[index].parent_;
314  }
315 
316  //- Store splitting of cell into 8
317  void storeSplit
318  (
319  const label celli,
320  const labelList& addedCells
321  );
322 
323  //- Store combining 8 cells into master
324  void combineCells
325  (
326  const label masterCelli,
327  const labelList& combinedCells
328  );
329 
330  //- Low level clone
332  (
333  const IOobject& io,
334  const labelList& decomposition,
335  const labelList& splitCellProc,
336  const labelList& splitCellNum,
337  const label procI,
338  labelList& oldToNewSplit
339  ) const;
340 
341  //- Create clone from subset
343  (
344  const IOobject& io,
345  const labelList& cellMap
346  ) const;
347 
348  //- Update numbering for mesh changes
349  void updateMesh(const mapPolyMesh&);
350 
351  //- Update numbering for subsetting
352  void subset
353  (
354  const labelList& pointMap,
355  const labelList& faceMap,
356  const labelList& cellMap
357  );
358 
359  //- Update local numbering for mesh redistribution.
360  // Can only distribute clusters sent across in one go; cannot
361  // handle parts recombined in multiple passes.
362  void distribute(const mapDistributePolyMesh&);
363 
364  //- Compact splitCells_. Removes all freeSplitCells_ elements.
365  void compact();
366 
367  //- Extend/shrink storage. additional visibleCells_ elements get
368  // set to -1.
369  void resize(const label nCells);
370 
371  //- Debug write
372  void writeDebug() const;
373 
374 
375  //- Read object. If global number of visible cells > 0 becomes active
376  virtual bool read();
377 
378  //- ReadData function required for regIOobject read operation. Note:
379  // does not do a reduction - does not set active_ flag
380  virtual bool readData(Istream&);
381 
382  //- WriteData function required for regIOobject write operation
383  virtual bool writeData(Ostream&) const;
384 
385  // Helpers for decompositionConstraint
386 
387  //- Add my decomposition constraints
388  void add
389  (
390  boolList& blockedFace,
391  PtrList<labelList>& specifiedProcessorFaces,
392  labelList& specifiedProcessor,
393  List<labelPair>& explicitConnections
394  ) const;
395 
396  //- Apply any additional post-decomposition constraints
397  void apply
398  (
399  const boolList& blockedFace,
400  const PtrList<labelList>& specifiedProcessorFaces,
401  const labelList& specifiedProcessor,
402  const List<labelPair>& explicitConnections,
403  labelList& decomposition
404  ) const;
405 
406 
407  //- Helper: remove all sets files from mesh instance
408  static void removeFiles(const polyMesh&);
409 
410 
411  // IOstream Operators
412 
413  //- Istream operator. Note: does not do a reduction - does not set
414  // active_ flag
416 
417  friend Ostream& operator<<(Ostream&, const refinementHistory&);
418 };
419 
420 
421 Istream& operator>>(Istream&, refinementHistory::splitCell8&);
422 Ostream& operator<<(Ostream&, const refinementHistory::splitCell8&);
423 
424 
425 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
426 
427 } // End namespace Foam
428 
429 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
430 
431 #endif
432 
433 // ************************************************************************* //
regIOobject.H
Foam::refinementHistory::visibleCells
const labelList & visibleCells() const
Per cell in the current mesh (i.e. visible) either -1 (unrefined)
Definition: refinementHistory.H:272
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::refinementHistory::refinementHistory
refinementHistory(const IOobject &)
Construct (read) given an IOobject. If global number of visible.
Definition: refinementHistory.C:554
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeFast.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:494
s
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputSpray.H:25
Foam::refinementHistory::read
virtual bool read()
Read object. If global number of visible cells > 0 becomes active.
Definition: refinementHistory.C:1706
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:57
Foam::refinementHistory::storeSplit
void storeSplit(const label celli, const labelList &addedCells)
Store splitting of cell into 8.
Definition: refinementHistory.C:1645
Foam::refinementHistory::compact
void compact()
Compact splitCells_. Removes all freeSplitCells_ elements.
Definition: refinementHistory.C:1482
Foam::refinementHistory::active
bool active() const
Is there unrefinement history?
Definition: refinementHistory.H:290
Foam::refinementHistory::operator<<
friend Ostream & operator<<(Ostream &, const refinementHistory &)
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:228
Foam::refinementHistory::writeData
virtual bool writeData(Ostream &) const
WriteData function required for regIOobject write operation.
Definition: refinementHistory.C:1724
Foam::refinementHistory::splitCell8
Definition: refinementHistory.H:112
Foam::refinementHistory::splitCell8::parent_
label parent_
Definition: refinementHistory.H:119
Foam::refinementHistory::splitCell8::operator==
bool operator==(const splitCell8 &s) const
Definition: refinementHistory.C:166
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:284
Foam::refinementHistory
All refinement history. Used in unrefinement.
Definition: refinementHistory.H:106
Foam::refinementHistory::splitCell8::splitCell8
splitCell8()
Construct null (parent = -1)
Definition: refinementHistory.C:112
Foam::refinementHistory::writeDebug
void writeDebug() const
Debug write.
Definition: refinementHistory.C:1638
Foam::refinementHistory::splitCell8::addedCellsPtr_
autoPtr< FixedList< label, 8 > > addedCellsPtr_
Cells this cell was refined into.
Definition: refinementHistory.H:122
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
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:63
Foam::IOobject::clone
autoPtr< IOobject > clone() const
Clone.
Definition: IOobject.H:326
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:65
Foam::refinementHistory::splitCell8::operator!=
bool operator!=(const splitCell8 &s) const
Definition: refinementHistory.C:185
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:1085
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:137
Foam::refinementHistory::removeFiles
static void removeFiles(const polyMesh &)
Helper: remove all sets files from mesh instance.
Definition: refinementHistory.C:1732
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:1717
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:1683
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:67
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::refinementHistory::add
void add(boolList &blockedFace, PtrList< labelList > &specifiedProcessorFaces, labelList &specifiedProcessor, List< labelPair > &explicitConnections) const
Add my decomposition constraints.
Definition: refinementHistory.C:448
Foam::List< label >
Foam::refinementHistory::subset
void subset(const labelList &pointMap, const labelList &faceMap, const labelList &cellMap)
Update numbering for subsetting.
Definition: refinementHistory.C:1151
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:160
Foam::refinementHistory::splitCell8::operator=
void operator=(const splitCell8 &s)
Copy operator since autoPtr otherwise 'steals' storage.
Definition: refinementHistory.C:146
Foam::refinementHistory::splitCells
const DynamicList< splitCell8 > & splitCells() const
Storage for splitCell8s.
Definition: refinementHistory.H:278
Foam::refinementHistory::distribute
void distribute(const mapDistributePolyMesh &)
Update local numbering for mesh redistribution.
Definition: refinementHistory.C:1232
Foam::refinementHistory::updateMesh
void updateMesh(const mapPolyMesh &)
Update numbering for mesh changes.
Definition: refinementHistory.C:1105
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:296
Foam::refinementHistory::parentIndex
label parentIndex(const label celli) const
Get parent of cell.
Definition: refinementHistory.H:302
Foam::refinementHistory::splitCell8::operator<<
friend Ostream & operator<<(Ostream &, const splitCell8 &)
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &)
Definition: boundaryPatch.C:102
labelPair.H
autoPtr.H