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-2015 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
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 "UPtrList.H"
75 #include "DynamicList.H"
76 #include "labelList.H"
77 #include "FixedList.H"
78 #include "autoPtr.H"
79 #include "regIOobject.H"
80 #include "boolList.H"
81 #include "labelPair.H"
82 
83 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
84 
85 namespace Foam
86 {
87 
88 // Forward declaration of classes
89 class mapPolyMesh;
90 class mapDistributePolyMesh;
91 
92 /*---------------------------------------------------------------------------*\
93  Class refinementHistory Declaration
94 \*---------------------------------------------------------------------------*/
95 
96 class refinementHistory
97 :
98  public regIOobject,
99  public refCount
100 {
101 public:
102 
103  class splitCell8
104  {
105  public:
106 
107  // Index to original splitCell this cell was refined off from
108  // -1: top level cell
109  // -2: free splitCell (so should also be in freeSplitCells_)
110  label parent_;
111 
112  //- Cells this cell was refined into
113  autoPtr<FixedList<label, 8> > addedCellsPtr_;
114 
115  //- Construct null (parent = -1)
116  splitCell8();
117 
118  //- Construct from parent
119  splitCell8(const label parent);
120 
121  //- Construct from Istream
122  splitCell8(Istream& is);
123 
124  //- Construct as deep copy
125  splitCell8(const splitCell8&);
126 
127  //- Copy operator since autoPtr otherwise 'steals' storage.
128  void operator=(const splitCell8& s);
129 
130  bool operator==(const splitCell8& s) const;
131 
132  bool operator!=(const splitCell8& s) const;
133 
134  friend Istream& operator>>(Istream&, splitCell8&);
135  friend Ostream& operator<<(Ostream&, const splitCell8&);
136  };
137 
138 
139 private:
140 
141  // Private data
142 
143  //- Is active?
144  bool active_;
145 
146  //- Storage for splitCells
147  DynamicList<splitCell8> splitCells_;
148 
149  //- Unused indices in splitCells
150  DynamicList<label> freeSplitCells_;
151 
152  //- Currently visible cells. Indices into splitCells.
154 
155 
156  // Private Member Functions
157 
158  //- Debug write
159  static void writeEntry
160  (
161  const List<splitCell8>&,
162  const splitCell8&
163  );
164  //- Debug write
165  static void writeDebug
166  (
167  const labelList&,
168  const List<splitCell8>&
169  );
170 
171  //- Check consistency of structure, i.e. indices into splitCells_.
172  void checkIndices() const;
173 
174  //- Allocate a splitCell. Return index in splitCells_.
175  label allocateSplitCell(const label parent, const label i);
176 
177  //- Free a splitCell.
178  void freeSplitCell(const label index);
179 
180  //- Mark entry in splitCells. Recursively mark its parent and subs.
181  void markSplit
182  (
183  const label,
184  labelList& oldToNew,
185  DynamicList<splitCell8>&
186  ) const;
187 
188  void countProc
189  (
190  const label index,
191  const label newProcNo,
192  labelList& splitCellProc,
193  labelList& splitCellNum
194  ) const;
195 
196  // For distribution:
197 
198  //- Mark index and all its descendants
199  void mark(const label, const label, labelList&) const;
200 
201  //- Mark cells according to top parent. Return number of clusters
202  // (set of cells originating from same parent)
203  label markCommonCells(labelList& cellToCluster) const;
204 
205 public:
206 
207  // Declare name of the class and its debug switch
208  TypeName("refinementHistory");
209 
210 
211  // Constructors
212 
213  //- Construct (read) given an IOobject. If global number of visible
214  // cells > 0 becomes active
215  refinementHistory(const IOobject&);
216 
217  //- Construct (read) or construct from components
219  (
220  const IOobject&,
222  const labelList& visibleCells,
223  const bool active
224  );
225 
226  //- Construct (read) or construct from initial number of cells
227  // (all visible). If global number of visible
228  // cells > 0 becomes active
229  refinementHistory(const IOobject&, const label nCells);
230 
231  //- Construct (read) or construct from initial number of cells
232  // (all visible) and active flag
234  (
235  const IOobject&,
236  const label nCells,
237  const bool active
238  );
239 
240  //- Construct as copy
242 
243  //- Construct from multiple refinement histories. If global number of
244  // visible cells > 0 becomes active
246  (
247  const IOobject&,
248  const UPtrList<const labelList>& cellMaps,
249  const UPtrList<const refinementHistory>&
250  );
251 
252  //- Construct from Istream. If global number of
253  // visible cells > 0 becomes active
254  refinementHistory(const IOobject&, Istream&);
255 
256 
257  // Member Functions
258 
259 
260  //- Per cell in the current mesh (i.e. visible) either -1 (unrefined)
261  // or an index into splitCells.
262  const labelList& visibleCells() const
263  {
264  return visibleCells_;
265  }
266 
267  //- Storage for splitCell8s.
268  const DynamicList<splitCell8>& splitCells() const
269  {
270  return splitCells_;
271  }
272 
273  //- Cache of unused indices in splitCells
274  const DynamicList<label>& freeSplitCells() const
275  {
276  return freeSplitCells_;
277  }
278 
279  //- Is there unrefinement history?
280  bool active() const
281  {
282  return active_;
283  }
284 
285  //- Is there unrefinement history?
286  bool& active()
287  {
288  return active_;
289  }
290 
291  //- Get parent of cell
292  label parentIndex(const label cellI) const
293  {
294  label index = visibleCells_[cellI];
295 
296  if (index < 0)
297  {
299  << "Cell " << cellI << " is not visible"
300  << abort(FatalError);
301  }
302  return splitCells_[index].parent_;
303  }
304 
305  //- Store splitting of cell into 8
306  void storeSplit
307  (
308  const label cellI,
309  const labelList& addedCells
310  );
311 
312  //- Store combining 8 cells into master
313  void combineCells
314  (
315  const label masterCellI,
316  const labelList& combinedCells
317  );
318 
319  //- Low level clone
321  (
322  const IOobject& io,
323  const labelList& decomposition,
324  const labelList& splitCellProc,
325  const labelList& splitCellNum,
326  const label procI,
327  labelList& oldToNewSplit
328  ) const;
329 
330  //- Create clone from subset
332  (
333  const IOobject& io,
334  const labelList& cellMap
335  ) const;
336 
337  //- Update numbering for mesh changes
338  void updateMesh(const mapPolyMesh&);
339 
340  //- Update numbering for subsetting
341  void subset
342  (
343  const labelList& pointMap,
344  const labelList& faceMap,
345  const labelList& cellMap
346  );
347 
348  //- Update local numbering for mesh redistribution.
349  // Can only distribute clusters sent across in one go; cannot
350  // handle parts recombined in multiple passes.
351  void distribute(const mapDistributePolyMesh&);
352 
353  //- Compact splitCells_. Removes all freeSplitCells_ elements.
354  void compact();
355 
356  //- Extend/shrink storage. additional visibleCells_ elements get
357  // set to -1.
358  void resize(const label nCells);
359 
360  //- Debug write
361  void writeDebug() const;
362 
363 
364  //- Read object. If global number of visible cells > 0 becomes active
365  virtual bool read();
366 
367  //- ReadData function required for regIOobject read operation. Note:
368  // does not do a reduction - does not set active_ flag
369  virtual bool readData(Istream&);
370 
371  //- WriteData function required for regIOobject write operation
372  virtual bool writeData(Ostream&) const;
373 
374  // Helpers for decompositionConstraint
375 
376  //- Add my decomposition constraints
377  void add
378  (
379  boolList& blockedFace,
380  PtrList<labelList>& specifiedProcessorFaces,
381  labelList& specifiedProcessor,
382  List<labelPair>& explicitConnections
383  ) const;
384 
385  //- Apply any additional post-decomposition constraints
386  void apply
387  (
388  const boolList& blockedFace,
389  const PtrList<labelList>& specifiedProcessorFaces,
390  const labelList& specifiedProcessor,
391  const List<labelPair>& explicitConnections,
392  labelList& decomposition
393  ) const;
394 
395 
396  // IOstream Operators
397 
398  //- Istream operator. Note: does not do a reduction - does not set
399  // active_ flag
401 
402  friend Ostream& operator<<(Ostream&, const refinementHistory&);
403 };
404 
405 
406 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
407 
408 } // End namespace Foam
409 
410 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
411 
412 #endif
413 
414 // ************************************************************************* //
regIOobject.H
Foam::refinementHistory::visibleCells
const labelList & visibleCells() const
Per cell in the current mesh (i.e. visible) either -1 (unrefined)
Definition: refinementHistory.H:261
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::refinementHistory::refinementHistory
refinementHistory(const IOobject &)
Construct (read) given an IOobject. If global number of visible.
Definition: refinementHistory.C:557
UPtrList.H
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeFast.C:90
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:497
Foam::labelList
List< label > labelList
A List of labels.
Definition: labelList.H:56
Foam::refinementHistory::read
virtual bool read()
Read object. If global number of visible cells > 0 becomes active.
Definition: refinementHistory.C:1742
Foam::refinementHistory::active_
bool active_
Is active?
Definition: refinementHistory.H:143
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:56
Foam::refinementHistory::compact
void compact()
Compact splitCells_. Removes all freeSplitCells_ elements.
Definition: refinementHistory.C:1518
Foam::refinementHistory::markSplit
void markSplit(const label, labelList &oldToNew, DynamicList< splitCell8 > &) const
Mark entry in splitCells. Recursively mark its parent and subs.
Definition: refinementHistory.C:340
Foam::refinementHistory::splitCells_
DynamicList< splitCell8 > splitCells_
Storage for splitCells.
Definition: refinementHistory.H:146
Foam::refinementHistory::parentIndex
label parentIndex(const label cellI) const
Get parent of cell.
Definition: refinementHistory.H:291
Foam::refinementHistory::active
bool active() const
Is there unrefinement history?
Definition: refinementHistory.H:279
Foam::refinementHistory::writeEntry
static void writeEntry(const List< splitCell8 > &, const splitCell8 &)
Debug write.
Definition: refinementHistory.C:176
Foam::refinementHistory::operator<<
friend Ostream & operator<<(Ostream &, const refinementHistory &)
Foam::refinementHistory::storeSplit
void storeSplit(const label cellI, const labelList &addedCells)
Store splitting of cell into 8.
Definition: refinementHistory.C:1681
Foam::refinementHistory::writeData
virtual bool writeData(Ostream &) const
WriteData function required for regIOobject write operation.
Definition: refinementHistory.C:1760
Foam::refinementHistory::splitCell8::parent_
label parent_
Definition: refinementHistory.H:109
Foam::refinementHistory::splitCell8::operator==
bool operator==(const splitCell8 &s) const
Definition: refinementHistory.C:101
Foam::refinementHistory::countProc
void countProc(const label index, const label newProcNo, labelList &splitCellProc, labelList &splitCellNum) const
Definition: refinementHistory.C:1227
Foam::refinementHistory::freeSplitCells
const DynamicList< label > & freeSplitCells() const
Cache of unused indices in splitCells.
Definition: refinementHistory.H:273
Foam::refinementHistory::checkIndices
void checkIndices() const
Check consistency of structure, i.e. indices into splitCells_.
Definition: refinementHistory.C:239
Foam::refinementHistory::mark
void mark(const label, const label, labelList &) const
Mark index and all its descendants.
Definition: refinementHistory.C:377
Foam::refinementHistory
All refinement history. Used in unrefinement.
Definition: refinementHistory.H:95
Foam::refinementHistory::splitCell8::splitCell8
splitCell8()
Construct null (parent = -1)
Definition: refinementHistory.C:42
Foam::refinementHistory::writeDebug
void writeDebug() const
Debug write.
Definition: refinementHistory.C:1674
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:59
labelList.H
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::refinementHistory::TypeName
TypeName("refinementHistory")
Foam::PtrList
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
Foam::refinementHistory::splitCell8::operator!=
bool operator!=(const splitCell8 &s) const
Definition: refinementHistory.C:122
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:1120
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
s
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().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))
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:1753
Foam::refinementHistory::markCommonCells
label markCommonCells(labelList &cellToCluster) const
Mark cells according to top parent. Return number of clusters.
Definition: refinementHistory.C:403
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
Foam::refinementHistory::freeSplitCells_
DynamicList< label > freeSplitCells_
Unused indices in splitCells.
Definition: refinementHistory.H:149
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::refinementHistory::splitCell8::addedCellsPtr_
autoPtr< FixedList< label, 8 > > addedCellsPtr_
Cells this cell was refined into.
Definition: refinementHistory.H:112
Foam::refinementHistory::add
void add(boolList &blockedFace, PtrList< labelList > &specifiedProcessorFaces, labelList &specifiedProcessor, List< labelPair > &explicitConnections) const
Add my decomposition constraints.
Definition: refinementHistory.C:451
Foam::IOobject::IOobject
IOobject(const word &name, const fileName &instance, const objectRegistry &registry, readOption r=NO_READ, writeOption w=NO_WRITE, bool registerObject=true)
Construct from name, instance, registry, io options.
Definition: IOobject.C:116
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::IOobject::clone
Foam::autoPtr< IOobject > clone() const
Clone.
Definition: IOobject.H:252
Foam::refinementHistory::combineCells
void combineCells(const label masterCellI, const labelList &combinedCells)
Store combining 8 cells into master.
Definition: refinementHistory.C:1719
Foam::refinementHistory::subset
void subset(const labelList &pointMap, const labelList &faceMap, const labelList &cellMap)
Update numbering for subsetting.
Definition: refinementHistory.C:1187
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
Foam::refinementHistory::splitCell8::operator=
void operator=(const splitCell8 &s)
Copy operator since autoPtr otherwise 'steals' storage.
Definition: refinementHistory.C:80
Foam::refinementHistory::splitCells
const DynamicList< splitCell8 > & splitCells() const
Storage for splitCell8s.
Definition: refinementHistory.H:267
Foam::refinementHistory::distribute
void distribute(const mapDistributePolyMesh &)
Update local numbering for mesh redistribution.
Definition: refinementHistory.C:1268
Foam::refinementHistory::updateMesh
void updateMesh(const mapPolyMesh &)
Update numbering for mesh changes.
Definition: refinementHistory.C:1140
List
Definition: Test.C:19
DynamicList.H
Foam::refinementHistory::allocateSplitCell
label allocateSplitCell(const label parent, const label i)
Allocate a splitCell. Return index in splitCells_.
Definition: refinementHistory.C:258
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::mapDistributePolyMesh
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Definition: mapDistributePolyMesh.H:57
FixedList.H
Foam::refinementHistory::active
bool & active()
Is there unrefinement history?
Definition: refinementHistory.H:285
Foam::refinementHistory::visibleCells_
labelList visibleCells_
Currently visible cells. Indices into splitCells.
Definition: refinementHistory.H:152
Foam::refinementHistory::freeSplitCell
void freeSplitCell(const label index)
Free a splitCell.
Definition: refinementHistory.C:301
Foam::refinementHistory::splitCell8::operator<<
friend Ostream & operator<<(Ostream &, const splitCell8 &)
labelPair.H
autoPtr.H