All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
hexRef8.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-2019 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::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 "labelIOList.H"
39 #include "face.H"
40 #include "HashSet.H"
41 #include "DynamicList.H"
42 #include "primitivePatch.H"
43 #include "removeFaces.H"
44 #include "refinementHistory.H"
45 #include "PackedBoolList.H"
47 #include "cellShapeList.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 // Forward declaration of classes
55 class polyMesh;
56 class polyPatch;
57 class polyTopoChange;
58 class mapPolyMesh;
59 class mapDistributePolyMesh;
60 
61 /*---------------------------------------------------------------------------*\
62  Class hexRef8 Declaration
63 \*---------------------------------------------------------------------------*/
64 
65 class hexRef8
66 {
67  // Private Data
68 
69  //- Reference to underlying mesh.
70  const polyMesh& mesh_;
71 
72  //- Per cell the refinement level
73  labelIOList cellLevel_;
74 
75  //- Per point the refinement level
76  labelIOList pointLevel_;
77 
78  //- Typical edge length between unrefined points
80 
81  //- Refinement history
82  refinementHistory history_;
83 
84  //- Face remover engine
85  removeFaces faceRemover_;
86 
87  //- Level of saved points
88  Map<label> savedPointLevel_;
89 
90  //- Level of saved cells
91  Map<label> savedCellLevel_;
92 
93  //- Cell shapes when seen as split hexes
94  mutable autoPtr<cellShapeList> cellShapesPtr_;
95 
96 
97  // Private Member Functions
98 
99  //- Reorder according to map.
100  static void reorder
101  (
102  const labelList& map,
103  const label len,
104  const label null,
105  labelList& elems
106  );
107 
108  //- Get patch and zone info
109  void getFaceInfo
110  (
111  const label facei,
112  label& patchID,
113  label& zoneID,
114  label& zoneFlip
115  ) const;
116 
117  //- Adds a face on top of existing facei. Reverses if necessary.
118  label addFace
119  (
120  polyTopoChange& meshMod,
121  const label facei,
122  const face& newFace,
123  const label own,
124  const label nei
125  ) const;
126 
127  //- Adds internal face from point. No checks on reversal.
128  label addInternalFace
129  (
130  polyTopoChange& meshMod,
131  const label meshFacei,
132  const label meshPointi,
133  const face& newFace,
134  const label own,
135  const label nei
136  ) const;
137 
138  //- Modifies existing facei for either new owner/neighbour or new face
139  // points. Reverses if necessary.
140  void modFace
141  (
142  polyTopoChange& meshMod,
143  const label facei,
144  const face& newFace,
145  const label own,
146  const label nei
147  ) const;
148 
149  scalar getLevel0EdgeLength() const;
150 
151  //- Get cell added to point of celli (if any)
152  label getAnchorCell
153  (
154  const labelListList& cellAnchorPoints,
155  const labelListList& cellAddedCells,
156  const label celli,
157  const label facei,
158  const label pointi
159  ) const;
160 
161  //- Get new owner and neighbour (in unspecified order) of pointi
162  // on facei.
163  void getFaceNeighbours
164  (
165  const labelListList& cellAnchorPoints,
166  const labelListList& cellAddedCells,
167  const label facei,
168  const label pointi,
169 
170  label& own,
171  label& nei
172  ) const;
173 
174 
175  //- Get index of minimum pointlevel.
176  label findMinLevel(const labelList& f) const;
177  //- Get maximum pointlevel.
178  label findMaxLevel(const labelList& f) const;
179  //- Count number of vertices <= anchorLevel
180  label countAnchors(const labelList&, const label) const;
181  //- Debugging: dump cell as .obj file
182  void dumpCell(const label celli) const;
183  //- Find index of point with wantedLevel, starting from fp.
184  label findLevel
185  (
186  const label facei,
187  const face& f,
188  const label startFp,
189  const bool searchForward,
190  const label wantedLevel
191  ) const;
192 
194  // void printLevels(Ostream&, const labelList&) const;
195 
196  //- debug:check orientation of added internal face
197  static void checkInternalOrientation
198  (
199  polyTopoChange& meshMod,
200  const label celli,
201  const label facei,
202  const point& ownPt,
203  const point& neiPt,
204  const face& newFace
205  );
206 
207  //- debug:check orientation of new boundary face
208  static void checkBoundaryOrientation
209  (
210  polyTopoChange& meshMod,
211  const label celli,
212  const label facei,
213  const point& ownPt,
214  const point& boundaryPt,
215  const face& newFace
216  );
217 
218  //- If p0 and p1 are existing vertices check if edge is split and insert
219  // splitPoint.
220  void insertEdgeSplit
221  (
222  const labelList& edgeMidPoint,
223  const label p0,
224  const label p1,
225  DynamicList<label>& verts
226  ) const;
227 
228  //- Store in maps correspondence from midpoint to anchors and faces.
229  label storeMidPointInfo
230  (
231  const labelListList& cellAnchorPoints,
232  const labelListList& cellAddedCells,
233  const labelList& cellMidPoint,
234  const labelList& edgeMidPoint,
235  const label celli,
236  const label facei,
237  const bool faceOrder,
238  const label midPointi,
239  const label anchorPointi,
240  const label faceMidPointi,
241 
242  Map<edge>& midPointToAnchors,
243  Map<edge>& midPointToFaceMids,
244  polyTopoChange& meshMod
245  ) const;
246 
247  //- Create all internal faces from an unsplit face.
248  void createInternalFromSplitFace
249  (
250  const labelListList& cellAnchorPoints,
251  const labelListList& cellAddedCells,
252  const labelList& cellMidPoint,
253  const labelList& faceMidPoint,
254  const labelList& edgeMidPoint,
255  const label celli,
256  const label facei,
257 
258  Map<edge>& midPointToAnchors,
259  Map<edge>& midPointToFaceMids,
260  polyTopoChange& meshMod,
261  label& nFacesAdded
262  ) const;
263 
264  //- Create all internal faces to split celli into 8.
265  void createInternalFaces
266  (
267  const labelListList& cellAnchorPoints,
268  const labelListList& cellAddedCells,
269  const labelList& cellMidPoint,
270  const labelList& faceMidPoint,
271  const labelList& faceAnchorLevel,
272  const labelList& edgeMidPoint,
273  const label celli,
274  polyTopoChange& meshMod
275  ) const;
276 
277  //- Store vertices from startFp up to face split point.
278  // Used when splitting face into 4.
279  void walkFaceToMid
280  (
281  const labelList& edgeMidPoint,
282  const label cLevel,
283  const label facei,
284  const label startFp,
285  DynamicList<label>& faceVerts
286  ) const;
287 
288  //- Same as walkFaceToMid but now walk back.
289  void walkFaceFromMid
290  (
291  const labelList& edgeMidPoint,
292  const label cLevel,
293  const label facei,
294  const label startFp,
295  DynamicList<label>& faceVerts
296  ) const;
297 
298  //- Updates refineCell so consistent 2:1 refinement. Returns local
299  // number of cells changed.
300  label faceConsistentRefinement
301  (
302  const bool maxSet,
304  ) const;
305 
306  //- Check wanted refinement for 2:1 consistency
307  void checkWantedRefinementLevels(const labelList&) const;
308 
309 
310  // Cellshape recognition
311 
312  //- Collect all points on face of certain level
313  void collectLevelPoints
314  (
315  const labelList& f,
316  const label level,
318  ) const;
319 
320  //- Collect all points on face (in local numbering) of certain level
321  void collectLevelPoints
322  (
323  const labelList& meshPoints,
324  const labelList& f,
325  const label level,
326  DynamicList<label>& points
327  ) const;
328 
329  //- Collect all faces with four corner points and return true if
330  // hex was matched (6 faces of each four corner points)
331  bool matchHexShape
332  (
333  const label celli,
334  const label cellLevel,
335  DynamicList<face>& quads
336  ) const;
337 
338 
339 public:
340 
341  //- Runtime type information
342  ClassName("hexRef8");
343 
344 
345  // Constructors
346 
347  //- Construct from mesh, read_if_present refinement data
348  // (from write below). If readHistory is true does read_if_present
349  // of refinement history. If false clears all history
350  hexRef8(const polyMesh& mesh, const bool readHistory = true);
351 
352  //- Construct from mesh and un/refinement data and optional size of
353  // starting cells
354  hexRef8
355  (
356  const polyMesh& mesh,
357  const labelList& cellLevel,
358  const labelList& pointLevel,
359  const refinementHistory& history,
360  const scalar level0Edge = -great
361  );
362 
363  //- Construct from mesh and refinement data and optional size of
364  // starting cells
365  hexRef8
366  (
367  const polyMesh& mesh,
368  const labelList& cellLevel,
369  const labelList& pointLevel,
370  const scalar level0Edge = -great
371  );
372 
373  //- Disallow default bitwise copy construction
374  hexRef8(const hexRef8&) = delete;
375 
376 
377  // Member Functions
378 
379  // Access
381  const polyMesh& mesh() const
382  {
383  return mesh_;
384  }
386  const labelIOList& cellLevel() const
387  {
388  return cellLevel_;
389  }
391  const labelIOList& pointLevel() const
392  {
393  return pointLevel_;
394  }
396  const refinementHistory& history() const
397  {
398  return history_;
399  }
400 
401  //- Typical edge length between unrefined points
402  scalar level0EdgeLength() const
403  {
404  return level0Edge_.value();
405  }
406 
407  // Refinement
408 
409  //- Gets level such that the face has four points <= level.
410  label faceLevel(const label facei) const;
411 
412  //- Given valid mesh and current cell level and proposed
413  // cells to refine calculate any clashes (due to 2:1) and return
414  // ok list of cells to refine.
415  // Either adds cells to refine to set (maxSet = true) or
416  // removes cells to refine (maxSet = false)
418  (
419  const labelList& cellsToRefine,
420  const bool maxSet
421  ) const;
422 
423  //- Like consistentRefinement but slower:
424  //
425  // - specify number of cells between consecutive refinement levels
426  // (consistentRefinement equivalent to 1)
427  // - specify max level difference between point-connected cells.
428  // (-1 to disable) Note that with normal 2:1 limitation
429  // (maxFaceDiff=1) there can be 8:1 size difference across point
430  // connected cells so maxPointDiff allows you to make that less.
431  // cellsToRefine : cells we're thinking about refining. It will
432  // extend this set. All refinement levels will be
433  // at least maxFaceDiff layers thick.
434  // facesToCheck : additional faces where to implement the
435  // maxFaceDiff thickness (usually only boundary
436  // faces)
438  (
439  const label maxFaceDiff,
440  const labelList& cellsToRefine,
441  const labelList& facesToCheck,
442  const label maxPointDiff,
443  const labelList& pointsToCheck
444  ) const;
445 
446  //- Like consistentSlowRefinement but uses different meshWave
447  // (proper distance instead of toplogical count). No point checks
448  // yet.
450  (
451  const label maxFaceDiff,
452  const labelList& cellsToRefine,
453  const labelList& facesToCheck
454  ) const;
455 
456  //- Insert refinement. All selected cells will be split into 8.
457  // Returns per element in cells the 8 cells they were split into.
458  // Guarantees that the 0th element is the original cell label.
459  // Mapping:
460  // -split cells: 7 new ones get added from original
461  // -split faces: original gets modified; 3 new ones get added
462  // from original
463  // -added internal faces: added from original cell face(if
464  // that was internal) or created out-of-nothing (so will not
465  // get mapped!). Note: could make this inflate from point but
466  // that will allocate interpolation.
467  // -points added to split edge: added from edge start()
468  // -midpoints added: added from cellPoints[0].
470  (
471  const labelList& cells,
473  );
474 
475  //- Update local numbering for changed mesh.
476  void updateMesh(const mapPolyMesh&);
477 
478 
479  // Restoring : is where other processes delete and reinsert data.
480  // These callbacks allow this to restore the cellLevel
481  // and pointLevel for reintroduced points.
482  // Is not related to undoing my refinement
483 
484  //- Signal points/face/cells for which to store data
485  void storeData
486  (
487  const labelList& pointsToStore,
488  const labelList& facesToStore,
489  const labelList& cellsToStore
490  );
491 
492  //- Update local numbering + undo
493  // Data to restore given as new pointlabel + stored pointlabel
494  // (i.e. what was in pointsToStore)
495  void updateMesh
496  (
497  const mapPolyMesh&,
498  const Map<label>& pointsToRestore,
499  const Map<label>& facesToRestore,
500  const Map<label>& cellsToRestore
501  );
502 
503 
504  //- Update local numbering for subsetted mesh.
505  // Gets new-to-old maps. Not compatible with unrefinement.
506  void subset
507  (
508  const labelList& pointMap,
509  const labelList& faceMap,
510  const labelList& cellMap
511  );
512 
513  //- Update local numbering for mesh redistribution
514  void distribute(const mapDistributePolyMesh&);
515 
516  //- Debug: Check coupled mesh for correctness
517  void checkMesh() const;
518 
519  //- Debug: Check 2:1 consistency across faces.
520  // maxPointDiff==-1 : only check 2:1 across faces
521  // maxPointDiff!=-1 : check point-connected cells.
523  (
524  const label maxPointDiff,
525  const labelList& pointsToCheck
526  ) const;
527 
528  //- Utility: get hexes as cell shapes
529  const cellShapeList& cellShapes() const;
530 
531 
532  // Unrefinement (undoing refinement, not arbitrary coarsening)
533 
534  //- Return the points at the centre of top-level split cells
535  // that can be unsplit.
536  labelList getSplitPoints() const;
537 
538  //- Given proposed
539  // splitPoints to unrefine according to calculate any clashes
540  // (due to 2:1) and return ok list of points to unrefine.
541  // Either adds points to refine to set (maxSet = true) or
542  // removes points to refine (maxSet = false)
544  (
545  const labelList& pointsToUnrefine,
546  const bool maxSet
547  ) const;
548 
549  //- Remove some refinement. Needs to be supplied output of
550  // consistentUnrefinement. Only call if undoable set.
551  // All 8 pointCells of a split point will be combined into
552  // the lowest numbered cell of those 8.
553  void setUnrefinement
554  (
555  const labelList& splitPointLabels,
557  );
558 
559  // Write
560 
561  // Set instance for mesh files
562  void setInstance(const fileName& inst);
563 
564  //- Force writing refinement+history to polyMesh directory.
565  bool write(const bool write = true) const;
566 
567 
568  // Member Operators
569 
570  //- Disallow default bitwise assignment
571  void operator=(const hexRef8&) = delete;
572 };
573 
574 
575 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
576 
577 } // End namespace Foam
578 
579 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
580 
581 #endif
582 
583 // ************************************************************************* //
void distribute(const mapDistributePolyMesh &)
Update local numbering for mesh redistribution.
Definition: hexRef8.C:4570
const refinementHistory & history() const
Definition: hexRef8.H:395
Given list of faces to remove insert all the topology changes. Contains helper function to get consis...
Definition: removeFaces.H:62
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
A class for handling file names.
Definition: fileName.H:79
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
const labelIOList & pointLevel() const
Definition: hexRef8.H:390
void setUnrefinement(const labelList &splitPointLabels, polyTopoChange &)
Remove some refinement. Needs to be supplied output of.
Definition: hexRef8.C:5558
void checkMesh() const
Debug: Check coupled mesh for correctness.
Definition: hexRef8.C:4598
void storeData(const labelList &pointsToStore, const labelList &facesToStore, const labelList &cellsToStore)
Signal points/face/cells for which to store data.
Definition: hexRef8.C:4260
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
labelList consistentSlowRefinement2(const label maxFaceDiff, const labelList &cellsToRefine, const labelList &facesToCheck) const
Like consistentSlowRefinement but uses different meshWave.
Definition: hexRef8.C:2815
labelListList setRefinement(const labelList &cells, polyTopoChange &)
Insert refinement. All selected cells will be split into 8.
Definition: hexRef8.C:3240
labelList consistentUnrefinement(const labelList &pointsToUnrefine, const bool maxSet) const
Given proposed.
Definition: hexRef8.C:5324
scalar level0EdgeLength() const
Typical edge length between unrefined points.
Definition: hexRef8.H:401
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
void subset(const labelList &pointMap, const labelList &faceMap, const labelList &cellMap)
Update local numbering for subsetted mesh.
Definition: hexRef8.C:4487
hexRef8(const polyMesh &mesh, const bool readHistory=true)
Construct from mesh, read_if_present refinement data.
Definition: hexRef8.C:1928
void setInstance(const fileName &inst)
Definition: hexRef8.C:1732
const cellShapeList & cells
const pointField & points
labelList consistentRefinement(const labelList &cellsToRefine, const bool maxSet) const
Given valid mesh and current cell level and proposed.
Definition: hexRef8.C:2256
Refinement of (split) hexes using polyTopoChange.
Definition: hexRef8.H:64
bool write(const bool write=true) const
Force writing refinement+history to polyMesh directory.
Definition: hexRef8.C:5746
labelList consistentSlowRefinement(const label maxFaceDiff, const labelList &cellsToRefine, const labelList &facesToCheck, const label maxPointDiff, const labelList &pointsToCheck) const
Like consistentRefinement but slower:
Definition: hexRef8.C:2331
const Type & value() const
Return const reference to value.
Container with cells to refine. Refinement given as single direction.
Definition: refineCell.H:56
void updateMesh(const mapPolyMesh &)
Update local numbering for changed mesh.
Definition: hexRef8.C:4285
labelList f(nPoints)
void operator=(const hexRef8 &)=delete
Disallow default bitwise assignment.
A bit-packed bool list.
ClassName("hexRef8")
Runtime type information.
const polyMesh & mesh() const
Definition: hexRef8.H:380
label faceLevel(const label facei) const
Gets level such that the face has four points <= level.
Definition: hexRef8.C:796
Direct mesh changes based on v1.3 polyTopoChange syntax.
labelList getSplitPoints() const
Return the points at the centre of top-level split cells.
Definition: hexRef8.C:5120
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
void checkRefinementLevels(const label maxPointDiff, const labelList &pointsToCheck) const
Debug: Check 2:1 consistency across faces.
Definition: hexRef8.C:4808
All refinement history. Used in unrefinement.
const cellShapeList & cellShapes() const
Utility: get hexes as cell shapes.
Definition: hexRef8.C:5060
const labelIOList & cellLevel() const
Definition: hexRef8.H:385
Namespace for OpenFOAM.