FreeFOAM The Cross-Platform CFD Toolkit
hexRef8.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) 1991-2010 OpenCFD Ltd.
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::hexRef8
26 
27 Description
28  Refinement of (split) hexes using polyTopoChange.
29 
30 SourceFiles
31  hexRef8.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef hexRef8_H
36 #define hexRef8_H
37 
38 #include <OpenFOAM/labelIOList.H>
39 #include <OpenFOAM/face.H>
40 #include <OpenFOAM/HashSet.H>
41 #include <OpenFOAM/DynamicList.H>
43 #include "removeFaces.H"
44 #include "refinementHistory.H"
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 // Forward declaration of classes
53 class polyMesh;
54 class polyPatch;
55 class polyTopoChange;
56 class mapPolyMesh;
57 class mapDistributePolyMesh;
58 
59 /*---------------------------------------------------------------------------*\
60  Class hexRef8 Declaration
61 \*---------------------------------------------------------------------------*/
62 
63 class hexRef8
64 {
65  // Private data
66 
67  //- Reference to underlying mesh.
68  const polyMesh& mesh_;
69 
70  //- Per cell the refinement level
71  labelIOList cellLevel_;
72 
73  //- Per point the refinement level
74  labelIOList pointLevel_;
75 
76  //- Typical edge length between unrefined points
77  const scalar level0Edge_;
78 
79  //- Refinement history
80  refinementHistory history_;
81 
82  //- Face remover engine
83  removeFaces faceRemover_;
84 
85  //- Level of saved points
86  Map<label> savedPointLevel_;
87 
88  //- Level of saved cells
89  Map<label> savedCellLevel_;
90 
91 
92  // Private Member Functions
93 
94  //- Reorder according to map.
95  static void reorder
96  (
97  const labelList& map,
98  const label len,
99  const label null,
100  labelList& elems
101  );
102 
103  //- Get patch and zone info
104  void getFaceInfo
105  (
106  const label faceI,
107  label& patchID,
108  label& zoneID,
109  label& zoneFlip
110  ) const;
111 
112  //- Adds a face on top of existing faceI. Reverses if nessecary.
113  label addFace
114  (
115  polyTopoChange& meshMod,
116  const label faceI,
117  const face& newFace,
118  const label own,
119  const label nei
120  ) const;
121 
122  //- Adds internal face from point. No checks on reversal.
123  label addInternalFace
124  (
125  polyTopoChange& meshMod,
126  const label meshFaceI,
127  const label meshPointI,
128  const face& newFace,
129  const label own,
130  const label nei
131  ) const;
132 
133  //- Modifies existing faceI for either new owner/neighbour or new face
134  // points. Reverses if nessecary.
135  void modFace
136  (
137  polyTopoChange& meshMod,
138  const label faceI,
139  const face& newFace,
140  const label own,
141  const label nei
142  ) const;
143 
144  scalar getLevel0EdgeLength() const;
145 
146  //- Get cell added to point of cellI (if any)
147  label getAnchorCell
148  (
149  const labelListList& cellAnchorPoints,
150  const labelListList& cellAddedCells,
151  const label cellI,
152  const label faceI,
153  const label pointI
154  ) const;
155 
156  //- Get new owner and neighbour (in unspecified order) of pointI
157  // on faceI.
158  void getFaceNeighbours
159  (
160  const labelListList& cellAnchorPoints,
161  const labelListList& cellAddedCells,
162  const label faceI,
163  const label pointI,
164 
165  label& own,
166  label& nei
167  ) const;
168 
169 
170  //- Get index of minimum pointlevel.
171  label findMinLevel(const labelList& f) const;
172  //- Get maximum pointlevel.
173  label findMaxLevel(const labelList& f) const;
174  //- Count number of vertices <= anchorLevel
175  label countAnchors(const labelList&, const label) const;
176  //- Debugging: dump cell as .obj file
177  void dumpCell(const label cellI) const;
178  //- Find index of point with wantedLevel, starting from fp.
179  label findLevel
180  (
181  const label faceI,
182  const face& f,
183  const label startFp,
184  const bool searchForward,
185  const label wantedLevel
186  ) const;
187 
189  //void printLevels(Ostream&, const labelList&) const;
190 
191  //- debug:check orientation of added internal face
192  static void checkInternalOrientation
193  (
194  polyTopoChange& meshMod,
195  const label cellI,
196  const label faceI,
197  const point& ownPt,
198  const point& neiPt,
199  const face& newFace
200  );
201 
202  //- debug:check orientation of new boundary face
203  static void checkBoundaryOrientation
204  (
205  polyTopoChange& meshMod,
206  const label cellI,
207  const label faceI,
208  const point& ownPt,
209  const point& boundaryPt,
210  const face& newFace
211  );
212 
213  //- If p0 and p1 are existing vertices check if edge is split and insert
214  // splitPoint.
215  void insertEdgeSplit
216  (
217  const labelList& edgeMidPoint,
218  const label p0,
219  const label p1,
220  DynamicList<label>& verts
221  ) const;
222 
223  //- Store in maps correspondence from midpoint to anchors and faces.
224  label storeMidPointInfo
225  (
226  const labelListList& cellAnchorPoints,
227  const labelListList& cellAddedCells,
228  const labelList& cellMidPoint,
229  const labelList& edgeMidPoint,
230  const label cellI,
231  const label faceI,
232  const bool faceOrder,
233  const label midPointI,
234  const label anchorPointI,
235  const label faceMidPointI,
236 
237  Map<edge>& midPointToAnchors,
238  Map<edge>& midPointToFaceMids,
239  polyTopoChange& meshMod
240  ) const;
241 
242  //- Create all internal faces from an unsplit face.
243  void createInternalFromSplitFace
244  (
245  const labelListList& cellAnchorPoints,
246  const labelListList& cellAddedCells,
247  const labelList& cellMidPoint,
248  const labelList& faceMidPoint,
249  const labelList& edgeMidPoint,
250  const label cellI,
251  const label faceI,
252 
253  Map<edge>& midPointToAnchors,
254  Map<edge>& midPointToFaceMids,
255  polyTopoChange& meshMod,
256  label& nFacesAdded
257  ) const;
258 
259  //- Create all internal faces to split cellI into 8.
260  void createInternalFaces
261  (
262  const labelListList& cellAnchorPoints,
263  const labelListList& cellAddedCells,
264  const labelList& cellMidPoint,
265  const labelList& faceMidPoint,
266  const labelList& faceAnchorLevel,
267  const labelList& edgeMidPoint,
268  const label cellI,
269  polyTopoChange& meshMod
270  ) const;
271 
272  //- Store vertices from startFp upto face split point.
273  // Used when splitting face into 4.
274  void walkFaceToMid
275  (
276  const labelList& edgeMidPoint,
277  const label cLevel,
278  const label faceI,
279  const label startFp,
280  DynamicList<label>& faceVerts
281  ) const;
282 
283  //- Same as walkFaceToMid but now walk back.
284  void walkFaceFromMid
285  (
286  const labelList& edgeMidPoint,
287  const label cLevel,
288  const label faceI,
289  const label startFp,
290  DynamicList<label>& faceVerts
291  ) const;
292 
293  //- Updates refineCell so consistent 2:1 refinement. Returns local
294  // number of cells changed.
295  label faceConsistentRefinement
296  (
297  const bool maxSet,
299  ) const;
300 
301  //- Check wanted refinement for 2:1 consistency
302  void checkWantedRefinementLevels(const labelList&) const;
303 
304 
305 
306  //- Disallow default bitwise copy construct
307  hexRef8(const hexRef8&);
308 
309  //- Disallow default bitwise assignment
310  void operator=(const hexRef8&);
311 
312 
313 public:
314 
315  //- Runtime type information
316  ClassName("hexRef8");
317 
318 
319  // Constructors
320 
321  //- Construct from mesh, read_if_present refinement data
322  // (from write below)
323  hexRef8(const polyMesh& mesh);
324 
325  //- Construct from mesh and un/refinement data.
326  hexRef8
327  (
328  const polyMesh& mesh,
329  const labelList& cellLevel,
330  const labelList& pointLevel,
332  );
333 
334  //- Construct from mesh and refinement data.
335  hexRef8
336  (
337  const polyMesh& mesh,
338  const labelList& cellLevel,
339  const labelList& pointLevel
340  );
341 
342 
343  // Member Functions
344 
345  // Access
346 
347  const labelIOList& cellLevel() const
348  {
349  return cellLevel_;
350  }
351 
352  const labelIOList& pointLevel() const
353  {
354  return pointLevel_;
355  }
356 
357  const refinementHistory& history() const
358  {
359  return history_;
360  }
361 
362  //- Typical edge length between unrefined points
363  scalar level0EdgeLength() const
364  {
365  return level0Edge_;
366  }
367 
368  // Refinement
369 
370  //- Gets level such that the face has four points <= level.
371  label getAnchorLevel(const label faceI) const;
372 
373  //- Given valid mesh and current cell level and proposed
374  // cells to refine calculate any clashes (due to 2:1) and return
375  // ok list of cells to refine.
376  // Either adds cells to refine to set (maxSet = true) or
377  // removes cells to refine (maxSet = false)
379  (
380  const labelList& cellsToRefine,
381  const bool maxSet
382  ) const;
383 
384  //- Like consistentRefinement but slower:
385  // - specify number of cells between consecutive refinement levels
386  // (consistentRefinement equivalent to 1)
387  // - specify max level difference between point-connected cells.
388  // (-1 to disable) Note that with normal 2:1 limitation
389  // (maxFaceDiff=1) there can be 8:1 size difference across point
390  // connected cells so maxPointDiff allows you to make that less.
391  // cellsToRefine : cells we're thinking about refining. It will
392  // extend this set. All refinement levels will be
393  // at least maxFaceDiff layers thick.
394  // facesToCheck : additional faces where to implement the
395  // maxFaceDiff thickness (usually only boundary
396  // faces)
398  (
399  const label maxFaceDiff,
400  const labelList& cellsToRefine,
401  const labelList& facesToCheck,
402  const label maxPointDiff,
403  const labelList& pointsToCheck
404  ) const;
405 
406  //- Like consistentSlowRefinement but uses different meshWave
407  // (proper distance instead of toplogical count). No point checks
408  // yet.
410  (
411  const label maxFaceDiff,
412  const labelList& cellsToRefine,
413  const labelList& facesToCheck
414  ) const;
415 
416  //- Insert refinement. All selected cells will be split into 8.
417  // Returns per element in cells the 8 cells they were split into.
418  // Guarantees that the 0th element is the original cell label.
419  // Mapping:
420  // -split cells: 7 new ones get added from original
421  // -split faces: original gets modified; 3 new ones get added
422  // from original
423  // -added internal faces: added from original cell face(if
424  // that was internal) or created out-of-nothing (so will not
425  // get mapped!). Note: could make this inflate from point but
426  // that will allocate interpolation.
427  // -points added to split edge: added from edge start()
428  // -midpoints added: added from cellPoints[0].
430  (
431  const labelList& cells,
433  );
434 
435  //- Update local numbering for changed mesh.
436  void updateMesh(const mapPolyMesh&);
437 
438 
439  // Restoring : is where other processes delete and reinsert data.
440  // These callbacks allow this to restore the cellLevel
441  // and pointLevel for reintroduced points.
442  // Is not related to undoing my refinement
443 
444  //- Signal points/face/cells for which to store data
445  void storeData
446  (
447  const labelList& pointsToStore,
448  const labelList& facesToStore,
449  const labelList& cellsToStore
450  );
451 
452  //- Update local numbering + undo
453  // Data to restore given as new pointlabel + stored pointlabel
454  // (i.e. what was in pointsToStore)
455  void updateMesh
456  (
457  const mapPolyMesh&,
458  const Map<label>& pointsToRestore,
459  const Map<label>& facesToRestore,
460  const Map<label>& cellsToRestore
461  );
462 
463 
464  //- Update local numbering for subsetted mesh.
465  // Gets new-to-old maps. Not compatible with unrefinement.
466  void subset
467  (
468  const labelList& pointMap,
469  const labelList& faceMap,
470  const labelList& cellMap
471  );
472 
473  //- Update local numbering for mesh redistribution
474  void distribute(const mapDistributePolyMesh&);
475 
476  //- Debug: Check coupled mesh for correctness
477  void checkMesh() const;
478 
479  //- Debug: Check 2:1 consistency across faces.
480  // maxPointDiff==-1 : only check 2:1 across faces
481  // maxPointDiff!=-1 : check point-connected cells.
483  (
484  const label maxPointDiff,
485  const labelList& pointsToCheck
486  ) const;
487 
488  // Unrefinement (undoing refinement, not arbitrary coarsening)
489 
490  //- Return the points at the centre of top-level split cells
491  // that can be unsplit.
492  labelList getSplitPoints() const;
493 
494  //- Given proposed
495  // splitPoints to unrefine according to calculate any clashes
496  // (due to 2:1) and return ok list of points to unrefine.
497  // Either adds points to refine to set (maxSet = true) or
498  // removes points to refine (maxSet = false)
500  (
501  const labelList& pointsToUnrefine,
502  const bool maxSet
503  ) const;
504 
505  //- Remove some refinement. Needs to be supplied output of
506  // consistentUnrefinement. Only call if undoable set.
507  // All 8 pointCells of a split point will be combined into
508  // the lowest numbered cell of those 8.
509  void setUnrefinement
510  (
511  const labelList& splitPointLabels,
513  );
514 
515  // Write
516 
517  // Set instance for mesh files
518  void setInstance(const fileName& inst);
519 
520  //- Force writing refinement+history to polyMesh directory.
521  bool write() const;
522 
523 };
524 
525 
526 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
527 
528 } // End namespace Foam
529 
530 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
531 
532 #endif
533 
534 // ************************ vim: set sw=4 sts=4 et: ************************ //