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