1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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
29 Refinement of (split) hexes using polyTopoChange.
34 \*---------------------------------------------------------------------------*/
39 #include "labelIOList.H"
42 #include "DynamicList.H"
43 #include "primitivePatch.H"
44 #include "removeFaces.H"
45 #include "refinementHistory.H"
46 #include "PackedBoolList.H"
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 // Forward declaration of classes
58 class mapDistributePolyMesh;
60 /*---------------------------------------------------------------------------*\
61 Class hexRef8 Declaration
62 \*---------------------------------------------------------------------------*/
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.
104 //- Get patch and zone info
113 //- Adds a face on top of existing faceI. Reverses if nessecary.
116 polyTopoChange& meshMod,
123 //- Adds internal face from point. No checks on reversal.
124 label addInternalFace
126 polyTopoChange& meshMod,
127 const label meshFaceI,
128 const label meshPointI,
134 //- Modifies existing faceI for either new owner/neighbour or new face
135 // points. Reverses if nessecary.
138 polyTopoChange& meshMod,
145 scalar getLevel0EdgeLength() const;
147 //- Get cell added to point of cellI (if any)
150 const labelListList& cellAnchorPoints,
151 const labelListList& cellAddedCells,
157 //- Get new owner and neighbour (in unspecified order) of pointI
159 void getFaceNeighbours
161 const labelListList& cellAnchorPoints,
162 const labelListList& cellAddedCells,
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.
185 const bool searchForward,
186 const label wantedLevel
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
195 polyTopoChange& meshMod,
203 //- debug:check orientation of new boundary face
204 static void checkBoundaryOrientation
206 polyTopoChange& meshMod,
210 const point& boundaryPt,
214 //- If p0 and p1 are existing vertices check if edge is split and insert
218 const labelList& edgeMidPoint,
221 DynamicList<label>& verts
224 //- Store in maps correspondence from midpoint to anchors and faces.
225 label storeMidPointInfo
227 const labelListList& cellAnchorPoints,
228 const labelListList& cellAddedCells,
229 const labelList& cellMidPoint,
230 const labelList& edgeMidPoint,
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
243 //- Create all internal faces from an unsplit face.
244 void createInternalFromSplitFace
246 const labelListList& cellAnchorPoints,
247 const labelListList& cellAddedCells,
248 const labelList& cellMidPoint,
249 const labelList& faceMidPoint,
250 const labelList& edgeMidPoint,
254 Map<edge>& midPointToAnchors,
255 Map<edge>& midPointToFaceMids,
256 polyTopoChange& meshMod,
260 //- Create all internal faces to split cellI into 8.
261 void createInternalFaces
263 const labelListList& cellAnchorPoints,
264 const labelListList& cellAddedCells,
265 const labelList& cellMidPoint,
266 const labelList& faceMidPoint,
267 const labelList& faceAnchorLevel,
268 const labelList& edgeMidPoint,
270 polyTopoChange& meshMod
273 //- Store vertices from startFp upto face split point.
274 // Used when splitting face into 4.
277 const labelList& edgeMidPoint,
281 DynamicList<label>& faceVerts
284 //- Same as walkFaceToMid but now walk back.
287 const labelList& edgeMidPoint,
291 DynamicList<label>& faceVerts
294 //- Updates refineCell so consistent 2:1 refinement. Returns local
295 // number of cells changed.
296 label faceConsistentRefinement
299 PackedBoolList& refineCell
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&);
316 //- Runtime type information
317 ClassName("hexRef8");
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.
329 const polyMesh& mesh,
330 const labelList& cellLevel,
331 const labelList& pointLevel,
332 const refinementHistory& history
335 //- Construct from mesh and refinement data.
338 const polyMesh& mesh,
339 const labelList& cellLevel,
340 const labelList& pointLevel
348 const labelIOList& cellLevel() const
353 const labelIOList& pointLevel() const
358 const refinementHistory& history() const
363 //- Typical edge length between unrefined points
364 scalar level0EdgeLength() const
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
381 const labelList& cellsToRefine,
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
398 labelList consistentSlowRefinement
400 const label maxFaceDiff,
401 const labelList& cellsToRefine,
402 const labelList& facesToCheck,
403 const label maxPointDiff,
404 const labelList& pointsToCheck
407 //- Like consistentSlowRefinement but uses different meshWave
408 // (proper distance instead of toplogical count). No point checks
410 labelList consistentSlowRefinement2
412 const label maxFaceDiff,
413 const labelList& cellsToRefine,
414 const labelList& facesToCheck
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.
421 // -split cells: 7 new ones get added from original
422 // -split faces: original gets modified; 3 new ones get added
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
432 const labelList& cells,
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
448 const labelList& pointsToStore,
449 const labelList& facesToStore,
450 const labelList& cellsToStore
453 //- Update local numbering + undo
454 // Data to restore given as new pointlabel + stored pointlabel
455 // (i.e. what was in pointsToStore)
459 const Map<label>& pointsToRestore,
460 const Map<label>& facesToRestore,
461 const Map<label>& cellsToRestore
465 //- Update local numbering for subsetted mesh.
466 // Gets new-to-old maps. Not compatible with unrefinement.
469 const labelList& pointMap,
470 const labelList& faceMap,
471 const labelList& cellMap
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
485 const label maxPointDiff,
486 const labelList& pointsToCheck
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;
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
502 const labelList& pointsToUnrefine,
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.
512 const labelList& splitPointLabels,
518 // Set instance for mesh files
519 void setInstance(const fileName& inst);
521 //- Force writing refinement+history to polyMesh directory.
527 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
529 } // End namespace Foam
531 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
535 // ************************************************************************* //