refinementHistory.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2022 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 "autoPtr.H"
78 #include "regIOobject.H"
79 #include "boolList.H"
80 #include "labelPair.H"
81 
82 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
83 
84 namespace Foam
85 {
86 
87 // Forward declaration of classes
88 class polyTopoChangeMap;
89 class polyDistributionMap;
90 
91 
92 // Forward declaration of friend functions and operators
93 
94 class refinementHistory;
95 
96 Istream& operator>>(Istream&, refinementHistory&);
97 Ostream& operator<<(Ostream&, const refinementHistory&);
98 
99 
100 /*---------------------------------------------------------------------------*\
101  Class refinementHistory Declaration
102 \*---------------------------------------------------------------------------*/
104 class refinementHistory
105 :
106  public regIOobject
107 {
108 public:
110  class splitCell8
111  {
112  public:
113 
114  // Index to original splitCell this cell was refined off from
115  // -1: top level cell
116  // -2: free splitCell (so should also be in freeSplitCells_)
117  label parent_;
118 
119  //- Cells this cell was refined into
121 
122  //- Construct null (parent = -1)
123  splitCell8();
124 
125  //- Construct from parent
126  splitCell8(const label parent);
127 
128  //- Construct from Istream
129  splitCell8(Istream& is);
130 
131  //- Construct as deep copy
132  splitCell8(const splitCell8&);
133 
134  //- Copy operator since autoPtr otherwise 'steals' storage.
135  void operator=(const splitCell8& s);
136 
137  bool operator==(const splitCell8& s) const;
138 
139  bool operator!=(const splitCell8& s) const;
140 
141  friend Istream& operator>>(Istream&, splitCell8&);
142  friend Ostream& operator<<(Ostream&, const splitCell8&);
143  };
144 
145 
146 private:
147 
148  // Private Data
149 
150  //- Is active?
151  bool active_;
152 
153  //- Storage for splitCells
154  DynamicList<splitCell8> splitCells_;
155 
156  //- Unused indices in splitCells
157  DynamicList<label> freeSplitCells_;
158 
159  //- Currently visible cells. Indices into splitCells.
160  labelList visibleCells_;
161 
162 
163  // Private Member Functions
164 
165  //- Debug write
166  static void writeEntry
167  (
168  const List<splitCell8>&,
169  const splitCell8&
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. If global number of visible
221  // cells > 0 becomes active
222  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). If global number of visible
235  // 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  //- Copy constructor
249 
250  //- Construct from multiple refinement histories. If global number of
251  // visible cells > 0 becomes active
253  (
254  const IOobject&,
255  const UPtrList<const labelList>& cellMaps,
257  );
258 
259  //- Construct from Istream. If global number of
260  // visible cells > 0 becomes active
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 topoChange(const polyTopoChangeMap&);
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 polyDistributionMap&);
359 
360 
361  //- Compact splitCells_. Removes all freeSplitCells_ elements.
362  void compact();
363 
364  //- Extend/shrink storage. additional visibleCells_ elements get
365  // set to -1.
366  void resize(const label nCells);
367 
368  //- Debug write
369  void writeDebug() const;
370 
371 
372  //- Read object. If global number of visible cells > 0 becomes active
373  virtual bool read();
374 
375  //- ReadData function required for regIOobject read operation. Note:
376  // does not do a reduction - does not set active_ flag
377  virtual bool readData(Istream&);
378 
379  //- WriteData function required for regIOobject write operation
380  virtual bool writeData(Ostream&) const;
381 
382  // Helpers for decompositionConstraint
383 
384  //- Add my decomposition constraints
385  void add
386  (
387  boolList& blockedFace,
388  PtrList<labelList>& specifiedProcessorFaces,
389  labelList& specifiedProcessor,
390  List<labelPair>& explicitConnections
391  ) const;
392 
393  //- Apply any additional post-decomposition constraints
394  void apply
395  (
396  const boolList& blockedFace,
397  const PtrList<labelList>& specifiedProcessorFaces,
398  const labelList& specifiedProcessor,
399  const List<labelPair>& explicitConnections,
400  labelList& decomposition
401  ) const;
402 
403 
404  // IOstream Operators
405 
406  //- Istream operator. Note: does not do a reduction - does not set
407  // active_ flag
409 
410  friend Ostream& operator<<(Ostream&, const refinementHistory&);
411 };
412 
413 
416 
417 
418 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
419 
420 } // End namespace Foam
421 
422 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
423 
424 #endif
425 
426 // ************************************************************************* //
autoPtr< IOobject > clone() const
Clone.
Definition: IOobject.H:288
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
const DynamicList< splitCell8 > & splitCells() const
Storage for splitCell8s.
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
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
splitCell8()
Construct null (parent = -1)
autoPtr< FixedList< label, 8 > > addedCellsPtr_
Cells this cell was refined into.
refinementHistory(const IOobject &)
Construct (read) given an IOobject. If global number of visible.
bool operator==(const splitCell8 &s) const
virtual bool writeData(Ostream &) const
WriteData function required for regIOobject write operation.
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
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))
void topoChange(const polyTopoChangeMap &)
Update numbering for mesh changes.
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:56
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Istream & operator>>(Istream &, directionInfo &)
void subset(const labelList &pointMap, const labelList &faceMap, const labelList &cellMap)
Update numbering for subsetting.
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: UPtrList.H:54
errorManip< error > abort(error &err)
Definition: errorManip.H:131
void distribute(const polyDistributionMap &)
Update local numbering for mesh redistribution.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
bool operator!=(const splitCell8 &s) const
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.
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
friend Ostream & operator<<(Ostream &, const splitCell8 &)
const labelList & visibleCells() const
Per cell in the current mesh (i.e. visible) either -1 (unrefined)
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 templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:70
void operator=(const splitCell8 &s)
Copy operator since autoPtr otherwise &#39;steals&#39; storage.
label parentIndex(const label celli) const
Get parent of cell.
Ostream & operator<<(Ostream &, const ensightPart &)
TypeName("refinementHistory")
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:52
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
All refinement history. Used in unrefinement.
void add(boolList &blockedFace, PtrList< labelList > &specifiedProcessorFaces, labelList &specifiedProcessor, List< labelPair > &explicitConnections) const
Add my decomposition constraints.
void writeDebug() const
Debug write.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:98
void resize(const label nCells)
Extend/shrink storage. additional visibleCells_ elements get.
friend Istream & operator>>(Istream &, splitCell8 &)
Namespace for OpenFOAM.