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-2018 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  //- Disallow default bitwise copy construct
340  hexRef8(const hexRef8&);
341 
342  //- Disallow default bitwise assignment
343  void operator=(const hexRef8&);
344 
345 
346 public:
347 
348  //- Runtime type information
349  ClassName("hexRef8");
350 
351 
352  // Constructors
353 
354  //- Construct from mesh, read_if_present refinement data
355  // (from write below). If readHistory is true does read_if_present
356  // of refinement history. If false clears all history
357  hexRef8(const polyMesh& mesh, const bool readHistory = true);
358 
359  //- Construct from mesh and un/refinement data and optional size of
360  // starting cells
361  hexRef8
362  (
363  const polyMesh& mesh,
364  const labelList& cellLevel,
365  const labelList& pointLevel,
366  const refinementHistory& history,
367  const scalar level0Edge = -great
368  );
369 
370  //- Construct from mesh and refinement data and optional size of
371  // starting cells
372  hexRef8
373  (
374  const polyMesh& mesh,
375  const labelList& cellLevel,
376  const labelList& pointLevel,
377  const scalar level0Edge = -great
378  );
379 
380 
381  // Member Functions
382 
383  // Access
385  const polyMesh& mesh() const
386  {
387  return mesh_;
388  }
390  const labelIOList& cellLevel() const
391  {
392  return cellLevel_;
393  }
395  const labelIOList& pointLevel() const
396  {
397  return pointLevel_;
398  }
400  const refinementHistory& history() const
401  {
402  return history_;
403  }
404 
405  //- Typical edge length between unrefined points
406  scalar level0EdgeLength() const
407  {
408  return level0Edge_.value();
409  }
410 
411  // Refinement
412 
413  //- Gets level such that the face has four points <= level.
414  label faceLevel(const label facei) const;
415 
416  //- Given valid mesh and current cell level and proposed
417  // cells to refine calculate any clashes (due to 2:1) and return
418  // ok list of cells to refine.
419  // Either adds cells to refine to set (maxSet = true) or
420  // removes cells to refine (maxSet = false)
422  (
423  const labelList& cellsToRefine,
424  const bool maxSet
425  ) const;
426 
427  //- Like consistentRefinement but slower:
428  //
429  // - specify number of cells between consecutive refinement levels
430  // (consistentRefinement equivalent to 1)
431  // - specify max level difference between point-connected cells.
432  // (-1 to disable) Note that with normal 2:1 limitation
433  // (maxFaceDiff=1) there can be 8:1 size difference across point
434  // connected cells so maxPointDiff allows you to make that less.
435  // cellsToRefine : cells we're thinking about refining. It will
436  // extend this set. All refinement levels will be
437  // at least maxFaceDiff layers thick.
438  // facesToCheck : additional faces where to implement the
439  // maxFaceDiff thickness (usually only boundary
440  // faces)
442  (
443  const label maxFaceDiff,
444  const labelList& cellsToRefine,
445  const labelList& facesToCheck,
446  const label maxPointDiff,
447  const labelList& pointsToCheck
448  ) const;
449 
450  //- Like consistentSlowRefinement but uses different meshWave
451  // (proper distance instead of toplogical count). No point checks
452  // yet.
454  (
455  const label maxFaceDiff,
456  const labelList& cellsToRefine,
457  const labelList& facesToCheck
458  ) const;
459 
460  //- Insert refinement. All selected cells will be split into 8.
461  // Returns per element in cells the 8 cells they were split into.
462  // Guarantees that the 0th element is the original cell label.
463  // Mapping:
464  // -split cells: 7 new ones get added from original
465  // -split faces: original gets modified; 3 new ones get added
466  // from original
467  // -added internal faces: added from original cell face(if
468  // that was internal) or created out-of-nothing (so will not
469  // get mapped!). Note: could make this inflate from point but
470  // that will allocate interpolation.
471  // -points added to split edge: added from edge start()
472  // -midpoints added: added from cellPoints[0].
474  (
475  const labelList& cells,
477  );
478 
479  //- Update local numbering for changed mesh.
480  void updateMesh(const mapPolyMesh&);
481 
482 
483  // Restoring : is where other processes delete and reinsert data.
484  // These callbacks allow this to restore the cellLevel
485  // and pointLevel for reintroduced points.
486  // Is not related to undoing my refinement
487 
488  //- Signal points/face/cells for which to store data
489  void storeData
490  (
491  const labelList& pointsToStore,
492  const labelList& facesToStore,
493  const labelList& cellsToStore
494  );
495 
496  //- Update local numbering + undo
497  // Data to restore given as new pointlabel + stored pointlabel
498  // (i.e. what was in pointsToStore)
499  void updateMesh
500  (
501  const mapPolyMesh&,
502  const Map<label>& pointsToRestore,
503  const Map<label>& facesToRestore,
504  const Map<label>& cellsToRestore
505  );
506 
507 
508  //- Update local numbering for subsetted mesh.
509  // Gets new-to-old maps. Not compatible with unrefinement.
510  void subset
511  (
512  const labelList& pointMap,
513  const labelList& faceMap,
514  const labelList& cellMap
515  );
516 
517  //- Update local numbering for mesh redistribution
518  void distribute(const mapDistributePolyMesh&);
519 
520  //- Debug: Check coupled mesh for correctness
521  void checkMesh() const;
522 
523  //- Debug: Check 2:1 consistency across faces.
524  // maxPointDiff==-1 : only check 2:1 across faces
525  // maxPointDiff!=-1 : check point-connected cells.
527  (
528  const label maxPointDiff,
529  const labelList& pointsToCheck
530  ) const;
531 
532  //- Utility: get hexes as cell shapes
533  const cellShapeList& cellShapes() const;
534 
535 
536  // Unrefinement (undoing refinement, not arbitrary coarsening)
537 
538  //- Return the points at the centre of top-level split cells
539  // that can be unsplit.
540  labelList getSplitPoints() const;
541 
542  //- Given proposed
543  // splitPoints to unrefine according to calculate any clashes
544  // (due to 2:1) and return ok list of points to unrefine.
545  // Either adds points to refine to set (maxSet = true) or
546  // removes points to refine (maxSet = false)
548  (
549  const labelList& pointsToUnrefine,
550  const bool maxSet
551  ) const;
552 
553  //- Remove some refinement. Needs to be supplied output of
554  // consistentUnrefinement. Only call if undoable set.
555  // All 8 pointCells of a split point will be combined into
556  // the lowest numbered cell of those 8.
557  void setUnrefinement
558  (
559  const labelList& splitPointLabels,
561  );
562 
563  // Write
564 
565  // Set instance for mesh files
566  void setInstance(const fileName& inst);
567 
568  //- Force writing refinement+history to polyMesh directory.
569  bool write(const bool valid = true) const;
570 
571 };
572 
573 
574 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
575 
576 } // End namespace Foam
577 
578 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
579 
580 #endif
581 
582 // ************************************************************************* //
void distribute(const mapDistributePolyMesh &)
Update local numbering for mesh redistribution.
Definition: hexRef8.C:4572
const refinementHistory & history() const
Definition: hexRef8.H:399
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:69
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
const labelIOList & pointLevel() const
Definition: hexRef8.H:394
void setUnrefinement(const labelList &splitPointLabels, polyTopoChange &)
Remove some refinement. Needs to be supplied output of.
Definition: hexRef8.C:5560
void checkMesh() const
Debug: Check coupled mesh for correctness.
Definition: hexRef8.C:4600
void storeData(const labelList &pointsToStore, const labelList &facesToStore, const labelList &cellsToStore)
Signal points/face/cells for which to store data.
Definition: hexRef8.C:4262
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:2817
labelListList setRefinement(const labelList &cells, polyTopoChange &)
Insert refinement. All selected cells will be split into 8.
Definition: hexRef8.C:3242
labelList consistentUnrefinement(const labelList &pointsToUnrefine, const bool maxSet) const
Given proposed.
Definition: hexRef8.C:5326
scalar level0EdgeLength() const
Typical edge length between unrefined points.
Definition: hexRef8.H:405
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:4489
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:2258
Refinement of (split) hexes using polyTopoChange.
Definition: hexRef8.H:64
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:2333
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:4287
labelList f(nPoints)
A bit-packed bool list.
ClassName("hexRef8")
Runtime type information.
const polyMesh & mesh() const
Definition: hexRef8.H:384
label faceLevel(const label facei) const
Gets level such that the face has four points <= level.
Definition: hexRef8.C:796
bool write(const bool valid=true) const
Force writing refinement+history to polyMesh directory.
Definition: hexRef8.C:5749
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:5122
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:4810
All refinement history. Used in unrefinement.
const cellShapeList & cellShapes() const
Utility: get hexes as cell shapes.
Definition: hexRef8.C:5062
const labelIOList & cellLevel() const
Definition: hexRef8.H:389
Namespace for OpenFOAM.